/* ==========================================================================
   Tambola — visual system

   Type uses the platform font, which already ships optical sizing and
   legibility tuning. Tracking is set per size rather than once globally:
   large numerals read too loose as they grow, small labels too tight.
   Surfaces are translucent materials over a fixed backdrop, so hierarchy
   comes from material weight rather than from borders everywhere.
   ========================================================================== */

:root {
  color-scheme: light dark;

  /* Spacing in rem so the layout grows with the reader's text size. */
  --gap-1: 0.375rem;
  --gap-2: 0.625rem;
  --gap-3: 1rem;
  --gap-4: 1.5rem;

  --r-sm: 0.625rem;
  --r-md: 0.875rem;
  --r-lg: 1.25rem;
  --r-full: 999px;

  /* Light: a cream hall with white cards. Flat colour, no glows: a game
     board, not a landing page. Marigold is the one loud colour. */
  --bg: #fbf4e6;
  --surface: #ffffff;
  --surface-strong: #ffffff;
  --surface-sunken: #f4ead6;
  --hairline: #eadcc0;
  --edge: #e2d1ae;              /* the solid lip under cards and buttons */
  --edge-light: #ffffff;

  --ink: #14272d;
  --ink-2: rgba(20, 39, 45, 0.66);
  --ink-3: rgba(20, 39, 45, 0.36);

  --gold: #b86e00;              /* gold as text, dark enough to read */
  --gold-bright: #ffb627;       /* gold as a fill */
  --gold-soft: rgba(255, 182, 39, 0.20);
  --green: #138a5e;
  --green-soft: rgba(19, 138, 94, 0.13);
  --red: #d8433b;
  --red-soft: rgba(216, 67, 59, 0.12);
  --blue: #1b6fa8;
  --blue-soft: rgba(27, 111, 168, 0.12);
  --teal: #0f5c63;

  --shadow-sm: 0 2px 0 var(--edge);
  --shadow-md: 0 4px 0 var(--edge);
  --shadow-lg: 0 6px 0 var(--edge), 0 18px 40px rgba(20, 39, 45, 0.14);

  /* Critically damped by default. Overshoot is reserved for the two moments
     that carry real momentum: a number landing, and a prize being won. */
  --band-1: #ff6b5e;
  --band-2: #ffb627;
  --band-3: #3ddc97;
  --band-4: #5cc8ff;
  --band-5: #ff8f3d;
  --band-6: #2ec4b6;
  --band-7: #ff7eb3;
  --band-8: #b5e655;
  --band-9: #8fa8ff;

  --ease-settle: cubic-bezier(0.22, 0.61, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.42, 0.52, 1);
  --t-press: 90ms;
  --t-settle: 380ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Dark: deep teal felt, like a card table under a lamp. */
    --bg: #0b2229;
    --surface: #123039;
    --surface-strong: #173a44;
    --surface-sunken: #0a1c22;
    --hairline: rgba(255, 255, 255, 0.07);
    --edge: #061419;
    --edge-light: rgba(255, 255, 255, 0.06);

    --ink: #f5efe2;
    --ink-2: rgba(245, 239, 226, 0.66);
    --ink-3: rgba(245, 239, 226, 0.34);

    --gold: #ffc23d;
    --gold-bright: #ffb627;
    --gold-soft: rgba(255, 182, 39, 0.15);
    --green: #3ddc97;
    --green-soft: rgba(61, 220, 151, 0.14);
    --red: #ff6b5e;
    --red-soft: rgba(255, 107, 94, 0.15);
    --blue: #5cc8ff;
    --blue-soft: rgba(92, 200, 255, 0.14);
    --teal: #7fd6d0;

    --shadow-sm: 0 2px 0 var(--edge);
    --shadow-md: 0 4px 0 var(--edge);
    --shadow-lg: 0 6px 0 var(--edge), 0 18px 40px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

input[type="checkbox"] {
  flex: none;
  width: 1.25rem !important;
  height: 1.25rem;
  margin: 0.125rem 0 0;
  accent-color: var(--gold-bright);
}

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  letter-spacing: 0;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- layout */

.wrap { max-width: 74rem; margin: 0 auto; padding: 1.25rem 1rem 5rem; }
.wrap.narrow { max-width: 38rem; }

.grid2 {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: var(--gap-3);
  align-items: start;
}
@media (max-width: 60rem) { .grid2 { grid-template-columns: minmax(0, 1fr); } }

.row { display: flex; gap: var(--gap-2); align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: var(--gap-2); }
.stack > * + * { margin-top: var(--gap-2); }
.hidden { display: none !important; }

/* ------------------------------------------------------------ typography */

h1, h2, h3 { margin: 0 0 var(--gap-2); font-weight: 650; }
h1 { font-size: 1.75rem; line-height: 1.12; letter-spacing: -0.022em; }
h2 { font-size: 1.125rem; line-height: 1.22; letter-spacing: -0.014em; }
h3 { font-size: 0.9375rem; line-height: 1.3; letter-spacing: -0.006em; }
p { margin: 0 0 var(--gap-2); }
p:last-child { margin-bottom: 0; }

.muted {
  color: var(--ink-2);
  font-size: 0.8125rem;
  line-height: 1.45;
  letter-spacing: 0.005em; /* small text reads better very slightly open */
}

.brand {
  display: flex;
  align-items: baseline;
  gap: var(--gap-2);
  flex-wrap: wrap;
  margin-bottom: var(--gap-3);
}
.brand .logo {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.03em; /* tighter as it grows */
  color: var(--ink);
}
/* A called ball beside the name. */
.brand .logo::before {
  content: "90";
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  font-size: 0.8125rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #2a1c00;
  background: var(--gold-bright);
  box-shadow: inset 0 0 0 3px #fff8e6, 0 2px 0 #b86e00;
}
.brand .tag { color: var(--ink-2); font-size: 0.8125rem; }

/* ------------------------------------------------------- material layers */

.panel {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: var(--gap-3);
  margin-bottom: var(--gap-3);
  box-shadow: var(--shadow-md);
}
.panel > h2 { display: flex; align-items: center; justify-content: space-between; gap: var(--gap-2); }

.banner {
  padding: var(--gap-3);
  border-radius: var(--r-md);
  border: 1px solid color-mix(in srgb, var(--gold) 38%, transparent);
  background: var(--gold-soft);
  margin-bottom: var(--gap-3);
}
/* Home-screen install tip on the landing page. */
.install-hint {
  display: flex;
  align-items: center;
  gap: var(--gap-2);
  padding: var(--gap-2) var(--gap-3);
  margin-bottom: var(--gap-3);
}
.install-hint[hidden] { display: none; }
.install-hint img { flex-shrink: 0; border-radius: var(--r-sm); }
.install-copy { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 0.8125rem; line-height: 1.35; }
.install-copy strong { font-size: 0.9375rem; }
.install-hint .install-close {
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  margin-right: calc(-1 * var(--gap-2));
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
  color: var(--ink-2);
}

.banner.good { border-color: color-mix(in srgb, var(--green) 38%, transparent); background: var(--green-soft); }
.banner.bad { border-color: color-mix(in srgb, var(--red) 38%, transparent); background: var(--red-soft); }

/* -------------------------------------------------------------- controls */

label.field {
  display: block;
  font-size: 0.75rem;
  font-weight: 550;
  letter-spacing: 0.01em;
  color: var(--ink-2);
  margin-bottom: var(--gap-1);
}

input[type="text"], input[type="email"], input[type="tel"], input[type="number"], input[type="password"], input[type="date"], select {
  width: 100%;
  padding: 0.625rem 0.75rem;
  font: inherit;
  font-size: 1rem; /* 16px minimum stops iOS zooming the page on focus */
  color: var(--ink);
  background: var(--surface-sunken);
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  transition: border-color 160ms var(--ease-settle), background 160ms var(--ease-settle);
}
input:focus, select:focus {
  outline: none;
  border-color: var(--gold);
  background: var(--surface-strong);
  box-shadow: 0 0 0 3.5px var(--gold-soft);
}
button:focus-visible, a:focus-visible, .tcell:focus-visible {
  outline: 2.5px solid var(--gold);
  outline-offset: 2px;
}

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.006em;
  padding: 0.625rem 1rem;
  color: var(--ink);
  background: var(--surface-strong);
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  cursor: pointer;
  /* Feedback belongs on the press, and it has to be immediate. */
  box-shadow: 0 3px 0 var(--edge);
  transition: transform var(--t-press) var(--ease-settle),
              box-shadow var(--t-press) var(--ease-settle),
              filter 160ms var(--ease-settle),
              opacity 160ms var(--ease-settle);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:hover:not(:disabled), .btn:hover { filter: brightness(1.05); }
/* Pressed: the button sinks onto its lip. */
button:active:not(:disabled), .btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--edge); }
button:disabled { opacity: 0.38; cursor: not-allowed; }

