:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface-1: #fcfcfb;
  --surface-2: #efeeea;
  --border: #dcdbd5;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77766f;
  --accent: #2a78d6;
  --bar: #2a78d6;
  --bar-heal: #1baf7a;
  --bar-taken: #e34948;
  --row-hover: #e9eef7;
  --grid: #e3e2dc;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --tile-l: 34%;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --border: #34342f;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e85;
    --accent: #3987e5;
    --bar: #3987e5;
    --bar-heal: #199e70;
    --bar-taken: #e66767;
    --row-hover: #24292f;
    --grid: #2b2b28;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --border: #34342f;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e85;
  --accent: #3987e5;
  --bar: #3987e5;
  --bar-heal: #199e70;
  --bar-taken: #e66767;
  --row-hover: #24292f;
  --grid: #2b2b28;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text-primary);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
button, select, input { font: inherit; color: inherit; }

header.app {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface-1); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
header.app h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: .2px; }
header.app .spacer { flex: 1; }
.file-btn {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 6px;
  padding: 5px 12px; cursor: pointer;
}
.file-btn:hover { border-color: var(--accent); }
.status { color: var(--text-muted); font-size: 13px; }

main { padding: 16px 20px 60px; max-width: 1500px; margin: 0 auto; }

.dropzone {
  border: 2px dashed var(--border); border-radius: 12px; padding: 70px 20px; text-align: center;
  color: var(--text-secondary); background: var(--surface-1); margin-top: 30px;
}
.dropzone.drag { border-color: var(--accent); background: var(--surface-2); }
.dropzone h2 { margin: 0 0 8px; color: var(--text-primary); font-weight: 600; }
.dropzone code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
body.dragging .dropzone { border-color: var(--accent); }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center;
  padding: 10px 14px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px;
}
.toolbar label { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: 13px; }
.toolbar select, .toolbar input[type=number] {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px;
}
.toolbar select#fightSelect { min-width: 340px; max-width: 100%; }
.toolbar input[type=number] { width: 60px; }

.dropdown { position: relative; }
.dropdown > button {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; cursor: pointer;
}
.dropdown .menu {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; z-index: 30; min-width: 280px; max-height: 360px; overflow: auto;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.dropdown.open .menu { display: block; }
.dropdown .menu label { display: flex; gap: 8px; padding: 3px 4px; color: var(--text-primary); }
.dropdown .menu label span.v { margin-left: auto; color: var(--text-muted); }
.dropdown .menu .actions { display: flex; gap: 6px; margin-bottom: 6px; }
.dropdown .menu .actions button { font-size: 12px; padding: 2px 8px; border-radius: 5px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin: 14px 0; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; }
.tile .k { color: var(--text-secondary); font-size: 12px; }
.tile .v { font-size: 22px; font-weight: 650; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .s { color: var(--text-muted); font-size: 12px; }

nav.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 16px 0 14px; flex-wrap: wrap; }
nav.tabs button {
  background: none; border: none; border-bottom: 2px solid transparent; padding: 8px 14px; cursor: pointer;
  color: var(--text-secondary); font-weight: 550;
}
nav.tabs button.active { color: var(--text-primary); border-bottom-color: var(--accent); }
nav.tabs button:hover { color: var(--text-primary); }

.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 14px; }
.card h3 { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
.card h3 .sub { color: var(--text-muted); font-weight: 400; margin-left: 8px; }

.table-wrap { overflow-x: auto; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th, table.data td { padding: 5px 9px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
table.data th { color: var(--text-secondary); font-weight: 600; cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--surface-1); }
table.data th:hover { color: var(--text-primary); }
table.data th.sorted::after { content: " ▾"; }
table.data th.sorted.asc::after { content: " ▴"; }
table.data th.l, table.data td.l { text-align: left; }
table.data tbody tr:hover { background: var(--row-hover); }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.selected { background: var(--row-hover); box-shadow: inset 3px 0 0 var(--accent); }
table.data td.bar { position: relative; min-width: 150px; padding-bottom: 9px; }
table.data td.bar .fill { position: absolute; left: 9px; bottom: 4px; height: 4px; border-radius: 0 3px 3px 0; max-width: calc(100% - 18px); }
table.data td.bar .txt { position: relative; }
table.data tfoot td { font-weight: 650; border-top: 2px solid var(--border); border-bottom: none; }
.muted { color: var(--text-muted); }
.pet-tag { color: var(--text-muted); font-size: 12px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 7px; vertical-align: -1px; }

.player-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 13px;
}
.chip.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.chip .handle { color: var(--text-muted); margin-left: 4px; }

/* chart */
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .axis text { fill: var(--text-muted); font-size: 11px; }
.chart .grid line { stroke: var(--grid); }
.chart .crosshair { stroke: var(--text-muted); stroke-dasharray: 3 3; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-secondary); margin: 6px 0 0; }
.legend .item { display: inline-flex; align-items: center; cursor: pointer; }
.legend .item.off { opacity: .35; }
.legend .sw { width: 14px; height: 3px; border-radius: 2px; margin-right: 6px; }

