:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --surface: #fcfcfb;
  --surface-2: #f0eee8;
  --border: #e2dfd6;
  --grid: #e8e6df;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7872;
  --accent: #c8102e;
  --accent-ink: #a00d25;
  --link: #1d5fb0;
  --series-1: #2a78d6;
  --good: #0b7a3e;
  --chip: #ece9e1;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #222220;
    --border: #2f2e2b;
    --grid: #2a2927;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #96948c;
    --accent: #ef4a5f;
    --accent-ink: #ff7385;
    --link: #7fb2f0;
    --series-1: #3987e5;
    --good: #4cc47e;
    --chip: #2a2927;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #222220; --border: #2f2e2b; --grid: #2a2927;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #96948c; --accent: #ef4a5f; --accent-ink: #ff7385;
  --link: #7fb2f0; --series-1: #3987e5; --good: #4cc47e; --chip: #2a2927; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 28px; letter-spacing: -.01em; }
h2 { font-size: 18px; margin: 28px 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ------------------------------------------------ top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 10px 16px; display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.brand { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 17px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand b { color: var(--accent); }
.brand svg { width: 26px; height: 26px; fill: none; stroke: var(--accent); stroke-width: 2; }
.nav { display: flex; gap: 2px; flex-wrap: wrap; }
.nav a { color: var(--text-2); padding: 6px 10px; border-radius: 8px; font-size: 14px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--chip); font-weight: 600; }
.nav a.soon::after { content: "soon"; font-size: 10px; margin-left: 5px; padding: 1px 5px; border-radius: 6px; background: var(--chip); color: var(--muted); vertical-align: 1px; }
.search { margin-left: auto; position: relative; flex: 0 1 300px; min-width: 200px; }
.search input { width: 100%; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit; }
.search input:focus { outline: 2px solid var(--series-1); outline-offset: -1px; }
.search-pop { position: absolute; top: calc(100% + 6px); right: 0; width: min(420px, 92vw); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,.15); max-height: 70vh; overflow: auto; padding: 6px; }
.search-pop .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px 10px 4px; }
.search-pop a { display: flex; justify-content: space-between; gap: 10px; padding: 7px 10px; border-radius: 6px; color: var(--text); }
.search-pop a:hover, .search-pop a.sel { background: var(--surface-2); text-decoration: none; }
.search-pop .meta { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* ------------------------------------------------ layout */
.page { max-width: 1280px; margin: 0 auto; padding: 24px 16px 40px; min-height: 70vh; }
.footer { max-width: 1280px; margin: 0 auto; padding: 16px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--border); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.sub { color: var(--text-2); margin-top: 6px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.chip { font-size: 12px; padding: 3px 9px; border-radius: 20px; background: var(--chip); color: var(--text-2); }
.chip.gold { background: #f6e7b0; color: #5d4500; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip.gold { background: #4a3b0c; color: #f2d77a; } }
:root[data-theme="dark"] .chip.gold { background: #4a3b0c; color: #f2d77a; }

/* hero */
.hero { padding: 36px 0 18px; }
.hero h1 { font-size: 38px; }
.hero p { color: var(--text-2); max-width: 680px; font-size: 17px; }
.hero-search { margin-top: 18px; max-width: 640px; position: relative; }
.hero-search input { width: 100%; font: inherit; font-size: 18px; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.hero-search input:focus { outline: 2px solid var(--series-1); outline-offset: -1px; }
.hero-search .search-pop { left: 0; right: auto; width: 100%; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin: 18px 0 6px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.tile .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.tile .v { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }

/* tabs & controls */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 24px 0 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; font: inherit; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
select, input[type=number], button.btn {
  font: inherit; font-size: 14px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
button.btn { cursor: pointer; background: var(--accent); color: #fff; border-color: transparent; font-weight: 600; }
button.btn.ghost { background: var(--surface); color: var(--text); border-color: var(--border); font-weight: 500; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); color: var(--text-2); padding: 7px 12px; font: inherit; font-size: 14px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--chip); color: var(--text); font-weight: 600; }
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field input[type=number] { width: 100px; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.stats { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 13.5px; }
table.stats th, table.stats td { padding: 6px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
table.stats th { position: sticky; top: 0; background: var(--surface-2); color: var(--text-2); font-weight: 600; font-size: 12px; cursor: pointer; user-select: none; }
table.stats th.sorted::after { content: " ▾"; }
table.stats th.sorted.asc::after { content: " ▴"; }
table.stats th.nosort { cursor: default; }
table.stats .l { text-align: left; }
table.stats tbody tr:hover { background: var(--surface-2); }
table.stats tfoot td { font-weight: 650; background: var(--surface-2); border-top: 1px solid var(--border); }
table.stats td.hl { font-weight: 650; }
table.stats tr.dim td { color: var(--muted); }
.rank { color: var(--muted); width: 1%; }
.flag { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--chip); color: var(--text-2); margin-left: 6px; }

/* leaders cards */
.leader-card ol { margin: 0; padding: 0; list-style: none; }
.leader-card li { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
.leader-card li:last-child { border-bottom: 0; }
.leader-card li b { font-weight: 650; }
.leader-card li:first-child b { color: var(--accent-ink); }

/* standings */
.grid.standings { grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); }
.standings table.stats td:first-child, .standings table.stats th:first-child { text-align: left; }

/* chart */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .ref { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .cross { stroke: var(--text-2); stroke-width: 1; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.12); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tip .k { color: var(--muted); font-size: 12px; }

.empty { padding: 30px; text-align: center; color: var(--muted); }
.soon-page { max-width: 720px; }
.soon-page ul { color: var(--text-2); }
.err { color: var(--accent-ink); }

@media (max-width: 640px) {
  h1 { font-size: 23px; }
  .hero h1 { font-size: 28px; }
  .search { flex-basis: 100%; margin-left: 0; }
  .topbar-inner { gap: 8px; }
  .topbar { position: static; }
  .grid.standings { grid-template-columns: 1fr; }
}
.standings table.stats th, .standings table.stats td { padding: 6px 8px; }

/* model pages */
.flag.ol-strong { background: #dcefe3; color: #0b5a2e; }
.flag.ol-weak { background: #f7dfdc; color: #8a1f12; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .flag.ol-strong { background: #173a25; color: #8fdcac; } :root:not([data-theme="light"]) .flag.ol-weak { background: #45201b; color: #f2a79c; } }
:root[data-theme="dark"] .flag.ol-strong { background: #173a25; color: #8fdcac; }
:root[data-theme="dark"] .flag.ol-weak { background: #45201b; color: #f2a79c; }
.tile .small { margin-top: 2px; }
pre.code { background: var(--surface-2); padding: 10px 12px; border-radius: 8px; font-family: var(--mono); font-size: 13px; }
code { font-family: var(--mono); font-size: 0.92em; }