.btn-primary {
  color: #2a1c00;
  font-weight: 700;
  background: var(--gold-bright);
  border-color: #d98e00;
  --edge: #b86e00;
}
.btn-good { color: #06281a; background: #3ddc97; border-color: #22b97a; --edge: #138a5e; }
.btn-bad { color: #fff; background: #e5483f; border-color: #c4352d; --edge: #9c2620; }
/* Removing a prize is undone with Discard changes, so it stays quiet. */
.btn-remove { color: var(--red); }
.btn-remove:hover:not(:disabled) { background: var(--red-soft); }
.btn-sm { padding: 0.375rem 0.6875rem; font-size: 0.8125rem; }
.btn-wide { width: 100%; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--gap-1);
  padding: 0.1875rem 0.625rem;
  border-radius: var(--r-full);
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.006em;
  white-space: nowrap;
  color: var(--ink-2);
  background: var(--surface-sunken);
  border: 1px solid transparent;
}
.pill.good { color: var(--green); background: var(--green-soft); }
.pill.warn { color: var(--gold); background: var(--gold-soft); }
.pill.bad { color: var(--red); background: var(--red-soft); }
.pill.info { color: var(--blue); background: var(--blue-soft); }

.code-chip {
  display: inline-block;
  padding: 0.5rem 0.875rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-indent: 0.2em; /* balances the trailing letter-space */
  color: var(--gold);
  background: var(--gold-soft);
  border: 1px dashed color-mix(in srgb, var(--gold) 52%, transparent);
  border-radius: var(--r-sm);
}

/* ----------------------------------------------------------- the callout */

.callout {
  text-align: center;
  padding: var(--gap-4) var(--gap-3);
  border-radius: var(--r-md);
  background: var(--teal);
  border: 1px solid transparent;
  color: #fff;
}
@media (prefers-color-scheme: dark) {
  .callout { background: var(--surface-sunken); border-color: var(--hairline); color: var(--ink); }
}
.callout .big {
  font-size: clamp(3.25rem, 17vw, 5.5rem);
  font-weight: 700;
  line-height: 0.94;          /* tight leading for large type */
  letter-spacing: -0.045em;   /* strongly negative tracking at display size */
  font-variant-numeric: tabular-nums;
  color: var(--gold-bright);
  display: block;
}
.callout .big.idle {
  font-size: clamp(1.5rem, 5vw, 2rem);
  letter-spacing: -0.02em;
  color: inherit;
  opacity: 0.5;
}
.callout .said {
  margin-top: var(--gap-2);
  font-size: 1.0625rem;
  line-height: 1.35;
  letter-spacing: -0.01em;
  font-style: italic;
  color: inherit;
  min-height: 1.4em;
}

/* --------------------------------------------------------------- ticket */

/* A thin line naming a ticket and saying how much of it is marked. It
   replaces a heading and a panel per ticket, which together cost more height
   than the tickets did. */
.ticket-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--gap-2);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: -0.006em;
  color: var(--ink-2);
  margin-bottom: calc(-1 * var(--gap-1));
}

