/* Infinite Party · visual system (identity: docs/roadmap.md, R2, the taste guide).
   Every value is a token on :root. Player-facing text never lives here. */
@font-face {
  font-family: "Fredoka";
  src: url("fonts/fredoka.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}
:root {
  color-scheme: dark;
  /* Ground and panels */
  --ink: #1b1236;
  --ground-1: #3c2885;
  --ground-2: #5434b3;
  --ground-glow: #7455db;
  --panel: #291d59;
  --panel-2: #382768;
  --panel-side: #160e30;
  --line: #ffffff24;
  /* Text */
  --cream: #fff8ea;
  --cream-dim: #d9cdef;
  --gold: #ffe285;
  /* Actions */
  --yellow: #ffdb50;
  --yellow-press: #ffc53d;
  --lilac: #f3eaff;
  --good: #81e5b5;
  --warn: #ffb347;
  /* Players: ten colours, each with light, base and dark steps. Picked to stay
     apart under simulated deuteranopia and protanopia (closest pair: 2 and 5);
     a player is never identified by colour alone. */
  --p0: #bda1ff; --p0-light: #dbcbff; --p0-dark: #745eaa;
  --p1: #ff9873; --p1-light: #ffc6b2; --p1-dark: #945a64;
  --p2: #8edfb9; --p2-light: #c1edd8; --p2-dark: #5c7d87;
  --p3: #ffd968; --p3-light: #ffeaac; --p3-dark: #947a5e;
  --p4: #83cfe9; --p4-light: #bbe5f3; --p4-dark: #56759f;
  --p5: #f4a0c0; --p5-light: #f9cbdc; --p5-dark: #8e5d87;
  --p6: #e8892a; --p6-light: #f0bc85; --p6-dark: #854e38;
  --p7: #f4efe6; --p7-light: #f9f6f1; --p7-dark: #8f829e;
  --p8: #7a93f5; --p8-light: #b6c4fa; --p8-dark: #5e64bd;
  --p9: #b9dc62; --p9-light: #d8eca9; --p9-dark: #809a5e;
  /* Shape */
  --r-panel: 20px;
  --r-button: 16px;
  --outline: 3px;
  --side: 5px;
  /* Type */
  --font-display: "Fredoka", ui-rounded, system-ui, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", sans-serif;
  /* Motion */
  --t-fast: 120ms;
  --t-base: 220ms;
  --t-slow: 420ms;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-in: cubic-bezier(0.6, 0, 0.9, 0.4);
  --ease-pop: cubic-bezier(0.34, 1.56, 0.64, 1);
  /* Layout */
  --top-h: 44px;
  --bar-h: 32px;
  --deck-h: 200px;
  --gap: 10px;
  --button-h: 76px;
  --tint: #3c2885;
}
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-rows: var(--top-h) minmax(0, 1fr);
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
  background:
    radial-gradient(ellipse at 25% 17%, var(--ground-glow) 0, transparent 60%),
    linear-gradient(130deg, var(--ground-2), var(--tint) 82%);
  color: var(--cream);
  font: 600 15px/1.3 var(--font-body);
  -webkit-tap-highlight-color: transparent;
}
body[data-phase="break"] {
  --tint: #44308f;
}
body[data-phase="final"] {
  --tint: #6b2f7a;
}
button,
input {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--cream);
  outline-offset: 3px;
}
h1,
h2,
p {
  margin: 0;
}
[hidden] {
  display: none !important;
}
.icon {
  width: 1.3em;
  height: 1.3em;
  flex: none;
  vertical-align: -0.28em;
}
.icon .fill {
  fill: currentColor;
}

