/* Design tokens. Light is the base; dark redefines only what changes, under both the
   OS setting and the explicit toggle, so the toggle wins in either direction. */
:root {
  color-scheme: light;

  --plane: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --hairline: rgba(11, 11, 11, 0.1);

  /* Categorical slots 1 and 2: observed, and the expected reference it is read
     against. Validated as an adjacent pair in both modes. */
  --series-1: #2a78d6;
  --series-2: #eb6834;

  /* Sequential blue ramp, for the position heatmap. */
  --seq-0: #f2f5f8;
  --seq-1: #cde2fb;
  --seq-2: #9ec5f4;
  --seq-3: #6da7ec;
  --seq-4: #3987e5;
  --seq-5: #256abf;
  --seq-6: #104281;

  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;

  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --ink-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --hairline: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;
    --series-2: #d95926;
    --seq-0: #202024;
    --seq-1: #16314f;
    --seq-2: #184f95;
    --seq-3: #256abf;
    --seq-4: #3987e5;
    --seq-5: #6da7ec;
    --seq-6: #9ec5f4;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --ink-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --hairline: rgba(255, 255, 255, 0.1);
  --series-1: #3987e5;
  --series-2: #d95926;
  --seq-0: #202024;
  --seq-1: #16314f;
  --seq-2: #184f95;
  --seq-3: #256abf;
  --seq-4: #3987e5;
  --seq-5: #6da7ec;
  --seq-6: #9ec5f4;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  background: var(--plane);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding-block: 24px 64px;
  padding-inline: 16px;
}

a { color: var(--series-1); }

/* ------------------------------------------------------------------ header */

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

#theme { flex: none; width: 36px; height: 36px; padding: 0; font-size: 18px; line-height: 1; }

header h1 {
  margin: 0 0 4px;
  font-size: 22px;
  letter-spacing: -0.01em;
}

.sub {
  margin: 0;
  color: var(--ink-2);
  font-size: 13px;
}

.latest {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
}

.latest h2 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}

.latest-grid {
  clear: both;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 8px 18px;
}

/* One wheel per row, whatever the width. */
.latest-grid.column { grid-template-columns: 1fr; }

#latest-layout {
  float: right;
  display: flex;
  margin-bottom: 14px;
  padding: 5px;
}

/* The icon shows the layout the button switches to. */
#latest-layout[aria-pressed="false"] .as-grid,
#latest-layout[aria-pressed="true"] .as-column { display: none; }

.latest-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.latest-row .wheel {
  flex: 0 0 76px;
  color: var(--ink-2);
  font-size: 12px;
}

.ball {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 5px;
  border-radius: 50%;
  background: var(--seq-1);
  color: var(--ink);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

:root[data-theme="dark"] .ball,
:root:not([data-theme="light"]) .ball { color: var(--ink); }

/* ----------------------------------------------------------------- sections */

/* The switch between the two halves of the page, a level above the statistics' tabs. */
.sections {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.sections button {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border-radius: var(--radius);
  text-align: left;
}

.sections button b { font-size: 15px; }
.sections button span { color: var(--ink-2); font-size: 13px; }

.sections button[aria-current="page"] {
  border-color: var(--series-1);
  box-shadow: inset 0 0 0 1px var(--series-1);
}

/* ------------------------------------------------------------------- notice */

.notice {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--warning);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13px;
}

.notice strong { color: var(--ink); }
.notice p { margin: 0 0 6px; }
.notice p:last-child { margin: 0; }

/* ------------------------------------------------------------------ filters */

.filters {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin: 20px 0 0;
  padding: 12px 0;
  background: var(--plane);
  border-bottom: 1px solid var(--hairline);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  color: var(--ink-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

select,
input[type="number"],
button {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--axis);
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
}

select:focus-visible,
button:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

/* --------------------------------------------------------------------- tabs */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 16px 0 20px;
}

.tabs button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-2);
  padding: 7px 12px;
  border-radius: 999px;
}

.tabs button:hover { background: var(--surface); }

.tabs button[aria-selected="true"] {
  background: var(--surface);
  border-color: var(--hairline);
  color: var(--ink);
  font-weight: 600;
}

/* -------------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 20px;
}

.card > h2 {
  margin: 0 0 4px;
  font-size: 15px;
}

.card > .help {
  margin: 0 0 16px;
  color: var(--ink-2);
  font-size: 13px;
  max-width: 78ch;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

/* -------------------------------------------------------------------- tiles */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.tile {
  padding: 12px 14px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
}