/* One row per prize, with a numbered chip for each ticket. Full width inside
   the wrapping claim bar, or two prizes share a line and it stops being clear
   which chips belong to which prize. */
.claim-row {
  flex: 1 1 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap-2);
  padding: 0.25rem 0;
  border-top: 1px solid var(--hairline);
}
.claim-row:first-child { border-top: none; }
.claim-prize {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.008em;
  overflow-wrap: anywhere;
}
.claim-chips { display: flex; gap: var(--gap-1); flex: none; }
/* A claim is made inside a six-second window and a mis-tap is a bogey, so
   these meet the 44px touch target rather than the size the text wants. */
.claim-chips .chip {
  width: 2.75rem;
  min-height: 2.75rem;
  padding-left: 0;
  padding-right: 0;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.ticket {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 0.3125rem;
  padding: 0.5rem;
  background: var(--surface-sunken);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
}

.tcell {
  aspect-ratio: 1 / 0.94;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.5rem;
  font-size: clamp(0.8125rem, 3.2vw, 1.3125rem);
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--surface-strong);
  border: 1px solid var(--hairline);
  box-shadow: 0 2px 0 var(--edge);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  /* Scale settles with a little spring; colour follows without overshoot. */
  transition: transform 260ms var(--ease-spring),
              background-color 200ms var(--ease-settle),
              border-color 200ms var(--ease-settle),
              color 200ms var(--ease-settle);
}
.tcell.blank { background: none; border-color: transparent; box-shadow: none; }
.ticket.live .tcell.num { cursor: pointer; }

