/*
  ONE TUBE IN A DARK ROOM.

  The page is a machine seen at night: everything is deep CPS-board blue, and
  exactly one thing glows. On the landing page that is the hero — a powered-on
  tube running its attract loop. In a room it is the game screen. Every other
  surface is quiet hardware: hairline seams, small stamped labels, monospace
  readouts.

  Colour discipline: blue surfaces, one warm accent. The accent is marquee
  yellow — the colour of INSERT COIN — and it is spent only on the actions that
  start something and on the room code. The three player colours and red-means-
  recording are the only other hues on the page, so each still means something.

  Type discipline: three faces, three jobs. The wordmark is a hand-drawn pixel
  path (no webfont, crisp at any size). UI text is the system grotesk. Anything
  that is a *readout* — the room code, the HUD, the log — is monospace, because
  those are numbers that must line up and change without the layout twitching.

  Everything decorative is `pointer-events: none`. tools/verify drives real
  trusted mouse events at element centres, so an overlay that swallowed clicks
  would break the harness rather than merely look wrong.
*/
:root {
  color-scheme: dark;

  --void: #060a13;      /* the dark of the room */
  --panel: #0c1322;     /* CPS board blue, unlit */
  --panel-lit: #121b30; /* the same board catching screen light */
  --well: #070c17;      /* recessed: inputs, the screen bezel */
  --line: #1c2846;      /* hairline seams */
  --line-lit: #2c3b64;

  --ink: #e9eef9;
  --dim: #97a3c2;
  --faint: #5d6a8c;

  /* Marquee yellow. The only warm light in the building. */
  --coin: #ffc83d;
  --coin-hot: #ffe08a;
  --coin-edge: #7e5c00;
  --on-coin: #1a1200;

  --p1: #ff4f57;
  --p2: #3ea6ff;
  --p3: #46d483;
  --ok: var(--p3);
  --ng: var(--p1);

  --gap: 14px;
  --pad: 22px;
  --radius: 8px;

  --font-ui: -apple-system, 'SF Pro Text', 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --font-data: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/*
  The UA's `[hidden] { display: none }` loses to any author `display`, which has
  already produced one real bug (a hidden canvas painting black over the ROM
  picker). This rule retires the whole class of it.
*/
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: calc(var(--pad) * 1.2) var(--gap) calc(var(--pad) * 3);
  /* App-like: no double-tap zoom and no tap delay anywhere. Controls keep
     their own stricter touch-action (none); intersection takes the strictest,
     so this never loosens them. */
  touch-action: manipulation;
  background:
    radial-gradient(90% 40rem at 50% -6rem, #101a33 0%, var(--void) 70%);
  background-color: var(--void);
  color: var(--ink);
  font: 15px/1.55 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--coin); color: var(--on-coin); }

.shell {
  max-width: 62rem;
  margin: 0 auto;
  display: grid;
  gap: var(--gap);
}

/* The pixel wordmark. crispEdges keeps unit squares square at any scale. */
.px {
  display: block;
  fill: currentColor;
  shape-rendering: crispEdges;
}

/* -------------------------------------------------------------- masthead */

/*
  Slim header for the room and author views; the landing page leads with the
  wordmark in the hero instead, so it hides this. A browser without :has()
  shows it everywhere — harmless duplication, never a missing header.
*/
.masthead {
  display: flex;
  align-items: baseline;
  gap: 0.9rem;
  padding: 0 0.2rem;
}
body:has(#view-landing:not([hidden])) .masthead { display: none; }

.mark {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink);
  text-decoration: none;
}
.mark .px { height: 14px; width: auto; }
.mark-chip { color: var(--coin); display: block; }
.mark:hover .mark-chip { color: var(--coin-hot); }
.mark:focus-visible { outline: 2px solid var(--coin); outline-offset: 4px; }
.mast-tag {
  margin: 0;
  color: var(--faint);
  font-family: var(--font-data);
  font-size: 11px;
  letter-spacing: 0.04em;
}

/* ------------------------------------------------------------------ hero */

.hero { display: grid; gap: var(--gap); }

/*
  The signature: a powered-on tube running its attract loop. Vignette, faint
  scanlines, and a phosphor bloom on the wordmark. This is the one loud thing
  on the page; everything after it stays quiet.
*/
.crt {
  position: relative;
  overflow: hidden;
  padding: clamp(2.4rem, 7vw, 4.5rem) clamp(1.2rem, 6vw, 4rem) clamp(2rem, 5vw, 3.2rem);
  text-align: center;
  border-radius: 14px;
  border: 1px solid var(--line);
  background:
    radial-gradient(120% 100% at 50% 0%, #182852 0%, #0c1530 48%, #080e1e 100%);
  box-shadow:
    inset 0 0 90px rgba(4, 7, 16, 0.9),
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 20px 60px rgba(0, 0, 0, 0.55);
}
/* Scanlines and a top sheen, painted once by the compositor. Inert to input. */
.crt-glass {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 18%),
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.22) 0 1px, transparent 1px 4px);
}

.attract {
  margin: 0 0 1.6rem;
  font-family: var(--font-data);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5em;
  text-indent: 0.5em;
  text-transform: uppercase;
  color: var(--coin);
  text-shadow: 0 0 14px rgba(255, 200, 61, 0.55);
  animation: attract-blink 1.6s steps(1, end) infinite;
}
@keyframes attract-blink {
  0%, 64% { opacity: 1; }
  65%, 100% { opacity: 0.12; }
}

.wordmark {
  margin: 0 0 1.4rem;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(0.7rem, 2.5vw, 1.3rem);
  color: var(--ink);
}
.wordmark .px {
  width: min(62vw, 330px);
  height: auto;
  filter: drop-shadow(0 0 22px rgba(160, 190, 255, 0.35));
}
.wordmark-chip { color: var(--coin); display: block; }
.wordmark-chip .px {
  width: min(24vw, 128px);
  filter: drop-shadow(0 0 18px rgba(255, 200, 61, 0.5));
}

.lede {
  margin: 0 auto 2.2rem;
  max-width: 34rem;
  color: var(--dim);
  font-size: 16px;
  line-height: 1.65;
  text-wrap: balance;
}

.start-row { display: grid; justify-items: center; gap: 0.6rem; margin-bottom: 2rem; }
.start-row .btn-coin {
  font-size: 16px;
  padding: 0.95rem 2.6rem;
}
.start-hint { margin: 0; color: var(--faint); font-size: 12.5px; }

/* Joining is the quieter path — most guests arrive by link and never type. */
.join-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding-top: 1.4rem;
  border-top: 1px solid rgba(44, 59, 100, 0.5);
  max-width: 30rem;
  margin: 0 auto;
}
.join-label { color: var(--dim); font-size: 13px; }
.join-row input {
  width: 13.5rem;
  text-align: center;
  text-transform: uppercase;
}

/* The engineer's plaque: exact numbers, quietly stated. */
.spec {
  list-style: none;
  margin: 0;
  padding: 0 0.2rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  column-gap: 1.6rem;
  row-gap: 0.3rem;
  color: var(--faint);
  font-family: var(--font-data);
  font-size: 11px;
  letter-spacing: 0.05em;
}
.spec li { position: relative; }
.spec li + li::before {
  content: '·';
  position: absolute;
  left: -1rem;
  color: var(--line-lit);
}

