/* style.css — Flag Party. One stylesheet for every page (index, player,
 * screen, howto). Dark, party-appropriate; readable on a TV (large) and on
 * phones. Design tokens follow the GeoParty kernel's palette for family
 * consistency; the flag-reveal grid + buzzer are new. No build step, no web
 * fonts (must render offline once served) — hierarchy is carried by scale,
 * weight, spacing and one warm accent, not by a downloaded typeface. */

:root {
  --bg: #0e0e12;
  --panel: #17171e;
  --panel-2: #22222c;
  --raised: #2e2e3a;
  --fg: #f4f4f6;
  --muted: #b0b0bc;
  --faint: #7c7c8a;
  --accent: #ffcf3f;
  --accent-ink: #1c1608; /* text/icon on the yellow accent */
  --accent-2: #4dd6ff;
  --good: #4ade80;
  --bad: #f87171;
  --team-1: #ffcf3f;
  --team-2: #4dd6ff;
  --team-3: #ff6ec7;
  --team-4: #7dff8a;
  --disabled-fg: #8a8a96;
  --tile-cover: #1b1b24;

  /* hairlines: light-on-dark borders read as crafted edges, not boxes */
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.15);
  --focus: var(--accent-2);

  /* No web font by design; lean on the best available display faces per OS,
     then do the real work with scale/weight/tracking below. */
  --font-display: "Space Grotesk", "SF Pro Display", "Segoe UI", system-ui,
    -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;

  --radius: 16px;
  --radius-sm: 11px;
  --shadow-1: 0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 10px 30px -18px rgba(0, 0, 0, 0.9);
  --shadow-pop: 0 18px 44px -20px rgba(0, 0, 0, 0.85);
  --maxw: 560px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background:
    radial-gradient(900px 620px at 50% -12%, #1c1c28 0%, transparent 62%),
    radial-gradient(700px 500px at 88% 108%, #1a1622 0%, transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.05;
  text-wrap: balance;
}
p { text-wrap: pretty; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--fg); text-decoration: underline; text-underline-offset: 3px; }

/* One focus ring for the whole app — visible, keyboard-only. */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

button {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--panel-2);
  color: var(--fg);
  padding: 0.72em 1.2em;
  min-height: 44px; /* comfortable phone target */
  transition: transform 0.06s ease, background 0.15s ease, border-color 0.15s ease,
    filter 0.15s ease, opacity 0.15s ease;
}
button:hover { background: var(--raised); border-color: var(--line-strong); }
button:active { transform: translateY(1px); }
button:disabled {
  opacity: 1;
  background: var(--raised);
  border-color: transparent;
  color: var(--disabled-fg);
  cursor: default;
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  letter-spacing: 0.01em;
  border-color: transparent;
  box-shadow: 0 10px 26px -14px rgba(255, 207, 63, 0.7);
}
.btn-primary:hover { background: var(--accent); filter: brightness(1.06); }
.btn-primary:disabled { background: var(--raised); color: var(--disabled-fg); box-shadow: none; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--fg); background: rgba(255, 255, 255, 0.05); }
.link-btn {
  background: none;
  border: none;
  min-height: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link-btn:hover { color: var(--fg); background: none; }

.hidden { display: none !important; }
.muted-note { color: var(--muted); font-size: 0.95rem; }
.eyebrow {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  font-weight: 700;
  margin: 0 0 0.35rem;
}

/* ---- Layout ---- */
.wrap {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1.5rem 1.15rem 6rem;
}
.phase-screen { min-height: 100vh; }
.brand {
  font-size: clamp(2.1rem, 8vw, 3.1rem);
  margin: 0.1em 0 0.12em;
  letter-spacing: -0.03em;
}
.brand .accent { color: var(--accent); }
.tagline {
  color: var(--muted);
  margin: 0 0 1.5rem;
  line-height: 1.45;
  font-size: 1.02rem;
  max-width: 42ch;
}

/* ---- Forms ---- */
.settings-group { margin: 0 0 1.15rem; }
.field-label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0.6rem 0 0.35rem;
}
input, select {
  width: 100%;
  font: inherit;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0.72em 0.85em;
  min-height: 48px;
}
input::placeholder { color: var(--faint); }
input:focus, select:focus {
  outline: none;
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(77, 214, 255, 0.22);
}
.code-input {
  text-transform: uppercase;
  letter-spacing: 0.35em;
  font-weight: 800;
  font-family: var(--font-display);
  text-align: center;
}
.join-row { display: flex; gap: 0.5rem; align-items: stretch; }
.join-row .code-input { flex: 1; }
.join-row .btn-primary { white-space: nowrap; }
.join-err { color: var(--bad); font-size: 0.9rem; min-height: 1.2em; margin-top: 0.4rem; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow-1);
}

