/* App shell, the component set from ui/components.js, the right rail, the lobby,
   the controls and the modals.

   Nothing below names a material. Every colour, fill, border, space, radius,
   duration and type value resolves to a semantic token in tokens.css, so a new
   visual direction is a rewrite of that file and not of this one.

   The one rule that makes the set cohere: a piece is a dark face, one lit
   keyline in its own colour, and a hard slab of shadow under it. Light is the
   only thing that separates a piece from the ground. The single exception is a
   card that gets dealt to you — that is cream, because it is paper. */

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--ink);
  background-image: var(--tex-confetti), var(--fill-app);
  background-size: var(--tex-size), cover;
  background-attachment: fixed;
}

/* ---- topbar ---- */

.topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2) var(--sp-3);
  flex-wrap: wrap;
  min-height: var(--topbar-h);
  padding: var(--sp-1) var(--sp-4);
  color: var(--text);
  background: rgba(10, 3, 24, 0.55);
  border-bottom: 2px solid var(--border);
}

.brand {
  appearance: none;
  border: 0;
  background: none;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  margin-right: auto;
  min-width: 0;
}

.brand__mark {
  font-family: var(--font-emoji);
  font-size: var(--fs-md);
  line-height: 1;
}

.brand__word {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: var(--accent);
  text-shadow: 0 0 22px color-mix(in srgb, var(--accent) 70%, transparent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-3);
  font-family: var(--font-display);
  font-size: var(--fs-xs);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-label);
  color: var(--text-faint);
  border: var(--bd-thin);
  border-radius: var(--r-pill);
}

.conn::before {
  content: "";
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--text-faint);
}

.conn.is-live { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, transparent); }
.conn.is-live::before { background: var(--ok); box-shadow: 0 0 10px var(--ok); }

.conn.is-lost { color: var(--danger-hi); border-color: color-mix(in srgb, var(--danger) 55%, transparent); }
.conn.is-lost::before { background: var(--danger); box-shadow: 0 0 10px var(--danger); }

.conn.is-connecting { color: var(--wild-hi); border-color: color-mix(in srgb, var(--wild) 55%, transparent); }
.conn.is-connecting::before {
  background: var(--wild);
  animation: conn-blink var(--dur-blink) var(--ease-in-out) var(--anim-iter) alternate;
}

@keyframes conn-blink {
  from { opacity: 0.25; }
  to { opacity: 1; }
}

/* ---- stage ---- */

/* data-screen is the router: hidden screens leave the tab order entirely. */
.stage,
.dock,
.screen {
  display: none;
}

body[data-screen="game"] .stage { display: grid; }
body[data-screen="game"] .dock { display: flex; }

body[data-screen="landing"] .screen,
body[data-screen="join"] .screen,
body[data-screen="lobby"] .screen,
body[data-screen="results"] .screen {
  display: flex;
}

/* Board on the left, rail on the right, both full height — the game screen is
   two columns and nothing below them. */
.stage {
  flex: 1;
  min-height: 0;
  gap: var(--sp-3);
  padding: var(--sp-3);
  grid-template-columns: minmax(0, 1fr) var(--rail-w);
  grid-template-rows: minmax(0, 1fr);
  align-content: stretch;
}

.screen {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  flex-direction: column;
  gap: var(--sp-4);
  width: min(46rem, 100%);
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-4);
}

/* On a TV the shell owns the viewport and only the ledger scrolls. */
@media (min-width: 901px) {
  body[data-screen="game"] .app {
    height: 100vh;
    overflow: hidden;
  }
}

/* The frame the ribbon is laid in. It only ever holds the board. */
.board-wrap {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 0;
  padding: var(--sp-2);
  border: 2px solid var(--border);
  border-radius: var(--r-lg);
  background: rgba(10, 3, 24, 0.42);
  box-shadow: inset 0 0 60px -20px var(--halo);
}

/* The view nests the stage one level down; that wrapper has to carry the size
   through and centre what it holds. */
.board-wrap > * {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
}

/* ---- the rail: room, turn, last result, standings, tab, controls ---- */

.rail {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  min-height: 0;
  min-width: 0;
  padding: var(--sp-2);
  border: var(--bd-key);
  border-radius: var(--r-lg);
  background-image: var(--fill-surface);
  box-shadow: var(--shadow-panel);
}

.rail__block {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  border: var(--bd-thin);
  border-radius: var(--r-md);
  background: rgba(10, 3, 24, 0.42);
  overflow: hidden;
}

.rail__slot {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  min-width: 0;
}

.rail__slot:empty { display: none; }

/* The code and the banner size to themselves, the standings take the slack, and
   the tab is capped — it is the one thing that reads short, and every row it
   does not claim is a seat shown whole rather than sliced in half. */
.rail__block--room { flex: 0 0 auto; }
.rail__block--score { flex: 1 1 auto; min-height: 4rem; }
.rail__block--tab { flex: 0 0 auto; height: 6.5rem; }

/* Kept short on purpose: every row it does not take is a seat the standings
   below can show without scrolling. */
.room {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  min-width: 0;
  padding: var(--sp-1) var(--led-pad);
}

.room .stamp--lg { flex: 1 1 auto; min-width: 0; justify-content: space-between; padding: 0 var(--sp-2); }
.room .stamp--lg .stamp__code { font-size: var(--fs-lg); }
.room .btn { flex: 0 0 auto; min-height: var(--ctl-h-sm); padding: 0 var(--sp-2); font-size: var(--fs-xs); }

.rail__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 var(--sp-2);
  flex: 0 0 auto;
  padding: var(--sp-1) var(--led-pad);
  font-family: var(--font-display);
  font-size: var(--fs-xs);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-label);
  color: var(--accent-hi);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border-bottom: var(--bd-thin);
}

/* The two columns of the scoreboard are the whole game, and neither glyph
   explains itself. This says what they are, permanently, next to them. */
.rail__legend {
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-faint);
  white-space: nowrap;
}

.rail__block--tab .rail__head { color: var(--info-hi); background: color-mix(in srgb, var(--info) 13%, transparent); }

.ledger {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 var(--led-pad);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text);
  /* Ruled paper: the page stays ruled past the last entry. */
  background-image:
    repeating-linear-gradient(to bottom,
      transparent 0 calc(var(--led-row) - 1px),
      var(--border) calc(var(--led-row) - 1px) var(--led-row));
  background-size: 100% var(--led-row);
  background-attachment: local;
}

.ledger-line {
  display: grid;
  grid-template-columns: var(--led-c1) var(--led-c2) minmax(0, 1fr) var(--led-c4);
  align-items: start;
  line-height: var(--led-row);
  min-height: var(--led-row);
}