/* ----------------------------------------------------------------- panels */

.panel {
  padding: var(--pad);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel-lit), var(--panel) 70%);
}

.panel h2 {
  margin: 0 0 0.5rem;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--dim);
}

.eyebrow {
  margin: 0 0 0.3rem;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--faint);
}

/* --------------------------------------------------------------- controls */

/*
  Two button voices. The coin button starts something and there is at most one
  on screen; ghosts do everything else. Both press down 1px — hardware travel,
  not a colour swap.
*/
.btn {
  font: inherit;
  font-weight: 700;
  font-size: 13.5px;
  letter-spacing: 0.06em;
  padding: 0.6rem 1.1rem;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  color: var(--ink);
  background: var(--panel-lit);
  /* A .btn may be an <a> — the author page's back link is one. */
  display: inline-block;
  text-decoration: none;
  text-align: center;
  transition: transform 70ms ease-out, box-shadow 70ms ease-out,
    background-color 120ms ease-out, border-color 120ms ease-out, color 120ms ease-out;
}
.btn:focus-visible { outline: 2px solid var(--coin); outline-offset: 2px; }
.btn:active { transform: translateY(1px); }
.btn:disabled { cursor: not-allowed; transform: none; opacity: 0.45; }

.btn-coin {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 800;
  color: var(--on-coin);
  background: linear-gradient(180deg, var(--coin-hot) 0%, var(--coin) 45%);
  box-shadow: 0 3px 0 var(--coin-edge), 0 6px 24px rgba(255, 200, 61, 0.22);
}
.btn-coin:hover:not(:disabled) { background: linear-gradient(180deg, #fff0c0 0%, #ffd45e 45%); }
.btn-coin:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--coin-edge), 0 3px 12px rgba(255, 200, 61, 0.18);
}
.btn-coin:disabled { box-shadow: none; background: var(--panel-lit); color: var(--dim); opacity: 1; }

.btn-ghost {
  color: var(--dim);
  background: transparent;
  border-color: var(--line-lit);
}
.btn-ghost:hover:not(:disabled) { color: var(--ink); border-color: var(--faint); background: rgba(44, 59, 100, 0.25); }

.btn-small { font-size: 11px; padding: 0.32rem 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; }

input {
  font: inherit;
  font-family: var(--font-data);
  font-size: 14px;
  padding: 0.62rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--well);
  color: var(--ink);
  letter-spacing: 0.08em;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.55);
}
input::placeholder { color: var(--faint); }
input:focus {
  outline: none;
  border-color: var(--coin);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.55), 0 0 0 3px rgba(255, 200, 61, 0.15);
}

/*
  A fault is an inverted block, never a red word: red is a player colour here
  and the recording colour too, so hue alone would read as neither urgent nor
  wrong.
*/
.error { min-height: 1.2em; margin: 0; }
.error:not(:empty) {
  padding: 0.6rem 0.9rem;
  border-radius: 7px;
  background: var(--ng);
  color: #2a0507;
  font-weight: 700;
  font-size: 13px;
}
.error:not(:empty)::before { content: '⚠ '; }

/* ------------------------------------------------------------------- room */

.room-head {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  align-items: center;
  justify-content: space-between;
}
.code-block { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.code-label {
  color: var(--faint);
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
/* The one string in this app that gets read aloud down a phone. */
.code {
  font-family: var(--font-data);
  font-size: clamp(1.1rem, 3.6vw, 1.5rem);
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--coin);
  background: var(--well);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.3rem 0.7rem;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.55);
}
.status-block { display: flex; align-items: center; gap: 0.6rem; margin-left: auto; }

/* Room invite QR: white card so phone cameras see it, crisp modules. */
.qr-modal {
  background: var(--panel);
  border: 1px solid var(--line-lit);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  text-align: center;
  color: var(--ink);
  max-width: min(92vw, 22rem);
}
.qr-modal::backdrop { background: rgba(0, 0, 0, 0.7); }
.qr-note { margin: 0.2rem 0 0.6rem; color: var(--dim); font-size: 12px; }
#qr-canvas {
  background: #fff;
  border-radius: 6px;
  image-rendering: pixelated;
  max-width: 100%;
  height: auto;
}
/* QR camera viewfinder. */
#scan-video {
  width: min(78vw, 320px);
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: 6px;
  object-fit: cover;
}
.qr-code {
  font-family: var(--font-data);
  font-size: 11px;
  color: var(--dim);
  word-break: break-all;
  user-select: text;
  -webkit-user-select: text;
}
.qr-modal menu { display: flex; justify-content: center; padding: 0; margin: 0.8rem 0 0; }

/* An indicator lamp, not a chip. Off is a dark lens; on is lit from inside. */
.pill {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  color: var(--faint);
  background: var(--well);
  border: 1px solid var(--line);
}
.pill[data-status='ready'] { color: #05240f; background: var(--ok); border-color: transparent; box-shadow: 0 0 14px rgba(70, 212, 131, 0.45); }
.pill[data-status='error'] { color: #2a0507; background: var(--ng); border-color: transparent; box-shadow: 0 0 14px rgba(255, 79, 87, 0.45); }
.pill[data-status='connecting'],
.pill[data-status='reconnecting'] { color: var(--coin); border-color: rgba(255, 200, 61, 0.4); }

/*
 * Solo-fallback alarm. Same red as the error pill, but a full-width banner:
 * this is not a status, it is news the player must not miss. Hidden unless a
 * multiplayer game just lost its last peer.
 */
.solo-alarm {
  margin: var(--pad) 0 0;
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  border: 1px solid transparent;
  color: #2a0507;
  background: var(--ng);
  box-shadow: 0 0 14px rgba(255, 79, 87, 0.45);
  font-weight: 800;
  font-size: 14px;
  line-height: 1.4;
}
.solo-alarm[hidden] { display: none; }

/* --------------------------------------------------------------- the lobby */

.lobby { margin-top: var(--pad); }
.lobby-head { display: flex; align-items: baseline; gap: 0.5rem; }
.lobby-count { color: var(--faint); font-weight: 400; letter-spacing: 0.08em; }

.roster { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--gap); }
@media (min-width: 46rem) { .roster { grid-template-columns: repeat(3, 1fr); } }

/* A player's card wears their colour: one rule feeds the stripe, the portrait,
   the slot label and the talker chip. */
[data-slot='1'] { --hue: var(--p1); }
[data-slot='2'] { --hue: var(--p2); }
[data-slot='3'] { --hue: var(--p3); }

.roster li {
  position: relative;
  display: flex;
  gap: var(--gap);
  align-items: center;
  padding: 0.75rem;
  border-radius: 7px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--hue, var(--faint));
  background: var(--panel);
}
.roster li[data-self='true'] { background: var(--panel-lit); }
/* A live microphone is the one state in here worth catching your eye. */
.roster li[data-talking='true'] { box-shadow: inset 0 0 0 1px var(--ng), 0 0 16px rgba(255, 79, 87, 0.22); }

/*
 * The portrait, and the control tucked into its corner.
 *
 * The size rules are written as `.portrait > .portrait-art` on purpose: the
 * element carries `avatar-art` too, for the fill and display shared with the
 * picker, and a bare `.portrait-art` would lose to whichever of the two is
 * declared later in this file. Specificity, not source order, decides here.
 */
