:root {
  color-scheme: light;
  --bg: #f6f6f3;
  --panel: #fff;
  --panel-2: #fafaf7;
  --text: #1a1a1a;
  --text-2: #3d3d38;
  --muted: #5b5b55;
  --faint: #8a8a83;
  --border: #deded8;
  --border-soft: #ecece6;
  --border-strong: #c9c9c2;
  --accent: #3366cc;
  --accent-dark: #1f4fa8;
  --accent-soft: #f2f6fd;
  --accent-soft-2: #e3ecfb;
  --primary: #3366cc;
  --primary-hover: #1f4fa8;
  --on-primary: #fff;
  --ink: #1a1a1a;
  --on-ink: #fff;
  --on-avatar: #fff;
  --target: #9a3412;
  --target-bg: #fff4ec;
  --target-border: #f0c9ae;
  --good: #1e6b3a;
  --good-soft: #eef7f0;
  --bad: #b42318;
  --violet: #6d28d9;
  --teal: #0f766e;
  --orange: #c2410c;
  --warn-bg: #fffbf2;
  --warn-border: #f0d9a8;
  --gold: #f5b301;
  --bar-bg: #1a1a1a;
  --on-bar: #fff;
  --bar-muted: #bdbdb5;
  --bar-border: #5b5b55;
  --chip: #f0f0eb;
  --img-bg: transparent;
  --on-overlay: #fff;
  --overlay: rgba(26, 26, 26, 0.75);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
  --radius: 12px;
  --serif: 'Source Serif 4', Georgia, serif;
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #141413;
    --panel: #1e1e1c;
    --panel-2: #242422;
    --text: #ecece8;
    --text-2: #cfcfc8;
    --muted: #a3a39b;
    --faint: #7a7a73;
    --border: #34342f;
    --border-soft: #2a2a27;
    --border-strong: #4a4a44;
    --accent: #8ab0f5;
    --accent-dark: #afc8f8;
    --accent-soft: #1b2438;
    --accent-soft-2: #22304d;
    --primary: #4677d8;
    --primary-hover: #5a88e2;
    --on-primary: #fff;
    --ink: #ecece8;
    --on-ink: #141413;
    --on-avatar: #141413;
    --target: #f8b48a;
    --target-bg: #2e1d12;
    --target-border: #6b3a1e;
    --good: #6fcf8e;
    --good-soft: #16261b;
    --bad: #f87171;
    --violet: #b79cf5;
    --teal: #5ec8bc;
    --orange: #f59e6b;
    --warn-bg: #2a2414;
    --warn-border: #5a4a22;
    --gold: #f5c542;
    --bar-bg: #0b0b0a;
    --on-bar: #ecece8;
    --bar-muted: #8a8a83;
    --bar-border: #4a4a44;
    --chip: #2c2c29;
    --img-bg: #f4f4f0;
    --on-overlay: #fff;
    --overlay: rgba(0, 0, 0, 0.8);
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #141413;
  --panel: #1e1e1c;
  --panel-2: #242422;
  --text: #ecece8;
  --text-2: #cfcfc8;
  --muted: #a3a39b;
  --faint: #7a7a73;
  --border: #34342f;
  --border-soft: #2a2a27;
  --border-strong: #4a4a44;
  --accent: #8ab0f5;
  --accent-dark: #afc8f8;
  --accent-soft: #1b2438;
  --accent-soft-2: #22304d;
  --primary: #4677d8;
  --primary-hover: #5a88e2;
  --on-primary: #fff;
  --ink: #ecece8;
  --on-ink: #141413;
  --on-avatar: #141413;
  --target: #f8b48a;
  --target-bg: #2e1d12;
  --target-border: #6b3a1e;
  --good: #6fcf8e;
  --good-soft: #16261b;
  --bad: #f87171;
  --violet: #b79cf5;
  --teal: #5ec8bc;
  --orange: #f59e6b;
  --warn-bg: #2a2414;
  --warn-border: #5a4a22;
  --gold: #f5c542;
  --bar-bg: #0b0b0a;
  --on-bar: #ecece8;
  --bar-muted: #8a8a83;
  --bar-border: #4a4a44;
  --chip: #2c2c29;
  --img-bg: #f4f4f0;
  --on-overlay: #fff;
  --overlay: rgba(0, 0, 0, 0.8);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }

