:root {
  color-scheme: light;
  --bg: #f4f4f2; --surface-1: #fcfcfb; --surface-2: #f0efec; --line: #e3e2dd; --grid: #ebeae6;
  --text-primary: #0b0b0b; --text-secondary: #52514e; --text-muted: #7a7974;
  --series-1: #2a78d6; --series-2: #eb6834;
  --accent: #2a78d6; --bad: #d03b3b; --good: #0a7d0a;
  --seq-0: #f0efec; --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5; --seq-5: #256abf; --seq-6: #184f95;
  --r: 12px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121211; --surface-1: #1a1a19; --surface-2: #242422; --line: #2e2e2b; --grid: #2a2a27;
    --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8d8c84;
    --series-1: #3987e5; --series-2: #d95926; --accent: #3987e5; --bad: #e66767; --good: #3cc23c;
    --seq-0: #242422; --seq-1: #104281; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #256abf; --seq-5: #2a78d6; --seq-6: #5598e7;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text-primary); }
button, select, input { font: inherit; color: inherit; }
button { background: var(--surface-1); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
button:hover { border-color: var(--accent); }
select, input { background: var(--surface-1); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- login --- */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--surface-1); border: 1px solid var(--line); border-radius: 16px; padding: 28px; width: min(360px, 100%);
  display: flex; flex-direction: column; gap: 10px; }
.login-card h1 { margin: 0 0 8px; font-size: 22px; }
.login-card label { font-size: 13px; color: var(--text-secondary); }
.login-card button { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; padding: 9px; }
.login-err { color: var(--bad); min-height: 1.2em; margin: 0; font-size: 14px; }
.brand span, .login-card h1 span { color: var(--accent); }

/* --- layout --- */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface-1); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; font-size: 17px; color: var(--text-primary); text-decoration: none; margin-right: 6px; }
.grow { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; border-radius: 0; padding: 6px 12px; }
.seg button.on { background: var(--accent); color: #fff; }
main { padding: 20px; max-width: 1280px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
h2 { font-size: 15px; margin: 0 0 4px; }
.sub { color: var(--text-muted); font-size: 12.5px; margin: 0 0 12px; }
.card { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); gap: 16px; }
@media (max-width: 520px) { main { padding: 12px; } .top { padding: 10px 12px; } .card { padding: 14px; } }
html, body { overflow-x: hidden; }
.empty { color: var(--text-muted); text-align: center; padding: 40px 10px; }
.err { color: var(--bad); }

/* --- stat tiles --- */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 760px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } .tile .v { font-size: 22px; } }
.tile { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.tile .k { font-size: 12.5px; color: var(--text-secondary); }
.tile .v { font-size: 26px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .h { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* --- games list --- */
.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.game { cursor: pointer; text-align: left; padding: 16px; }
.game .n { font-weight: 700; font-size: 16px; margin-bottom: 8px; }
.game .row { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-secondary); padding: 2px 0; }
.game .row b { color: var(--text-primary); font-variant-numeric: tabular-nums; }

/* --- charts --- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis { fill: var(--text-muted); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--line); stroke-width: 1; }
.chart .hair { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .dlabel { font-size: 11.5px; fill: var(--text-secondary); font-weight: 600; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-secondary); margin-bottom: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.legend i.s1 { background: var(--series-1); } .legend i.s2 { background: var(--series-2); }
.tip { position: fixed; z-index: 20; pointer-events: none; background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 12.5px; box-shadow: 0 4px 16px rgba(0,0,0,.18);
  display: none; min-width: 120px; }
.tip .t { color: var(--text-muted); font-size: 11.5px; margin-bottom: 3px; }
.tip .r { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tip .r span { color: var(--text-secondary); }
.tip .sw { width: 10px; height: 3px; border-radius: 2px; display: inline-block; margin-right: 6px; }

/* --- tables --- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; color: var(--text-secondary); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 6px 8px; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
.tbl td.num, .tbl th.num { text-align: right; }
.scroll { overflow-x: auto; }
.heat td.cell { text-align: center; border: 2px solid var(--surface-1); border-radius: 4px; min-width: 52px; }
.heat td.na { color: var(--text-muted); }
.heat td.dark { color: #fff; }
.mono { font-family: Consolas, "SF Mono", monospace; font-size: 12px; word-break: break-all; }

/* --- funnel --- */
.funnel { display: flex; flex-direction: column; gap: 8px; }
.fstep { display: grid; grid-template-columns: 150px 1fr 110px; gap: 10px; align-items: center; font-size: 13px; }
.fstep .lab { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); }
.fstep .track { height: 22px; background: var(--surface-2); border-radius: 4px; position: relative; overflow: hidden; }
.fstep .bar { height: 100%; border-radius: 0 4px 4px 0; background: var(--series-1); }
.fstep .val { text-align: right; font-variant-numeric: tabular-nums; }
.fstep .drop { color: var(--bad); font-size: 11.5px; margin-left: 6px; }
.fedit { display: flex; gap: 8px; margin-top: 12px; }
.fedit input { flex: 1; min-width: 0; }
@media (max-width: 520px) { .fstep { grid-template-columns: 90px 1fr 80px; } }