.portrait {
  position: relative;
  flex: none;
  line-height: 0;
  color: var(--hue, var(--dim));
}
.portrait > .portrait-art {
  width: 72px;
  height: 72px;
  padding: 0.55rem;
  border-radius: 999px;
  background: var(--well);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.7), 0 0 0 1px var(--line);
}
@media (max-width: 46rem) { .portrait > .portrait-art { width: 60px; height: 60px; } }

/* A small round control on the portrait's corner — pressable without a label. */
.mic-orb,
.mic-badge {
  position: absolute;
  right: -4px;
  bottom: -4px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line-lit);
  border-radius: 999px;
  color: var(--dim);
  background: var(--panel-lit);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.6);
}
.mic-badge { width: 26px; height: 26px; }
.mic-icon { width: 16px; height: 16px; display: block; }
.mic-badge .mic-icon { width: 14px; height: 14px; }
.mic-orb { cursor: pointer; }
.mic-orb:hover:not(:disabled) { color: var(--ink); border-color: var(--faint); }
.mic-orb:focus-visible { outline: 2px solid var(--coin); outline-offset: 2px; }
.mic-orb:disabled { opacity: 0.45; cursor: not-allowed; }
.mic-orb[data-busy='true'] { cursor: progress; }
/* Red means recording — the one convention nobody has to learn. */
.mic-orb[aria-pressed='true'],
.mic-badge[data-muted='false'] {
  color: #2a0507;
  background: var(--ng);
  border-color: transparent;
  box-shadow: 0 0 12px rgba(255, 79, 87, 0.55);
}

.card-body { display: grid; gap: 0.1rem; min-width: 0; }
.roster .slot {
  font-weight: 700;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--hue, var(--ink));
}
.roster .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15.5px; font-weight: 600; }
.roster .mic-state {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
}
.roster .mic-state[data-muted='false'] { color: var(--ng); }
.roster .peer-id {
  color: var(--faint);
  font-family: var(--font-data);
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.roster .you {
  position: absolute;
  top: 0.45rem;
  right: 0.5rem;
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  background: var(--coin);
  color: var(--on-coin);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.roster .speaker { position: absolute; top: 0.4rem; right: 0.45rem; }
.roster .speaker[aria-pressed='false'] { opacity: 0.55; }

/* ------------------------------------------------------------------ stage */

.stage-wrap { position: relative; margin-top: var(--pad); }

/* The game screen sits in a deep bezel, the room view's one recessed surface. */
.stage {
  position: relative;
  min-height: 14rem;
  display: grid;
  place-items: center;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--well);
  overflow: hidden;
  box-shadow: inset 0 2px 16px rgba(0, 0, 0, 0.8);
  /* Double-clicking the screen toggles fullscreen; without this it also drags
     a selection across whatever placeholder text is under the pointer. */
  user-select: none;
}

/*
 * The canvas carries its own intrinsic ratio from the width/height attributes
 * renderer.ts rewrites whenever the core's geometry changes, so `height: auto`
 * tracks whatever game is loaded.
 */
#screen {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 3px;
  background: #04060c;
  /* Pixel art blown up; never let the browser smooth it. */
  image-rendering: pixelated;
}

/*
 * Scanlines, on the tube only. A static pseudo-element the compositor paints
 * once, never a per-frame effect over a canvas repainting 59.63 times a second.
 * Inert to input, and below the fullscreen latch at z-index 2.
 */
.stage::after {
  content: '';
  position: absolute;
  inset: 12px;
  z-index: 1;
  pointer-events: none;
  border-radius: 3px;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.26) 0 1px, transparent 1px 3px);
}
#stage-wrap:is(:fullscreen,.force-full) .stage::after { inset: 0; border-radius: 0; }

/* Fullscreen latch, held in the bezel's corner. Out of the way until the
   pointer is over the screen, like a video player's controls. */
.stage-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  /* Deliberately NOT backdrop-filter: this button sits over a canvas that
     repaints 59.63 times a second, and a backdrop filter makes the compositor
     read that canvas back and blur it every single frame. It cost ~1ms of the
     16.78ms budget and dropped catch-up frames. A flat scrim is free. */
  background: rgba(6, 10, 19, 0.85);
  /* Dimmed rather than hidden: a control nobody can find is not a control. */
  opacity: 0.5;
  transition: opacity 140ms ease-out;
}
.stage:hover .stage-btn,
.stage-btn:focus-visible { opacity: 1; }
/* The bezel's latches, in one corner: touch toggle beside fullscreen. The
   container places them; buttons inside it are in flow, not absolute. */
.stage-tools {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: flex;
  gap: 6px;
}
.stage-tools .stage-btn {
  position: static;
}

/* ------------------------------------------------- on-screen touch controls
 *
 * The cabinet, on the glass: a stick bottom-left and a six-button cluster
 * bottom-right, from the live site (see src/touch-controls.ts). Sizing lives
 * in --tp-* below so one rule scales the whole pad with the viewport.
 */
.stage-wrap {
  --tp-stick: clamp(104px, 23vmin, 164px);
  --tp-ring: calc(var(--tp-stick) * .45);
  --tp-cap: clamp(48px, 11vmin, 78px);
  --tp-cell: calc(var(--tp-cap) * 1.26);
  --tp-arc: calc(var(--tp-cell) * .16);
  --tp-foot: clamp(6px, 2vmin, 20px);
  --tp-band: calc(max(var(--tp-stick), calc(var(--tp-cell) * 2 + var(--tp-arc))) + var(--tp-foot));
  --tp-sys: clamp(30px, 6.5vmin, 44px);
}
.touchpad {
  z-index: 3;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  position: absolute;
  inset: 0;
}
.touchpad, .touchpad * {
  touch-action: none;
  /* iOS gray flash on rapid taps can read as a second, stuck button. */
  -webkit-tap-highlight-color: transparent;
}
.tp-zone { pointer-events: none; position: absolute; bottom: 0; }
.tp-zone-stick {
  width: min(46%, calc(var(--tp-stick) * 2.1));
  height: var(--tp-band);
  pointer-events: auto;
  left: 0;
}
.tp-zone-stick:before {
  /* The old custom stick has a single ring (the base itself); the dashed rest
     circle would double it. Kept in the stylesheet so the shape still reads
     while idle, drawn only by .tp-stick below. */
  display: none;
}
/* Fixed ring, from this project's old custom stick: transparent face, solid
   rim. The base never moves — only the knob travels. */
