/* ============================================================
   DROP FOUR
   After-hours arcade: a smoked-graphite cabinet in a dark room,
   lit by whichever player is holding the next disc.
   ============================================================ */

/* ---------- tokens ---------- */
:root {
  --bg:        #08070c;
  --bg-lift:   #100e18;
  --ink:       #f4f0fa;
  --ink-dim:   #9c95ad;
  --ink-faint: #8b84a0;
  --line:      rgba(255, 255, 255, .09);
  --line-lit:  rgba(255, 255, 255, .16);
  --glass:     rgba(255, 255, 255, .045);
  --glass-lit: rgba(255, 255, 255, .08);

  /* players */
  --p1:      #ff5a36;  --p1-lit: #ffc4a4;  --p1-deep: #641402;  --p1-ink: #240702;
  --p2:      #2fd3f5;  --p2-lit: #c2f2ff;  --p2-deep: #04455c;  --p2-ink: #00202b;

  /* cabinet */
  --slab-hi:  #2a283a;
  --slab-lo:  #14131e;
  --cavity-1: #0c0b16;
  --cavity-2: #04030a;

  --font-display: 'Syne', 'Trebuchet MS', system-ui, sans-serif;
  --font-ui:      'Chivo', 'Helvetica Neue', system-ui, sans-serif;
  --font-mono:    'Chivo Mono', ui-monospace, 'SF Mono', monospace;

  --r-md: 16px;
  --r-lg: 26px;

  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-in-out: cubic-bezier(.65, 0, .35, 1);
}

:root,
:root[data-turn="1"] { --accent: var(--p1); --accent-lit: var(--p1-lit); --accent-deep: var(--p1-deep); --accent-ink: var(--p1-ink); }
:root[data-turn="2"] { --accent: var(--p2); --accent-lit: var(--p2-lit); --accent-deep: var(--p2-deep); --accent-ink: var(--p2-ink); }

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }

/* our components set display, which would otherwise defeat [hidden] */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  overflow: hidden;
  /* Static: the player-coloured light lives on the .atmos layers below, where
     it can cross-fade with opacity instead of repainting the whole viewport. */
  background:
    radial-gradient(90% 60% at 50% 115%, #15111d, transparent 70%),
    var(--bg);
}

button, input { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }

svg {
  width: 1.15em; height: 1.15em;
  fill: none; stroke: currentColor;
  stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
  flex: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* ---------- atmosphere ---------- */
.atmos { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }

/*
 * Two soft washes of player light. Deliberately gradients rather than blurred
 * circles: a `filter: blur()` layer has to be re-rasterised whenever it moves or
 * scales, which is a permanent GPU tax for something nobody can see moving.
 * Only their opacity changes, and only when the turn does.
 */
.atmos__blob {
  position: absolute; inset: 0;
  opacity: .05;
  transition: opacity 900ms var(--ease-in-out);
}
.atmos__blob--1 {
  background:
    radial-gradient(58vmax 52vmax at 8% -12%, var(--p1), transparent 68%),
    radial-gradient(72vmax 44vmax at 62% -16%, var(--p1), transparent 62%);
}
.atmos__blob--2 {
  background:
    radial-gradient(58vmax 52vmax at 94% 112%, var(--p2), transparent 68%),
    radial-gradient(72vmax 44vmax at 38% 116%, var(--p2), transparent 62%);
}
:root[data-turn="1"] .atmos__blob--1 { opacity: .3; }
:root[data-turn="1"] .atmos__blob--2 { opacity: .07; }
:root[data-turn="2"] .atmos__blob--2 { opacity: .3; }
:root[data-turn="2"] .atmos__blob--1 { opacity: .07; }

/* film grain — keeps the flat darks from banding.
   Plain alpha, not a blend mode: a full-viewport blended layer has to be
   re-composited by the GPU on every frame any animation produces. */
.grain {
  position: fixed; inset: 0;
  z-index: 1; pointer-events: none;
  opacity: .055;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.42'/%3E%3C/svg%3E");
}

/* ============================================================
   app shell
   ============================================================ */
.app {
  position: relative;
  z-index: 2;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "top" "players" "stage" "act";
  gap: clamp(6px, 1.4vh, 14px);
  padding:
    max(env(safe-area-inset-top), 10px)
    max(env(safe-area-inset-right), 12px)
    max(env(safe-area-inset-bottom), 10px)
    max(env(safe-area-inset-left), 12px);
}

/* ---------- top bar ---------- */
.topbar {
  grid-area: top;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem;
}
.topbar__tools { display: flex; gap: 6px; }

.icon-btn {
  width: 40px; height: 40px;
  display: inline-grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--glass);
  color: var(--ink-dim);
  cursor: pointer;
  transition: color .2s, background .2s, border-color .2s, transform .12s;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { color: var(--ink); background: var(--glass-lit); border-color: var(--line-lit); }
.icon-btn:active { transform: scale(.94); }

#btn-sound .i-sound-off { display: none; }
#btn-sound[aria-pressed="false"] .i-sound-on { display: none; }
#btn-sound[aria-pressed="false"] .i-sound-off { display: block; }
#btn-sound path:first-child { fill: currentColor; stroke-linejoin: miter; }
#btn-sound .wave { opacity: .9; }
#btn-sound .wave--2 { opacity: .5; }

/* ---------- wordmark ---------- */
.wordmark {
  display: flex; align-items: baseline; flex-wrap: nowrap;
  white-space: nowrap;
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -.03em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--ink);
  line-height: .86;
}
.wordmark__four { color: var(--accent); transition: color .5s var(--ease-in-out); }
.wordmark__disc {
  display: inline-block;
  width: .58em; height: .58em;
  margin: 0 .04em;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, var(--accent-lit), var(--accent) 52%, var(--accent-deep));
  box-shadow: 0 0 .7em -.1em var(--accent);
  transform: translateY(.02em);
  transition: background .5s var(--ease-in-out), box-shadow .5s var(--ease-in-out);
}
.wordmark--sm { font-size: clamp(15px, 4.4vw, 19px); gap: .38em; }
.wordmark--sm:hover { opacity: .85; }
.wordmark--xl {
  flex-direction: column; align-items: flex-start;
  gap: .02em; margin: 0;
  font-size: clamp(58px, 18vw, 118px);
}

