:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --surface-2: #efefec;
  --border: #deddd8;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #dbe8f8;
  --win: #1f7a3d;
  --loss: #b3261e;
  --draw: #8a6d00;
  --grid: #e7e6e2;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #242423; --border: #34332f;
    --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e86;
    --accent: #3987e5; --accent-ink: #ffffff; --accent-soft: #1d3350;
    --win: #5cc27e; --loss: #f07a72; --draw: #e0bb4a; --grid: #2c2c2a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #242423; --border: #34332f;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e86;
  --accent: #3987e5; --accent-ink: #ffffff; --accent-soft: #1d3350;
  --win: #5cc27e; --loss: #f07a72; --draw: #e0bb4a; --grid: #2c2c2a;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }

.top {
  display: flex; align-items: center; gap: 16px; padding: 12px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--accent); }
.brand h1 { font-size: 17px; margin: 0; color: var(--text); letter-spacing: -.01em; }
.comp { margin-left: auto; display: flex; gap: 8px; align-items: center; color: var(--text-2); }
.comp select { max-width: 280px; }

select, input[type=search], input[type=number], input:not([type]) {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 8px; min-height: 34px;
}
select:focus, input:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button { cursor: pointer; border-radius: 8px; padding: 6px 12px; min-height: 34px; border: 1px solid var(--border); background: var(--surface); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:disabled { opacity: .55; cursor: default; }
button.ghost { background: transparent; }
button.ghost:hover { background: var(--surface-2); }

.filters {
  display: flex; flex-wrap: wrap; gap: 14px 22px; padding: 14px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field.check { flex-direction: row; align-items: center; gap: 6px; align-self: flex-end; min-height: 34px; color: var(--text-2); }
.lbl { font-size: 12px; color: var(--text-2); font-weight: 600; }
.row { display: flex; gap: 6px; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 4px 11px; min-height: 30px; font-size: 13px; color: var(--text-2);
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); font-weight: 600; }

.coverage {
  display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; align-items: center;
  margin: 12px 16px 0; padding: 10px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.cov-actions { display: flex; gap: 6px; }
.progress { grid-column: 1 / -1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.cov-log { grid-column: 1 / -1; font-size: 12px; }
.cov-log:empty { display: none; }
.warn { color: var(--draw); font-weight: 600; }
.note { font-size: 12px; margin-top: 2px; }

.tabs { display: flex; gap: 2px; padding: 14px 16px 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button {
  border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none;
  padding: 8px 14px; color: var(--text-2); font-weight: 600; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 12px 16px 40px; }
.table-tools { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.table-tools input { min-width: 220px; }
.table-tools .ghost { margin-left: auto; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
th:first-child, td:first-child, th.l, td.l { text-align: left; }
thead th {
  position: sticky; top: 0; background: var(--surface); font-size: 12px; color: var(--text-2);
  font-weight: 600; cursor: pointer; user-select: none; border-bottom: 1px solid var(--border);
}
thead th[aria-sort] { color: var(--text); }
thead th[aria-sort="descending"]::after { content: " ↓"; }
thead th[aria-sort="ascending"]::after { content: " ↑"; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.wrap { white-space: normal; min-width: 180px; color: var(--text-2); font-size: 13px; }
.link { color: var(--text); background: none; border: 0; padding: 0; min-height: 0; font-weight: 600; text-align: left; }
.link:hover { color: var(--accent); text-decoration: underline; }
.rank { color: var(--muted); width: 1%; }

.pct { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; }
.pct .track { display: block; width: 60px; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.pct .fill { display: block; height: 100%; background: var(--accent); border-radius: 0 3px 3px 0; }
.res { font-weight: 700; }
.res.W { color: var(--win); } .res.L { color: var(--loss); } .res.D { color: var(--draw); }
.pos { color: var(--win); } .neg { color: var(--loss); }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--text-2); }

.empty { padding: 36px 16px; text-align: center; color: var(--muted); }

.teampick {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px; min-height: 34px; min-width: 220px; max-width: 460px;
  padding: 2px 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
.teampick:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.teampick.picker input { width: auto; border: 0; min-height: 28px; flex: 1; min-width: 120px; padding: 2px 4px; background: transparent; }
.teampick input:focus { outline: none; }
.teamchips { display: contents; }
.chip.on { display: inline-flex; align-items: center; gap: 2px; padding: 2px 4px 2px 10px; min-height: 26px;
  background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.chip .x { border: 0; background: none; min-height: 0; padding: 0 5px; font-size: 15px; line-height: 1; color: var(--text-2); }
.chip .x:hover { color: var(--text); }

/* drawer */
.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / .35); z-index: 9; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(880px, 100vw); z-index: 10;
  background: var(--bg); border-left: 1px solid var(--border); overflow-y: auto;
  box-shadow: -8px 0 30px rgb(0 0 0 / .15);
}
.drawer-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 2;
}
.drawer-head h2 { margin: 0; font-size: 20px; }
#dBody { padding: 16px; display: flex; flex-direction: column; gap: 18px; }
#dBody h3, #h2hOut section h3 { font-size: 13px; margin: 0 0 8px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.tile .k { font-size: 12px; color: var(--text-2); }
.tile .v { font-size: 22px; font-weight: 650; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.tile .s { font-size: 12px; color: var(--muted); }

.chart { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .gridline { stroke: var(--grid); }
.chart .bar { fill: var(--accent); }
.chart .bar:hover, .chart .hit:hover + .bar { opacity: .8; }
.chart .val { fill: var(--text-2); font-size: 11px; }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; font-size: 12px;
  box-shadow: 0 4px 16px rgb(0 0 0 / .15); max-width: 260px;
}
.tooltip b { font-weight: 650; }

.h2h-pick { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.picker { position: relative; }
.picker input { width: 260px; }
.suggest {
  position: absolute; top: 100%; left: 0; right: 0; margin: 2px 0 0; padding: 4px 0; list-style: none; z-index: 4;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; max-height: 260px; overflow-y: auto;
}
.suggest:empty { display: none; }
.suggest li { padding: 6px 10px; cursor: pointer; }
.suggest li:hover, .suggest li.on { background: var(--surface-2); }
#h2hOut { display: flex; flex-direction: column; gap: 0; }
.h2h-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 18px; }
.h2h-grid h3 { font-size: 13px; margin: 0 0 8px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }

@media (max-width: 700px) {
  .top { flex-wrap: wrap; }
  #themeToggle { margin-left: auto; }
  .comp { order: 3; margin-left: 0; width: 100%; }
  .comp select { flex: 1; min-width: 0; max-width: none; }
  .coverage { grid-template-columns: 1fr; }
  .h2h-grid { grid-template-columns: 1fr; }
  .picker, .picker input { width: 100%; }
  .table-tools input { min-width: 0; flex: 1; }
}

/* login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); display: flex; flex-direction: column; gap: 10px; padding: 24px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.login-card .brand { margin-bottom: 8px; }
.login-card .err { margin: 0; color: var(--loss); font-size: 13px; }
.role { font-size: 12px; color: var(--text-2); }