.tp-stick {
  width: var(--tp-stick);
  height: var(--tp-stick);
  pointer-events: none;
  opacity: .92;
  will-change: transform;
  background: transparent;
  border: 2px solid #4c6a92;
  border-radius: 50%;
  transition: opacity .14s ease-out;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.tp-stick[data-engaged=true] { opacity: 1; border-color: var(--coin); }
.tp-gate { pointer-events: none; position: absolute; inset: 0; }
.tp-dir {
  color: var(--dim);
  text-shadow: 0 0 3px #000000f2;
  font-size: clamp(11px, 2.4vmin, 16px);
  font-style: normal;
  line-height: 1;
  transition: color 90ms ease-out, text-shadow 90ms ease-out;
  position: absolute;
  top: 50%;
  left: 50%;
}
.tp-dir[data-dir=UP] { transform: translate(-50%, calc(-50% - var(--tp-ring))); }
.tp-dir[data-dir=DOWN] { transform: translate(-50%, calc(-50% + var(--tp-ring))); }
.tp-dir[data-dir=LEFT] { transform: translate(calc(-50% - var(--tp-ring)), -50%); }
.tp-dir[data-dir=RIGHT] { transform: translate(calc(-50% + var(--tp-ring)), -50%); }
.tp-dir[data-pressed=true] { color: var(--coin); text-shadow: 0 0 10px rgba(255, 200, 61, 0.85); }
/* Fat centred knob: same blue-steel face as the button caps so the whole pad
   reads as one theme. Flat steel at rest, coin-hot while steering. */
.tp-knob {
  pointer-events: none;
  background: radial-gradient(circle at 50% 32%, #1c2f57e6, #05080feb 74%);
  border: 1px solid #4c6a92;
  opacity: .85;
  will-change: transform;
  border-radius: 50%;
  width: 45%;
  height: 45%;
  transition: transform .19s cubic-bezier(.22, .9, .28, 1), background .14s ease-out;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.tp-stick[data-engaged=true] .tp-knob {
  background: radial-gradient(circle at 44% 34%, var(--coin-hot), var(--coin) 44%, var(--coin-edge) 100%);
  opacity: 1;
}
.tp-zone-cluster {
  grid-template-columns: repeat(3, var(--tp-cell));
  padding: 0 clamp(4px, 1.6vmin, 18px) var(--tp-foot) 0;
  align-content: end;
  display: grid;
  right: 0;
}
.tp-zone-cluster .tp-key:nth-child(3n+2) { transform: translateY(-9%); }
.tp-zone-cluster .tp-key:nth-child(3n) { transform: translateY(-16%); }
.tp-key {
  width: var(--tp-cell);
  height: var(--tp-cell);
  pointer-events: auto;
  place-items: center;
  display: grid;
}
.tp-cap {
  width: var(--tp-cap);
  height: var(--tp-cap);
  color: var(--ink);
  font-family: var(--font-data);
  opacity: .92;
  /* Blue steel to match the CPS-board theme (the live site's green stays
     on the live site): same rim as the stick ring. */
  background: radial-gradient(circle at 50% 32%, #1c2f57e6, #05080feb 74%);
  border: 1px solid #4c6a92;
  border-radius: 50%;
  place-items: center;
  font-size: clamp(20px, 4.8vmin, 32px);
  line-height: 1;
  /* NOTE: no transform in the transition list. Rapid taps re-triggered the
     scale transition faster than iOS composites it, then a hold froze the cap
     mid-scale: a stuck oversized ghost next to the live button. The pressed
     scale below still applies — instantly, which a finger cannot out-tap. */
  transition: opacity .11s ease-out, color .11s ease-out, background .11s ease-out, box-shadow .11s ease-out;
  display: grid;
  position: relative;
  box-shadow: 0 0 0 1px #0000008c, inset 0 -4px 10px #0009;
}
.tp-cap:after {
  content: "";
  border-radius: inherit;
  border: 1px solid var(--coin);
  opacity: 0;
  pointer-events: none;
  transition: none;
  position: absolute;
  inset: -7%;
  transform: scale(.84);
}
.tp-key[data-pressed=true] .tp-cap {
  opacity: 1;
  color: var(--on-coin);
  background: radial-gradient(circle at 50% 34%, var(--coin-hot), var(--coin) 62%, var(--coin-edge) 100%);
  transition-duration: 55ms;
  transform: scale(.9);
  box-shadow: 0 0 24px rgba(255, 200, 61, 0.55), inset 0 3px 8px rgba(0, 0, 0, 0.45);
}
.tp-key[data-pressed=true] .tp-cap:after {
  opacity: .8;
  transition-duration: 45ms;
  transform: scale(1);
}
.tp-zone-system {
  bottom: auto;
  left: 50%;
  top: calc(100% - var(--tp-band) - var(--tp-sys));
  height: var(--tp-sys);
  align-items: center;
  gap: clamp(10px, 2.4vmin, 20px);
  display: flex;
  transform: translate(-50%);
}
.tp-key-pill { width: auto; height: auto; padding: clamp(3px, 1vmin, 7px); }
.tp-key-pill .tp-cap {
  letter-spacing: .16em;
  text-transform: uppercase;
  border-radius: 999px;
  width: auto;
  min-width: clamp(54px, 13vmin, 92px);
  height: auto;
  padding: clamp(5px, 1.3vmin, 10px) clamp(10px, 2.2vmin, 18px);
  font-size: clamp(14px, 2.88vmin, 20px);
}
/* Settings gear + panel: per-button size/opacity for the pad on screen. */
.tp-gear {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 5;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line-lit);
  background: rgba(10, 15, 25, 0.92);
  color: var(--dim);
  font-size: 15px;
  line-height: 1;
  /* Emoji iOS has a tall ascent: without flex centring the glyph sits low
     and clips against the circle. */
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  cursor: pointer;
}
/* Master speaker toggle: same 30px circle language as the gear, one row
   below it so a thumb never covers both. Dimmed while everything is silent. */
.tp-sound {
  position: absolute;
  top: 42px;
  left: 6px;
  z-index: 5;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line-lit);
  background: rgba(10, 15, 25, 0.92);
  color: var(--dim);
  font-size: 15px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  cursor: pointer;
}
/* Own microphone, one row below the speaker button. Dimmed while muted. */
.tp-mic {
  position: absolute;
  top: 78px;
  left: 6px;
  z-index: 5;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line-lit);
  background: rgba(10, 15, 25, 0.92);
  color: var(--dim);
  font-size: 15px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  cursor: pointer;
}
.tp-mic[data-muted='true'] {
  opacity: 0.55;
}
.tp-mic .mic-icon { width: 16px; height: 16px; display: block; }
/* Live reads like the lobby orb: red means recording. */
.tp-mic[aria-pressed='true'] {
  color: #2a0507;
  background: var(--ng);
  border-color: transparent;
  box-shadow: 0 0 12px rgba(255, 79, 87, 0.55);
  opacity: 1;
}
/* Member speaker list. Same fixed-docked, draggable language as the settings
   panel, parked top-right so the two panels never cover each other. */
.tp-soundpanel {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top, 0px));
  right: 8px;
  z-index: 60;
  width: min(240px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px 10px;
  border-radius: 10px;
  border: 1px solid var(--line-lit);
  background: rgba(10, 15, 25, 0.95);
  color: var(--ink);
  font-size: 12px;
  pointer-events: auto;
}
.tp-soundrows {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 40vh;
  overflow-y: auto;
}
.tp-soundrow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
}
.tp-soundname {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Per-member playback gain. Narrow on purpose: the panel is 240px and the
   name plus the mute button already live here. */
.tp-vol {
  flex: 0 0 84px;
  width: 84px;
  margin: 0;
  accent-color: var(--coin);
  cursor: pointer;
}
.tp-soundbtn {
  border: 1px solid var(--line-lit);
  background: transparent;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1;
  padding: 2px 8px;
  cursor: pointer;
}
.tp-soundbtn[data-audible='false'] {
  opacity: 0.55;
}
.tp-soundempty {
  color: var(--dim);
}
.tp-panel {
  /* Viewport-docked, not pad-docked: inside the pad box the panel falls over
     the cluster it configures (B3/START swallowed taps on phones). Fixed is
     viewport-anchored windowed, and contained by the top-layer box in real
     fullscreen — visible in both. Draggable for the rest. */
  position: fixed;
  top: calc(8px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  width: min(280px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 10px 10px;
  border-radius: 10px;
  border: 1px solid var(--line-lit);
  background: rgba(10, 15, 25, 0.95);
  color: var(--ink);
  font-size: 12px;
  pointer-events: auto;
}
.tp-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--dim);
  font-weight: 700;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
.tp-panel-x {
  border: 1px solid var(--line-lit);
  background: transparent;
  color: var(--dim);
  border-radius: 6px;
  font-size: 11px;
  padding: 1px 7px;
  cursor: pointer;
}
.tp-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.tp-name { min-width: 26px; color: var(--dim); }
.tp-row select {
  flex: 1;
  background: var(--well);
  color: var(--ink);
  border: 1px solid var(--line-lit);
  border-radius: 6px;
  font-size: 12px;
  padding: 2px 4px;
}
.tp-row input[type='range'] { flex: 1; min-width: 0; }
.tp-val { min-width: 30px; text-align: right; font-family: var(--font-data); color: var(--dim); }
.tp-reset, .tp-arrange {
  border: 1px solid var(--line-lit);
  background: transparent;
  color: var(--ink);
  border-radius: 6px;
  font-size: 12px;
  padding: 4px 8px;
  cursor: pointer;
}
.stage[data-touch=on] { padding-bottom: calc(var(--tp-band) + var(--tp-sys) + 10px); }
#stage-wrap:is(:fullscreen,.force-full) .stage[data-touch=on] { padding-bottom: 0; }
#stage-wrap:is(:fullscreen,.force-full) .tp-zone-system {
  justify-content: space-between;
  height: auto;
  /* Below the corner latches: full-width at the very top puts COIN over the
     gear and START over the touch/fullscreen buttons. */
  inset: clamp(40px, 9vmin, 56px) clamp(8px, 2vmin, 18px) auto;
  transform: none;
}

.stage-placeholder {
  margin: 0;
  padding: 1rem;
  text-align: center;
  color: var(--faint);
  font-family: var(--font-data);
  font-size: 12px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

.rom-picker {
  max-width: min(32rem, 100%);
  padding: var(--pad);
  border-radius: 7px;
  text-align: center;
  color: var(--dim);
  background: var(--panel);
  border: 1px solid var(--line);
}
.rom-picker > p:first-child { margin: 0 0 0.8rem; color: var(--ink); font-size: 15px; font-weight: 600; }
.rom-bar {
  display: grid;
  gap: 0.5rem;
  padding: 0.7rem;
  border-radius: 7px;
  text-align: left;
  background: var(--well);
  border: 1px solid var(--line);
}
.rom-bar input { background: transparent; box-shadow: none; border: 0; padding: 0; font-size: 12px; }
/* The browser draws this one itself, and its default is a light-grey OS button
   in the middle of a dark panel. Dressed as a ghost button like every other
   secondary action on the page. */
.rom-bar input[type='file']::file-selector-button {
  font: inherit;
  font-family: var(--font-ui);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-right: 0.6rem;
  padding: 0.32rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  color: var(--dim);
  background: var(--panel-lit);
  border: 1px solid var(--line-lit);
}
.rom-bar input[type='file']::file-selector-button:hover {
  color: var(--ink);
  border-color: var(--faint);
}
.rom-why { margin: 0; color: var(--dim); font-size: 11px; line-height: 1.6; }

/* Which machine, above which game. Reads as one labelled control. */
.rom-system { display: grid; gap: 0.3rem; }
.rom-system .field {
  color: var(--faint);
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}
/*
  A native select, dressed to match the text inputs. The arrow is drawn here
  rather than left to the platform, because the platform's is black-on-white and
  this control sits in a recessed well.
*/
.rom-system select {
  font: inherit;
  font-family: var(--font-ui);
  font-size: 13px;
  appearance: none;
  width: 100%;
  padding: 0.5rem 2rem 0.5rem 0.7rem;
  border: 1px solid var(--line-lit);
  border-radius: 7px;
  background:
    linear-gradient(45deg, transparent 50%, var(--dim) 50%) calc(100% - 15px) 50% / 5px 5px no-repeat,
    linear-gradient(135deg, var(--dim) 50%, transparent 50%) calc(100% - 10px) 50% / 5px 5px no-repeat,
    var(--panel-lit);
  color: var(--ink);
}
.rom-system select:focus-visible { outline: 2px solid var(--coin); outline-offset: 2px; }
.rom-system select:disabled { opacity: 0.55; cursor: not-allowed; }
/* The options themselves are drawn by the OS, which does not inherit any of the
   above — naming both colours is what stops a white-on-white menu. */
.rom-system select option { background: var(--panel); color: var(--ink); }

/* The games each emulator is for, in titles rather than board names. */
.rom-hint { margin: -0.15rem 0 0; color: var(--dim); font-size: 11.5px; line-height: 1.6; }
.rom-hint b { color: var(--ink); font-weight: 600; }

/* Sits inside the picker so the fault and the control that caused it are one
   object. Collapses to nothing when empty — see the shared .error rule. */
.rom-error { margin: 0.7rem 0 0; min-height: 0; text-align: left; }
/* The guest's half of the picker: nothing to do, and it says so. */
.rom-wait { margin: 0; color: var(--dim); font-size: 12.5px; line-height: 1.6; }

/* A transfer in flight. The bar is the element's own background, filled to
   --fraction, so there is no second node to keep in step with the label. */
.rom-progress {
  margin: 0.6rem 0 0;
  padding: 0.35rem 0.6rem;
  border-radius: 5px;
  font-family: var(--font-data);
  font-size: 11px;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(70, 212, 131, 0.4) var(--fraction, 0%), transparent var(--fraction, 0%)),
    var(--panel-lit);
  transition: background 120ms linear;
}

/* Quieter than the HUD numbers beside it: this is standing context, not a
   figure anybody is watching change. */
.rom-note {
  margin: 0.5rem 0 0;
  font-size: 11px;
  color: var(--faint);
  letter-spacing: 0.04em;
}

.hud {
  margin: 0.5rem 0 0;
  font-family: var(--font-data);
  font-size: 11px;
  color: var(--faint);
  display: flex;
  gap: 1.2rem;
  flex-wrap: wrap;
}
.hud b { color: var(--dim); font-weight: 400; }
.hud[data-warn='true'] b { color: var(--ng); }
.netplay .phase { text-transform: uppercase; letter-spacing: 0.12em; font-weight: 700; }
.netplay[data-phase='lockstep'] .phase { color: var(--ok); }
.netplay[data-phase='stalled'] .phase { color: var(--ng); }
.netplay[data-phase='syncing'] .phase { color: var(--coin); }
.netplay[data-phase='solo'] .phase { color: var(--dim); }
/* Peers disagreeing about a frame is the one number worth an inverted block. */
.netplay .desync {
  background: var(--ng);
  color: #2a0507;
  font-weight: 700;
  padding: 0 0.4rem;
  border-radius: 3px;
}

/* -------------------------------------------------------------- fullscreen */

/*
 * The wrapper is what goes fullscreen, so the HUD lines come along instead of
 * being left behind on the page. They float over the bottom of the picture
 * rather than stealing height from it.
 */
#stage-wrap:is(:fullscreen,.force-full) {
  display: flex;
  flex-direction: column;
  background: #000;
}
/* Painted behind the element for the moment before the transition settles. */
#stage-wrap::backdrop { background: #000; }
/*
 * The CSS fallback for browsers with no Fullscreen API for elements (iPhone
 * Safari): the same selectors as native, via :is() above, plus real viewport
 * positioning here — a class cannot borrow the top layer. dvh tracks the
 * visible height past the collapsing URL bar; env() keeps clear of the notch.
 */
