/* Hunt HQ — mobile-first. Tokens first; everything else uses them. */

:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --ink: #1b2421;
  --muted: #5f6b66;
  --line: #d9d3c6;

  --brand: #1d3b34;
  --accent: #e0662b;
  --accent-ink: #ffffff;
  --ok: #2f7d4f;
  --warn: #b7791f;
  --danger: #b3341b;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --r: 10px;
  --gap: 1rem;
  --tap: 48px; /* minimum touch target */
  --shadow: 0 1px 2px rgba(27, 36, 33, 0.06), 0 6px 20px rgba(27, 36, 33, 0.06);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px; /* 16px stops iOS zooming into inputs */
  line-height: 1.5;
}

a { color: var(--brand); text-underline-offset: 3px; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; margin-top: 1.25rem; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* --- Layout ------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: calc(0.6rem + env(safe-area-inset-top, 0px)) 1rem 0.6rem;
  background: var(--brand);
  color: #fff;
}
.brand { color: #fff; font-weight: 800; text-decoration: none; letter-spacing: 0.02em; }
.topnav { display: flex; align-items: center; gap: 1rem; min-width: 0; }
.topnav-user {
  min-width: 0; max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 0.95rem; color: rgba(255, 255, 255, 0.75);
}
.topnav a, .topnav .linklike { color: #fff; font-size: 0.95rem; }
.topnav form { margin: 0; }

.page {
  max-width: 40rem;
  margin: 0 auto;
  padding: 1rem 1rem calc(2rem + env(safe-area-inset-bottom, 0px));
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: var(--gap);
}
.card.narrow { max-width: 26rem; margin-inline: auto; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.card-head h2 { margin: 0; }
summary.card-head { cursor: pointer; list-style: none; }
summary.card-head::-webkit-details-marker { display: none; }

.section-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 1.5rem 0 0.5rem;
}

/* --- Controls ----------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 1.1rem;
  border: 1px solid transparent;
  border-radius: var(--r);
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  background: transparent;
  color: var(--ink);
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:active { filter: brightness(0.92); }
.btn-quiet { border-color: var(--line); background: var(--surface); }
.btn-danger { color: var(--danger); }
/* Handler decisions: solid green to approve, solid red to send back. */
.btn-approve { background: var(--ok); color: #fff; }
.btn-reject { background: var(--danger); color: #fff; }
.btn-approve:active, .btn-reject:active { filter: brightness(0.92); }
.btn-block { display: flex; width: 100%; margin-top: 0.75rem; }
.btn-small { min-height: 36px; padding: 0 0.75rem; font-size: 0.9rem; }

.linklike {
  background: none; border: 0; padding: 0; font: inherit;
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}

input[type="text"], input[type="email"], input[type="password"], input:not([type]) {
  width: 100%;
  min-height: var(--tap);
  padding: 0 0.8rem;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: #fff;
  font: inherit;
  color: var(--ink);
}
input:focus-visible, .btn:focus-visible, .linklike:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; margin-bottom: 0.3rem; }
.help { font-size: 0.85rem; color: var(--muted); margin: 0.3rem 0 0; }
.help ul { margin: 0; padding-left: 1.2rem; }
.error { color: var(--danger); font-weight: 600; margin: 0.3rem 0; }

/* QR scanner on the challenge page */
.qr-camera { margin: 0.75rem 0; border-radius: var(--r); overflow: hidden; background: #000; }
.qr-camera video { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.field-error input { border-color: var(--danger); }

.inline-form { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.inline-form input { flex: 1; min-width: 0; }

.choices { border: 0; padding: 0; margin: 0 0 1rem; }
.choices legend { font-weight: 600; margin-bottom: 0.3rem; }
.choice {
  display: flex; align-items: center; gap: 0.6rem;
  min-height: var(--tap); padding: 0 0.8rem; margin-bottom: 0.4rem;
  border: 1px solid var(--line); border-radius: var(--r); background: #fff;
}
.choice input { width: 1.2rem; height: 1.2rem; accent-color: var(--accent); }

.code-input { font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.15em; }

/* --- Pieces ------------------------------------------------------------- */

.flash { list-style: none; padding: 0; margin: 0 0 1rem; }
.flash li {
  padding: 0.75rem 1rem;
  border-radius: var(--r);
  margin-bottom: 0.5rem;
  background: var(--surface);
  border-left: 4px solid var(--brand);
}
.flash-success { border-left-color: var(--ok) !important; }
.flash-error { border-left-color: var(--danger) !important; }

.event-list { list-style: none; padding: 0; margin: 0; }
.event-row {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  min-height: var(--tap); padding: 0.75rem 1rem; margin-bottom: 0.5rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  color: var(--ink); text-decoration: none;
}
.event-row-name { font-weight: 600; }
.event-row-when { color: var(--muted); font-size: 0.9rem; white-space: nowrap; }

.event-head { margin-bottom: var(--gap); }
.event-desc { margin: 0.75rem 0 0; }
.status {
  display: flex; flex-wrap: wrap; gap: 0.25rem 0.75rem; align-items: center;
  padding: 0.6rem 0.9rem; border-radius: var(--r);
  background: var(--surface); border: 1px solid var(--line);
}
.status-label { font-weight: 700; text-transform: uppercase; font-size: 0.8rem; letter-spacing: 0.08em; }
.status-running { border-color: var(--ok); }
.status-running .status-label { color: var(--ok); }
.status-paused { border-color: var(--warn); }
.status-paused .status-label { color: var(--warn); }
.status-ended .status-label, .status-draft .status-label { color: var(--muted); }

.tag {
  display: inline-block; padding: 0.05rem 0.5rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 700; background: var(--brand); color: #fff;
  vertical-align: middle;
}
.tag-quiet { background: var(--line); color: var(--ink); }
.tag-regional { background: transparent; color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }

.roster { list-style: none; padding: 0; margin: 0; }
.roster li {
  display: flex; justify-content: space-between; align-items: center; gap: 0.5rem;
  min-height: var(--tap); border-bottom: 1px solid var(--line);
}
.roster li:last-child { border-bottom: 0; }
.roster form { margin: 0; }

.invite { margin-top: 1rem; padding-top: 0.25rem; border-top: 1px solid var(--line); }
.code-display {
  font-family: var(--mono); font-size: 2rem; font-weight: 700; letter-spacing: 0.25em;
  text-align: center; padding: 0.5rem; margin-top: 0.5rem;
  background: var(--bg); border-radius: var(--r); user-select: all;
}

.note {
  margin-top: 1rem; padding: 0.75rem; border-radius: var(--r);
  background: var(--bg); font-size: 0.9rem;
}

.plain { list-style: none; padding: 0; margin: 0.75rem 0 0; }
.plain li { padding: 0.25rem 0; }

/* --- Phase 2: challenges, leaderboard, organiser -------------------------- */

.small { font-size: 0.85rem; }
.back { margin: 0 0 0.75rem; }
.back a { text-decoration: none; font-weight: 600; }

.tabs {
  display: flex; gap: 0.25rem; margin: 0 0 var(--gap);
  border-bottom: 1px solid var(--line); overflow-x: auto;
}
.tabs a {
  display: inline-flex; align-items: center; min-height: var(--tap);
  padding: 0 1rem; color: var(--muted); font-weight: 600; text-decoration: none;
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

.badge {
  display: inline-block; padding: 0.1rem 0.55rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 700; white-space: nowrap;
}
.badge-ok { background: #dcefe2; color: var(--ok); }
.badge-wait { background: #f6ead2; color: #8a5a12; }
.badge-bad { background: #f6dcd5; color: var(--danger); }

.score-strip {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 0.75rem 1rem; margin-bottom: 0.75rem;
  background: var(--brand); color: #fff; border-radius: var(--r);
}
.score-strip strong { font-size: 1.5rem; }
.score-strip .muted { color: rgba(255, 255, 255, 0.75); }

.challenge-list { list-style: none; padding: 0; margin: 0 0 0.5rem; }
.challenge-row {
  display: flex; flex-direction: column; gap: 0.3rem;
  padding: 0.8rem 1rem; margin-bottom: 0.5rem; min-height: var(--tap);
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--line);
  border-radius: var(--r); color: var(--ink); text-decoration: none;
}
.challenge-row.state-solved { border-left-color: var(--ok); opacity: 0.75; }
.challenge-row.state-pending { border-left-color: var(--warn); }
.challenge-row.state-rejected { border-left-color: var(--danger); }
.challenge-row-title { font-weight: 700; }
.challenge-row-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.type-label { color: var(--muted); }
.points { margin-left: auto; font-weight: 700; }

.challenge-value { margin: 0 0 0.5rem; }
.clue { font-size: 1.05rem; }
.clue p { margin: 0 0 0.75rem; }
.hints { padding-left: 0; list-style: none; margin: 0.5rem 0 0; }
.hints li {
  padding: 0.6rem 0.8rem; margin-bottom: 0.4rem;
  background: var(--bg); border-radius: var(--r);
}
.hint-label { display: block; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

input[type="file"].file-input {
  width: 100%; padding: 0.75rem; border: 2px dashed var(--line); border-radius: var(--r);
  background: #fff; font: inherit;
}

.attempts { list-style: none; padding: 0; margin: 0; }
.attempt {
  padding: 0.75rem 1rem; margin-bottom: 0.5rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
}
.attempt-head { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.9rem; }
.attempt-text { margin: 0.4rem 0 0; }
.attempt-reason { margin: 0.4rem 0 0; font-weight: 600; color: var(--danger); }
.attempt-points { margin: 0.4rem 0 0; font-weight: 600; color: var(--ok); }
.attempt-media { display: block; width: 100%; max-height: 60vh; object-fit: contain; margin-top: 0.5rem; border-radius: var(--r); background: #000; }

/* Leaderboard: a real table, drawn as separated rows. */
.lb-wrap { overflow-x: auto; }
.leaderboard {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 0.4rem;
  margin-top: -0.4rem; /* the spacing adds a gap above the header */
}
.leaderboard th, .leaderboard td { padding: 0.7rem 0.6rem; text-align: left; vertical-align: middle; }
.leaderboard thead th {
  padding-block: 0.2rem 0;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted);
}
.leaderboard tbody td, .leaderboard tbody th {
  background: var(--surface);
  border-block: 1px solid var(--line);
}
.leaderboard tbody tr > :first-child { border-left: 1px solid var(--line); border-radius: var(--r) 0 0 var(--r); padding-left: 0.9rem; }
.leaderboard tbody tr > :last-child { border-right: 1px solid var(--line); border-radius: 0 var(--r) var(--r) 0; padding-right: 0.9rem; }

.lb-rank { width: 2.75rem; text-align: center !important; }
.lb-rank-badge {
  display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: 50%;
  font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums;
}
.lb-top-1 .lb-rank-badge { background: #e9b949; color: #3d2c00; }
.lb-top-2 .lb-rank-badge { background: #cfd3d8; color: #2b3138; }
.lb-top-3 .lb-rank-badge { background: #d9a878; color: #3b2410; }

.lb-team { font-weight: 700; overflow-wrap: anywhere; }
.lb-team-name { margin-right: 0.35rem; }
.lb-you, .lb-final {
  display: inline-block; margin: 0.15rem 0.25rem 0 0; padding: 0.05rem 0.45rem; border-radius: 999px;
  font-size: 0.7rem; font-weight: 700; vertical-align: middle; white-space: nowrap;
}
.lb-you { background: var(--accent); color: #fff; }
.lb-final { background: #fbe3d4; color: #9c3f10; }

.lb-solved { width: 4.5rem; text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lb-of { color: var(--muted); font-size: 0.85em; }
.lb-score { width: 5rem; text-align: right !important; font-size: 1.2rem; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.leaderboard thead .lb-score { font-size: 0.72rem; }

.leaderboard tbody tr.lb-mine > * { border-color: var(--accent); border-width: 2px; }
.leaderboard tbody tr.lb-mine > :not(:first-child) { border-left-width: 0; }
.leaderboard tbody tr.lb-mine > :not(:last-child) { border-right-width: 0; }

@media (max-width: 420px) {
  .leaderboard th, .leaderboard td { padding-inline: 0.4rem; }
  .lb-rank { width: 2.25rem; }
  .lb-solved { width: 3.4rem; }
  .lb-score { width: 4rem; font-size: 1.05rem; }
}

.button-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr)); gap: 0.5rem; }
.button-grid form { margin: 0; }
.button-grid .btn-block { margin-top: 0; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; text-align: center; }
.stats div { padding: 0.6rem 0.25rem; background: var(--bg); border-radius: var(--r); }
.stats strong { display: block; font-size: 1.5rem; }
.stats span { font-size: 0.8rem; color: var(--muted); }

.organise-list { list-style: none; padding: 0; margin: 0; }
.organise-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 0.75rem;
  padding: 0.6rem 0; border-bottom: 1px solid var(--line);
}
.organise-list li > div { display: flex; flex-direction: column; min-width: 0; }
.organise-list form { margin: 0; flex-shrink: 0; }

.qr-sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: 1rem; }
.qr-card {
  margin: 0; padding: 1rem; text-align: center; background: #fff;
  border: 1px solid var(--line); border-radius: var(--r); break-inside: avoid;
}
.qr-card svg { width: 100%; height: auto; max-width: 16rem; }
.qr-card figcaption { display: flex; flex-direction: column; gap: 0.2rem; margin-top: 0.5rem; }

@media print {
  .topbar, .no-print, .flash { display: none !important; }
  body, .page { background: #fff; padding: 0; max-width: none; }
  .qr-sheet { grid-template-columns: repeat(2, 1fr); }
  .qr-card { border: 1px dashed #999; }
}

/* --- Final puzzle -------------------------------------------------------- */

input[type="number"], select {
  width: 100%; min-height: var(--tap); padding: 0 0.8rem;
  border: 1px solid var(--line); border-radius: var(--r); background: #fff;
  font: inherit; color: var(--ink);
}

.final-kicker {
  display: block; font-size: 0.75rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.1em; color: var(--accent);
}

.final-card {
  display: flex; flex-direction: column; gap: 0.3rem;
  padding: 1rem; margin-bottom: 0.75rem;
  background: linear-gradient(135deg, #2a1f14, #4a2f17); color: #fff;
  border-radius: var(--r); text-decoration: none; box-shadow: var(--shadow);
}
.final-card .final-kicker { color: #ffb47a; }
.final-title { font-size: 1.15rem; font-weight: 800; }
.final-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; font-size: 0.9rem; color: rgba(255, 255, 255, 0.85); }
.final-race { font-size: 0.9rem; }
.final-card .final-race { color: #ffb47a; }
.final-panel .final-race { display: block; margin-top: 0.75rem; padding: 0.6rem 0.75rem; border-radius: var(--r); background: var(--bg); }
.final-card.state-solved { background: linear-gradient(135deg, #17392a, #235a3f); }

.clue-pips { display: inline-flex; gap: 4px; }
.pip { width: 10px; height: 10px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.6); }
.pip-on { background: #ffb47a; border-color: #ffb47a; }

.final-panel { border-top: 4px solid var(--accent); }
.final-result { font-size: 1.1rem; }
.final-clues { padding-left: 1.4rem; margin: 0.5rem 0 0; }
.final-clue { padding: 0.5rem 0; border-bottom: 1px solid var(--line); }
.final-clue:last-child { border-bottom: 0; }
.final-clue.locked { color: var(--muted); font-style: italic; }
.final-gps { margin-top: 1rem; padding-top: 0.5rem; border-top: 1px solid var(--line); }


.handler-answer { border-left: 4px solid var(--accent); }
.decision h3 { margin: 0; }
.decision form { margin-top: 0.75rem; }
.guess { font-size: 1.2rem; font-weight: 700; margin: 0.5rem 0 0.25rem; }
.guess-ok { color: var(--ok); font-size: 1rem; }
.bonus summary { cursor: pointer; color: var(--muted); padding: 0.4rem 0; }
.arrival-form label { display: block; font-weight: 600; margin-bottom: 0.3rem; }

/* --- Phase 3: handling and organiser editors ------------------------------ */

.stack > * + * { margin-top: var(--gap); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.field-row .field { min-width: 0; }
textarea, input[type="datetime-local"] {
  width: 100%; padding: 0.6rem 0.8rem; border: 1px solid var(--line); border-radius: var(--r);
  background: #fff; font: inherit; color: var(--ink);
}
input[type="datetime-local"] { min-height: var(--tap); }
input[type="color"] { width: 100%; min-height: var(--tap); padding: 0.2rem; border: 1px solid var(--line); border-radius: var(--r); background: #fff; }
.field input[type="checkbox"] { width: 1.3rem; height: 1.3rem; accent-color: var(--accent); }

.map { width: 100%; border-radius: var(--r); border: 1px solid var(--line); z-index: 0; }
.map-small { height: 16rem; margin-bottom: 0.5rem; }
.map-large { height: 60vh; min-height: 20rem; margin-bottom: 0.5rem; }
.map-actions { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }
.swatch { display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 3px; margin-right: 0.4rem; vertical-align: middle; }

.clue-row { border: 1px solid var(--line); border-radius: var(--r); padding: 0.75rem; margin: 0 0 0.75rem; }
.clue-row legend { font-weight: 700; padding: 0 0.3rem; }

.tool-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; margin-bottom: var(--gap); }
.tool-grid a {
  display: flex; align-items: center; justify-content: center; min-height: var(--tap);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  font-weight: 600; text-decoration: none; color: var(--ink); font-size: 0.9rem;
}
@media (max-width: 420px) { .tool-grid { grid-template-columns: repeat(2, 1fr); } }

.segmented { display: flex; gap: 0.25rem; padding: 0.25rem; margin-bottom: 0.75rem; background: var(--line); border-radius: var(--r); overflow-x: auto; }
.segmented a {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 0.35rem;
  min-height: 40px; padding: 0 0.6rem; border-radius: calc(var(--r) - 3px);
  color: var(--ink); text-decoration: none; font-weight: 600; font-size: 0.9rem; white-space: nowrap;
}
.segmented a[aria-current="page"] { background: var(--surface); box-shadow: var(--shadow); }
.count { display: inline-block; min-width: 1.4rem; padding: 0 0.35rem; border-radius: 999px; background: var(--accent); color: #fff; font-size: 0.75rem; text-align: center; }

.queue { list-style: none; padding: 0; margin: 0; }
.queue-item {
  display: flex; justify-content: space-between; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem; margin-bottom: 0.5rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
}
.queue-item.claimed { border-style: dashed; }
.queue-main { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.queue-team { font-weight: 800; }
.queue-challenge { font-weight: 600; }
.queue-item form { margin: 0; flex-shrink: 0; }

.review-title { margin-top: 0.75rem; }
.clue-toggle summary { cursor: pointer; color: var(--muted); padding: 0.3rem 0; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

/* --- Phase 4: live updates, freeze and reveal ----------------------------- */

.live-banner {
  position: fixed; left: 1rem; right: 1rem; z-index: 50;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  max-width: 38rem; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.75rem 1rem; border-radius: var(--r);
  background: var(--brand); color: #fff; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

/* Shown only after a connection has been lost (not before the first one). */
body.live-off .topbar::after {
  content: "Reconnecting…";
  position: absolute; left: 50%; top: 100%; transform: translate(-50%, 0.4rem);
  padding: 0.2rem 0.7rem; border-radius: 999px;
  background: var(--warn); color: #fff; font-size: 0.75rem; font-weight: 700;
}
.topbar { position: sticky; }

.frozen-banner {
  display: flex; flex-wrap: wrap; gap: 0.3rem 0.75rem; align-items: baseline;
  padding: 0.75rem 1rem; margin-bottom: 0.75rem; border-radius: var(--r);
  background: #e3eef6; border: 1px solid #b7d0e2; color: #17415c;
}
.frozen-banner a { color: inherit; font-weight: 600; }
.freeze-row { margin-top: 0.5rem; }

/* Reveal: rows arrive from last place up to first. --i counts from the bottom. */
.leaderboard.revealing .lb-row {
  animation: reveal-row 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  animation-delay: calc(var(--i) * 0.7s + 0.3s);
}
.leaderboard.revealing tbody .lb-row:first-child {
  animation-name: reveal-winner;
  animation-duration: 1s;
}
@keyframes reveal-row {
  from { opacity: 0; transform: translateY(1rem) scale(0.97); }
  to { opacity: 1; transform: none; }
}
@keyframes reveal-winner {
  0% { opacity: 0; transform: scale(0.9); }
  60% { opacity: 1; transform: scale(1.04); box-shadow: 0 0 0 6px rgba(224, 102, 43, 0.35); }
  100% { transform: none; box-shadow: var(--shadow); }
}
@media (prefers-reduced-motion: reduce) {
  .leaderboard.revealing .lb-row { animation: none; }
}

/* --- Phase 5: gallery, results, archive ----------------------------------- */

.gallery { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: 0.6rem; }
.gallery-item { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.gallery-item a { display: block; position: relative; aspect-ratio: 1; background: #000; }
.gallery-item img, .gallery-item video { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-play { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 2rem; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6); }
.gallery-caption { display: flex; flex-direction: column; padding: 0.4rem 0.6rem; font-size: 0.8rem; line-height: 1.3; }
.gallery-caption span { color: var(--muted); }
.gallery-item form { padding: 0 0.5rem 0.5rem; }
.gallery-item form .btn { width: 100%; }
.gallery-item.is-hidden { opacity: 0.45; }

.results h2 { margin-bottom: 0.75rem; }
.podium { list-style: none; padding: 0; margin: 0 0 0.75rem; }
.podium-place {
  display: grid; grid-template-columns: 2.5rem 1fr auto; align-items: center; gap: 0.75rem;
  padding: 0.7rem 1rem; margin-bottom: 0.4rem; border-radius: var(--r); background: var(--bg);
}
.podium-place.place-1 { background: linear-gradient(135deg, #f7d27a, #e9b949); font-size: 1.15rem; }
.podium-place.place-2 { background: #e3e4e6; }
.podium-place.place-3 { background: #ecd2b8; }
.podium-rank { font-weight: 800; text-align: center; font-size: 1.3rem; }
.podium-team { font-weight: 700; overflow-wrap: anywhere; }
.podium-score { font-weight: 800; font-variant-numeric: tabular-nums; }
.archive-winner { display: block; font-size: 0.85rem; color: var(--muted); }
.copy-link { margin: -0.5rem 0 var(--gap); font-size: 0.9rem; }
.create-event { margin-bottom: var(--gap); }

.rules ul { padding-left: 1.2rem; margin: 0; }
.rules li { margin-bottom: 0.5rem; }
.rules-list { margin: 0 0 0.75rem; }
.rules-list dt { font-weight: 700; margin-top: 0.75rem; }
.rules-list dd { margin: 0.2rem 0 0; }

/* Handler queue: the final puzzle card is quiet until something needs doing. */
.handler-final { position: relative; transition: background 0.3s, box-shadow 0.3s; }
.handler-final.is-quiet {
  background: var(--surface); color: var(--muted);
  border: 1px dashed var(--line); box-shadow: none;
}
.handler-final.is-quiet .final-kicker { color: var(--muted); }
.handler-final.is-quiet .final-title { color: var(--ink); font-size: 1rem; }
.handler-final.is-quiet .final-meta { color: var(--muted); }
.handler-final.needs-action {
  background: linear-gradient(135deg, #e0662b, #c4441a); color: #fff;
  border: 0; padding-right: 4.5rem;
  animation: final-attention 1.8s ease-in-out infinite;
}
.handler-final.needs-action .final-kicker { color: #fff3ea; }
.handler-final.needs-action .final-meta { color: #fff; }
.final-count {
  position: absolute; right: 1rem; top: 50%; transform: translateY(-50%);
  display: grid; place-items: center; width: 2.6rem; height: 2.6rem; border-radius: 50%;
  background: #fff; color: #c4441a; font-weight: 800; font-size: 1.2rem;
}
@keyframes final-attention {
  0%, 100% { box-shadow: 0 0 0 0 rgba(224, 102, 43, 0.55); }
  50% { box-shadow: 0 0 0 8px rgba(224, 102, 43, 0); }
}
@media (prefers-reduced-motion: reduce) { .handler-final.needs-action { animation: none; } }
.shared-text { color: var(--ink) !important; white-space: normal; margin-top: 0.2rem; }
.shared-teaser { margin-top: 1rem; }
