:root {
  --ink: #1d2433;
  --muted: #667085;
  --paper: #fff8e8;
  --panel: rgba(255, 255, 255, 0.92);
  --line: #d8dfcf;
  --accent: #d9262e;
  --accent-2: #006fd6;
  --accent-3: #ffd166;
  --shadow: 0 18px 44px rgba(29, 36, 51, 0.18);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(217, 38, 46, 0.08) 0 12px, transparent 12px 50px, rgba(0, 111, 214, 0.08) 50px 62px, transparent 62px 100px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.42) 0 2px, transparent 2px 24px),
    linear-gradient(135deg, #f4ead2 0%, #e7eddc 48%, #dce9ed 100%);
}

* {
  box-sizing: border-box;
}

html,
body,
button,
canvas,
.shell,
.touch {
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  overscroll-behavior: none;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255, 209, 102, 0.22) 0 9px, transparent 9px 100%),
    repeating-linear-gradient(90deg, rgba(29, 36, 51, 0.055) 0 1px, transparent 1px 48px),
    linear-gradient(90deg, rgba(217, 38, 46, 0.08), transparent 28%, transparent 72%, rgba(0, 111, 214, 0.08));
  opacity: 0.72;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid #d7c7b1;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #fff3dd);
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 3px 0 #c5b08f, 0 9px 18px rgba(29, 36, 51, 0.08);
  touch-action: manipulation;
}

button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #cdbfaa;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

button.primary {
  border-color: #b91f28;
  background: linear-gradient(180deg, #ef4a50, #d9262e);
  color: white;
  box-shadow: 0 4px 0 #9f1820;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  box-shadow: inset 0 2px 0 rgba(29, 36, 51, 0.04);
  -webkit-user-select: text;
  user-select: text;
}

input[type="range"] {
  min-height: 34px;
  padding: 0;
  border: 0;
  box-shadow: none;
  background: transparent;
  accent-color: var(--accent-2);
  -webkit-user-select: none;
  user-select: none;
}

select {
  appearance: none;
  font-weight: 800;
  cursor: pointer;
  background:
    linear-gradient(45deg, transparent 50%, #667085 50%) calc(100% - 18px) 19px / 7px 7px no-repeat,
    linear-gradient(135deg, #667085 50%, transparent 50%) calc(100% - 11px) 19px / 7px 7px no-repeat,
    rgba(255, 255, 255, 0.95);
  -webkit-user-select: none;
  user-select: none;
}

.shell {
  position: relative;
  z-index: 1;
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 14px;
}

.topbar,
.panel,
.hud,
.event-log {
  border: 1px solid rgba(216, 223, 207, 0.9);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(255, 246, 226, 0.92));
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 14px;
  border-color: rgba(217, 38, 46, 0.2);
  background:
    linear-gradient(90deg, rgba(217, 38, 46, 0.14), rgba(255, 246, 226, 0.96) 34%, rgba(0, 111, 214, 0.14));
  box-shadow: 0 8px 0 rgba(0, 111, 214, 0.12), var(--shadow);
}

h1 {
  margin: 0;
  font-size: 48px;
  line-height: 0.9;
  letter-spacing: 0;
  color: #d9262e;
  text-shadow: 2px 0 0 #ffffff, -2px 0 0 #ffffff, 0 3px 0 rgba(0, 111, 214, 0.35);
}

p {
  margin: 6px 0 0;
  color: var(--muted);
}

.login {
  display: grid;
  grid-template-columns: minmax(140px, 220px) 88px;
  gap: 8px;
}

.is-playing .login {
  display: none;
}

.is-playing .topbar {
  padding-block: 10px;
}

.is-playing h1 {
  font-size: 40px;
}

.lobby {
  position: relative;
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 14px;
  align-items: start;
}

.lobby::before {
  content: "";
  position: absolute;
  inset: -8px;
  z-index: -1;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(217, 38, 46, 0.1), transparent 22%, transparent 78%, rgba(0, 111, 214, 0.1)),
    repeating-linear-gradient(90deg, transparent 0 30px, rgba(255, 255, 255, 0.2) 30px 32px);
  opacity: 0.82;
}

.side-stack {
  display: grid;
  gap: 14px;
  align-content: start;
}

.panel {
  padding: 14px;
  border-color: rgba(45, 92, 88, 0.18);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-weight: 900;
}

.panel-title strong {
  color: var(--accent-2);
}

.map-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.map-card {
  min-height: 164px;
  display: grid;
  align-content: space-between;
  padding: 12px;
  border: 2px solid transparent;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(255, 245, 224, 0.92));
  cursor: pointer;
  overflow: hidden;
}

