/* wanparty shell styles (game-agnostic). Dark only. System fonts only; no images beyond inline SVG.
   Screens are driven by body[data-mode] (set by play.js: lobby | playing | ended; none on boot and the test harness pages)
   and by which of the sections (#connect #room #voice #play) are visible. */

/* ----------------------------------------------------------------------------------------------------------- tokens */
:root {
  color-scheme: dark;
  --bg: #0d0b14;
  --surface: #191627;
  --surface-2: #231f37;
  --surface-3: #2d2846;
  --stage: #000;
  --border: #353051;
  --border-strong: #6a628c;
  --text: #f3f0fa;
  --text-muted: #b4adc9;
  --text-faint: #8e87a6;
  --brand: #ff5fa8;
  --brand-2: #ff8a6b;
  --brand-hover: #ff7ab7;
  --brand-ink: #1a0712;
  --accent: #46e0d2;
  --ok: #5ee08a;
  --warn: #ffc65c;
  --danger: #ff7b7b;
  --danger-fill: #c2304a;
  --focus: var(--accent);
  --scrim: rgb(8 6 14 / 0.9);
  --glass: rgb(25 22 39 / 0.86);
  --slot-1: #ff5fa8;
  --slot-2: #46e0d2;
  --slot-3: #ffc65c;
  --slot-4: #a98bff;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --fs-xs: .8125rem; --fs-sm: .875rem; --fs-md: 1rem; --fs-lg: 1.25rem; --fs-xl: 1.75rem; --fs-xxl: 2.25rem;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --radius-sm: 10px; --radius: 14px; --radius-lg: 20px; --radius-pill: 999px;
  --shadow: 0 1px 0 rgb(255 255 255 / .04) inset, 0 18px 48px rgb(0 0 0 / .38);
  --tap: 44px;
  --bar-h: 56px;
  --rail-w: clamp(176px, 15vw, 248px);
  --dur: 160ms;
}

/* ------------------------------------------------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
  font: 400 1rem/1.5 var(--font); color: var(--text);
  background:
    radial-gradient(60rem 28rem at 50% -14rem, rgb(255 95 168 / .16), transparent 70%),
    radial-gradient(36rem 22rem at 100% 0, rgb(70 224 210 / .08), transparent 70%),
    radial-gradient(rgb(255 255 255 / .035) 1px, transparent 1px) 0 0 / 22px 22px,
    var(--bg);
  background-attachment: fixed;
}
h1, h2, h3, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
::selection { background: rgb(255 95 168 / .35); }
.sr-only { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: var(--s4); top: -100px; z-index: 100; padding: var(--s2) var(--s4); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); }
.skip-link:focus { top: var(--s4); }
main:focus { outline: none; }

/* ------------------------------------------------------------------------------------------------- header, footer */
.site-header {
  width: 100%; max-width: 1160px; margin: 0 auto; padding: var(--s5) var(--s5) var(--s4);
  display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: var(--s3); }
.brand-mark { display: block; width: 36px; height: 36px; flex: none; filter: drop-shadow(0 4px 14px rgb(255 95 168 / .25)); }
.wordmark { font-size: 1.75rem; font-weight: 800; letter-spacing: -.035em; line-height: 1; }
.wordmark span { color: var(--brand); }
.tagline { color: var(--text-muted); padding-left: var(--s4); border-left: 1px solid var(--border); line-height: 1.2; }
.site-footer { width: 100%; max-width: 46rem; margin: 0 auto; padding: var(--s5) var(--s5) var(--s6); text-align: center; color: var(--text-faint); font-size: var(--fs-sm); }

/* Landing and boot: the brand is the hero. */
body.is-landing .site-header, body[data-mode=ended] .site-header, body:not([data-mode]):not(.harness) .site-header {
  flex-direction: column; justify-content: center; text-align: center; gap: var(--s3); padding-top: clamp(32px, 9vh, 96px); padding-bottom: var(--s6);
}
body.is-landing .brand-mark, body[data-mode=ended] .brand-mark, body:not([data-mode]):not(.harness) .brand-mark { width: 64px; height: 64px; }
body.is-landing .brand, body[data-mode=ended] .brand, body:not([data-mode]):not(.harness) .brand { flex-direction: column; gap: var(--s4); }
body.is-landing .wordmark, body[data-mode=ended] .wordmark, body:not([data-mode]):not(.harness) .wordmark { font-size: clamp(2.75rem, 8vw, 4.25rem); }
body.is-landing .tagline, body[data-mode=ended] .tagline, body:not([data-mode]):not(.harness) .tagline { border: 0; padding: 0; font-size: clamp(1.05rem, 2.4vw, 1.3rem); }

/* --------------------------------------------------------------------------------------------------------- layout */
main {
  flex: 1; width: 100%; max-width: 40rem; margin: 0 auto; padding: 0 var(--s5) var(--s6);
  display: grid; gap: var(--s5); align-content: start; grid-template-columns: minmax(0, 1fr);
}
body.is-landing main { max-width: 32rem; }
#status:empty { display: none; }
#stage:has(> #canvas[hidden]) { display: none; }