/* ---------- scoreboard cards ---------- */
.players {
  grid-area: players;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.card {
  --c: var(--p1); --c-lit: var(--p1-lit); --c-deep: var(--p1-deep);
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "chip name score" "turn turn score";
  align-items: center;
  gap: 2px 8px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: linear-gradient(180deg, rgba(255, 255, 255, .05), rgba(255, 255, 255, .015));
  overflow: hidden;
  transition: border-color .35s, box-shadow .35s, background .35s, opacity .35s;
}
.card--2 { --c: var(--p2); --c-lit: var(--p2-lit); --c-deep: var(--p2-deep); }
.card::before { /* active wash */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(105deg, color-mix(in srgb, var(--c) 22%, transparent), transparent 62%);
  opacity: 0; transition: opacity .4s var(--ease-in-out);
}
.card > * { position: relative; }

.card.is-active {
  border-color: rgba(255, 255, 255, .32);
  border-color: color-mix(in srgb, var(--c) 55%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--c) 30%, transparent),
              0 8px 30px -14px var(--c);
}
.card.is-active::before { opacity: 1; }
.card:not(.is-active) { opacity: .62; }

.card__chip {
  position: relative;
  grid-area: chip;
  width: 15px; height: 15px; border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, var(--c-lit), var(--c) 55%, var(--c-deep));
  box-shadow: 0 0 8px -1px var(--c), inset 0 -1px 2px rgba(0, 0, 0, .45);
}
/* The pulse fades a separate glow rather than animating box-shadow, which would
   repaint the card on every frame for the whole game. */
.card__chip::after {
  content: "";
  position: absolute; inset: -2px;
  border-radius: 50%;
  box-shadow: 0 0 14px 1px var(--c);
  opacity: 0;
  transition: opacity .4s var(--ease-in-out);
}
/* Two beats when the turn arrives, then it holds. An endless pulse would keep
   the compositor busy for the whole game to say something already said. */
.card.is-active .card__chip::after {
  opacity: .45;
  animation: chipPulse 1.05s var(--ease-in-out) 2;
}
@keyframes chipPulse {
  0%   { opacity: .2; }
  45%  { opacity: 1; }
  100% { opacity: .45; }
}

.card__name {
  grid-area: name;
  min-width: 0; width: 100%;
  padding: 2px 4px; margin-left: -4px;
  border: 0; border-radius: 6px;
  background: transparent;
  font-family: var(--font-display);
  font-weight: 700; font-size: clamp(14px, 4vw, 17px);
  letter-spacing: -.01em;
  text-overflow: ellipsis;
  transition: background .2s;
}
.card__name:hover { background: var(--glass); }
.card__name:focus { background: rgba(0, 0, 0, .35); outline: 1px solid var(--line-lit); }
.card__name:read-only { pointer-events: none; }

.card__score {
  grid-area: score;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(22px, 6.6vw, 30px);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--c);
  text-shadow: 0 0 22px color-mix(in srgb, var(--c) 45%, transparent);
}
.card__score.is-bump { animation: scoreBump .5s var(--ease-out); }
@keyframes scoreBump {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.35); }
  100% { transform: scale(1); }
}

.card__turn {
  grid-area: turn;
  font-size: 10px; font-weight: 600;
  letter-spacing: .16em; text-transform: uppercase;
  color: color-mix(in srgb, var(--c) 75%, var(--ink));
  opacity: 0; transform: translateY(-2px);
  transition: opacity .3s, transform .3s;
}
.card__turn { display: flex; align-items: baseline; gap: .5em; }
.card.is-active .card__turn { opacity: 1; transform: none; }

/* ---------- turn clock ---------- */
.card__clock {
  font-family: var(--font-mono);
  font-size: 11px; font-weight: 700;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  color: var(--c);
}
.card__clock[hidden] { display: none; }

/* Depleting bar along the card's bottom edge, stepped from JS four times a
   second. Deliberately *no* transition: interpolating between steps keeps the
   compositor busy for the whole turn (measured 11% of a core while a player just
   thinks, versus 0% stepping), and at 4Hz a 30s clock moves under 1% per step,
   so there is nothing to smooth. */