.map-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217, 38, 46, 0.16), 0 3px 0 #9f1820;
}

.map-preview {
  display: grid;
  grid-template-columns: repeat(var(--map-width, 15), minmax(0, 1fr));
  grid-template-rows: repeat(var(--map-height, 13), minmax(0, 1fr));
  aspect-ratio: var(--map-width, 15) / var(--map-height, 13);
  gap: 0;
  padding: 3px;
  border-radius: 8px;
  border: 2px solid rgba(29, 36, 51, 0.08);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 38%),
    linear-gradient(180deg, #a6da73, #74bf55);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.22);
  overflow: hidden;
}

.map-card[data-theme="water"] .map-preview {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 38%),
    linear-gradient(180deg, #8fd8c5, #70c396);
}

.map-card[data-theme="night"] .map-preview {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.14), transparent 38%),
    linear-gradient(180deg, #88b8bd, #6c9ab0);
}

.map-card[data-theme="pirate"] .map-preview {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.16), transparent 38%),
    linear-gradient(180deg, #caa46a, #9b7449);
}

.map-preview[data-theme="water"] {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 38%),
    linear-gradient(180deg, #8fd8c5, #70c396);
}

.map-preview[data-theme="night"] {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.14), transparent 38%),
    linear-gradient(180deg, #88b8bd, #6c9ab0);
}

.map-preview[data-theme="pirate"] {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.16), transparent 38%),
    linear-gradient(180deg, #caa46a, #9b7449);
}

.map-tile {
  min-width: 0;
  min-height: 0;
  border-radius: 0;
  background: transparent;
}

.map-card[data-theme="water"] .map-tile.floor {
  background: transparent;
}

.map-card[data-theme="night"] .map-tile.floor {
  background: transparent;
}

.map-card[data-theme="pirate"] .map-tile.floor {
  background: transparent;
}