#tooltip {
  position: fixed; pointer-events: none; z-index: 100; display: none;
  background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.3); max-width: 340px;
}
#tooltip .tt-title { font-weight: 650; margin-bottom: 4px; }
#tooltip table { border-collapse: collapse; }
#tooltip td { padding: 1px 6px 1px 0; }
#tooltip td.n { text-align: right; }

/* rotation */
.rot-controls { display: flex; gap: 10px 18px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; font-size: 13px; color: var(--text-secondary); }
.rot-controls label { display: inline-flex; gap: 6px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { border: none; background: var(--surface-2); padding: 4px 10px; cursor: pointer; }
.seg button.active { background: var(--accent); color: #fff; }

.icon {
  --size: 30px;
  width: var(--size); height: var(--size); flex: 0 0 var(--size);
  border-radius: 4px; border: 2px solid #3fd6ff; position: relative; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 750; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.8);
  letter-spacing: -.3px; user-select: none; cursor: default;
}
.icon img { width: 100%; height: 100%; object-fit: cover; display: block; }
.icon.inferred { border-style: dashed; border-color: #999; }
.icon.sel { outline: 2px solid #fff; }

.seq-player { margin-bottom: 22px; }
.seq-player h4 { margin: 0 0 6px; font-size: 14px; display: flex; align-items: center; }
.seq-row { display: flex; gap: 6px; align-items: center; margin-bottom: 3px; }
.seq-row .tlabel { width: 46px; flex: 0 0 46px; color: var(--text-muted); font-size: 11px; text-align: right; }
.seq-row .icons { display: flex; flex-wrap: wrap; gap: 2px; }

.tl-outer { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.tl-inner { position: relative; }
.tl-ruler { position: sticky; top: 0; height: 22px; border-bottom: 1px solid var(--border); background: var(--surface-1); }
.tl-ruler span { position: absolute; top: 3px; font-size: 11px; color: var(--text-muted); transform: translateX(-50%); }
.tl-lane { position: relative; border-bottom: 1px solid var(--border); }
.tl-lane .tl-name {
  position: sticky; left: 0; z-index: 2; display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px;
  background: var(--surface-1); border-radius: 0 0 6px 0; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.tl-lane .icon { position: absolute; --size: 24px; font-size: 9px; }
.tl-gridline { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--grid); }

.skill-legend { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
.skill-legend .sl {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px 2px 2px; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; font-size: 12px;
}
.skill-legend .sl .icon { --size: 22px; font-size: 9px; }
.skill-legend .sl.off { opacity: .35; }
.skill-legend .sl .c { color: var(--text-muted); }

.note { color: var(--text-muted); font-size: 12px; margin-top: 6px; }
.hidden { display: none !important; }

@media (max-width: 700px) {
  main { padding: 12px 12px 40px; }
  header.app { padding: 10px 12px; }
  .toolbar select#fightSelect { min-width: 0; width: 100%; }
}