.resume-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-top: 1.1rem;
  box-shadow: var(--shadow-1);
}

/* ---- Lobby (a Configure surface: set the table, then start) ---- */
.lobby-head { margin-bottom: 1.1rem; }
.room-code-block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem 1rem 0.9rem;
  text-align: center;
  box-shadow: var(--shadow-1);
}
.room-code-huge {
  font-family: var(--font-display);
  font-size: clamp(2.7rem, 13vw, 4rem);
  font-weight: 800;
  letter-spacing: 0.26em;
  text-indent: 0.26em; /* balance the trailing tracking */
  text-align: center;
  color: var(--accent);
  margin: 0.1rem 0 0;
  line-height: 1;
}

/* The lobby's setup summary now leads the "Who's in" block; give it room to
   breathe below the TV-connect card above it. */
.lobby-mode { margin: 1.1rem 0 0; }

.section-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  font-weight: 700;
  margin: 1.4rem 0 0.5rem;
}

.totals-list { list-style: none; margin: 0.6rem 0; padding: 0; display: flex; flex-direction: column; gap: 0.45rem; }
.team-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--raised);
  border-radius: var(--radius-sm);
  padding: 0.72em 0.9em;
  font-weight: 600;
}
.team-row .score { color: var(--accent); font-variant-numeric: tabular-nums; font-family: var(--font-display); }
.team-row .delta { color: var(--good); font-size: 0.8em; margin-left: 0.35em; font-variant-numeric: tabular-nums; }
.team-row .delta.zero { opacity: 0.4; }
.team-1 { border-left-color: var(--team-1); }
.team-2 { border-left-color: var(--team-2); }
.team-3 { border-left-color: var(--team-3); }
.team-4 { border-left-color: var(--team-4); }
.waiting-note { color: var(--muted); text-align: center; margin: 0.9rem 0; }
.advance-note { color: var(--accent-2); }

/* ---- TV-connect callout (lobby only) ------------------------------------
 * The lobby's hero affordance: "set this up on the big screen for the best
 * reveal." Prominent for the host, a quiet hint for other phones, and a calm
 * success state once a TV is actually live. Never reads as an error. */
/* Tight, code-forward card: glyph · title · the room code as hero · one quiet
 * line. Host vs guest and waiting vs connected differ in color + scale, not in
 * word count. */
.tv-connect {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem 0.9rem;
  align-items: center;
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin: 0.4rem 0 0.2rem;
  background:
    linear-gradient(180deg, rgba(255, 207, 63, 0.12), rgba(255, 207, 63, 0.04));
  border: 1px solid rgba(255, 207, 63, 0.34);
  box-shadow: var(--shadow-1);
}
.tv-connect-glyph {
  grid-row: 1 / span 2;
  align-self: start;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(255, 207, 63, 0.16);
  color: var(--accent);
}
.tv-connect-glyph svg { width: 25px; height: 25px; display: block; }
.tv-connect-body { min-width: 0; }
.tv-connect-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 0.1rem;
}
.tv-connect-line {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
  margin: 0.28rem 0 0;
}
.tv-connect-line strong { color: var(--fg); font-weight: 700; }
.tv-connect-ok { display: none; color: var(--muted); font-size: 0.9rem; margin: 0.28rem 0 0; }

