:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --good: #0ca30c;
  --good-text: #006300;
  --bad: #d03b3b;
  --warn: #fab219;
  --c-ironclad: #eb6834;
  --c-silent: #1baf7a;
  --c-defect: #2a78d6;
  --c-regent: #eda100;
  --c-necrobinder: #e87ba4;
  --t-monster: #898781;
  --t-elite: #eb6834;
  --t-boss: #e34948;
  --t-rest: #1baf7a;
  --t-shop: #eda100;
  --t-event: #6250d6;
  --t-treasure: #e87ba4;
  --t-ancient: #2a78d6;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-wash: rgba(57, 135, 229, 0.14);
    --good-text: #0ca30c;
    --c-ironclad: #d95926;
    --c-silent: #199e70;
    --c-defect: #3987e5;
    --c-regent: #c98500;
    --c-necrobinder: #d55181;
    --t-elite: #d95926;
    --t-boss: #e66767;
    --t-rest: #199e70;
    --t-shop: #c98500;
    --t-event: #9085e9;
    --t-treasure: #d55181;
    --t-ancient: #3987e5;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-wash: rgba(57, 135, 229, 0.14);
  --good-text: #0ca30c;
  --c-ironclad: #d95926;
  --c-silent: #199e70;
  --c-defect: #3987e5;
  --c-regent: #c98500;
  --c-necrobinder: #d55181;
  --t-elite: #d95926;
  --t-boss: #e66767;
  --t-rest: #199e70;
  --t-shop: #c98500;
  --t-event: #9085e9;
  --t-treasure: #d55181;
  --t-ancient: #3987e5;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font-size: 15px; line-height: 1.5; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h2 { font-size: 1.05rem; font-weight: 600; }
h3 { font-size: 0.95rem; font-weight: 600; }
small, .small { font-size: 0.82rem; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
code, kbd { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.88em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; border: 1px solid var(--border); }
kbd { box-shadow: inset 0 -1px 0 var(--border); }

/* ---- Header & nav ---- */
header.top { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.top-inner { max-width: 1240px; margin: 0 auto; padding: 10px 16px 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 20px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); padding-bottom: 10px; }
.brand svg { width: 26px; height: 26px; color: var(--accent); }
.brand b { font-size: 1.1rem; letter-spacing: -0.01em; }
.brand small { color: var(--muted); }
nav.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs a { padding: 8px 12px 10px; text-decoration: none; color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap; font-size: 0.93rem; }
nav.tabs a:hover { color: var(--ink); }
nav.tabs a.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
nav.tabs a.disabled { opacity: 0.4; pointer-events: none; }
.theme-btn { background: none; border: 1px solid var(--border); color: var(--ink-2); border-radius: 8px; padding: 4px 8px; cursor: pointer; margin-bottom: 10px; }

/* ---- Filters ---- */
.filters { background: var(--surface); border-bottom: 1px solid var(--border); }
.filters-inner { max-width: 1240px; margin: 0 auto; padding: 10px 16px; display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; }
.filters label, .fgroup { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--ink-2); }
select, input[type="date"], input[type="search"], input[type="number"] {
  font: inherit; font-size: 0.88rem; color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 7px; padding: 4px 8px;
}
input[type="search"] { min-width: 200px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font: inherit; font-size: 0.84rem; border: 1px solid var(--border); background: var(--surface); color: var(--ink-2); border-radius: 999px; padding: 3px 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--accent-wash); color: var(--ink); border-color: var(--accent); }
.match-count { margin-left: auto; font-size: 0.85rem; color: var(--ink-2); }
.match-count b { color: var(--ink); }

