/* ───────────────────────── Tokens ───────────────────────── */
:root {
  --bg: #0b0d16;
  --bg-2: #10131f;
  --panel: #161a2a;
  --panel-2: #1d2236;
  --panel-3: #262c45;
  --board: #141725;
  --line: rgba(255, 255, 255, 0.07);
  --text: #f1f3fc;
  --muted: #8d93b3;
  --faint: #5a6080;
  --accent: #ffd23f;
  --hot-1: #ff8b1f;
  --hot-2: #ff3d6e;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --font: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, "SF Pro Rounded", "Helvetica Neue", Roboto, sans-serif;
  --ease-pop: cubic-bezier(0.34, 1.56, 0.64, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 700px at 15% -10%, rgba(59, 130, 255, 0.13), transparent 60%),
    radial-gradient(900px 600px at 110% 110%, rgba(255, 61, 110, 0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; }
button:focus-visible, summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
kbd {
  font: 700 0.8em var(--font);
  padding: 1px 6px; border-radius: 6px;
  background: var(--panel-3); border-bottom: 2px solid #0006;
}

/* ───────────────────────── Screens ───────────────────────── */
.screen {
  position: fixed; inset: 0;
  opacity: 0; visibility: hidden;
  transform: scale(0.985);
  transition: opacity 0.28s ease, transform 0.28s ease, visibility 0s linear 0.28s;
}
.screen.is-active {
  opacity: 1; visibility: visible; transform: none;
  transition: opacity 0.28s ease, transform 0.28s ease, visibility 0s;
}

/* ───────────────────────── Setup ───────────────────────── */
#screen-setup { overflow-y: auto; }
.setup {
  min-height: 100%;
  max-width: 1040px; margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 16px 32px;
  display: grid; gap: 24px;
  align-content: center;
}
@media (min-width: 860px) {
  .setup { grid-template-columns: 1.05fr 1fr; gap: 56px; align-items: center; padding: 40px 32px; }
}

.setup__hero { display: grid; justify-items: center; gap: 14px; text-align: center; }

.logo { margin: 0; display: grid; gap: 6px; justify-items: center; }
.logo__row { display: flex; gap: 6px; }
.logo__tile {
  --c: #fff;
  width: clamp(38px, 9vw, 58px); aspect-ratio: 1;
  display: grid; place-items: center;
  border-radius: 14px;
  background: var(--c);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.22), 0 8px 18px rgba(0, 0, 0, 0.35);
  font-size: clamp(24px, 6vw, 38px); font-weight: 900; color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.22);
  animation: tile-in 0.5s var(--ease-pop) both;
}
.tagline { margin: 4px 0 0; color: var(--muted); font-size: 1.02rem; max-width: 34ch; }

.demo {
  margin-top: 8px;
  padding: 10px; border-radius: 22px;
  background: var(--board);
  box-shadow: var(--shadow), inset 0 0 0 1px var(--line);
  transform: rotate(-2deg);
}
#demo-board { display: block; width: min(300px, 62vw); height: min(300px, 62vw); }
@media (max-height: 760px) and (max-width: 859px) { .demo { display: none; } }