/* The rail is too narrow to spend a column on a clock nobody reads, so its lead
   track collapses to nothing. The span itself has to stay in flow — display:none
   would take a grid item out of the layout and shift every column left one. */
.ledger .ledger-line { grid-template-columns: 0 var(--led-c2) minmax(0, 1fr) var(--led-c4); }
.ledger .ledger-line__lead { overflow: hidden; }

.ledger-line__lead {
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  padding-right: var(--sp-1);
}

.ledger-line__who {
  font-weight: 700;
  color: color-mix(in srgb, var(--pc, var(--text)) 72%, var(--text));
  padding-right: var(--sp-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* One entry, one ruled line. The rail is narrow enough that a wrapped entry
   reads as two events; the full text is on the row's tooltip. */
.ledger-line__text {
  color: var(--text-dim);
  padding-right: var(--sp-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ledger-line__amt {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: right;
  color: var(--text);
  /* "2 drinks" broken over two lines reads as two entries. */
  white-space: nowrap;
}

.ledger-line--drink .ledger-line__text,
.ledger-line--setback .ledger-line__text {
  color: var(--danger-hi);
  font-weight: 700;
}

.ledger-line--drink .ledger-line__amt,
.ledger-line--setback .ledger-line__amt { color: var(--danger-hi); }

.ledger-line--score .ledger-line__amt {
  color: var(--prize);
  font-weight: 700;
}

.ledger-line--water .ledger-line__text,
.ledger-line--water .ledger-line__amt { color: var(--info-hi); }

.ledger-line--win .ledger-line__text,
.ledger-line--win .ledger-line__amt {
  color: var(--ok);
  font-weight: 700;
}

.ledger-line--win { background: var(--ok-dim); }
.ledger-line--setback { background: var(--danger-dim); }
.ledger-line--move .ledger-line__text { color: var(--text-faint); }

.ledger-line--system { font-style: italic; }
.ledger-line--system .ledger-line__text { color: var(--text-faint); }

.ledger-line.is-new { animation: ledger-write var(--dur-slow) var(--ease-out) both; }

@keyframes ledger-write {
  from { opacity: 0; transform: translateX(-0.4rem); }
  to { opacity: 1; transform: none; }
}

/* ---- the turn banner ---- */

/* The loudest thing on the rail: whose turn, what they rolled, where it put
   them, and what the table is waiting for. */
.turn-banner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: var(--sp-1) var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border: 2px solid var(--accent);
  border-radius: var(--r-md);
  background:
    linear-gradient(180deg,
      color-mix(in srgb, var(--accent) 22%, transparent),
      color-mix(in srgb, var(--accent) 7%, transparent));
  box-shadow: 0 0 30px -10px var(--accent);
}

.turn-banner.is-mine {
  border-color: var(--ok);
  background:
    linear-gradient(180deg,
      color-mix(in srgb, var(--ok) 22%, transparent),
      color-mix(in srgb, var(--ok) 7%, transparent));
  box-shadow: 0 0 30px -10px var(--ok);
}

.turn-banner__line {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
}

/* min-width: 0 or the flex default (min-content) makes a long nowrap name push
   the whole rail wider than the page instead of ellipsising. */
/* A long name wraps rather than truncating — the rail is narrow and whose turn
   it is is the one thing on it that may never be guessed at. */
.turn-banner__who {
  display: block;
  min-width: 0;
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  line-height: var(--lh-tight);
  color: color-mix(in srgb, var(--pc, var(--accent)) 82%, var(--text));
  overflow-wrap: break-word;
  hyphens: none;
}

/* The stage word is printed in the pill; keep the plain copy for assistive tech
   and the harnesses without saying it twice on screen. */
.turn-banner__what {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.turn-banner__stage {
  grid-column: 2;
  grid-row: 1;
  padding: 0 var(--sp-2);
  font-family: var(--font-display);
  font-size: var(--fs-xs);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-label);
  white-space: nowrap;
  color: var(--on-accent);
  background: var(--accent);
  border-radius: var(--r-pill);
}

.turn-banner.is-mine .turn-banner__stage { color: var(--on-ok); background: var(--ok); }

.turn-banner__read,
.turn-banner__sub,
.turn-banner__hint {
  grid-column: 1 / -1;
  min-width: 0;
}

.turn-banner__read {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-top: var(--sp-1);
}

.turn-banner__lines { min-width: 0; }

.turn-banner__big {
  display: block;
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.turn-banner__sub {
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  font-weight: 900;
  letter-spacing: var(--track-caps);
  text-transform: uppercase;
  color: #F3D9FF;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.turn-banner__hint {
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  color: var(--text-dim);
}

/* ---- the last thing that happened ---- */

.last-result {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: var(--sp-1) var(--sp-3);
  border: 2px solid var(--border-strong);
  border-left: 6px solid var(--pc, var(--violet));
  border-radius: var(--r-md);
  background: rgba(10, 3, 24, 0.5);
}

.last-result__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 var(--sp-2);
  min-width: 0;
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  font-weight: 900;
  line-height: 1.14;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
}

.last-result__glyph {
  font-family: var(--font-emoji);
  font-size: var(--fs-sm);
  flex: 0 0 auto;
}

.last-result__who {
  flex: 0 0 auto;
  color: color-mix(in srgb, var(--pc, var(--text)) 78%, var(--text));
}

.last-result__what {
  min-width: 0;
  color: var(--text);
  overflow-wrap: break-word;
}

.last-result__detail {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-dim);
}

.last-result--drink,
.last-result--setback {
  border-color: var(--danger);
  border-left-color: var(--danger);
  background: linear-gradient(180deg, var(--danger-dim), rgba(10, 3, 24, 0.5));
}

.last-result--drink .last-result__detail,
.last-result--setback .last-result__detail { color: var(--danger-hi); }

.last-result--score { border-color: color-mix(in srgb, var(--prize) 60%, transparent); }
.last-result--score .last-result__detail { color: var(--prize); }
.last-result--water { border-color: color-mix(in srgb, var(--info) 60%, transparent); }
.last-result--win { border-color: var(--ok); background: linear-gradient(180deg, var(--ok-dim), rgba(10, 3, 24, 0.5)); }

/* ---- the controls ---- */

/* display is owned by the data-screen router above; re-declaring it here would
   unhide the dock. */
.dock {
  flex: 0 0 auto;
  flex-direction: column;
  align-items: stretch;
  gap: var(--sp-2);
}

.dock > div {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}

.dock__controls > .btn { flex: 1 1 8rem; }

.dock__you {
  justify-content: center;
  padding-top: var(--sp-2);
  border-top: var(--bd-thin);
}

.dock__you-label {
  font-family: var(--font-display);
  font-size: var(--fs-xs);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-label);
  color: var(--text-faint);
}

/* ---- the roll cue ---- */

/* The roll is the one thing the game ever waits on a person for, so it is asked
   for in the middle of the screen rather than in a corner. It sits over the
   board, above the toast lane, and clears itself the moment the die is thrown. */
/* Anchored to the middle of the screen, not lifted off the bottom edge — at
   1600x900 the old offset put it two thirds of the way down, which reads as
   another dock rather than a call to act. */
.cue-slot {
  position: fixed;
  /* Centred on the board, not the viewport — the rail owns the right-hand
     column, so a viewport-centred cue lands noticeably right of the board. */
  left: calc((100vw - var(--rail-w)) / 2);
  top: 50%;
  z-index: 52;
  display: flex;
  justify-content: center;
  width: max-content;
  max-width: min(38rem, calc(100vw - var(--sp-5)));
  transform: translate(-50%, -50%);
  pointer-events: none;
}

body:not([data-screen="game"]) .cue-slot,
.cue-slot:empty { display: none; }

.cue {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
  pointer-events: auto;
  text-align: center;
}

.cue--mine {
  min-width: min(30rem, calc(100vw - var(--sp-5)));
  padding: var(--sp-5) var(--sp-6) var(--sp-6);
  background: rgba(10, 3, 24, 0.96);
  border: 3px solid var(--ok);
  border-radius: var(--r-lg);
  box-shadow: 0 8px 0 var(--slab-deep), 0 0 70px -14px var(--ok);
  animation: cue-breathe var(--dur-breathe) var(--ease-in-out) var(--anim-iter) alternate;
}

@keyframes cue-breathe {
  from { box-shadow: 0 8px 0 var(--slab-deep), 0 0 50px -18px var(--ok); }
  to { box-shadow: 0 8px 0 var(--slab-deep), 0 0 90px -8px var(--ok); }
}

.cue__eyebrow {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-label);
  color: color-mix(in srgb, var(--pc, var(--accent)) 80%, var(--text));
  overflow-wrap: break-word;
}

