/* Layout: an instrument page. Controls bar, cable trims, then diode | phase plots,
   the polarization signal with circuit readout, and circuit constants. */
:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --ink: #15202b;
  --ink-2: #485664;
  --muted: #778492;
  --line: #d6dde4;
  --copper: #b4531b;
  --copper-soft: #f6e4d8;
  --ok: #1d7448;
  --ok-soft: #dcefe4;
  --warn: #8f5a00;
  --warn-soft: #f7e9c9;
  --bad: #b02a1d;
  --bad-soft: #f8dcd8;
  --track: #e3e8ed;
  --canvas-bg: #f7f9fa;
  --shell: #2a78d6;
  --k-rise: #1baf7a; --k-rev: #eda100;
  --fitc: #148a5e;
  --f-display: "IBM Plex Sans Condensed", "Arial Narrow", system-ui, sans-serif;
  --f-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e141a; --panel: #161f28; --ink: #e5ebf0; --ink-2: #b0bcc7; --muted: #7d8a97;
    --line: #283440; --copper: #e5834a; --copper-soft: #3a2518; --ok: #5cc794; --ok-soft: #173326;
    --warn: #e2a93f; --warn-soft: #382b12; --bad: #f0786a; --bad-soft: #3c1d19;
    --track: #24303b; --canvas-bg: #111a22; --shell: #4d95ea; --fitc: #3dbd8a; --k-rise: #199e70; --k-rev: #c98500; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e141a; --panel: #161f28; --ink: #e5ebf0; --ink-2: #b0bcc7; --muted: #7d8a97;
  --line: #283440; --copper: #e5834a; --copper-soft: #3a2518; --ok: #5cc794; --ok-soft: #173326;
  --warn: #e2a93f; --warn-soft: #382b12; --bad: #f0786a; --bad-soft: #3c1d19;
  --track: #24303b; --canvas-bg: #111a22; --shell: #4d95ea; --fitc: #3dbd8a; --k-rise: #199e70; --k-rev: #c98500; color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 14px; line-height: 1.5;
}
.wrap {
  max-width: 1240px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 20px 40px;
  display: flex; flex-direction: column; gap: 18px;
}
header h1 {
  font-family: var(--f-display); font-weight: 600; font-size: 1.9rem; letter-spacing: 0.005em;
  margin: 0; text-wrap: balance;
}
header p { margin: 4px 0 0; color: var(--ink-2); max-width: 78ch; }
.mono, .num { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.eyebrow {
  font-family: var(--f-display); font-weight: 500; font-size: 0.78rem; text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--muted);
}