#stage-wrap.force-full {
  position: fixed;
  inset: 0;
  z-index: 1000;
  width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  overscroll-behavior: none;
}
/*
 * Page-scroll lock while the fallback is up. `overflow: hidden` alone is a
 * desktop-only lock — iOS keeps scrolling the document and shows its scrollbar
 * over the black stage. Taking the body out of flow is the lock iOS honours;
 * ui.ts remembers and restores the offset.
 */
body.fs-lock {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
#stage-wrap:is(:fullscreen,.force-full) .stage {
  flex: 1;
  min-height: 0;
  margin: 0;
  /* No bezel on a fullscreen screen — the surround would just be picture
     thrown away. */
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
/* Here the canvas must fit the viewport rather than carry its own height, and
   object-fit is what keeps the game's aspect honest while letterboxing.
   Measured in viewport units, NOT %: % heights resolve through the
   flex-then-grid chain as indefinite in some engines, fall back to the
   intrinsic ratio, and the canvas comes out 844x492 in a 844x390 viewport —
   over-zoom with the pad fitted outside the screen after it. dvh second so
   the URL bar never donates its height on iOS. */
#stage-wrap:is(:fullscreen,.force-full) #screen {
  width: auto;
  height: 100vh;
  height: 100dvh;
  max-width: 100vw;
  max-height: 100vh;
  max-height: 100dvh;
  margin: auto;
  object-fit: contain;
  border-radius: 0;
}