.cue__btn {
  width: 100%;
  min-height: calc(var(--ctl-h-big) * 1.45);
  font-size: var(--fs-3xl);
  padding: var(--sp-4) var(--sp-6);
}

.cue__hint {
  font-size: var(--fs-base);
  line-height: var(--lh-snug);
  color: var(--text-dim);
}

/* Waiting is not an event. Everyone who is not holding the dice gets one quiet
   line in the same place, so the screen always answers "who are we on?". */
.cue--wait {
  flex-direction: row;
  gap: var(--sp-2);
  padding: var(--sp-1) var(--sp-4);
  font-size: var(--fs-sm);
  color: var(--text-dim);
  background: rgba(10, 3, 24, 0.82);
  border: 2px solid var(--border);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-stamp);
}

.cue__dot {
  flex: 0 0 auto;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--accent);
  animation: conn-blink var(--dur-blink) var(--ease-in-out) var(--anim-iter) alternate;
}

.cue__wait { min-width: 0; }
.cue__who { color: color-mix(in srgb, var(--pc, var(--accent)) 82%, var(--text)); }

@media (max-width: 560px) {
  .cue-slot { bottom: var(--sp-4); }
  .cue-slot { left: 50%; max-width: calc(100vw - var(--sp-4)); }
  .cue--mine { min-width: 0; }
  .cue__btn { font-size: var(--fs-xl); padding: var(--sp-3) var(--sp-4); }
}

/* ---- why a number happened ---- */

/* A number with no reason next to it is the one thing players complained about.
   It reads on cream card stock and on the claret setback card, so every colour
   here is mixed off the surface's own text colour. */
.why-block {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding: var(--sp-2) var(--sp-3);
  border: 2px solid color-mix(in srgb, currentColor 22%, transparent);
  border-left: 6px solid var(--danger);
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
}

.why-block__head {
  font-family: var(--font-display);
  font-size: var(--fs-xs);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-label);
  color: color-mix(in srgb, currentColor 70%, transparent);
}

.why {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.why__row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 var(--sp-2);
  min-width: 0;
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
}

.why__glyph { font-family: var(--font-emoji); }

.why__amt {
  font-family: var(--font-mono);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.why__who {
  font-family: var(--font-display);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: color-mix(in srgb, var(--pc, currentColor) 58%, currentColor);
}

.why__cause { min-width: 0; overflow-wrap: break-word; }

/* ---- utilities ---- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* The skip link is .sr-only until it is tabbed to, then it has to be visible. */
.sr-only:focus-visible {
  position: fixed;
  top: var(--sp-2);
  left: var(--sp-2);
  z-index: 90;
  width: auto;
  height: auto;
  margin: 0;
  padding: var(--sp-2) var(--sp-3);
  clip-path: none;
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  text-transform: uppercase;
  color: var(--on-accent);
  background: var(--accent);
  border-radius: var(--r-pill);
}

.muted { color: var(--text-dim); }

.rule {
  height: 2px;
  border: 0;
  margin: var(--sp-3) 0;
  border-radius: var(--r-pill);
  background: var(--border);
}

.stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.row { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.chip-row { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.spacer { flex: 1 1 auto; }

/* ---- buttons ---- */

/* Every button is a lit key: pill, keyline in its own colour, hard slab it drops
   into when you press it. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--ctl-h);
  padding: var(--sp-1) var(--sp-4);
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: var(--text);
  background-color: rgba(10, 3, 24, 0.5);
  background-image: var(--fill-control);
  border: 2px solid var(--border-strong);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-press);
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast), filter var(--dur-fast);
}

.btn:hover { filter: brightness(1.18); }

.btn:active {
  transform: translateY(var(--press-travel));
  box-shadow: var(--shadow-press-down);
}

.btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  transform: none;
  box-shadow: var(--shadow-stamp);
  filter: none;
}

.btn--primary {
  color: var(--on-ok);
  background-color: var(--ok);
  background-image: var(--fill-accent);
  border-color: var(--ok);
  box-shadow: 0 5px 0 var(--slab-deep), 0 0 26px -6px var(--ok);
}

.btn--primary:hover { background-image: var(--fill-accent-hover); }

.btn--ghost {
  color: var(--text-dim);
  background-image: none;
}

.btn--ghost:hover { color: var(--text); }

.btn--danger {
  color: var(--on-danger);
  background-color: var(--danger);
  background-image: var(--fill-danger);
  border-color: var(--danger);
  box-shadow: 0 5px 0 var(--slab-deep), 0 0 28px -6px var(--danger);
}

.btn--big {
  min-height: var(--ctl-h-big);
  padding: var(--sp-2) var(--sp-5);
  font-size: var(--fs-lg);
}

/* The top bar's way in to the rules. Quiet, but never hidden. */
.btn--help {
  min-height: var(--ctl-h-sm);
  padding: 0 var(--sp-3);
  font-size: var(--fs-xs);
  letter-spacing: var(--track-label);
  color: var(--prize);
  border-color: color-mix(in srgb, var(--prize) 55%, transparent);
  box-shadow: var(--shadow-stamp);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
}

.btn-row--end { justify-content: flex-end; }
.btn-row--between { justify-content: space-between; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--ctl-h-sm);
  height: var(--ctl-h-sm);
  padding: 0;
  font-family: var(--font-emoji);
  font-size: var(--fs-sm);
  line-height: 1;
  color: var(--text);
  background: rgba(10, 3, 24, 0.5);
  border: 2px solid var(--border-strong);
  border-radius: 50%;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast);
}

.icon-btn:active { transform: translateY(2px); }

/* ---- fields ---- */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  min-width: 0;
}