/* "Share the TV link" — a compact affordance under the instruction line: copies
   screen.html?room=CODE so the host can send it to a TV that can't scan the QR.
   Hidden once a TV is live (the instruction line gives way to the confirmation). */
.tv-connect-share {
  margin: 0.55rem 0 0;
  min-height: 0;
  padding: 0.36rem 0.72rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
  background: rgba(255, 207, 63, 0.14);
  border: 1px solid rgba(255, 207, 63, 0.34);
  border-radius: var(--radius-sm);
}
.tv-connect-share:hover { background: rgba(255, 207, 63, 0.22); border-color: rgba(255, 207, 63, 0.5); }
.tv-connect[data-role="guest"] .tv-connect-share {
  color: var(--muted); background: rgba(255, 255, 255, 0.05); border-color: var(--line);
}
.tv-connect[data-role="guest"] .tv-connect-share:hover { color: var(--fg); }
.tv-connect[data-state="connected"] .tv-connect-share { display: none; }

/* Guest phones: quieter and more compact — same code, less shout. */
.tv-connect[data-role="guest"] {
  background: rgba(255, 255, 255, 0.03);
  border-color: var(--line);
  padding: 0.7rem 0.9rem;
}
.tv-connect[data-role="guest"] .tv-connect-glyph {
  width: 38px; height: 38px; background: rgba(255, 255, 255, 0.05); color: var(--muted);
}
.tv-connect[data-role="guest"] .tv-connect-glyph svg { width: 21px; height: 21px; }
.tv-connect[data-role="guest"] .tv-connect-title { color: var(--muted); }

/* Connected: calm cyan confirmation — the instruction line gives way to it. */
.tv-connect[data-state="connected"] {
  background: linear-gradient(180deg, rgba(77, 214, 255, 0.12), rgba(77, 214, 255, 0.03));
  border-color: rgba(77, 214, 255, 0.34);
}
.tv-connect[data-state="connected"] .tv-connect-glyph { background: rgba(77, 214, 255, 0.16); color: var(--accent-2); }
.tv-connect[data-state="connected"] .tv-connect-title { color: var(--accent-2); }
.tv-connect[data-state="connected"] .tv-connect-line { display: none; }
.tv-connect[data-state="connected"] .tv-connect-ok { display: block; color: var(--accent-2); }

.action-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex; gap: 0.6rem;
  padding: 0.85rem 1.15rem calc(0.85rem + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 55%, transparent);
  max-width: var(--maxw); margin: 0 auto;
}
.action-bar .btn-primary { flex: 1; }
.action-bar .btn-ghost { flex: 0 0 auto; }

/* Reveal dock: pins the auto-advance note directly above the action bar so the
 * countdown/CTA and the eye land in one place. The nested action bar drops its
 * own fixed positioning; the dock owns the pin and the background fade. */
.reveal-dock {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: var(--maxw); margin: 0 auto;
  background: linear-gradient(to top, var(--bg) 62%, transparent);
}
.reveal-dock #revealNote { margin: 0.4rem 0 0; }
.reveal-dock .action-bar {
  position: static;
  max-width: none; margin: 0;
  background: none;
}
/* Pressed pause button: accent border signals the timer is held. */
.btn-ghost.is-active {
  border-color: var(--accent);
  color: var(--fg);
}

/* ---- Round (an Operate surface: recognise, then ring) ---- */
.round-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.7rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--line);
}
.hud-item { font-weight: 700; font-family: var(--font-display); letter-spacing: -0.01em; }
#roundHeader { font-size: 1.15rem; }