.map-tile.hard {
  background: linear-gradient(180deg, #e8e5f4, #908bbb);
  box-shadow: inset 0 -1px 0 rgba(40, 44, 76, 0.14);
}

.map-card[data-theme="pirate"] .map-tile.hard {
  background: linear-gradient(180deg, #e4dcc9, #837763);
}

.map-tile.crate {
  background: linear-gradient(180deg, #f3c36b, #d88155);
  box-shadow: inset 0 0 0 1px rgba(117, 74, 42, 0.22);
}

.map-card[data-theme="pirate"] .map-tile.crate {
  background: linear-gradient(180deg, #d7a35b, #9b603f);
}

.map-tile.water {
  background: linear-gradient(180deg, #76d8f1, #006fd6);
}

.map-tile.post {
  background: linear-gradient(180deg, #fff2b0, #d6ad45);
}

.map-tile.spawn {
  background: radial-gradient(circle at 50% 50%, #ffffff 0 24%, #d9262e 26% 52%, #74bf55 54%);
}

.modes {
  display: grid;
  gap: 10px;
  align-content: start;
}

.difficulty-row,
.volume-row {
  display: grid;
  grid-template-columns: 1fr 126px;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  border: 1px solid #d7c7b1;
  border-radius: 8px;
  padding: 8px 10px;
  background: linear-gradient(180deg, #ffffff, #fff3dd);
  box-shadow: 0 3px 0 #c5b08f, 0 9px 18px rgba(29, 36, 51, 0.08);
  font-weight: 900;
}

.difficulty-row:has(select:disabled) {
  opacity: 0.58;
}

.volume-row {
  grid-template-columns: 64px 1fr;
}

.room-panel {
  display: grid;
  gap: 10px;
}

.room-code-form {
  display: grid;
  grid-template-columns: 1fr 72px;
  gap: 8px;
}

.room-tools {
  display: grid;
  grid-template-columns: 1fr 112px;
  gap: 8px;
}

.current-room,
.room-list {
  display: grid;
  gap: 8px;
}

.room-card {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 10px;
  text-align: left;
  border: 2px solid rgba(0, 111, 214, 0.16);
  background: linear-gradient(180deg, #ffffff, #fff3dd);
  overflow: hidden;
}

.room-card.mine {
  border-color: rgba(217, 38, 46, 0.3);
  box-shadow: 0 3px 0 rgba(217, 38, 46, 0.14);
}

.room-card.full {
  cursor: not-allowed;
  opacity: 0.62;
  background: linear-gradient(180deg, #ffffff, #f0f2f5);
}

.room-map-preview {
  width: 100%;
  max-width: 220px;
  justify-self: start;
}

.room-list-preview {
  width: min(100%, 148px);
  justify-self: start;
}

.room-card .map-preview {
  padding: 2px;
  border-width: 1px;
  border-radius: 7px;
}

.room-head,
.room-player,
.room-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.room-player-main,
.room-player-chip {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.room-avatar {
  flex: 0 0 auto;
  width: 24px;
  height: 26px;
  position: relative;
  border-radius: 7px;
  background:
    radial-gradient(circle at 50% 30%, var(--char-skin) 0 36%, transparent 37%),
    linear-gradient(180deg, transparent 0 49%, var(--char-suit) 50% 100%);
  box-shadow: inset 0 0 0 1px rgba(29, 36, 51, 0.12), 0 1px 0 rgba(29, 36, 51, 0.08);
}

.room-avatar::before,
.room-avatar::after {
  content: "";
  position: absolute;
  top: 8px;
  width: 3px;
  height: 4px;
  border-radius: 50%;
  background: #26324b;
}

.room-avatar::before {
  left: 8px;
}

.room-avatar::after {
  right: 8px;
}

.room-avatar.char-dao,
.room-avatar.char-bazzi,
.room-avatar.char-mos {
  background:
    linear-gradient(180deg, var(--char-accent) 0 28%, transparent 29%),
    radial-gradient(circle at 50% 34%, var(--char-skin) 0 36%, transparent 37%),
    linear-gradient(180deg, transparent 0 49%, var(--char-suit) 50% 100%);
}

.room-avatar.char-dizni {
  background:
    radial-gradient(circle at 14% 42%, var(--char-hair) 0 14%, transparent 15%),
    radial-gradient(circle at 86% 42%, var(--char-hair) 0 14%, transparent 15%),
    linear-gradient(180deg, var(--char-hair) 0 24%, transparent 25%),
    radial-gradient(circle at 50% 34%, var(--char-skin) 0 36%, transparent 37%),
    linear-gradient(180deg, transparent 0 49%, var(--char-suit) 50% 100%);
}

.room-map-select {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.room-head strong,
.room-player-main > span,
.room-code,
.room-ready,
.room-names {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-names {
  display: flex;
  gap: 5px;
  align-items: center;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
  white-space: normal;
}

.room-player-chip {
  max-width: 100%;
  padding: 2px 6px 2px 3px;
  border-radius: 999px;
  background: rgba(0, 111, 214, 0.08);
}

.room-player-chip > span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-ready {
  display: block;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 900;
}

.room-code {
  display: block;
  width: max-content;
  max-width: 100%;
  padding: 3px 7px;
  border-radius: 8px;
  background: rgba(0, 111, 214, 0.1);
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 950;
  letter-spacing: 0.08em;
}

.ready-pill {
  flex-shrink: 0;
  min-width: 70px;
  padding: 4px 7px;
  border-radius: 8px;
  background: rgba(29, 36, 51, 0.08);
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.ready-pill.ready {
  background: rgba(56, 206, 145, 0.18);
  color: #13764f;
}

.room-player button,
.room-actions button {
  min-height: 34px;
  padding: 6px 10px;
  white-space: nowrap;
}

.network-status {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border: 1px solid rgba(0, 111, 214, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.match-timer {
  min-height: 34px;
  min-width: 58px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border: 1px solid rgba(29, 36, 51, 0.12);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #fff7e7);
  color: var(--ink);
  font-size: 14px;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.match-timer.urgent {
  border-color: rgba(217, 38, 46, 0.34);
  color: var(--accent);
  box-shadow: inset 0 -3px 0 rgba(217, 38, 46, 0.12);
}

.network-status.slow {
  border-color: rgba(217, 38, 46, 0.28);
  color: var(--accent);
  background: rgba(255, 242, 230, 0.9);
}

.network-status.busy {
  box-shadow: inset 0 -3px 0 rgba(255, 189, 72, 0.34);
}

.two-player-toggle,
.coop-toggle {
  min-height: 48px;
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: center;
  gap: 10px;
  border: 1px solid #d7c7b1;
  border-radius: 8px;
  padding: 8px 10px;
  background: linear-gradient(180deg, #ffffff, #fff3dd);
  box-shadow: 0 3px 0 #c5b08f, 0 9px 18px rgba(29, 36, 51, 0.08);
  cursor: pointer;
}

.two-player-toggle input,
.coop-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.two-player-toggle span,
.coop-toggle span {
  width: 54px;
  height: 30px;
  border-radius: 999px;
  background: #d9dfd1;
  box-shadow: inset 0 2px 4px rgba(29, 36, 51, 0.18);
  position: relative;
}

.two-player-toggle span::after,
.coop-toggle span::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 4px rgba(29, 36, 51, 0.18);
  transition: transform 0.15s ease;
}

.two-player-toggle input:checked + span,
.coop-toggle input:checked + span {
  background: #006fd6;
}

.two-player-toggle input:checked + span::after,
.coop-toggle input:checked + span::after {
  transform: translateX(24px);
}

.two-player-toggle:has(input:disabled),
.coop-toggle:has(input:disabled) {
  opacity: 0.58;
  cursor: not-allowed;
}

.character-list {
  display: grid;
  gap: 8px;
}

.character-card {
  min-height: 116px;
  display: grid;
  grid-template-columns: 96px 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px;
  text-align: left;
  border: 2px solid transparent;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.98), rgba(255, 248, 232, 0.96)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(255, 245, 224, 0.92));
  overflow: hidden;
}

.character-card.selected {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(0, 111, 214, 0.16), 0 3px 0 #164d93;
}

.mini-character {
  position: relative;
  width: 88px;
  height: 96px;
  display: block;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.08)),
    linear-gradient(90deg, rgba(217, 38, 46, 0.08), rgba(0, 111, 214, 0.1)),
    linear-gradient(180deg, rgba(255, 245, 224, 0.9), rgba(221, 232, 232, 0.82));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.68), 0 5px 0 rgba(29, 36, 51, 0.08);
}

.mini-character::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 2px;
  height: 12px;
  border-radius: 999px;
  background: rgba(29, 36, 51, 0.16);
}

.mini-head,
.mini-body,
.mini-arm {
  position: absolute;
  display: block;
}

.mini-head {
  left: 19px;
  top: 10px;
  width: 50px;
  height: 48px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 27%, rgba(255, 255, 255, 0.62), transparent 18%),
    linear-gradient(var(--char-suit) 0 24%, transparent 25%),
    radial-gradient(circle at 42% 35%, #fff2d7 0 10%, var(--char-skin) 56%);
  box-shadow: 0 3px 0 rgba(29, 36, 51, 0.1), inset 0 -2px 0 rgba(29, 36, 51, 0.12);
  z-index: 3;
}

.mini-head::before,
.mini-head::after {
  content: "";
  position: absolute;
  top: 24px;
  width: 6px;
  height: 7px;
  border-radius: 50%;
  background: #26324b;
}

.mini-head::before {
  left: 14px;
}

.mini-head::after {
  right: 14px;
}

.mini-body {
  left: 23px;
  top: 55px;
  width: 42px;
  height: 33px;
  border-radius: 18px 18px 12px 12px;
  background:
    radial-gradient(circle at 34% 22%, rgba(255, 255, 255, 0.42), transparent 22%),
    linear-gradient(90deg, transparent 0 37%, var(--char-trim) 37% 63%, transparent 63%),
    linear-gradient(180deg, color-mix(in srgb, var(--char-suit), white 22%), var(--char-suit));
  z-index: 2;
}

.mini-body::before,
.mini-body::after {
  content: "";
  position: absolute;
  bottom: -6px;
  width: 15px;
  height: 10px;
  border-radius: 999px;
  background: var(--char-shoe);
}

.mini-body::before {
  left: 2px;
}

.mini-body::after {
  right: 2px;
}

.mini-arm {
  top: 60px;
  width: 18px;
  height: 24px;
  border-radius: 999px;
  background:
    radial-gradient(circle at 50% 78%, var(--char-glove) 0 32%, transparent 33%),
    var(--char-suit);
  z-index: 1;
}

.mini-arm.left {
  left: 16px;
  transform: rotate(12deg);
}

.mini-arm.right {
  right: 16px;
  transform: rotate(-12deg);
}

.mini-character.char-dao .mini-head::before,
.mini-character.char-dao .mini-head::after {
  top: 23px;
}

.mini-character.char-dao .mini-head {
  background:
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.62), transparent 18%),
    radial-gradient(circle at 35% 3%, var(--char-accent) 0 9%, transparent 10%),
    radial-gradient(circle at 62% 2%, var(--char-accent) 0 8%, transparent 9%),
    linear-gradient(var(--char-suit) 0 35%, transparent 36%),
    radial-gradient(circle at 42% 38%, #fff2d7 0 10%, var(--char-skin) 56%);
}

.mini-character.char-bazzi .mini-head {
  background:
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.62), transparent 18%),
    radial-gradient(circle at 16% 4%, color-mix(in srgb, var(--char-suit), white 22%) 0 14%, transparent 15%),
    radial-gradient(circle at 84% 4%, color-mix(in srgb, var(--char-suit), white 22%) 0 14%, transparent 15%),
    linear-gradient(var(--char-suit) 0 40%, transparent 41%),
    radial-gradient(circle at 42% 38%, #fff2d7 0 10%, var(--char-skin) 56%);
}

.mini-character.char-bazzi .mini-head {
  box-shadow:
    inset 0 10px 0 rgba(255, 255, 255, 0.7),
    0 3px 0 rgba(29, 36, 51, 0.1);
}

.mini-character.char-dizni .mini-head {
  background:
    radial-gradient(circle at 8% 44%, var(--char-hair) 0 16%, transparent 17%),
    radial-gradient(circle at 92% 44%, var(--char-hair) 0 16%, transparent 17%),
    radial-gradient(circle at 26% 15%, var(--char-accent) 0 9%, transparent 10%),
    radial-gradient(circle at 74% 15%, var(--char-accent) 0 9%, transparent 10%),
    linear-gradient(var(--char-hair) 0 28%, transparent 29%),
    radial-gradient(circle at 42% 38%, #fff2d7 0 10%, var(--char-skin) 56%);
}

.mini-character.char-mos .mini-head {
  background:
    radial-gradient(ellipse at 42% -5%, var(--char-accent) 0 13%, transparent 14%),
    radial-gradient(ellipse at 58% -4%, var(--char-accent) 0 12%, transparent 13%),
    linear-gradient(var(--char-suit) 0 38%, transparent 39%),
    radial-gradient(circle at 42% 38%, #fff2d7 0 10%, var(--char-skin) 56%);
}

.character-copy {
  display: grid;
  gap: 4px;
}

.character-copy strong {
  font-size: 15px;
}

.stat-row {
  display: grid;
  grid-template-columns: 64px 1fr;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
}

.stat-row b {
  font-weight: 800;
}

.stat-row i {
  height: 7px;
  border-radius: 999px;
  background:
    linear-gradient(90deg, var(--accent-2) calc(var(--value) * 100%), rgba(29, 36, 51, 0.12) 0);
}

.item-guide-panel {
  box-shadow: 0 8px 0 rgba(217, 38, 46, 0.12), var(--shadow);
}

.item-guide-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.item-guide-card {
  min-height: 58px;
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(216, 223, 207, 0.86);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(255, 248, 232, 0.78));
}

.item-guide-card .item-badge {
  width: 24px;
  height: 24px;
  border-radius: 7px;
}

.item-guide-card strong,
.item-guide-card small {
  display: block;
}

.item-guide-card strong {
  font-size: 12px;
  line-height: 1.1;
}

.item-guide-card small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.25;
}

.local-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.game {
  position: relative;
  display: grid;
  gap: 10px;
  min-height: 0;
}

.hidden {
  display: none !important;
}

.hud {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 10px;
  box-shadow: 0 8px 0 rgba(75, 154, 160, 0.22), var(--shadow);
}

.players-hud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.player-chip {
  min-width: 132px;
  border-radius: 8px;
  padding: 8px 10px;
  background:
    linear-gradient(180deg, #ffffff, #fff7e7);
  border: 1px solid var(--line);
  box-shadow: inset 4px 0 0 var(--accent);
}

.player-chip.player-2 {
  box-shadow: inset 4px 0 0 #006fd6;
}

.player-chip.player-3 {
  box-shadow: inset 4px 0 0 #ffd75e;
}

.player-chip.player-4 {
  box-shadow: inset 4px 0 0 #6bd978;
}

.player-chip.coop-objective {
  min-width: 188px;
  box-shadow: inset 4px 0 0 #0f8f7a;
}

.player-chip strong {
  display: block;
  font-size: 14px;
}

.player-chip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.item-badges {
  display: flex !important;
  gap: 4px;
  margin-top: 4px;
  min-height: 18px;
}

.item-badge {
  width: 18px;
  height: 18px;
  display: inline-block;
  border-radius: 6px;
  border: 1px solid rgba(29, 36, 51, 0.12);
  background: #ffffff;
  position: relative;
}

.item-badge.power::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 3px;
  width: 4px;
  height: 12px;
  border-radius: 999px;
  background: #0078d7;
  box-shadow: -4px 4px 0 #0078d7, 4px 4px 0 #0078d7;
}

.item-badge.speed {
  background: linear-gradient(180deg, #fff9ca, #ffd34f);
}

.item-badge.speed::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 7px;
  width: 11px;
  height: 5px;
  border-radius: 4px;
  background: #ffffff;
  border-bottom: 3px solid #26324b;
}

.item-badge.splash::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 25%, #ffffff, #79d4f5 32%, #006fd6 72%);
}

.item-badge.boots {
  background: linear-gradient(180deg, #fff7dc, #c9a37a);
}

.item-badge.boots::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 8px;
  width: 12px;
  height: 5px;
  border-radius: 5px;
  background: #ffffff;
  border-bottom: 3px solid #d9262e;
}

.item-badge.kick::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 4px;
  width: 11px;
  height: 10px;
  border-radius: 6px;
  background: #8f7dff;
}

.item-badge.dart::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 8px;
  width: 12px;
  height: 3px;
  border-radius: 999px;
  background: #d9262e;
  transform: rotate(-38deg);
}

.item-badge.dart::after {
  content: "";
  position: absolute;
  right: 3px;
  top: 3px;
  width: 0;
  height: 0;
  border-left: 6px solid #ffffff;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transform: rotate(-38deg);
}

.item-badge.shield::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 3px;
  width: 10px;
  height: 12px;
  clip-path: polygon(50% 0, 100% 18%, 86% 76%, 50% 100%, 14% 76%, 0 18%);
  background: #38ce91;
}

.item-badge.needle::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 3px;
  width: 3px;
  height: 13px;
  border-radius: 999px;
  background: #26324b;
  transform: rotate(22deg);
}

.item-badge.needle::after {
  content: "";
  position: absolute;
  left: 3px;
  bottom: 2px;
  width: 6px;
  height: 6px;
  border: 2px solid #d9262e;
  border-radius: 50%;
}

.empty-items {
  color: #98a2b3;
}

#board {
  display: block;
  width: min(100%, calc((100vh - 245px) * 15 / 13));
  height: auto;
  max-width: 100%;
  margin-inline: auto;
  aspect-ratio: 15 / 13;
  border: 7px solid #ffffff;
  border-radius: 8px;
  background: #8fdc72;
  box-shadow:
    0 8px 0 #3d8894,
    inset 0 0 0 3px rgba(255, 255, 255, 0.48),
    0 24px 54px rgba(29, 36, 51, 0.22);
  touch-action: none;
}

.event-log {
  min-height: 46px;
  max-height: 74px;
  overflow: hidden;
  padding: 8px 10px;
  color: #344054;
  font-size: 13px;
  box-shadow: 0 5px 0 rgba(75, 154, 160, 0.18), var(--shadow);
}

.result-overlay {
  position: absolute;
  left: 50%;
  top: 52%;
  z-index: 8;
  transform: translate(-50%, -50%);
  width: min(86vw, 520px);
  padding: 22px 18px;
  text-align: center;
  color: #ffffff;
  font-size: clamp(26px, 6vw, 48px);
  font-weight: 900;
  line-height: 1.04;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.2);
  border: 3px solid rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(0, 111, 214, 0.94), rgba(2, 67, 140, 0.94));
  box-shadow: 0 10px 0 rgba(0, 51, 112, 0.34), 0 28px 50px rgba(29, 36, 51, 0.28);
  pointer-events: none;
}

.result-overlay > strong {
  display: block;
}

.result-overlay.lose {
  background: linear-gradient(180deg, rgba(217, 38, 46, 0.94), rgba(128, 25, 38, 0.94));
  box-shadow: 0 10px 0 rgba(104, 24, 35, 0.34), 0 28px 50px rgba(29, 36, 51, 0.28);
}

.result-overlay.draw {
  background: linear-gradient(180deg, rgba(38, 50, 75, 0.94), rgba(29, 36, 51, 0.94));
  box-shadow: 0 10px 0 rgba(29, 36, 51, 0.34), 0 28px 50px rgba(29, 36, 51, 0.28);
}

.result-stats {
  display: grid;
  gap: 6px;
  margin-top: 14px;
  font-size: 13px;
  line-height: 1.2;
  text-align: left;
  text-shadow: none;
}

.result-stats span {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 7px 9px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.14);
}