.setup__panel {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border-radius: 26px;
  padding: 22px;
  box-shadow: var(--shadow), inset 0 0 0 1px var(--line);
  display: grid; gap: 18px;
  width: 100%; max-width: 460px; justify-self: center;
}
.field { display: grid; gap: 8px; }
.field__label {
  padding: 0; margin-bottom: 8px;
  font-size: 0.78rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted);
}

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.seg__opt {
  position: relative;
  min-height: 52px; padding: 10px 8px;
  border: 0; border-radius: 14px;
  background: var(--panel-2);
  box-shadow: inset 0 0 0 2px transparent, inset 0 -3px 0 rgba(0, 0, 0, 0.25);
  display: grid; place-items: center; gap: 4px;
  font-weight: 800; font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, transform 0.12s;
}
.seg__opt:hover { background: var(--panel-3); }
.seg__opt:active { transform: scale(0.96); }
.seg__opt[aria-checked="true"] {
  background: #2b3150;
  box-shadow: inset 0 0 0 2px var(--accent), 0 6px 18px rgba(255, 210, 63, 0.15);
}
.seg__sub { font-size: 0.72rem; font-weight: 600; color: var(--muted); }
.seg--players .seg__opt { min-height: 74px; }
.seg__big { font-size: 1.6rem; line-height: 1; font-weight: 900; }
.seg__emblems { display: flex; gap: 3px; }
.seg__emblems svg { width: 12px; height: 12px; fill: var(--muted); }
.seg__opt[aria-checked="true"] .seg__emblems svg { fill: var(--text); }
.seg__swatches { display: flex; gap: 2px; }
.seg__swatches i { width: 7px; height: 7px; border-radius: 2px; }

.seats { display: grid; gap: 8px; margin-top: 4px; }
.seat { display: grid; grid-template-columns: 32px minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 8px; align-items: center; }
.seat__badge {
  width: 32px; height: 32px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--panel-2);
}
.seat__badge svg { width: 16px; height: 16px; fill: var(--muted); }
.seg--mini { gap: 4px; }
.seg--mini .seg__opt { min-height: 40px; padding: 6px; border-radius: 11px; font-size: 0.86rem; }
.seat__detail { min-width: 0; }
.seat__name {
  width: 100%; min-height: 40px; padding: 8px 12px;
  border: 0; border-radius: 11px;
  background: var(--panel-2);
  box-shadow: inset 0 0 0 2px transparent;
  color: var(--text); font: inherit; font-weight: 700; font-size: 0.92rem;
  transition: box-shadow 0.15s;
}
.seat__name::placeholder { color: var(--faint); }
.seat__name:focus { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }

.play-btn {
  position: relative; overflow: hidden;
  margin-top: 4px;
  border: 0; border-radius: 20px;
  min-height: 72px;
  background: linear-gradient(135deg, var(--hot-1), var(--hot-2));
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.2), 0 14px 30px rgba(255, 61, 110, 0.35);
  font-size: 1.9rem; font-weight: 900; letter-spacing: 0.16em;
  cursor: pointer;
  transition: transform 0.15s var(--ease-pop), box-shadow 0.2s, filter 0.2s;
}
.play-btn span { position: relative; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.18); }
.play-btn::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, 0.35) 50%, transparent 70%);
  transform: translateX(-100%);
  animation: shine 3.2s ease-in-out infinite 1s;
}
.play-btn:hover { transform: translateY(-2px); filter: brightness(1.06); }
.play-btn:active { transform: translateY(2px) scale(0.98); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.2), 0 6px 16px rgba(255, 61, 110, 0.3); }
.play-btn.is-loading { filter: saturate(0.6); pointer-events: none; }