/* ---- The progressive flag reveal ---- */
.reveal-holder { margin: 0.5rem 0 1.1rem; }
.flag-canvas {
  position: relative;
  width: 100%;
  aspect-ratio: var(--flag-aspect, 3 / 2);
  background: var(--tile-cover);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.flag-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: filter 0.5s ease;
}
.flag-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--flag-grid, 4), 1fr);
  grid-template-rows: repeat(var(--flag-grid, 4), 1fr);
}
.flag-tile {
  background: var(--tile-cover);
  opacity: 1;
  transition: opacity 0.45s ease;
  border: 0.5px solid rgba(0, 0, 0, 0.25);
}
.flag-tile.exposed { opacity: 0; }
.flag-canvas.full .flag-grid { display: none; }
/* The reveal "pulse": when a flag lands fully, a single confident glow. */
#revealFlag.flag-canvas.full, .tv-reveal.flag-canvas.full {
  animation: reveal-pop 0.6s ease-out;
}
@keyframes reveal-pop {
  0% { box-shadow: 0 0 0 0 rgba(255, 207, 63, 0), var(--shadow-1); transform: scale(0.992); }
  40% { box-shadow: 0 0 0 6px rgba(255, 207, 63, 0.28), var(--shadow-pop); transform: scale(1); }
  100% { box-shadow: 0 0 0 0 rgba(255, 207, 63, 0), var(--shadow-1); transform: scale(1); }
}

/* ---- Buzzer ---- */
.buzzer { margin: 0.7rem 0; }
.typeahead { position: relative; }
.suggest {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0.25rem;
  position: absolute;
  left: 0; right: 0;
  z-index: 20;
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-pop);
}
.suggest li { padding: 0.72em 0.75em; cursor: pointer; border-radius: 8px; }
.suggest li:hover { background: var(--raised); }
.buzz-hint { color: var(--muted); font-size: 0.9rem; text-align: center; margin: 0.6rem 0; }
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.choice-btn {
  padding: 1.1em 0.8em;
  font-weight: 700;
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  min-height: 68px;
}
.choice-btn:not(:disabled):hover { background: var(--raised); }
.round-status { text-align: center; margin: 0.9rem 0; min-height: 1.4em; font-weight: 600; }

/* ---- Reveal ---- */
.reveal-round { color: var(--muted); font-weight: 700; font-family: var(--font-display); text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.8rem; }
.reveal-headline { font-size: clamp(1.7rem, 6.5vw, 2.5rem); font-weight: 800; font-family: var(--font-display); margin: 0.25rem 0; letter-spacing: -0.02em; }
.reveal-result { font-size: 1.12rem; font-weight: 700; margin: 0.2rem 0 0.9rem; }
.reveal-result.good { color: var(--good); }
.reveal-result.bad { color: var(--bad); }
.reveal-beats { margin: 0.7rem 0; display: flex; flex-direction: column; gap: 0.4rem; }
.beat { color: var(--muted); font-size: 0.95rem; }

/* ---- Chrome ---- */
.conn-pill {
  position: fixed; top: 0; left: 0; right: 0; z-index: 3000;
  text-align: center; padding: 0.55em; font-size: 0.9rem; font-weight: 700;
  background: var(--bad); color: #300;
}
.toast {
  position: fixed; left: 50%; bottom: 6rem; transform: translateX(-50%);
  z-index: 3000; background: var(--panel-2); color: var(--fg);
  padding: 0.75em 1.15em; border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-pop); max-width: 90vw;
}
/* ---- Landing (a Decide/Learn surface: one idea, a hero earns its place) ---- */
.landing-hero { max-width: var(--maxw); padding-top: 11vh; }
.landing-hero .brand { font-size: clamp(2.6rem, 11vw, 4rem); }
.landing-hero .tagline { font-size: 1.1rem; }
.ld-panel { margin: 1.6rem 0 0.4rem; display: flex; flex-direction: column; gap: 0.7rem; align-items: stretch; }
.ld-cta-main { font-size: 1.18rem; padding: 1.05em; text-align: center; }
.ld-cta-sub { background: transparent; color: var(--fg); border: 1px solid var(--line-strong); }
.ld-cta-sub:hover { background: rgba(255, 255, 255, 0.05); }
.ld-footer {
  text-align: center;
  color: var(--muted);
  padding: 8px 0 16px;
  display: flex;
  justify-content: center;
  gap: 10px;
}
.ld-footer a, .ld-footer .link-btn { color: var(--muted); text-decoration: none; }
.ld-footer a:hover, .ld-footer .link-btn:hover { color: var(--fg); }