/* Lobby: the bar first, then (host) the invite card next to the players and voice cards. */
body[data-mode=lobby] #play { order: 0; }
body[data-mode=lobby] #connect { order: 1; }
body[data-mode=lobby] #room { order: 2; }
body[data-mode=lobby] #voice { order: 3; }
@media (min-width: 1024px) {
  body[data-mode=lobby] main:has(> #connect:not([hidden])):has(> #room:not([hidden])) {
    max-width: 1160px; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); grid-template-rows: auto auto 1fr; align-items: start;
    grid-template-areas: "bar bar" "connect room" "connect voice";
  }
  body[data-mode=lobby] main:has(> #connect:not([hidden])):has(> #room:not([hidden])) > #play { grid-area: bar; }
  body[data-mode=lobby] main:has(> #connect:not([hidden])):has(> #room:not([hidden])) > #connect { grid-area: connect; }
  body[data-mode=lobby] main:has(> #connect:not([hidden])):has(> #room:not([hidden])) > #room { grid-area: room; }
  body[data-mode=lobby] main:has(> #connect:not([hidden])):has(> #room:not([hidden])) > #voice { grid-area: voice; }
}
body[data-mode=ended] main { max-width: 34rem; }
body[data-mode=ended] #room { order: 1; }
body[data-mode=ended] #play { order: 2; }

/* ----------------------------------------------------------------------------------------------------- components */
.card {
  background: linear-gradient(180deg, rgb(255 255 255 / .025), transparent 40%), var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--s5);
  box-shadow: var(--shadow); display: grid; gap: var(--s4); min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; }
.card-title { font-size: var(--fs-lg); font-weight: 700; letter-spacing: -.01em; line-height: 1.25; }
.screen-title { font-size: var(--fs-xl); font-weight: 800; letter-spacing: -.025em; line-height: 1.15; }
.lead { color: var(--text-muted); }
.hint { color: var(--text-muted); font-size: var(--fs-sm); }
.subhead { font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }
.field { display: grid; gap: var(--s2); }
.field-label { font-weight: 600; font-size: var(--fs-sm); }
.input, .link-field {
  width: 100%; min-height: var(--tap); padding: 10px 14px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); transition: border-color var(--dur), box-shadow var(--dur);
}
.input-lg { min-height: 52px; font-size: 1.0625rem; }
.input:focus, .link-field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(70 224 210 / .18); outline: none; }
.input:focus-visible, .link-field:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.input::placeholder, .link-field::placeholder { color: var(--text-faint); }
.link-field { font: 500 var(--fs-sm)/1.45 var(--mono); word-break: break-all; resize: none; display: block; }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: var(--tap); min-width: var(--tap);
  padding: 0 18px; border-radius: 12px; border: 1px solid transparent; font: 600 1rem/1.1 var(--font); cursor: pointer;
  text-decoration: none; white-space: nowrap; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background var(--dur), border-color var(--dur), color var(--dur), box-shadow var(--dur), transform var(--dur);
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn .icon { flex: none; }
.btn > * { pointer-events: none; } /* the button itself is the click target (hit tests land on it, not its icon) */
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: var(--brand-ink); box-shadow: 0 8px 24px rgb(255 95 168 / .25); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-danger { background: var(--danger-fill); color: #fff; }
.btn-danger-outline { background: transparent; color: var(--danger); border-color: rgb(255 123 123 / .55); }
@media (hover: hover) {
  .btn-primary:hover:not(:disabled) { background: linear-gradient(135deg, var(--brand-hover), #ffa07f); box-shadow: 0 10px 28px rgb(255 95 168 / .35); }
  .btn-secondary:hover:not(:disabled) { background: var(--surface-3); }
  .btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
  .btn-danger:hover:not(:disabled) { background: #d63a56; }
  .btn-danger-outline:hover:not(:disabled) { background: rgb(255 123 123 / .1); border-color: var(--danger); }
}
.btn-lg { min-height: 54px; padding: 0 28px; font-size: 1.0625rem; border-radius: 14px; }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: var(--fs-sm); }
.btn-icon { width: var(--tap); padding: 0; }
.btn:disabled { background: var(--surface-2); color: var(--text-faint); border-color: var(--border); box-shadow: none; cursor: not-allowed; }
.btn[data-copied] { border-color: var(--ok); color: var(--ok); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: var(--radius-pill); background: var(--surface-2); border: 1px solid var(--border); font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted); width: fit-content; max-width: 100%; }
.tag { display: inline-flex; align-items: center; font-size: var(--fs-xs); font-weight: 700; padding: 1px 8px; border-radius: var(--radius-pill); background: var(--surface-3); color: var(--text-muted); line-height: 1.5; }
.tag-host { background: rgb(255 198 92 / .14); color: var(--warn); }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-muted); }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
[data-tone=ok] { --tone: var(--ok); }
[data-tone=warn] { --tone: var(--warn); }
[data-tone=danger] { --tone: var(--danger); }
[data-tone=muted] { --tone: var(--text-faint); }
.badge[data-tone] { color: var(--tone); }
.notice {
  display: grid; gap: var(--s1); padding: var(--s3) var(--s4); border-radius: var(--radius); background: var(--surface-2);
  border-left: 4px solid var(--tone, var(--accent)); color: var(--text);
}
.notice.error, p.error { --tone: var(--danger); }
p.error:not(.notice) { color: var(--danger); }
.notice-row { display: flex; align-items: flex-start; gap: var(--s3); }
.notice-row > :first-child { flex: 1; min-width: 0; padding-top: 2px; }
.spinner {
  display: inline-block; width: 1em; height: 1em; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .8s linear infinite; flex: none; vertical-align: -.125em;
}
@keyframes spin { to { transform: rotate(360deg); } }
.with-spinner { display: flex; align-items: center; gap: var(--s3); }
.countdown { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.countdown[data-urgent] { color: var(--warn); }
.or { display: flex; align-items: center; gap: var(--s3); color: var(--text-faint); font-size: var(--fs-sm); }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
details > summary {
  cursor: pointer; min-height: var(--tap); display: flex; align-items: center; gap: var(--s2); color: var(--text-muted);
  font-weight: 600; font-size: var(--fs-sm); list-style: none; border-radius: var(--radius-sm);
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: ""; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform var(--dur); margin: 0 4px; }
details[open] > summary::before { transform: rotate(45deg); }
@media (hover: hover) { details > summary:hover { color: var(--text); } }
details > :not(summary) { margin-top: var(--s2); }
details.quiet { border-top: 1px solid var(--border); padding-top: var(--s2); }
details.quiet[open] { display: grid; gap: var(--s3); }
details.quiet[open] > :not(summary) { margin-top: 0; }
kbd { font: 600 .8125rem/1.3 var(--mono); background: var(--surface-3); border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 6px; padding: 1px 6px; color: var(--text); white-space: nowrap; }

/* Avatars and slot colours. Colour is never the only cue: every avatar has initials, every row its slot number. */
[data-player-index] { --slot: var(--text-faint); }
[data-player-index="0"] { --slot: var(--slot-1); }
[data-player-index="1"] { --slot: var(--slot-2); }
[data-player-index="2"] { --slot: var(--slot-3); }
[data-player-index="3"] { --slot: var(--slot-4); }
.avatar {
  width: 48px; height: 48px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--slot, var(--text-faint)); color: #0d0b14; font: 800 1.125rem/1 var(--font); letter-spacing: -.02em;
}
.avatar::before, .slot::before { content: attr(data-label); }
.slot {
  width: 26px; height: 26px; border-radius: 8px; flex: none; display: grid; place-items: center;
  background: var(--slot, var(--text-faint)); color: #0d0b14; font: 800 var(--fs-xs)/1 var(--font);
}