/* Pressed state is applied on pointer-down, before any network round-trip. */
.tcell.pressing { transform: scale(0.9); transition-duration: var(--t-press); }

.tcell.marked {
  color: #2a1c00;
  background: var(--gold-bright);
  border-color: #d98e00;
  box-shadow: 0 2px 0 #b86e00;
}
/* The daubed ring, drawn like ink on a paper ticket. */
.tcell.marked::after {
  content: "";
  position: absolute;
  inset: 15%;
  border: 2.5px solid rgba(42, 28, 0, 0.5);
  border-radius: 50%;
}
.tcell.num { position: relative; }

/* Awaiting the server's word — visible but not alarming. */
.tcell.pending { opacity: 0.66; }

.tcell.shake { animation: shake 320ms var(--ease-settle); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  22% { transform: translateX(-5px); }
  62% { transform: translateX(4px); }
}

/* ---------------------------------------------------------------- board */

.board { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 0.25rem; }
.board .cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.4375rem;
  font-size: clamp(0.5625rem, 1.9vw, 0.8125rem);
  font-weight: 600;
  letter-spacing: 0.004em;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
  background: var(--surface-sunken);
  border: 1px solid transparent;
  transition: background-color 240ms var(--ease-settle),
              color 240ms var(--ease-settle),
              transform 300ms var(--ease-spring);
}
/* Each ten has its own colour, as on a printed housie board, so a glance
   says which part of the board has come up. */
.board .cell:nth-child(n+1)  { --band: var(--band-1); }
.board .cell:nth-child(n+11) { --band: var(--band-2); }
.board .cell:nth-child(n+21) { --band: var(--band-3); }
.board .cell:nth-child(n+31) { --band: var(--band-4); }
.board .cell:nth-child(n+41) { --band: var(--band-5); }
.board .cell:nth-child(n+51) { --band: var(--band-6); }
.board .cell:nth-child(n+61) { --band: var(--band-7); }
.board .cell:nth-child(n+71) { --band: var(--band-8); }
.board .cell:nth-child(n+81) { --band: var(--band-9); }
.board .cell:not(.hit) {
  color: color-mix(in srgb, var(--band) 62%, var(--ink-3));
  background: color-mix(in srgb, var(--band) 9%, var(--surface-sunken));
}
.board .cell.hit {
  color: #14272d;
  background: var(--band);
  border-color: color-mix(in srgb, var(--band) 80%, black);
}
.board .cell.latest {
  color: #2a1c00;
  background: #fff;
  border-color: var(--gold-bright);
  box-shadow: 0 0 0 3px var(--gold-bright);
  font-weight: 800;
  animation: land 460ms var(--ease-spring);
  position: relative;
  z-index: 1;
}
/* A called number arrives with momentum, so a touch of overshoot is honest. */
@keyframes land {
  0% { transform: scale(0.55); }
  100% { transform: scale(1); }
}

/* ---------------------------------------------------------------- lists */

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--gap-2);
  padding: 0.5625rem 0.6875rem;
  margin-bottom: var(--gap-1);
  background: var(--surface-sunken);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
}
.list li.settled { opacity: 0.58; }
.list .who { display: flex; flex-direction: column; gap: 0.125rem; min-width: 0; }
.list .who strong { font-size: 0.9375rem; font-weight: 600; letter-spacing: -0.008em; overflow-wrap: anywhere; }

