/* ------------------------------------------------------------------------------------------------
   The Gauntlet board: a TV / OBS screen first, readable on a phone.

   Type is sized to the window (the root font follows the smaller of its height and width), so the same
   page fills a 1080p TV, an OBS canvas or a laptop window without zooming. Nothing on it relies on
   colour alone: finalists, ties, drops, who's up and who advances each carry a word or a symbol too,
   and the accents are blue and amber rather than a red/green pair.
   ------------------------------------------------------------------------------------------------ */

:root {
  color-scheme: dark;
  --bg: #0f1117;
  --panel: rgba(255, 255, 255, 0.05);
  --text: #f3f4f6;
  --muted: #9ca3af;
  --faint: #6b7280;
  --border: #374151;
  --accent: #60a5fa;          /* blue: up now / up next, finalists */
  --accent-bg: rgba(96, 165, 250, 0.16);
  --gold: #fbbf24;            /* amber: the line to beat, the winner */
  --gold-bg: rgba(251, 191, 36, 0.16);
  --side-w: 36%;
  --timer-h: 28vh;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --panel: rgba(0, 0, 0, 0.04);
  --text: #111827;
  --muted: #4b5563;
  --faint: #6b7280;
  --border: #d1d5db;
  --accent: #1d4ed8;
  --accent-bg: rgba(29, 78, 216, 0.10);
  --gold: #92400e;
  --gold-bg: rgba(217, 119, 6, 0.14);
}

* { box-sizing: border-box; }

/* Background and colour set outright: an OBS browser source's default CSS makes the body transparent. */
html {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: max(14px, min(2.3vh, 1.3vw));
  height: 100%;
}

body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ---- Frame -------------------------------------------------------------------------------------- */

.stage {
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--side-w);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "head side" "main side" "foot side";
  gap: 0 1.6rem;
  padding: 1.2rem 1.6rem;
}

.head { grid-area: head; min-width: 0; }
.main { grid-area: main; min-height: 0; display: flex; flex-direction: column; }
.side { grid-area: side; min-height: 0; display: flex; flex-direction: column; gap: 1rem; }
.side-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 1rem; overflow: hidden; }
.side-body > .panel { flex-shrink: 0; }
.side-body > .panel.grow { flex-shrink: 1; }
.foot { grid-area: foot; display: flex; flex-wrap: wrap; gap: 0.5rem 1.4rem; padding-top: 0.8rem; color: var(--muted); }
.foot b { color: var(--text); font-weight: 600; }

/* The side column on the left, for a timer in a left corner. */
.timer-left .stage {
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  grid-template-areas: "side head" "side main" "side foot";
}

/* The empty box the OBS timer sits over. Only the obs layout has one; a bottom corner puts it last. */
.timer-slot { display: none; flex: 0 0 var(--timer-h); }
.layout-obs .timer-slot { display: block; }
.timer-bottom .timer-slot { order: 2; }
.guide .timer-slot { outline: 3px dashed var(--gold); outline-offset: -3px; }

/* ?qr=1: a tile in the side column, above the latest runs, while games and goals or how a run works is up.
   gauntlet.js sizes the code to fit. Black on white in both themes (qr-tile.js paints it so). */
.side-body > .panel.qr-panel { flex: none; display: flex; flex-direction: row; align-items: center; gap: 1.2rem; }
.qr-panel h2 { margin: 0; line-height: 1.35; }
.qr { display: flex; margin-left: auto; margin-right: auto; }
.qr .qr-code { width: auto; aspect-ratio: 1; border-radius: 0.3rem; }

.title { margin: 0; font-size: 2.1rem; line-height: 1.15; letter-spacing: -0.01em; }
.subhead { margin: 0.3rem 0 0.9rem; display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; align-items: baseline; }
.phase-label { font-size: 1.15rem; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: 0.06em; }
.status { font-size: 0.85rem; color: var(--faint); }
.status.stale { color: var(--gold); }
.status.stale::before { content: "⚠ "; }

