/* Values from the dataviz reference palette; the mark pair below was run through validate_palette (light and
   dark: all checks pass, worst CVD dE 21.6 light / 19.2 dark). Dark tokens repeat under the media query (OS
   setting) and under [data-theme="dark"] (an explicit stamp), with :where() keeping the light stamp able to win. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --ghost: rgba(11, 11, 11, 0.045);
  --series-1: #2a78d6;  /* pick bar, win dot */
  --pos: #2a78d6;       /* vs expected above 0 */
  --neg: #e34948;       /* vs expected below 0 */
  --accent: #2a78d6;    /* focus ring */
  --critical: #d03b3b;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --ring: rgba(255, 255, 255, 0.10);
    --ghost: rgba(255, 255, 255, 0.06);
    --series-1: #3987e5;
    --pos: #3987e5;
    --neg: #e66767;
    --accent: #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --ring: rgba(255, 255, 255, 0.10);
  --ghost: rgba(255, 255, 255, 0.06);
  --series-1: #3987e5;
  --pos: #3987e5;
  --neg: #e66767;
  --accent: #3987e5;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 15px/1.45 var(--font); }
h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--muted); }

/* Header */
.top {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--grid);
}
.brand { font-weight: 650; letter-spacing: 0.01em; }
.top nav { display: flex; gap: 4px; margin-left: auto; }
.top nav a {
  display: inline-flex; align-items: center; min-height: 36px; padding: 0 12px; border-radius: 8px;
  color: var(--ink-2); text-decoration: none;
}
.top nav a:hover { background: var(--ghost); color: var(--ink); }
.top nav a[aria-current="page"] { background: var(--ghost); color: var(--ink); font-weight: 600; }

main { max-width: 1180px; margin: 0 auto; padding: 16px 16px 48px; }
#app > * { transition: opacity 0.15s ease; }
#app.is-loading > * { opacity: 0.5; }
.status { color: var(--muted); padding: 24px 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--ring);
  background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 550;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--ghost); }
.btn:disabled { cursor: progress; color: var(--muted); }
.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--page); }
.btn-primary:hover { background: var(--ink-2); }

/* Filter row: one row above everything it scopes, wrapping on phones */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 20px; }
.filter { display: flex; flex-direction: column; gap: 4px; min-width: 0; max-width: 100%; }
.filter-label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg-option {
  min-height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--ring);
  background: var(--surface); color: var(--ink-2); font-size: 14px; cursor: pointer; white-space: nowrap;
}
.seg-option:hover { background: var(--ghost); color: var(--ink); }
.seg-option[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--page); font-weight: 600; }
select {
  min-height: 36px; max-width: 100%; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--ring); background: var(--surface); font-size: 14px;
}
.filter-check { justify-content: flex-end; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--ink); }

/* Scope line */
.scope { margin: 14px 0 20px; display: grid; gap: 10px; }
.scope-line { font-size: 13px; color: var(--ink-2); }
.scope-line span { white-space: nowrap; }
.banner {
  padding: 10px 12px; border-radius: 8px; border: 1px solid var(--ring);
  background: var(--surface); font-size: 14px;
}

/* Errors and empty states */
.error {
  display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--ring); border-left: 4px solid var(--critical); background: var(--surface);
}
.error-icon {
  flex: none; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--critical); color: #fff; font-weight: 700; font-size: 14px;
}
.error-body { flex: 1 1 200px; min-width: 0; }
.error-title { font-weight: 600; }
.error-detail { margin-top: 2px; font-size: 13px; color: var(--ink-2); overflow-wrap: anywhere; }
.empty {
  display: grid; justify-items: center; gap: 8px; text-align: center;
  padding: 40px 16px; border: 1px solid var(--ring); border-radius: 12px; background: var(--surface);
  color: var(--ink-2);
}
.empty-title { font-weight: 600; color: var(--ink); }
.empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 8px; }

/* Stats groups */
/* Column layout follows each card's own width (container queries), so a half-width slot card gets the same
   stacked cells as a phone while the full-width weapons card prints values beside their marks. */