.feed { max-height: 17rem; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.feed li { display: block; font-size: 0.8438rem; padding: 0.4375rem 0.625rem; }
.feed li.call { color: var(--gold); font-weight: 600; }
.feed li.award { color: var(--green); font-weight: 650; }
.feed li.bogey { color: var(--red); }

/* --------------------------------------------------------------- claims */

.claimbar { display: flex; flex-wrap: wrap; gap: var(--gap-2); }
.claimbar .btn-claim {
  color: #2a1c00;
  background: var(--gold-bright);
  border-color: #d98e00;
  --edge: #b86e00;
  animation: beckon 1.5s var(--ease-settle) infinite;
}
/* Slow enough to read as an invitation rather than an alarm. */
@keyframes beckon {
  0%, 100% { box-shadow: 0 3px 0 var(--edge), 0 0 0 0 color-mix(in srgb, var(--gold-bright) 55%, transparent); }
  55% { box-shadow: 0 3px 0 var(--edge), 0 0 0 0.75rem transparent; }
}

/* ---------------------------------------------------------------- misc */

.qr {
  width: 10.75rem;
  padding: 0.5rem;
  background: #fff;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}
.qr svg { display: block; width: 100%; height: auto; }

/* One prize reads as a block: its name, its pattern, whatever that pattern
   needs, and a line saying what it will mean to players. The rule underneath
   is what keeps three prizes from running together into a wall of inputs. */
/* Every row keeps the same columns, so names, patterns and buttons line up
   down the list whatever each pattern needs. Sized against the editor's own
   width, not the window's: on the host desk it sits in a column. */
#prize-editor { container-type: inline-size; }
.prize-row {
  display: grid;
  grid-template-columns: minmax(8rem, 1fr) minmax(9rem, 13rem) 8.5rem auto;
  gap: var(--gap-1);
  align-items: center;
  padding-bottom: var(--gap-2);
  margin-bottom: var(--gap-2);
  border-bottom: 1px solid var(--hairline);
}
.prize-row:last-of-type { border-bottom: none; margin-bottom: 0; }

.prize-row select { width: 100%; min-width: 0; }
.prize-row input[type="number"] { width: 4.5rem; }

/* Whatever the chosen pattern needs: a count, a row picker, three boxes. */
.prize-row .prize-extra {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap-1);
  min-width: 0;
}
.prize-row .prize-extra:empty { display: none; }
.prize-row .prize-extra input[type="number"] { width: 3.5rem; }
.prize-row .prize-extra select { flex: 1; min-width: 5rem; }

.prize-row > input[type="text"] { grid-row: 1; grid-column: 1; }
.prize-row > select { grid-row: 1; grid-column: 2; }
.prize-row .prize-extra { grid-row: 1; grid-column: 3; }
.prize-row .drag { grid-row: 1; grid-column: 4; justify-self: end; flex-wrap: nowrap; gap: var(--gap-1); }
.prize-row .drag .btn-sm { width: 2.25rem; padding-left: 0; padding-right: 0; }

/* "Take the first 2, 2, 2 of rows" needs a line of its own. */
.prize-row .prize-extra.needs-room { grid-row: 2; grid-column: 1 / -1; }
.prize-row .prize-note { grid-column: 1 / -1; margin-top: 2px; }

/* Custom rule: which columns and rows count, as toggles. */
.chip-set { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.chip {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  border: 1px solid var(--hairline);
  border-radius: var(--r-full);
  background: var(--surface-sunken);
  color: var(--ink-2);
  box-shadow: none;
  cursor: pointer;
}
.chip.on { background: var(--gold-soft); border-color: var(--gold-bright); color: var(--ink); }

/* One player's ticket count, in the lobby roster. */
.ticket-count { width: 3.5rem; }

/* Narrow: name and buttons on top, pattern and its setting under them. */
@container (max-width: 36rem) {
  .prize-row { grid-template-columns: minmax(0, 1fr) auto; }
  .prize-row > input[type="text"] { grid-column: 1; grid-row: 1; }
  .prize-row .drag { grid-column: 2; grid-row: 1; }
  .prize-row > select { grid-column: 1 / -1; grid-row: 2; }
  .prize-row .prize-extra,
  .prize-row .prize-extra.needs-room { grid-column: 1 / -1; grid-row: 3; }
  .prize-row .prize-note { grid-column: 1 / -1; grid-row: 4; }
  .prize-row:has(.prize-extra:not(.needs-room):not(:empty)) > select { grid-column: 1; }
  .prize-row:has(.prize-extra:not(.needs-room):not(:empty)) .prize-extra { grid-column: 2; grid-row: 2; }
}

/* Narrow — the host desk's own left column counts as narrow, so this is what
   most hosts see. Placed row by row rather than left to auto-placement: the
   name wants the full width, the reorder buttons belong beside the pattern
   instead of on a line of their own, and whatever the pattern needs wants the
   whole width under both. */
/* Phone. Several tickets have to share one screen with the number being
   called, so the callout stops being a tall block and starts following the
   player down the page. */
@media (max-width: 40rem) {
  .called-panel {
    position: sticky;
    top: 0;
    z-index: 30;
    padding: var(--gap-2);
    margin-bottom: var(--gap-2);
  }
  .called-panel .callout { padding: var(--gap-2) var(--gap-2); }
  .called-panel .callout .big { font-size: clamp(2.25rem, 11vw, 3.25rem); }
  .called-panel .callout .said { margin-top: 2px; font-size: 0.9375rem; }

  /* Tighter squares, so three tickets and the callout fit one screen. */
  .ticket { gap: 0.25rem; padding: 0.375rem; }
  .tcell { aspect-ratio: 1 / 0.86; border-radius: 0.4375rem; }

  /* The panel holding the tickets earns none of its padding on a phone. */
  #play-tickets .panel { padding: var(--gap-2); gap: var(--gap-2); }

  /* Moving device is a once-a-game errand and was sitting above the game,
     costing the third ticket its place on the first screen. It goes to the
     bottom, where an errand belongs. */
  #game-view { display: flex; flex-direction: column; }
  #move-line { order: 99; }
  #move-note { order: 100; }
}


.toast-host {
  position: fixed;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--gap-1);
  z-index: 50;
  width: min(27rem, calc(100vw - 2rem));
  pointer-events: none;
}
.toast {
  padding: 0.6875rem 0.9375rem;
  font-size: 0.875rem;
  font-weight: 550;
  letter-spacing: -0.004em;
  color: var(--ink);
  background: var(--surface-strong);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  /* Glass arrives as a material: blur and scale together, not a flat fade. */
  animation: materialise 300ms var(--ease-spring);
}
.toast.bad { color: var(--red); border-color: color-mix(in srgb, var(--red) 34%, transparent); }
.toast.good { color: var(--green); border-color: color-mix(in srgb, var(--green) 34%, transparent); }
@keyframes materialise {
  from { opacity: 0; transform: translateY(0.75rem) scale(0.94); filter: blur(6px); }
  to { opacity: 1; transform: none; filter: blur(0); }
}

/* ------------------------------------------------------- reaction dock */

.react-dock {
  position: fixed;
  right: max(0.75rem, env(safe-area-inset-right));
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  z-index: 45;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--gap-2);
}