.result-stats span.winner {
  background: rgba(255, 255, 255, 0.24);
}

.result-stats b,
.result-stats i {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-stats i {
  font-style: normal;
  opacity: 0.88;
}

.result-stats em {
  display: inline-block;
  margin-right: 6px;
  padding: 2px 5px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.2);
  font-style: normal;
  font-weight: 900;
}

.result-stats span.out,
.result-stats span.bubble {
  opacity: 0.82;
}

.result-overlay small {
  display: block;
  margin-top: 10px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0;
  opacity: 0.9;
}

.touch {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 14px max(14px, env(safe-area-inset-bottom));
  touch-action: none;
}

.touch,
.touch * {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch button {
  pointer-events: auto;
  width: 58px;
  height: 58px;
  min-height: 58px;
  display: grid;
  place-items: center;
  gap: 1px;
  padding: 6px;
  font-size: 11px;
  line-height: 1;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(255, 245, 218, 0.92));
  box-shadow: 0 4px 0 rgba(120, 104, 79, 0.72), 0 12px 22px rgba(29, 36, 51, 0.18);
  touch-action: none;
}

.touch button.has-item .item-badge {
  width: 20px;
  height: 20px;
}

.touch-label {
  display: block;
  max-width: 46px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.touch button.pressed {
  transform: translateY(4px);
  box-shadow: 0 1px 0 rgba(120, 104, 79, 0.72), 0 8px 16px rgba(29, 36, 51, 0.16);
}

.move-zone {
  pointer-events: auto;
  width: min(46vw, 230px);
  height: 184px;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  touch-action: none;
}

.joystick {
  pointer-events: none;
  width: 164px;
  height: 164px;
  position: relative;
  border-radius: 50%;
  touch-action: none;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.8) 0 30%, rgba(255, 255, 255, 0.38) 31% 54%, rgba(36, 86, 118, 0.2) 55% 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(227, 239, 236, 0.7));
  border: 2px solid rgba(255, 255, 255, 0.72);
  box-shadow:
    inset 0 3px 8px rgba(255, 255, 255, 0.58),
    inset 0 -9px 18px rgba(36, 86, 118, 0.18),
    0 8px 0 rgba(60, 100, 102, 0.36),
    0 18px 34px rgba(29, 36, 51, 0.18);
}

