:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface-1: #fcfcfb;
  --surface-2: #f0efeb;
  --border: #e2e0da;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #85837d;
  --grid: #e8e6e1;
  --accent: #2a78d6;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
  --other: #b4b2ab;
  --select: rgba(42, 120, 214, .14);
  --critical: #c62828;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface-1: #1a1a19; --surface-2: #232321; --border: #33332f;
    --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8d8c84; --grid: #2b2b28;
    --accent: #3987e5;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --other: #5c5b56; --select: rgba(57, 135, 229, .22); --critical: #ef6b6b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface-1: #1a1a19; --surface-2: #232321; --border: #33332f;
  --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8d8c84; --grid: #2b2b28;
  --accent: #3987e5;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --other: #5c5b56; --select: rgba(57, 135, 229, .22); --critical: #ef6b6b;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 22px; margin: 0 0 8px; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
.muted { color: var(--text-muted); }
.error { color: var(--critical); font-weight: 600; }
button, select, input { font: inherit; color: inherit; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 8px; }
button { cursor: pointer; }
button:hover { border-color: var(--accent); }

.top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--surface-1);
  border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 17px; }
.brand span { font-weight: 400; color: var(--text-secondary); }
.filebtn { background: var(--accent); color: #fff; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-weight: 600; }
.filebtn input { display: none; }

.drop { display: grid; place-items: center; min-height: 70vh; padding: 16px; }
.drop-inner { max-width: 560px; text-align: center; border: 2px dashed var(--border); border-radius: 12px; padding: 40px 24px;
  background: var(--surface-1); }
.drop.over .drop-inner { border-color: var(--accent); }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 16px; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .1s; }

#report { padding: 0 16px 32px; max-width: 1500px; margin: 0 auto; }
.filters { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center;
  padding: 10px 0; background: var(--bg); border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.filters label { display: flex; gap: 6px; align-items: center; color: var(--text-secondary); min-width: 0; max-width: 100%; }
.filters select { max-width: calc(100vw - 100px); min-width: 0; }
@media (max-width: 700px) { .filters { position: static; } }
.banner { background: var(--surface-2); border-left: 3px solid var(--series-4); padding: 8px 12px; margin-bottom: 12px; border-radius: 4px; }

.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 12px; min-width: 0; }
.card-head { display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap; margin-bottom: 10px; }
.hint { color: var(--text-muted); font-size: 12px; }
.inline { display: flex; gap: 6px; align-items: center; color: var(--text-secondary); }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr)); gap: 12px; }
.cols > .card { margin-bottom: 0; }
.cols { margin-bottom: 12px; }
.tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 12px; scrollbar-width: thin; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 14px;
  color: var(--text-secondary); white-space: nowrap; font-weight: 500; }
