:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --surface-3: #2c2c2a;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-strong: #256abf;
  /* categorical slots, dark steps (validated on #1a1a19) */
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--page); color: var(--text-primary); }
body { display: flex; flex-direction: column; font-size: 14px; }

header {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--surface-1); border-bottom: 1px solid var(--border);
}
.brand { display: flex; flex-direction: column; line-height: 1; }
.brand img { height: 26px; width: auto; align-self: flex-start; }
.brand span { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--text-muted); margin-top: 3px; }
nav { display: flex; gap: 4px; }
button {
  font: inherit; color: var(--text-secondary); background: var(--surface-3);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; cursor: pointer;
}
button:hover { color: var(--text-primary); background: #383835; }
button.primary { background: var(--accent-strong); color: #fff; border-color: transparent; }
button.primary:hover { background: var(--accent); }
.tab { background: transparent; border-color: transparent; }
.tab.active { background: var(--accent-strong); color: #fff; }
.state-switch { display: flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.seg { border: 0; border-radius: 0; background: transparent; }
.seg.active { background: var(--surface-3); color: var(--text-primary); box-shadow: inset 0 -2px 0 var(--accent); }
.seg[data-state="damaged"].active { box-shadow: inset 0 -2px 0 #d03b3b; }
.status { margin-left: auto; font: 12px ui-monospace, Consolas, monospace; color: var(--text-muted); }

main { flex: 1; display: flex; min-height: 0; }
aside {
  width: 340px; flex-shrink: 0; overflow-y: auto; background: var(--surface-1);
  border-right: 1px solid var(--border); padding: 4px 16px 24px;
}
.panel h3 {
  font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-secondary); margin: 18px 0 8px;
}
.panel h3 small { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--text-muted); margin-left: 6px; }
.panel.anim { border-top: 1px solid var(--border); margin-top: 16px; }
.hidden { display: none !important; }

.slider-row { display: grid; grid-template-columns: 92px 1fr 64px; gap: 8px; align-items: center; margin: 6px 0; }
.slider-row label { font-size: 12px; color: var(--text-secondary); }
.slider-row label small { color: var(--text-muted); font-family: ui-monospace, Consolas, monospace; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=number] {
  width: 64px; background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 4px; padding: 3px 5px; font: 12px ui-monospace, Consolas, monospace; text-align: right;
}
.num { font: 12px ui-monospace, Consolas, monospace; color: var(--text-secondary); text-align: right; font-variant-numeric: tabular-nums; }
.btn-row { display: flex; gap: 8px; margin: 8px 0; }
.btn-row button { flex: 1; }
.hint { font-size: 12px; color: var(--text-muted); margin: 6px 0; line-height: 1.45; }
.check { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-secondary); margin: 6px 0; cursor: pointer; }

.freq-list { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.freq-list button {
  display: flex; justify-content: space-between; gap: 4px; text-align: left; padding: 5px 6px; white-space: nowrap;
  font: 11px ui-monospace, Consolas, monospace; font-variant-numeric: tabular-nums; background: var(--surface-2);
}
.freq-list button .z { color: var(--text-muted); }
.freq-list button.active { background: var(--accent-strong); color: #fff; }
.freq-list button.active .z { color: #dbe8fb; }
.freq-list.compact button { cursor: default; }

.readout { font: 12px ui-monospace, Consolas, monospace; color: var(--text-secondary); line-height: 1.6; font-variant-numeric: tabular-nums; }
.readout b { color: var(--text-primary); font-weight: 600; }
#grid-map { display: block; width: 260px; height: 260px; background: var(--surface-2); border-radius: 6px; }

.view { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
#viewer { flex: 1; min-height: 200px; position: relative; }
.view-label {
  position: absolute; top: 10px; left: 12px; pointer-events: none; font: 12px ui-monospace, Consolas, monospace;
  color: var(--text-secondary); background: rgba(13, 13, 13, .7); padding: 4px 8px; border-radius: 4px;
}
.traj-chart { height: 260px; flex-shrink: 0; border-top: 1px solid var(--border); background: var(--surface-1); padding: 6px 12px 8px; display: flex; flex-direction: column; }
.traj-chart .chart-wrap { flex: 1; min-height: 0; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--text-secondary); padding: 2px 0 4px; }
.legend label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.legend .key { width: 16px; height: 2px; border-radius: 1px; display: inline-block; }

.chart-wrap { position: relative; }
.chart-wrap canvas { display: block; width: 100%; height: 100%; }
#shape-chart { height: 170px; }
.tooltip {
  position: absolute; pointer-events: none; display: none; z-index: 5; min-width: 120px;
  background: var(--surface-3); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px;
  font-size: 12px; color: var(--text-secondary); box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
}
.tooltip .row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.tooltip .row b { color: var(--text-primary); font-variant-numeric: tabular-nums; min-width: 58px; text-align: right; }
.tooltip .key { width: 12px; height: 2px; display: inline-block; }
.tooltip .head { color: var(--text-muted); margin-bottom: 3px; }

@media (max-width: 760px) {
  main { flex-direction: column; }
  aside { width: 100%; max-height: 45vh; border-right: 0; border-bottom: 1px solid var(--border); }
  .status { margin-left: 0; }
}
