/* quiz-platform base styles. Every colour, font and corner comes from theme variables
   (docs/themes.md); the defaults below are a neutral dark theme used before a theme loads. */

:root {
  --bg: #121420; --bg-image: none;
  --surface: rgba(255,255,255,.07); --surface-2: rgba(255,255,255,.13); --line: rgba(255,255,255,.16);
  --text: #fff; --muted: #b9bdd0;
  --accent: #6c5ce7; --on-accent: #fff;
  --ok: #2ecc71; --on-ok: #08250f; --bad: #ff4d5e; --on-bad: #fff;
  --gold: #ffd34d; --silver: #cfd6e6; --bronze: #e0955a;
  --font-display: system-ui, sans-serif; --font-body: system-ui, sans-serif; --font-num: system-ui, sans-serif;
  --display-weight: 800; --display-stretch: 100%; --display-case: none;
  --radius: 16px; --tile-radius: 18px; --tile-border: 0; --tile-shadow: none;
  --t1: #e21b3c; --t2: #1368ce; --t3: #d89e00; --t4: #26890c; --t5: #864cbf; --t6: #0a8f8f;
  --t1-text: #fff; --t2-text: #fff; --t3-text: #fff; --t4-text: #fff; --t5-text: #fff; --t6-text: #fff;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background-color: var(--bg);
  background-image: var(--bg-image);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.display {
  font-family: var(--font-display);
  font-weight: var(--display-weight);
  font-stretch: var(--display-stretch);
  text-transform: var(--display-case);
  line-height: 1.05;
  letter-spacing: -0.01em;
}
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: var(--display-weight); }
.muted { color: var(--muted); }

