:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #006300;
  --warn: #b26a00;
  --bad: #d03b3b;
  --mythic: #ff8000;
  --heroic: #a335ee;
  --normal: #0070dd;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242423;
    --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5; --good: #0ca30c; --warn: #fab219; --bad: #e66767;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242423;
  --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5; --good: #0ca30c; --warn: #fab219; --bad: #e66767;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; color: var(--ink-2); }
small, .muted { color: var(--muted); }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9em; }
pre { background: var(--surface-2); padding: .75rem; border-radius: 8px; overflow-x: auto; }

.topbar { display: flex; align-items: center; gap: 1.25rem; padding: .75rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: .5rem; color: var(--ink); }
.brand .faction { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.nav a { padding: .35rem .7rem; border-radius: 6px; color: var(--ink-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent); color: var(--accent-ink); }
.topbar .spacer { flex: 1; }
.team-seg { font-size: .8rem; }
.team-seg a { padding: .25rem .6rem; }
.topbar .sync { font-size: .8rem; color: var(--muted); }
.theme-btn { background: none; border: 1px solid var(--border); color: var(--ink-2); border-radius: 6px; padding: .25rem .5rem; cursor: pointer; }

main { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.filters select, .filters input, select.control { background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 6px; padding: .4rem .6rem; font: inherit; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg a { padding: .35rem .75rem; color: var(--ink-2); border-right: 1px solid var(--border); }
.seg a:last-child { border-right: 0; }
.seg a.active { background: var(--surface-2); color: var(--ink); font-weight: 600; text-decoration: none; }

.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.15rem; min-width: 0; }
.card h2 { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.card h2 .tools { font-size: .75rem; font-weight: 500; }
.card h2 .tools button { background: none; border: 1px solid var(--border); border-radius: 5px; color: var(--ink-2); padding: .1rem .5rem; cursor: pointer; font: inherit; font-size: .75rem; }
.card h2 .tools button:hover { background: var(--surface-2); }

.tiles { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 1.25rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .9rem 1rem; }
.tile .label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.tile .value { font-size: 1.9rem; font-weight: 650; line-height: 1.15; margin: .15rem 0; }
.tile .value.small { font-size: 1.25rem; }
.tile .sub { font-size: .8rem; color: var(--ink-2); }
.tile.hero .value { font-size: 2.6rem; }

.chart-wrap { position: relative; width: 100%; min-height: 260px; }
.chart-wrap canvas { width: 100% !important; }
.chart-note { font-size: .8rem; color: var(--muted); margin-top: .4rem; }
.table-view { display: none; overflow-x: auto; }
.table-view.show { display: block; }
.chart-wrap.hidden { display: none; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.home td { background: color-mix(in srgb, var(--accent) 12%, transparent); font-weight: 600; }
tr.rival td { background: color-mix(in srgb, var(--s2) 8%, transparent); }
tr.killed td:first-child::before { content: "✓ "; color: var(--good); }
.table-scroll { overflow-x: auto; }
.pill { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; border: 1px solid var(--border); color: var(--ink-2); }
.pill.mythic { color: var(--mythic); border-color: color-mix(in srgb, var(--mythic) 50%, transparent); }
.pill.heroic { color: var(--heroic); border-color: color-mix(in srgb, var(--heroic) 50%, transparent); }
.pill.normal { color: var(--normal); border-color: color-mix(in srgb, var(--normal) 50%, transparent); }
.pill.good { color: var(--good); }
.pill.bad { color: var(--bad); }
.progress { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

.btn { display: inline-block; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; padding: .5rem .9rem; font: inherit; font-weight: 600; cursor: pointer; }
.btn.secondary { background: var(--surface-2); color: var(--ink); border: 1px solid var(--border); }
.btn:disabled { opacity: .5; cursor: default; }

/* Ask */
.ask-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 1rem; }
@media (max-width: 900px) { .ask-layout { grid-template-columns: 1fr; } }
.chat { display: flex; flex-direction: column; gap: 1rem; }
.msg { border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.15rem; background: var(--surface); }
.msg.q { background: var(--surface-2); border-color: transparent; font-weight: 600; }
.msg .meta { font-size: .75rem; color: var(--muted); margin-top: .5rem; display: flex; gap: 1rem; flex-wrap: wrap; }
.msg .answer table { margin: .5rem 0; width: auto; min-width: 50%; }
.msg .answer th, .msg .answer td { padding: .3rem .6rem; }
.msg details { margin-top: .5rem; }
.msg details summary { cursor: pointer; color: var(--muted); font-size: .8rem; }
.trace { font-size: .78rem; margin: .5rem 0 0; }
.trace li { margin-bottom: .3rem; }
.trace pre { margin: .2rem 0 0; max-height: 160px; overflow: auto; font-size: .75rem; }
.ask-form { display: flex; gap: .5rem; align-items: flex-end; position: sticky; bottom: 0; background: var(--page); padding: .75rem 0; }
.ask-form textarea { flex: 1; min-height: 56px; resize: vertical; background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 10px; padding: .6rem .8rem; font: inherit; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { background: var(--surface); border: 1px solid var(--border); color: var(--ink-2); border-radius: 999px; padding: .3rem .75rem; font-size: .8rem; cursor: pointer; text-align: left; }
.chip:hover { background: var(--surface-2); color: var(--ink); }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--grid); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: .4rem; }
@keyframes spin { to { transform: rotate(360deg); } }
.error { color: var(--bad); }
.log { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .78rem; background: var(--surface-2); border-radius: 8px; padding: .6rem .8rem; max-height: 320px; overflow: auto; white-space: pre-wrap; }
.steps { counter-reset: step; }
.steps li { margin-bottom: .5rem; }
footer { text-align: center; color: var(--muted); font-size: .75rem; padding: 2rem 1rem; }