/* ----------------------------------------------------------------------------------------------------- boot status */
#status {
  width: 100%; max-width: 30rem; justify-self: center; text-align: center; color: var(--text-muted);
  display: grid; gap: var(--s3); padding: var(--s4) 0;
}
#status.loading::after {
  content: ""; display: block; height: 6px; border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--brand), var(--brand-2)) 0 0 / calc(var(--progress, 0) * 100%) 100% no-repeat, var(--surface-2);
}
#status.error {
  text-align: left; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--danger);
  border-radius: var(--radius); padding: var(--s4) var(--s5);
}
#reload { justify-self: center; }

/* --------------------------------------------------------------------------------------------- landing / connect */
#connect { display: grid; gap: var(--s4); min-width: 0; }
.landing { gap: var(--s5); }
.landing .screen-title { margin-top: calc(-1 * var(--s2)); }
.landing-actions { display: grid; gap: var(--s3); }
.link-hint { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) var(--s4); border-radius: var(--radius); background: rgb(70 224 210 / .07); border: 1px solid rgb(70 224 210 / .18); color: var(--text-muted); font-size: var(--fs-sm); }
.link-hint .icon { color: var(--accent); flex: none; margin-top: 1px; }
.link-hint strong { color: var(--text); }
.fine { color: var(--text-faint); font-size: var(--fs-xs); text-align: center; }

.invite-link-box { display: grid; gap: var(--s3); padding: var(--s4); border-radius: var(--radius); background: var(--bg); border: 1px solid var(--border); }
.invite-link-box .link-field { border: 0; padding: 0; min-height: 0; background: transparent; color: var(--accent); }
.invite-link-box .link-field:focus { box-shadow: none; }
.invite-meta { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); align-items: center; justify-content: space-between; color: var(--text-faint); font-size: var(--fs-xs); }
.relay-pill[data-tone] { color: var(--tone); }
.relay-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.relay-pill .spinner { width: 10px; height: 10px; }
[data-testid=connect-note]:empty, [data-testid=copy-status]:empty { display: none; }