/* ---- Living background: slow drifting shapes, tinted per phase ---- */
.ground {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.ground i {
  position: absolute;
  width: 22vmax;
  height: 22vmax;
  border-radius: 38%;
  background: #ffffff;
  opacity: 0.035;
  animation: drift 46s ease-in-out infinite alternate;
}
.ground i:nth-child(1) { left: -6%; top: 8%; }
.ground i:nth-child(2) { left: 62%; top: -10%; width: 16vmax; height: 16vmax; border-radius: 50%; animation-duration: 58s; }
.ground i:nth-child(3) { left: 78%; top: 54%; animation-duration: 64s; animation-delay: -20s; }
.ground i:nth-child(4) { left: 18%; top: 70%; width: 12vmax; height: 12vmax; border-radius: 50%; animation-duration: 52s; }
.ground i:nth-child(5) { left: 40%; top: 30%; width: 9vmax; height: 9vmax; animation-duration: 70s; animation-delay: -35s; }
.ground i:nth-child(6) { left: 4%; top: 44%; width: 7vmax; height: 7vmax; border-radius: 50%; animation-duration: 40s; }
.ground i:nth-child(7) { left: 86%; top: 20%; width: 8vmax; height: 8vmax; animation-duration: 54s; animation-delay: -12s; }
.ground i:nth-child(8) { left: 55%; top: 82%; width: 14vmax; height: 14vmax; animation-duration: 62s; animation-delay: -28s; }
@keyframes drift {
  from { transform: translate(0, 0) rotate(0deg); }
  to { transform: translate(6vmax, -5vmax) rotate(40deg); }
}

/* ---- Top bar ---- */
.top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  min-width: 0;
}
.mark {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  flex: none;
  background: var(--yellow);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 9px;
  box-shadow: 0 3px 0 var(--ink);
  transform: rotate(-7deg);
}
.mark .icon {
  width: 20px;
  height: 20px;
  vertical-align: 0;
}
.titles {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.wordmark {
  font: 700 18px var(--font-display);
  white-space: nowrap;
  display: none;
}
h1 {
  font: 700 21px/1.1 var(--font-display);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 2px var(--ink);
}
.progress {
  display: flex;
  gap: 6px;
  flex: none;
}
.progress span {
  display: flex;
  gap: 3px;
}
.progress i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 2px solid var(--cream-dim);
  opacity: 0.75;
}
.progress i.done {
  background: var(--cream-dim);
}
.progress i.now {
  background: var(--yellow);
  border-color: var(--yellow);
  opacity: 1;
  transform: scale(1.35);
}
.icon-button {
  width: 40px;
  height: 40px;
  flex: none;
  display: grid;
  place-items: center;
  border: 2px solid #ffffff40;
  background: #ffffff10;
  border-radius: 12px;
  padding: 0;
}

/* A game with no deck buttons: the deck keeps one line (the status, or the
   emotes between rounds) and the stage takes the rest. */