#stage-wrap:is(:fullscreen,.force-full) .hud-rows {
  position: absolute;
  inset: auto 0 0;
  z-index: 2;
  padding: 0.5rem 1rem 0.6rem;
  /* The scrim has to hold grey-on-bright: arcade backgrounds go to full-value
     green and yellow, and a gentle fade leaves the HUD unreadable over them. */
  background: linear-gradient(to top, rgba(0, 0, 0, 0.95) 0%, rgba(0, 0, 0, 0.85) 55%, transparent 100%);
  transition: opacity 200ms ease-out;
}
#stage-wrap:is(:fullscreen,.force-full) .hud { margin: 0; justify-content: center; }

/* Idle means the pointer has not moved for a couple of seconds. Fade the
   furniture out — but never a live desync count, which is the one number worth
   interrupting a game for. Browsers without :has() drop the whole rule and
   simply keep the HUD up, which is the harmless way to be wrong. */
#stage-wrap:is(:fullscreen,.force-full)[data-idle='true'] { cursor: none; }
#stage-wrap:is(:fullscreen,.force-full)[data-idle='true'] .stage-btn { opacity: 0; pointer-events: none; }
#stage-wrap:is(:fullscreen,.force-full)[data-idle='true'] .hud-rows:not(:has(.desync)) { opacity: 0; }

/*
 * Fullscreen is for playing, not reading: hide the small diagnostic print
 * (ROM line, emulator counters, netplay counters) so it never sits over the
 * game, idle or not. The desync badge is the exception — it only exists when
 * non-zero — so the net line hides by visibility (children can opt back in)
 * while the plain rows hide by display.
 */
#stage-wrap:is(:fullscreen,.force-full) #rom-note,
#stage-wrap:is(:fullscreen,.force-full) #emu-hud { display: none; }
#stage-wrap:is(:fullscreen,.force-full) #net-hud { visibility: hidden; }
#stage-wrap:is(:fullscreen,.force-full) #net-hud .desync { visibility: visible; }

/* ------------------------------------------------------- chat and the log */

.chat { display: flex; align-items: stretch; gap: 0.5rem; margin-top: var(--pad); }
.chat input { flex: 1; letter-spacing: normal; font-family: var(--font-ui); }

.chat-log,
.log {
  list-style: none;
  margin: var(--gap) 0 0;
  padding: 0;
  display: grid;
  gap: 2px;
  max-height: 15rem;
  overflow: auto;
  font-family: var(--font-data);
}
.chat-log:empty { margin: 0; }
.chat-log li {
  padding: 0.35rem 0.6rem;
  border-radius: 5px;
  background: var(--well);
  border-left: 2px solid transparent;
  font-size: 13px;
}
.chat-log li[data-mine='true'] { border-left-color: var(--coin); }
.chat-log .from { color: var(--dim); margin-right: 0.5rem; }

.diagnostics summary,
.controls summary {
  cursor: pointer;
  color: var(--dim);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  list-style: none;
}
.diagnostics summary::-webkit-details-marker,
.controls summary::-webkit-details-marker { display: none; }
.diagnostics summary::before,
.controls summary::before { content: '▸ '; color: var(--faint); }
.diagnostics details[open] > summary::before,
.controls details[open] > summary::before { content: '▾ '; }
.diagnostics summary:focus-visible,
.controls summary:focus-visible { outline: 2px solid var(--coin); outline-offset: 2px; }
.diagnostics details + details { margin-top: var(--gap); }
.diagnostics pre {
  overflow: auto;
  margin: var(--gap) 0 0;
  padding: 0.7rem;
  border-radius: 7px;
  font-size: 11px;
  color: var(--dim);
  background: var(--well);
  border: 1px solid var(--line);
}
.log li { font-size: 11px; color: var(--faint); white-space: pre-wrap; word-break: break-word; }
.log li[data-level='info'] { color: var(--dim); }
.log li[data-level='warn'] { color: var(--coin); }
.log li[data-level='error'] { color: var(--ng); }
.log .ts { color: #3d4763; margin-right: 0.5rem; }

/* --------------------------------------------------------------- identity */

/*
 * The dialog every way into a room comes through — START, JOIN, and a shared
 * link. A name is mandatory, so the confirm button is disabled until there is
 * one; <dialog> handles the focus trap, the backdrop and Escape without any
 * code of ours.
 */
.identity {
  width: min(33rem, calc(100vw - 1.5rem));
  /* Short screens (Android landscape, small phones): the profile + token +
     capacity rows are taller than the viewport. Cap the box and scroll the
     body inside it so the bottom buttons are always reachable. */
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  padding: 0;
  border: 1px solid var(--line-lit);
  border-radius: 12px;
  overflow: hidden auto;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
}
.identity::backdrop { background: rgba(3, 5, 10, 0.8); }
.identity-head {
  padding: 1rem var(--pad) 0.8rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel-lit);
}
.identity-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.identity-body { display: grid; gap: 0.5rem; padding: var(--pad); }
.identity .field {
  margin: 0.5rem 0 0;
  color: var(--faint);
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}
.identity .error { margin: 0; min-height: 0; }
.identity input { font-family: var(--font-ui); letter-spacing: normal; }
.identity menu {
  margin: var(--gap) 0 0;
  padding: 0;
  display: flex;
  gap: 0.6rem;
  align-items: stretch;
  justify-content: flex-end;
}
.identity menu .btn-coin { flex: 1; }
.mic-note {
  margin: 0.6rem 0 0;
  padding: 0.6rem 0.8rem;
  border-radius: 7px;
  background: var(--well);
  border: 1px solid var(--line);
  color: var(--dim);
  font-size: 12px;
}
.mic-note b { color: var(--ink); }
.mic-note kbd {
  font: inherit;
  font-family: var(--font-data);
  font-size: 11px;
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  background: var(--coin);
  color: var(--on-coin);
  font-weight: 700;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
}
@media (max-width: 30rem) { .avatar-grid { grid-template-columns: repeat(3, 1fr); } }

