:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e0db;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #85837e;
  --grid: #e8e6e1;
  --accent: #2a78d6;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s7: #4a3aa7;
  --neutral: #a3a19b;
  --band: rgba(42, 120, 214, 0.08);
  --good: #008300;
  --bad: #c43333;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #8d8c84;
    --grid: #2a2a28;
    --accent: #3987e5;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s7: #9085e9;
    --neutral: #6b6a64;
    --band: rgba(57, 135, 229, 0.12);
    --good: #3fb950;
    --bad: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --surface: #1a1a19;
  --surface-2: #232321;
  --border: #2f2f2c;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #8d8c84;
  --grid: #2a2a28;
  --accent: #3987e5;
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s7: #9085e9;
  --neutral: #6b6a64;
  --band: rgba(57, 135, 229, 0.12);
  --good: #3fb950;
  --bad: #e66767;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text-primary);
  font: 14px/1.45 Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.mono, input[type="number"], .val { font-family: "JetBrains Mono", ui-monospace, monospace; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 24px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.top h1 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.sub { margin: 2px 0 0; color: var(--text-secondary); font-size: 13px; }
.top-actions { display: flex; gap: 8px; flex-shrink: 0; }
button.ghost {
  font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 6px; cursor: pointer;
  background: transparent; color: var(--text-primary); border: 1px solid var(--border);
}
button.ghost:hover { background: var(--surface-2); }

.layout { display: grid; grid-template-columns: 300px 1fr; align-items: start; }
.controls {
  position: sticky; top: 0; max-height: 100vh; overflow-y: auto;
  padding: 16px 20px 40px; border-right: 1px solid var(--border); background: var(--surface);
}
.controls section { margin-bottom: 20px; }
.controls h2 {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); margin: 0 0 8px;
}
.ctl { margin-bottom: 10px; }
.ctl label { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13px; color: var(--text-secondary); }
.ctl .num { display: flex; align-items: baseline; gap: 4px; }
.ctl input[type="number"] {
  width: 76px; text-align: right; font-size: 12px; padding: 2px 4px;
  background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--border); border-radius: 4px;
}
.ctl .unit { font-size: 11px; color: var(--text-muted); min-width: 30px; }
.ctl input[type="range"] { width: 100%; margin: 4px 0 0; accent-color: var(--accent); }
.hint { font-size: 12px; color: var(--text-muted); margin: 4px 0 8px; }

.seg { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; margin: 6px 0 10px; }
.seg button {
  flex: 1; font: inherit; font-size: 12px; padding: 6px; cursor: pointer;
  background: transparent; color: var(--text-secondary); border: 0;
}
.seg button.on { background: var(--surface-2); color: var(--text-primary); font-weight: 500; }

.zrow { display: grid; grid-template-columns: 22px 1fr 1fr; gap: 6px; align-items: center; margin-bottom: 6px; font-size: 12px; color: var(--text-secondary); }
.zrow input {
  width: 100%; font: 12px "JetBrains Mono", monospace; padding: 3px 4px;
  background: var(--surface-2); color: var(--text-primary); border: 1px solid var(--border); border-radius: 4px;
}

main { padding: 20px 24px 48px; min-width: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.tile .k { font-size: 12px; color: var(--text-secondary); }
.tile .v { font: 500 22px/1.2 "JetBrains Mono", monospace; margin-top: 4px; letter-spacing: -0.02em; }
.tile .d { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.tile .flag { font-size: 12px; font-weight: 500; }
.flag.ok { color: var(--good); }
.flag.no { color: var(--bad); }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.card header h3 { margin: 0; font-size: 14px; font-weight: 600; }
.card header p { margin: 2px 0 6px; font-size: 12px; color: var(--text-secondary); }
.plot { width: 100%; height: 320px; }
.plot.square { height: 360px; }
.plot.tall { height: 440px; }

details { margin-top: 8px; font-size: 12px; color: var(--text-secondary); }
summary { cursor: pointer; }
.tbl-wrap { overflow-x: auto; margin-top: 8px; }
table { border-collapse: collapse; width: 100%; font: 12px "JetBrains Mono", monospace; }
th, td { text-align: right; padding: 4px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 500; }

.notes { margin-top: 20px; color: var(--text-secondary); font-size: 13px; }
.notes h3 { color: var(--text-primary); font-size: 14px; margin: 0 0 6px; }
.notes ul { margin: 0; padding-left: 18px; }
.notes li { margin-bottom: 4px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .controls { position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--border); padding: 16px; }
  main { padding: 16px; }
  .grid { grid-template-columns: 1fr; }
  .top { padding: 12px 16px; flex-wrap: wrap; }
}