.react-fab {
  width: 3.25rem;
  height: 3.25rem;
  padding: 0;
  font-size: 1.6rem;
  line-height: 1;
  border-radius: 50%;
  background: var(--surface-strong);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow-lg);
}

/* Four across and two down: short enough that it does not reach up over the
   claim buttons, which are time-critical during play. */
.react-grid {
  display: grid;
  grid-template-columns: repeat(4, 2.75rem);
  gap: var(--gap-1);
  padding: var(--gap-2);
  border-radius: var(--r-lg);
  background: var(--surface-strong);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--hairline);
  box-shadow: var(--shadow-lg);
  animation: materialise 240ms var(--ease-spring);
}

.react-grid button {
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  border-radius: var(--r-sm);
  background: transparent;
  border-color: transparent;
}

/* The floaters rise from the dock, so they must not sit under it. */
.toast-host { bottom: max(1rem, calc(env(safe-area-inset-bottom) + 4.5rem)); }

/* The third row is the animated stickers, which need more room than a glyph. */
.react-grid .sticker { width: 2.25rem; height: 2.25rem; display: block; margin: auto; }

/* ------------------------------------------------------------- reactions */

/* Reactions used to be centred in the viewport, which put them squarely on
   top of the ticket — the one thing on screen a player actually needs to
   read. They now stack in a narrow lane pinned to the bottom-right, rising
   out of the dock they were sent from. The lane is sized so it cannot reach
   the ticket or the claim bar at any viewport width. */
.react-lane {
  position: fixed;
  right: max(0.75rem, env(safe-area-inset-right));
  bottom: max(5.25rem, calc(env(safe-area-inset-bottom) + 5.25rem));
  z-index: 44;
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: var(--gap-1);
  width: min(13rem, 46vw);
  /* Three compact rows is the whole lane. Bounding the height is what keeps a
     busy room's reactions in the bottom corner instead of climbing over the
     ticket. */
  max-height: 7.5rem;
  overflow: hidden;
  pointer-events: none;
}

