/* ---------- fonts (self-hosted, OFL) ---------- */
@font-face { font-family: "Schibsted Grotesk"; font-weight: 400; font-style: normal; font-display: swap; src: url("../fonts/schibsted-grotesk-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Schibsted Grotesk"; font-weight: 500; font-style: normal; font-display: swap; src: url("../fonts/schibsted-grotesk-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Schibsted Grotesk"; font-weight: 600; font-style: normal; font-display: swap; src: url("../fonts/schibsted-grotesk-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Schibsted Grotesk"; font-weight: 700; font-style: normal; font-display: swap; src: url("../fonts/schibsted-grotesk-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "STIX Two Text"; font-weight: 400; font-style: normal; font-display: swap; src: url("../fonts/stix-two-text-latin-400-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212, U+2215; }
@font-face { font-family: "STIX Two Text"; font-weight: 400; font-style: italic; font-display: swap; src: url("../fonts/stix-two-text-latin-400-italic.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212, U+2215; }
@font-face { font-family: "STIX Two Text"; font-weight: 500; font-style: normal; font-display: swap; src: url("../fonts/stix-two-text-latin-500-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+2212; }
@font-face { font-family: "STIX Two Text"; font-weight: 500; font-style: italic; font-display: swap; src: url("../fonts/stix-two-text-latin-500-italic.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+2212; }
@font-face { font-family: "STIX Two Text"; font-weight: 400; font-style: normal; font-display: swap; src: url("../fonts/stix-two-text-greek-400-normal.woff2") format("woff2"); unicode-range: U+0370-03FF; }
@font-face { font-family: "STIX Two Text"; font-weight: 400; font-style: italic; font-display: swap; src: url("../fonts/stix-two-text-greek-400-italic.woff2") format("woff2"); unicode-range: U+0370-03FF; }

/* ---------- tokens ---------- */
:root {
  --bg: #060912;
  --bg-deep: #03050b;
  --panel: rgba(12, 17, 33, 0.72);
  --line: rgba(150, 170, 230, 0.12);
  --line-strong: rgba(150, 170, 230, 0.22);
  --text: #e8ecf8;
  --dim: #8a94ad;
  --faint: #78829e;
  --control: #5b6480;   /* form-control edges, 3:1 against --bg */
  --band: #f3f6ff;
  --ef: #ffc857;
  --electron: #5cc8ff;
  --hole: #ff6b8b;
  --field: #b69cff;
  --diff: #ff5ccf;
  --rgc: #8ef0c4;
  --left: 268px;
  --right: 252px;
  --header: 64px;
  --ui: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --math: "STIX Two Text", "STIX Two Math", "Cambria Math", "Times New Roman", serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font: 400 15px/1.5 var(--ui);
  background:
    radial-gradient(1100px 620px at 52% 34%, rgba(38, 58, 120, 0.28), transparent 70%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
h2 { margin: 0 0 12px; font-size: 13px; font-weight: 600; color: var(--dim); letter-spacing: 0.01em; }
sup, sub { font-size: 0.72em; line-height: 0; }
:focus-visible { outline: 2px solid var(--ef); outline-offset: 2px; }
::selection { background: rgba(255, 200, 87, 0.28); color: var(--text); }
html { scrollbar-color: rgba(150, 170, 230, 0.28) transparent; }
h1, h2, h3 { text-wrap: balance; }

.mi { font-family: var(--math); font-style: italic; font-size: 1.12em; padding-right: 0.04em; }
.mr { font-family: var(--math); font-style: normal; }
sub.mr, sup.mr { font-size: 0.7em; }
.mu { font-family: var(--ui); }
.hint { color: var(--faint); font-size: 12px; font-weight: 500; margin-left: 4px; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--header);
  display: grid;
  grid-template-columns: var(--left) minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 0 22px;
  background: rgba(6, 9, 18, 0.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark { width: 30px; height: 30px; flex: none; }
.bm-band { stroke: var(--band); stroke-width: 2.2; fill: none; stroke-linecap: round; filter: drop-shadow(0 0 3px rgba(170, 196, 255, 0.9)); }
.bm-ef { stroke: var(--ef); stroke-width: 1.6; stroke-linecap: round; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { white-space: nowrap; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.brand-tag { font-size: 12px; color: var(--dim); }

.material-picker { display: flex; justify-content: center; gap: 4px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.material-picker::-webkit-scrollbar { display: none; }
.mat {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 70px; padding: 6px 10px 5px;
  border: 1px solid transparent; border-radius: 10px;
  background: none; cursor: pointer; line-height: 1.1;
  transition: background-color 0.15s, border-color 0.15s;
}
.mat:hover { background: rgba(150, 170, 230, 0.07); }
.mat .sym { font-size: 16px; font-weight: 600; }
.mat .eg { font-size: 11px; color: var(--faint); margin-top: 2px; white-space: nowrap; }
.mat[aria-checked="true"] { border-color: var(--line-strong); background: rgba(243, 246, 255, 0.07); box-shadow: inset 0 -2px 0 var(--band); }
.mat[aria-checked="true"] .eg { color: var(--dim); }

.segmented { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--line); border-radius: 11px; background: rgba(3, 5, 11, 0.6); }
.segmented button {
  border: 0; background: none; padding: 7px 14px; border-radius: 8px;
  color: var(--dim); font-weight: 500; cursor: pointer; white-space: nowrap;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-checked="true"] { background: rgba(243, 246, 255, 0.1); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-strong); }
.segmented.small { display: flex; margin-bottom: 16px; }
.segmented.small button { flex: 1; padding: 6px 8px; font-size: 13px; }

/* ---------- workspace ---------- */
.workspace {
  display: grid;
  grid-template-columns: var(--left) minmax(0, 1fr) var(--right);
  align-items: start;
}
.controls, .bias { padding: 20px 22px 28px; }
.controls { border-right: 1px solid var(--line); min-height: calc(100vh - var(--header)); }
.bias {
  border-left: 1px solid var(--line);
  position: sticky; top: var(--header);
  height: calc(100vh - var(--header));
  overflow-y: auto; scrollbar-width: thin;
  display: flex; flex-direction: column; gap: 10px;
}
.bias > *, .bias-ui > *, .rg-ui > * { flex: none; }
.stage { padding: 18px 20px 28px; min-width: 0; }

.group + .group { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }

/* range fields */
.range-field { display: block; }
.range-field + .range-field { margin-top: 14px; }
.range-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0 8px; margin-bottom: 4px; }
.range-name { font-size: 14px; }
.range-field output { font-size: 14px; font-weight: 500; }
.range-scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--faint); margin-top: 2px; }
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 24px; margin: 0; background: none; cursor: pointer;
  --fill: var(--band);
}
.side-p input[type="range"] { --fill: var(--hole); }
.side-n input[type="range"] { --fill: var(--electron); }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, var(--fill) var(--p, 50%), rgba(150, 170, 230, 0.16) var(--p, 50%)); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: rgba(150, 170, 230, 0.16); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--fill); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--fill); box-shadow: 0 0 10px color-mix(in srgb, var(--fill) 60%, transparent);
}
input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--fill); box-shadow: 0 0 10px color-mix(in srgb, var(--fill) 60%, transparent);
}

.presets { display: flex; gap: 6px; margin-top: 14px; }
.presets button, .ghost {
  border: 1px solid var(--line-strong); background: none; border-radius: 8px;
  padding: 5px 10px; font-size: 13px; color: var(--dim); cursor: pointer;
}
.presets button { flex: 1; }
.presets button:hover, .ghost:hover { color: var(--text); border-color: var(--line-strong); }

/* switches */
.toggles { display: grid; gap: 10px; }
.switch { display: flex; align-items: center; gap: 10px; font-size: 14px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { position: relative; width: 30px; height: 18px; border-radius: 9px; background: rgba(150, 170, 230, 0.18); flex: none; transition: background-color 0.15s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--dim); transition: transform 0.15s, background-color 0.15s; }
.switch input:checked + .track { background: rgba(243, 246, 255, 0.24); }
.switch input:checked + .track::after { transform: translateX(12px); background: var(--band); box-shadow: 0 0 8px rgba(170, 196, 255, 0.8); }
.switch input:focus-visible + .track { outline: 2px solid var(--ef); outline-offset: 2px; }
.switch.disabled { opacity: 0.4; cursor: default; }

/* material properties */
.props { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
.props dt { color: var(--dim); }
.props dd { margin: 0; text-align: right; font-weight: 500; }
.props-note { margin: 10px 0 0; font-size: 12px; color: var(--faint); line-height: 1.45; }

/* ---------- figure ---------- */
.figure {
  margin: 0;
  display: flex; flex-direction: column;
  height: clamp(520px, calc(100vh - var(--header) - 132px), 860px);
  border: 1px solid var(--line);
  border-radius: 16px;
  background:
    radial-gradient(70% 60% at 50% 45%, rgba(40, 62, 130, 0.22), transparent 75%),
    rgba(3, 5, 11, 0.72);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4), 0 30px 80px -40px rgba(60, 100, 220, 0.35);
  overflow: hidden;
}
.figure canvas { display: block; flex: 1; width: 100%; min-height: 0; touch-action: pan-y; }
.legend {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 20px;
  padding: 10px 16px 12px; border-top: 1px solid var(--line);
  font-size: 13px; color: var(--dim);
}
.legend .item { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.sw { display: inline-block; width: 22px; height: 0; border-top: 2px solid; }
.sw.band { border-color: var(--band); box-shadow: 0 0 6px rgba(170, 196, 255, 0.9); }
.sw.ei { border-top: 2px dashed rgba(225, 232, 255, 0.6); }
.sw.ef { border-color: var(--ef); box-shadow: 0 0 6px rgba(255, 200, 87, 0.8); }
.sw.fn { border-top: 2px dashed var(--electron); }
.sw.fp { border-top: 2px dashed var(--hole); }
.sw.diff { border-top: 2.5px solid var(--diff); box-shadow: 0 0 6px rgba(255, 92, 207, 0.6); }
.sw.drift { border-top: 2.5px dashed var(--field); }
.t-diff { color: var(--diff); }
.t-drift { color: var(--field); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--electron); box-shadow: 0 0 8px var(--electron); display: inline-block; }
.ring { width: 9px; height: 9px; border-radius: 50%; border: 1.6px solid var(--hole); box-shadow: 0 0 8px var(--hole); display: inline-block; }
.legend .note { margin-left: auto; color: var(--faint); font-size: 12px; }

/* ---------- readouts ---------- */
.readouts {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.metric { padding: 10px 14px 12px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric-label { font-size: 14px; color: var(--dim); white-space: nowrap; }
.metric-value { font-size: clamp(16px, 1.32vw, 21px); font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; margin-top: 2px; }
.metric-label .u { font-family: var(--ui); font-size: 12px; color: var(--faint); margin-left: 4px; }
.metric-value .unit { font-size: 13px; font-weight: 500; color: var(--dim); margin-left: 3px; }
.metric.accent .metric-value { color: var(--band); text-shadow: 0 0 14px rgba(170, 196, 255, 0.55); }

.notice {
  margin: 12px 0 0; padding: 10px 14px;
  border: 1px solid rgba(255, 200, 87, 0.3); background: rgba(255, 200, 87, 0.06);
  border-radius: 8px; font-size: 13px; color: #f0e2bf;
}

/* ---------- equations ---------- */
.equations { margin-top: 26px; }
.equations h2 { margin-bottom: 4px; }
.eq-intro { margin: 0 0 12px; font-size: 13px; color: var(--faint); }
.eq-row {
  display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) auto;
  gap: 18px; align-items: center;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.eq { font-family: var(--math); font-size: 19px; line-height: 1.4; white-space: nowrap; overflow-x: auto; scrollbar-width: thin; }
.eq .mi { font-size: 1em; }
.eq-val { font-size: 14px; color: var(--dim); line-height: 1.5; }
.eq-val b { color: var(--text); font-weight: 600; }
.eq-ref { font-size: 12px; color: var(--faint); white-space: nowrap; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 0.15em; font-size: 0.92em; line-height: 1.15; }
.frac > span:first-child { border-bottom: 1px solid currentColor; padding: 0 0.2em 0.06em; }
.frac > span:last-child { padding: 0.08em 0.2em 0; }
.big { font-size: 1.5em; vertical-align: -0.12em; font-weight: 300; }

/* ---------- applied-voltage panel ---------- */
.bias h2 { margin-bottom: 6px; }
.va-readout { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.va-readout .mi { font-size: 1em; }
.va-readout .unit { font-size: 16px; color: var(--dim); font-weight: 500; margin-left: 4px; }
.bias-state { margin: 6px 0 0; font-size: 13px; color: var(--dim); line-height: 1.45; min-height: 4.4em; }
.bias-state strong { color: var(--text); font-weight: 600; }

.vslider { height: clamp(190px, 30vh, 330px); display: flex; justify-content: center; padding: 10px 0; }
.vs-track { position: relative; width: 120px; height: 100%; cursor: pointer; touch-action: none; }
.vs-rail { position: absolute; left: 70%; top: 0; bottom: 0; width: 6px; transform: translateX(-50%); border-radius: 3px; background: rgba(150, 170, 230, 0.14); }
.vs-fill { position: absolute; left: 70%; width: 6px; transform: translateX(-50%); bottom: var(--lo); height: calc(var(--hi) - var(--lo)); border-radius: 3px; }
.vslider[data-bias="forward"] .vs-fill { background: var(--ef); box-shadow: 0 0 12px rgba(255, 200, 87, 0.7); }
.vslider[data-bias="reverse"] .vs-fill { background: var(--field); box-shadow: 0 0 12px rgba(182, 156, 255, 0.7); }
.vs-thumb {
  position: absolute; left: 70%; bottom: var(--t);
  width: 24px; height: 24px; transform: translate(-50%, 50%);
  border-radius: 50%; background: var(--band);
  box-shadow: 0 0 0 4px rgba(6, 9, 18, 0.9), 0 0 18px rgba(170, 196, 255, 0.9);
  transition: transform 0.12s;
}
.vslider.dragging .vs-thumb { transform: translate(-50%, 50%) scale(1.12); }
.vs-thumb:focus-visible { outline: 2px solid var(--ef); outline-offset: 5px; }
.vs-tick { position: absolute; left: 0; right: 30%; bottom: var(--t); height: 0; display: flex; align-items: center; justify-content: flex-end; pointer-events: none; }
.vs-tick span { font-size: 12px; color: var(--faint); margin-right: 14px; transform: translateY(-1px); }
.vs-tick::after { content: ""; width: 8px; border-top: 1px solid var(--line-strong); margin-right: 3px; }
.vs-tick.zero span { color: var(--text); font-weight: 600; }
.vs-tick.zero::after { width: 14px; border-color: var(--band); }
#va-zero { align-self: center; }

/* currents */
.currents { border-top: 1px solid var(--line); padding-top: 14px; }
.currents h2 { margin-bottom: 10px; }
.cur-row { display: grid; grid-template-columns: 14px 1fr auto; gap: 2px 10px; align-items: center; padding: 4px 0; }
.cur-name { font-size: 13px; }
.cur-flow { grid-column: 2 / 4; font-size: 11px; color: var(--faint); margin-top: -3px; }
.cur-dir { width: 34px; height: 12px; }
.cur-bar { grid-column: 2 / 4; height: 3px; margin-top: 2px; border-radius: 2px; background: rgba(150, 170, 230, 0.12); overflow: hidden; }
.cur-bar i { display: block; height: 100%; border-radius: 2px; }
.cur-val { grid-column: 2 / 4; font-size: 12px; color: var(--dim); margin-top: -1px; }
.cur-net { margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.cur-net .eqline { font-family: var(--math); font-size: 16px; }
.cur-net .eqline .mi { font-size: 1em; }
.cur-net .value { font-size: 20px; font-weight: 600; margin-top: 4px; }
.cur-net .value .unit { font-size: 12px; color: var(--dim); font-weight: 500; margin-left: 3px; }
.cur-net .dirtext { font-size: 12px; color: var(--dim); }
.cur-note { font-size: 11px; color: var(--faint); margin: 10px 0 0; line-height: 1.45; }

.footnote { padding: 18px 22px 32px; border-top: 1px solid var(--line); }
.footnote p { margin: 0 auto; max-width: 78ch; font-size: 12.5px; line-height: 1.6; color: var(--faint); text-align: center; }
.footnote cite { font-style: italic; color: var(--dim); }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  :root { --left: 248px; }
  .topbar { grid-template-columns: auto minmax(0, 1fr) auto; }
  .workspace {
    grid-template-columns: var(--left) minmax(0, 1fr);
    grid-template-areas: "controls figure" "controls bias" "controls readouts" "controls notice" "controls equations";
  }
  .stage { display: contents; }
  .controls { grid-area: controls; grid-row: 1 / 6; }
  .figure { grid-area: figure; margin: 18px 20px 0; height: clamp(540px, 74vh, 780px); }
  .readouts { grid-area: readouts; margin: 14px 20px 0; }
  .notice { grid-area: notice; margin: 12px 20px 0; }
  .equations { grid-area: equations; margin: 26px 20px 28px; }
  .bias {
    grid-area: bias; position: static; min-height: 0; height: auto; overflow: visible; border-left: 0;
    margin: 14px 20px 0; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px;
    display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 4px 24px;
  }
  .bias-head { grid-column: 1; grid-row: 1 / 3; }
  .vslider { grid-column: 2; height: 64px; padding: 0 4px; }
  #va-zero { grid-column: 2; justify-self: end; }
  .currents { grid-column: 1 / 3; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(0, 1.3fr); gap: 0 20px; align-items: start; }
  .currents h2 { grid-column: 1 / -1; }
  .cur-net { margin-top: 0; padding-top: 6px; border-top: 0; }
  .cur-note { grid-column: 1 / -1; }

  /* horizontal slider */
  .vs-track { width: 100%; height: 100%; }
  .vs-rail { left: 0; right: 0; top: 34%; bottom: auto; width: auto; height: 6px; transform: translateY(-50%); }
  .vs-fill { left: var(--lo); width: calc(var(--hi) - var(--lo)); top: 34%; bottom: auto; height: 6px; transform: translateY(-50%); }
  .vs-thumb { left: var(--t); top: 34%; bottom: auto; transform: translate(-50%, -50%); }
  .vslider.dragging .vs-thumb { transform: translate(-50%, -50%) scale(1.12); }
  .vs-tick { left: var(--t); right: auto; bottom: auto; top: 34%; width: 0; height: auto; flex-direction: column; justify-content: flex-start; }
  .vs-tick::after { order: -1; width: 0; height: 8px; border-top: 0; border-left: 1px solid var(--line-strong); margin: 8px 0 0; }
  .vs-tick.zero::after { width: 0; height: 12px; border-left-color: var(--band); }
  .vs-tick span { margin: 2px 0 0; transform: none; white-space: nowrap; }
}

@media (max-width: 820px) {
  .topbar { height: auto; grid-template-columns: 1fr auto; padding: 10px 14px; row-gap: 8px; position: static; }
  .material-picker { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; }
  .brand-tag { display: none; }
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-areas: "figure" "bias" "readouts" "notice" "controls" "equations"; }
  .controls { grid-row: auto; border-right: 0; min-height: 0; margin: 14px 16px 0; padding: 16px; border: 1px solid var(--line); border-radius: 12px; }
  .figure { margin: 12px 16px 0; height: clamp(440px, 74vh, 620px); }
  .readouts, .notice { margin-left: 16px; margin-right: 16px; }
  .equations { margin: 24px 16px 24px; }
  .bias { margin: 12px 16px 0; grid-template-columns: 1fr; }
  .bias-head, .vslider, #va-zero { grid-column: 1; grid-row: auto; }
  .currents { grid-column: 1; grid-template-columns: 1fr 1fr; gap: 0 16px; }
  .cur-net { grid-column: 1 / -1; }
  .readouts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric { border-bottom: 1px solid var(--line); padding: 8px 10px 10px; }
  .metric:nth-child(3n) { border-right: 0; }
  .metric:nth-child(n+4) { border-bottom: 0; }
  .metric-value { font-size: 17px; }
  .eq-row { grid-template-columns: 1fr; gap: 4px; }
  .legend .note { margin-left: 0; }
  .mat { min-width: 60px; }
  .mode-switch button { padding: 6px 10px; font-size: 13px; }
  .brand-mark { width: 26px; height: 26px; }
  .brand-name { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- material table-value card ---------- */
.mat-card {
  position: fixed; z-index: 40; width: 260px;
  padding: 12px 14px 10px;
  background: rgba(10, 14, 28, 0.97);
  border: 1px solid var(--line-strong); border-radius: 12px;
  box-shadow: 0 18px 50px -12px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}
.mc-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.mc-sym { font-size: 18px; font-weight: 700; }
.mc-name { font-size: 13px; color: var(--dim); }
.mc-t { margin-left: auto; font-size: 12px; color: var(--faint); }
.mc-rows { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; font-size: 13px; }
.mc-rows dt { color: var(--dim); }
.mc-rows dd { margin: 0; text-align: right; font-weight: 500; }
.mc-src { margin: 8px 0 0; font-size: 11px; color: var(--faint); line-height: 1.4; }

/* ---------- diagram hover readout ---------- */
.figure { position: relative; }
.probe {
  position: absolute; z-index: 5; width: 250px;
  padding: 10px 12px;
  background: rgba(8, 11, 22, 0.97);
  border: 1px solid var(--line-strong); border-radius: 10px;
  box-shadow: 0 14px 40px -10px rgba(0, 0, 0, 0.8);
  font-size: 12.5px; pointer-events: none;
}
.pr-region { color: var(--text); font-weight: 600; font-size: 12.5px; line-height: 1.35; }
.pr-x { color: var(--dim); font-size: 12px; margin-top: 2px; }
.pr-rows { margin-top: 6px; display: grid; gap: 2px; }
.pr-row { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 0 8px; padding: 1px 4px; border-radius: 5px; }
.pr-row.near { background: rgba(243, 246, 255, 0.07); }
.pr-sw { width: 8px; height: 2px; border-radius: 1px; }
.pr-name { font-size: 14px; }
.pr-val { color: var(--dim); }
.pr-row.near .pr-val { color: var(--text); font-weight: 600; }
.pr-desc { grid-column: 2 / 4; color: var(--dim); font-size: 11.5px; }
.pr-carriers { display: flex; gap: 10px; margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); color: var(--dim); }
.pr-carriers .u { color: var(--faint); }
.pr-field { color: var(--dim); margin-top: 2px; }

/* ---------- slider extra mark ---------- */
.vs-tick.vbi span { color: var(--ef); font-weight: 500; }
.vs-tick.vbi::after { border-color: rgba(255, 200, 87, 0.7); width: 12px; }

/* ---------- I-V curve ---------- */
.iv { border-top: 1px solid var(--line); padding-top: 12px; }
.iv-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.iv-head h2 { margin: 0; }
.segmented.tiny { padding: 2px; border-radius: 8px; }
.segmented.tiny button { padding: 3px 8px; font-size: 12px; border-radius: 6px; }
#iv-canvas { display: block; width: 100%; height: 132px; }
.iv-caption { margin: 4px 0 0; font-size: 11px; color: var(--faint); line-height: 1.4; }

/* ---------- currents grouped by mechanism ---------- */
.mech { padding: 6px 0 4px; }
.mech + .mech { border-top: 1px dashed var(--line); margin-top: 4px; }
.mech-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0 8px; font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.mech-diff .mech-head { color: var(--diff); }
.mech-drift .mech-head { color: var(--field); }
.mech-head .sw { width: 16px; }
.mech-why { flex-basis: 100%; padding-left: 24px; font-weight: 400; color: var(--faint); font-size: 11.5px; }
.mech-why .mi { font-size: 1.05em; }

@media (max-width: 1180px) {
  .currents { grid-template-columns: repeat(2, minmax(0, 1fr)) minmax(0, 1fr); gap: 0 20px; }
  .mech + .mech { border-top: 0; margin-top: 0; }
  .iv { grid-column: 1 / 3; }
}
@media (max-width: 820px) {
  .currents { grid-template-columns: 1fr; }
  .mat-card { display: none; }
}

/* ---------- legend glyphs for R–G ---------- */
.trap-sq { width: 9px; height: 9px; border: 1.6px solid var(--rgc); box-shadow: 0 0 6px rgba(142, 240, 196, 0.7); display: inline-block; }
.wave { width: 22px; height: 8px; display: inline-block; background: no-repeat center / 22px 8px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 8'%3E%3Cpath d='M1 4 Q3.5 0 6 4 T11 4 T16 4 T21 4' fill='none' stroke='%23fff1a8' stroke-width='1.6'/%3E%3C/svg%3E"); }
.zig { width: 22px; height: 8px; display: inline-block; background: no-repeat center / 22px 8px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 8'%3E%3Cpath d='M1 6 L4 2 L7 6 L10 2 L13 6 L16 2 L19 6' fill='none' stroke='%23ffb35c' stroke-width='1.5'/%3E%3C/svg%3E"); }
.t-rg { color: var(--rgc); }

/* ---------- carrier story tooltip ---------- */
.probe.story { width: 270px; }
.probe .tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; margin: 0 4px 6px 0; border: 1px solid currentColor; }
.probe .tag.t-diff { color: var(--diff); }
.probe .tag.t-drift { color: var(--field); }
.probe .tag.t-rand { color: var(--dim); }
.probe .tag.t-rg { color: var(--rgc); }
.st-title { font-size: 13.5px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.probe p { margin: 0; color: var(--dim); line-height: 1.45; }
.probe .st-foot { margin-top: 6px; color: var(--faint); font-size: 11.5px; }

/* ---------- R–G tab ---------- */
.bias-ui { display: contents; }
.rg-ui { display: flex; flex-direction: column; gap: 16px; }
.rg-grid { display: grid; grid-template-columns: auto 1fr 1fr; gap: 6px; align-items: stretch; }
.rg-col { font-size: 11.5px; color: var(--faint); text-align: center; align-self: end; }
.rg-row { font-size: 12.5px; color: var(--dim); align-self: center; line-height: 1.2; }
.rg-grid button {
  border: 1px solid var(--line); background: rgba(3, 5, 11, 0.6); border-radius: 8px;
  padding: 7px 4px; font-size: 12px; color: var(--dim); cursor: pointer; line-height: 1.2;
}
.rg-grid button:hover { color: var(--text); border-color: var(--line-strong); }
.rg-grid button[aria-checked="true"] { color: var(--text); background: rgba(142, 240, 196, 0.1); border-color: rgba(142, 240, 196, 0.6); box-shadow: 0 0 12px -2px rgba(142, 240, 196, 0.4); }
.rg-rates { border-top: 1px solid var(--line); padding-top: 14px; }
.rate-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 5px 0; }
.rate-name { font-size: 12.5px; color: var(--dim); }
.rate-row.dom .rate-name { color: var(--text); font-weight: 600; }
.rate-row.dom .rate-name::after { content: "dominant"; margin-left: 6px; font-size: 10.5px; font-weight: 600; color: var(--rgc); }
.rate-val { font-size: 12px; color: var(--text); }
.rate-row .cur-bar { grid-column: 1 / -1; }
.metric-value.txt { font-size: clamp(15px, 1.15vw, 18px); }
.eq-note { font-size: 12px; color: var(--faint); font-family: var(--ui); margin-left: 6px; }
.rg-presets button { font-size: 12px; padding: 5px 6px; }
.range-field.trap input[type="range"] { --fill: var(--rgc); }
#rg-controls .range-field + .range-field, #rg-controls .presets + .range-field { margin-top: 14px; }
#rg-controls .presets { margin-top: 10px; }

.rg-steps { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.6fr); gap: 4px 24px; padding: 12px 16px; border-top: 1px solid var(--line); }
.rg-title strong { display: block; font-size: 14px; margin-bottom: 2px; }
.rg-title .rg-note { font-size: 12.5px; color: var(--dim); line-height: 1.45; display: block; }
.rg-list { margin: 0; padding-left: 20px; display: grid; gap: 4px; align-content: start; font-size: 13px; color: var(--faint); }
.rg-step { padding: 2px 6px; border-radius: 6px; transition: color 0.2s, background-color 0.2s; }
.rg-step.on { color: var(--text); background: rgba(142, 240, 196, 0.08); }
.rg-step::marker { color: var(--faint); }
.rg-step.on::marker { color: var(--rgc); }
body[data-mode="rg"] .figure { height: clamp(560px, calc(100vh - var(--header) - 120px), 880px); }

@media (max-width: 1180px) {
  .rg-ui { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 24px; }
  .rg-rates { border-top: 0; padding-top: 0; }
}
@media (max-width: 820px) {
  .rg-ui { grid-template-columns: 1fr; gap: 14px; }
  .rg-steps { grid-template-columns: 1fr; }
  .mode-switch button { padding: 6px 8px; font-size: 12.5px; }
}

.metric-sub { font-size: 11.5px; color: var(--dim); margin-top: 1px; white-space: nowrap; }
.rg-steps { flex: none; }

.mode-switch .sm { display: none; }
@media (max-width: 1180px) {
  .mode-switch .lg { display: none; }
  .mode-switch .sm { display: inline; }
}

/* ---------- typed values ---------- */
.num {
  font: inherit; font-weight: 500; color: var(--text);
  background: rgba(3, 5, 11, 0.6);
  border: 1px solid var(--control); border-radius: 6px;
  padding: 1px 4px; text-align: right; caret-color: var(--ef);
  -moz-appearance: textfield; appearance: textfield;
  transition: border-color 0.15s, background-color 0.15s;
}
.num::-webkit-outer-spin-button, .num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.num:hover { border-color: var(--dim); }
.num:focus { outline: none; border-color: var(--ef); background: rgba(255, 200, 87, 0.06); }
.sci-in, .num-in { display: inline-flex; align-items: baseline; gap: 3px; font-size: 14px; white-space: nowrap; }
.sci-in .mant { width: 3.4em; }
.sci-in .exp { width: 2.4em; font-size: 0.78em; text-align: center; transform: translateY(-0.45em); padding: 0 2px; }
.sci-in .x { color: var(--dim); }
.sci-in .u, .num-in .u { color: var(--dim); font-size: 12.5px; margin-left: 2px; }
.num-in .num { width: 4.4em; }
.range-sub { display: block; font-size: 12.5px; color: var(--dim); margin: -2px 0 2px; min-height: 1.5em; }

.va-readout { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.va-in { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; width: 3.9em; padding: 0 6px; line-height: 1.1; }
.va-readout .unit { margin-left: 0; }

/* the bias description sits below the slider, so its changing length
   never moves the slider while it is being dragged */
@media (min-width: 1181px), (max-width: 820px) {
  .bias-head { display: contents; }
  .bias-state { order: 1; margin: 0; flex: none; }
  .bias .iv, .bias .currents { order: 2; }
}
@media (max-width: 820px) {
  .bias .iv, .bias .currents, .bias h2, .va-readout, .bias-state { grid-column: 1; }
}
@media (min-width: 821px) and (max-width: 1180px) { .bias-state { min-height: 7.4em; } }

/* legend entries that don't apply right now stay in place, dimmed */
.legend .item.off { opacity: 0.3; }

/* ---------- header: mode switch + About ---------- */
.top-right { display: flex; align-items: center; gap: 14px; }
.about-link { color: var(--dim); text-decoration: none; font-size: 14px; font-weight: 500; padding: 6px 4px; white-space: nowrap; }
.about-link:hover { color: var(--text); }

/* ---------- About ---------- */
html { scroll-behavior: smooth; }
.about { border-top: 1px solid var(--line); padding: 44px 22px 40px; scroll-margin-top: var(--header); }
.about-inner { max-width: 68ch; margin: 0 auto; }
.about h2 { font-size: 22px; color: var(--text); font-weight: 700; letter-spacing: -0.01em; margin-bottom: 14px; }
.about p { margin: 0 0 14px; color: #c3cadc; font-size: 15.5px; line-height: 1.65; }
.about-cta {
  display: inline-flex; align-items: center; gap: 10px; margin-top: 6px;
  padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--line-strong); color: var(--text); text-decoration: none; font-weight: 600; font-size: 14px;
  background: rgba(243, 246, 255, 0.05);
  transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.about-cta svg { width: 18px; height: 18px; }
.about-cta:hover { background: rgba(243, 246, 255, 0.1); border-color: var(--band); box-shadow: 0 0 18px -4px rgba(170, 196, 255, 0.6); }

@media (max-width: 820px) {
  .top-right { gap: 8px; }
  .about { padding: 32px 16px; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

/* narrow phones: make room for the longer name and the About link */
@media (max-width: 480px) {
  .topbar { padding: 10px 12px; column-gap: 8px; }
  .brand { gap: 8px; }
  .brand-mark { width: 22px; height: 22px; }
  .brand-name { font-size: 15px; }
  .top-right { gap: 6px; }
  .mode-switch button { padding: 5px 7px; font-size: 12px; }
  .about-link { font-size: 13px; padding: 4px 2px; }
}

/* touch screens: bigger targets, and 16px inputs so phones don't zoom on focus */
@media (pointer: coarse) {
  .presets button, .ghost, .rg-grid button { min-height: 40px; }
  .segmented button { min-height: 38px; }
  .segmented.tiny button { min-height: 32px; }
  .about-link { padding-top: 10px; padding-bottom: 10px; }
  .mat { min-height: 44px; }
  .num { font-size: 16px; }
  .sci-in .exp { font-size: 13px; }
  input[type="range"] { height: 32px; }
  input[type="range"]::-webkit-slider-thumb { width: 22px; height: 22px; margin-top: -9px; }
  input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; }
}