/* controls */
.controls {
  display: flex; flex-wrap: wrap; gap: 14px 22px; align-items: flex-end;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px;
}
.ctl { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ctl label, .ctl .eyebrow { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
  font: 500 0.9rem var(--f-body); color: var(--ink-2); background: transparent; border: 0;
  padding: 7px 12px; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--copper); color: #fff; }
select, input[type="number"] {
  font: 0.9rem var(--f-body); color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; max-width: 100%;
}
input[type="number"] { width: 7.4em; font-family: var(--f-mono); }
input[type="number"].bad { border-color: var(--bad); }
input[type="range"] { width: 200px; max-width: 100%; accent-color: var(--copper); }
.btn {
  font: 500 0.86rem var(--f-body); color: var(--ink); background: transparent;
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 11px; cursor: pointer;
}
.btn:hover { border-color: var(--copper); color: var(--copper); }
.btn.primary { background: var(--copper); border-color: var(--copper); color: #fff; }
.btn.primary:hover { color: #fff; filter: brightness(1.08); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.sm { padding: 3px 12px; font-size: 0.82rem; }
.card-head .title { display: flex; align-items: baseline; gap: 10px; }
button:focus-visible, select:focus-visible, input:focus-visible, canvas:focus-visible, summary:focus-visible {
  outline: 2px solid var(--copper); outline-offset: 2px;
}
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1 1 0; }
.status { font-size: 0.86rem; color: var(--ink-2); display: inline-flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.dot.ok { background: var(--ok); } .dot.busy { background: var(--warn); } .dot.err { background: var(--bad); }

/* panels */
section.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
section.panel h2 { font-family: var(--f-display); font-weight: 600; font-size: 1.15rem; margin: 0 0 2px; }
section.panel > p { margin: 0 0 12px; color: var(--ink-2); max-width: 90ch; }
.designer { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px 16px; align-items: end; }
.designer .ctl input[type="number"], .designer .ctl select { width: 100%; }
.trims { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px 22px; }
.trim .row { flex-wrap: nowrap; }
.trim input[type="range"] { flex: 1 1 auto; width: auto; min-width: 0; }
.trim .len { color: var(--muted); font-size: 0.8rem; }
.subhead { font-family: var(--f-display); font-weight: 600; font-size: 0.95rem; margin: 16px 0 8px; }
details.panel > summary, details.desc > summary {
  cursor: pointer; font-family: var(--f-display); font-weight: 600; font-size: 1.15rem; list-style: none;
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px;
}
details.panel > summary::-webkit-details-marker, details.desc > summary::-webkit-details-marker { display: none; }
details.panel > summary::before, details.desc > summary::before { content: "▸"; color: var(--muted); font-size: 0.9rem; }
details.panel[open] > summary::before, details.desc[open] > summary::before { content: "▾"; }
details.panel > summary .hint, details.desc > summary .hint { font-family: var(--f-body); font-weight: 400; }
details.desc { margin-bottom: 14px; }
details.desc > summary { font-size: 0.95rem; }
details.desc[open] > summary { margin-bottom: 4px; }
details.desc > summary .hint { color: var(--muted); font-size: 0.85rem; }
details.panel[open] > summary { margin-bottom: 12px; }
details.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }

/* views */
.stage { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 880px) { .stage { grid-template-columns: 1fr; } }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 14px; display: flex; flex-direction: column; gap: 10px; min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.card-head h2 { font-family: var(--f-display); font-weight: 600; font-size: 1.05rem; margin: 0; }
.hint { color: var(--muted); font-size: 0.8rem; }
.canvas-box { position: relative; width: 100%; max-width: 100%; aspect-ratio: 16 / 10; }
.canvas-box canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 8px;
  background: var(--canvas-bg); cursor: crosshair; touch-action: pan-y;
}
.legend-line { display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.8rem; color: var(--muted); }
.legend-line span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 14px; height: 8px; border-radius: 2px; background: var(--copper); display: inline-block; }
.sw.dash { background: none; border-top: 2px dashed currentColor; height: 0; width: 18px; border-radius: 0; }
.readline { font-family: var(--f-mono); font-size: 0.8rem; color: var(--ink-2); min-height: 1.5em; font-variant-numeric: tabular-nums; }

.readline sup, .dread sup { font-size: 0.75em; line-height: 0; }