/* Each token is a dark tile until you choose it; chosen is a lit coin. */
.avatar-pick {
  display: grid;
  justify-items: center;
  gap: 0.3rem;
  padding: 0.5rem 0.25rem;
  border-radius: 7px;
  background: var(--well);
  border: 1px solid var(--line);
  color: var(--dim);
  cursor: pointer;
  transition: border-color 100ms ease-out, color 100ms ease-out;
}
/* The radio itself is the a11y story; the tile is what people look at. */
.avatar-pick input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}
.avatar-pick:hover { color: var(--ink); border-color: var(--line-lit); }
.avatar-pick:has(input:checked) {
  color: var(--on-coin);
  background: linear-gradient(180deg, var(--coin-hot), var(--coin));
  border-color: transparent;
  box-shadow: 0 0 14px rgba(255, 200, 61, 0.3);
}
.avatar-pick:has(input:focus-visible) { outline: 2px solid var(--coin); outline-offset: 2px; }
.avatar-name { font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase; }

.avatar-art { fill: currentColor; display: block; }
.avatar-pick .avatar-art { width: 28px; height: 28px; }

/* Host only: how many the room is opened for. Same tiles, wider, because the
   number is the whole content. */
.capacity-grid, .profile-grid { display: grid; grid-auto-flow: column; gap: 0.4rem; justify-content: start; }
.capacity-pick, .profile-pick {
  display: grid;
  justify-items: center;
  gap: 0.1rem;
  min-width: 5rem;
  padding: 0.5rem 0.9rem;
  border-radius: 7px;
  background: var(--well);
  border: 1px solid var(--line);
  color: var(--dim);
  cursor: pointer;
  transition: border-color 100ms ease-out, color 100ms ease-out;
}
.capacity-pick input, .profile-pick input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}
.capacity-pick:hover, .profile-pick:hover { color: var(--ink); border-color: var(--line-lit); }
.capacity-pick:has(input:checked), .profile-pick:has(input:checked) {
  color: var(--on-coin);
  background: linear-gradient(180deg, var(--coin-hot), var(--coin));
  border-color: transparent;
  box-shadow: 0 0 14px rgba(255, 200, 61, 0.3);
}
.capacity-pick:has(input:focus-visible), .profile-pick:has(input:focus-visible) { outline: 2px solid var(--coin); outline-offset: 2px; }
/* Logged in elsewhere: not pickable until that tab leaves (or its lock goes stale). */
.profile-pick:has(input:disabled) { opacity: 0.45; cursor: not-allowed; }
.capacity-n { font-size: 22px; font-weight: 800; line-height: 1; }
.profile-n { font-size: 15px; font-weight: 800; line-height: 1.4; }
.capacity-word { font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase; }

/* Out of the layout rather than display:none — an <audio> element under
   display:none does play, but not by a wide enough margin to rely on. */
.voice-sinks {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* --------------------------------------------------------- control panel */

.controls summary { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.controls summary h2 { margin: 0; display: inline; color: inherit; }
.controls-who {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--hue, var(--faint));
}
.controls-body { margin-top: var(--gap); display: grid; gap: var(--gap); }
.controls-actions { display: flex; justify-content: flex-end; }

/* The pad lamp is the whole answer to "is my controller even seen?" — the
   Gamepad API stays silent until a button is pressed, which surprises everyone. */
.pad-pill {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  color: var(--faint);
  background: var(--well);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.pad-pill[data-state='standard'] { color: #05240f; background: var(--ok); border-color: transparent; }
.pad-pill[data-state='unmapped'] { color: var(--on-coin); background: var(--coin); border-color: transparent; }

.control-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (max-width: 46rem) { .control-list { grid-template-columns: 1fr; } }

.control-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 2.4rem;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  background: var(--well);
  border: 1px solid var(--line);
  transition: background-color 80ms linear;
}
/* Lit while the control is actually down. This is the legend's real job: it is
   how you find out that the stick you just plugged in is stuck on LEFT. */
.control-list li[data-held='true'] { background: #0e2417; border-color: rgba(70, 212, 131, 0.4); }
.control-list li[data-capturing='true'] { background: #2a2310; border-color: rgba(255, 200, 61, 0.4); }

.ctl-label { display: flex; align-items: center; gap: 0.5rem; min-width: 5rem; }
/* The legend's glyphs are button caps laid out in panel order, so the legend
   looks like the thing it describes. */
.ctl-glyph {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: none;
  border-radius: 999px;
  font-size: 12px;
  color: var(--ink);
  background: var(--panel-lit);
  border: 1px solid var(--line-lit);
}
.control-list li[data-held='true'] .ctl-glyph {
  color: #05240f;
  background: var(--ok);
  border-color: transparent;
  box-shadow: 0 0 8px rgba(70, 212, 131, 0.5);
}
.ctl-name { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); }
.control-list li[data-held='true'] .ctl-name { color: var(--ink); }

.ctl-binds { display: flex; flex-wrap: wrap; gap: 0.25rem; align-items: center; }
.ctl-none { font-size: 11px; color: var(--ng); letter-spacing: 0.1em; text-transform: uppercase; }

button.bind {
  font: inherit;
  font-family: var(--font-data);
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--dim);
  background: var(--panel);
  cursor: pointer;
}
button.bind:hover { color: var(--ink); border-color: var(--line-lit); }
button.bind:focus-visible { outline: 2px solid var(--coin); outline-offset: 1px; }
/* Lit per physical control, not per game button: with three things bound to B4
   this is what tells you which one fired. */
button.bind[data-down='true'] { color: #05240f; background: var(--ok); border-color: transparent; }
button.bind[data-source='pad-axis'] { font-style: italic; }
button.bind.add { color: var(--faint); }
button.bind.add:hover { color: var(--ink); }

.bind .x { color: var(--faint); font-size: 12px; line-height: 1; }
.bind .x:hover { color: var(--ng); }
button.bind[data-down='true'] .x { color: #05240f; }

/* ------------------------------------------------- the controller dialog */

/*
  A console's controller screen: the pad big and central, one instruction at a
  time under it, and nothing else competing for the eye. Sized off the canvas
  rather than the text, because the picture is the point.
*/
.pad-dialog {
  width: min(38rem, calc(100vw - 2rem));
  padding: 0;
  border: 1px solid var(--line-lit);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.66);
}
.pad-dialog::backdrop { background: rgba(3, 6, 12, 0.72); }
.pad-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--gap);
  padding: var(--pad) var(--pad) 0;
}
.pad-head h2 { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: -0.01em; }

/* The well the pad sits in, so the drawing reads as a lit object on a surface
   rather than as ink on the panel. */
.pad-canvas {
  display: block;
  width: calc(100% - var(--pad) * 2);
  /*
   * Tall enough that the 340x200 drawing is limited by the width rather than
   * the height — at 210 the pad sat in the middle of its own box with a third
   * of the canvas empty either side.
   */
  height: 250px;
  margin: 0.8rem var(--pad) 0;
  border-radius: 7px;
  background: var(--well);
  border: 1px solid var(--line);
}

/* Three dots and three words. Enough to know where you are without reading. */
.pad-steps {
  list-style: none;
  display: flex;
  gap: 0.4rem;
  margin: var(--gap) var(--pad) 0;
  padding: 0;
}
.pad-steps li {
  flex: 1;
  padding: 0.3rem 0.5rem;
  border-radius: 5px;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-align: center;
  color: var(--faint);
  background: var(--well);
  border: 1px solid var(--line);
}
.pad-steps li[data-state='now'] {
  color: var(--on-coin);
  background: var(--coin);
  border-color: var(--coin-edge);
  font-weight: 700;
}
.pad-steps li[data-state='done'] { color: var(--ok); border-color: var(--line-lit); }

.pad-body {
  margin: 0.8rem var(--pad) 0;
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--dim);
  /* Three lines of copy, so a longer instruction does not shove the buttons
     down the screen and move them under the pointer mid-read. */
  min-height: 3.9em;
}
.pad-readout {
  margin: 0.5rem var(--pad) 0;
  font-family: var(--font-data);
  font-size: 10.5px;
  color: var(--faint);
  min-height: 1.3em;
}
/* The bar is the element's own background, filled to --fraction, so there is no
   second node to keep in step with the label. Same trick as the ROM transfer. */