.card__bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 3px;
  border-radius: 0 3px 3px 0;
  background: rgba(255, 255, 255, .7);
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--c) 55%, transparent), var(--c));
  transform: scaleX(var(--t, 0));
  transform-origin: 0 50%;
  opacity: 0;
}
.card.is-active .card__bar { opacity: .95; }

/* Last three seconds. The danger colour is its own red, not a player colour —
   coral would be invisible as a warning on Ember's own card. */
.card.is-urgent { border-color: #ff3b2f; }
.card.is-urgent .card__clock { color: #fff; }
.card.is-urgent .card__bar {
  background: #fff;
  box-shadow: 0 0 12px 1px #ff3b2f;
}
.card.is-beat .card__clock { animation: clockBeat 320ms var(--ease-out); }
@keyframes clockBeat {
  0%   { transform: scale(1); }
  36%  { transform: scale(1.42); }
  100% { transform: scale(1); }
}
/* the computer's difficulty stays on show even when it is not its turn */
.card.is-cpu:not(.is-active) .card__turn { opacity: .8; transform: none; color: var(--ink-faint); }

/* ============================================================
   the cabinet
   ============================================================ */
.stage {
  grid-area: stage;
  min-height: 0; min-width: 0;
  display: grid; place-items: center;
}

.board {
  --cols: 7;
  --rows: 6;
  --cell: 44px;
  --gap: 7px;
  --pitch: calc(var(--cell) + var(--gap));
  --hole-r: calc(var(--cell) / 2);

  /* one tile per cell: circle centred, so a single element can be punched */
  --mask-hole:     radial-gradient(circle at center, #000 calc(var(--hole-r) - .6px), transparent var(--hole-r));
  --mask-panel:    radial-gradient(circle at center, transparent calc(var(--hole-r) - .6px), #000 var(--hole-r));
  --tile-size:     var(--pitch) var(--pitch);
  --tile-origin:   calc(var(--gap) / 2) calc(var(--gap) / 2);

  position: relative;
  width: calc(var(--cols) * var(--pitch) + var(--gap));
  will-change: transform;
}
.board.is-shaking { animation: shake .5s var(--ease-in-out); }
@keyframes shake {
  0%, 100% { transform: translate3d(0, 0, 0); }
  15% { transform: translate3d(-5px, 2px, 0) rotate(-.35deg); }
  35% { transform: translate3d(4px, -2px, 0) rotate(.3deg); }
  55% { transform: translate3d(-3px, 1px, 0) rotate(-.2deg); }
  78% { transform: translate3d(2px, 0, 0); }
}

/* the disc waiting in your hand */
.chute { position: relative; height: var(--pitch); }
/* Two elements on purpose: the outer one slides between columns, the inner one
   bobs. Both are transform-only, so the idle bob never touches layout or paint. */
.ready {
  position: absolute; top: 0; left: 0;
  width: var(--cell); height: var(--cell);
  transform: translate3d(var(--rx, 0px), 0, 0);
  transition: transform .22s var(--ease-out), opacity .18s;
}
.ready::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, var(--accent-lit), var(--accent) 48%, var(--accent-deep));
  box-shadow:
    inset 0 calc(var(--cell) * -.05) calc(var(--cell) * .1) rgba(0, 0, 0, .5),
    inset 0 calc(var(--cell) * .04) calc(var(--cell) * .06) rgba(255, 255, 255, .28),
    0 calc(var(--cell) * .18) calc(var(--cell) * .3) -.35rem rgba(0, 0, 0, .7),
    0 0 calc(var(--cell) * .7) calc(var(--cell) * -.14) var(--accent);
}
/* One settle when the disc arrives in your hand, rather than an endless bob:
   the motion lands on the turn change, and idle costs nothing to composite. */
.ready:not(.is-hidden)::after { animation: readyIn 620ms var(--ease-out); }
.ready.is-hidden { opacity: 0; transition-duration: .06s; }
@keyframes readyIn {
  0%   { transform: translateY(calc(var(--cell) * -.5)) scale(.86); }
  55%  { transform: translateY(calc(var(--cell) * .04)) scale(1.02); }
  78%  { transform: translateY(calc(var(--cell) * -.05)); }
  100% { transform: translateY(0); }
}

.grid {
  position: relative;
  height: calc(var(--rows) * var(--pitch) + var(--gap));
  isolation: isolate;
}
/* unmasked twin of the panel: carries the shadow, glow and rim */
.grid::before {
  content: "";
  position: absolute; inset: 0;
  border-radius: var(--r-lg);
  background: linear-gradient(168deg, var(--slab-hi), var(--slab-lo) 62%, #0c0b12);
  box-shadow:
    0 2px 0 rgba(255, 255, 255, .05) inset,
    0 30px 60px -24px rgba(0, 0, 0, .95),
    0 6px 18px -8px rgba(0, 0, 0, .8),
    0 0 90px -26px var(--accent);
  transition: box-shadow .6s var(--ease-in-out);
}

.layer { position: absolute; inset: 0; pointer-events: none; }

/* recessed sockets, seen through the punched panel */
.cavity {
  background-image: radial-gradient(circle at 50% 34%, var(--cavity-1), var(--cavity-2) 72%);
  background-size: var(--tile-size);
  background-position: var(--tile-origin);
  background-repeat: repeat;
  -webkit-mask-image: var(--mask-hole); mask-image: var(--mask-hole);
  -webkit-mask-size: var(--tile-size); mask-size: var(--tile-size);
  -webkit-mask-position: var(--tile-origin); mask-position: var(--tile-origin);
  -webkit-mask-repeat: repeat; mask-repeat: repeat;
}

.discs { z-index: 1; }
/* only while emptying the board, so discs vanish into the cabinet */
.discs.is-clipping { overflow: hidden; }

/* the panel's shadow falling on whatever sits in the socket */
.holeshade {
  z-index: 2;
  background-image: radial-gradient(circle at 50% 42%,
    transparent 52%, rgba(0, 0, 0, .3) 82%, rgba(0, 0, 0, .62) 100%);
  background-size: var(--tile-size);
  background-position: var(--tile-origin);
  background-repeat: repeat;
  -webkit-mask-image: var(--mask-hole); mask-image: var(--mask-hole);
  -webkit-mask-size: var(--tile-size); mask-size: var(--tile-size);
  -webkit-mask-position: var(--tile-origin); mask-position: var(--tile-origin);
  -webkit-mask-repeat: repeat; mask-repeat: repeat;
}

/* the front panel: same fill as ::before, with 42 holes punched out */
.slab {
  z-index: 3;
  border-radius: var(--r-lg);
  background: linear-gradient(168deg, var(--slab-hi), var(--slab-lo) 62%, #0c0b12);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .07),
    inset 0 0 0 1px rgba(255, 255, 255, .04),
    inset 0 -14px 30px -18px rgba(0, 0, 0, .9);
  -webkit-mask-image: var(--mask-panel); mask-image: var(--mask-panel);
  -webkit-mask-size: var(--tile-size); mask-size: var(--tile-size);
  -webkit-mask-position: var(--tile-origin); mask-position: var(--tile-origin);
  -webkit-mask-repeat: repeat; mask-repeat: repeat;
}

.fx { z-index: 4; overflow: hidden; border-radius: var(--r-lg); }

/* ---------- discs ---------- */
.disc {
  --c: var(--p1); --c-lit: var(--p1-lit); --c-deep: var(--p1-deep);
  position: absolute; top: 0; left: 0;
  width: var(--cell); height: var(--cell);
  border-radius: 50%;
  background: radial-gradient(circle at 34% 27%, var(--c-lit), var(--c) 46%, var(--c-deep) 100%);
  box-shadow:
    inset 0 calc(var(--cell) * -.06) calc(var(--cell) * .12) rgba(0, 0, 0, .55),
    inset 0 calc(var(--cell) * .05) calc(var(--cell) * .07) rgba(255, 255, 255, .3),
    0 0 calc(var(--cell) * .55) calc(var(--cell) * -.16) var(--c);
  /* translate3d, not translate: this gives every resting disc its own
     compositor layer, so adding a disc does not dirty the others. Measured on a
     120Hz panel at dpr 3, a move every 1.4s: 3D ~32% of a core, 2D ~55%, because
     with one shared layer each new disc re-rasterises the whole board. Adding
     will-change on top measured no better (~36%) — these are already promoted. */
  transform: translate3d(calc(var(--gap) + var(--col) * var(--pitch)),
                         calc(var(--gap) + var(--vrow) * var(--pitch)), 0);
  transition: filter .5s var(--ease-in-out);
}
.disc[data-p="2"] { --c: var(--p2); --c-lit: var(--p2-lit); --c-deep: var(--p2-deep); }

/* moulded ring — reads as plastic, not a flat circle */
.disc::after {
  content: "";
  position: absolute; inset: 16%;
  border-radius: 50%;
  box-shadow:
    inset 0 0 0 max(1px, calc(var(--cell) * .022)) rgba(0, 0, 0, .18),
    inset 0 max(1px, calc(var(--cell) * .02)) 0 rgba(255, 255, 255, .16);
}

/* optional colour-blind marks: solid pip vs open ring */
:root[data-marks="on"] .disc::before {
  content: "";
  position: absolute; inset: 34%;
  border-radius: 50%;
  background: rgba(0, 0, 0, .34);
}
:root[data-marks="on"] .disc[data-p="2"]::before {
  inset: 28%;
  background: none;
  border: max(2px, calc(var(--cell) * .045)) solid rgba(0, 0, 0, .34);
}

/* landing preview.
   Each pair is fallback-then-enhanced: color-mix() needs Safari 16.4+, and a
   dropped `background` here would leave the preview looking like a real disc. */
.disc--ghost {
  background: rgba(255, 255, 255, .13);
  background: color-mix(in srgb, var(--c) 24%, transparent);
  box-shadow: inset 0 0 0 max(2px, calc(var(--cell) * .045)) rgba(255, 255, 255, .5);
  box-shadow: inset 0 0 0 max(2px, calc(var(--cell) * .045)) color-mix(in srgb, var(--c) 70%, transparent);
  opacity: 0;
  transition: opacity .18s, transform .16s var(--ease-out);
}
.disc--ghost::after, .disc--ghost::before { display: none; }
.disc--ghost.is-on { opacity: 1; }

.disc.is-last::after { box-shadow: inset 0 0 0 max(1px, calc(var(--cell) * .03)) rgba(255, 255, 255, .5); }

/* resolved board: winners keep their light, the rest step back */
.discs.is-resolved .disc:not(.is-win) { filter: brightness(.5) saturate(.35); }
.disc.is-win { animation: winPop .6s var(--ease-out) both; }
.disc.is-win::after {
  box-shadow:
    inset 0 0 0 max(2px, calc(var(--cell) * .04)) rgba(255, 255, 255, .85),
    0 0 calc(var(--cell) * .5) var(--c);
  /* celebrate, then hold: looping would keep the compositor busy until restart */
  animation: winRing 1.5s ease-in-out 4 both;
}
@keyframes winPop {
  0%   { filter: brightness(1); }
  40%  { filter: brightness(1.7) saturate(1.2); }
  100% { filter: brightness(1.12); }
}
@keyframes winRing {
  0%, 100% { opacity: .55; }
  50%      { opacity: 1; }
}

/* ---------- fx: beam, shockwave, aim glow ---------- */
.beam {
  position: absolute;
  height: calc(var(--cell) * .17);
  border-radius: 99px;
  transform-origin: 0 50%;
  background: linear-gradient(90deg, transparent, #fff 12%, #fff 88%, transparent);
  box-shadow: 0 0 calc(var(--cell) * .5) rgba(255, 255, 255, .8);
  mix-blend-mode: plus-lighter;
  opacity: .9;
}
.wave {
  position: absolute;
  border-radius: 50%;
  border: 2px solid var(--accent);
  mix-blend-mode: plus-lighter;
  pointer-events: none;
}
.aim {
  position: absolute; top: 0;
  width: var(--cell);
  height: var(--ah, 100%);
  border-radius: 0 0 99px 99px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .03), rgba(255, 255, 255, .12));
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--accent) 4%, transparent),
    color-mix(in srgb, var(--accent) 15%, transparent));
  mix-blend-mode: plus-lighter;
  opacity: 0;
  transform: translate3d(var(--ax, 0px), 0, 0);
  transition: opacity .2s, transform .18s var(--ease-out), height .18s var(--ease-out);
}
.aim.is-on { opacity: 1; }