.tile .k {
  display: block;
  color: var(--ink-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tile .v {
  font-size: 24px;
  line-height: 1.2;
}

.tile .n {
  display: block;
  color: var(--ink-2);
  font-size: 12px;
}

/* ------------------------------------------------------------------- tables */

.scroll { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th, td {
  padding: 7px 10px;
  text-align: right;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}

th:first-child, td:first-child { text-align: left; }

thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  border-bottom: 1px solid var(--axis);
}

th[aria-sort] { cursor: pointer; user-select: none; }
th[aria-sort]:hover { color: var(--ink); }
th[aria-sort="descending"]::after { content: " \25BC"; font-size: 9px; }
th[aria-sort="ascending"]::after { content: " \25B2"; font-size: 9px; }

tbody tr:hover { background: color-mix(in srgb, var(--series-1) 7%, transparent); }

td.num { font-weight: 600; }
td.dim { color: var(--ink-muted); }
.over { color: var(--series-1); }
.under { color: var(--series-2); }

/* --------------------------------------------------------------- tabellone */

/* The grid scrolls inside its own box, both ways, under a header that stays put. */
.grid-box {
  overflow: auto;
  max-height: 80vh;
  border: 1px solid var(--axis);
  border-radius: 6px;
}

.grid-box .help { margin: 12px; }

/* Separate borders: with collapsed ones a sticky cell leaves its border behind. */
.grid { width: auto; border-collapse: separate; border-spacing: 0; }

.grid th, .grid td {
  padding: 0;
  text-align: center;
  border-bottom: 1px solid var(--grid);
  border-right: 1px solid var(--grid);
}

.grid .edge { border-left: 1px solid var(--axis); }

.grid thead th { z-index: 3; color: var(--ink); }
.grid thead tr:first-child th { height: 36px; padding: 0 4px; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; }
.grid thead tr:last-child th { top: 36px; height: 20px; color: var(--ink-muted); font-size: 10px; font-weight: 400; }
.grid thead small { display: block; color: var(--ink-muted); font-size: 9px; font-weight: 400; letter-spacing: 0; text-transform: none; }
.grid thead th.on { color: var(--series-1); }
.grid thead th.rail { left: 0; z-index: 5; }

/* The delay, always in view. */
.grid tbody th {
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 44px;
  padding: 0 8px 0 5px;
  text-align: right;
  font-size: 11px;
  border-right: 1px solid var(--axis);
  background: var(--tier, var(--surface));
}

.grid td { min-width: 27px; height: 22px; font-size: 12px; font-weight: 600; }
.grid td.full { background: var(--tier-cell, transparent); }
/* Past a wheel's longest delay there is nothing left to place. */
.grid td.out { background: var(--plane); opacity: 0.5; }

/* One step per tier, mixed into the surface so it holds in both themes. */
.grid .t1, .swatch.t1 { --tier: color-mix(in srgb, var(--warning) 22%, var(--surface)); --tier-cell: color-mix(in srgb, var(--warning) 10%, var(--surface)); }
.grid .t2, .swatch.t2 { --tier: color-mix(in srgb, var(--warning) 45%, var(--surface)); --tier-cell: color-mix(in srgb, var(--warning) 22%, var(--surface)); }
.grid .t3, .swatch.t3 { --tier: color-mix(in srgb, var(--warning) 70%, var(--surface)); --tier-cell: color-mix(in srgb, var(--warning) 36%, var(--surface)); }
.grid .t4, .swatch.t4 { --tier: color-mix(in srgb, var(--series-2) 60%, var(--surface)); --tier-cell: color-mix(in srgb, var(--series-2) 32%, var(--surface)); }
.grid .t5, .swatch.t5 { --tier: color-mix(in srgb, var(--critical) 65%, var(--surface)); --tier-cell: color-mix(in srgb, var(--critical) 36%, var(--surface)); }
.swatch[class*=" t"] { background: var(--tier); }

/* ------------------------------------------------------------------- charts */

figure {
  margin: 0;
}

figcaption {
  margin-bottom: 10px;
  color: var(--ink-2);
  font-size: 13px;
}

svg { display: block; width: 100%; height: auto; overflow: visible; }

.gridline { stroke: var(--grid); stroke-width: 1; }
.axis { stroke: var(--axis); stroke-width: 1; }
.tick { fill: var(--ink-muted); font-size: 10px; }
.bar { fill: var(--series-1); }
.bar-down { fill: var(--series-2); }
.bar-hit { fill: transparent; cursor: pointer; }
.bar-hit:hover + .bar, .bar-hit:focus-visible + .bar { fill: var(--series-2); }
.expected-mark { stroke: var(--series-2); stroke-width: 2; }
.label { fill: var(--ink-2); font-size: 10px; font-variant-numeric: tabular-nums; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin: 10px 0 0;
  color: var(--ink-2);
  font-size: 12px;
}

.legend span { display: inline-flex; align-items: center; gap: 6px; }

.swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  background: var(--series-1);
}

.swatch.down { background: var(--series-2); }

.swatch.ref {
  height: 3px;
  border-radius: 2px;
  background: var(--series-2);
}

.tip {
  position: fixed;
  z-index: 20;
  max-width: 260px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  line-height: 1.45;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.16);
  pointer-events: none;
}