/* Ownership line, quiet, under the footer links (cribbed from GeoParty). */
.ld-ownership {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  opacity: 0.7;
  margin: 0 0 8px;
}

/* ---- Doc pages ---- */
.doc-wrap { max-width: 640px; }
.howto { line-height: 1.65; padding-left: 1.3rem; }
.howto li { margin-bottom: 1rem; }
.howto li::marker { color: var(--accent); font-weight: 700; }
code {
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 0.1em 0.4em;
  border-radius: 6px;
  font-size: 0.92em;
}

/* ---- Consent banner ---- */
.consent-banner {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4000;
  background: var(--panel); border-top: 1px solid var(--line-strong);
  padding: 1.1rem 1.15rem calc(1.1rem + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6);
}
.consent-banner p { margin: 0 auto 0.85rem; max-width: var(--maxw); color: var(--muted); line-height: 1.5; }
.consent-banner strong { color: var(--fg); }
.consent-actions { display: flex; gap: 0.6rem; max-width: var(--maxw); margin: 0 auto; }
.consent-actions button { flex: 1; }

/* ============================ TV (a Monitor surface) ============================ */
body.tv { overflow: hidden; }
.tv .phase-screen { min-height: 100vh; }
.tv-join { text-align: center; padding-top: 16vh; }
.tv-join .brand { font-size: clamp(3rem, 9vw, 5rem); }
.tv-join .join-row { max-width: 30rem; margin: 0 auto; }
#s-display {
  display: grid;
  grid-template-columns: 1fr 23rem;
  grid-template-rows: auto 1fr;
  grid-template-areas: "head head" "main side";
  height: 100vh;
  gap: 1.6rem;
  padding: 1.6rem 2.1rem;
  position: relative;
}
.tv-head {
  grid-area: head;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}
.tv-room { color: var(--muted); font-size: 1.25rem; }
.tv-room strong { color: var(--accent); letter-spacing: 0.18em; font-family: var(--font-display); }
.tv-round { font-size: clamp(1.6rem, 3vw, 2.6rem); font-weight: 800; font-family: var(--font-display); letter-spacing: -0.02em; }
.tv-main { grid-area: main; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; }
.tv-reveal { width: 100%; max-width: 70vh; }
.tv-reveal .flag-canvas, .tv-reveal.flag-canvas { border-width: 2px; }
.tv-answer { font-size: clamp(2.1rem, 5vw, 3.6rem); font-weight: 800; font-family: var(--font-display); letter-spacing: -0.02em; margin-top: 1.1rem; text-align: center; }
.tv-result { font-size: 1.6rem; margin-top: 0.55rem; text-align: center; color: var(--muted); }
.tv-result strong { color: var(--accent); }
.tv-comingup { font-size: 1.2rem; margin-top: 0.5rem; text-align: center; color: var(--accent-2); }
.tv-side { grid-area: side; overflow-y: auto; }
.side-title { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.14em; font-weight: 700; margin: 0 0 0.6rem; }
.tv-board .team-row { font-size: 1.3rem; padding: 0.8em 1em; }
.tv-board .score { font-size: 1.4rem; }
.tv-note, #tvNote { color: var(--muted); }
/* The wrong-guess gallery: its own grid block, hidden until the reveal
   layout claims it (below). */
.tv-busts { grid-area: busts; display: none; }

/* ---- TV layout state machine (data-phase drives the whole screen) --------
 * roundActive: the flag is the ONLY thing on screen — full-bleed. Everything
 * else (standings, answer, busts) is hidden; the head shrinks to a corner chip.
 * reveal / gameOver: a centered "results card" — answer, leaderboard and the
 * wrong-guess flags stacked and legible from the couch; the flag shrinks back. */