.joystick-ring {
  position: absolute;
  inset: 22px;
  border-radius: 50%;
  border: 2px dashed rgba(0, 111, 214, 0.32);
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background:
    radial-gradient(circle at 36% 30%, rgba(255, 255, 255, 0.94) 0 18%, rgba(255, 255, 255, 0) 19%),
    linear-gradient(180deg, #2f8fe3, #006fd6 58%, #0755a4);
  border: 2px solid rgba(255, 255, 255, 0.82);
  box-shadow:
    inset 0 -8px 12px rgba(0, 53, 120, 0.2),
    0 6px 0 rgba(0, 77, 143, 0.42),
    0 14px 24px rgba(29, 36, 51, 0.2);
  will-change: transform;
}

.touch-actions {
  display: flex;
  gap: 10px;
}

.touch-actions button {
  width: 72px;
  height: 72px;
  min-height: 72px;
}

.touch-actions button[data-touch="bomb"] {
  background: linear-gradient(180deg, #4aa5f0, #006fd6);
  color: #ffffff;
}

.touch-actions button[data-touch="item"] {
  background: linear-gradient(180deg, #fff094, #ffbd48);
}

@media (max-width: 760px) {
  body.is-playing .topbar {
    display: none;
  }

  body.is-playing .shell {
    min-height: 100dvh;
    grid-template-rows: 1fr;
    padding: 8px 8px calc(178px + env(safe-area-inset-bottom));
  }

  body.is-playing .game {
    align-content: start;
    gap: 7px;
  }

  .move-zone {
    width: min(54vw, 244px);
    height: 190px;
  }

  .shell {
    padding: 10px 10px 182px;
    gap: 10px;
  }

  .topbar,
  .lobby,
  .hud {
    grid-template-columns: 1fr;
  }

  .topbar,
  .hud {
    align-items: stretch;
  }

  h1 {
    font-size: 36px;
  }

  .login,
  .local-row,
  .room-code-form,
  .room-tools {
    grid-template-columns: 1fr;
  }

  .lobby {
    display: grid;
  }

  .side-stack {
    gap: 10px;
  }

  .map-list {
    grid-template-columns: 1fr;
  }

  .item-guide-list {
    grid-template-columns: 1fr;
  }

  .character-card {
    grid-template-columns: 88px 1fr;
    min-height: 108px;
  }

  #board {
    width: min(100%, calc((100dvh - 344px - env(safe-area-inset-bottom)) * 15 / 13));
    max-width: none;
  }
}

@media (max-width: 380px), (max-height: 640px) {
  body.is-playing .shell {
    padding-bottom: calc(146px + env(safe-area-inset-bottom));
  }

  body.is-playing .hud {
    padding: 7px;
    gap: 6px;
  }

  body.is-playing .player-chip {
    min-width: 112px;
    padding: 6px 8px;
  }

  body.is-playing .event-log {
    display: none;
  }

  body.is-playing #board {
    width: min(100%, calc((100dvh - 400px - env(safe-area-inset-bottom)) * 15 / 13));
    border-width: 5px;
  }

  .move-zone {
    width: min(48vw, 184px);
    height: 146px;
  }

  .joystick {
    width: 128px;
    height: 128px;
  }

  .joystick-ring {
    inset: 17px;
  }

  .joystick-knob {
    width: 56px;
    height: 56px;
  }

  .touch-actions {
    gap: 8px;
  }

  .touch-actions button {
    width: 62px;
    height: 62px;
    min-height: 62px;
  }
}
