/* Shared look for index.html and dashboard.html.
   Colors are roles (custom properties); light and dark values swap in one place. */

:root {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink2: #52514e;
  --muted: #6f6d67;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.12);
  --link: #1c5cab;
  --series-1: #2a78d6;   /* blue   */
  --series-2: #eb6834;   /* orange */
  --context: #898781;    /* gray for "everyone else" */
  --div-pos: #2a78d6;    /* gained  */
  --div-neg: #e34948;    /* lost    */
  --focus: #2a78d6;
  --accent: #f5c400;     /* flag yellow: decoration and highlights only, never data */
  --serif: Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink2: #c3c2b7;
    --muted: #a4a29b;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.12);
    --link: #86b6ef;
    --series-1: #3987e5;
    --series-2: #d95926;
    --div-pos: #3987e5;
    --div-neg: #e66767;
    --focus: #86b6ef;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --ink: #f0efec;
  --ink2: #c3c2b7;
  --muted: #a4a29b;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.12);
  --link: #86b6ef;
  --series-1: #3987e5;
  --series-2: #d95926;
  --div-pos: #3987e5;
  --div-neg: #e66767;
  --focus: #86b6ef;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.6;
}

a { color: var(--link); }
a:focus-visible, button:focus-visible, summary:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- navigation ---------- */
.nav {
  background: #0f1114;           /* asphalt band in both themes */
  position: sticky; top: 0; z-index: 30;
}
.nav-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.35rem 16px;
  display: flex;
  align-items: center;
  gap: 0.5rem 1rem;
  flex-wrap: wrap;
}
.brand { display: inline-flex; align-items: center; gap: 0.6rem; font-family: var(--serif); font-size: 1.15rem; font-weight: 700; color: #f5f5f2; text-decoration: none; margin-right: auto; }
.brand::before {                 /* a tiny checkered flag */
  content: ""; width: 20px; height: 20px; border-radius: 3px; border: 1px solid #f5f5f2;
  background: repeating-conic-gradient(#f5f5f2 0 25%, #0f1114 0 50%) 0 0 / 10px 10px;
}
.nav a.tab { color: #b9bbc2; text-decoration: none; padding: 0.55rem 0.7rem; border-radius: 0; box-shadow: inset 0 -3px 0 transparent; }
.nav a.tab[aria-current="page"] { color: #fff; box-shadow: inset 0 -3px 0 var(--accent); }
.nav a.tab:hover { color: #fff; }
.nav a:focus-visible, .nav button:focus-visible { outline-color: var(--accent); }
.theme-btn {
  font: inherit; font-size: 0.875rem; color: #d7d8dc; background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.28); border-radius: 6px; padding: 0.3rem 0.65rem; cursor: pointer;
}
.theme-btn:hover { color: #fff; border-color: rgba(255, 255, 255, 0.5); }
.stripe { height: 8px; background: repeating-conic-gradient(#0f1114 0 25%, #f5f5f2 0 50%) 0 0 / 16px 16px; }

/* ---------- page frame ---------- */
main { max-width: 960px; margin: 0 auto; padding: 24px 16px 64px; }
.narrow { max-width: 720px; }

h1, h2, h3 { font-family: var(--serif); font-weight: 700; line-height: 1.2; margin: 0; }
h1 { font-size: clamp(1.5rem, 3.6vw, 2.1rem); margin-bottom: 0.5rem; }
h2 { font-size: clamp(1.3rem, 3vw, 1.65rem); margin: 0 0 0.6rem; }
h3 { font-size: 1.15rem; margin: 1.5rem 0 0.4rem; }
.byline { color: var(--ink2); margin: 0 0 0.25rem; }
.reader { color: var(--ink2); font-style: italic; margin: 0 0 1.25rem; }
.figure .rows { margin: 4px 0 6px; font-size: 0.8rem; }
.lede { font-size: 1.1rem; }
p { margin: 0 0 1rem; }
.note { color: var(--ink2); font-size: 0.9rem; }

/* ---------- summary numbers ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 1.25rem 0 2rem; padding: 0; list-style: none; }
.tile { background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--accent); border-radius: 8px; padding: 12px 16px 14px; }
.tile .label { color: var(--ink2); font-size: 0.875rem; margin: 0; }
.tile .value { font-size: clamp(1.6rem, 4vw, 2.1rem); font-weight: 600; line-height: 1.2; margin: 0.15rem 0; }
.tile .sub { color: var(--muted); font-size: 0.8rem; margin: 0; line-height: 1.35; }

/* ---------- findings ---------- */
.finding { border-top: 1px solid var(--border); padding-top: 1.5rem; margin-top: 2rem; }
.finding .num { color: var(--muted); font-size: 0.85rem; margin: 0 0 0.25rem; letter-spacing: 0.02em; }
.figure { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px 16px 12px; margin: 1rem 0; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06); }
.figure .title { font-weight: 600; font-size: 0.95rem; margin: 0; }
.figure .subtitle { color: var(--ink2); font-size: 0.85rem; margin: 0 0 8px; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0 0 6px; padding: 0; list-style: none; font-size: 0.85rem; color: var(--ink2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.key-line { display: inline-block; width: 16px; height: 2px; border-radius: 1px; }
.key-box { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }

/* ---------- SVG chart parts (colors come from the roles above) ---------- */
.c-grid { stroke: var(--grid); stroke-width: 1; }
.c-axis { stroke: var(--axis); stroke-width: 1; }
.c-tick, .c-cat { fill: var(--muted); font-size: 11.5px; font-family: var(--sans); }
.c-cat { fill: var(--ink2); font-size: 12px; }
.c-label { fill: var(--ink); font-size: 12px; font-family: var(--sans); font-weight: 600; }
.c-dot { stroke: var(--surface); stroke-width: 2; }
.c-cross { stroke: var(--axis); stroke-width: 1; }
.c-bar { outline: none; }
.c-bar .mark { transition: opacity 0.1s; }
.c-bar:hover .mark, .c-bar:focus .mark { opacity: 0.75; }
.c-bar:focus-visible .mark { stroke: var(--ink); stroke-width: 1.5; }
.c-empty { fill: var(--ink2); font-size: 13px; font-family: var(--sans); }

.tip {
  position: fixed; z-index: 20; pointer-events: none; display: none;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; font-size: 0.85rem; line-height: 1.4;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18); max-width: 260px;
}
.tip .tip-head { color: var(--ink2); margin-bottom: 2px; }
.tip .tip-row { display: flex; align-items: center; gap: 8px; }
.tip .tip-val { font-weight: 700; }
.tip .tip-name { color: var(--ink2); }

/* ---------- tables ("view the numbers") ---------- */
details.numbers { margin: 0.5rem 0 0; }
details.numbers summary { cursor: pointer; color: var(--link); font-size: 0.9rem; padding: 4px 0; }
.table-wrap { overflow-x: auto; margin-top: 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
caption { text-align: left; padding: 8px 10px; color: var(--ink2); }
th, td { padding: 6px 10px; text-align: right; white-space: nowrap; border-top: 1px solid var(--grid); }
th:first-child, td:first-child { text-align: left; }
thead th { border-top: 0; color: var(--ink2); font-weight: 600; background: var(--surface); }
td { font-variant-numeric: tabular-nums; }
tr.total td { font-weight: 700; border-top: 1px solid var(--axis); }

/* ---------- closing section ---------- */
.about h3 { margin-top: 1.6rem; }
.about dl { margin: 0; }
.about dt { font-weight: 600; margin-top: 0.8rem; }
.about dd { margin: 0.1rem 0 0; color: var(--ink2); }
.about a { overflow-wrap: anywhere; }
.about code { font-size: 0.9em; background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }

/* ---------- dashboard controls ---------- */
.controls { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; display: grid; gap: 12px; margin-bottom: 16px; }
.control-row { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: flex-start; }
.control-group { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.control-group > .glabel { font-size: 0.8rem; color: var(--ink2); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.chip span { display: inline-block; padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px; font-size: 0.875rem; color: var(--ink2); background: var(--bg); }
.chip input:checked + span { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.chip input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.btn { font: inherit; font-size: 0.85rem; color: var(--ink); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
.btn:hover { border-color: var(--axis); }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.team-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 2px 14px; }
.team-grid label { display: flex; align-items: center; gap: 6px; font-size: 0.875rem; color: var(--ink2); padding: 2px 0; }
details.teams > summary { cursor: pointer; font-size: 0.8rem; font-weight: 600; color: var(--ink2); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.seg span { display: block; padding: 4px 12px; font-size: 0.875rem; color: var(--ink2); background: var(--bg); border-right: 1px solid var(--border); }
.seg label:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--series-1); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: -2px; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.grid-2 > * { min-width: 0; }
.grid-2 .figure { margin: 0; }
.dash-note { color: var(--ink2); font-size: 0.9rem; margin: 0 0 12px; }
.dim { opacity: 0.55; }

/* ---------- headline kicker, scroll reveal ---------- */
.kicker { display: inline-block; margin: 0 0 0.6rem; padding: 2px 10px; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: #0f1114; background: var(--accent); border-radius: 3px; }
.js-reveal .reveal { opacity: 0; transform: translateY(18px); transition: opacity 0.6s ease, transform 0.6s ease; }
.js-reveal .reveal.in { opacity: 1; transform: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- racetrack panel (dark in both themes) ---------- */
.race {
  --bg: #0e1013; --surface: #171a1f; --ink: #f2f2ef; --ink2: #c9cac4; --muted: #9b9c96;
  --grid: #2a2d33; --axis: #3b3f46; --border: rgba(255, 255, 255, 0.14); --link: #86b6ef;
  --series-1: #3987e5; --series-2: #d95926; --context: #a09f98; --focus: #ffd633;
  color-scheme: dark; color: var(--ink);
  background: linear-gradient(180deg, #15181d 0%, #0e1013 100%);
  border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 14px;
  padding: 20px; margin: 1.75rem 0 2rem;
}
.race h2 { color: #fff; margin-bottom: 0.25rem; }
.race .note { color: var(--ink2); margin: 0 0 14px; }
.race-controls { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; margin-bottom: 14px; }
.race .seg { flex-wrap: wrap; }
.race .seg span { padding: 5px 11px; }
.race .btn { background: #1d2127; color: var(--ink); border-color: rgba(255, 255, 255, 0.2); }
.race .btn[aria-pressed="true"] { background: var(--accent); color: #0f1114; border-color: var(--accent); }
.race-body { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(220px, 1fr); gap: 18px; align-items: start; }
.track-wrap svg { display: block; width: 100%; height: auto; }
.track-asphalt { fill: none; stroke: #2a2d33; }
.track-edge { fill: none; stroke: #e7e7e1; }
.track-center { fill: none; stroke: #6c707a; stroke-width: 2; stroke-dasharray: 10 14; }
.infield { fill: rgba(255, 255, 255, 0.025); }
.year-big { fill: #fff; font-family: var(--serif); font-weight: 700; text-anchor: middle; }
.year-cap { fill: #b9bbc2; font-family: var(--sans); text-anchor: middle; }
.car { cursor: pointer; transition: opacity 0.2s; }
.car.dim { opacity: 0.32; }
.car-body { stroke: #fff; stroke-width: 1.6; }
.car-glass { fill: rgba(10, 12, 16, 0.78); }
.pill-bg { fill: rgba(10, 12, 16, 0.9); stroke-width: 2; }
.pill-text { fill: #fff; font-family: var(--sans); font-weight: 700; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.car.sel .pill-bg { stroke: var(--accent) !important; stroke-width: 3.2; }
.car.hot .pill-bg { stroke: #fff !important; stroke-width: 3; }
.car:focus { outline: none; }
.car:focus-visible .pill-bg { stroke: var(--accent) !important; stroke-width: 3.5; }
.board { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.board-row {
  display: grid; grid-template-columns: 1.6rem 1.7rem 1fr auto; gap: 8px; align-items: center; width: 100%;
  font: inherit; font-size: 0.9rem; color: var(--ink); text-align: left; cursor: pointer;
  background: #171a1f; border: 1px solid transparent; border-radius: 8px; padding: 5px 10px;
}
.board-row:hover, .board-row.hot { border-color: rgba(255, 255, 255, 0.35); }
.board-row.sel { border-color: var(--accent); background: #1d2127; }
.board-row .rk { color: var(--muted); font-variant-numeric: tabular-nums; }
.board-row .vl { font-variant-numeric: tabular-nums; font-weight: 700; }
.badge { display: inline-flex; align-items: center; justify-content: center; width: 1.7rem; height: 1.7rem; border-radius: 50%; font-size: 0.62rem; font-weight: 800; color: #fff; letter-spacing: 0; border: 2px solid rgba(255, 255, 255, 0.85); overflow: hidden; }
.badge img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.combo { position: relative; }
.combo input {
  font: inherit; font-size: 0.9rem; color: var(--ink); background: #1d2127; width: 15rem; max-width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 6px; padding: 5px 10px;
}
.combo input::placeholder { color: var(--muted); }
.combo ul {
  position: absolute; z-index: 15; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none;
  background: #1d2127; border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 8px; max-height: 14rem; overflow-y: auto;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5);
}
.combo li { padding: 5px 8px; border-radius: 5px; cursor: pointer; font-size: 0.9rem; }
.combo li[aria-selected="true"], .combo li:hover { background: #2a2f37; }
.spot { margin-top: 16px; }
.spot-card { background: #171a1f; border: 1px solid rgba(255, 255, 255, 0.14); border-top: 4px solid var(--accent); border-radius: 10px; padding: 14px 16px; }
.spot-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.spot-head h3 { margin: 0; font-size: 1.25rem; color: #fff; }
.spot-head .btn { margin-left: auto; }
.spot-card p { color: var(--ink2); margin: 0 0 10px; }
.spot-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 14px; margin: 0 0 10px; }
.spot-stats div { background: #1d2127; border-radius: 6px; padding: 6px 10px; }
.spot-stats dt { color: var(--muted); font-size: 0.75rem; }
.spot-stats dd { margin: 0; font-weight: 700; font-size: 1rem; }
.spot-chart { margin-top: 6px; }
.spot-empty { color: var(--muted); font-size: 0.9rem; margin: 0; }

@media (max-width: 900px) {
  .race-body { grid-template-columns: 1fr; }
  .board { grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); }
}
@media (max-width: 720px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .race { padding: 14px; }
}
@media (max-width: 520px) {
  .brand { font-size: 0; gap: 0; }          /* keep the checkered-flag icon; the link still has an aria-label */
  .brand::before { width: 24px; height: 24px; }
  .nav-inner { gap: 0.25rem 0.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .js-reveal .reveal { opacity: 1; transform: none; }
}