.tabs button:hover { color: var(--text-primary); }
.tabs button[aria-selected="true"] { color: var(--text-primary); border-bottom-color: var(--accent); font-weight: 650; }
.sect { margin: 4px 0 8px; }
.tabbar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-bottom: 12px; }
.tabbar select { max-width: calc(100vw - 100px); }
.cols4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 12px; margin-bottom: 12px; }
.cols4 > .card { margin-bottom: 0; }
#taken-tiles { margin-bottom: 12px; }
.close { margin-left: auto; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 3px 10px; background: var(--surface-1); color: var(--text-secondary); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.grid-top { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 12px; margin-bottom: 12px; }
.grid-top > .card { margin-bottom: 0; }
@media (max-width: 900px) { .grid-top { grid-template-columns: 1fr; } }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; align-content: start; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.tile.click { cursor: pointer; }
.tile.click:hover { border-color: var(--accent); }
.tile .k { color: var(--text-secondary); font-size: 12px; }
.tile .v { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile .s { color: var(--text-muted); font-size: 12px; }

.char-head { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.char-name { font-size: 20px; font-weight: 700; }
.char-sub { color: var(--text-secondary); }
.char-body { display: grid; grid-template-columns: minmax(0, 220px) minmax(0, 1fr); gap: 16px; margin-top: 10px; }
@media (max-width: 600px) { .char-body { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-variant-numeric: tabular-nums; }
.kv dt { color: var(--text-secondary); }
.kv dd { margin: 0; text-align: right; }
.gear { list-style: none; margin: 0; padding: 0; }
.gear li { display: grid; grid-template-columns: 100px 1fr; gap: 8px; padding: 2px 0; border-bottom: 1px solid var(--grid); }
.gear li span:first-child { color: var(--text-secondary); font-size: 12px; padding-top: 1px; }
.gear .cards { color: var(--text-muted); font-size: 12px; }
.gear .opts { color: var(--series-3); font-size: 12px; }
.res-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: 12px 20px; }
.res-grid h3 { font-size: 13px; margin: 0 0 4px; color: var(--text-secondary); font-weight: 600; }
.kv dd .muted { font-size: 12px; }
.kv dd.zero { color: var(--text-muted); }
.vs { width: 100%; max-width: 520px; }
.vs td:first-child { color: var(--text-secondary); }
.vs tr.total td { font-weight: 600; border-top: 1px solid var(--border); }
.chip.def { border-color: var(--series-1); }
.calc { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 12px 24px; }
.calc fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px 10px; margin: 0; min-width: 0; }
.calc legend { color: var(--text-secondary); font-size: 13px; font-weight: 600; padding: 0 4px; }
.calc label { display: grid; grid-template-columns: 1fr 96px; align-items: center; gap: 8px; font-size: 13px; padding: 2px 0; }
.calc label.chk { grid-template-columns: 1fr auto; }
.calc input[type=number], .calc select { width: 100%; box-sizing: border-box; font: inherit; padding: 2px 6px; background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--border); border-radius: 6px; }
.calc .row-btn { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.calc-out { margin-top: 12px; }
.chip.deb { border-color: var(--series-5); }
details.src summary { cursor: pointer; color: var(--text-secondary); font-size: 13px; margin-top: 10px; }
.note { color: var(--text-muted); font-size: 12px; margin-top: 8px; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--text-secondary); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.chart { position: relative; height: 220px; user-select: none; }
.chart.tall { height: 260px; }
.chart canvas { width: 100%; height: 100%; display: block; cursor: crosshair; }
.tip { position: absolute; pointer-events: none; background: var(--surface-1); border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 8px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.15); white-space: nowrap; z-index: 3; }
.tip b { font-variant-numeric: tabular-nums; }

.tbl-wrap { overflow: auto; max-height: 460px; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 4px 8px; text-align: left; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface-1); color: var(--text-secondary); font-weight: 600; cursor: pointer; font-size: 12px; }
th.num, td.num { text-align: right; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--surface-2); }
tr.sub td { color: var(--text-secondary); font-size: 12px; background: var(--surface-2); }
tr.sub td:first-child { padding-left: 24px; }
tr.sel { background: var(--select) !important; }
.rolebar { display: inline-flex; gap: 1px; width: 120px; height: 10px; border-radius: 3px; overflow: hidden; vertical-align: middle; }
.rolebar span { display: block; min-width: 3px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.bar { display: inline-block; height: 8px; background: var(--series-1); border-radius: 0 4px 4px 0; vertical-align: middle; margin-right: 6px; }
.link { color: var(--accent); cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 1px 8px; font-size: 12px; }
.chip.endow { border-color: var(--series-2); }
.insp { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: 16px; }
.insp h3 { font-size: 13px; margin: 0 0 6px; color: var(--text-secondary); font-weight: 600; }
footer { font-size: 12px; margin-top: 8px; }
.neg { color: var(--critical); }
#evlog tr.ev-taken td:nth-child(3) { color: var(--text-primary); }
#evlog tr.ev-status td, #evlog tr.ev-item td { color: var(--text-secondary); }
#evlog tr.ev-hp td { font-weight: 600; }
#evlog tr.ev-devo td { font-weight: 600; }

.cols3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 12px; margin-bottom: 12px; }
.cols3 > .card { margin-bottom: 0; }
.blist { display: grid; gap: 6px; }
.brow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; cursor: pointer; }
.brow .track { position: relative; height: 26px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.brow .fill { position: absolute; inset: 0 auto 0 0; background: var(--series-1); opacity: .85; border-radius: 0 4px 4px 0; }
.brow.me .fill { background: var(--series-2); }
.brow .label { position: absolute; inset: 0; display: flex; align-items: center; gap: 6px; padding: 0 8px; white-space: nowrap; overflow: hidden;
  color: var(--text-primary); text-shadow: 0 0 3px var(--surface-1), 0 0 3px var(--surface-1); }
.brow .label small { color: var(--text-secondary); }
.brow .val { font-variant-numeric: tabular-nums; min-width: 56px; text-align: right; }
.brow:hover .track { outline: 1px solid var(--accent); }
.more { margin-top: 8px; }