body.bare {
  --deck-h: 72px;
}
/* ---- Shell ---- */
.shell {
  min-height: 0;
  display: grid;
  gap: var(--gap);
  padding: 0 var(--gap) var(--gap);
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) var(--deck-h);
  grid-template-areas: "stage" "deck";
}
.stage,
.deck,
.board {
  background: var(--panel);
  border: var(--outline) solid var(--ink);
  border-radius: var(--r-panel);
  box-shadow: 0 var(--side) 0 var(--panel-side);
}
.stage {
  grid-area: stage;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.bar {
  height: var(--bar-h);
  flex: none;
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
}
.conn {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--good);
}
.conn.off {
  background: var(--warn);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
  50% { opacity: 0.35; }
}
.clock {
  font: 600 17px var(--font-display);
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  gap: 5px;
}
/* Clock: warm and pulsing (transform set per frame) in the last 3 s. */
.clock {
  transform-origin: left center;
}
.clock.warm {
  color: var(--warn);
}
/* Time bar: drains along the bottom of the stage bar during play. */
.timebar {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 2px;
  height: 4px;
  border-radius: 2px;
  background: #ffffff1a;
  overflow: hidden;
}
.timebar b {
  display: block;
  height: 100%;
  background: var(--good);
  transform-origin: left;
}
.timebar.warm b {
  background: var(--warn);
}
.chip {
  margin-left: auto;
  border: 2px solid #ffffff40;
  background: #ffffff14;
  border-radius: 99px;
  padding: 2px 10px;
  font: 600 14px var(--font-display);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.scene {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #9edcd9;
  border-top: var(--outline) solid var(--ink);
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---- Deck: three exclusive states in a fixed-height box ---- */
.deck {
  grid-area: deck;
  position: relative;
  overflow: hidden;
}
.deck-state {
  position: absolute;
  inset: 0;
  padding: 12px;
  display: grid;
  align-content: end;
  gap: 8px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition:
    opacity var(--t-fast) var(--ease-in),
    transform var(--t-fast) var(--ease-in),
    visibility 0s var(--t-fast);
}
body[data-deck="idle"] .idle,
body[data-deck="play"] .play,
body[data-deck="result"] .result {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition:
    opacity var(--t-base) var(--ease-out),
    transform var(--t-base) var(--ease-out);
}
.caption {
  color: var(--cream-dim);
  font-size: 13px;
  text-align: center;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
/* Why the match cannot start: the room does not fit the game's player range. */
.caption.warn {
  color: var(--warn, #ffb347);
  font-weight: 600;
}
.primary[aria-disabled="true"] {
  opacity: 0.55;
  cursor: default;
}
.waiting {
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  font: 600 18px var(--font-display);
  color: var(--gold);
}
.secondary-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 8px;
}
.metrics {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 26px;
}
.metrics b {
  flex: 1;
  font: 600 16px var(--font-display);
}
.metrics span {
  color: var(--cream-dim);
  font-size: 14px;
}
.track {
  height: 6px;
  background: #514178;
  border-radius: 4px;
  overflow: hidden;
}
.track i {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--yellow);
  transform-origin: left;
  transform: scaleX(0);
}

/* ---- Buttons: chunky 2.5D, a solid darker side that compresses on press ---- */
.primary,
.controls button,
dialog button:not(.close):not(.secondary) {
  color: var(--ink);
  background: var(--yellow);
  border: var(--outline) solid var(--ink);
  border-radius: var(--r-button);
  box-shadow:
    inset 0 2px #ffffff8c,
    0 var(--side) 0 var(--ink);
  font: 700 20px var(--font-display);
  touch-action: none;
  -webkit-touch-callout: none;
  transition:
    transform var(--t-fast) var(--ease-out),
    box-shadow var(--t-fast) var(--ease-out);
}
.primary {
  min-height: 60px;
  font-size: 22px;
  position: relative;
  overflow: hidden;
}
/* Idle life: a slow sheen crosses the primary button every 4 s. */
.primary::after {
  content: "";
  position: absolute;
  inset: -20% auto -20% 0;
  width: 40%;
  background: linear-gradient(100deg, transparent, #ffffff8c, transparent);
  transform: translateX(-120%) skewX(-18deg);
  animation: sheen 4s var(--ease-out) infinite 1s;
  pointer-events: none;
}
@keyframes sheen {
  0% { transform: translateX(-120%) skewX(-18deg); }
  22%, 100% { transform: translateX(320%) skewX(-18deg); }
}
/* A rejected press shakes 4 px. */
.nope {
  animation: nope 240ms var(--ease-out);
}
@keyframes nope {
  20% { translate: -4px 0; }
  45% { translate: 4px 0; }
  70% { translate: -2px 0; }
  100% { translate: 0 0; }
}
/* FX layer: particles, flashes and wipes above everything, never in the way. */
canvas.fx {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  pointer-events: none;
  z-index: 50;
}
.controls {
  display: grid;
  gap: 12px;
}
.controls button {
  min-height: var(--button-h);
  padding: 6px 4px;
  font-size: 22px;
  line-height: 1.1;
}
.controls button:nth-child(2) {
  background: var(--lilac);
}
.primary:active,
.controls button:active,
.controls button.down,
dialog button:not(.close):not(.secondary):active {
  transform: translateY(var(--side));
  box-shadow: inset 0 2px #ffffff60;
  background: var(--yellow-press);
}
.controls button[aria-disabled="true"] {
  opacity: 0.55;
  cursor: default;
}
/* Offline: game buttons dim further and refuse presses (net banner shows). */
body.offline .controls button {
  opacity: 0.35;
  filter: saturate(0.4);
}
.controls button.ghost-down {
  opacity: 1;
}
.deck-state.play {
  overflow: hidden;
}
/* The how-to demo's ghost finger (position and opacity set per frame). */
.ghost {
  position: absolute;
  left: 0;
  top: 0;
  width: 56px;
  height: 56px;
  margin: -8px 0 0 -18px;
  color: var(--cream);
  opacity: 0;
  pointer-events: none;
  filter: drop-shadow(0 3px 0 var(--ink));
}
.ghost .icon {
  width: 56px;
  height: 56px;
  stroke: var(--ink);
  stroke-width: 1.6;
}
.ghost .icon .fill {
  fill: var(--cream);
}
/* Visually hidden live region for beat announcements. */
.announce {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
kbd {
  font: 600 12px var(--font-body);
  border: 1.5px solid #3a2a5a66;
  border-radius: 5px;
  padding: 1px 5px;
  vertical-align: middle;
}
@media (pointer: coarse) {
  .controls kbd {
    display: none;
  }
}
.secondary {
  min-height: 56px;
  border: 2px solid #ffffff55;
  background: #ffffff0f;
  border-radius: 14px;
  padding: 6px 10px;
  font: 600 15px var(--font-body);
}
.secondary.small {
  min-height: 36px;
  font-size: 13px;
}

/* ---- Scoreboard: desktop sidebar, phone bottom sheet ---- */
.board {
  display: flex;
  flex-direction: column;
  padding: 14px;
  min-height: 0;
  overflow: hidden;
}
.sheet-handle {
  display: none;
}
#result {
  color: var(--gold);
  font: 600 16px var(--font-display);
}
#result:empty {
  display: none;
}
.sidehead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 6px 0 8px;
}
h2 {
  font: 700 20px var(--font-display);
}
.sidehead b {
  background: #51417b;
  padding: 2px 9px;
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
}
#roster {
  overflow: auto;
  min-height: 0;
}
.waiting .face {
  width: 34px;
  height: 34px;
  flex: none;
}
.row {
  position: relative;
  background: var(--panel);
  border-radius: 10px;
  display: grid;
  grid-template-columns: 22px 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 7px 6px;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
.row.me {
  background: #2f2263;
  border-radius: 10px;
}
.row .place {
  font: 600 14px var(--font-display);
  color: var(--cream-dim);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.row .face {
  width: 22px;
  height: 22px;
  display: block;
}
.row .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row em {
  font: 600 12px var(--font-body);
  color: var(--cream-dim);
  margin-left: 4px;
}
.row .icon {
  width: 14px;
  height: 14px;
  color: var(--gold);
  vertical-align: -2px;
}
.row b {
  font: 600 15px var(--font-display);
  font-variant-numeric: tabular-nums;
  display: inline-block;
}
.row.acted .name .icon:last-child {
  color: var(--good);
  margin-left: 4px;
}
.board-note {
  color: var(--cream-dim);
  font-size: 12px;
  margin-top: 8px;
}
.board-note:empty {
  display: none;
}
.many #roster {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 8px;
  align-content: start;
}
.many .row {
  padding: 4px;
  gap: 5px;
  grid-template-columns: 20px 18px minmax(0, 1fr) auto;
  font-size: 13px;
}
.many .row .face {
  width: 18px;
  height: 18px;
}

/* Phone: the scoreboard is a bottom sheet opened from the chip. */
@media (max-width: 719px) and (not ((orientation: landscape) and (max-height: 520px))) {
  /* It rises over the stage and stops above the deck, so the deck's
     buttons stay reachable while it is open. */
  .board {
    position: fixed;
    left: calc(var(--gap) + env(safe-area-inset-left));
    right: calc(var(--gap) + env(safe-area-inset-right));
    bottom: calc(var(--deck-h) + 2 * var(--gap) + env(safe-area-inset-bottom));
    z-index: 5;
    /* Never above the stage bar, so its chip can always close the sheet. */
    max-height: calc(100dvh - var(--deck-h) - var(--top-h) - var(--bar-h) - 4 * var(--gap) - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    padding: 4px 12px 12px;
    transform: translateY(calc(100% + var(--deck-h) + 3 * var(--gap)));
    visibility: hidden;
    transition:
      transform var(--t-slow) var(--ease-in),
      visibility 0s var(--t-slow);
  }
  body.sheet-open .board {
    transform: none;
    visibility: visible;
    transition: transform var(--t-slow) var(--ease-out);
  }
  /* The sheet rises from behind the deck, so it never covers its buttons,
     even while it moves. */
  .deck {
    z-index: 6;
  }
  .sheet-handle {
    display: flex;
    justify-content: center;
  }
  .sheet-handle button {
    width: 72px;
    height: 28px;
    border: 0;
    background: transparent;
    position: relative;
  }
  .sheet-handle button::after {
    position: absolute;
    inset: 11px 16px;
    border-radius: 3px;
    background: #ffffff55;
    content: "";
  }
}

/* Desktop and landscape phones: two columns, scoreboard on the side. */
@media (min-width: 720px), (orientation: landscape) and (max-height: 520px) {
  :root {
    --top-h: 56px;
    --deck-h: 176px;
    --button-h: 64px;
  }
  .wordmark {
    display: inline;
  }
  .top {
    padding: 0 16px;
    gap: 12px;
  }
  h1 {
    font-size: 24px;
  }
  .shell {
    grid-template-columns: minmax(0, 1fr) minmax(250px, 30%);
    grid-template-rows: minmax(0, 1fr) var(--deck-h);
    grid-template-areas: "stage board" "deck board";
  }
  .board {
    grid-area: board;
  }
  .chip {
    display: none;
  }
}
@media (orientation: landscape) and (max-height: 520px) {
  :root {
    --top-h: 40px;
    --deck-h: 150px;
    --button-h: 56px;
  }
  .wordmark,
  .caption {
    display: none;
  }
}
@media (min-width: 1200px) {
  .shell {
    grid-template-columns: minmax(0, 1fr) 360px;
  }
}

/* ---- Dialog ---- */
dialog {
  width: min(92%, 420px);
  max-height: 90dvh;
  background: var(--panel-2);
  color: var(--cream);
  border: var(--outline) solid var(--ink);
  border-radius: var(--r-panel);
  box-shadow: 0 var(--side) 0 var(--panel-side);
  padding: 22px;
}
dialog::backdrop {
  background: #160f2cc7;
}
dialog h2 {
  margin-bottom: 14px;
}
dialog button:not(.close),
dialog input {
  display: block;
  width: 100%;
  margin-top: 10px;
}
dialog button:not(.close):not(.secondary) {
  min-height: 56px;
  font-size: 18px;
}
dialog input {
  min-height: 52px;
  padding: 10px 12px;
  border: var(--outline) solid var(--ink);
  border-radius: 12px;
  background: #fff;
  color: #211541;
}
dialog .game small {
  display: block;
  font: 600 12px var(--font-body);
  opacity: 0.7;
}
/* A game the practice room does not fit: who it is for. */
dialog .game em {
  display: block;
  font: 700 12px var(--font-body);
  color: #a3420c;
}
dialog .langs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 14px;
}
dialog .langs button.secondary {
  display: inline-block;
  width: auto;
  min-width: 64px;
  min-height: 44px;
  margin: 0;
}
dialog .langs button[aria-pressed="true"] {
  background: var(--cream);
  color: var(--ink);
}
dialog .sound {
  margin-top: 12px;
  display: grid;
  gap: 4px;
}
dialog .sound button.secondary {
  min-height: 44px;
  margin-top: 0;
}
dialog .level {
  display: grid;
  grid-template-columns: 5.5em minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
dialog input[type="range"] {
  min-height: 32px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  accent-color: var(--yellow);
}
dialog input[type="range"]:disabled {
  opacity: 0.4;
}
dialog h3 {
  margin: 12px 0 0;
  font: 600 15px var(--font-display);
}
dialog .sound-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
dialog .sound-grid button.secondary {
  margin-top: 0;
  min-height: 36px;
  padding: 4px;
  font-size: 12px;
}
.close {
  float: right;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: transparent;
  border: 0;
  padding: 0;
}
#error {
  color: var(--gold);
  margin-top: 8px;
}
#error:empty {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .ground i,
  .conn.off,
  .primary::after,
  .nope,
  .toast,
  .banner,
  .banner i,
  dialog[open],
  dialog[open]::backdrop,
  .row.enter,
  #count.bump {
    animation: none !important;
  }
  .toast,
  .banner {
    transform: none !important;
    transition: opacity var(--t-fast) !important;
  }
  .deck-state,
  body[data-deck] .deck-state,
  .board,
  body.sheet-open .board {
    transform: none !important;
    transition: opacity var(--t-fast) !important;
  }
}