.knocks { display: grid; gap: var(--s2); }
.knock {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--s3);
  padding: var(--s3); border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border);
  border-left: 4px solid var(--brand); animation: knock-in 240ms ease-out;
}
.knock .avatar { width: 40px; height: 40px; font-size: 1rem; background: var(--brand); }
.knock-text { display: grid; min-width: 0; }
.knock-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.knock-full { grid-column: 1 / -1; }
@keyframes knock-in { from { opacity: 0; transform: translateY(-4px); } }
.empty-state { display: flex; align-items: center; gap: var(--s3); padding: var(--s4); border-radius: var(--radius); border: 1px dashed var(--border-strong); color: var(--text-muted); font-size: var(--fs-sm); }
.empty-state .dots { display: inline-flex; gap: 4px; flex: none; }
.empty-state .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint); animation: blink 1.4s infinite both; }
.empty-state .dots i:nth-child(2) { animation-delay: .2s; } .empty-state .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.joined { display: grid; gap: var(--s2); }
.joined li { display: flex; align-items: center; gap: var(--s2); color: var(--text-muted); font-size: var(--fs-sm); }
.joined li[data-state=up] { display: none; }
.joined:not(:has(li:not([data-state=up]))) { display: none; }

.waiting-card { text-align: center; justify-items: center; }
.waiting-card .pill { justify-self: center; }
.waiting-card .btn-row { justify-content: center; }
.waiting-card details.quiet { justify-self: stretch; text-align: left; }
.waiting-card .notice, .waiting-card .link-field { text-align: left; justify-self: stretch; }
.waiting-line { font-size: var(--fs-lg); font-weight: 700; justify-content: center; }
.waiting-line .spinner { display: none; }
.knocker { position: relative; width: 88px; height: 88px; display: grid; place-items: center; margin: var(--s2) 0; }
.knocker .avatar { width: 72px; height: 72px; font-size: 1.5rem; background: var(--brand); position: relative; z-index: 1; }
.knocker::before, .knocker::after { content: ""; position: absolute; inset: 8px; border-radius: 50%; border: 2px solid var(--brand); opacity: 0; animation: ripple 2.4s ease-out infinite; }
.knocker::after { animation-delay: 1.2s; }
@keyframes ripple { from { transform: scale(1); opacity: .6; } to { transform: scale(1.6); opacity: 0; } }
.waiting-card .screen-title { text-align: center; }
.steps { display: grid; gap: var(--s5); counter-reset: step; }
.steps > li { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: var(--s3); counter-increment: step; }
.steps > li::before { content: counter(step); width: 32px; height: 32px; border-radius: 50%; background: var(--surface-3); display: grid; place-items: center; font-weight: 800; font-size: var(--fs-sm); }
.steps > li > div { display: grid; gap: var(--s3); min-width: 0; }

/* Unsupported / insecure page */
.unsupported .screen-title { color: var(--warn); }

/* --------------------------------------------------------------------------------------------------- the bar (#play) */
#play { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; min-width: 0; }
.hud-title { display: flex; align-items: center; gap: var(--s3); min-width: 0; flex: 1; }
.hud-title .brand-mark { width: 28px; height: 28px; filter: none; }
.game-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.game-meta { color: var(--text-faint); font-size: var(--fs-sm); white-space: nowrap; }
body[data-mode=lobby] .hud-title .brand-mark { display: none; }
body[data-mode=lobby] #play .game-name { font-size: var(--fs-sm); color: var(--text-muted); font-weight: 600; }
body[data-mode=lobby] [data-testid=leave-game] { min-height: 40px; padding: 0 14px; font-size: var(--fs-sm); }
.controls-hint { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; justify-content: center; font-size: var(--fs-sm); color: var(--text-muted); }
.key-hint { white-space: nowrap; }
.keyboard-note { flex-basis: 100%; }
body[data-mode=playing] .keyboard-note { display: none; }
body[data-mode=ended] #play { justify-content: center; }
body[data-mode=ended] #play .hud-title { display: none; }