/* ---------- last-three-seconds countdown ---------- */
/* Sits above everything but never intercepts a tap, so you can still play out
   of trouble while the number is on screen. */
.countdown {
  z-index: 6;
  display: grid; place-items: center;
}
.countdown b {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: min(44vw, calc(var(--cell) * 3.6));
  line-height: 1;
  color: #fff;
  text-shadow:
    0 0 .14em var(--accent),
    0 0 .42em var(--accent),
    0 .03em .03em rgba(0, 0, 0, .55);
  opacity: 0;
}
.countdown.is-beat b { animation: countPop 900ms var(--ease-out); }
@keyframes countPop {
  0%   { opacity: 0;   transform: scale(1.85); }
  16%  { opacity: .88; transform: scale(1); }
  62%  { opacity: .5;  transform: scale(1); }
  100% { opacity: 0;   transform: scale(.94); }
}
/* reduced motion: hold the digit instead of animating it */
.countdown.is-static b { opacity: .8; }

/* the cabinet itself goes into the danger colour — one transition, no loop */
.board.is-urgent .grid::before {
  box-shadow:
    0 2px 0 rgba(255, 255, 255, .05) inset,
    0 30px 60px -24px rgba(0, 0, 0, .95),
    0 6px 18px -8px rgba(0, 0, 0, .8),
    0 0 100px -16px #ff2d1f;
}

