/* Saturation & the Tolerance Window. Layout: title with the experiments; the logistic curve with its slope and the
   probe beside the gradient gauge and the target settings; then the single-unit sandbox with its tracks and telemetry.
   Changing text has a fixed size, so nothing moves while it runs. */
:root {
  color-scheme: dark;
  --bg: #080c14;
  --panel: #0d131e;
  --panel-2: #131b29;
  --line: #1b2536;
  --line-2: #2a3850;
  --fg: #e3e9f3;
  --muted: #8c98ad;
  --dim: #58647a;
  --cyan: #00f5ff;
  --mag: #ff2a6d;
  --amber: #ffb800;
  --green: #10b981;
  --blue: #3b82f6;
  --display: "Literata", "Iowan Old Style", Georgia, serif;
  --sans: "Instrument Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r: 6px;
}
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 var(--sans); }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.app { display: grid; gap: 12px; padding-block: 12px 20px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; }
.eyebrow { font: 500 11px/1.2 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h1 { margin: 4px 0 0; font: 600 24px/1.15 var(--display); text-wrap: balance; }
h1 span { display: block; margin-top: 3px; font: 400 13px/1.3 var(--sans); color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: 12.5px var(--sans); padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--panel); cursor: pointer; transition: border-color .15s, color .15s; }
.chip:hover { border-color: var(--cyan); }
.chip.on { border-color: var(--cyan); color: var(--cyan); background: rgba(0,245,255,.07); }
.note { margin: 0; font-size: 13.5px; color: #c6cfdf; max-width: 135ch; min-height: calc(3 * 1.45em); }

select, .btn { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--r); padding: 4px 9px; min-height: 30px; max-width: 100%; }
.btn { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; transition: border-color .15s; white-space: nowrap; }
.btn:hover { border-color: var(--cyan); }
.btn svg { width: 14px; height: 14px; flex: none; }
.btn.primary { background: rgba(0,245,255,.09); border-color: rgba(0,245,255,.5); color: var(--cyan); }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--r); overflow: hidden; flex: none; }
.segb { background: var(--panel-2); border: 0; padding: 3px 9px; font: 12px var(--mono); cursor: pointer; color: var(--muted); white-space: nowrap; }
.segb + .segb { border-left: 1px solid var(--line-2); }
.segb.on { background: rgba(0,245,255,.12); color: var(--cyan); }

.card { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 10px 12px 12px; display: grid; gap: 8px; min-width: 0; align-content: start; }
.card > * { min-width: 0; }
.card-h { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; }
.sec-h { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 0; font: 500 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); min-width: 0; }
.sec-h em { font-style: normal; text-transform: none; letter-spacing: 0; color: var(--dim); }
.cap { margin: 0; font: 11.5px/1.45 var(--mono); color: var(--dim); }
canvas { display: block; max-width: 100%; width: 100%; border-radius: 6px; border: 1px solid var(--line); background: #05080e; }

.main { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 12px; align-items: start; }
#cvCurve { height: 430px; cursor: ew-resize; touch-action: none; }
.probe { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.probe div { border: 1px solid var(--line-2); border-radius: 6px; padding: 5px 9px; background: var(--panel-2); display: grid; gap: 1px; }
.probe span { font: 10.5px var(--mono); color: var(--muted); white-space: nowrap; }
.probe b { font: 600 17px/1.2 var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.side { display: grid; gap: 12px; min-width: 0; }
.chain { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font: 12px var(--mono); font-variant-numeric: tabular-nums; min-height: 52px; }
.chain .f { display: grid; justify-items: center; padding: 4px 8px; border: 1px solid var(--line-2); border-radius: 5px; }
.chain .f span { font-size: 10.5px; color: var(--muted); }
.chain .f b { font-weight: 600; }
.chain .op { color: var(--muted); }
.chain .res { font: 700 15px var(--mono); }
#cvGauge { height: 66px; }
#gaugeCap { height: calc(3 * 1.45em); overflow: hidden; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12.5px; color: var(--muted); }
.row b { font: 500 12.5px var(--mono); color: var(--cyan); font-variant-numeric: tabular-nums; }
#cvNorm { height: 120px; }
.status { font: 700 12px/1.4 var(--mono); letter-spacing: .03em; padding: 6px 10px; border-radius: 6px; border: 1px solid var(--line-2); height: calc(2 * 1.4em + 14px); overflow: hidden; }
.status.ok { color: #34f5a0; border-color: rgba(52,245,160,.5); background: rgba(16,185,129,.08); }
.status.bad { color: var(--mag); border-color: rgba(255,42,109,.5); background: rgba(255,42,109,.07); }
.status.mid { color: var(--amber); border-color: rgba(255,184,0,.5); }

.row-btns { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cfg { display: grid; gap: 8px; }
.grp { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 12.5px; color: var(--muted); }
.grp .gl { font: 500 11px var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--dim); min-width: 8ch; }
.grp input[type=range] { width: 120px; }
.grp b { font: 500 12px var(--mono); color: var(--cyan); min-width: 5ch; font-variant-numeric: tabular-nums; }
.grp .single { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.grp .single.off { opacity: .35; pointer-events: none; }
#cvTracks { height: 360px; }
.tele { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.tele div { border: 1px solid var(--line-2); border-radius: 6px; padding: 5px 9px; background: var(--panel-2); display: grid; gap: 1px; min-width: 0; }
.tele span { font: 10.5px var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tele b { font: 600 15px/1.25 var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; background: transparent; height: 18px; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line-2); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: var(--fg); border: 2px solid var(--bg); box-shadow: 0 0 0 1px var(--cyan); }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--fg); border: 2px solid var(--bg); }

@media (max-width: 1150px) {
  .main { grid-template-columns: minmax(0, 1fr); }
  .side { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
  .tele { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  h1 { font-size: 20px; }
  #cvCurve { height: 320px; }
  .probe { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tele { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grp input[type=range] { width: 90px; }
  .note { min-height: 0; }
}
.pg-embedded .top > div:first-child { display: none; }
@media (prefers-reduced-motion: reduce) { .btn, .chip { transition: none; } }