/* -------------------------------------------------------------------------------------------------------- players */
#room { min-width: 0; }
#room.card { gap: var(--s4); }
.players { display: grid; }
.player {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--s3);
  min-height: 60px; padding: var(--s2) 0; border-top: 1px solid var(--border);
}
.player:first-child { border-top: 0; }
.player[data-state=left] { opacity: .6; }
.player .avatar { width: 40px; height: 40px; font-size: .9375rem; }
.player-main { display: grid; min-width: 0; gap: 2px; }
.player-name { display: flex; align-items: center; gap: var(--s2); font-weight: 600; min-width: 0; }
.player-name .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-name .you { color: var(--accent); font-weight: 600; font-size: var(--fs-sm); }
.player-sub { display: flex; flex-wrap: wrap; gap: 2px var(--s3); align-items: center; }
.link-note { font-size: var(--fs-xs); }
.link-note[data-tone] { color: var(--tone); }
.player-voice { display: flex; align-items: center; gap: 6px; color: var(--text-faint); }
.player-voice[data-on=true] { color: var(--text-muted); }
.player-voice[data-speaking=true] { color: var(--ok); }
.player-slot-empty { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: var(--s3); min-height: 52px; border-top: 1px dashed var(--border); color: var(--text-faint); font-size: var(--fs-sm); }
.player-slot-empty .avatar { width: 40px; height: 40px; background: transparent; border: 2px dashed var(--border-strong); }
.start-box { display: grid; gap: var(--s2); }
#room[data-state=waiting] .room-lead { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--radius); background: rgb(70 224 210 / .07); border: 1px solid rgb(70 224 210 / .2); color: var(--text); font-weight: 600; }
#room[data-state=waiting] .room-lead .spinner { color: var(--accent); }
.room-count { font-variant-numeric: tabular-nums; }
.room-ended { text-align: center; padding: var(--s6) var(--s5); }
.room-ended .room-body { justify-items: center; }
.room-ended .notice { text-align: left; justify-self: stretch; }
.room-ended .screen-title { outline: none; }
.room-ended [data-testid=room-error] { color: var(--text-muted); }
.ended-mark { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--tone, var(--text-muted)); }
.ended-mark .icon { width: 28px; height: 28px; }

/* Desync: blocks the game (and the page) until the player leaves. */
.desync {
  position: fixed; inset: 0; z-index: 1; overflow: auto; background: var(--scrim); backdrop-filter: blur(6px);
  padding: calc(var(--bar-h) + 32px) var(--s5) var(--s6); display: grid; align-content: start; pointer-events: auto;
}
.desync-panel { width: 100%; max-width: 40rem; margin: 0 auto; display: grid; gap: var(--s4); }
.desync h2 { font-size: var(--fs-xl); font-weight: 800; color: var(--danger); letter-spacing: -.02em; }
.desync-players { display: grid; gap: var(--s2); }
.desync-players li { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3); border-radius: var(--radius-sm); background: var(--surface-2); font: var(--fs-sm)/1.4 var(--mono); }
.desync-players li[data-suspect="1"] { box-shadow: inset 3px 0 0 var(--danger); }
.desync pre { white-space: pre-wrap; word-break: break-all; font: .8125rem/1.45 var(--mono); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--s3); max-height: 12rem; overflow: auto; margin: 0; }

/* ---------------------------------------------------------------------------------------------- voice and video */
#voice { min-width: 0; }
.av-controls { display: flex; flex-wrap: wrap; gap: var(--s2); }
.av-btn .icon-on, .av-btn[aria-pressed=true] .icon-off { display: none; }
.av-btn[aria-pressed=true] .icon-on { display: block; }
.av-btn[data-testid=mic-toggle][aria-pressed=true], .av-btn[data-testid=cam-toggle][aria-pressed=true] { border-color: var(--ok); color: var(--ok); background: rgb(94 224 138 / .1); }
.av-btn[data-testid=mic-mute][aria-pressed=true] { border-color: var(--warn); color: var(--warn); background: rgb(255 198 92 / .1); }
.av-errors:not(:has(> :not([hidden]))) { display: none; }
.av-errors { display: grid; gap: var(--s2); }
.av-hint { font-size: var(--fs-xs); color: var(--text-faint); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.tile { position: relative; min-width: 0; }
.tile-media {
  position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--slot) 22%, transparent), transparent 70%), var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border); transition: box-shadow var(--dur);
}
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile[data-self] video { transform: scaleX(-1); }
.tile[data-video=true] .avatar { visibility: hidden; }
.tile[data-speaking=true] .tile-media { box-shadow: inset 0 0 0 3px var(--ok), 0 0 20px rgb(94 224 138 / .3); }
.tile[data-speaking=true] .avatar { animation: speak 1s ease-out infinite; }
@keyframes speak { from { box-shadow: 0 0 0 0 rgb(94 224 138 / .5); } to { box-shadow: 0 0 0 10px rgb(94 224 138 / 0); } }
.tile[data-muted=true] .tile-media { opacity: .55; }
.tile-label {
  position: absolute; left: 6px; bottom: 6px; max-width: calc(100% - 12px); display: flex; align-items: center; gap: 6px;
  padding: 3px 9px 3px 6px; border-radius: var(--radius-pill); background: rgb(13 11 20 / .8); font-size: var(--fs-xs); line-height: 1.4;
}
.tile-label::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--slot); flex: none; }
.tile-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tile-mic { display: none; color: var(--danger); }
.tile-mic .icon { width: 14px; height: 14px; }
.tile[data-remote-mic=false] .tile-mic, .tile[data-self][data-mic=off] .tile-mic { display: inline-flex; }
.tile-status { color: var(--text-muted); white-space: nowrap; }
.tile-status:empty { display: none; }
.tile-mute { position: absolute; top: 4px; right: 4px; width: 36px; min-width: 36px; height: 36px; min-height: 36px; padding: 0; border-radius: 50%; background: rgb(13 11 20 / .7); color: var(--text); border: 0; }
.tile-mute::after { content: ""; position: absolute; inset: -4px; }
.tile-mute .icon-on { display: none; }
.tile-mute[aria-pressed=true] .icon-on { display: block; }
.tile-mute[aria-pressed=true] .icon-off { display: none; }
.tile-mute[aria-pressed=true] { color: var(--warn); }
.tile-mute .icon { width: 18px; height: 18px; }