/* readout */
.big {
  font-family: var(--f-mono); font-weight: 500; font-size: 2.2rem; line-height: 1; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.dread { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 0.88rem; align-items: baseline; }
.dread .k { color: var(--ink-2); }
.dread .v { font-family: var(--f-mono); font-variant-numeric: tabular-nums; text-align: right; }
.dread .hdr { font: 500 0.72rem var(--f-display); text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.dread hr { grid-column: 1 / -1; border: 0; border-top: 1px solid var(--line); margin: 2px 0; width: 100%; }

/* notes */
.notes { color: var(--ink-2); font-size: 0.84rem; max-width: 95ch; }
.notes h3 { font-family: var(--f-display); font-size: 0.95rem; margin: 0 0 4px; color: var(--ink); }
.notes ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.schem { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 18px; align-items: start; }
@media (max-width: 880px) { .schem { grid-template-columns: 1fr; } }
.schem img { width: 100%; height: auto; border-radius: 8px; background: #fff; border: 1px solid var(--line); }
/* analysis */
ol.steps { margin: 0 0 14px; padding-left: 20px; color: var(--ink-2); max-width: 95ch; display: grid; gap: 6px; }
ol.steps b { color: var(--ink); font-weight: 600; }
.controls.inset { background: var(--canvas-bg); margin-bottom: 14px; }
.controls.inset input.frac { width: 5.2em; }
.card.flat { background: transparent; border: 0; padding: 0; }
.an-stage { margin-bottom: 4px; }
.results { grid-template-columns: 1fr auto auto; max-width: 820px; }
.results .e { text-align: right; }
.sw.dot { background: none; border-top: 2px dotted currentColor; height: 0; width: 18px; border-radius: 0; }
#subLegend { display: inline-flex; gap: 6px 10px; align-items: center; flex-wrap: wrap; }
#subLegend[hidden], #pedLegend[hidden] { display: none; }
#pedLegend { display: inline-flex; gap: 6px; align-items: center; }
.sw.ped { background: none; width: 12px; height: 10px; border-radius: 0; border-right: 2px solid currentColor; border-bottom: 1.5px dashed currentColor; }
.chip {
  display: inline-block; font: 500 0.74rem var(--f-body); border-radius: 999px; padding: 2px 9px;
  white-space: nowrap; border: 1px solid transparent; font-variant-numeric: tabular-nums;
}
.chip.ok { color: var(--ok); background: var(--ok-soft); }
.chip.warn { color: var(--warn); background: var(--warn-soft); }
.chip.bad { color: var(--bad); background: var(--bad-soft); }
code { font-family: var(--f-mono); font-size: 0.92em; }

.eqintro { margin: 0 0 12px; color: var(--ink-2); max-width: 90ch; }
.eqgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); gap: 14px; }
.eqcard {
  background: var(--canvas-bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.eqcard h3 { font-family: var(--f-display); font-weight: 600; font-size: 0.95rem; margin: 0 0 4px; }
.eqcard p { margin: 6px 0 0; color: var(--ink-2); font-size: 0.84rem; }
.eq { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.eq .katex-display { margin: 0.35em 0; }
.katex { font-size: 1.08em; }
.eqcard p .katex, .eqintro .katex { font-size: 1em; }

footer.site { color: var(--muted); font-size: 0.8rem; }
footer.site a { color: var(--ink-2); }
a { color: var(--copper); text-underline-offset: 2px; }
a:hover { color: var(--ink); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* proton page */
.crumb { margin: 0 0 6px; font-size: 0.85rem; }
.crumb a, section.panel a, .after-eq a { color: var(--copper); }
.stage.one { grid-template-columns: 1fr; }
.stage.trio { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1000px) { .stage.trio { grid-template-columns: 1fr 1fr; } }
@media (max-width: 880px) { .stage.trio { grid-template-columns: 1fr; } }
.canvas-box.short { aspect-ratio: 16 / 5; }
@media (max-width: 880px) { .canvas-box.short { aspect-ratio: 16 / 9; } }
.stage.one .canvas-box:not(.short) { aspect-ratio: 16 / 7; }
@media (max-width: 880px) { .stage.one .canvas-box:not(.short) { aspect-ratio: 16 / 11; } }
.canvas-box.mid { aspect-ratio: 16 / 8; }
.ramp { display: inline-block; width: 100px; height: 8px; border-radius: 2px; }
.ramp-label { font-family: var(--f-mono); font-size: 0.78rem; }
.legend-line .group { display: inline-flex; align-items: center; gap: 6px; }
.sw.dot-m { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.sw.ring { width: 9px; height: 9px; border-radius: 50%; background: none; border: 2px solid var(--ink-2); box-sizing: border-box; }
.sw.band { width: 14px; height: 10px; opacity: 0.3; }
.sw.line { height: 3px; border-radius: 1px; background: currentColor; }
.tablewrap { overflow-x: auto; margin-top: 14px; }
.eptable { border-collapse: collapse; width: 100%; font-size: 0.86rem; color: var(--ink-2); }
.eptable th { text-align: left; font: 500 0.72rem var(--f-display); text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); padding: 4px 10px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.eptable td { padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.eptable td.num, .eptable td.when { font-family: var(--f-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.eptable tbody tr { cursor: pointer; }
.eptable tbody tr:hover td { background: var(--canvas-bg); }
.eptable tbody tr[aria-selected="true"] td { background: var(--copper-soft); color: var(--ink); }
.eptable .epbtn { font: 600 0.86rem var(--f-mono); width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid currentColor; background: transparent; cursor: pointer; padding: 0; }
.eptable .what { display: block; color: var(--muted); font-size: 0.8rem; }
.eptable .kind { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; }
.findings, ul.plain { margin: 14px 0 0; padding-left: 18px; color: var(--ink-2); max-width: 95ch; display: grid; gap: 6px; }
ul.plain { margin-top: 0; }
.after-eq { margin: 8px 0 12px; color: var(--ink-2); max-width: 90ch; }
section.panel > .eq { margin: 6px 0; overflow-x: auto; }
.ctl.wide { flex: 1 1 320px; }
.ctl.wide .row { flex-wrap: nowrap; }
.ctl.wide input[type="range"] { flex: 1 1 auto; width: auto; min-width: 0; }
#pValue { min-width: 4.5em; text-align: right; }
.ctl.pol .row { flex-wrap: nowrap; }
.ctl.pol input[type="number"] { width: 6.5em; }
.ctl.pol input[type="range"] { width: 170px; }
@media (max-width: 560px) { .ctl.pol { flex: 1 1 100%; } .ctl.pol input[type="range"] { flex: 1 1 auto; width: auto; min-width: 0; } }