.tip[hidden] { display: none; }
.tip b { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ heatmap */

.heat-cell { stroke: var(--surface); stroke-width: 2; }

.scale {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  color: var(--ink-2);
  font-size: 12px;
}

.scale .steps { display: flex; }
.scale .steps i { width: 22px; height: 11px; }

/* -------------------------------------------------------------- number grid */

.numgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 6px;
}

.numgrid button {
  padding: 7px 0;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.numgrid button[aria-pressed="true"] {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #fff;
  font-weight: 600;
}

/* ----------------------------------------------------------------- formulas */

.groups { display: flex; flex-wrap: wrap; gap: 12px; }

.groups fieldset {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 16px;
  min-width: 0;
  margin: 0;
  padding: 8px 14px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
}

.groups legend { padding: 0 6px; color: var(--ink-2); font-size: 12px; font-weight: 600; }

.checks { display: flex; flex-direction: column; }
.check { display: inline-flex; align-items: center; gap: 6px; padding: 2px 0; cursor: pointer; }

input[type="file"] { font: inherit; color: var(--ink); width: 230px; max-width: 100%; padding: 6px 0; }

details { border-top: 1px solid var(--grid); }
details > summary { padding: 9px 0; cursor: pointer; font-variant-numeric: tabular-nums; }
details > summary .found { margin-left: 10px; }
details > summary button.link { margin-left: 10px; }
details > .scroll { margin-bottom: 12px; }

.findings td, .findings th { text-align: left; vertical-align: top; }
.findings tbody tr { cursor: pointer; }
.findings .bets { white-space: normal; }
.found { display: inline-flex; align-items: center; gap: 4px; margin-right: 12px; }
.kind { display: inline-block; min-width: 68px; color: var(--ink-muted); font-size: 12px; }
.bets > div { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 0; margin-bottom: 4px; }
.bet { display: inline-flex; gap: 4px; margin-right: 12px; }
.findings .bets > div { flex-wrap: nowrap; align-items: flex-start; }
.findings .kind { line-height: 28px; }
.stack { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.dirty { color: var(--critical); }
.bet.dirty { margin-right: 6px; }

/* A bet's numbers: white while it is clean, red and barred once it is dirty.
   The .findings prefix is there to outweigh the themed .ball colour above. */
.findings .bet .ball { background: #fff; color: #0b0b0b; border: 1px solid var(--axis); }

.findings .bet.dirty .ball {
  position: relative;
  background: var(--critical);
  border-color: var(--critical);
  color: #fff;
}

/* The oblique bar of a "do not play" sign, drawn over the number. */
.findings .bet.dirty .ball::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: linear-gradient(to top right,
    transparent calc(50% - 1px), #0b0b0b calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px));
}

button.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--series-1);
  text-decoration: underline;
}

button.link.dirty { margin-right: 10px; color: var(--critical); }

.outcome { color: var(--ink-muted); font-size: 13px; }
.outcome.open { color: var(--ink-2); font-style: italic; }
button.link.outcome.won { color: var(--good); font-weight: 600; }
input[type="number"] { width: 84px; cursor: text; }

dialog {
  max-width: min(560px, calc(100vw - 32px));
  padding: 18px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}

dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h2 { margin: 0 0 4px; font-size: 15px; }
dialog .help { margin: 0 0 12px; color: var(--ink-2); font-size: 13px; }
dialog form { margin-top: 14px; text-align: right; }

/* In the formula's details each bet is its own capsule, so two ambi never read as one row. */
dialog .bets > div { gap: 6px 0; margin-bottom: 8px; }
dialog .bet { margin-right: 8px; padding: 3px; border: 1px solid var(--axis); border-radius: 999px; }

.matrix td { text-align: center; }
.matrix td.hit { background: var(--series-1); color: #fff; font-weight: 600; }
.matrix td.hit.iso { background: #104281; }

/* -------------------------------------------------------------------- misc */

.verdict {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.verdict::before { font-size: 13px; }
.verdict.ok { color: var(--good); }
.verdict.ok::before { content: "\2713"; }
.verdict.no { color: var(--critical); }
.verdict.no::before { content: "\2717"; }
.verdict.watch { color: var(--critical); }
.verdict.watch::before { content: "\26A0"; }

footer {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--hairline);
  color: var(--ink-muted);
  font-size: 12px;
}

.unavailable {
  padding: 14px;
  border: 1px dashed var(--axis);
  border-radius: var(--radius);
  color: var(--ink-2);
  font-size: 13px;
}

@media (max-width: 560px) {
  .filters { position: static; }
  .field { flex: 1 1 140px; }
  .field select { width: 100%; }
}