/* ---------- buttons and inputs ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer;
  background: var(--accent); color: var(--on-accent);
  border-radius: var(--radius);
  padding: 18px 28px; font-size: 1.25rem; font-weight: 700;
  min-height: 56px;
  transition: transform .08s ease, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.small { padding: 8px 14px; min-height: 40px; font-size: 1rem; }
.btn.big { width: 100%; font-size: 1.6rem; min-height: 72px; }
.field {
  width: 100%; border-radius: var(--radius);
  border: 3px solid var(--line); background: var(--surface);
  padding: 16px 18px; font-size: 1.4rem; outline: none;
}
.field:focus { border-color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

/* ---------- answer tiles (shared by player + host) ---------- */
.tile {
  --c: var(--t1); --ct: var(--t1-text);
  position: relative;
  display: flex; align-items: center; gap: .6em;
  background: var(--c); color: var(--ct);
  border: var(--tile-border); border-radius: var(--tile-radius);
  box-shadow: var(--tile-shadow);
  padding: .5em .7em; min-width: 0;
  text-align: left; cursor: pointer; user-select: none;
  transition: transform .1s ease, opacity .2s, filter .2s;
  overflow: hidden;
}
.tile .n {
  flex: none;
  display: grid; place-items: center;
  width: 1.7em; height: 1.7em; border-radius: calc(var(--tile-radius) * .7);
  background: color-mix(in srgb, var(--ct) 22%, transparent);
  font-family: var(--font-num); font-weight: var(--display-weight); font-variant-numeric: tabular-nums;
  line-height: 1;
}
.tile .label {
  min-width: 0; font-weight: 700; line-height: 1.1;
  overflow-wrap: break-word;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
/* "Display (@handle)": the name breaks only at spaces, the handle gets its own smaller line */
.tile .label.two { display: flex; flex-direction: column; gap: .08em; -webkit-line-clamp: unset; }
.tile .label.two .nm { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: break-word; }
.tile .label.two .hd { font-size: .7em; font-weight: 600; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* answer tiles: a word never breaks; fitTiles() (util.js) shrinks the label instead, .brk is the last resort */
.p-tiles .tile .label, .h-tiles .tile .label, .p-tiles .tile .label .nm, .h-tiles .tile .label .nm { overflow-wrap: normal; max-width: 100%; }
.p-tiles .tile .label.two .hd, .h-tiles .tile .label.two .hd { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.p-tiles .tile .label.brk, .h-tiles .tile .label.brk, .tile .label.brk .nm { overflow-wrap: anywhere; }
.tile .avatar { width: 1.6em; height: 1.6em; border-radius: 50%; object-fit: cover; flex: none; }
.tile.dim { opacity: .28; filter: saturate(.5); }
.tile.picked { outline: 6px solid var(--text); outline-offset: 3px; }
.tile .check {
  position: absolute; right: .4em; top: .3em; font-size: .9em; font-weight: 900;
}

/* ---------- player app ---------- */
.player {
  min-height: 100dvh; display: flex; flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  max-width: 720px; margin: 0 auto;
}
.p-top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 1rem; color: var(--muted); min-height: 36px; padding: 0 4px;
}
.p-top .who { font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.who { appearance: none; background: none; border: 0; padding: 6px 0; font: inherit; font-weight: 700; color: var(--text); cursor: pointer; max-width: 50%; text-align: left; }
dialog.rename { border: 2px solid var(--line); border-radius: var(--radius); background: var(--bg); color: var(--text); padding: 20px; width: min(92vw, 420px); }
dialog.rename::backdrop { background: rgb(0 0 0 / .55); }
dialog.rename form { display: flex; flex-direction: column; gap: 12px; }
dialog.rename label { font-weight: 700; }
dialog.rename input { font-size: 1.25rem; padding: 12px; border-radius: 10px; border: 2px solid var(--surface-2); background: var(--surface-2); color: var(--text); }
dialog.rename .row { display: flex; gap: 10px; justify-content: flex-end; background: none; border: 0; padding: 0; }
.p-top .score { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text); }
.p-main { flex: 1; display: flex; flex-direction: column; gap: 12px; padding-top: 8px; }
.p-center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 16px; padding: 16px; }
.p-big { font-size: clamp(2.4rem, 11vw, 4.5rem); }
.p-mid { font-size: clamp(1.4rem, 6vw, 2.2rem); }
.p-prompt { font-size: clamp(1.15rem, 4.6vw, 1.6rem); text-align: center; padding: 0 6px; }
.p-timer { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.p-timer i { display: block; height: 100%; background: var(--accent); width: 100%; transform-origin: left; }

.p-tiles { flex: 1; display: grid; gap: 10px; grid-template-columns: 1fr 1fr; grid-auto-rows: 1fr; min-height: 60dvh; }
/* match (cm-798): A-D strip, the row being set, the number tiles fill the rest; a taken number dims and shows its letter */
.p-match { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.p-match .p-tiles { min-height: 0; }
.p-mrows { display: flex; justify-content: center; gap: 8px; }
.p-mrows .mrow { display: flex; align-items: center; gap: 6px; padding: 4px 8px 4px 10px; border-radius: 99px; background: var(--surface-2); font-size: 1.1rem; opacity: .65; }
.p-mrows .mrow i { font: var(--display-weight) 1rem/1 var(--font-num); font-style: normal; min-width: 1.6em; height: 1.6em; display: grid; place-items: center; border-radius: 50%; background: var(--surface); color: var(--muted); }
.p-mrows .mrow.set { opacity: 1; }
.p-mrows .mrow.now { opacity: 1; outline: 3px solid var(--text); }
.p-mcur { display: flex; align-items: center; justify-content: center; gap: 14px; min-width: 0; }
.p-mcur .lt { font-size: clamp(2.6rem, 13vw, 4rem); line-height: 1; }
.p-mcur .lb { font-size: clamp(1.4rem, 6.5vw, 2.2rem); font-weight: 800; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-match .tile { position: relative; }
.p-match .tile.taken { opacity: .28; filter: saturate(.3); }
.p-match .tile .used { position: absolute; top: 6px; right: 8px; font: var(--display-weight) 1.6rem/1 var(--font-num); }
.p-mbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; }
.p-mbar [data-undo][hidden] { display: inline-block; visibility: hidden; }
.p-mlist { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 420px; }
.p-mlist .mr { display: grid; grid-template-columns: 2em minmax(0, 1fr) auto 1.4em; align-items: center; gap: 10px; text-align: left; font-size: 1.2rem; background: var(--surface); border-radius: var(--radius); padding: 6px 10px; }
.p-mlist .mr b { font-size: 1.4rem; }
.p-mlist .mr .lb { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-mlist .mr .ch { display: flex; align-items: center; gap: 6px; }
.p-mlist .mr .p-mini { padding: 2px 10px; min-height: 0; }
.p-mlist .mr .p-mini.wrong { opacity: .45; text-decoration: line-through; }
.p-mlist .mr .mk { font-weight: 900; }
.p-mlist .mr.ok .mk { color: var(--ok); }
.p-mlist .mr.bad .mk { color: var(--bad, #c0392b); }
.p-tiles[data-count="2"] { grid-template-columns: 1fr; }
.p-tiles[data-count="3"] .tile:last-child { grid-column: span 2; }
.p-tiles[data-count="5"] .tile:last-child { grid-column: span 2; }
.p-tiles .tile { flex-direction: column; justify-content: center; text-align: center; font-size: clamp(1.35rem, 6.4vw, 2.1rem); padding: 14px 10px; }
.p-tiles .tile .n { font-size: clamp(2.2rem, 12vw, 4rem); width: 1.5em; height: 1.5em; }
.p-tiles[data-count="2"] .tile { flex-direction: row; justify-content: flex-start; text-align: left; font-size: clamp(1.4rem, 6.5vw, 2.2rem); }
.p-tiles .tile:active { transform: scale(.96); }
/* a phone on its side (cm-578): one screen, no scroll; 2-3 side by side, 4 = 2x2, 5 = 3+2 full width, 6 = 3x2 */
@media (orientation: landscape) and (max-height: 560px) {
  .player { height: 100dvh; min-height: 0; max-width: none; padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .p-main { min-height: 0; gap: 8px; padding-top: 4px; }
  .p-prompt { font-size: clamp(1rem, 4.2vh, 1.4rem); }
  .p-tiles { min-height: 0; gap: 8px; grid-template-columns: 1fr 1fr; }
  .p-tiles[data-count="2"] { grid-template-columns: 1fr 1fr; }
  .p-tiles[data-count="3"], .p-tiles[data-count="6"] { grid-template-columns: repeat(3, 1fr); }
  .p-tiles[data-count="5"] { grid-template-columns: repeat(6, 1fr); }
  .p-tiles[data-count="3"] .tile:last-child { grid-column: auto; }
  .p-tiles[data-count="5"] .tile { grid-column: span 2; }
  .p-tiles[data-count="5"] .tile:nth-child(n+4) { grid-column: span 3; }
  .p-tiles .tile, .p-tiles[data-count="2"] .tile { min-height: 0; flex-direction: row; justify-content: flex-start; text-align: left; padding: 6px 12px; font-size: clamp(1rem, 5.2vh, 1.6rem); }
  .p-tiles .tile .n { font-size: clamp(1.4rem, 9vh, 2.4rem); }
  .p-center { gap: 6px; padding: 6px; }
  /* match on its side: strip, row and undo on one line over the tiles; the result rows in two columns */
  .p-match { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-rows: auto minmax(0, 1fr); gap: 6px 12px; }
  .p-match .p-mrows { grid-area: 1 / 1; }
  .p-match .p-mcur { grid-area: 1 / 2; justify-content: flex-start; }
  .p-match .p-mbar { grid-area: 1 / 3; min-height: 0; }
  .p-match .p-mbar [data-mhint] { display: none; }
  .p-match .p-tiles { grid-area: 2 / 1 / 3 / 4; }
  .p-mcur .lt { font-size: clamp(1.6rem, 9vh, 2.4rem); }
  .p-mcur .lb { font-size: clamp(1.1rem, 6vh, 1.6rem); }
  .p-mrows .mrow { font-size: .95rem; padding: 2px 6px 2px 8px; }
  .p-mlist { display: grid; grid-template-columns: 1fr 1fr; max-width: none; gap: 6px; }
  .p-mlist .mr { font-size: 1rem; padding: 3px 8px; }
  .p-center .p-result { padding: 10px 14px; }
  .p-center .p-result .pts { font-size: clamp(1.4rem, 9vh, 2.4rem); }
  .p-big { font-size: clamp(1.8rem, 11vh, 3rem); }
  .p-mid { font-size: clamp(1rem, 5.5vh, 1.5rem); }
}

.p-list { display: flex; flex-direction: column; gap: 8px; }
.p-list .tile { font-size: clamp(1.25rem, 5.6vw, 1.7rem); min-height: 64px; padding: 8px 12px; }
.p-list .tile .n { font-size: 1.35em; }
.p-list .tile:active { transform: scale(.98); }

.p-sendbar { position: sticky; bottom: 0; padding: 10px 0 4px; background: linear-gradient(transparent, var(--bg) 35%); }

.p-number { display: flex; flex-direction: column; gap: 14px; padding: 8px 4px; }
.p-number input { font-size: clamp(2.5rem, 14vw, 4.5rem); text-align: center; font-family: var(--font-num); font-weight: 700; padding: 18px 10px; }
.p-number .unit { text-align: center; font-size: 1.3rem; }
.p-numhint { text-align: center; font-size: 1.3rem; min-height: 1.6em; margin-top: -4px; color: var(--muted); }
.p-numhint b { font-family: var(--font-num); font-size: 2rem; color: var(--text); }
.p-numhint.bad { color: var(--bad); font-weight: 700; }

.p-result { border-radius: var(--radius); padding: 28px 18px; width: 100%; }
.p-result.ok { background: var(--ok); color: var(--on-ok); }
.p-result.bad { background: var(--bad); color: var(--on-bad); }
.p-result.neutral { background: var(--surface-2); }
.p-result .pts { font-size: clamp(2rem, 10vw, 3.5rem); }
.p-mini { pointer-events: none; font-size: 1.4rem; width: 100%; justify-content: flex-start; min-height: 64px; }

/* the race on the phone (cm-579/580): place, movement, the neighbours just ahead and behind */
.p-race { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.p-race-head { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.p-race .mv { font-weight: 800; font-size: 1.1rem; }
.p-race .mv.up { color: var(--ok); } .p-race .mv.down { color: var(--bad); } .p-race .mv.same { color: var(--muted); }
.p-track { width: 100%; display: flex; flex-direction: column; gap: 4px; }
.p-track .rc { display: grid; grid-template-columns: 1.6em 1fr auto auto; align-items: center; gap: 10px; padding: 8px 12px; border-radius: var(--radius);
  background: var(--surface); color: var(--muted); font-size: 1rem; text-align: left; }
.p-track .rc .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.p-track .rc .df { font-size: .85em; min-width: 5.5em; text-align: right; }
.p-track .rc.me { background: var(--accent); color: var(--on-accent); font-weight: 800; font-size: 1.15rem; }
.p-track .rc.lead { color: var(--gold, var(--text)); }
.rows { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  background: var(--surface); border-radius: var(--radius); font-size: 1.15rem;
}
.row.me { background: var(--accent); color: var(--on-accent); }
.row .rk { width: 2.2em; font-family: var(--font-num); font-weight: 700; }
.row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.row .sc { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: 700; }

.pop { animation: pop .45s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.rise { animation: rise .5s ease both; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.spin { width: 48px; height: 48px; border-radius: 50%; border: 6px solid var(--surface-2); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- host / TV: a fixed 1920x1080 stage scaled to the screen ---------- */
body.tv { overflow: hidden; }
.stage-wrap { position: fixed; inset: 0; display: grid; place-items: center; overflow: hidden; }
.stage {
  position: absolute; left: 50%; top: 50%; width: 1920px; height: 1080px; flex: none;
  transform: translate(-50%, -50%) scale(var(--s, 1)); transform-origin: center;
  padding: 56px 72px; display: flex; flex-direction: column;
}
.h-top { display: flex; align-items: center; justify-content: space-between; gap: 32px; font-size: 34px; color: var(--muted); height: 64px; }
.h-top .brand { font-weight: 700; color: var(--text); }
.h-top .joinhint { font-size: 30px; }
.h-top .joinhint b { color: var(--text); font-family: var(--font-num); letter-spacing: .08em; }

/* lobby */
.h-lobby { flex: 1; display: grid; grid-template-columns: 1fr 560px; gap: 72px; align-items: center; }
.h-lobby .how { font-size: 44px; color: var(--muted); margin: 0 0 12px; }
.h-lobby .how b { color: var(--text); }
/* lobby: the code and the QR are always at full contrast, never faded, never selectable; the state is .h-status */
.h-code { font-size: 260px; line-height: .9; letter-spacing: .02em; color: var(--text); white-space: nowrap; display: flex; gap: .3em;
  opacity: 1; text-shadow: none; background: none; user-select: none; -webkit-user-select: none; cursor: default; }
.h-status { display: inline-flex; align-items: center; gap: 16px; font-size: 34px; font-weight: 700; line-height: 1.1; padding: 12px 24px;
  border: 3px solid currentColor; border-radius: var(--radius); margin: 0 0 26px; color: var(--text); user-select: none; }
.h-status i { width: 20px; height: 20px; border-radius: 50%; border: 4px solid currentColor; flex: none; }
.h-status.live { color: var(--ok); }
.h-status.live i { background: currentColor; }
/* above any theme overlay (arcade's scanlines sit at z-index 40): the code and the QR stay crisp */
.h-code, .h-qr { position: relative; z-index: 45; }
.h-act { display: flex; align-items: center; gap: 24px; margin: 30px 0 26px; flex-wrap: wrap; }
.h-btn { font: 800 40px/1 var(--font-display); font-stretch: var(--display-stretch, 100%); padding: 22px 38px; border-radius: var(--radius); border: 0;
  background: var(--accent); color: var(--on-accent); cursor: pointer; }
.h-btn:hover { filter: brightness(1.08); }
.h-btn:focus-visible { outline: 4px solid var(--text); outline-offset: 4px; }
.h-why { font-size: 30px; font-weight: 600; color: var(--text); max-width: 560px; line-height: 1.25; }
.h-qr { background: #fff; border-radius: var(--radius); padding: 24px 24px 18px; width: 560px; display: flex; flex-direction: column; align-items: center; gap: 8px; opacity: 1; }
.h-qr img { width: 512px; height: 512px; display: block; image-rendering: pixelated; }
.h-qr .noqr { width: 512px; height: 512px; display: grid; place-items: center; color: #1a1a1a; font-size: 36px; text-align: center; }
.h-qr .cap { color: #111; font: 700 28px/1.2 var(--font-body); letter-spacing: 0; text-transform: none; }
.h-names { height: 230px; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 14px; overflow: hidden; margin-top: 12px; }
.h-names .chip { font-size: 36px; font-weight: 700; padding: 10px 22px; border-radius: var(--radius); background: var(--surface-2); }
.h-count { font-size: 40px; color: var(--muted); display: flex; align-items: baseline; gap: 16px; }
.h-count .num { font-size: 96px; color: var(--text); }

/* question */
.h-q { flex: 1; display: flex; flex-direction: column; gap: 28px; min-height: 0; }
.h-prompt { font-size: 76px; text-align: center; margin: 4px 40px 0; text-wrap: balance; }
.h-prompt.long { font-size: 60px; }
.h-sub { font-size: 34px; text-align: center; color: var(--muted); margin-top: -12px; }
.h-mid { flex: 0 0 auto; height: 230px; display: flex; align-items: center; justify-content: space-between; gap: 40px; min-height: 0; }
.h-clock {
  width: 200px; height: 200px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: conic-gradient(var(--accent) calc(var(--p, 1) * 360deg), var(--surface-2) 0);
  position: relative;
}
.h-clock::after { content: ""; position: absolute; inset: 16px; border-radius: 50%; background: var(--bg); }
.h-clock span { position: relative; z-index: 1; font-size: 96px; }
.h-answered { text-align: center; width: 220px; flex: none; }
.h-answered .num { font-size: 120px; display: block; line-height: 1; }
.h-answered .lbl { font-size: 32px; color: var(--muted); }
.h-media { flex: 1; display: grid; place-items: center; min-height: 0; height: 100%; }
.h-media img { max-height: 100%; max-width: 100%; border-radius: var(--radius); }
.h-guess { font-size: 64px; text-align: center; color: var(--muted); }
.h-q.has-media .h-mid { flex: 1; height: auto; }
.h-tiles { flex: 1; min-height: 0; max-height: 560px; display: grid; gap: 20px; grid-template-columns: 1fr 1fr; grid-auto-rows: 1fr; }
.h-q.has-media .h-tiles { flex: 0 0 auto; max-height: 300px; }
/* match (cm-798): rows A.. on the left, the numbered tiles on the right, both columns the full height */
.h-match { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 56px; }
.h-mleft, .h-mright { display: grid; grid-auto-rows: 1fr; gap: 16px; min-height: 0; }
.h-mrow { display: flex; align-items: center; gap: 22px; background: var(--surface); border-radius: var(--tile-radius, var(--radius)); padding: 0 26px; font-size: 48px; font-weight: 800; min-width: 0; min-height: 0; }
.h-mrow .lt { font-size: 68px; width: 1.1em; flex: none; text-align: center; }
.h-mrow .avatar { width: 64px; height: 64px; }
.h-mrow .lb, .h-mright .tile .label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-mright .tile { font-size: 44px; min-height: 0; cursor: default; padding-top: 0; padding-bottom: 0; }
.h-mright .tile .n { font-size: 56px; }
.h-match[data-rows="5"] .h-mrow, .h-match[data-rows="6"] .h-mrow, .h-match[data-count="5"] .h-mright .tile, .h-match[data-count="6"] .h-mright .tile { font-size: 38px; }
.h-mhint { text-align: center; font-size: 30px; color: var(--muted); margin-top: -12px; }
.h-tiles .tile { font-size: 58px; min-height: 110px; cursor: default; }
.h-tiles .tile .n { font-size: 72px; }
.h-tiles[data-count="3"], .h-tiles[data-count="6"] { grid-template-columns: 1fr 1fr 1fr; }
/* 5 options: 3 on top, 2 below, both rows the full width (cm-578) */
.h-tiles[data-count="5"] { grid-template-columns: repeat(6, 1fr); }
.h-tiles[data-count="5"] .tile { grid-column: span 2; }
.h-tiles[data-count="5"] .tile:nth-child(n+4) { grid-column: span 3; }
.h-tiles[data-count="5"] .tile, .h-tiles[data-count="6"] .tile { font-size: 50px; }
.h-tiles[data-count="3"] .tile, .h-tiles[data-dense] .tile { flex-direction: column; justify-content: center; text-align: center; }
.h-tiles[data-dense] { grid-template-columns: repeat(4, 1fr); gap: 14px; }
.h-tiles[data-dense] .tile { font-size: 34px; min-height: 96px; padding: 10px 12px; flex-direction: row; justify-content: flex-start; text-align: left; }
.h-tiles[data-dense] .tile .n { font-size: 40px; }
.h-tiles[data-dense="xl"] { grid-template-columns: repeat(5, 1fr); }
.h-tiles[data-dense="xl"] .tile { font-size: 28px; min-height: 80px; padding: 10px 10px; gap: .45em; }
.h-tiles[data-dense="xl"] .tile .n { font-size: 34px; }
.h-tiles[data-dense] .tile .label.two .nm { -webkit-line-clamp: 4; }
.h-tiles .tile .cnt { margin-left: auto; font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: .8em; opacity: .9; padding-left: 12px; }
.h-tally { display: flex; height: 18px; border-radius: 99px; overflow: hidden; background: var(--surface-2); }
.h-tally i { display: block; height: 100%; transition: flex-grow .4s ease; }
.h-autobar { position: absolute; left: 0; right: 0; bottom: 0; height: 6px; z-index: 7; }
.h-autobar i { display: block; height: 100%; background: var(--accent); transform-origin: left; transition: transform .25s linear; }
/* in the middle row between the clock and the count, never on top of the answers (cm-629) */
.h-locked { font-size: 84px; line-height: 1; padding: 18px 44px; background: var(--accent); color: var(--on-accent); border-radius: var(--radius); white-space: nowrap; transform: rotate(-2deg); }

/* reveal */
.h-rv-head { display: flex; align-items: center; gap: 28px; margin-bottom: 18px; }
.h-rv-head .qn { font-size: 34px; color: var(--muted); white-space: nowrap; }
.h-rv-head .p { font-size: 48px; flex: 1; text-wrap: balance; }
.h-reveal { flex: 1; position: relative; overflow: hidden; container-type: size; min-height: 0; }

/* leaderboard */
/* the break between rounds: the round's name on the left, the standings so far on the right */
.h-round { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 72px; align-items: center; min-height: 0; }
.h-round.first { grid-template-columns: 1fr; justify-items: center; text-align: center; }
.h-rhead .kick { font-size: 40px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }
.h-rhead h2 { font-size: 120px; line-height: 1; margin: 12px 0 16px; overflow-wrap: break-word; }
.h-round.first .h-rhead h2 { font-size: 150px; }
.h-rhead p { font-size: 40px; color: var(--muted); margin: 0 0 36px; }
.h-round.first .h-act { justify-content: center; }
.h-round .h-lb { margin: 0; }
.h-round .h-lb h2 { font-size: 56px; text-align: left; }
.h-lb { flex: 1; display: flex; flex-direction: column; gap: 18px; justify-content: center; max-width: 1400px; width: 100%; margin: 0 auto; }
.h-lb h2 { font-size: 80px; margin: 0 0 18px; text-align: center; }
.lbrow { display: grid; grid-template-columns: 110px 90px 1fr auto auto; align-items: center; gap: 24px; padding: 18px 32px; background: var(--surface); border-radius: var(--radius); font-size: 52px; }
.lbrow:nth-child(2) { background: var(--surface-2); }
.lbrow .rk { font-family: var(--font-num); font-weight: var(--display-weight); }
.lbrow .mv { font-size: 34px; font-weight: 800; text-align: center; }
.lbrow .mv.up { color: var(--ok); } .lbrow .mv.down { color: var(--bad); } .lbrow .mv.same { color: var(--muted); }
.lbrow .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lbrow .dl { font-size: 36px; color: var(--muted); font-family: var(--font-num); }
.lbrow .sc { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-weight: var(--display-weight); min-width: 5ch; text-align: right; }
.h-lb .rest { text-align: center; font-size: 34px; color: var(--muted); margin-top: 6px; }

/* podium */
.h-final { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.h-final h2 { font-size: 84px; text-align: center; margin: 0; }
.podium { flex: 1; display: grid; grid-template-columns: repeat(3, 420px); justify-content: center; align-items: end; gap: 28px; }
.pod { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.pod .nm { font-size: 56px; font-weight: 800; text-align: center; max-width: 420px; overflow-wrap: anywhere; line-height: 1.05; }
.pod .sc { font-size: 40px; color: var(--muted); font-family: var(--font-num); }
.pod .block { width: 100%; border-radius: var(--radius) var(--radius) 0 0; display: grid; place-items: start center; padding-top: 22px; font-size: 140px; color: var(--bg); }
.pod.p1 .block { height: 440px; background: var(--gold); }
.pod.p2 .block { height: 320px; background: var(--silver); }
.pod.p3 .block { height: 230px; background: var(--bronze); }
.pod { animation: rise .8s ease both; }
.pod.p3 { animation-delay: .3s; } .pod.p2 { animation-delay: 1s; } .pod.p1 { animation-delay: 1.8s; }
.h-final .others { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px 28px; font-size: 30px; color: var(--muted); padding-top: 20px; max-height: 96px; overflow: hidden; }

.h-banner { text-align: center; font-size: 40px; padding: 14px; border-radius: var(--radius); background: var(--surface-2); margin-bottom: 14px; }

/* host control bar (outside the stage, not scaled) */
.ctl {
  position: fixed; left: 0; right: 0; margin: 0 auto; width: fit-content; bottom: 14px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center;
  padding: 8px 10px; border-radius: 16px;
  background: rgba(10, 12, 20, .82); color: #fff; backdrop-filter: blur(8px);
  font-family: system-ui, sans-serif; font-size: 15px; z-index: 50;
  transition: opacity .3s, transform .3s;
  max-width: calc(100vw - 20px);
}
.ctl.hide { opacity: 0; transform: translateY(20px); pointer-events: none; }
.ctl button, .ctl select { border: 0; border-radius: 10px; padding: 9px 14px; background: #2b2f40; color: #fff; cursor: pointer; font: 600 15px system-ui, sans-serif; }
.ctl select { max-width: 140px; padding-right: 8px; text-overflow: ellipsis; }
.ctl button.primary { background: #4c6ef5; }
.ctl button.go { background: #2f9e44; }
.ctl button.warn { background: #c92a2a; }
.ctl button:disabled { opacity: .4; cursor: default; }
.ctl .st { padding: 0 8px; color: #c9cee0; white-space: nowrap; }
.ctl .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #868e96; margin-right: 6px; }
.ctl .dot.live { background: #40c057; } .ctl .dot.stopped { background: #fa5252; }
.ctl .sep { width: 1px; align-self: stretch; background: #3b4055; margin: 0 4px; }

.toast { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); background: #c92a2a; color: #fff; padding: 10px 16px; border-radius: 10px; font: 600 15px system-ui, sans-serif; z-index: 60; }
/* realtime (docs/realtime.md): calm reconnect pill, answer delivery line, host connection dots */
.conn { position: fixed; left: 0; right: 0; margin: 0 auto; width: fit-content; bottom: max(14px, env(safe-area-inset-bottom)); z-index: 60; display: flex; align-items: center; gap: 10px; background: linear-gradient(var(--surface-2), var(--surface-2)), var(--bg); border: 1px solid var(--line); color: var(--text); padding: 10px 16px; border-radius: var(--radius); font-weight: 600; font-size: 15px; max-width: calc(100vw - 28px); animation: rise .25s ease-out; }
.conn i { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; animation: breathe 1.4s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .25; } }
.p-astatus { margin: 0; font-weight: 700; font-size: 1.05rem; color: var(--ok); min-height: 1.4em; }
.p-astatus[data-s="sending"], .p-astatus[data-s="offline"] { color: var(--muted); }
.h-names .chip[data-conn] { position: relative; padding-left: 46px; cursor: pointer; }
.h-names .chip[data-conn]::before { content: ""; position: absolute; left: 18px; top: 50%; width: 14px; height: 14px; margin-top: -7px; border-radius: 50%; background: var(--ok); }
.h-names .chip[data-conn="reconnecting"]::before { background: var(--muted); animation: breathe 1.4s ease-in-out infinite; }
.h-names .chip[data-conn="gone"] { opacity: .45; animation: none; } /* .pop fills opacity:1 */
.h-names .chip[data-conn="gone"]::before { background: var(--bad); }
.h-reconn { display: block; font-size: 22px; color: var(--muted); min-height: 28px; }

/* ---------- landing / join ---------- */
.gate { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; padding: 24px 18px; text-align: center; max-width: 520px; margin: 0 auto; }
.gate h1 { font-size: clamp(2.6rem, 12vw, 4.2rem); margin: 0; }
.gate p { margin: 0; font-size: 1.2rem; color: var(--muted); }
.gate form { width: 100%; display: flex; flex-direction: column; gap: 14px; }
.code-in { font-family: var(--font-num); font-size: clamp(2.6rem, 14vw, 4rem); text-align: center; letter-spacing: .18em; padding: 14px 8px; }
.err { color: var(--bad); font-weight: 700; min-height: 1.4em; font-size: 1.1rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
}