.group {
  container-type: inline-size;
  background: var(--surface); border: 1px solid var(--ring); border-radius: 12px;
  padding: 14px 16px 6px; min-width: 0;
}
.group-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 6px; }
.group-title { font-size: 16px; font-weight: 650; }
.group-note { font-size: 12px; color: var(--muted); }
.section-title { font-size: 16px; font-weight: 650; margin: 28px 0 12px; }
.slot-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
@media (min-width: 900px) { .slot-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.stats { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 14px; }
.stats th, .stats td { padding: 7px 6px; text-align: left; vertical-align: middle; border-top: 1px solid var(--grid); }
.stats thead th { border-top: 0; padding-top: 4px; font-size: 12px; font-weight: 600; color: var(--ink-2); vertical-align: bottom; }
.stats .c-name { width: 31%; padding-left: 0; }
.stats .c-metric { width: 23%; }
.stats .c-num { width: 8%; text-align: right; font-variant-numeric: tabular-nums; }
.stats .c-link { width: 40px; padding-right: 0; text-align: right; }
.stats .wide-only, .stats .key { display: none; }
@container (min-width: 640px) {
  .wide .wide-only { display: table-cell; }
  .wide .key { display: block; }
  .wide .counts { display: none; }
  .wide .c-name { width: 21%; }
  .wide .c-metric { width: 21%; }
  .wide .c-link { width: 92px; }
  .wide .replays-text { display: inline; }
  .wide .metric { grid-template-columns: minmax(40px, 1fr) auto; align-items: center; gap: 10px; }
  .wide .metric .value { order: 0; min-width: 4.2em; text-align: right; }
}

.sort {
  display: inline-flex; align-items: flex-end; gap: 2px; padding: 0; border: 0; background: none;
  font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.sort:hover { color: var(--ink); }
th[aria-sort] .sort { color: var(--ink); }
.sort-mark { min-width: 0.8em; }

.row:hover th, .row:hover td { background: var(--ghost); }
.row { cursor: pointer; }
.name-btn {
  display: grid; gap: 1px; width: 100%; padding: 0; border: 0; background: none;
  text-align: left; cursor: pointer; font: inherit; color: inherit;
}
.name { font-weight: 600; overflow-wrap: anywhere; }
.sub { font-size: 12px; font-weight: 400; color: var(--muted); overflow-wrap: anywhere; }
.is-low th, .is-low td { color: var(--ink-2); }
.is-low .name { font-weight: 500; }
.divider td { padding-top: 14px; font-size: 12px; color: var(--muted); }
.detail td { padding-top: 2px; padding-left: 0; border-top: 0; font-size: 13px; color: var(--ink-2); }
.none { color: var(--muted); }

.metric { display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px; }
.metric .value { order: -1; font-variant-numeric: tabular-nums; white-space: nowrap; }

.replays {
  display: inline-flex; align-items: center; justify-content: flex-end; gap: 4px;
  min-height: 32px; min-width: 32px; font-size: 13px; color: var(--ink-2); text-decoration: none;
}
.replays:hover { color: var(--ink); text-decoration: underline; }
.replays .icon { fill: currentColor; flex: none; }
.replays-text { display: none; }

/* Marks: thin, one hue per column, hairline references */
.mark { display: block; overflow: visible; }
.m-axis, .m-ref { stroke: var(--axis); stroke-width: 1; }
.m-pick { fill: var(--series-1); }
.m-ci { stroke: var(--series-1); stroke-width: 2; stroke-linecap: round; opacity: 0.4; }
.m-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.m-dot.is-hollow { fill: var(--surface); stroke: var(--series-1); stroke-width: 2; }
.m-pos { fill: var(--pos); }
.m-neg { fill: var(--neg); }
.m-cap { stroke: var(--surface); stroke-width: 2; }
.is-low .mark { opacity: 0.7; }

/* Weapon picker */
.picker { position: relative; width: min(100%, 380px); }
.picker-field {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px; min-height: 36px; padding: 3px;
  border: 1px solid var(--ring); border-radius: 8px; background: var(--surface);
}
.picker-field:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.picker-input {
  flex: 1 1 10ch; min-width: 10ch; min-height: 28px; padding: 0 6px;
  border: 0; background: none; font-size: 14px; outline: none;
}
.picker-input:disabled { cursor: not-allowed; }
.chip {
  display: inline-flex; align-items: center; gap: 2px; max-width: 100%;
  padding: 0 2px 0 10px; min-height: 28px; border-radius: 999px; background: var(--ghost);
  border: 1px solid var(--ring); font-size: 13px; font-weight: 600;
}
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-remove {
  display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%;
  background: none; color: var(--ink-2); font-size: 16px; line-height: 1; cursor: pointer;
}
.chip-remove:hover { background: var(--ghost); color: var(--ink); }
.picker-list {
  position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 280px; overflow-y: auto; margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--ring); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
}
.picker-option {
  display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px; border-radius: 6px;
  font-size: 14px; cursor: pointer;
}
.picker-option:hover { background: var(--ghost); }
.picker-option[aria-selected="true"] { background: var(--ghost); box-shadow: inset 2px 0 0 var(--accent); }
.picker-empty { padding: 8px 10px; font-size: 14px; color: var(--muted); }

/* Match log */
.matches { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.match {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px 16px;
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--ring); background: var(--surface);
}
.match:focus-visible { outline-offset: 1px; }
.match-head { font-size: 13px; color: var(--ink-2); }
.sides { display: grid; gap: 6px; min-width: 0; }
.side {
  display: grid; grid-template-columns: 1.4em 3.2em minmax(0, 1fr); align-items: baseline; gap: 0 6px;
}
.side-score { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; text-align: center; color: var(--ink-2); }
.side-result { font-size: 12px; font-weight: 700; }
.side.is-winner .side-score { color: var(--ink); }
.fighters { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; min-width: 0; }
.fighter { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; font-size: 14px; }
.rating { font-weight: 600; font-variant-numeric: tabular-nums; }
.rating-change { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.loadout { color: var(--ink-2); overflow-wrap: anywhere; }
.hit { color: var(--ink); font-weight: 650; }
.legs { font-size: 12px; color: var(--muted); }
.tag {
  display: inline-block; padding: 0 6px; border-radius: 4px; border: 1px solid var(--ring);
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em; color: var(--ink-2);
}
.replay { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.replay-code {
  padding: 4px 8px; border-radius: 6px; background: var(--ghost); border: 1px solid var(--ring);
  font: 600 15px/1.4 var(--mono); letter-spacing: 0.04em; user-select: all; -webkit-user-select: all;
}
.copy { min-width: 6.5em; }
.copy.is-done { border-color: var(--ink-2); }
.expires { flex-basis: 100%; font-size: 12px; color: var(--muted); }
.replay.is-expired { font-size: 13px; color: var(--muted); }
@media (min-width: 720px) {
  .match { grid-template-columns: minmax(0, 1fr) auto; }
  .match-head { grid-column: 1 / -1; }
  .replay { justify-content: flex-end; align-content: center; max-width: 260px; }
  .expires { text-align: right; }
}
.pager { display: grid; justify-items: center; gap: 6px; margin-top: 16px; }
.pager-status { font-size: 13px; color: var(--critical); }
.end { font-size: 13px; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  #app > * { transition: none; }
}
@media (forced-colors: active) {
  .m-pick, .m-dot, .m-pos, .m-neg { fill: CanvasText; }
  .m-ci { stroke: CanvasText; }
}