#s-display[data-phase="roundActive"] {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  grid-template-areas: "main";
  padding: 1rem;
}
#s-display[data-phase="roundActive"] .tv-side { display: none; }
/* The head becomes an unobtrusive corner chip floating over the big flag. It
   keeps the room code (masked, reused elsewhere) and the round indicator. */
#s-display[data-phase="roundActive"] .tv-head {
  position: absolute;
  top: 0.7rem;
  right: 1.3rem;
  z-index: 5;
  gap: 1.1rem;
  padding: 0.4rem 0.9rem;
  border-bottom: 0;
  border-radius: 999px;
  background: rgba(14, 14, 18, 0.55);
  opacity: 0.8;
}
#s-display[data-phase="roundActive"] .tv-room { font-size: 0.95rem; }
#s-display[data-phase="roundActive"] .tv-round { font-size: 1.15rem; }
/* Height-driven so the flag always fits the viewport height; max-width caps
   the rare very-wide flag. aspect-ratio (on .flag-canvas) keeps it undistorted. */
#s-display[data-phase="roundActive"] .tv-reveal {
  width: auto;
  max-width: 96vw;
  height: 94vh;
  margin: 0;
}

#s-display[data-phase="reveal"],
#s-display[data-phase="gameOver"] {
  grid-template-columns: minmax(0, 62rem);
  grid-template-rows: auto auto auto auto;
  grid-template-areas: "head" "main" "side" "busts";
  justify-content: center;
  align-content: start;
  overflow-y: auto;
  gap: 1rem;
}
#s-display[data-phase="reveal"] .tv-main,
#s-display[data-phase="gameOver"] .tv-main {
  justify-content: flex-start;
}
/* The flag is revealed now — shrink it so the answer + standings own the frame. */
#s-display[data-phase="reveal"] .tv-reveal,
#s-display[data-phase="gameOver"] .tv-reveal {
  max-width: min(46vh, 42rem);
  margin: 0 auto;
}
/* Standings move out of the sidebar into the centered column, center-stage. */
#s-display[data-phase="reveal"] .tv-side,
#s-display[data-phase="gameOver"] .tv-side {
  overflow: visible;
  width: 100%;
  max-width: 42rem;
  margin: 0 auto;
}
#s-display[data-phase="reveal"] .side-title,
#s-display[data-phase="gameOver"] .side-title {
  text-align: center;
  font-size: 1rem;
}
#s-display[data-phase="reveal"] .tv-busts,
#s-display[data-phase="gameOver"] .tv-busts {
  display: flex;
  width: 100%;
  max-width: 42rem;
  margin: 0 auto;
}

/* Each wrong guess: its flag beside the "team guessed COUNTRY" line. */
.beat { display: flex; align-items: center; gap: 0.7rem; }
.beat-flag {
  flex: 0 0 auto;
  width: 3.2rem;
  height: 2.13rem;
  object-fit: contain;
  border-radius: 4px;
  border: 1px solid var(--line-strong);
  background: var(--tile-cover);
}
.beat-text { min-width: 0; font-size: 1.15rem; }

@media (max-width: 720px) {
  #s-display {
    grid-template-columns: 1fr;
    grid-template-areas: "head" "main" "side";
    height: auto; min-height: 100vh;
  }
}

/* ---- Confetti (cheap) ---- */
.confetti { height: 0; }

/* ---- Game-over celebration — "your color takes the room" ------------------
 * Cribbed from GeoParty (references/win-celebration-ui.md). A FAST, NON-BLOCKING
 * enhancement of the TV game-over screen (no modal, buttons/nav stay live): the
 * winner's color floods in behind the "👑 name wins" headline, the headline
 * punches with a colored glow, a confetti burst falls in that color, then it
 * settles (~1.4s) into a calm resting glow. `--win` is the single color knob
 * (screen-flag.js sets it per-winner via celebrationSpec); a champion goes gold
 * (var(--accent)). Color is never the sole signal — the headline text carries
 * the meaning. Both layers are aria-hidden decoration. */