/* ---------- column hit areas ---------- */
.cols { z-index: 5; display: flex; pointer-events: auto; }
.col {
  flex: 1 1 0;
  min-width: 0;
  border: 0; padding: 0; margin: 0;
  background: transparent;
  cursor: pointer;
  border-radius: calc(var(--r-lg) * .7);
  touch-action: none;
  -webkit-user-select: none; user-select: none;
}
.col:disabled { cursor: not-allowed; }
/* the aim beam and landing ghost are the hover affordance — no box needed */
.col:focus-visible { outline-offset: -4px; }

/* ---------- action bar ---------- */
.actions {
  grid-area: act;
  display: flex; justify-content: center; gap: 8px;
}
.actions .btn { flex: 1 1 0; max-width: 220px; }

/* ---------- buttons ---------- */
.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: .55em;
  min-height: 50px; padding: 0 1.15rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--glass);
  color: var(--ink);
  font-weight: 600; font-size: 13px;
  letter-spacing: .12em; text-transform: uppercase;
  cursor: pointer;
  transition: transform .12s var(--ease-out), background .2s, border-color .2s, box-shadow .25s, color .2s, opacity .2s;
}
.btn:hover:not(:disabled) { background: var(--glass-lit); border-color: var(--line-lit); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(.985); }
.btn:disabled { opacity: .3; cursor: default; }
.btn svg { width: 17px; height: 17px; }