/* ----------------------------------------------------------------------------------------------- the game stage */
#stage { position: relative; min-width: 0; min-height: 0; display: grid; place-items: center; }
#canvas { display: block; max-width: 100%; background: #000; image-rendering: pixelated; image-rendering: crisp-edges; outline: none; }
#canvas { image-rendering: pixelated; }
.stage-note, .focus-hint { position: absolute; z-index: 2; }
.stage-note {
  inset: 50% auto auto 50%; transform: translate(-50%, -50%); padding: var(--s3) var(--s5); border-radius: var(--radius-pill);
  background: var(--glass); border: 1px solid var(--border); display: flex; align-items: center; gap: var(--s3); font-weight: 600;
}
.focus-hint {
  left: 50%; top: 50%; transform: translate(-50%, -50%); min-height: var(--tap); padding: 0 var(--s5); border-radius: var(--radius-pill);
  background: var(--glass); color: var(--text); border: 1px solid var(--accent); font-weight: 600; cursor: pointer;
  box-shadow: 0 10px 30px rgb(0 0 0 / .5); display: inline-flex; align-items: center; gap: var(--s2); backdrop-filter: blur(4px);
}

/* ------------------------------------------------------------------------------------------------------ in game */
html:has(body[data-mode=playing]) { overflow: hidden; }
body[data-mode=playing] { height: 100vh; height: 100dvh; overflow: hidden; background: #050409; }
body[data-mode=playing] .site-header, body[data-mode=playing] .site-footer, body[data-mode=playing] #status, body[data-mode=playing] #reload { display: none; }
body[data-mode=playing] main {
  max-width: none; height: 100%; min-height: 0; padding: 0 var(--s3) var(--s3); gap: 0 var(--s3);
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  grid-template-rows: var(--bar-h) minmax(0, 1fr);
  grid-template-areas: "title tiles ctrl leave" "stage stage stage stage";
  align-items: center;
}
body[data-mode=playing] #play, body[data-mode=playing] #voice { display: contents; }
body[data-mode=playing] .hud-title { grid-area: title; flex: none; max-width: 18rem; }
body[data-mode=playing] .game-meta { display: none; }
body[data-mode=playing] [data-testid=leave-game] { grid-area: leave; position: relative; z-index: 30; }
body[data-mode=playing] .voice-head, body[data-mode=playing] .av-hint { display: none; }
body[data-mode=playing] .av-controls { grid-area: ctrl; flex-wrap: nowrap; gap: 6px; }
body[data-mode=playing] .av-btn { width: var(--tap); padding: 0; border-radius: 50%; }
body[data-mode=playing] .av-btn .btn-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
body[data-mode=playing] .av-errors {
  position: fixed; z-index: 25; top: calc(var(--bar-h) + 12px); right: var(--s3); width: min(24rem, calc(100vw - 24px));
}
body[data-mode=playing] .av-errors .notice { box-shadow: 0 12px 30px rgb(0 0 0 / .45); }
body[data-mode=playing] #stage {
  grid-area: stage; align-self: stretch; justify-self: stretch; container-type: size; background: var(--stage);
  border-radius: var(--radius); overflow: hidden;
}
body[data-mode=playing] #canvas { width: min(100cqw, 100cqh * var(--game-aspect, 1.6)); height: auto; aspect-ratio: var(--game-aspect, 1.6); }
#stage::after { content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; box-shadow: inset 0 0 0 2px transparent; transition: box-shadow var(--dur); }
body[data-mode=playing] #stage:has(#canvas:focus)::after { box-shadow: inset 0 0 0 2px rgb(70 224 210 / .35); }

/* The controls hint floats at the bottom of the game for a while, then fades out; it comes back whenever the game
   has lost the keyboard. */