/* Bloom: a radial wash of the winner's color, BEHIND the content (z-index 0). */
.tv-bloom {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(58% 55% at 50% 44%, var(--win, transparent), transparent 70%);
}
/* Confetti wrap: ABOVE the content (z-index 2). PITFALL (GeoParty): a burst at
   z-index 0 falls behind the leaderboard and reads as broken. */
.tv-confetti {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  overflow: hidden;
}
/* During the celebration, lift the results content above the bloom: the bloom is
   a positioned z-index:0 layer, so the (non-positioned) grid items would
   otherwise paint under it. Confetti still sits above everything. */
#s-display.celebrate .tv-head,
#s-display.celebrate .tv-main,
#s-display.celebrate .tv-side,
#s-display.celebrate .tv-busts { position: relative; z-index: 1; }

#s-display.celebrate .tv-bloom { animation: tv-bloom-in 1.4s ease-out forwards; }
@keyframes tv-bloom-in {
  0%   { opacity: 0; }
  22%  { opacity: 0.9; }
  100% { opacity: 0.4; } /* resting glow */
}

/* Headline punch: the "👑 name wins" line glows in the win color, then eases. */
#s-display.celebrate .tv-result strong { color: var(--win, var(--accent)); }
#s-display.celebrate .tv-result { animation: tv-headline-punch 1.4s ease-out; }
@keyframes tv-headline-punch {
  0%   { transform: scale(0.92); text-shadow: none; }
  30%  { transform: scale(1.06); text-shadow: 0 0 30px var(--win, var(--accent)); }
  100% { transform: scale(1); text-shadow: 0 0 12px var(--win, var(--accent)); }
}

/* Confetti pieces — cheap DOM spans; screen-flag.js sets --x/--dx/--rot/--delay/--c. */
.tv-confetti span {
  position: absolute;
  top: -8%;
  left: var(--x, 50%);
  width: 0.7rem;
  height: 1rem;
  background: var(--c, var(--win, var(--accent)));
  border-radius: 1px;
  opacity: 0;
  animation: tv-confetti-fall 1.4s var(--delay, 0s) ease-in forwards;
}
@keyframes tv-confetti-fall {
  0%   { opacity: 0; transform: translate(0, 0) rotate(0deg); }
  12%  { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx, 0), 108vh) rotate(var(--rot, 540deg)); }
}

@media (prefers-reduced-motion: reduce) {
  .flag-tile, .flag-img, button { transition: none; }
  #revealFlag.flag-canvas.full, .tv-reveal.flag-canvas.full { animation: none; }
  /* Collapse the celebration to its final static frame: bloom at resting
     opacity, headline static, NO confetti. */
  #s-display.celebrate .tv-bloom { animation: none; opacity: 0.4; }
  #s-display.celebrate .tv-result { animation: none; }
  .tv-confetti { display: none; }
}

/* ============================ v0.2 additions ============================ */

/* ---- QR joins (lobby + TV connect) ------------------------------------
 * drawQr paints a fixed-resolution white QR canvas; CSS caps the DISPLAYED
 * size so the code stays a quiet affordance. The white quiet-zone is baked
 * into the canvas, so a subtle rounded frame is all we add. */
