:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #dddcd6;
  --grid: #e7e6e1;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #77766f;
  --accent: #2a78d6;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --good: #0ca30c; --warn: #fab219; --crit: #d03b3b; --none: #9a9992;
  --up: #006300; --down: #b42626;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #232321;
    --border: #383835; --grid: #2b2b29;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86; --accent: #3987e5;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --none: #6b6a64; --up: #4cc24c; --down: #f07575;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321;
  --border: #383835; --grid: #2b2b29;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86; --accent: #3987e5;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --none: #6b6a64; --up: #4cc24c; --down: #f07575;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.4rem; } h2 { font-size: 1.1rem; } h3 { font-size: .95rem; color: var(--text-2); font-weight: 600; }

.top {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  padding: .75rem 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; color: var(--text); }
.sub { color: var(--text-2); }
.spacer { flex: 1; }
.who { display: flex; gap: .5rem; align-items: center; color: var(--text-2); }

main { max-width: 1400px; margin: 0 auto; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.login { display: grid; place-items: center; min-height: 60vh; }
.login form, dialog form { display: grid; gap: .75rem; width: min(340px, 100%); }
label { display: grid; gap: .25rem; color: var(--text-2); font-size: .9rem; }
input, select, textarea, button {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: .45rem .6rem;
}
textarea { resize: vertical; min-height: 4.5rem; width: 100%; }
button { cursor: pointer; background: var(--accent); color: #fff; border-color: transparent; font-weight: 600; }
button.ghost { background: transparent; color: var(--text); border-color: var(--border); }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 500; }
button:disabled { opacity: .5; cursor: default; }
.err { color: var(--down); min-height: 1.2em; margin: 0; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
dialog { border: 0; padding: 0; background: transparent; }
dialog::backdrop { background: rgb(0 0 0 / .45); }
.muted { color: var(--muted); }
.note { color: var(--text-2); font-size: .85rem; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 0 0 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; min-width: 0; }
.tile .k { color: var(--text-2); font-size: .8rem; }
.tile .v { font-size: 1.5rem; font-weight: 700; margin-top: 2px; }
.tile .d { font-size: .8rem; margin-top: 2px; color: var(--muted); }
.up { color: var(--up); } .down { color: var(--down); }
.seg { display: flex; height: 8px; border-radius: 4px; overflow: hidden; margin: 8px 0 6px; gap: 2px; background: var(--surface); }
.seg span { display: block; height: 100%; }
.legend { display: flex; gap: .75rem; flex-wrap: wrap; font-size: .8rem; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* charts */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 12px; margin-bottom: 16px; }
.chart { min-width: 0; }
.chart svg { display: block; width: 100%; height: 220px; overflow: visible; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .pre { stroke-dasharray: 3 3; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart .empty { fill: var(--muted); font-size: 13px; }
.tip {
  position: fixed; z-index: 20; pointer-events: none; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: .8rem;
  box-shadow: 0 4px 16px rgb(0 0 0 / .18); max-width: 280px;
}
.tip .t { color: var(--text-2); margin-bottom: 4px; }
.tip .r { display: flex; gap: .5rem; justify-content: space-between; }
.tip .r i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; }

/* filters + table */
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.filters input[type=search] { flex: 1 1 200px; min-width: 0; }
.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: .85rem; }
th, td { padding: 6px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
th { position: sticky; top: 0; background: var(--surface-2); color: var(--text-2); font-weight: 600; cursor: pointer; user-select: none; }
th.nosort { cursor: default; }
th[aria-sort=ascending]::after { content: " ▲"; font-size: .7em; }
th[aria-sort=descending]::after { content: " ▼"; font-size: .7em; }
td.l, th.l { text-align: left; }
tbody tr:hover { background: var(--surface-2); }
tr.former td { color: var(--muted); }
td select { padding: .2rem .35rem; font-size: .8rem; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: .78rem; }
.pill i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.st-yes { --c: var(--good); } .st-maybe { --c: var(--warn); } .st-no { --c: var(--crit); } .st-unknown { --c: var(--none); }
.pill i, .swatch { background: var(--c); }
td select.st { border-left: 4px solid var(--c); }
.bar { display: inline-block; vertical-align: middle; width: 46px; height: 6px; background: var(--grid); border-radius: 3px; margin-left: 6px; overflow: hidden; }
.bar b { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.rank { color: var(--muted); font-size: .75rem; margin-left: 4px; }

/* player page */
.head { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-start; margin-bottom: 16px; }
.head .grow { flex: 1 1 260px; min-width: 0; }
.interest { flex: 1 1 320px; display: grid; gap: .5rem; }
.interest .opts { display: flex; gap: .4rem; flex-wrap: wrap; }
.interest .opts label { display: flex; gap: .35rem; align-items: center; border: 1px solid var(--border); border-radius: 6px; padding: .3rem .6rem; cursor: pointer; color: var(--text); }
.interest .opts input { margin: 0; }
.interest .opts label:has(input:checked) { border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c); }
.log { font-size: .8rem; color: var(--text-2); margin: 0; padding-left: 1rem; }
.section { margin: 20px 0 8px; }
.help { font-size: .82rem; color: var(--text-2); max-width: 80ch; }
.help summary { cursor: pointer; color: var(--accent); }

@media (max-width: 600px) {
  .tile .v { font-size: 1.25rem; }
  .chart svg { height: 190px; }
}