/* ---- Layout ---- */
main { max-width: 1240px; margin: 0 auto; padding: 20px 16px 60px; }
section.view { display: none; }
section.view.active { display: block; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(12, 1fr); }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-7 { grid-column: span 7; }
.span-6 { grid-column: span 6; } .span-5 { grid-column: span 5; } .span-4 { grid-column: span 4; }
@media (max-width: 900px) { .grid > * { grid-column: span 12 !important; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head p { margin: 2px 0 0; color: var(--muted); font-size: 0.83rem; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { font-size: 0.82rem; color: var(--ink-2); }
.tile .value { font-size: 1.7rem; font-weight: 600; letter-spacing: -0.01em; }
.tile.hero .value { font-size: 2.6rem; }
.tile .sub { font-size: 0.8rem; color: var(--muted); }
.empty { color: var(--muted); font-size: 0.9rem; padding: 12px 0; margin: 0; }
.note { font-size: 0.85rem; color: var(--ink-2); background: var(--surface-2); border-radius: 8px; padding: 10px 12px; margin: 0 0 16px; }

/* ---- Bars ---- */
.hbars { display: flex; flex-direction: column; gap: 6px; }
.hbar { display: grid; grid-template-columns: minmax(110px, 40%) 1fr; gap: 10px; align-items: center; padding: 2px 0; }
.hbar-label { display: flex; align-items: center; gap: 7px; font-size: 0.88rem; min-width: 0; }
.hbar-label span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-label small { color: var(--muted); white-space: nowrap; }
.hbar-track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hbar-fill { height: 18px; min-width: 2px; background: var(--accent); border-radius: 0 4px 4px 0; max-width: calc(100% - 92px); }
.hbar-value { font-size: 0.82rem; color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.stack { display: flex; gap: 2px; height: 22px; }
.seg { border-radius: 2px; display: flex; align-items: center; justify-content: center; min-width: 2px; }
.seg span { font-size: 0.75rem; color: #fff; font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 0.82rem; color: var(--ink-2); margin-bottom: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---- SVG charts ---- */
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
svg .grid { stroke: var(--grid); stroke-width: 1; }
svg .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
svg .col { fill: var(--accent); }
svg .hit { fill: transparent; }
svg g:hover .col { opacity: 0.8; }
svg .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg .line.max { stroke: var(--muted); stroke-width: 1.5; opacity: 0.7; }
svg .line.gold { stroke: var(--c-regent); }
svg .area { fill: var(--accent); opacity: 0.1; stroke: none; }
svg .band { fill: var(--surface-2); }
svg .band-label { fill: var(--muted); font-size: 11px; }
svg .marker { stroke: var(--surface); stroke-width: 2; }
svg .marker.elite { fill: var(--t-elite); }
svg .marker.boss { fill: var(--t-boss); }
svg .crosshair { stroke: var(--axis); stroke-width: 1; }
svg .overlay { fill: transparent; cursor: crosshair; }

.tooltip { position: fixed; left: 0; top: 0; z-index: 100; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--border); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18); border-radius: 8px; padding: 8px 10px; font-size: 0.82rem; max-width: 320px; opacity: 0; transition: opacity 0.08s; }
.tooltip.show { opacity: 1; }
.tooltip b { font-weight: 600; }

/* ---- Tables ---- */
.table-wrap { overflow: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.87rem; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { font-weight: 600; color: var(--ink-2); font-size: 0.8rem; cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--surface); }
th:hover { color: var(--ink); }
th.sorted::after { content: " ▾"; color: var(--accent); }
th.sorted.asc::after { content: " ▴"; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
tr.selected { background: var(--accent-wash) !important; }
.meter { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; }
.meter b { font-weight: 400; min-width: 38px; }
.mtrack { width: 48px; height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; display: inline-block; }
.mtrack i { display: block; height: 100%; background: var(--accent); border-radius: 0 3px 3px 0; }
.delta-up { color: var(--good-text); }
.delta-down { color: var(--bad); }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 0.78rem; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; }
.pill.win { color: var(--good-text); border-color: color-mix(in srgb, var(--good) 40%, transparent); }
.pill.loss { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.pill.abandoned { color: var(--muted); }
.table-tools { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin-bottom: 10px; font-size: 0.85rem; color: var(--ink-2); }
.table-tools label { display: flex; align-items: center; gap: 6px; }

/* ---- Run detail ---- */
.run-detail { margin-top: 16px; }
.path { display: flex; flex-wrap: wrap; gap: 3px; margin: 8px 0 4px; }
.node { width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; font-size: 0.7rem; font-weight: 700; color: #fff; background: var(--t-monster); cursor: default; }
.node.elite { background: var(--t-elite); } .node.boss { background: var(--t-boss); }
.node.rest_site { background: var(--t-rest); } .node.shop { background: var(--t-shop); color: #0b0b0b; }
.node.unknown, .node.event { background: var(--t-event); } .node.treasure { background: var(--t-treasure); }
.node.ancient { background: var(--t-ancient); }
.node.act-break { margin-left: 10px; }
.deck { columns: 3 180px; column-gap: 20px; font-size: 0.86rem; }
.deck div { break-inside: avoid; padding: 1px 0; }
.deck .up { color: var(--good-text); font-weight: 600; }
.taglist { display: flex; flex-wrap: wrap; gap: 4px; }
.log td { white-space: normal; vertical-align: top; }
.log td:first-child { white-space: nowrap; }
.picked { font-weight: 600; }
.skipped { color: var(--muted); text-decoration: line-through; }
.close-btn { font: inherit; background: none; border: 1px solid var(--border); border-radius: 7px; padding: 3px 10px; cursor: pointer; color: var(--ink-2); }

/* ---- Upload ---- */
.upload-hero { text-align: center; max-width: 720px; margin: 10px auto 24px; }
.upload-hero h1 { font-size: 1.8rem; letter-spacing: -0.02em; margin-bottom: 8px; }
.upload-hero p { color: var(--ink-2); margin: 0; }
.dropzone { max-width: 720px; margin: 0 auto; border: 2px dashed var(--axis); border-radius: 14px; padding: 40px 20px; text-align: center; background: var(--surface); transition: border-color 0.1s, background 0.1s; }
.dropzone.over { border-color: var(--accent); background: var(--accent-wash); }
.dropzone svg { width: 44px; height: 44px; color: var(--accent); }
.dropzone h2 { font-size: 1.15rem; margin: 10px 0 4px; }
.dropzone p { margin: 0 0 16px; color: var(--ink-2); font-size: 0.9rem; }
.btn { font: inherit; font-size: 0.92rem; border-radius: 8px; padding: 8px 16px; cursor: pointer; border: 1px solid var(--border); background: var(--surface-2); color: var(--ink); display: inline-flex; gap: 8px; align-items: center; text-decoration: none; }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn:hover { filter: brightness(1.05); }
.btn-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.status { max-width: 720px; margin: 16px auto 0; font-size: 0.9rem; }
.status .ok { color: var(--good-text); }
.status .err { color: var(--bad); }
.status details { margin-top: 6px; color: var(--ink-2); }
.privacy { max-width: 720px; margin: 20px auto 0; display: flex; gap: 10px; font-size: 0.85rem; color: var(--ink-2); align-items: flex-start; }
.privacy svg { flex: none; width: 18px; height: 18px; margin-top: 2px; color: var(--good); }
.loaded-summary { max-width: 720px; margin: 20px auto 0; }

/* ---- Guide ---- */
.guide { max-width: 860px; margin: 0 auto; }
.guide h1 { font-size: 1.6rem; letter-spacing: -0.01em; margin-bottom: 6px; }
.guide > p { color: var(--ink-2); }
.step { display: grid; grid-template-columns: 36px 1fr; gap: 14px; margin: 28px 0; }
.step-num { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; }
.step h2 { font-size: 1.1rem; margin: 4px 0 6px; }
.step p { margin: 0 0 10px; color: var(--ink-2); }
.shot { margin: 10px 0 0; }
.shot img { max-width: 100%; border-radius: 8px; border: 1px solid var(--border); box-shadow: var(--shadow); display: block; }
.shot figcaption { font-size: 0.8rem; color: var(--muted); margin-top: 6px; }
.copy-line { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 6px 0 10px; }
.copy-line code { font-size: 0.92rem; padding: 6px 10px; user-select: all; word-break: break-all; }
.os-paths { width: 100%; font-size: 0.85rem; }
.os-paths td { white-space: normal; }
.tip { border-left: 3px solid var(--accent); padding: 6px 12px; background: var(--surface); border-radius: 0 8px 8px 0; font-size: 0.88rem; color: var(--ink-2); }

footer { text-align: center; font-size: 0.8rem; color: var(--muted); padding: 20px 16px 40px; }

.filters-toggle { display: none; }
@media (max-width: 700px) {
  .brand small { display: none; }
  nav.tabs { order: 3; flex-basis: 100%; }
  .theme-btn { margin-left: auto; }
  .filters-toggle { display: flex; justify-content: space-between; width: 100%; font: inherit; font-size: 0.9rem; background: none; border: 0; color: var(--ink); padding: 10px 16px; cursor: pointer; }
  .filters-toggle::after { content: "▾"; color: var(--muted); }
  .filters.open .filters-toggle::after { content: "▴"; }
  .filters:not(.open) .filters-inner { display: none; }
  .filters-inner { padding-top: 0; }
}
@media (max-width: 600px) {
  .hbar { grid-template-columns: minmax(90px, 40%) 1fr; }
  .tile.hero .value { font-size: 2rem; }
  .match-count { margin-left: 0; }
  input[type="search"] { min-width: 0; width: 100%; }
}