.btn--primary {
  border-color: transparent;
  background: linear-gradient(175deg, var(--accent-lit), var(--accent) 62%);
  color: var(--accent-ink);
  box-shadow: 0 12px 34px -16px var(--accent), inset 0 1px 0 rgba(255, 255, 255, .55);
}
.btn--primary:focus-visible { outline-color: #fff; }
.btn--primary:hover:not(:disabled) {
  background: linear-gradient(175deg, #fff, var(--accent) 68%);
  box-shadow: 0 16px 40px -14px var(--accent), inset 0 1px 0 rgba(255, 255, 255, .6);
}

.link {
  border: 0; background: none; padding: 6px 2px;
  color: var(--ink-dim);
  font-size: 12px; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase;
  cursor: pointer;
  transition: color .2s;
}
.link:hover { color: var(--ink); }

/* ============================================================
   overlays: menu, settings, result
   ============================================================ */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: grid;
  background: rgba(8, 7, 12, .84);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: blur(18px) saturate(1.1);
  backdrop-filter: blur(18px) saturate(1.1);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.overlay[hidden] { display: none; }
.overlay.is-out { animation: overlayOut .32s var(--ease-in-out) both; }
@keyframes overlayOut { to { opacity: 0; transform: scale(1.02); visibility: hidden; } }

/* ---------- menu ---------- */
.menu {
  width: 100%; max-width: 480px;
  margin: auto;
  display: flex; flex-direction: column;
  gap: clamp(14px, 2.6vh, 22px);
  padding:
    calc(max(env(safe-area-inset-top), 16px) + 4vh) 22px
    calc(max(env(safe-area-inset-bottom), 16px) + 3vh);
}
.menu > * { animation: rise .6s var(--ease-out) both; }
.menu > *:nth-child(1) { animation-delay: .02s; }
.menu > *:nth-child(2) { animation-delay: .08s; }
.menu > *:nth-child(3) { animation-delay: .13s; }
.menu > *:nth-child(4) { animation-delay: .18s; }
.menu > *:nth-child(5) { animation-delay: .23s; }
.menu > *:nth-child(6) { animation-delay: .28s; }
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

.menu__head { display: flex; flex-direction: column; gap: 10px; }
.menu__tag {
  margin: 0;
  max-width: 24ch;
  color: var(--ink-dim);
  font-size: clamp(13px, 3.6vw, 15px);
  line-height: 1.45;
}

.btn--resume { justify-content: space-between; }
.btn--resume em {
  font-style: normal; font-family: var(--font-mono);
  font-size: 11px; letter-spacing: .06em;
  opacity: .7;
}

.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode {
  display: flex; flex-direction: column; gap: 4px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--glass);
  text-align: left;
  cursor: pointer;
  transition: border-color .25s, background .25s, box-shadow .25s, transform .12s;
}
.mode:hover { background: var(--glass-lit); }
.mode:active { transform: translateY(1px); }
.mode.is-on {
  border-color: rgba(255, 255, 255, .32);
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 9%, var(--glass));
  box-shadow: 0 10px 30px -18px var(--accent);
}
.mode__art { display: flex; gap: 5px; margin-bottom: 6px; }
.mode__art i {
  width: 15px; height: 15px; border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, var(--p1-lit), var(--p1) 55%, var(--p1-deep));
  box-shadow: 0 0 10px -2px var(--p1);
}
.mode__art i:last-child {
  background: radial-gradient(circle at 34% 28%, var(--p2-lit), var(--p2) 55%, var(--p2-deep));
  box-shadow: 0 0 10px -2px var(--p2);
}
.mode__art--cpu i:last-child {
  background: linear-gradient(140deg, #6d6880, #2c2937);
  box-shadow: none;
  border: 1px solid var(--line-lit);
}
.mode__label {
  font-family: var(--font-display); font-weight: 700;
  font-size: 15px; letter-spacing: -.01em;
}
.mode__sub { font-size: 11.5px; color: var(--ink-dim); line-height: 1.3; }

.field { display: flex; flex-direction: column; gap: 8px; }
.field__label {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: .5em;
  font-size: 11px; font-weight: 700;
  letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-dim);
}
.field__label em {
  font-style: normal; font-size: 10.5px; font-weight: 400;
  letter-spacing: .04em; text-transform: none;
  color: var(--ink-faint);
}

.levels { display: flex; gap: 8px; }
.levels[hidden] { display: none; }
.pill {
  flex: 1;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--glass);
  color: var(--ink-dim);
  font-size: 12px; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase;
  cursor: pointer;
  transition: color .2s, background .2s, border-color .2s;
}
.pill:hover { color: var(--ink); }
.pill.is-on {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: transparent;
  box-shadow: 0 8px 24px -14px var(--accent);
}

.btn--start { min-height: 60px; font-size: 14px; }
.menu__foot { display: flex; justify-content: space-between; align-items: center; }

.how {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: rgba(0, 0, 0, .28);
  color: var(--ink-dim);
  font-size: 13px; line-height: 1.55;
  animation: rise .4s var(--ease-out) both;
}
.how[hidden] { display: none; }
.how p { margin: 0 0 10px; }
.how ul { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
.how b { color: var(--ink); font-weight: 600; }
.how kbd {
  display: inline-block;
  min-width: 20px; padding: 1px 5px; margin: 0 1px;
  border: 1px solid var(--line-lit); border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--glass);
  font-family: var(--font-mono); font-size: 11px;
  color: var(--ink);
}

/* ---------- settings sheet ---------- */
.overlay--sheet { align-items: end; }
@media (min-width: 620px) { .overlay--sheet { align-items: center; justify-items: center; } }