body[data-mode=playing] .controls-hint {
  grid-area: stage; align-self: end; justify-self: center; z-index: 3; margin-bottom: var(--s4); max-width: calc(100% - 32px);
  padding: 8px 16px; border-radius: var(--radius); background: var(--glass); border: 1px solid var(--border); backdrop-filter: blur(4px);
  transition: opacity 600ms ease, transform 600ms ease; pointer-events: none;
}
body[data-mode=playing] .controls-hint[data-faded] { opacity: 0; transform: translateY(8px); }
body[data-mode=playing]:has(#focus-hint:not([hidden])) .controls-hint[data-faded] { opacity: 1; transform: none; }
.shell-keys { color: var(--text-faint); }
body:not([data-mode=playing]) .shell-keys { display: none; }

/* Players in the bar: compact chips (avatar with a speaking ring, name, mic state, per-player mute). */
body[data-mode=playing] .tiles {
  grid-area: tiles; display: flex; gap: 6px; align-items: center; justify-content: center; min-width: 0; overflow-x: auto; overflow-y: hidden;
  scrollbar-width: none; padding: 4px;
}
body[data-mode=playing] .tile {
  display: flex; align-items: center; gap: 8px; height: 44px; padding: 3px 4px 3px 3px; border-radius: var(--radius-pill);
  background: var(--surface); border: 1px solid var(--border); flex: none;
}
body[data-mode=playing] .tile-media { width: 36px; height: 36px; aspect-ratio: 1; border-radius: 50%; background: var(--slot); box-shadow: none; overflow: visible; }
body[data-mode=playing] .tile video { display: none; }
body[data-mode=playing] .tile .avatar { width: 36px; height: 36px; font-size: .8125rem; visibility: visible; }
body[data-mode=playing] .tile[data-speaking=true] .tile-media { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ok); }
body[data-mode=playing] .tile-label { position: static; background: none; padding: 0 4px 0 0; max-width: 9rem; font-size: var(--fs-sm); }
body[data-mode=playing] .tile-label::before { display: none; }
body[data-mode=playing] .tile-status { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
body[data-mode=playing] .tile-mute { position: relative; top: auto; right: auto; width: 32px; min-width: 32px; height: 32px; min-height: 32px; background: var(--surface-2); margin-left: -4px; }
body[data-mode=playing] .tile-mute::after { inset: -6px; }

/* Somebody's camera is on: the players become video tiles beside the game (wide screens) or under it (tall ones). */
body[data-mode=playing] main:has(#voice[data-video=true]) { grid-template-areas: "title . ctrl leave" "stage stage stage rail"; }
body[data-mode=playing] main:has(#voice[data-video=true]) [data-testid=leave-game] { justify-self: end; }
body[data-mode=playing] #voice[data-video=true] .tiles {
  grid-area: rail; align-self: start; width: var(--rail-w); max-height: 100%; display: grid; grid-auto-rows: min-content; gap: var(--s2);
  overflow-y: auto; overflow-x: hidden; padding: 0;
}
body[data-mode=playing] #voice[data-video=true] .tile { display: block; height: auto; padding: 0; border: 0; background: none; border-radius: 0; }
body[data-mode=playing] #voice[data-video=true] .tile-media { width: 100%; height: auto; aspect-ratio: 16 / 9; border-radius: var(--radius); box-shadow: inset 0 0 0 1px var(--border); overflow: hidden; background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--slot) 22%, transparent), transparent 70%), var(--surface-2); }
body[data-mode=playing] #voice[data-video=true] .tile video { display: block; }
body[data-mode=playing] #voice[data-video=true] .tile[data-video=true] .avatar { visibility: hidden; }
body[data-mode=playing] #voice[data-video=true] .tile .avatar { width: 44px; height: 44px; font-size: 1rem; }
body[data-mode=playing] #voice[data-video=true] .tile[data-speaking=true] .tile-media { box-shadow: inset 0 0 0 3px var(--ok); }
body[data-mode=playing] #voice[data-video=true] .tile-label { position: absolute; background: rgb(13 11 20 / .8); padding: 3px 9px 3px 6px; font-size: var(--fs-xs); }
body[data-mode=playing] #voice[data-video=true] .tile-label::before { display: block; }
body[data-mode=playing] #voice[data-video=true] .tile-mute { position: absolute; top: 4px; right: 4px; margin: 0; background: rgb(13 11 20 / .7); }
@media (max-aspect-ratio: 3/2) {
  body[data-mode=playing] main:has(#voice[data-video=true]) {
    grid-template-rows: var(--bar-h) minmax(0, 1fr) auto;
    grid-template-areas: "title . ctrl leave" "stage stage stage stage" "rail rail rail rail";
  }
  body[data-mode=playing] #voice[data-video=true] .tiles {
    width: auto; max-width: 100%; max-height: none; grid-auto-flow: column; grid-auto-columns: minmax(0, 200px); justify-self: center; padding-top: var(--s2);
  }
}

/* Room notices while playing: a toast stack over the top-left of the game; clicks fall through to the game. */
body[data-mode=playing] #room {
  position: fixed; z-index: 20; top: calc(var(--bar-h) + 12px); left: var(--s5); width: min(22rem, calc(100vw - 48px));
  display: grid; gap: var(--s2); pointer-events: none; background: none; border: 0; padding: 0; box-shadow: none;
}
body[data-mode=playing] #room .card-head, body[data-mode=playing] #room .players, body[data-mode=playing] #room .start-box,
body[data-mode=playing] #room .room-lead { display: none; }
body[data-mode=playing] #room [data-testid=room-status] { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
body[data-mode=playing] #room .room-body { display: grid; gap: var(--s2); }
body[data-mode=playing] #room .notice { pointer-events: auto; background: var(--glass); backdrop-filter: blur(6px); box-shadow: 0 12px 30px rgb(0 0 0 / .45); font-size: var(--fs-sm); }
body[data-mode=playing] #room .notice button { pointer-events: auto; }
body[data-mode=playing] #room .notice.is-old { display: none; }
body[data-mode=playing] #room .desync { pointer-events: auto; }
.notice-dismiss { width: 32px; min-width: 32px; height: 32px; min-height: 32px; padding: 0; margin: -4px -6px -4px 0; border-radius: 50%; position: relative; }
.notice-dismiss::after { content: ""; position: absolute; inset: -6px; }
.notice-dismiss .icon { width: 16px; height: 16px; }