.qr-canvas {
  display: block;
  width: 128px;
  height: 128px;
  border-radius: 10px;
  background: #fff;
  image-rendering: pixelated; /* crisp modules when scaled down */
}
.join-qr {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  margin: 0.85rem auto 0.1rem;
}
.join-qr .qr-canvas { width: 116px; height: 116px; }
.join-qr-cap {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
/* The TV-connect callout QR: a third column beside the title + line, captioned
   so it reads as a distinct job from the join QR up in the hero. */
.tv-connect { grid-template-columns: auto 1fr auto; }
.tv-connect-qr {
  grid-row: 1 / span 2;
  align-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}
/* Gold-tinted frame ties the square to the card's border — different job, same
   family, so a guest never confuses it with the join QR. */
.tv-connect-qr .qr-canvas {
  width: 84px; height: 84px; border-radius: 8px;
  border: 2px solid rgba(255, 207, 63, 0.45);
}
.tv-connect[data-role="guest"] .tv-connect-qr .qr-canvas { width: 70px; height: 70px; }
/* Once the TV is live, the connect QR gives way to the "ok" confirmation. */
.tv-connect[data-state="connected"] .tv-connect-qr { display: none; }

/* The TV lobby's own couch-join QR (big — read across the room). */
.tv-join-qr {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  margin-top: 1rem;
}
.qr-tv { width: min(38vh, 300px); height: min(38vh, 300px); border-radius: 14px; }
.tv-join-qr-cap { color: var(--muted); font-size: 1.15rem; text-align: center; margin: 0; }
/* The room code, sized to read across the room — the small top-left label
   can't be seen at couch distance. */
.tv-join-code {
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 2.5rem;
  letter-spacing: 0.16em;
  vertical-align: middle;
}

/* ---- Game-over share row ---- */
.go-share-row { display: flex; justify-content: center; margin: 0.4rem 0 0.2rem; }

/* ---- Landing Daily card (GeoParty .ld-daily pattern) ---- */
.ld-daily {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 420px;
  margin: 14px auto 0;
  padding: 13px 16px;
  background: rgba(28, 28, 34, 0.75);
  border: 1px solid var(--panel-2);
  border-radius: 14px;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.35;
  text-decoration: none;
}
.ld-daily:hover { border-color: var(--accent); text-decoration: none; }
.ld-daily .art { font-size: 1.5rem; }
.ld-daily strong { color: var(--accent); }
.ld-daily-streak {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--accent);
  background: rgba(255, 207, 63, 0.12);
  border: 1px solid rgba(255, 207, 63, 0.3);
  border-radius: 999px;
  padding: 0.1em 0.6em;
}

/* ============================ Daily Challenge page ============================ */
.daily-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.2rem 1rem 1.3rem;
  text-align: center;
  box-shadow: var(--shadow-1);
  margin: 0.6rem 0 1.2rem;
}
.daily-card-label {
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  font-weight: 700;
  margin: 0 0 0.2rem;
}
.daily-num {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.8rem, 13vw, 4rem);
  line-height: 1;
  letter-spacing: -0.02em;
}
.daily-num.accent { color: var(--accent); }
.daily-date { color: var(--muted); margin-top: 0.35rem; font-size: 0.95rem; }
.daily-streak {
  margin-top: 0.7rem;
  color: var(--accent);
  font-weight: 700;
  font-size: 0.95rem;
}
.daily-rules { color: var(--muted); line-height: 1.55; max-width: 40ch; margin: 0 auto 1rem; }
.daily-rules strong { color: var(--fg); }
.daily-emoji {
  font-size: 2rem;
  letter-spacing: 0.18em;
  margin-top: 0.7rem;
  line-height: 1;
}
.daily-emoji-cap { color: var(--muted); text-align: center; font-size: 0.8rem; margin: 0.5rem 0 0; }
.daily-note { color: var(--muted); text-align: center; margin: 1.1rem 0 0.6rem; }

/* The reveal "Total so far" row (daily). */
.total-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.7em 0.95em;
  margin: 0.4rem 0 0.6rem;
}
.total-label { color: var(--muted); font-weight: 600; }
.total-val {
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.4rem;
  font-variant-numeric: tabular-nums;
}

/* A stacked (non-fixed) action bar, used on the Daily done screen. */
.action-bar-stack {
  position: static;
  padding: 0;
  background: none;
  box-shadow: none;
  border: 0;
  display: flex;
  justify-content: center;
  margin: 0.4rem 0;
}