/* An unlabelled field that has to share a row with a button. */
.field--flush { flex: 1 1 16rem; }

.field__label {
  font-family: var(--font-display);
  font-size: var(--fs-xs);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-label);
  color: var(--accent-hi);
}

.field__hint {
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  color: var(--text-dim);
}

.field__ticks {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-2);
  font-family: var(--font-display);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: var(--track-label);
  color: var(--text-faint);
}

.input,
.select {
  width: 100%;
  min-height: var(--ctl-h);
  padding: var(--sp-1) var(--sp-3);
  font-family: var(--font-body);
  font-size: var(--fs-md);
  color: var(--text);
  background: rgba(10, 3, 24, 0.6);
  border: 2px solid var(--border-strong);
  border-radius: var(--r-md);
}

.input--mono {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  letter-spacing: 0.03em;
}

.input::placeholder { color: var(--text-faint); }

.input:hover,
.select:hover { border-color: var(--violet); }

.select {
  font-family: var(--font-mono);
  appearance: none;
  padding-right: var(--sp-5);
}

.range {
  width: 100%;
  height: var(--ctl-h-thin);
  appearance: none;
  background: transparent;
  cursor: pointer;
}

.range::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: var(--r-pill);
  background-image: var(--fill-prize);
  border: 2px solid var(--slab-deep);
}

.range::-moz-range-track {
  height: 8px;
  border-radius: var(--r-pill);
  background-image: var(--fill-prize);
  border: 2px solid var(--slab-deep);
}

.range::-webkit-slider-thumb {
  appearance: none;
  width: 1.3rem;
  height: var(--ctl-h-thin);
  margin-top: -0.45rem;
  border-radius: var(--r-pill);
  background-image: var(--fill-accent);
  border: 2px solid var(--slab-deep);
}

.range::-moz-range-thumb {
  width: 1.3rem;
  height: var(--ctl-h-thin);
  border-radius: var(--r-pill);
  background-image: var(--fill-accent);
  border: 2px solid var(--slab-deep);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
}

.switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch__track {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  width: 3.2rem;
  height: var(--ctl-h-thin);
  border-radius: var(--r-pill);
  background: rgba(10, 3, 24, 0.7);
  border: 2px solid var(--border-strong);
  transition: background-color var(--dur-fast), border-color var(--dur-fast);
}

.switch__knob {
  position: absolute;
  top: 1px;
  left: 1px;
  width: calc(var(--ctl-h-thin) - 8px);
  height: calc(var(--ctl-h-thin) - 8px);
  border-radius: 50%;
  background: var(--text-faint);
  transition: transform var(--dur-fast) var(--ease-pop), background var(--dur-fast);
}

.switch__label { line-height: var(--lh-snug); }

.switch input:checked ~ .switch__track {
  background: color-mix(in srgb, var(--ok) 35%, transparent);
  border-color: var(--ok);
}

.switch input:checked ~ .switch__track .switch__knob {
  transform: translateX(calc(3.2rem - var(--ctl-h-thin) - 2px));
  background: var(--ok);
}

.switch input:focus-visible ~ .switch__track {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.swatch {
  width: var(--ctl-h-sm);
  height: var(--ctl-h-sm);
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.6);
  background-color: var(--pc, var(--text-faint));
  box-shadow: 0 0 14px -3px var(--pc, transparent);
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-pop), box-shadow var(--dur-fast);
}

.swatch:hover { transform: translateY(-2px); }

.swatch.is-on {
  transform: translateY(-2px) scale(1.1);
  box-shadow: 0 0 0 3px var(--ink), 0 0 0 5px #FFF1F7, 0 0 20px var(--pc, transparent);
}

.swatch:disabled {
  opacity: 0.28;
  cursor: not-allowed;
  transform: none;
}

/* ---- panels & modals ---- */

.panel {
  border: var(--bd-key);
  border-radius: var(--r-lg);
  background-image: var(--fill-surface);
  box-shadow: var(--shadow-lift);
  min-width: 0;
}

.panel__head {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: var(--bd-thin);
}

.panel__title {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: var(--text);
}

/* A level-1 heading only ever appears on a screen that owns the whole viewport,
   so it gets to be the loudest thing on it. */
h1.panel__title {
  font-size: var(--fs-2xl);
  color: var(--accent);
  text-shadow: 0 0 34px color-mix(in srgb, var(--accent) 60%, transparent);
}

.panel__aside {
  margin-left: auto;
  font-size: var(--fs-sm);
  color: var(--text-dim);
}

.panel__body {
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.panel__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-top: var(--bd-thin);
}

/* The lit panel: the screens before the game, and anything that has to be the
   one thing you look at. Cream is reserved for a card that gets dealt. */
.panel--paper {
  border-color: var(--accent);
  box-shadow: var(--shadow-lift), 0 0 60px -18px var(--accent);
}

.panel--paper .panel__head { border-bottom-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.panel--paper .panel__foot { border-top-color: color-mix(in srgb, var(--accent) 40%, transparent); }

.notice {
  padding: var(--sp-3) var(--sp-4);
  border: 2px solid var(--ok);
  border-radius: var(--r-md);
  background: var(--ok-dim);
  color: var(--text);
}

.notice--warn { border-color: var(--danger); background: var(--danger-dim); }

.notice__title {
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: var(--ok);
}

.notice--warn .notice__title { color: var(--danger-hi); }

.wait { color: var(--text-dim); }

.wait__text {
  margin: 0;
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
}

.wait__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: var(--accent-hi);
}

/* With a title it holds a whole region open; without one it is a single line. */
.wait--block {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-3);
  border: 2px dashed var(--border);
  border-radius: var(--r-md);
  text-align: center;
}