/* Online: entry + lobby (js/ui/lobby.js) */
.setup__group { display: grid; gap: 18px; }
.setup__group[hidden], .field[hidden], .play-btn[hidden] { display: none; }
.play-btn--small { min-height: 58px; font-size: 1.25rem; letter-spacing: 0.12em; }
.btn:disabled, .play-btn:disabled { opacity: 0.55; pointer-events: none; }
.btn--small { min-height: 40px; padding: 0 14px; border-radius: 11px; font-size: 0.82rem; letter-spacing: 0.04em; }
.join { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.join .btn { padding: 0 22px; min-height: 44px; }
.join__code { text-transform: uppercase; letter-spacing: 0.2em; font-size: 1.05rem; min-height: 44px; }
.join__code::placeholder { letter-spacing: 0.2em; }
#online-name { min-height: 44px; }

.room-head { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 8px; }
.room-head__code { display: grid; line-height: 1.05; }
.room-head__code .field__label { margin: 0; }
#room-code { font-size: 2rem; font-weight: 900; letter-spacing: 0.16em; color: var(--accent); font-variant-numeric: tabular-nums; }
.members { list-style: none; margin: -6px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.member {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  background: var(--panel-2);
  font-size: 0.82rem; font-weight: 700;
}
.member__tag {
  padding: 1px 6px; border-radius: 6px;
  background: var(--panel-3); color: var(--muted);
  font-size: 0.6rem; font-weight: 900; letter-spacing: 0.08em; text-transform: uppercase;
}
.member.is-host .member__tag { background: color-mix(in srgb, var(--accent) 22%, var(--panel-3)); color: var(--accent); }

.seat--room { grid-template-columns: 32px minmax(0, 1.15fr) minmax(0, 1fr); }
.seat__badge.is-taken svg { fill: var(--text); }
.seat__badge.is-mine { background: #2b3150; box-shadow: inset 0 0 0 2px var(--accent); }
.seat__badge.is-mine svg { fill: var(--accent); }
.seat__kind { font-size: 0.86rem; font-weight: 800; color: var(--muted); padding-left: 4px; }
.seat__who {
  display: flex; align-items: center; gap: 8px; min-height: 40px; min-width: 0;
  font-weight: 800; font-size: 0.92rem;
}
.seat__who > span:not(.member__tag) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat__who .btn { margin-left: auto; }
.seat__detail > .btn { width: 100%; }
.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.dot.is-on { background: #22c97a; box-shadow: 0 0 0 3px rgba(34, 201, 122, 0.18); }
.seg--readonly .seg__opt:disabled { cursor: default; opacity: 0.75; }
.seg--readonly .seg__opt:disabled:hover { background: var(--panel-2); }
.seg--readonly .seg__opt[aria-checked="true"]:disabled { opacity: 1; background: #2b3150; }
.room-wait { margin: 0; padding: 18px; border-radius: 20px; background: var(--panel-2); text-align: center; font-weight: 800; color: var(--muted); }
.room-wait[hidden] { display: none; }
.online-msg { margin: -6px 0 0; min-height: 1.2em; font-size: 0.88rem; font-weight: 600; color: var(--muted); overflow-wrap: anywhere; }
.online-msg:empty { display: none; }
.online-msg[data-kind="error"] { color: var(--hot-2); }

.net-status {
  position: fixed; left: 50%; top: max(10px, env(safe-area-inset-top)); z-index: 25;
  transform: translateX(-50%);
  padding: 8px 16px; border: 0; border-radius: 999px;
  background: rgba(14, 16, 28, 0.94);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5), inset 0 0 0 2px var(--hot-2);
  font-weight: 800; font-size: 0.86rem;
  cursor: pointer;
}
.net-status[hidden] { display: none; }

.howto { color: var(--muted); font-size: 0.92rem; }
.howto summary { cursor: pointer; font-weight: 700; color: var(--text); list-style: none; display: flex; align-items: center; gap: 8px; }
.howto summary::-webkit-details-marker { display: none; }
.howto summary::before { content: "?"; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--panel-3); font-size: 0.8rem; }
.howto ol { padding-left: 20px; margin: 10px 0 6px; display: grid; gap: 6px; line-height: 1.4; }
.howto__tip { margin: 6px 0 0; font-size: 0.85rem; }

/* ───────────────────────── Game layout ───────────────────────── */
.game {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  gap: 10px;
}

/* Stacked (phones / portrait): scores, board and palette grouped and centred.
   The board's size is computed in JS from the space left over. */
.play {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; justify-content: center;
  gap: 10px;
}
.scoreboard { order: 1; }
.stage { order: 2; }
.controls { order: 3; }

/* Side-by-side (desktop / landscape tablets) */
@media (min-width: 600px) and (min-aspect-ratio: 1/1) {
  .game { padding: 18px 24px 24px; gap: 18px; }
  .play {
    display: grid;
    grid-template-columns: minmax(290px, 350px) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto auto minmax(0, 1fr);
    grid-template-areas: ". stage" "scores stage" "controls stage" ". stage";
    gap: 18px 28px;
  }
  .scoreboard { grid-area: scores; }
  .controls { grid-area: controls; }
  .stage { grid-area: stage; }
}

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.topbar__title { display: grid; justify-items: center; line-height: 1.15; }
.topbar__round { font-weight: 900; font-size: 1.05rem; letter-spacing: 0.02em; }
.topbar__meta { font-size: 0.75rem; color: var(--muted); font-weight: 600; }
.topbar__actions { display: flex; gap: 8px; }
.icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 42px; min-width: 42px; padding: 0 12px;
  border: 0; border-radius: 13px;
  background: var(--panel);
  box-shadow: inset 0 0 0 1px var(--line), inset 0 -3px 0 rgba(0, 0, 0, 0.25);
  font-weight: 800; font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.12s;
}
.icon-btn:hover { background: var(--panel-2); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
#btn-symbols svg { fill: currentColor; stroke: none; }
.icon-btn[aria-pressed="true"] { background: #2b3150; box-shadow: inset 0 0 0 2px var(--accent); color: var(--accent); }
@media (max-width: 420px) { .icon-btn__text { display: none; } .icon-btn { padding: 0 10px; } }

/* Scoreboard */
.scoreboard {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(var(--n, 2), minmax(0, 1fr)); gap: 8px;
}
.pcard {
  --pc: #888;
  position: relative;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px;
  padding: 8px 10px 12px;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: inset 0 0 0 1px var(--line);
  transition: transform 0.25s var(--ease-pop), box-shadow 0.25s, opacity 0.3s, background 0.25s;
  overflow: hidden;
}
.pcard__badge {
  width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--pc);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.22);
  transition: background 0.3s;
}
.pcard__badge svg { width: 15px; height: 15px; fill: #fff; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35)); }
.pcard__name { font-weight: 800; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard__name .short { display: none; }
.pcard__tiles { display: block; font-size: 0.72rem; color: var(--muted); font-weight: 600; }
.pcard__pct { font-weight: 900; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.pcard__bar { position: absolute; left: 10px; right: 10px; bottom: 5px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.07); overflow: hidden; }
.pcard__bar i { display: block; height: 100%; width: 0; background: var(--pc); border-radius: inherit; transition: width 0.45s cubic-bezier(0.2, 0.8, 0.2, 1), background 0.3s; }
.pcard__tag {
  display: none;
  font-size: 0.62rem; font-weight: 900; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted);
}
.pcard.is-active {
  background: linear-gradient(180deg, color-mix(in srgb, var(--pc) 18%, var(--panel)), var(--panel));
  box-shadow: inset 0 0 0 2px var(--pc), 0 8px 24px color-mix(in srgb, var(--pc) 28%, transparent);
  transform: translateY(-2px);
}
.pcard.is-sealed { opacity: 0.55; }
.pcard.is-sealed .pcard__tag { display: block; }
.pcard.is-sealed .pcard__tiles { display: none; }
.pcard__ai {
  margin-left: 6px; padding: 1px 5px; border-radius: 6px;
  background: var(--panel-3); color: var(--muted);
  font-size: 0.6rem; font-weight: 900; letter-spacing: 0.08em; vertical-align: 2px;
}
.pcard.bump .pcard__pct { animation: bump 0.4s var(--ease-pop); }

@media (max-width: 599px), (max-aspect-ratio: 1/1) {
  .scoreboard.is-crowded { gap: 6px; }
  .scoreboard.is-crowded .pcard { grid-template-columns: auto 1fr; padding: 7px 8px 11px; gap: 6px; }
  .scoreboard.is-crowded .pcard__name { display: none; }
  .scoreboard.is-crowded .pcard__pct { justify-self: end; font-size: 1rem; }
  .pcard__badge { width: 26px; height: 26px; border-radius: 8px; }
  .pcard__badge svg { width: 13px; height: 13px; }
}
@media (min-width: 600px) and (min-aspect-ratio: 1/1) {
  .scoreboard { grid-template-columns: 1fr; gap: 10px; }
  .pcard { padding: 12px 14px 16px; gap: 12px; border-radius: 16px; }
  .pcard__badge { width: 40px; height: 40px; border-radius: 12px; }
  .pcard__badge svg { width: 20px; height: 20px; }
  .pcard__name { font-size: 1rem; }
  .pcard__tiles { font-size: 0.8rem; }
  .pcard__pct { font-size: 1.4rem; }
  .pcard__bar { left: 14px; right: 14px; bottom: 7px; }
  .pcard.is-active { transform: translateX(6px); }
}

/* Controls: prompt + palette */
.controls {
  display: grid; gap: 10px;
  padding: 12px;
  border-radius: 20px;
  background: var(--panel);
  box-shadow: inset 0 0 0 1px var(--line);
}
.prompt { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.prompt__badge {
  --pc: #888;
  flex: none; width: 38px; height: 38px; border-radius: 11px;
  display: grid; place-items: center;
  background: var(--pc);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.22), 0 4px 14px color-mix(in srgb, var(--pc) 45%, transparent);
  transition: background 0.3s;
}
.prompt__badge svg { width: 18px; height: 18px; fill: #fff; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35)); }
.prompt__text { display: grid; line-height: 1.2; min-width: 0; }
.prompt__text strong { font-size: 1.05rem; font-weight: 900; }
#prompt-hint { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.prompt.is-new .prompt__badge { animation: pop 0.45s var(--ease-pop); }
.prompt.is-regroup #prompt-hint { color: var(--accent); }
.prompt__timer {
  margin-left: auto; flex: none;
  min-width: 52px; padding: 6px 10px; border-radius: 10px;
  background: var(--panel-2);
  font-weight: 900; font-size: 1rem; font-variant-numeric: tabular-nums; text-align: center;
}
.prompt__timer[hidden] { display: none; }
.prompt__timer.is-low { color: #fff; background: var(--hot-2); animation: pop 0.4s var(--ease-pop); }

.palette {
  display: grid;
  grid-template-columns: repeat(var(--k, 6), minmax(0, 1fr));
  gap: 8px;
}
@media (min-width: 600px) and (min-aspect-ratio: 1/1) {
  .palette { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
}

.swatch {
  --c: #888;
  position: relative;
  aspect-ratio: 1;
  max-height: 76px;
  border: 0; border-radius: 16px;
  background: var(--c);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.25), 0 6px 14px rgba(0, 0, 0, 0.3);
  display: grid; place-items: center;
  cursor: pointer;
  transition: transform 0.15s var(--ease-pop), filter 0.2s, opacity 0.2s, box-shadow 0.2s;
}
.swatch__glyph { width: 34%; height: 34%; fill: rgba(10, 12, 24, 0.38); }
.swatch__gain {
  position: absolute; top: -7px; right: -5px;
  min-width: 28px; padding: 2px 7px;
  border-radius: 999px;
  background: #fff; color: #11131f;
  font-size: 0.78rem; font-weight: 900; font-variant-numeric: tabular-nums;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
}
.swatch__lock {
  position: absolute; inset: 0; display: grid; place-items: center;
}
.swatch__lock svg { width: 40%; height: 40%; fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; opacity: 0.9; }
.swatch:enabled:hover { transform: translateY(-3px); filter: brightness(1.08); }
.swatch:enabled:active { transform: scale(0.9); }
.swatch:disabled { cursor: default; opacity: 0.22; filter: saturate(0.5); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25); }
.swatch.is-blocked:disabled { opacity: 0.45; }
.swatch.is-current:disabled {
  filter: none; opacity: 1;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.9), inset 0 0 0 6px rgba(0, 0, 0, 0.25);
}
.swatch.is-current .swatch__glyph { display: none; }
.swatch__you { font-size: 0.66rem; font-weight: 900; letter-spacing: 0.06em; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); }
.swatch.is-blocked .swatch__glyph { display: none; }
.swatch.is-picked { animation: picked 0.35s var(--ease-pop); }
.palette.is-busy .swatch:enabled { pointer-events: none; }
.palette.is-offline { opacity: 0.45; filter: saturate(0.6); transition: opacity 0.2s, filter 0.2s; }
.swatch.is-bot-pick { transform: translateY(-3px); box-shadow: 0 0 0 3px #fff, 0 6px 18px rgba(0, 0, 0, 0.4); }

@media (max-width: 380px) {
  .palette { gap: 6px; }
  .swatch { border-radius: 12px; }
  .swatch__gain { font-size: 0.7rem; min-width: 24px; padding: 1px 5px; }
}

/* Stage + board */
.stage { display: grid; place-items: center; min-height: 0; min-width: 0; position: relative; }
.board {
  position: relative;
  padding: 8px; border-radius: 20px;
  background: var(--board);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55), inset 0 0 0 1px var(--line);
}
.board.is-entering { animation: board-in 0.45s var(--ease-pop); }
#board-canvas { display: block; cursor: pointer; touch-action: manipulation; }

.banner {
  position: absolute; left: 50%; top: 0;
  transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 10px;
  padding: 12px 22px 12px 14px;
  border-radius: 999px;
  background: rgba(14, 16, 28, 0.88);
  backdrop-filter: blur(6px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5), inset 0 0 0 2px var(--pc, #fff);
  font-weight: 900; font-size: 1.15rem; white-space: nowrap;
  pointer-events: none;
  opacity: 0;
}
.banner .prompt__badge { width: 32px; height: 32px; }
@media (max-width: 520px) { .banner { font-size: 0.95rem; padding: 8px 16px 8px 10px; } .banner .prompt__badge { width: 26px; height: 26px; } }
.banner.is-showing { animation: banner 1s ease both; }

.toast {
  position: absolute; left: 50%; bottom: 18px;
  transform: translate(-50%, 10px);
  max-width: calc(100% - 32px);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(14, 16, 28, 0.92);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5), inset 0 0 0 1px var(--line);
  font-weight: 700; font-size: 0.88rem; text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.is-showing { opacity: 1; transform: translate(-50%, 0); }

/* ───────────────────────── Overlays ───────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  padding: 16px;
  background: rgba(6, 8, 14, 0.5);
  backdrop-filter: blur(1.5px);
  animation: fade 0.3s ease both;
}
.overlay[hidden], .icon-btn[hidden], .btn[hidden] { display: none; }
.end-card, .confirm-card {
  width: min(440px, 100%);
  max-height: 100%; overflow: auto;
  padding: 26px 22px 22px;
  border-radius: 28px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), inset 0 0 0 1px var(--line);
  text-align: center;
  animation: card-in 0.5s var(--ease-pop) both;
}
.end-card__emblem {
  --pc: var(--accent);
  width: 84px; height: 84px; margin: -4px auto 10px;
  border-radius: 24px;
  display: grid; place-items: center;
  background: var(--pc);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.22), 0 12px 34px color-mix(in srgb, var(--pc) 55%, transparent);
  animation: trophy 0.7s var(--ease-pop) 0.15s both;
}
.end-card__emblem svg { width: 42px; height: 42px; fill: #fff; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.3)); }
.end-card__emblem.is-draw { gap: 4px; grid-auto-flow: column; width: auto; padding: 0 18px; display: inline-grid; }
.end-card__emblem.is-draw svg { width: 30px; height: 30px; }
.end-card__title { margin: 0; font-size: 2rem; font-weight: 900; letter-spacing: -0.01em; }
.end-card__sub { margin: 6px 0 18px; color: var(--muted); font-weight: 600; }
.standings { list-style: none; padding: 0; margin: 0 0 22px; display: grid; gap: 8px; text-align: left; }
.standing {
  --pc: #888;
  position: relative; overflow: hidden;
  display: grid; grid-template-columns: 22px auto 1fr auto; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--bg-2);
  animation: row-in 0.4s ease both;
}
.standing__fill {
  position: absolute; inset: 0 auto 0 0; width: 0;
  background: color-mix(in srgb, var(--pc) 26%, transparent);
  transition: width 0.9s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.standing > :not(.standing__fill) { position: relative; }
.standing__rank { font-weight: 900; color: var(--muted); }
.standing__badge { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; background: var(--pc); }
.standing__badge svg { width: 14px; height: 14px; fill: #fff; }
.standing__name { font-weight: 800; }
.standing__score { font-weight: 900; font-variant-numeric: tabular-nums; text-align: right; }
.standing__score small { display: block; color: var(--muted); font-weight: 600; font-size: 0.72rem; }
.standing.is-winner { box-shadow: inset 0 0 0 2px var(--pc); }

.end-card__actions { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; }
.end-card__actions:has(> .btn[hidden]) { grid-template-columns: 1fr; }
.btn {
  min-height: 54px; border: 0; border-radius: 16px;
  background: var(--panel-3);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.25);
  font-weight: 900; font-size: 1rem; letter-spacing: 0.06em;
  cursor: pointer;
  transition: transform 0.12s, filter 0.15s;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: scale(0.96); }
.btn--primary { background: linear-gradient(135deg, var(--hot-1), var(--hot-2)); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.2), 0 10px 24px rgba(255, 61, 110, 0.3); }
.confirm-card__title { margin: 0 0 6px; font-size: 1.4rem; font-weight: 900; }
.confirm-card__sub { margin: 0 0 20px; color: var(--muted); }
.confirm-card .end-card__actions { grid-template-columns: 1fr 1fr; }

/* Short landscape screens (phones on their side) */
@media (min-width: 600px) and (min-aspect-ratio: 1/1) and (max-height: 600px) {
  .game { padding: max(8px, env(safe-area-inset-top)) 16px 10px; gap: 8px; }
  .icon-btn { min-height: 36px; min-width: 36px; }
  .play { grid-template-columns: minmax(240px, 300px) minmax(0, 1fr); gap: 8px 18px; }
  .scoreboard { grid-template-columns: 1fr 1fr; gap: 6px; }
  .pcard { padding: 6px 8px 10px; gap: 8px; }
  .pcard.is-active { transform: none; }
  .pcard__badge { width: 26px; height: 26px; border-radius: 8px; }
  .pcard__badge svg { width: 13px; height: 13px; }
  .pcard__name { font-size: 0.8rem; }
  .pcard__tiles { display: none; }
  .pcard__pct { font-size: 1rem; }
  .pcard__bar { left: 8px; right: 8px; bottom: 4px; }
  .controls { padding: 10px; gap: 8px; }
  .prompt { min-height: 0; }
  .prompt__badge { width: 30px; height: 30px; }
  .prompt__text strong { font-size: 0.95rem; }
  #prompt-hint { font-size: 0.74rem; }
  .palette { gap: 6px; }
  .swatch { max-height: 50px; aspect-ratio: auto; height: 50px; border-radius: 12px; }
}

.fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 30; }

/* ───────────────────────── Keyframes ───────────────────────── */
@keyframes tile-in { from { transform: translateY(-14px) scale(0.6) rotate(-12deg); opacity: 0; } }
@keyframes shine { 0%, 60% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }
@keyframes bump { 40% { transform: scale(1.25); } }
@keyframes pop { 0% { transform: scale(0.6); } 100% { transform: scale(1); } }
@keyframes picked { 0% { transform: scale(0.85); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes board-in { from { transform: scale(0.94); opacity: 0; } }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -20%) scale(0.85); }
  16%, 72% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(0.96); }
}
@keyframes fade { from { opacity: 0; } }
@keyframes card-in { from { transform: translateY(24px) scale(0.92); opacity: 0; } }
@keyframes trophy { from { transform: scale(0.2) rotate(-25deg); } }
@keyframes row-in { from { transform: translateX(-12px); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