/* ---- Panels and lists --------------------------------------------------------------------------- */

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 0.6rem; padding: 0.8rem 1rem; min-height: 0; }
.panel h2 { margin: 0 0 0.5rem; font-size: 0.95rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.panel.grow { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid;
  grid-template-columns: 3.2rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.8rem;
  height: 2.15rem;
  padding: 0 0.6rem;
  font-size: 1.25rem;
  border-radius: 0.35rem;
}
.row + .row { margin-top: 0.12rem; }

/* Column headings: the same grid as the rows under them. */
.colhead {
  display: grid; grid-template-columns: 3.2rem minmax(0, 1fr) auto; gap: 0.8rem; padding: 0 0.6rem 0.25rem;
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}
.colhead span:first-child, .colhead span:last-child { text-align: right; }
.small-rows .colhead { grid-template-columns: 2.2rem minmax(0, 1fr) auto; }
.two-col .colhead { break-inside: avoid; }
.round-colhead {
  grid-template-columns: 1.4em 3.4em minmax(0, 1fr) auto minmax(4.6em, auto);
  font-size: 1.5rem; padding: 0 0.9rem 0.1rem;
}
.round-colhead span { font-size: 0.5em; align-self: end; }
.round-colhead span:nth-child(4) { text-align: right; }
.final4 .round-colhead { font-size: 1.7rem; }
.unit { font-size: 0.4em; font-weight: 600; color: var(--muted); margin-left: 0.4rem; letter-spacing: 0.04em; text-transform: uppercase; }
.row .place { font-variant-numeric: tabular-nums; color: var(--muted); text-align: right; font-weight: 600; }
.row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .result { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.result .partial { color: var(--muted); }
.tag {
  display: inline-block; margin-left: 0.5rem; padding: 0.05rem 0.4rem; border-radius: 0.3rem;
  font-size: 0.7em; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; vertical-align: 0.12em;
  border: 1px solid currentColor; color: var(--muted);
}

.row.finalist { background: var(--accent-bg); }
.row.finalist .place { color: var(--accent); }
.row.cut-tie { background: var(--gold-bg); box-shadow: inset 0.25rem 0 0 var(--gold); }
.row.cut-tie .place { color: var(--gold); }
.tag.tiebreak { color: var(--gold); }
.cut.tied { color: var(--gold); }
.cut.tied::before, .cut.tied::after { border-top-color: var(--gold); }
.panel.alert { border: 2px solid var(--gold); background: var(--gold-bg); }
.panel.alert h2 { color: var(--gold); }
.row.dropped .name, .row.dropped .result { text-decoration: line-through; color: var(--faint); }
.cut {
  display: flex; align-items: center; gap: 0.6rem; margin: 0.25rem 0; color: var(--accent);
  font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
}
.cut::before, .cut::after { content: ""; flex: 1; border-top: 2px dashed var(--accent); }

.pager { margin-top: auto; padding-top: 0.4rem; font-size: 0.8rem; color: var(--faint); text-align: right; }

/* Up next */
.next-name { font-size: 2rem; font-weight: 700; line-height: 1.2; }
.next-meta { color: var(--muted); margin-top: 0.15rem; }
.small-rows .row { font-size: 1.05rem; height: 1.85rem; grid-template-columns: 2.2rem minmax(0, 1fr) auto; }
.more { color: var(--faint); font-size: 0.9rem; margin-top: 0.3rem; }
.closed-note { font-size: 1.4rem; font-weight: 600; }

/* ---- Games and goals, how a run works ----------------------------------------------------------- */

/* A page of its own on the TV (two columns of three), a section under the standings on a phone. */
.course-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.8rem 1.6rem; }
.course-list.two { grid-template-columns: repeat(2, minmax(0, 1fr)); align-content: start; }
.course-list.three { grid-template-columns: repeat(3, minmax(0, 1fr)); align-content: start; }
.course-game { min-width: 0; padding: 0.5rem 0.8rem; border-radius: 0.5rem; background: var(--panel); border-left: 0.25rem solid var(--accent); }
.cg-name { font-size: 0.95em; color: var(--muted); }
.cg-goal { font-size: 1.45em; font-weight: 700; line-height: 1.15; }
.cg-about { margin: 0.35em 0 0; font-size: 1em; line-height: 1.35; }
.cg-tips { list-style: none; margin: 0.35em 0 0; padding: 0; font-size: 0.95em; line-height: 1.35; color: var(--muted); }
.cg-tips b { color: var(--gold); text-transform: uppercase; font-size: 0.8em; letter-spacing: 0.05em; margin-right: 0.3rem; }
.main .panel.text-page:not(.grow) { margin-top: 1rem; }
/* How a run works: numbered steps, big enough to read from across the room. */
.rules-list { margin: 0.4rem 0 0; padding-left: 2.4em; font-size: 1.6rem; line-height: 1.3; }
.rules-list li { padding-left: 0.3em; }
.rules-list li + li { margin-top: 0.6em; }
.rules-list li::marker { color: var(--accent); font-weight: 700; }

/* ---- Finals rounds ------------------------------------------------------------------------------ */

.round { display: flex; flex-direction: column; gap: 0.35rem; }
.round-row {
  display: grid;
  grid-template-columns: 1.4em 3.4em minmax(0, 1fr) auto minmax(4.6em, auto);
  align-items: center;
  gap: 0.8rem;
  min-height: 3.1rem;
  padding: 0.35rem 0.9rem;
  border-radius: 0.5rem;
  background: var(--panel);
  border: 2px solid transparent;
  font-size: 1.5rem;
}
.final4 .round-row { min-height: 4.2rem; font-size: 1.7rem; }
.round-row .order { color: var(--faint); font-size: 0.75em; font-variant-numeric: tabular-nums; }
.round-row .seed { color: var(--muted); font-size: 0.7em; }
.round-row .name { font-weight: 600; line-height: 1.1; overflow-wrap: anywhere; }
.round-row .result { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.round-row .standing { text-align: right; font-size: 0.75em; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.round-row.waiting .name { color: var(--muted); font-weight: 500; }
.round-row.up { border-color: var(--accent); background: var(--accent-bg); }
.round-row.up .standing { color: var(--accent); font-weight: 700; }
.round-row.in .standing, .round-row.advance .standing { color: var(--accent); font-weight: 700; }
.round-row.leading .standing, .round-row.winner .standing { color: var(--gold); font-weight: 700; }
.round-row.winner { border-color: var(--gold); background: var(--gold-bg); }
/* Tied across the advance line (or for 1st): amber, dashed, and the word Tiebreak. */
.round-row.line-tie { border: 2px dashed var(--gold); background: var(--gold-bg); }
.round-row.line-tie .standing { color: var(--gold); font-weight: 700; }

.to-beat .big { font-size: 2.6rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--gold); line-height: 1.1; }
.to-beat .who { color: var(--muted); margin-top: 0.2rem; }

/* ---- Results ------------------------------------------------------------------------------------ */

.podium { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.6rem; }
.podium .card { background: var(--panel); border: 1px solid var(--border); border-radius: 0.6rem; padding: 0.8rem 1rem; }
.podium .card.first { border: 2px solid var(--gold); background: var(--gold-bg); }
.podium .card.minor {
  display: grid; grid-template-columns: 3.4rem minmax(0, 1fr) auto 4.5rem; align-items: baseline; gap: 1rem; padding: 0.55rem 1rem;
}
.card.minor .who { font-size: 1.7rem; }
.card.minor .prize { float: none; text-align: right; font-size: 1.3rem; }
.card.minor .what { font-variant-numeric: tabular-nums; white-space: nowrap; }
.card .pl { font-size: 0.95rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.card.first .pl { color: var(--gold); }
.card .who { font-size: 1.6rem; font-weight: 700; line-height: 1.15; overflow-wrap: anywhere; }
.card.first .who { font-size: 3rem; }
.card .what { color: var(--muted); font-variant-numeric: tabular-nums; }
.card .prize { float: right; font-weight: 700; color: var(--text); }
.two-col { columns: 2; column-gap: 1.6rem; }
.two-col .row { break-inside: avoid; }
.section-title { margin: 1rem 0 0.4rem; font-size: 0.95rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

/* ---- Problems ----------------------------------------------------------------------------------- */

.problem {
  position: fixed; left: 50%; top: 1rem; transform: translateX(-50%); max-width: 80vw;
  background: var(--bg); border: 2px solid var(--gold); color: var(--text);
  border-radius: 0.6rem; padding: 0.7rem 1rem; font-size: 1rem; z-index: 10;
}
.problem::before { content: "⚠ "; color: var(--gold); }
.empty { color: var(--muted); font-size: 1.2rem; }

/* ---- Phone -------------------------------------------------------------------------------------- */

@media (max-width: 700px) {
  html { font-size: 15px; }
  body { overflow: auto; }
  .stage, .timer-left .stage {
    height: auto; min-height: 100vh;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "head" "main" "side" "foot";
    padding: 1rem;
  }
  .layout-obs .timer-slot { display: none; }
  .side { margin-top: 1rem; }
  .side-body { overflow: visible; }
  .row { font-size: 1rem; height: 1.9rem; }
  .round-row, .final4 .round-row { grid-template-columns: 1.6rem 3.4rem minmax(0, 1fr) auto; font-size: 1.05rem; min-height: 2.6rem; }
  .round-row .standing { grid-column: 3 / -1; text-align: left; }
  .round-colhead, .final4 .round-colhead { grid-template-columns: 1.6rem 3.4rem minmax(0, 1fr) auto; font-size: 1.05rem; }
  .round-colhead span { font-size: 0.7em; }
  .round-colhead span:nth-child(5) { display: none; }
  .title { font-size: 1.5rem; }
  .course-list.two, .course-list.three { grid-template-columns: minmax(0, 1fr); }
  .rules-list { font-size: 1.05rem; }
  .cg-goal { font-size: 1.15em; }
}