/* ---- Online room ---- */

/* Connection banner: slides down over the stage while the socket is down. */
.banner {
  position: absolute;
  top: 10px;
  left: 50%;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 20px);
  padding: 8px 16px;
  border: var(--outline) solid var(--ink);
  border-radius: 99px;
  background: var(--warn);
  color: var(--ink);
  font: 700 16px var(--font-display);
  box-shadow: 0 4px 0 var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -150%);
  transition:
    transform var(--t-base) var(--ease-in),
    opacity var(--t-base) var(--ease-in);
}
.banner.on {
  opacity: 1;
  transform: translate(-50%, 0);
  transition:
    transform var(--t-slow) var(--ease-pop),
    opacity var(--t-base) var(--ease-out);
}
.banner i {
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 50%;
  background: var(--ink);
  animation: pulse 1s ease-in-out infinite;
}

/* Invite card: on the lobby stage of a room, for everyone. */
.invite {
  --qr: 84px;
  position: absolute;
  top: 17%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(calc(100% - 20px), 380px);
  padding: 10px;
  background: var(--panel);
  border: var(--outline) solid var(--ink);
  border-radius: var(--r-panel);
  box-shadow: 0 var(--side) 0 var(--panel-side);
  animation: card-in var(--t-slow) var(--ease-pop) both;
}
@keyframes card-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-12px) scale(0.94); }
}
.qr {
  display: block;
  flex: none;
  border-radius: 8px;
  image-rendering: pixelated;
}
.invite .qr {
  width: var(--qr);
  height: var(--qr);
}
.invite-body {
  min-width: 0;
  display: grid;
  gap: 4px;
}
.invite-body b {
  font: 700 18px var(--font-display);
  color: var(--gold);
}
.invite-link {
  font: 600 13px var(--font-body);
  color: var(--cream-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: all;
}
.invite-body button.secondary.small {
  justify-self: start;
  min-height: 40px;
  padding: 4px 14px;
  font: 600 15px var(--font-display);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
@media (min-width: 720px) {
  .invite {
    --qr: 104px;
  }
}
/* Short screens: a compact card higher up, clear of the back row. */
@media (max-height: 700px) {
  .invite {
    --qr: 64px;
    top: 9%;
    padding: 7px 10px;
    gap: 10px;
  }
  .invite-body {
    gap: 2px;
  }
  .invite-body b {
    font-size: 16px;
  }
  .invite-body button.secondary.small {
    min-height: 34px;
  }
}

/* Toasts: under the header, centred, never in the way of input. */
.toasts {
  position: fixed;
  top: calc(var(--top-h) + 8px + env(safe-area-inset-top));
  left: 0;
  right: 0;
  z-index: 60;
  display: grid;
  justify-items: center;
  gap: 6px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 8px 16px;
  border: var(--outline) solid var(--ink);
  border-radius: 99px;
  background: var(--cream);
  color: var(--ink);
  font: 600 15px var(--font-display);
  box-shadow: 0 4px 0 var(--ink);
  opacity: 0;
  transform: translateY(-16px) scale(0.96);
  transition:
    transform var(--t-base) var(--ease-pop),
    opacity var(--t-base) var(--ease-out);
}
.toast.in {
  opacity: 1;
  transform: none;
}
.toast.out {
  opacity: 0;
  transform: translateY(-8px);
  transition:
    transform var(--t-fast) var(--ease-in),
    opacity var(--t-fast) var(--ease-in);
}
.toast.good .icon {
  color: #1f8a57;
}
.toast.bad {
  background: #ffd9d2;
}
.toast .icon {
  width: 18px;
  height: 18px;
}

/* The social row of a room: character (or share), then four emotes, all the
   same square-ish size. */
.secondary-row.social {
  grid-auto-columns: minmax(0, 1fr);
}
.secondary-row .tool,
.secondary-row .emote {
  display: grid;
  place-items: center;
  padding: 2px;
}
.secondary-row .tool .face {
  width: 36px;
  height: 36px;
}
.secondary-row .emote .face {
  width: 34px;
  height: 34px;
  transition: transform var(--t-fast) var(--ease-out);
}
.secondary-row .emote:active .face {
  transform: scale(1.18);
}
.secondary-row .emote[aria-disabled="true"] {
  opacity: 0.4;
}
.secondary-row .tool .icon {
  width: 26px;
  height: 26px;
}
/* The break deck holds only the emotes, at the bottom like the others. */
.deck-state.result {
  align-content: end;
}

/* Scoreboard: rows scale in when someone joins; the head count bumps. */
.row.enter {
  animation: row-in var(--t-slow) var(--ease-pop) both;
}
@keyframes row-in {
  from { opacity: 0; transform: scale(0.8); }
}
#count.bump {
  animation: bump var(--t-slow) var(--ease-pop);
}
@keyframes bump {
  40% { transform: scale(1.35); }
}

/* Dialog variants: scale and fade in, backdrop fades. */
dialog[open] {
  animation: dialog-in var(--t-base) var(--ease-pop);
}
dialog[open]::backdrop {
  animation: fade-in var(--t-base) var(--ease-out);
}
@keyframes dialog-in {
  from { opacity: 0; transform: scale(0.92); }
}
@keyframes fade-in {
  from { opacity: 0; }
}
dialog .steps {
  display: flex;
  gap: 6px;
  margin: -6px 0 10px;
}
dialog .steps i {
  width: 22px;
  height: 6px;
  border-radius: 3px;
  background: #ffffff33;
}
dialog .steps i.done {
  background: var(--good);
}
dialog .steps i.now {
  background: var(--yellow);
  width: 34px;
}
dialog .note {
  margin-top: 10px;
  color: var(--cream-dim);
  font-size: 14px;
}
dialog .note:empty {
  display: none;
}
dialog .note.warn {
  color: var(--gold);
}
dialog .pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 8px;
  margin-top: 12px;
}
dialog .pair.single {
  grid-template-columns: minmax(0, 1fr);
}
dialog .pair button:not(.close) {
  margin-top: 0;
}
dialog button[aria-disabled="true"]:not(.swatch) {
  opacity: 0.5;
}
dialog button[aria-busy="true"] {
  opacity: 0.7;
  pointer-events: none;
}
/* Character preview: the live rig on a little stage. */
dialog .preview {
  position: relative;
  height: 118px;
  border-radius: 16px;
  background: linear-gradient(#5a3fb8, #3a2984);
  border: var(--outline) solid var(--ink);
  overflow: hidden;
}
dialog .preview.big {
  height: 170px;
}
dialog .preview canvas {
  display: block;
  width: 100%;
  height: calc(100% - 22px);
}
dialog .preview b {
  display: block;
  text-align: center;
  font: 700 16px var(--font-display);
  line-height: 22px;
  margin-top: -4px;
}
dialog .parts {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}
dialog .stepper {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  align-items: center;
  gap: 6px;
  text-align: center;
  font: 600 15px var(--font-display);
}
dialog .stepper button.secondary.arrow {
  margin: 0;
  min-height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
}
dialog .arrow .icon {
  transform: rotate(90deg);
}
dialog .arrow.next .icon {
  transform: rotate(-90deg);
}
dialog .swatches {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 5px;
}
dialog .swatches button.swatch {
  margin: 0;
  min-height: 0;
  aspect-ratio: 1;
  border-radius: 50%;
  border: var(--outline) solid var(--ink);
  background: var(--c);
  padding: 0;
  box-shadow: 0 3px 0 var(--ink);
  font-size: 0;
}
dialog .swatches button.swatch[aria-pressed="true"] {
  outline: 3px solid var(--cream);
  outline-offset: 2px;
}
/* A colour that would copy someone's whole look: greyed and struck out. */
dialog .swatches button.swatch.taken {
  background:
    linear-gradient(135deg, transparent 44%, var(--ink) 44% 56%, transparent 56%),
    color-mix(in srgb, var(--c) 35%, #4b3f6b);
  opacity: 0.6;
  box-shadow: none;
  cursor: not-allowed;
}
@media (max-width: 380px) {
  dialog .swatches {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    padding: 0 18%;
  }
}
/* Game picker cards. */
dialog .cards button.game {
  display: grid;
  gap: 2px;
  text-align: left;
  padding: 10px 14px;
  font-size: 18px;
}
dialog .cards button.game span {
  font: 500 13px var(--font-body);
}
/* A short explanation at the top of a dialog. */
dialog .hint {
  color: var(--cream-dim);
  font-size: 14px;
}
/* About: the original idea, the creators and every game with its author. */
dialog .about-idea {
  font: 600 16px var(--font-display);
  color: var(--yellow);
  overflow-wrap: anywhere;
}
dialog .credits {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  display: grid;
  gap: 4px;
}
dialog .credits li {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  column-gap: 10px;
  padding: 6px 10px;
  border-radius: 10px;
  background: #ffffff12;
  font: 500 14px var(--font-body);
}
dialog .credits li b {
  font: 600 15px var(--font-display);
  overflow-wrap: anywhere;
}
dialog .credits li span {
  color: var(--cream-dim);
}
/* Room menu: the big invite. */
dialog .invite-big {
  display: grid;
  justify-items: center;
  gap: 6px;
  text-align: center;
}
dialog .invite-big p {
  color: var(--cream-dim);
  font-size: 14px;
}
dialog .invite-big .invite-link {
  max-width: 100%;
}

/* ---- Big screen (?view=tv): a shared display with no controls ----
   Stage at full height, the scoreboard with characters on the side, the
   room QR in the stage's corner during the lobby. Every size follows the
   viewport height (--u is 1px at 720 px tall), so 720p and 1080p show the
   same composition; app.ts draws the stage enlarged to match (engine/tv.ts). */
.invite-scan:empty,
.invite-status:empty {
  display: none;
}
body.tv {
  --u: calc(100vh / 720);
  --top-h: calc(var(--u) * 60);
  --bar-h: calc(var(--u) * 40);
  --gap: calc(var(--u) * 12);
}
body.tv #audio,
body.tv #menu,
body.tv .deck,
body.tv .chip,
body.tv .sheet-handle,
body.tv #invite-share {
  display: none !important;
}
body.tv .top {
  padding: 0 calc(var(--u) * 20);
  gap: calc(var(--u) * 16);
}
body.tv .mark {
  width: calc(var(--u) * 40);
  height: calc(var(--u) * 40);
  border-radius: calc(var(--u) * 12);
}
body.tv .mark .icon {
  width: calc(var(--u) * 26);
  height: calc(var(--u) * 26);
}
body.tv .wordmark {
  display: inline;
  font-size: calc(var(--u) * 24);
}
body.tv h1 {
  font-size: calc(var(--u) * 30);
}
body.tv .progress,
body.tv .progress span {
  gap: calc(var(--u) * 6);
}
body.tv .progress {
  gap: calc(var(--u) * 14);
}
body.tv .progress i {
  width: calc(var(--u) * 13);
  height: calc(var(--u) * 13);
  border-width: calc(var(--u) * 2.5);
}
body.tv .shell {
  grid-template-columns: minmax(0, 1fr) clamp(300px, 27vw, 520px);
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "stage board";
}
/* The party photo takes the whole screen: the standings were just shown. */
body.tv.photo .shell {
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "stage";
}
body.tv.photo .board {
  display: none;
}
body.tv .bar {
  padding: 0 calc(var(--u) * 14);
  gap: calc(var(--u) * 12);
}
body.tv .clock {
  font-size: calc(var(--u) * 24);
  gap: calc(var(--u) * 8);
}
body.tv .conn {
  width: calc(var(--u) * 13);
  height: calc(var(--u) * 13);
}
body.tv .timebar {
  left: calc(var(--u) * 14);
  right: calc(var(--u) * 14);
  height: calc(var(--u) * 6);
  border-radius: calc(var(--u) * 3);
}
.tv-sound {
  margin-left: auto;
  font: 600 calc(var(--u, 1px) * 15) var(--font-body);
  color: var(--cream-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
body.tv .banner {
  top: calc(var(--u) * 14);
  gap: calc(var(--u) * 10);
  padding: calc(var(--u) * 10) calc(var(--u) * 22);
  font-size: calc(var(--u) * 24);
}
body.tv .banner i {
  width: calc(var(--u) * 13);
  height: calc(var(--u) * 13);
}
body.tv .toast {
  font-size: calc(var(--u) * 20);
}
/* The scoreboard is always on screen, one column even with twenty rows. */
body.tv .board {
  grid-area: board;
  position: static;
  transform: none;
  visibility: visible;
  max-height: none;
  padding: calc(var(--u) * 16);
}
body.tv #result {
  font-size: calc(var(--u) * 20);
}
body.tv h2 {
  font-size: calc(var(--u) * 26);
}
body.tv .sidehead {
  margin: calc(var(--u) * 6) 0 calc(var(--u) * 10);
}
body.tv .sidehead b {
  font-size: calc(var(--u) * 18);
  padding: calc(var(--u) * 2) calc(var(--u) * 11);
}
body.tv .board-note {
  font-size: calc(var(--u) * 15);
}
body.tv #roster {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
}
body.tv .row {
  grid-template-columns: calc(var(--u) * 26) auto minmax(0, 1fr) auto;
  gap: calc(var(--u) * 10);
  padding: calc(var(--u) * 6) calc(var(--u) * 8);
  font-size: calc(var(--u) * 19);
}
body.tv .row .place {
  font-size: calc(var(--u) * 18);
}
body.tv .row b {
  font-size: calc(var(--u) * 21);
}
body.tv .row em {
  font-size: calc(var(--u) * 14);
}
body.tv .row .icon {
  width: calc(var(--u) * 18);
  height: calc(var(--u) * 18);
  vertical-align: calc(var(--u) * -3);
}
body.tv.many .row {
  grid-template-columns: calc(var(--u) * 22) auto minmax(0, 1fr) auto;
  gap: calc(var(--u) * 8);
  padding: calc(var(--u) * 2) calc(var(--u) * 6);
  font-size: calc(var(--u) * 15);
}
body.tv.many .row .place {
  font-size: calc(var(--u) * 14);
}
body.tv.many .row b {
  font-size: calc(var(--u) * 16);
}
body.tv.many .row em {
  font-size: calc(var(--u) * 12);
}
body.tv.many .row .icon {
  width: calc(var(--u) * 14);
  height: calc(var(--u) * 14);
}
/* The invite card becomes the room QR in the stage's top-right corner,
   above the plaza's cast, for the phones in the room to scan. */
body.tv .invite {
  top: calc(var(--u) * 14);
  right: calc(var(--u) * 14);
  left: auto;
  transform: none;
  width: auto;
  max-width: calc(100% - var(--u) * 28);
  gap: calc(var(--u) * 16);
  padding: calc(var(--u) * 12);
  animation-name: tv-card-in;
}
@keyframes tv-card-in {
  from { opacity: 0; transform: translateY(-12px) scale(0.94); }
}
body.tv .invite .qr {
  border-radius: calc(var(--u) * 10);
}
body.tv .invite-body {
  width: calc(var(--u) * 230);
  gap: calc(var(--u) * 6);
}
body.tv .invite-body b {
  font-size: calc(var(--u) * 26);
  line-height: 1.1;
}
body.tv .invite-scan,
body.tv .invite-status {
  font: 600 calc(var(--u) * 15) / 1.3 var(--font-body);
  color: var(--cream-dim);
}
body.tv .invite-link {
  font-size: calc(var(--u) * 16);
  color: var(--cream);
  white-space: normal;
  word-break: break-all;
}
/* What to play: the cup being played, and the cup builder's numbered picks
   (dark until picked, so the chosen ones stand out). */
dialog .cards button.game[aria-pressed="true"] {
  background: var(--cream);
  color: var(--ink);
}
dialog .list {
  max-height: 50dvh;
  overflow-y: auto;
  margin-top: 10px;
  display: grid;
  gap: 8px;
  padding-bottom: var(--side);
}
dialog .list button:not(.close) {
  margin-top: 0;
}
dialog .picks button.game.pick {
  min-height: 46px;
  grid-template-columns: 28px minmax(0, 1fr);
  column-gap: 10px;
  align-items: center;
  padding: 6px 12px;
  font-size: 16px;
  background: var(--panel);
  color: var(--cream);
}
dialog .picks button.game.pick i {
  width: 28px;
  height: 28px;
  border: var(--outline) solid var(--ink);
  border-radius: 50%;
  background: #ffffff1f;
  color: var(--ink);
  font: 700 15px/22px var(--font-display);
  text-align: center;
}
dialog .picks button.game.pick[aria-pressed="true"] {
  background: var(--yellow);
  color: var(--ink);
}
dialog .picks button.game.pick[aria-pressed="true"] i {
  background: var(--cream);
}