/* ---- chips, stats, marks and the room stamp ---- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-3);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--text);
  background: rgba(10, 3, 24, 0.5);
  border: 2px solid var(--border-strong);
  border-radius: var(--r-pill);
}

.chip__label,
.stat__label {
  font-family: var(--font-emoji);
  font-size: var(--fs-xs);
  font-weight: 900;
  letter-spacing: var(--track-caps);
  color: var(--text-faint);
}

.chip__value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chip--score { color: var(--prize); border-color: color-mix(in srgb, var(--prize) 55%, transparent); }
.chip--score .chip__label { color: var(--prize); }
.chip--drink { color: var(--danger-hi); border-color: color-mix(in srgb, var(--danger) 55%, transparent); }
.chip--drink .chip__label { color: var(--danger-hi); }
.chip--pos { color: var(--text-dim); }
.chip--paper { color: var(--text); }

.stat {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0 var(--sp-1);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  border-radius: var(--r-sm);
}

.stat__value { font-weight: 700; }

.stat--score { color: var(--prize); }
.stat--drink { color: var(--danger-hi); }
.stat--pos { gap: 0; color: var(--text-faint); }
.stat--pos .stat__label { color: inherit; }
.stat--dim { color: var(--text-dim); }

.mark {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 0 var(--sp-2);
  font-family: var(--font-display);
  font-size: var(--fs-xs);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  white-space: nowrap;
  color: var(--text);
  background: rgba(10, 3, 24, 0.5);
  border: 2px solid var(--border-strong);
  border-radius: var(--r-pill);
}

.mark__glyph { font-family: var(--font-emoji); }

.mark--host { color: var(--on-accent); background: var(--accent); border-color: var(--accent); }
.mark--practice { color: var(--ink); background: var(--wild); border-color: var(--wild); }
.mark--offline { color: var(--text-faint); border-color: var(--border); }
.mark--shot { color: var(--on-danger); background: var(--danger); border-color: #20000A; }

/* The deck stamp on a prompt card, which is the one cream surface in the set. */
.mark--deck {
  align-self: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-1) var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
}

.stamp {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
  padding: 0 var(--sp-3);
  border: 2px solid var(--border-strong);
  border-radius: var(--r-md);
  background: rgba(10, 3, 24, 0.65);
}

button.stamp {
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast);
}

button.stamp:active { transform: translateY(2px); }

.stamp__label {
  font-family: var(--font-display);
  font-size: var(--fs-xs);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-label);
  color: var(--violet-hi);
}

/* The trailing letter-space is pushed back with an equal indent so the code sits square. */
.stamp__code {
  font-family: var(--font-mono);
  font-size: var(--fs-lg);
  font-weight: 800;
  line-height: var(--lh-tight);
  letter-spacing: var(--track-code);
  text-indent: var(--track-code);
  color: var(--text);
  text-shadow: 0 0 18px var(--halo);
  user-select: all;
  -webkit-user-select: all;
}

.stamp--lg {
  gap: var(--sp-3);
  padding: 0 var(--sp-3);
}

.stamp--lg .stamp__code { font-size: var(--fs-xl); }

/* On a screen of its own the code is the thing you read out, so it stacks and
   takes the size that carries across a call. */
.screen .stamp--lg {
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: var(--sp-1) var(--sp-4);
}

.screen .stamp--lg .stamp__code { font-size: var(--fs-2xl); }

/* ---- seats ---- */

.roster {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  /* A sideways scrollbar here would eat a whole seat out of the panel. */
  overflow-x: hidden;
  padding: var(--sp-1) var(--sp-1);
}

.seat {
  display: grid;
  align-items: center;
  gap: var(--sp-1) var(--sp-2);
  min-width: 0;
  transition: background var(--dur-fast), opacity var(--dur-fast);
}

/* A seat keeps its full height and the panel scrolls; a squeezed standings row
   is worse than one you have to scroll to. */
.roster > .seat { flex: 0 0 auto; }

.seat__dot {
  width: 0.85rem;
  height: 0.85rem;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--pc, var(--text-faint));
  box-shadow: 0 0 10px -1px var(--pc, transparent);
}

.seat__name {
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat__marks,
.seat__stats,
.seat__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-1);
  min-width: 0;
}

/* The standings row: the name on its own line in the seat's own colour, the
   numbers under it. The rail is too narrow to run both across one line without
   truncating a name, and the name is the thing you look for. */
.seat--score {
  position: relative;
  grid-template-columns: 1.1rem auto minmax(0, 1fr);
  gap: 0 var(--sp-2);
  padding: var(--sp-1) var(--sp-2) var(--sp-1) var(--sp-3);
  border: 2px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-well);
  overflow: hidden;
}

/* The seat colour, run up the edge of the row. */
.seat--score::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  background: var(--pc, var(--text-faint));
}

.seat--score .seat__num {
  font-family: var(--font-display);
  font-size: var(--fs-xs);
  font-weight: 900;
  color: var(--text-faint);
}

.seat--score .seat__name {
  min-width: 0;
  font-size: var(--fs-md);
  color: var(--pc, var(--text));
}

.seat--score .seat__marks,
.seat--score .seat__stats { grid-column: 1 / -1; }

.seat--score .seat__stats {
  flex-wrap: nowrap;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
}

.seat--score.is-active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  box-shadow: 0 0 20px -8px var(--accent);
}

.seat--score.is-you .seat__name { text-decoration: underline; text-decoration-thickness: 2px; }

.seat--score.is-leader {
  border-color: var(--prize);
  background: color-mix(in srgb, var(--prize) 13%, transparent);
}

.seat--score.is-leader .stat--score { text-shadow: 0 0 14px color-mix(in srgb, var(--prize) 80%, transparent); }

.seat--score.is-offline { opacity: 0.45; }

.seat--score.is-finished { border-color: var(--ok); background: var(--ok-dim); }

/* Roster tile: kept for any caller that still wants the compact form. */
.seat--chip {
  grid-template-columns: auto minmax(0, 1fr) auto;
  padding: var(--sp-2) var(--sp-3);
  border: var(--bd-key);
  border-radius: var(--r-md);
  background: rgba(10, 3, 24, 0.4);
}

.seat--chip .seat__stats { grid-column: 1 / -1; }

/* Register line: one entry per seat in the lobby. Flex, not grid, so a long
   name and its badges wrap onto a second line instead of squeezing each other
   out — the row height follows its content. */
.seat--register {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-1) var(--sp-3);
  min-height: var(--seat-row);
  padding: var(--sp-1) var(--sp-2);
  color: var(--text);
  border-bottom: 2px solid var(--border);
}