/* ----------------------------------------------------------------------------------------------------- responsive */
@media (max-width: 1023px) {
  body[data-mode=playing] .hud-title { max-width: 12rem; }
  body[data-mode=playing] .tile-label { max-width: 6rem; }
}
@media (max-width: 599px) {
  .site-header { padding: var(--s4); gap: var(--s2) var(--s3); }
  .wordmark { font-size: 1.375rem; }
  .brand-mark { width: 28px; height: 28px; }
  .tagline { flex-basis: 100%; border: 0; padding: 0; font-size: var(--fs-sm); }
  body.is-landing .site-header, body[data-mode=ended] .site-header, body:not([data-mode]):not(.harness) .site-header { padding-top: var(--s6); padding-bottom: var(--s5); }
  main { padding: 0 var(--s4) var(--s5); gap: var(--s4); }
  .card { padding: var(--s4) var(--s4) var(--s5); border-radius: var(--radius); }
  .btn-row > .btn { flex: 1 1 auto; }
  .knock { grid-template-columns: auto minmax(0, 1fr); }
  .knock .btn-row { grid-column: 1 / -1; }
  .screen-title { font-size: 1.5rem; }
  .site-footer { padding: var(--s4) var(--s4) var(--s5); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* Phone (portrait): the bar, the players, the game at full width, the controls under it (nothing covers the game). */
  body[data-mode=playing] main {
    padding: 0 var(--s2) var(--s2); gap: 0 var(--s2); align-content: start;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-rows: var(--bar-h) auto auto auto auto;
    grid-template-areas: "title ctrl leave" "tiles tiles tiles" "stage stage stage" "toasts toasts toasts" "hint hint hint";
  }
  /* Notices go under the game instead of over it (there is room below on a phone held upright). */
  body[data-mode=playing] #room { position: static; grid-area: toasts; width: auto; margin-top: var(--s3); }
  body[data-mode=playing] #room:not(:has(.notice, .desync)) { margin-top: 0; }
  body[data-mode=playing] .hud-title { max-width: none; }
  body[data-mode=playing] .hud-title .brand-mark { display: none; }
  body[data-mode=playing] .tiles { justify-content: flex-start; padding: 0 0 var(--s2); }
  body[data-mode=playing] [data-testid=leave-game] { padding: 0 12px; }
  body[data-mode=playing] [data-testid=leave-game] .btn-label-long { display: none; }
  body[data-mode=playing] #stage { align-self: start; height: auto; aspect-ratio: var(--game-aspect, 1.6); border-radius: var(--radius-sm); }
  body[data-mode=playing] #canvas { width: 100%; }
  body[data-mode=playing] .controls-hint, body[data-mode=playing] .controls-hint[data-faded] {
    grid-area: hint; align-self: start; justify-self: stretch; margin: var(--s3) 0 0; max-width: none; opacity: 1; transform: none;
    font-size: var(--fs-xs); background: var(--surface); justify-content: flex-start;
  }
  body[data-mode=playing] .controls-hint .sep { display: none; }
  body[data-mode=playing] main:has(#voice[data-video=true]) {
    grid-template-rows: var(--bar-h) auto auto auto auto;
    grid-template-areas: "title ctrl leave" "stage stage stage" "rail rail rail" "toasts toasts toasts" "hint hint hint";
  }
  body[data-mode=playing] #voice[data-video=true] .tiles { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-columns: auto; width: 100%; justify-self: stretch; padding-top: var(--s2); }
}
@media (max-width: 380px) {
  body[data-mode=playing] .av-controls { gap: 4px; }
}

/* ------------------------------------------------------------------------------------------------ reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .spinner { border-right-color: currentColor; opacity: .5; }
}

/* Harness pages (?test=1 without the product flow): sections stack and the canvas shows in flow. */
body.harness main { max-width: 56rem; }