.sheet {
  width: 100%; max-width: 440px;
  display: flex; flex-direction: column;
  padding: 18px 20px calc(max(env(safe-area-inset-bottom), 14px) + 14px);
  border: 1px solid var(--line);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  background: linear-gradient(180deg, var(--bg-lift), var(--bg));
  box-shadow: 0 -30px 80px -30px #000;
  animation: sheetUp .38s var(--ease-out) both;
}
@media (min-width: 620px) {
  .sheet { border-radius: var(--r-lg); }
}
@keyframes sheetUp {
  from { opacity: 0; transform: translateY(26px); }
  to   { opacity: 1; transform: none; }
}
.sheet__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.sheet__head h2 {
  margin: 0;
  font-family: var(--font-display); font-weight: 700;
  font-size: 19px; letter-spacing: -.01em;
}
.sheet__foot { margin-top: 14px; }
.sheet__foot .btn { width: 100%; }

.row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  cursor: pointer;
}
.row[hidden] { display: none; }
.row span { display: flex; flex-direction: column; gap: 3px; }
.row em {
  font-style: normal; font-size: 11.5px; color: var(--ink-faint); line-height: 1.35;
}

.switch {
  appearance: none; -webkit-appearance: none;
  position: relative; flex: none;
  width: 48px; height: 28px; margin: 0;
  border: 1px solid var(--line-lit); border-radius: 99px;
  background: rgba(0, 0, 0, .5);
  cursor: pointer;
  transition: background .25s, border-color .25s;
}
.switch::after {
  content: "";
  position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--ink-dim);
  transition: transform .25s var(--ease-out), background .25s;
}
.switch:checked { background: var(--accent); border-color: transparent; }
.switch:checked::after { transform: translateX(20px); background: #fff; }

/* ---------- result sheet ---------- */
.result {
  position: fixed; z-index: 18;
  left: max(env(safe-area-inset-left), 12px);
  right: max(env(safe-area-inset-right), 12px);
  bottom: max(env(safe-area-inset-bottom), 12px);
  width: auto; max-width: 460px;
  margin-inline: auto;
  display: flex; flex-direction: column; gap: 4px;
  padding: 18px 20px 20px;
  border: 1px solid var(--line-lit);
  border: 1px solid color-mix(in srgb, var(--accent) 34%, var(--line));
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, var(--bg-lift), #0a0910);
  background:
    radial-gradient(120% 130% at 50% 0%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 62%),
    linear-gradient(180deg, var(--bg-lift), #0a0910);
  box-shadow: 0 30px 70px -24px #000, 0 0 60px -30px var(--accent);
  animation: sheetUp .42s var(--ease-out) both;
}
.result[hidden] { display: none; }
.result.is-out { animation: resultOut .28s var(--ease-in-out) both; }
@keyframes resultOut { to { opacity: 0; transform: translateY(18px); } }

.result__eyebrow {
  margin: 0;
  font-size: 10px; font-weight: 700;
  letter-spacing: .24em; text-transform: uppercase;
  color: var(--accent);
}
.result__title {
  margin: 2px 0 0;
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(21px, 6vw, 27px);
  letter-spacing: -.02em; line-height: 1.05;
}
.result__score {
  margin: 6px 0 14px;
  font-family: var(--font-mono); font-size: 13px;
  letter-spacing: .1em;
  color: var(--ink-dim);
}
.result__score span:first-child { color: var(--p1); }
.result__score span:last-child { color: var(--p2); }
.result__buttons { display: flex; gap: 8px; }
.result__buttons .btn { flex: 1; }
.result__buttons .btn--primary { flex: 1.6; }

/* ============================================================
   wide + landscape layouts
   ============================================================ */
@media (min-width: 900px) and (min-height: 640px) {
  .app {
    /* the middle track must be definite: the board is measured from it */
    grid-template-columns:
      minmax(190px, clamp(200px, 22vw, 300px))
      minmax(0, 1fr)
      minmax(190px, clamp(200px, 22vw, 300px));
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "top top top" "p1 stage p2" "act act act";
    gap: clamp(10px, 2vh, 20px) clamp(14px, 3vw, 40px);
    padding-inline: clamp(18px, 4vw, 54px);
  }
  .players { display: contents; }
  .card--1 { grid-area: p1; align-self: center; justify-self: end; }
  .card--2 { grid-area: p2; align-self: center; justify-self: start; }
  .card {
    width: 100%; max-width: 260px;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "chip name" "score score" "turn turn";
    gap: 4px 10px;
    padding: 18px 20px 16px;
    border-radius: var(--r-lg);
  }
  .card__score { font-size: 54px; margin-top: 4px; }
  .card__name { font-size: 19px; }
  .actions { padding-bottom: 6px; }
  .actions .btn { flex: 0 1 190px; }
  .result { bottom: 84px; }
}

/* short landscape (phones on their side): rail beside the board */
@media (orientation: landscape) and (max-height: 640px) {
  .app {
    grid-template-columns: minmax(150px, 25vw) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "top stage" "players stage" "act stage";
    gap: 8px 14px;
  }
  .players { grid-template-columns: 1fr; align-content: center; gap: 6px; }
  .card { padding: 7px 10px; }
  .card__score { font-size: 22px; }
  .actions { flex-direction: column; }
  .actions .btn { max-width: none; min-height: 42px; }
  .result {
    left: auto; right: 12px; bottom: 12px; max-width: 330px;
    padding: 14px 16px 16px;
  }
  .menu { max-width: 620px; }
  .topbar { gap: 6px; }
  .wordmark--sm { font-size: 13px; gap: .3em; }
  .wordmark--xl { font-size: clamp(44px, 9vh, 70px); }
  .menu__head { flex-direction: row; align-items: flex-end; justify-content: space-between; gap: 20px; }
}

/* ============================================================
   reduced motion
   ============================================================ */
:root[data-motion="off"] *,
:root[data-motion="off"] *::before,
:root[data-motion="off"] *::after {
  animation-duration: .001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .001ms !important;
}

/* ============================================================
   platform shell: name gate, lobby, waiting room, toasts
   ============================================================ */
.menu--narrow { max-width: 420px; }

.eyebrow {
  margin: 0;
  font-size: 10px; font-weight: 700;
  letter-spacing: .24em; text-transform: uppercase;
  color: var(--accent);
}
.waitline {
  margin: 4px 0 0;
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(24px, 7vw, 34px);
  letter-spacing: -.02em; line-height: 1.04;
}

/* ---------- the one field that starts everything ---------- */
.bigfield { display: flex; flex-direction: column; gap: 10px; }
.bigfield__label {
  font-size: 11px; font-weight: 700;
  letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink-dim);
}
.bigfield__input {
  width: 100%;
  padding: 18px 20px;
  border: 1px solid var(--line-lit);
  border-radius: var(--r-md);
  background: rgba(0, 0, 0, .35);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(20px, 6vw, 26px);
  letter-spacing: -.01em;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
.bigfield__input::placeholder { color: var(--ink-faint); font-weight: 400; }
.bigfield__input:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

/* ---------- three ways to play ---------- */
.modes--3 { grid-template-columns: 1fr 1fr; }
.mode--wide { grid-column: 1 / -1; }

/* ---------- share box ---------- */
.sharebox {
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: rgba(0, 0, 0, .3);
}
.sharebox__link {
  display: block;
  padding: 12px 14px;
  border-radius: var(--r-sm, 10px);
  background: rgba(0, 0, 0, .45);
  border: 1px dashed var(--line-lit);
  font-family: var(--font-mono); font-size: 13px;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.sharebox__row { display: flex; gap: 8px; }
.sharebox__row .btn { flex: 1; }
.sharebox__code {
  margin: 0;
  font-size: 12px; color: var(--ink-faint);
}
.sharebox__code b {
  font-family: var(--font-mono); font-size: 14px;
  color: var(--accent); letter-spacing: .04em;
}

.waitstatus {
  display: flex; align-items: center; gap: 10px;
  margin: 0;
  font-size: 13px; color: var(--ink-dim);
}
.waitstatus .dot {
  width: 9px; height: 9px; flex: none;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px 1px var(--accent);
  /* Bounded on purpose: ~64s of breathing, then it settles rather than
     animating forever while a lobby sits open. */
  animation: waitDot 1.6s ease-in-out 40;
}
@keyframes waitDot {
  0%, 100% { opacity: .25; }
  50%      { opacity: 1; }
}
.waitstatus.is-live .dot { animation: none; opacity: 1; }

/* ---------- room chip in the top bar ---------- */
.roomchip {
  display: inline-flex; align-items: center; gap: 7px;
  height: 40px; padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--glass);
  font-family: var(--font-mono); font-size: 12px;
  color: var(--ink-dim);
}
.roomchip[hidden] { display: none; }
.roomchip i {
  width: 7px; height: 7px; border-radius: 50%;
  background: #3ddc84;
  box-shadow: 0 0 8px 1px rgba(61, 220, 132, .8);
}
.roomchip.is-offline i { background: #ff6b5e; box-shadow: 0 0 8px 1px rgba(255, 107, 94, .7); }
.roomchip b { color: var(--ink); font-weight: 700; letter-spacing: .04em; }

/* ---------- toast ---------- */
.toast {
  position: fixed; z-index: 40;
  left: 50%; bottom: calc(max(env(safe-area-inset-bottom), 16px) + 12px);
  transform: translateX(-50%);
  padding: 12px 18px;
  border: 1px solid var(--line-lit);
  border-radius: 99px;
  background: rgba(20, 19, 30, .96);
  box-shadow: 0 12px 40px -12px #000;
  font-size: 13px; font-weight: 600;
  animation: toastIn .3s var(--ease-out);
}
.toast[hidden] { display: none; }
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

.link--inline {
  padding: 0; font-size: inherit; letter-spacing: 0;
  text-transform: none; text-decoration: underline;
  color: var(--ink-dim);
}
.menu__tag b { color: var(--ink); }

.result__note {
  margin: 0 0 12px;
  font-size: 12.5px; color: var(--ink-dim);
}
.result__note[hidden] { display: none; }

/* the seat that is not connected reads as absent */
.card.is-away { opacity: .38; }
.card.is-away .card__name { text-decoration: line-through .06em; text-decoration-color: var(--ink-faint); }