body { -webkit-font-smoothing: antialiased; line-height: 1.45; }
h1, h2, h3 { font-family: var(--serif); font-weight: 700; line-height: 1.15; }
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }

button, input, select {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  padding: 0.5em 0.9em;
  background: var(--panel);
  color: inherit;
  transition: border-color 0.12s, background-color 0.12s, color 0.12s;
}
:where(button, select, input:not([type='checkbox'], [type='radio'])) { min-height: 40px; }
input[type='checkbox'], input[type='radio'] { accent-color: var(--accent); }
input::placeholder { color: var(--faint); }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
input:focus, select:focus { border-color: var(--accent); outline-color: var(--accent); }
button { cursor: pointer; font-weight: 600; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled, input:disabled, select:disabled { opacity: 0.6; cursor: default; }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
button.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
button.ink { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
button.ink:hover:not(:disabled) { background: var(--text-2); border-color: var(--text-2); }
button.ghost { background: transparent; border-color: var(--border); }
button.ghost:hover:not(:disabled) { background: var(--panel-2); border-color: var(--border); }
button.small { padding: 0.3em 0.75em; min-height: 34px; font-size: 0.9em; }
button.big { min-height: 52px; padding: 0 1.6em; border-radius: 10px; font-size: 17px; width: 100%; margin-top: 1em; }
input.busy { background: var(--accent-soft); }

.muted { color: var(--muted); }
.small-text { font-size: 0.85em; }
.error { color: var(--bad); margin: 0.75em 0 0; font-size: 0.95em; }
.eyebrow {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

body:not(.is-host) .host-only { display: none !important; }
body.is-host .guest-only { display: none !important; }

/* ---- home ---- */
#home { min-height: 100vh; }
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 32px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.home-header .brand span { font-size: 24px; }
.home-card {
  max-width: 1120px;
  margin: 0 auto;
  padding: 48px 24px 64px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}
.hero { display: flex; flex-direction: column; gap: 16px; }
.hero h1 { margin: 0; font-size: 56px; line-height: 1.05; max-width: 820px; letter-spacing: -0.01em; }
.route-demo {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  font-family: var(--serif);
  font-size: 22px;
  color: var(--muted);
}
.route-demo .chip { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); }
.route-demo .start-chip { background: var(--panel); color: var(--text); }
.route-demo .target-chip { background: var(--target-bg); border-color: var(--target-border); color: var(--target); }
.home-grid { display: flex; flex-wrap: wrap; gap: 24px; }
.home-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
}
.home-grid .home-panel { flex: 1 1 360px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.home-panel h2 { margin: 0; font-size: 28px; }
.field { display: grid; gap: 8px; margin: 0; }
.field > span, .field-label { font-size: 14px; font-weight: 600; color: var(--text-2); }
.field input { min-height: 52px; padding: 0 16px; border-radius: 10px; font-size: 17px; }
.home-actions { display: grid; gap: 0.75em; }
.home-actions .primary { min-height: 52px; border-radius: 10px; font-size: 17px; }
.join-row { display: flex; flex-wrap: wrap; gap: 10px; }
.join-row input {
  flex: 1 1 140px;
  min-width: 0;
  min-height: 52px;
  padding: 0 16px;
  border-radius: 10px;
  font-size: 22px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.join-row input::placeholder { letter-spacing: 0.05em; text-transform: none; font-size: 17px; }
.join-row button { min-height: 52px; padding: 0 22px; border-radius: 10px; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
#home-error { margin: -12px 0 0; }
.rules { padding: 20px 28px; color: var(--text-2); }
.rules summary { cursor: pointer; font-family: var(--serif); font-size: 22px; font-weight: 700; color: var(--text); }
.rules ul { margin: 12px 0 0; padding-left: 1.2em; }
.rules li { margin: 0.4em 0; }
@media (max-width: 640px) {
  .home-header { padding: 14px 16px; }
  .home-card { padding: 32px 16px 48px; gap: 24px; }
  .hero h1 { font-size: 36px; }
  .route-demo { font-size: 18px; }
  .home-panel { padding: 20px; }
  .home-panel h2 { font-size: 24px; }
}

/* ---- room chrome ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1em;
  padding: 10px 24px;
  min-height: 64px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand .logo { flex: none; }
.brand span { font-family: var(--serif); font-size: 21px; font-weight: 700; }
.room-code { margin-left: auto; display: flex; align-items: center; gap: 0.6em; color: var(--muted); font-size: 14px; }
.room-code b {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  letter-spacing: 0.15em;
  font-size: 16px;
  color: var(--text);
  padding: 4px 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
}
@media (max-width: 640px) {
  .topbar { padding: 8px 16px; gap: 0.6em; }
  .topbar .brand span { display: none; }
}

.view { padding: 1.2em; }
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4em;
}
.panel h2 { margin-top: 0; font-size: 24px; }

/* ---- lobby ---- */
.lobby-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  gap: 24px;
  align-items: start;
  max-width: 1120px;
  margin: 0 auto;
}
@media (max-width: 860px) { .lobby-grid { grid-template-columns: 1fr; } }
.lobby-settings { display: flex; flex-direction: column; gap: 24px; padding: 28px; }
.lobby-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
}
.lobby-head h2 { margin: 0; font-family: var(--serif); font-weight: 700; }
.lobby-settings .lobby-head h2 { font-size: 32px; }
.lobby-side .lobby-head { margin-bottom: 8px; }
.lobby-side .lobby-head h2 { font-size: 24px; }
.lobby-head .muted { font-size: 14px; }
.lobby-settings .lobby-head .muted { font-size: 13px; }
.lobby-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.lobby-side .panel { padding: 24px; }
.lobby-side button.big { width: 100%; min-height: 56px; margin: 0; font-size: 18px; border-radius: 10px; }
.lobby-side .error { margin: 0; text-align: center; }
.lobby-note { margin: 0; text-align: center; font-size: 13px; }

.page-picks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 560px) { .page-picks { grid-template-columns: 1fr; } }
.page-pick { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.page-pick label, .settings label, .house-rules legend {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
}
.pick-row { display: flex; gap: 8px; }
.pick-row input { flex: 1; min-width: 0; }
.article-input {
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-family: var(--serif);
  font-size: 19px;
}
.target-pick .article-input {
  border-color: var(--target-border);
  background: var(--target-bg);
  color: var(--target);
}
.target-pick .article-input::placeholder { color: var(--target); opacity: 0.55; }
.article-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.pick-row .dice { min-width: 48px; min-height: 48px; padding: 0; border-radius: 10px; border-color: var(--border-strong); }
.pick-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: -8px; }
.pick-actions button { min-height: 44px; padding: 0 16px; border-color: var(--border-strong); font-weight: 500; }

.target-preview:not(:empty), .target-card:not(:empty) {
  padding: 14px 16px;
  border: 1px solid var(--target-border);
  border-left: 4px solid var(--target);
  border-radius: 10px;
  background: var(--target-bg);
}
.target-preview:not(:empty) { margin-top: -8px; }
.target-card:not(:empty) { margin-top: 1em; }
.ts-head { display: flex; gap: 0.8em; align-items: center; }
.ts-head img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; }
.ts-head .muted { color: var(--target); opacity: 0.8; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; font-size: 12px; }
.ts-title { font-family: var(--serif); font-weight: 700; font-size: 20px; color: var(--target); }
.ts-extract { margin: 0.6em 0 0; font-size: 14px; line-height: 1.5; color: var(--text-2); }

.settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.settings label { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.settings .hint { font-weight: 400; color: var(--muted); font-size: 13px; }
.settings select, .settings input[type='number'] {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-weight: 400;
}
@media (max-width: 500px) { .settings { grid-template-columns: 1fr; } }

.house-rules { margin: 0; padding: 0; border: 0; display: flex; flex-direction: column; min-width: 0; }
.house-rules legend { padding: 0; margin-bottom: 8px; }
.house-rules label.check {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
  border-top: 1px solid var(--border-soft);
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
}
.house-rules label.check:last-child { border-bottom: 1px solid var(--border-soft); }
.house-rules label.check .muted { font-size: 14px; }
.house-rules input[type='checkbox'] { width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--accent); }

.player-list { list-style: none; padding: 0; margin: 0; }
.player-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  border-top: 1px solid var(--border-soft);
}
.player-list li.offline { opacity: 0.5; }
.dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  background: var(--accent);
  color: var(--on-avatar);
}
.dot.avatar-orange { background: var(--orange); }
.dot.avatar-teal { background: var(--teal); }
.dot.avatar-violet { background: var(--violet); }
.offline .dot { background: var(--faint); }
.pname { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.pmeta { margin-left: 6px; font-weight: 400; font-size: 13px; color: var(--muted); }
.pstatus { font-size: 13px; color: var(--muted); }
.tag { font-size: 0.75em; padding: 0.1em 0.5em; border-radius: 999px; background: var(--accent-soft-2); color: var(--accent-dark); margin-left: 0.3em; }
.tag.you { background: var(--good-soft); color: var(--good); }

/* ---- race ---- */
#race { padding: 0; }
.race-head {
  position: sticky;
  top: var(--topbar-h, 64px);
  z-index: 9;
}
.race-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 28px;
  padding: 12px 28px;
  background: var(--bar-bg);
  color: var(--on-bar);
}
.race-route {
  flex: 1 1 260px;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.3;
}
.race-route .pill { padding: 4px 10px; border-radius: 6px; overflow-wrap: anywhere; }
.race-route .pill:not(.target) { padding-left: 0; padding-right: 0; }
.race-route .pill.target { background: var(--target-bg); color: var(--target); font-weight: 700; }
.race-route .arrow { flex: none; color: var(--bar-muted); }
.race-stats { display: flex; align-items: baseline; gap: 28px; }
.race-stats .stat { display: flex; flex-direction: column; }
.race-stats .stat-label {
  font-size: 12px;
  color: var(--bar-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.race-stats .stat-value {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.race-stats .stat-limit { font-size: 16px; font-weight: 500; color: var(--bar-muted); }
.race-actions { display: flex; flex-wrap: wrap; gap: 8px; }
/* Buttons sit on the dark ink bar, so they need their own on-bar colours. */
.race-bar .race-actions button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--bar-border);
  border-radius: 8px;
  background: transparent;
  color: var(--on-bar);
  font-size: 15px;
  font-weight: 500;
}
.race-bar .race-actions button:hover:not(:disabled) { border-color: var(--on-bar); background: transparent; }

.race-path {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.race-path .path-label { flex: none; color: var(--muted); }
.breadcrumbs {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.breadcrumbs:empty::before { content: '—'; color: var(--faint); }
.breadcrumbs > span:not(.sep) {
  flex: none;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--text);
  white-space: nowrap;
}
.breadcrumbs > span:not(.sep):last-child { background: var(--accent-soft-2); color: var(--accent-dark); font-weight: 600; }
.sep { flex: none; color: var(--faint); }

@media (max-width: 600px) {
  .race-bar { padding: 10px 16px; gap: 8px 18px; }
  .race-route { font-size: 17px; flex-basis: 100%; }
  .race-stats { gap: 18px; }
  .race-stats .stat-value { font-size: 20px; }
  .race-bar .race-actions { margin-left: auto; }
  .race-bar .race-actions button { min-height: 40px; padding: 0 12px; }
  .race-path { padding: 8px 16px; }
}

.race-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 24px;
  padding: 24px 28px 48px;
  max-width: 1280px;
  margin: 0 auto;
}
.race-body > .sidebar {
  align-self: start;
  position: sticky;
  top: calc(var(--topbar-h, 64px) + var(--race-head-h, 120px) + 16px);
  max-height: calc(100vh - var(--topbar-h, 64px) - var(--race-head-h, 120px) - 32px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
@media (max-width: 900px) {
  .race-body { grid-template-columns: 1fr; gap: 16px; padding: 16px 16px 40px; }
  .race-body > .sidebar { order: -1; position: static; max-height: none; overflow: visible; }
}
.race-body > .sidebar .target-card:not(:empty) {
  margin: 0;
  padding: 16px 20px;
  background: var(--target-bg);
  border: 1px solid var(--target-border);
  border-radius: var(--radius);
}
.race-body > .sidebar .ts-title { color: var(--target); font-family: var(--serif); font-size: 20px; }
.race-body > .sidebar .ts-extract { color: var(--text-2); }
.side-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.side-card h2 { margin: 0 0 8px; font-size: 15px; font-weight: 600; }
.standings { list-style: none; padding: 0; margin: 0; }
.standings li {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 6px 0;
  border-top: 1px solid var(--border-soft);
}
.standings li.me { margin: 0 -8px; padding: 6px 8px; border-radius: 6px; background: var(--accent-soft); }
.standings li.offline { opacity: 0.55; }
.standings .avatar {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--on-ink);
  background: var(--muted);
}
.standings .avatar.cme { background: var(--accent); }
.standings .avatar.c0 { background: var(--orange); }
.standings .avatar.c1 { background: var(--violet); }
.standings .avatar.c2 { background: var(--teal); }
.standings .avatar.c3 { background: var(--good); }
.standings .who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.standings .who-name { display: flex; align-items: center; min-width: 0; font-size: 15px; }
.standings .who-name b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.standings .who-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.standings li.finished .who-sub { color: var(--good); }
.standings .place { flex: none; font-size: 15px; }
.standings .clicks {
  flex: none;
  min-width: 1.6em;
  text-align: right;
  font-family: ui-monospace, Menlo, monospace;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

#article-wrap {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 40px 40px;
  min-height: 60vh;
  position: relative;
  transition: opacity 0.15s;
}
@media (max-width: 600px) { #article-wrap { padding: 20px 18px 28px; } }
#article-wrap.loading { opacity: 0.5; cursor: progress; }
#article-wrap.locked .game-link { pointer-events: none; color: inherit; }
.banner {
  margin: 0 0 16px;
  padding: 12px 16px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 8px;
  color: var(--text);
  font-weight: 600;
}

.countdown {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 9em;
  font-weight: 700;
  color: var(--on-overlay);
  background: var(--overlay);
  z-index: 100;
}

/* ---- article content (Wikipedia HTML, themed via tokens) ---- */
.article-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 40px;
  line-height: 1.2;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  margin: 0 0 20px;
}
@media (max-width: 600px) { .article-title { font-size: 30px; } }
.article-body {
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.65;
  color: var(--text);
  overflow-wrap: break-word;
}
.article-body::after { content: ''; display: block; clear: both; }
.article-body p { margin: 0 0 16px; }
.article-body h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 28px;
  line-height: 1.3;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
  margin: 1.4em 0 0.5em;
}
.article-body h3 { font-size: 1.2em; font-weight: 700; margin: 1.2em 0 0.4em; }
.article-body h4, .article-body h5 { font-size: 1em; font-weight: 700; margin: 1em 0 0.3em; }
.article-body a { color: var(--accent); text-decoration: none; }
.article-body a.game-link:hover { color: var(--accent-dark); text-decoration: underline; }
.article-body a.dead-link { color: inherit; cursor: default; }
.article-body img {
  max-width: 100%;
  height: auto;
  background: var(--img-bg); /* light backdrop so transparent images/maths stay legible in dark mode */
  border-radius: 2px;
}
.article-body blockquote { margin: 1em 0; padding: 0 0 0 1em; border-left: 3px solid var(--border-strong); color: var(--text-2); }
.article-body hr { border: 0; border-top: 1px solid var(--border); }
.article-body pre, .article-body code {
  font-size: 0.85em;
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  border-radius: 4px;
}
.article-body pre { padding: 0.8em 1em; overflow-x: auto; }
.article-body code { padding: 0 0.25em; }
.article-body table { border-collapse: collapse; color: inherit; }
.article-body .wikitable,
.article-body .infobox,
.article-body figcaption,
.article-body .thumbcaption,
.article-body .reflist,
.article-body .references {
  font-family: Inter, system-ui, sans-serif;
}
.article-body .wikitable {
  background: var(--panel-2);
  border: 1px solid var(--border-strong);
  margin: 1em 0;
  font-size: 14px;
  line-height: 1.5;
  display: block;
  overflow-x: auto;
  max-width: 100%;
}
.article-body .wikitable th, .article-body .wikitable td { border: 1px solid var(--border-strong); padding: 0.3em 0.5em; }
.article-body .wikitable th { background: var(--chip); }
.article-body .infobox {
  float: right;
  clear: right;
  width: 22em;
  max-width: 100%;
  margin: 0 0 1em 1.4em;
  padding: 0.3em;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}
.article-body .infobox th, .article-body .infobox td { vertical-align: top; padding: 0.2em 0.45em; text-align: left; }
.article-body .infobox-above, .article-body .infobox-title {
  font-family: var(--serif);
  font-size: 125%;
  font-weight: 700;
  text-align: center;
}
.article-body .infobox-header, .article-body .infobox-subheader { background: var(--chip); text-align: center; }
.article-body .infobox-image, .article-body .infobox-caption { text-align: center; }
.article-body figure, .article-body .thumb {
  float: right;
  clear: right;
  margin: 0.5em 0 1em 1.4em;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 4px;
  max-width: 300px;
}
.article-body .thumbinner { max-width: 100%; }
.article-body figure.mw-halign-left, .article-body .tleft { float: left; clear: left; margin: 0.5em 1.4em 1em 0; }
.article-body figure.mw-halign-center, .article-body figure.mw-halign-none { float: none; margin: 1em auto; }
.article-body figcaption, .article-body .thumbcaption {
  font-size: 13px;
  line-height: 1.4;
  padding: 4px;
  color: var(--text-2);
}
.article-body .hatnote {
  font-style: italic;
  font-size: 0.9em;
  padding-left: 1.6em;
  margin-bottom: 0.6em;
  color: var(--muted);
}
.article-body .reflist, .article-body .references { font-size: 14px; color: var(--text-2); }
.article-body sup.reference { font-size: 70%; }
.article-body .mw-references-wrap { columns: 2 30em; }
.article-body .ambox, .article-body .mbox-small { display: none; }
@media (max-width: 600px) {
  .article-body .infobox, .article-body figure, .article-body .thumb { float: none; margin: 1em auto; width: auto; }
}
/* Wikipedia inline light backgrounds (infobox rows, table cells) would be unreadable under dark text colours. */
:root[data-theme='dark'] .article-body [style*='background']:not(:empty) { background: var(--panel-2) !important; color: inherit !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .article-body [style*='background']:not(:empty) { background: var(--panel-2) !important; color: inherit !important; }
}

/* ---- results ---- */
.results-panel {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 0 48px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.results-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 20px; }
.results-heading { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.results-eyebrow {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
#results-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 48px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text);
}
@media (max-width: 600px) { #results-title { font-size: 34px; } }
.results-head .results-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.results-head .results-actions button { min-height: 52px; padding: 0 22px; border-radius: 10px; }
#results-wait { margin: 0; }
.results-table {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.results-row {
  display: grid;
  grid-template-columns: 48px minmax(120px, 1.2fr) 100px 80px minmax(0, 3fr);
  align-items: center;
  gap: 0 20px;
  padding: 16px 20px;
}
.results-cols { padding: 14px 20px; font-size: 13px; font-weight: 600; color: var(--muted); }
.results-list { list-style: none; padding: 0; margin: 0; }
.results-list li { border-top: 1px solid var(--border-soft); font-size: 15px; }
.results-list li.winner { background: var(--warn-bg); }
.results-list li:not(.finished) { color: var(--muted); }
.results-list .place { font-size: 20px; font-weight: 700; }
.results-list .result-name { min-width: 0; overflow-wrap: anywhere; }
.results-list .result-name b { font-weight: 600; }
.results-list .result-time {
  font-family: ui-monospace, Menlo, monospace;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.results-list .result-time.dnf { font-family: inherit; font-weight: 400; font-size: 14px; }
.results-list .result-clicks { font-family: ui-monospace, Menlo, monospace; font-variant-numeric: tabular-nums; }
.results-list .result-clicks .unit { display: none; }
.result-path {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 6px;
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.5;
}
.result-path a { color: var(--text); text-decoration: none; }
.results-list li:not(.finished) .result-path a { color: var(--muted); }
.result-path a:hover { color: var(--accent); text-decoration: underline; }
.result-path a.is-target, .results-list li .result-path a.is-target { color: var(--target); font-weight: 700; }
@media (max-width: 720px) {
  .results-cols { display: none; }
  .results-row { grid-template-columns: 36px minmax(0, 1fr) auto auto; gap: 4px 14px; padding: 14px 16px; }
  .results-list .result-path { grid-column: 2 / -1; }
  .results-list .result-clicks .unit { display: inline; font-family: Inter, system-ui, sans-serif; font-size: 13px; color: var(--muted); }
}

/* ---- toast ---- */
.toast {
  position: fixed;
  bottom: 1.5em;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--on-ink);
  padding: 0.7em 1.2em;
  border-radius: 10px;
  font-weight: 500;
  z-index: 200;
  max-width: 90vw;
  box-shadow: var(--shadow);
}
.toast.error { background: var(--bad); color: var(--on-primary); }

/* ---- theme toggle ---- */
.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  flex: none;
  color: var(--text-2);
}
button.theme-toggle.ghost { border-color: var(--border-strong); background: var(--panel); }
button.theme-toggle.ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--text); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .moon { display: none; }
:root[data-theme='dark'] .theme-toggle .sun { display: none; }
:root[data-theme='dark'] .theme-toggle .moon { display: block; }

/* ---- find-in-page protection (see hideTextFromFind in app.js) ---- */
.nf::before { content: attr(data-t); }
#article:has(.nf) { user-select: none; -webkit-user-select: none; }

/* ---- page picker autocomplete ---- */
.ac { position: relative; flex: 1; min-width: 0; display: flex; }
.ac input { flex: 1; min-width: 0; }
.ac-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 6px 0;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 20;
  max-height: min(320px, 50vh);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.ac-list li { padding: 8px 14px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.ac-list li.active, .ac-list li:hover { background: var(--accent-soft); }
.ac-title { font-family: var(--serif); font-size: 16px; color: var(--text); }
.ac-desc { font-size: 13px; color: var(--muted); }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.suggestions button { font-weight: 500; color: var(--text); }

/* ---- radio groups in rules ---- */
.radio-group { border: 0; margin: 0; padding: 0; display: grid; gap: 8px; min-width: 0; }
.radio-group legend { padding: 0; margin-bottom: 6px; font-size: 14px; font-weight: 600; color: var(--text-2); }
.settings .radio-group label { display: flex; flex-direction: row; align-items: center; gap: 8px; cursor: pointer; font-size: 15px; font-weight: 400; color: var(--text); }
.radio-group input { width: auto; margin: 0; min-height: 0; accent-color: var(--accent); }

/* ---- site switcher (Hannah's / Vedant's deployments) ---- */
.header-actions { display: flex; align-items: center; gap: 12px; }
.site-switch { display: flex; align-items: center; gap: 6px; }
.site-switch a { display: block; border-radius: 50%; padding: 2px; border: 2px solid transparent; opacity: 0.6; transition: opacity 0.15s, border-color 0.15s; }
.site-switch a:hover, .site-switch a:focus-visible { opacity: 1; border-color: var(--border-strong); }
.site-switch a[aria-current='page'] { opacity: 1; border-color: var(--accent); cursor: default; }
.site-switch img { display: block; width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.topbar .site-switch img { width: 30px; height: 30px; }
@media (max-width: 640px) {
  .topbar .site-switch { display: none; }
}

/* ---- landmark alerts (top of page) ---- */
.alerts {
  position: fixed;
  top: 0.75em;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: 0.5em;
  justify-items: center;
  z-index: 210;
  pointer-events: none;
  width: max-content;
  max-width: 92vw;
}
.alert-pop {
  background: var(--ink);
  color: var(--on-ink);
  padding: 0.75em 1.3em;
  border-radius: 999px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: alert-in 0.25s ease-out;
  transition: opacity 0.3s, transform 0.3s;
}
.alert-pop.leaving { opacity: 0; transform: translateY(-10px); }
@keyframes alert-in {
  from { opacity: 0; transform: translateY(-14px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .alert-pop { animation: none; transition: none; }
}

/* ---- table of contents (optional rule) ---- */
.article-toc {
  display: inline-block;
  min-width: 240px;
  max-width: 100%;
  margin: 0.5em 0 1.2em;
  padding: 10px 16px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.92em;
}
.article-toc summary {
  cursor: pointer;
  font-weight: 700;
  font-family: var(--serif);
  font-size: 1.05em;
}
.article-toc ol { list-style: none; margin: 0.4em 0 0; padding: 0; }
.article-toc ol ol { margin: 0.1em 0 0.2em 1.6em; }
.article-toc li { margin: 0.15em 0; }
.article-body .article-toc a.toc-link { color: var(--accent); display: inline-flex; gap: 0.5em; }
.article-body .article-toc a.toc-link:hover { text-decoration: underline; }
.toc-num { color: var(--muted); font-variant-numeric: tabular-nums; }
/* Keep headings clear of the sticky top bar and race bar when jumped to. */
.article-body :is(h2, h3)[id] {
  scroll-margin-top: calc(var(--topbar-h, 64px) + var(--race-head-h, 120px) + 16px);
}
