: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 48px, rgba(0, 111, 214, 0.08) 48px 60px, transparent 60px 96px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.34) 0 2px, transparent 2px 20px),
    linear-gradient(135deg, #f8f0d8 0%, #d8ead2 48%, #d7e6ed 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.34) 0 10px, transparent 10px 100%),
    repeating-linear-gradient(90deg, rgba(29, 36, 51, 0.07) 0 1px, transparent 1px 46px);
  opacity: 0.8;
}

button,
input {
  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.primary {
  border-color: #b91f28;
  background: linear-gradient(180deg, #ef4a50, #d9262e);
  color: white;
  box-shadow: 0 4px 0 #9f1820;
}

input {
  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;
}

.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;
}

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

.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 {
  height: 90px;
  display: grid;
  grid-template-columns: repeat(var(--map-width, 15), minmax(0, 1fr));
  gap: 1px;
  padding: 4px;
  border-radius: 8px;
  border: 2px solid rgba(29, 36, 51, 0.08);
  background: #6eaa4f;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.22);
}

.map-card[data-theme="water"] .map-preview {
  background: #65b894;
}

.map-card[data-theme="night"] .map-preview {
  background: #5d7f91;
}

.map-tile {
  min-width: 0;
  min-height: 0;
  border-radius: 2px;
  background: linear-gradient(180deg, #a6da73, #74bf55);
}

.map-card[data-theme="water"] .map-tile.floor {
  background: linear-gradient(180deg, #8fd8c5, #70c396);
}

.map-card[data-theme="night"] .map-tile.floor {
  background: linear-gradient(180deg, #88b8bd, #6c9ab0);
}

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

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

.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;
}

.two-player-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 {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.two-player-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 {
  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 {
  background: #006fd6;
}

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

.two-player-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(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.56), rgba(255, 255, 255, 0)),
    linear-gradient(180deg, rgba(116, 191, 85, 0.16), rgba(0, 111, 214, 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);
}

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

.game {
  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;
}

.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 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.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;
}

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

#board {
  width: 100%;
  max-height: calc(100vh - 245px);
  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);
}

.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 button {
  pointer-events: auto;
  width: 58px;
  height: 58px;
  min-height: 58px;
  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;
}

.pad {
  width: 184px;
  height: 184px;
  display: grid;
  grid-template-areas:
    ". up ."
    "left . right"
    ". down .";
  gap: 4px;
}

.pad .up {
  grid-area: up;
}

.pad .left {
  grid-area: left;
}

.pad .right {
  grid-area: right;
}

.pad .down {
  grid-area: down;
}

.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) {
  .shell {
    padding: 10px 10px 150px;
    gap: 10px;
  }

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

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

  h1 {
    font-size: 36px;
  }

  .login,
  .local-row {
    grid-template-columns: 1fr;
  }

  .lobby {
    display: grid;
  }

  .side-stack {
    gap: 10px;
  }

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

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

  #board {
    max-height: none;
  }
}