.floater {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  max-width: 100%;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  background: var(--surface-strong);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--hairline);
  border-radius: var(--r-full);
  padding: 0.3125rem 0.6875rem;
  box-shadow: var(--shadow-md);
  animation: drift 2.8s var(--ease-settle) forwards;
}

.floater-emoji { font-size: 1.25rem; line-height: 1; }
.floater .sticker { width: 1.75rem; height: 1.75rem; flex: none; }
.floater-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8125rem;
  color: var(--ink-2);
}

/* It arrives with a lift and leaves by fading, rather than travelling up out
   of the lane. The old version rose 2.5rem on its way out, which carried it
   straight back over the bottom edge of the ticket — the exact complaint the
   lane was introduced to fix. Everything here stays inside the lane's box. */
@keyframes drift {
  0% { opacity: 0; transform: translateY(0.625rem) scale(0.9); }
  14% { opacity: 1; transform: translateY(0) scale(1); }
  72% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(0) scale(0.94); }
}

/* ---------------------------------------------------------- celebrations */

.celebrate-host { position: fixed; inset: 0; z-index: 70; pointer-events: none; }

.celebrate { position: absolute; inset: 0; }

/* A win is a top banner, never a takeover: the claim buttons underneath have
   to stay reachable, because the number just called is the only one another
   player's claim can still stand on. */
.celebrate.award .celebrate-card {
  position: absolute;
  top: max(0.75rem, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(26rem, calc(100vw - 1.5rem));
  animation: land 420ms var(--ease-spring) both;
}

/* A bogey lands in the same place as a win, so the room reads both the same
   way, but in the colour of bad news and with no confetti behind it. */
.celebrate.bogey .celebrate-card {
  position: absolute;
  top: max(0.75rem, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(26rem, calc(100vw - 1.5rem));
  border-color: color-mix(in srgb, var(--red) 46%, var(--hairline));
  animation: land 420ms var(--ease-spring) both;
}

/* The finale has no such constraint — the game is over. */
.celebrate.finale { background: rgba(6, 20, 25, 0.5); pointer-events: auto; }
.celebrate.finale .celebrate-card {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(27rem, calc(100vw - 2rem));
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
  /* Not `materialise`: its last frame is `transform: none`, which with
     fill-mode `both` wins over the centring transform above and leaves the
     card hanging off the right edge. Any keyframes on a transformed element
     have to carry that transform through. */
  animation: arrive 380ms var(--ease-spring) both;
}

@keyframes arrive {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.94); filter: blur(6px); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); filter: blur(0); }
}

.celebrate-card {
  display: flex;
  flex-direction: column;
  gap: var(--gap-2);
  padding: var(--gap-3);
  color: var(--ink);
  background: var(--surface-strong);
  backdrop-filter: blur(28px) saturate(185%);
  -webkit-backdrop-filter: blur(28px) saturate(185%);
  border: 1px solid color-mix(in srgb, var(--gold-bright) 42%, var(--hairline));
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
}

.celebrate-kicker {
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.014em;
  text-align: center;
}

.celebrate-lines { margin: 0; }
.celebrate-lines li { background: transparent; }
.celebrate.finale .celebrate-card button { align-self: center; }