.seat--register .seat__name { flex: 0 1 auto; min-width: 4ch; color: var(--pc, var(--text)); }
.seat--register .seat__marks { flex: 1 1 auto; }
.seat--register .seat__actions { margin-left: auto; }
.seat--register:last-child { border-bottom: 0; }

.seat--register .seat__num {
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  font-weight: 900;
  color: var(--text-faint);
}

/* Buttons inside the register keep the row rhythm. */
.seat--register .btn {
  min-height: calc(var(--seat-row) - var(--sp-2));
  padding: 0 var(--sp-3);
  font-size: var(--fs-xs);
  box-shadow: var(--shadow-stamp);
}

.seat--register.is-you { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.seat--register.is-offline { opacity: 0.55; }

/* ---- lobby ---- */

/* One surface: the invite band, three regions, and the action rail pinned to
   the bottom. Above 1100px it is sized to the viewport so the host never
   scrolls to reach Deal the board; each region scrolls on its own if the
   content outgrows it. */
.lobby {
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  border: var(--bd-key);
  border-radius: var(--r-lg);
  background-image: var(--fill-surface);
  box-shadow: var(--shadow-lift);
  overflow: hidden;
}

.lobby__band {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-4);
  padding: var(--sp-2) var(--sp-4);
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 20%, transparent), transparent);
  border-bottom: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
}

.lobby__intro { flex: 0 1 auto; min-width: 0; }

.lobby__title {
  font-size: var(--fs-xl);
  color: var(--accent);
  text-shadow: 0 0 28px color-mix(in srgb, var(--accent) 60%, transparent);
}

.lobby__sub {
  margin: 0;
  font-size: var(--fs-sm);
  color: var(--text-dim);
}

.lobby__invite {
  flex: 1 1 20rem;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}

.lobby__ident {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.lobby__cols {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  flex: 1;
  min-height: 0;
}

.lobby__region {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: var(--sp-3) var(--sp-4);
  border-top: var(--bd-thin);
}

.lobby__region:first-child { border-top: 0; }

.lobby__region .panel__head { padding: 0 0 var(--sp-1); border-bottom: 0; }
.lobby__region .panel__title { font-size: var(--fs-md); color: var(--accent-hi); }
.lobby__region .stack { gap: var(--sp-2); }
.lobby__region .field__hint { font-size: var(--fs-xs); }
.lobby__region .switch__label { font-size: var(--fs-sm); }

/* The guest list. */
.register {
  flex: 1;
  min-height: var(--seat-row);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 var(--sp-2);
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  background: rgba(10, 3, 24, 0.4);
}

.lobby__rail {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-4);
  border-top: var(--bd-key);
  background: rgba(10, 3, 24, 0.45);
}

.lobby__status {
  margin: 0;
  min-width: 0;
  font-size: var(--fs-sm);
  color: var(--text-dim);
}

@media (min-width: 1100px) {
  body[data-screen="lobby"] .app {
    height: 100vh;
    overflow: hidden;
  }

  body[data-screen="lobby"] .screen {
    width: 100%;
    max-width: 96rem;
    padding: var(--sp-3);
    overflow: hidden;
  }

  .lobby { flex: 1; }

  .lobby__cols {
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) minmax(0, 1fr);
  }

  .lobby__region {
    border-top: 0;
    border-left: var(--bd-thin);
  }

  .lobby__region:first-child { border-left: 0; }
}

/* ---- die ---- */

.dice-stage { pointer-events: none; }

.die {
  display: inline-grid;
  place-items: center;
  width: 4.2rem;
  height: 4.2rem;
  padding: var(--sp-2);
  border: 3px solid #180530;
  border-radius: var(--r-md);
  background: linear-gradient(158deg, #FFF9F2, #FFDCEC);
  box-shadow: 0 5px 0 var(--accent-deep), 0 0 30px -4px var(--accent);
}

.die__face {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  place-items: center;
  gap: 2px;
  width: 100%;
  height: 100%;
}

.die__pip {
  width: 0.62rem;
  height: 0.62rem;
  border-radius: 50%;
  background: #20082F;
}

/* The die on the rail, cocked the way a thrown die lands. */
.die--mini {
  flex: 0 0 auto;
  width: 2.3rem;
  height: 2.3rem;
  padding: 4px;
  border-width: 2px;
  border-radius: var(--r-sm);
  transform: rotate(-7deg);
  box-shadow: 0 3px 0 var(--accent-deep), 0 0 18px -4px var(--accent);
}

.die--mini .die__pip { width: 0.34rem; height: 0.34rem; }

.die.is-rolling { animation: die-tumble var(--dur-roll) var(--ease-in-out) var(--anim-iter); }

@keyframes die-tumble {
  0% { transform: rotate(0deg) translateY(0); }
  25% { transform: rotate(-14deg) translateY(-0.6rem); }
  50% { transform: rotate(11deg) translateY(0.1rem); }
  75% { transform: rotate(-6deg) translateY(-0.3rem); }
  100% { transform: rotate(0deg) translateY(0); }
}

.dice-label {
  margin-top: 3.2rem;
  padding: var(--sp-1) var(--sp-4);
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: var(--text);
  background: rgba(10, 3, 24, 0.85);
  border: 2px solid var(--accent);
  border-radius: var(--r-pill);
  box-shadow: 0 0 34px -8px var(--accent);
}

/* ---- overlay & modals ---- */

/* The track has to be an explicit minmax(0, 1fr). In an auto track the modal's
   `width: min(Xrem, 100%)` resolves against max-content instead of the grid
   area, and a long line of card text pushes the whole page sideways. */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: var(--sp-4);
  background: var(--scrim);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur-fade) linear, visibility 0s linear var(--dur-fade);
}

.overlay.is-open {
  opacity: 1;
  visibility: visible;
  transition-delay: 0s, 0s;
}

/* The minigame overlay is the second one in the document and always sits over the prompt. */
.overlay + .overlay { z-index: 61; }

.modal {
  position: relative;
  width: min(54rem, 100%);
  max-height: calc(100vh - var(--sp-5));
  display: flex;
  flex-direction: column;
  color: var(--text);
  background-color: var(--surface);
  background-image: var(--fill-surface);
  border: var(--bd-key);
  border-radius: var(--r-lg);
  box-shadow: 0 10px 0 var(--slab-deep), 0 0 80px -20px var(--halo);
  transform: translateY(0.8rem) scale(0.98);
  transition: transform var(--dur-mid) var(--ease-pop);
}

.overlay.is-open .modal { transform: none; }

.modal__head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-4);
  border-bottom: var(--bd-thin);
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: var(--text);
}

.modal__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--sp-4) var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.modal__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-top: var(--bd-thin);
}