.pad-progress {
  margin: 0.5rem var(--pad) 0;
  padding: 0.35rem 0.6rem;
  border-radius: 5px;
  font-family: var(--font-data);
  font-size: 11px;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(255, 200, 61, 0.38) var(--fraction, 0%), transparent var(--fraction, 0%)),
    var(--panel-lit);
  transition: background 120ms linear;
}

.pad-deadzone {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin: 0.8rem var(--pad) 0;
}
.pad-deadzone label {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--dim);
}
.pad-deadzone output {
  font-family: var(--font-data);
  font-size: 11px;
  color: var(--ink);
  min-width: 2.6rem;
}
/* The global `input` rule is written for text fields; a range needs none of it. */
.pad-deadzone input[type='range'] {
  flex: 1;
  min-width: 8rem;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  accent-color: var(--coin);
}

.pad-menu {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  justify-content: flex-end;
  margin: var(--gap) 0 0;
  padding: var(--gap) var(--pad) var(--pad);
  border-top: 1px solid var(--line);
}
.pad-menu form { display: contents; }
/* Pushes the destructive one away from the two a player actually wants. */
.pad-menu #btn-pad-secondary { margin-right: auto; }

.controls-hint { margin: 0; font-size: 12px; color: var(--faint); }

/* ------------------------------------------------------- who is talking */

/*
 * Inside the stage wrapper, which is the element that goes fullscreen, so this
 * comes along with the picture instead of being left behind on the page.
 */
.speaking {
  position: absolute;
  top: 18px;
  right: 18px;
  /* Above the HUD rows (2). */
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.4rem;
  pointer-events: none;
}
/*
 * Top-right on purpose: in fullscreen the HUD takes the bottom of the picture,
 * and this would sit on top of it anywhere down there.
 */
#stage-wrap:is(:fullscreen,.force-full) .speaking { top: 1rem; right: 1rem; }
/*
 * And it does NOT fade with the rest of the furniture when the pointer goes
 * idle. Knowing who is talking is worth more mid-fight than the pixels it
 * covers, and unlike the HUD it is only on screen while somebody is speaking.
 */
#stage-wrap:is(:fullscreen,.force-full)[data-idle='true'] .speaking { opacity: 1; }
.talker {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.6rem 0.2rem 0.3rem;
  border-radius: 999px;
  background: rgba(6, 10, 19, 0.88);
  box-shadow: inset 0 0 0 1px var(--hue, var(--ng));
  color: var(--hue, var(--ink));
  font-size: 12px;
}
.talker > .talker-art { width: 18px; height: 18px; }
.talker b { font-weight: 400; color: var(--ink); }

/* The lobby card lights up for the same reason, next to the portrait. */
.roster li[data-speaking='true'] .portrait-art {
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.7), 0 0 0 2px var(--ng), 0 0 16px rgba(255, 79, 87, 0.45);
}

/* ----------------------------------------------------------------- author */

.author { display: grid; gap: 0.6rem; justify-items: start; }
/* Written as `.author .author-name` so it outranks `.panel h2`, which would
   otherwise shrink the one human name on the site into a section label. */
.author .author-name {
  margin: 0;
  font-size: clamp(1.5rem, 4.5vw, 2.1rem);
  font-weight: 800;
  letter-spacing: -0.015em;
  text-transform: none;
  color: var(--ink);
}
.author-line { margin: 0; color: var(--dim); }
.author-story { margin: 0.4rem 0 0; max-width: 38rem; color: var(--dim); line-height: 1.7; }
.author-links {
  list-style: none;
  margin: 0.6rem 0 1rem;
  padding: 0;
  display: grid;
  gap: 0.35rem;
  font-family: var(--font-data);
  font-size: 13px;
}
.author-links a { color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--line-lit); }
.author-links a:hover { color: var(--coin); border-bottom-color: var(--coin); }
.author-links a:focus-visible { outline: 2px solid var(--coin); outline-offset: 3px; }
.author-links li::before { content: '→ '; color: var(--faint); }

/* ----------------------------------------------------------------- footer */

.foot { margin: 0; padding: 0 var(--pad); text-align: center; display: grid; gap: 0.3rem; }
.foot p { margin: 0; color: var(--faint); font-size: 12px; }
.foot-links { font-size: 12px; color: var(--faint); display: flex; gap: 0.6rem; justify-content: center; }
.foot-links a { color: var(--dim); text-decoration: none; border-bottom: 1px solid var(--line-lit); }
.foot-links a:hover { color: var(--coin); border-bottom-color: var(--coin); }
.foot-links button.linklike {
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line-lit);
  color: var(--dim);
  font: inherit;
  padding: 0;
  cursor: pointer;
}
.foot-links button.linklike:hover { color: var(--coin); border-bottom-color: var(--coin); }
.foot-links button.linklike[aria-pressed='true'] { color: var(--coin); border-bottom-color: var(--coin); }
.foot-links a:focus-visible { outline: 2px solid var(--coin); outline-offset: 3px; }
.foot .broker { font-family: var(--font-data); font-size: 10px; color: #3d4763; }

/* ---------------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {
  .attract { animation: none; opacity: 1; }
  .btn,
  .control-list li,
  .stage-btn,
  .avatar-pick,
  .capacity-pick,
  .profile-pick,
  #stage-wrap:is(:fullscreen,.force-full) .hud-rows { transition: none; }
  .btn:active { transform: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .roster li[data-speaking='true'] .portrait-art { transition: box-shadow 90ms linear; }
}