@keyframes land {
  from { opacity: 0; transform: translateX(-50%) translateY(-1.25rem) scale(0.95); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti-bit {
  position: absolute;
  top: -4vh;
  width: 0.5rem;
  height: 0.8125rem;
  border-radius: 1px;
  opacity: 0;
  animation-name: fall;
  animation-timing-function: linear;
  animation-iteration-count: 1;
  animation-fill-mode: forwards;
}

@keyframes fall {
  0% { opacity: 0; transform: translateY(0) rotate(0deg); }
  8% { opacity: 1; }
  85% { opacity: 1; }
  100% { opacity: 0; transform: translateY(105vh) rotate(680deg); }
}

/* ------------------------------------------------- accessibility signals */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  /* Reduced motion still needs feedback — it just must not travel. */
  .toast { animation: fade-in 180ms ease both; }
  @keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
  .tcell.pressing { transform: none; }
  /* The confetti is suppressed in JS as well, so nothing is left mid-fall
     frozen at the top of the screen. */
  .confetti { display: none; }
  /* A floater would otherwise sit there forever: its removal is driven by
     animationend, which a ~0ms animation still fires. */
  .floater { animation: fade-in 180ms ease both; }
}

@media (prefers-reduced-transparency: reduce) {
  .panel, .toast, .banner {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: Canvas;
  }
}

@media (prefers-contrast: more) {
  :root { --hairline: currentColor; --ink-2: var(--ink); }
  .panel, .list li, .tcell, .board .cell { border-color: currentColor; }
  .pill { border-color: currentColor; }
}

/* A checkbox sits beside its sentence, never on a line of its own above it. */
label.row:has(> input[type="checkbox"]) { flex-wrap: nowrap; align-items: flex-start; }

/* ------------------------------------------------------------- admin desk */

.wrap.admin { max-width: 46rem; }
.admin-list { display: grid; gap: var(--gap-2); margin-top: var(--gap-3); }
.admin-item {
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: var(--gap-3);
  display: grid;
  gap: var(--gap-2);
}
.admin-item.off { opacity: 0.72; }
.admin-item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--gap-3); }
.admin-item-head > div:first-child { min-width: 0; }
.admin-item-side { display: flex; align-items: center; gap: var(--gap-2); flex-wrap: wrap; justify-content: flex-end; }
.admin-item-foot { padding-top: var(--gap-2); border-top: 1px solid var(--hairline); }
.admin-item-foot > summary { cursor: pointer; }
.admin-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.75rem; color: var(--ink-3); }
.admin-codes { margin-top: var(--gap-2); }
.admin-codes .pill { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.admin-codes .pill.used { text-decoration: line-through; opacity: 0.6; }

.admin-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr)); gap: var(--gap-2); }
.admin-stat {
  border: 1px solid var(--hairline);
  border-radius: var(--r-sm);
  padding: var(--gap-2) var(--gap-3);
  display: grid;
}
.admin-stat strong { font-size: 1.375rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.admin-stat span { font-size: 0.75rem; color: var(--ink-2); }
.admin-stat.bad strong { color: var(--red); }

.admin-setting {
  display: grid;
  grid-template-columns: 9.5rem minmax(0, 1fr);
  align-items: center;
  gap: var(--gap-2);
  padding-top: var(--gap-2);
  border-top: 1px solid var(--hairline);
}
.admin-setting .field {
  display: grid;
  gap: var(--gap-1);
  justify-items: start;
  font-size: 0.75rem;
  font-weight: 550;
  color: var(--ink-2);
}
#agent-count { margin-right: auto; font-weight: 500; }
.admin-setting .row { flex-wrap: nowrap; }
.admin-setting input { flex: 1; min-width: 0; padding-top: 0.4rem; padding-bottom: 0.4rem; }
.admin-setting .btn-sm { flex: none; }

.admin-fold > summary { list-style: none; cursor: pointer; }
.admin-fold > summary::-webkit-details-marker { display: none; }
.admin-fold > summary h2 { display: flex; justify-content: space-between; align-items: center; }
.admin-fold > summary h2::after { content: '+'; color: var(--ink-2); font-weight: 500; }
.admin-fold[open] > summary h2::after { content: '−'; }
.admin-fold[open] > summary { margin-bottom: var(--gap-3); }

@media (max-width: 40rem) {
  .admin-item-head { flex-direction: column; }
  .admin-item-side { justify-content: flex-start; }
  .admin-setting { grid-template-columns: minmax(0, 1fr); }
  .admin-setting .field { grid-auto-flow: column; justify-content: start; align-items: center; }
}

/* An agent folds to its name and status; tapping opens the rest. */
.admin-agent > summary { list-style: none; cursor: pointer; align-items: center; flex-direction: row; }
.admin-agent > summary::-webkit-details-marker { display: none; }
.admin-agent > summary > strong { margin-right: auto; }
.admin-agent > summary::after { content: '+'; color: var(--ink-2); font-weight: 500; width: 1ch; text-align: center; }
.admin-agent[open] > summary::after { content: '−'; }
.admin-agent:not([open]) { padding-top: var(--gap-2); padding-bottom: var(--gap-2); }
.admin-agent-body { display: grid; gap: var(--gap-2); margin-top: var(--gap-2); }
.admin-agent-body > .admin-item-head { align-items: center; }