/* A prompt is the one printed thing in a lit room: cream card stock with a hot
   pink header, dealt at a slight angle so it reads as an object. */
.modal--prompt {
  color: var(--text-alt);
  background-color: var(--surface-alt);
  background-image: var(--fill-surface-alt);
  border-color: #20000A;
  box-shadow: 0 11px 0 var(--accent-deep), 0 24px 44px rgba(0, 0, 0, 0.65), 0 0 70px -10px var(--accent);
}

.modal--prompt .modal__head {
  color: var(--on-accent);
  background: var(--accent);
  border-bottom: 0;
}

.modal--prompt .panel__title { color: var(--text-alt); }
.modal--prompt .modal__foot { border-top-color: rgba(27, 10, 46, 0.18); }
.modal--prompt .muted,
.modal--prompt .wait { color: var(--text-alt-dim); }
.modal--prompt .wait__title { color: var(--accent-deep); }
.modal--prompt .chip { color: var(--text-alt); background: rgba(27, 10, 46, 0.07); border-color: rgba(27, 10, 46, 0.28); }
.modal--prompt .chip--paper { color: var(--text-alt); }
.modal--prompt .btn--ghost { color: var(--text-alt-dim); border-color: rgba(27, 10, 46, 0.32); }
.modal--prompt .btn--ghost:hover { color: var(--text-alt); }

.modal--minigame {
  width: min(70rem, 100%);
  min-height: min(38rem, 82vh);
}

.modal--setback { width: min(42rem, 100%); }
.modal--setback .modal__head { color: var(--on-danger); background: var(--danger); border-bottom: 0; }
.modal--setback .prompt-text { color: var(--danger-hi); }

.modal--rules { width: min(46rem, 100%); }
.modal--rules .modal__head { color: var(--on-accent); background: var(--accent); border-bottom: 0; }

/* ---- the shot ---- */

/* The biggest moment on the board. It arrives, rather than appears. */
.modal--shot {
  width: min(44rem, 100%);
  color: #FFF1F7;
  background-color: var(--blaze);
  background-image: linear-gradient(170deg, var(--blaze-hi) 0%, var(--blaze) 38%, var(--blaze-deep) 100%);
  border: 3px solid #20000A;
  box-shadow: 0 12px 0 rgba(0, 0, 0, 0.65), 0 0 100px -10px var(--blaze);
  animation: shot-slam var(--dur-slow) var(--ease-pop) both;
}

@keyframes shot-slam {
  0% { transform: translateY(-16%) scale(0.78) rotate(-3deg); opacity: 0; }
  62% { transform: translateY(0) scale(1.03) rotate(0.7deg); opacity: 1; }
  100% { transform: none; }
}

.modal--shot .modal__head {
  color: #1A0004;
  background: var(--hazard);
  border-bottom: 3px solid #20000A;
}

.modal--shot .modal__body { gap: var(--sp-4); }
.modal--shot .modal__foot { border-top-color: rgba(0, 0, 0, 0.4); }
.modal--shot .prompt-text { color: #FFF1F7; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35); }
.modal--shot .wait { color: #FFD9E1; }

/* On the red card the primary action is the hazard plate, not the green key —
   green on this surface reads as "everything is fine". */
.modal--shot .btn--primary {
  color: #1A0004;
  background-color: var(--hazard);
  background-image: linear-gradient(180deg, var(--sun-hi), var(--hazard) 60%);
  border-color: #20000A;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.55), 0 0 30px -6px var(--hazard);
}

.shot-note {
  margin: 0;
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  color: #1A0004;
  background: var(--hazard);
  border-radius: var(--r-sm);
}

.prompt-text {
  font-family: var(--font-display);
  font-size: var(--fs-prompt);
  font-weight: 900;
  line-height: var(--lh-tight);
  letter-spacing: var(--track-caps);
  color: var(--text-alt);
  text-wrap: balance;
}

.modal .prompt-text { text-transform: none; }

.intensity {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
}

.intensity__pip {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  border: 2px solid var(--on-accent);
  background: transparent;
}

.intensity__pip.is-on { background: var(--on-accent); }

/* A clock face on the dealt card: one square box, a masked ring drawn edge to
   edge inside it, and the number stacked in the same grid cell as a sibling.
   Every measurement comes off --timer-size, so the ring, the band and the
   numerals stay in proportion at any size. */
.timer {
  --timer-size: 5.6rem;
  --timer-band: calc(var(--timer-size) * 0.15);
  --timer-lit: var(--ok-deep);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  align-self: center;
  width: var(--timer-size);
  height: var(--timer-size);
  aspect-ratio: 1;
  border: 3px solid var(--accent-deep);
  border-radius: 50%;
}

/* --pct runs 1 → 0 as the clock drains and drives the conic sweep; the drained
   part stays as a faint track so the face reads as a ring even at zero. The
   mask punches the middle out, which is why the number can never live in here. */
.timer__ring {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background:
    conic-gradient(from -90deg,
      var(--timer-lit) 0 calc(var(--pct, 1) * 360deg),
      color-mix(in srgb, currentColor 16%, transparent) calc(var(--pct, 1) * 360deg) 360deg);
  /* The stencil's colour is irrelevant — only its alpha is read. */
  -webkit-mask: radial-gradient(closest-side,
    transparent calc(100% - var(--timer-band)),
    #000 calc(100% - var(--timer-band) + 1px));
  mask: radial-gradient(closest-side,
    transparent calc(100% - var(--timer-band)),
    #000 calc(100% - var(--timer-band) + 1px));
}

.timer__num {
  grid-area: 1 / 1;
  font-family: var(--font-display);
  font-size: calc(var(--timer-size) * 0.33);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: var(--track-caps);
  color: inherit;
}

/* Under ten seconds the ring goes hot; at zero it is spent. Both colours are
   the deep variants, because this face only ever sits on cream card stock. */
.timer.is-low { --timer-lit: var(--wild-deep); }
.timer.is-low .timer__num { color: var(--wild-deep); }
.timer.is-out { --timer-lit: var(--danger); }
.timer.is-out .timer__num { color: var(--danger); }

@media (max-width: 560px) {
  .timer { --timer-size: 4.6rem; }
}

/* ---- the vote ---- */

.modal--vote { width: min(48rem, 100%); }
.modal--vote .modal__head { color: var(--on-accent); background: var(--accent); border-bottom: 0; }

.modal--vote .modal__body {
  align-items: center;
  text-align: center;
  gap: var(--sp-2);
}

.vote__ask {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-label);
  color: var(--text-dim);
}

.vote__who {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  line-height: var(--lh-tight);
  color: color-mix(in srgb, var(--pc, var(--accent)) 85%, var(--text));
  text-shadow: 0 0 40px color-mix(in srgb, var(--pc, var(--accent)) 55%, transparent);
}

.vote__quote {
  margin: 0;
  max-width: min(44ch, 100%);
  font-size: var(--fs-lg);
  line-height: var(--lh-snug);
  color: var(--text-dim);
  text-wrap: balance;
}

.vote-meter {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  width: 100%;
  max-width: 32rem;
}

.vote-meter__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
}

.vote-meter__tick {
  display: inline-flex;
  align-items: baseline;
  gap: var(--sp-2);
  font-family: var(--font-display);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
}

.vote-meter__num {
  font-size: var(--fs-2xl);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.vote-meter__tick--yes .vote-meter__num { color: var(--ok); }
.vote-meter__tick--no .vote-meter__num { color: var(--danger-hi); }

.vote-meter__word {
  font-size: var(--fs-sm);
  color: var(--text-dim);
}

.vote-meter__count {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--text-faint);
}

.vote-meter__bar {
  display: flex;
  width: 100%;
  height: 1.3rem;
  border: 2px solid var(--border-strong);
  border-radius: var(--r-pill);
  background: rgba(10, 3, 24, 0.6);
  overflow: hidden;
}

.vote-meter__fill {
  height: 100%;
  transition: width var(--dur-mid) var(--ease-out);
}

.vote-meter__fill--yes { background: var(--ok); }
.vote-meter__fill--no { background: var(--danger); }

/* Yes and No get the whole width, split down the middle, at the size of a
   decision made across a room. */
.btn--verdict { flex: 1 1 12rem; }

.judge-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
}

.judge-who {
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: color-mix(in srgb, var(--pc, var(--accent)) 80%, var(--text));
}

/* ---- rules ---- */

.rules {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.rules__item {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border: var(--bd-thin);
  border-radius: var(--r-md);
  background: rgba(10, 3, 24, 0.4);
}

.rules__icon {
  flex: 0 0 auto;
  font-family: var(--font-emoji);
  font-size: var(--fs-lg);
  line-height: 1.1;
}

.rules__text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.rules__title {
  font-family: var(--font-display);
  font-size: var(--fs-md);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: var(--accent-hi);
}

.rules__body {
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  color: var(--text-dim);
}

/* The four ways each number happens, listed rather than buried in a sentence. */
.rules__list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: var(--sp-1) 0 0;
  padding: 0 0 0 var(--sp-4);
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  color: var(--text);
}

.rules__list li { list-style: "› "; padding-left: var(--sp-1); }

/* ---- results ---- */

.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: var(--sp-2);
  padding-top: var(--sp-2);
}

