:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #efeeeb;
  --border: #e0dfda;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7d7c76;
  --grid: #e7e6e2;
  --blue: #2a78d6;
  --orange: #eb6834;
  --accent: #6250d6;
  --good: #1f7a33;
  --bad: #c03a39;
  --shadow: 0 1px 2px rgb(0 0 0 / 5%), 0 4px 16px rgb(0 0 0 / 4%);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #242422;
    --border: #2f2f2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --grid: #2b2b28;
    --blue: #3987e5;
    --orange: #d95926;
    --accent: #9085e9;
    --good: #4fb366;
    --bad: #e66767;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --surface: #1a1a19;
  --surface-2: #242422;
  --border: #2f2f2c;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #8f8e86;
  --grid: #2b2b28;
  --blue: #3987e5;
  --orange: #d95926;
  --accent: #9085e9;
  --good: #4fb366;
  --bad: #e66767;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 26px; letter-spacing: -0.01em; }
h2 { font-size: 16px; }
h3 { font-size: 13px; color: var(--text-2); font-weight: 600; }
.num, td.n, th.n { font-variant-numeric: tabular-nums; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, var(--blue) 50%, var(--orange) 50%); }
.nav { display: flex; gap: 4px; overflow-x: auto; min-width: 0; scrollbar-width: none; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--text-2); white-space: nowrap; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .btn { flex-shrink: 0; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); font-weight: 600; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--text); color: var(--surface); border-color: var(--text); }
.btn.primary:hover { opacity: 0.88; }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.sub { color: var(--text-2); }
.muted { color: var(--muted); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head p { margin: 4px 0 0; color: var(--text-2); font-size: 13px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid-2 > .card { margin-bottom: 0; }
.stack { display: grid; gap: 20px; margin-bottom: 20px; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { color: var(--text-2); font-size: 12px; }
.tile .value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .hint { color: var(--muted); font-size: 12px; }

/* Hero / upload */
.hero { display: grid; grid-template-columns: 1.1fr 1fr; gap: 24px; align-items: stretch; margin-bottom: 20px; }
.hero h1 { font-size: 34px; margin-bottom: 12px; }
.hero p { color: var(--text-2); font-size: 15px; margin: 0 0 16px; max-width: 52ch; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center;
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 32px 20px; background: var(--surface);
  min-height: 200px; cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--surface-2); }
.dropzone strong { font-size: 16px; }
.dropzone code { font-size: 12px; background: var(--surface-2); padding: 2px 6px; border-radius: 4px; word-break: break-all; }
.drop-overlay {
  position: fixed; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(2px);
  font-size: 20px; font-weight: 700;
}
.drop-overlay.show { display: flex; }
.drop-overlay div { border: 2px dashed var(--accent); border-radius: 16px; padding: 48px 64px; background: var(--surface); }

.upload-panel {
  position: fixed; right: 16px; bottom: 16px; z-index: 40; width: min(380px, calc(100vw - 32px));
  max-height: 50vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 32px rgb(0 0 0 / 18%);
}
.upload-panel header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.upload-panel header button { border: 0; background: none; color: var(--text-2); font-size: 18px; line-height: 1; padding: 4px; }
.upload-panel ul { list-style: none; margin: 0; padding: 8px 0; }
.upload-panel li { padding: 6px 16px; display: grid; gap: 2px; }
.upload-panel .fname { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-added { color: var(--good); }
.status-error { color: var(--bad); }
.status-duplicate { color: var(--text-2); }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--text-2); }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sorted::after { content: " ▾"; }
td.n, th.n { text-align: right; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.team-row td { font-size: 12px; font-weight: 700; color: var(--text-2); background: var(--surface-2); border-bottom: 0; }
tr.focus td { background: color-mix(in srgb, var(--accent) 10%, transparent); }
tbody tr:last-child td { border-bottom: 0; }

.bar-cell { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.bar-cell .num { width: 38px; text-align: right; font-weight: 600; }
.bar-track { flex: 1; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; min-width: 60px; }
.bar-track i { display: block; height: 100%; border-radius: 4px; }

.team-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.t0 { color: var(--blue); }
.t1 { color: var(--orange); }
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 700; background: var(--surface-2); color: var(--text-2); vertical-align: 1px;
}
.badge.best { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--text); }
.result { font-weight: 700; }
.result.win { color: var(--good); }
.result.loss { color: var(--bad); }

/* Match list */
.match-list { display: grid; }
.match-item {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; align-items: center;
  padding: 12px 8px; border-bottom: 1px solid var(--grid); border-radius: 8px;
}
.match-item:last-child { border-bottom: 0; }
.match-item:hover { background: var(--surface-2); text-decoration: none; }
.match-item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match-item .meta { color: var(--text-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scoreline { font-weight: 800; font-size: 16px; font-variant-numeric: tabular-nums; text-align: right; }
.scoreline .dash { color: var(--muted); margin: 0 4px; font-weight: 400; }

/* Match header */
.match-head { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 16px; }
.big-score { display: flex; align-items: center; gap: 20px; font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; }
.big-score .side { display: grid; justify-items: center; line-height: 1; }
.big-score .side small { font-size: 12px; font-weight: 600; margin-top: 6px; }
.big-score .dash { color: var(--muted); font-weight: 300; }
.best-callout { justify-self: end; text-align: right; }
.best-callout .who { font-size: 18px; font-weight: 700; }
.leaders { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--grid); }
.leader { padding: 6px 12px; border-radius: 8px; background: var(--surface-2); font-size: 13px; }
.leader b { font-variant-numeric: tabular-nums; }

/* Tabs and chips */
.tabs { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 3px; gap: 2px; }
.tabs button { border: 0; background: none; padding: 5px 12px; border-radius: 6px; color: var(--text-2); font-weight: 600; font-size: 13px; }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / 10%); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 4px 12px; font-size: 13px; }
.chip.active { border-color: var(--text); font-weight: 600; }
select { font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; }

/* Charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; overflow: visible; }
.axis text { fill: var(--muted); font-size: 11px; }
.axis line, .gridline { stroke: var(--grid); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-2); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 4px; border-radius: 2px; display: inline-block; }
.heatmap canvas { display: block; width: 100%; border-radius: 8px; }
.focus-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 24px; }
.splits { display: grid; gap: 14px; }
.split .split-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.split .split-bar { display: flex; gap: 2px; height: 12px; }
.split .split-bar i { display: block; height: 100%; }
.split .split-bar i:first-child { border-radius: 4px 0 0 4px; }
.split .split-bar i:last-child { border-radius: 0 4px 4px 0; }
.split .split-legend { display: flex; gap: 12px; font-size: 12px; color: var(--text-2); margin-top: 4px; flex-wrap: wrap; }
.split .split-legend span { display: inline-flex; align-items: center; gap: 4px; }
.split .split-legend i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

.breakdown { display: grid; gap: 16px; }
.breakdown h3 { margin-bottom: 6px; display: flex; justify-content: space-between; }
.breakdown .row { display: grid; grid-template-columns: minmax(0, 1fr) 70px 110px; gap: 10px; align-items: center; font-size: 13px; padding: 3px 0; }
.breakdown .row .val { text-align: right; color: var(--text-2); font-variant-numeric: tabular-nums; }

.compare-row { display: grid; grid-template-columns: 80px minmax(0, 1fr) 44px; gap: 12px; align-items: center; padding: 6px 0; }
.compare-track { position: relative; height: 12px; background: var(--surface-2); border-radius: 4px; }
.compare-track .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--accent); }
.compare-track .avg { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--text); border-radius: 1px; box-shadow: 0 0 0 2px var(--surface); }
.insight { margin: 12px 0 0; color: var(--text-2); }

.tip {
  position: fixed; z-index: 100; pointer-events: none; display: none;
  background: var(--text); color: var(--surface); padding: 8px 10px; border-radius: 8px;
  font-size: 12px; line-height: 1.45; max-width: 260px; box-shadow: 0 4px 16px rgb(0 0 0 / 20%);
}
.tip b { font-weight: 700; }
.empty { text-align: center; padding: 48px 16px; color: var(--text-2); }
.loading { padding: 64px; text-align: center; color: var(--muted); }
.error { padding: 16px; border-radius: 8px; background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
.pager { display: flex; justify-content: center; gap: 8px; margin-top: 16px; align-items: center; }
.model-cat { margin-bottom: 20px; }
.model-cat table td:first-child { white-space: normal; }

@media (max-width: 900px) {
  .hero, .grid-2, .focus-grid { grid-template-columns: 1fr; }
  .match-head { grid-template-columns: 1fr; justify-items: start; }
  .best-callout { justify-self: start; text-align: left; }
}
@media (max-width: 640px) {
  main { padding: 16px; }
  .topbar { padding: 0 16px; gap: 12px; }
  .brand span { display: none; }
  .topbar .btn span { display: none; }
  .card { padding: 16px; }
  .big-score { font-size: 34px; }
  .hero h1 { font-size: 26px; }
}

/* Leaderboard filters */
.filters { display: grid; gap: 16px; }
.filter-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.filter-hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.picker {
  position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  min-height: 42px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: text;
}
.picker:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.picked { display: contents; }
.pick {
  display: inline-flex; align-items: center; gap: 2px; padding: 2px 4px 2px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 16%, transparent); font-size: 13px; font-weight: 600;
}
.pick button { border: 0; background: none; color: var(--text-2); font-size: 16px; line-height: 1; padding: 0 6px; border-radius: 999px; }
.pick button:hover { color: var(--text); background: color-mix(in srgb, var(--accent) 20%, transparent); }
.picker input { flex: 1; min-width: 160px; border: 0; outline: 0; background: none; font: inherit; color: inherit; padding: 4px; }
.picker-list {
  position: absolute; left: -1px; right: -1px; top: calc(100% + 4px); z-index: 20; list-style: none; margin: 0; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgb(0 0 0 / 16%);
}
.picker-list li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.picker-list li.active, .picker-list li:hover { background: var(--surface-2); }
.picker-list li span { font-size: 12px; white-space: nowrap; }
.filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; color: var(--text-2); }
.filter-row label { display: inline-flex; align-items: center; gap: 8px; }
.filter-row .spacer { flex: 1; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.check:has(input:disabled) { opacity: 0.5; }
.select-cell { width: 28px; padding-right: 0; }
.select-cell input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