.podium__slot {
  flex: 1 1 0;
  max-width: 12rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-1);
  padding: var(--sp-3);
  text-align: center;
  color: var(--text);
  border-radius: var(--r-md) var(--r-md) 0 0;
  border: 2px solid var(--border-strong);
  border-top: 8px solid var(--pc, var(--violet));
  border-bottom: 0;
  background: rgba(10, 3, 24, 0.45);
}

.podium__slot--1 {
  min-height: 10rem;
  order: 2;
  border-color: var(--prize);
  border-top-color: var(--pc, var(--prize));
  background: color-mix(in srgb, var(--prize) 14%, rgba(10, 3, 24, 0.45));
  box-shadow: 0 0 50px -14px var(--prize);
}

.podium__slot--2 { min-height: 8rem; order: 1; }
.podium__slot--3 { min-height: 6.5rem; order: 3; }

.podium__place {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: var(--lh-tight);
}

.podium__slot--1 .podium__place { color: var(--prize); }

.podium__name {
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: var(--track-caps);
  color: var(--pc, var(--text));
}

.podium__line {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-dim);
}

/* The closing tab is the ledger read back at full size, so it needs its own
   column rhythm — the rail's ch widths are set for a much smaller face. */
.final-tab .panel__body { gap: 0; font-family: var(--font-mono); }

.final-tab .ledger-line {
  grid-template-columns: 4.5ch 6ch minmax(0, 1fr) auto;
  line-height: var(--lh-snug);
  min-height: 0;
  padding: var(--sp-2) 0;
  border-bottom: 2px solid var(--border);
}

.final-tab .ledger-line:last-child { border-bottom: 0; }

/* The closing tab has the whole screen, so it reads in full. */
.final-tab .ledger-line__text { white-space: normal; overflow-wrap: anywhere; }

/* ---- toast ---- */

.toast {
  position: fixed;
  left: 50%;
  bottom: var(--sp-5);
  z-index: 55;
  max-width: min(34rem, calc(100vw - var(--sp-5)));
  padding: var(--sp-3) var(--sp-4);
  font-family: var(--font-body);
  font-size: var(--fs-md);
  line-height: var(--lh-snug);
  color: var(--text);
  background: rgba(10, 3, 24, 0.94);
  border: 2px solid var(--prize);
  border-radius: var(--r-md);
  box-shadow: 0 6px 0 var(--slab-deep), 0 0 48px -12px var(--prize);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate(-50%, var(--sp-2));
  transition:
    opacity var(--dur-fade) linear,
    transform var(--dur-mid) var(--ease-pop),
    visibility 0s linear var(--dur-fade);
}

.toast.is-open {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
  transition-delay: 0s, 0s, 0s;
}

/* ---- narrow layouts ---- */

@media (max-width: 900px) {
  .stage {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
  }

  .rail { flex-direction: column; }
  .rail__block--score { max-height: none; }
  .rail__block--tab { flex: 0 0 auto; max-height: 10rem; }

  .dock__controls > .btn { flex: 1 1 10rem; }

  .toast { top: calc(var(--topbar-h) + var(--sp-3)); bottom: auto; }
}

@media (max-width: 560px) {
  .stage { padding: var(--sp-2); gap: var(--sp-2); }
  .screen { padding: var(--sp-4) var(--sp-3); }
  .topbar { padding: var(--sp-1) var(--sp-3); gap: var(--sp-2); }
  .brand__word { font-size: var(--fs-md); }
  .stamp__code { font-size: var(--fs-md); letter-spacing: 0.1em; text-indent: 0.1em; }
  .stamp--lg .stamp__code { font-size: var(--fs-lg); }
  .modal__body { padding: var(--sp-3); }
  .btn-row > .btn,
  .modal__foot > .btn { flex: 1 1 100%; }
  .lobby__rail { flex-direction: column; align-items: stretch; }
  .room { justify-content: center; }
  .seat--score { grid-template-columns: 1.3rem auto minmax(0, 1fr) auto; }
  .seat--score .seat__stats { grid-column: 1 / -1; justify-content: flex-start; }
  .podium__slot { padding: var(--sp-2); }
}

