/* Dark tokens: the page by default, and any dark export drawn from a light page. */
:root,
.snap-dark {
  --bg: #090b10;
  --bg-elev: #12151c;
  --bg-inset: #0b0d12;
  --bg-well: #171b24;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --amber: #f3b63a;
  --amber-soft: rgba(243, 182, 58, 0.14);
  --cyan: #4fd6c8;
  --cyan-soft: rgba(79, 214, 200, 0.14);
  --text: #f2f1ea;
  --muted: #9aa1ae;
  --dim: #6b7382;
  --danger: #ef6a5c;
  --plus: #f3b63a;
  --minus: #7aa2ff;
  /* Port identity. Literal values, not aliases, so a quantity keeps its colour even on
     pages where --accent flips with the drive mode, and so scripts can read them back. */
  --port-in: #f3b63a;
  --port-out: #4fd6c8;
  --accent: var(--amber);
  --accent-soft: var(--amber-soft);
  --scroll-fade: rgba(255, 255, 255, 0.16);
  /* Depth comes from a one-pixel edge highlight and soft shadows, never from blur. */
  --edge: rgba(255, 255, 255, 0.05);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.35), 0 24px 48px -28px rgba(0, 0, 0, 0.7);
  --shadow-control: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 1px 1px rgba(0, 0, 0, 0.25);
  --shadow-inset: inset 0 1px 2px rgba(0, 0, 0, 0.3);
  --surface-card: var(--bg-elev);
  --font-ui: "IBM Plex Sans", "Segoe UI", sans-serif;
  --font-display: Sora, "IBM Plex Sans", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.38);
}

body[data-drive="diff"] {
  --accent: var(--cyan);
  --accent-soft: var(--cyan-soft);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

:root[data-theme="light"] {
  color-scheme: light;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-ui);
  color: var(--text);
  line-height: 1.45;
  background-color: var(--bg);
  background-image:
    radial-gradient(900px 480px at 8% -8%, rgba(243, 182, 58, 0.1), transparent 55%),
    radial-gradient(800px 420px at 100% 0%, rgba(79, 214, 200, 0.08), transparent 50%);
  -webkit-font-smoothing: antialiased;
}

[data-theme="light"] body {
  background-image:
    radial-gradient(900px 480px at 8% -8%, rgba(180, 83, 9, 0.07), transparent 55%),
    radial-gradient(800px 420px at 100% 0%, rgba(15, 118, 110, 0.06), transparent 50%);
  -webkit-font-smoothing: auto;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.skip {
  position: absolute;
  left: -999px;
  top: 0;
}

.skip:focus {
  left: 12px;
  top: 12px;
  z-index: 20;
  background: var(--bg-elev);
  padding: 8px 12px;
  border-radius: 8px;
}

.shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 72px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding: 12px 12px;
  margin: 0 -12px 18px;
  border-bottom: 1px solid var(--line);
}

@media (max-width: 700px) {
  .top {
    margin: 0 0 18px;
    padding: 12px 4px;
  }
}

/* The one glass gesture: on a desktop the header stays put and blurs what scrolls beneath it. */
@media (min-width: 701px) {
  .top {
    position: sticky;
    top: 0;
    z-index: 30;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: blur(14px) saturate(140%);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
  }
}

.wordmark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.16em;
  color: var(--text);
  text-decoration: none;
}

.wordmark span {
  color: var(--amber);
}

nav {
  order: 2;
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
  font-size: 0.86rem;
  font-weight: 500;
}

nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 999px;
}

nav a.is-active {
  color: var(--accent);
  background: var(--accent-soft);
}

/* One round button at the top right cycles Auto, Light and Dark. */
.theme-button {
  order: 3;
  margin-left: 4px;
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--bg-well);
  color: var(--muted);
  box-shadow: var(--shadow-control);
  cursor: pointer;
}

.theme-button:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

.theme-button svg {
  width: 18px;
  height: 18px;
}

@media (max-width: 700px) {
  nav {
    order: 3;
    flex-basis: 100%;
    margin-left: 0;
  }

  .theme-button {
    order: 2;
    margin-left: auto;
  }
}

nav a:hover {
  color: var(--text);
  text-decoration: none;
}

.lede {
  margin: 0 0 22px;
}

.kicker {
  font-family: var(--font-display);
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 8px;
}

h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(2rem, 4vw, 2.9rem);
  letter-spacing: -0.035em;
  margin: 0 0 10px;
}

.lede p {
  margin: 0;
  max-width: 40rem;
  color: var(--muted);
}

.board {
  background: var(--surface-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 var(--edge), var(--shadow-card);
  padding: 22px 22px 20px;
  margin-bottom: 22px;
}

.board-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.board-toolbar + .board-toolbar {
  margin-top: -8px;
}

.seg {
  display: inline-flex;
  flex-wrap: wrap;
  padding: 3px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-inset);
}

.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  pointer-events: auto;
  position: relative;
  z-index: 1;
}

.seg-btn.is-active {
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 90%, #ffffff), var(--accent));
  color: #14120c;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.z-ctrl {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.z-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.z-block {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  box-shadow: inset 0 1px 0 var(--edge);
}

.z-fixed {
  gap: 10px;
}

.z-fixed-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.z-fixed strong {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 500;
}

.z-fixed-note {
  color: var(--dim);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.node-z {
  display: block;
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--accent);
}

@media (max-width: 640px) {
  .z-pair {
    grid-template-columns: 1fr;
  }
}

.z-field {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.z-field input {
  width: 4.6rem;
  background: var(--bg-well);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  padding: 8px 8px;
  border-radius: 10px;
  box-shadow: var(--shadow-inset);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  min-width: 36px;
  padding: 7px 8px;
  background: var(--bg-well);
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  border-radius: 10px;
  box-shadow: var(--shadow-control);
  cursor: pointer;
}

.chip.is-active {
  color: #14120c;
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 90%, #ffffff), var(--accent));
  border-color: var(--accent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.schematic-stage {
  background:
    linear-gradient(rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    var(--bg-inset);
  background-size: 24px 24px, 24px 24px, auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: inset 0 1px 0 var(--edge);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 16px;
}

.schematic {
  margin: 0;
  padding: 16px 18px 18px;
  min-width: 680px;
}

.schematic.is-off,
.schematic[hidden] {
  display: none;
}

.schematic-cap {
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 0 0 14px;
}

/* ----- Block diagrams. js/diagram.js draws every page's diagram as HTML: blocks joined by
   buses, each bus carrying one or two rails. Placement is inline from the builder; the widths
   here reflow for a phone. Wires, arrows and boxes are structure; colour belongs to quantities,
   so a rail is neutral unless it carries a polarity or the page's drive colour. */
.blk {
  --block-w: 176px;
  --mid-w: 150px;
  --bus-min: 180px;
  display: grid;
  column-gap: 0;
  position: relative;
}

.blk[data-rails="1"] {
  grid-template-rows: auto 88px auto;
}

.blk[data-rails="2"] {
  grid-template-rows: auto 78px 78px auto;
}

/* Three blocks share the width, so their minimums are tighter; the buses still stretch. */
.blk[data-blocks="3"] {
  --block-w: 136px;
  --mid-w: 130px;
  --bus-min: 90px;
}

.blk[data-mid="wide"] {
  --mid-w: 190px;
}

.blk-shell {
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(23, 27, 36, 0.92);
  box-shadow: inset 0 1px 0 var(--edge), 0 10px 24px -14px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

.blk-shell.edge-in {
  box-shadow: inset 3px 0 0 var(--port-in), inset 0 1px 0 var(--edge), 0 10px 24px -14px rgba(0, 0, 0, 0.6);
}

.blk-shell.edge-out {
  box-shadow: inset -3px 0 0 var(--port-out), inset 0 1px 0 var(--edge), 0 10px 24px -14px rgba(0, 0, 0, 0.6);
}

.blk-head,
.blk-port,
.blk-foot,
.blk-bus,
.blk-midcap,
.bus-brace {
  position: relative;
  z-index: 1;
}

.blk-head {
  padding: 14px 14px 4px;
  min-width: 0;
}

.node-kicker {
  display: block;
  font-size: 0.64rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
}

.node-title {
  display: block;
  font-family: var(--font-display);
  font-size: 1.2rem;
  letter-spacing: -0.01em;
  font-weight: 600;
  margin-top: 2px;
}

.node-sub {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.blk-port {
  display: flex;
  z-index: 2;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  min-width: 0;
}

.src-port {
  justify-content: flex-end;
  justify-self: end;
}

.dut-port {
  justify-content: flex-start;
  justify-self: start;
}

.blk-port em {
  font-style: normal;
}

.blk-port.plus,
.blk-port.plus em {
  color: var(--plus);
}

.blk-port.minus,
.blk-port.minus em {
  color: var(--minus);
}

.nub {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--bg-well);
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 3px var(--bg-well);
  flex: 0 0 auto;
  position: relative;
}

.src-port .nub {
  margin-right: -19px;
}

.dut-port .nub {
  margin-left: -19px;
}

.plus .nub {
  border-color: var(--plus);
}

.minus .nub {
  border-color: var(--minus);
}

.neutral .nub {
  border-color: var(--line-strong);
}

.blk-bus {
  display: grid;
  /* minmax(0, 1fr) keeps the outer rows equal so the wire stays on the nub centre line. */
  grid-template-rows: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  justify-items: center;
  min-width: 0;
  /* 8px is the nub radius plus its ring, so the wire meets each nub exactly. */
  padding: 0 8px;
}

.rail-tag,
.rail-sub {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  min-width: 0;
}

.rail-tag {
  align-self: end;
  padding-bottom: 6px;
  color: var(--accent);
}

.rail-sub {
  align-self: start;
  padding-top: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.plus .rail-tag {
  color: var(--plus);
}

.minus .rail-tag {
  color: var(--minus);
}

.neutral .rail-tag {
  color: var(--muted);
}

.bus-track {
  display: flex;
  align-items: center;
  width: 100%;
}

.wire {
  display: block;
  flex: 1;
  height: 2px;
  background: var(--accent);
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 40%, transparent);
}

.arrow {
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 8px solid var(--accent);
}

.plus .wire {
  background: var(--plus);
  box-shadow: 0 0 10px color-mix(in srgb, var(--plus) 40%, transparent);
}

.plus .arrow {
  border-left-color: var(--plus);
}

.minus .wire {
  background: var(--minus);
  box-shadow: 0 0 10px color-mix(in srgb, var(--minus) 40%, transparent);
}

.minus .arrow {
  border-left-color: var(--minus);
}

.neutral .wire {
  background: var(--line-strong);
  box-shadow: none;
}

.neutral .arrow {
  border-left-color: var(--line-strong);
}

/* A single-ended rail can show its reference: a tap down to ground, labelled with the voltage. */
.rail-tap,
.rail-ground {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--dim);
}

.rail-tap::before,
.rail-ground::before {
  content: '';
  width: 1.5px;
  height: 12px;
  background: currentColor;
}

.rail-tap.side-in {
  color: var(--port-in);
}

.rail-tap.side-out {
  color: var(--port-out);
}

.rail-tap .gnd,
.rail-ground .gnd {
  color: var(--dim);
}

.gnd {
  width: 24px;
  height: 12px;
  color: var(--dim);
  display: block;
}

.blk-foot {
  padding: 8px 14px 14px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--muted);
  min-width: 0;
}

.blk-foot .gnd {
  margin-top: 8px;
}

.node-readout {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.node-readout span {
  font-size: 0.64rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
}

.node-readout strong {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.blk-midcap {
  align-self: center;
  justify-self: start;
  margin-left: 12px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  color: var(--dim);
  background: var(--bg-well);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  z-index: 2;
}

/* A brace across a pair of rails, at the end of the bus, with its quantity beside it. */
.bus-brace {
  justify-self: end;
  align-self: stretch;
  width: 12px;
  margin: 12px 14px 12px 0;
  border: 1px solid var(--port-out);
  border-left: 0;
  pointer-events: none;
  z-index: 2;
}

.bus-brace.side-in {
  border-color: var(--port-in);
}

.bus-callout {
  position: absolute;
  top: 50%;
  right: calc(100% + 8px);
  transform: translateY(-50%);
  display: block;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--port-out);
  line-height: 1.15;
  white-space: nowrap;
}

.side-in .bus-callout {
  color: var(--port-in);
}

.bus-callout .callout-kicker,
.bus-callout strong {
  display: block;
}

.bus-callout sub,
.bus-callout sup,
.rail-tap sub,
.rail-tap sup,
.blk-port sub,
.blk-port sup,
.node-sub sub {
  font-size: 0.72em;
  line-height: 0;
}

.bus-callout .callout-kicker {
  font-family: var(--font-ui);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
}

.bus-callout strong {
  font-family: var(--font-mono);
  font-size: 0.92rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.fields {
  display: grid;
  gap: 12px;
}

@media (min-width: 720px) {
  .fields {
    grid-template-columns: 1fr 1fr;
  }
}

.field {
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px 16px;
  box-shadow: inset 0 1px 0 var(--edge);
}

.field-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.64rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field input[type="text"] {
  flex: 1;
  min-width: 0;
  font-variant-numeric: tabular-nums;
  background: transparent;
  border: 0;
  outline: none;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 500;
  line-height: 1.1;
  padding: 4px 0;
}

.unit,
.unit-select {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--muted);
}

.unit-select {
  appearance: none;
  background: var(--bg-well);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 7px 10px;
  border-radius: 10px;
  box-shadow: var(--shadow-control);
  font: inherit;
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

.step {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border: 1px solid var(--line);
  background: var(--bg-well);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 1.1rem;
  border-radius: 10px;
  box-shadow: var(--shadow-control);
  cursor: pointer;
}

.step:hover,
.unit-select:hover,
.chip:hover,
.seg-btn:hover,
.copy:hover,
.ghost:hover {
  border-color: var(--line-strong);
}

.step:focus-visible,
.chip:focus-visible,
.seg-btn:focus-visible,
.copy:focus-visible,
.ghost:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.step:active,
.chip:active,
.seg-btn:active {
  transform: translateY(1px);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.metric {
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px 13px;
  margin: 0;
  box-shadow: inset 0 1px 0 var(--edge);
}

.metric dt {
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 0 0 4px;
}

.metric dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 1.08rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* A tile's second line restates the answer in the decibel domain. It is the same result, not
   another factor, so it is written as an equation on a line of its own. */
.metric-sub {
  display: block;
  margin-top: 5px;
  font-size: 0.78rem;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.metric.primary .metric-sub {
  font-size: 0.88rem;
}

/* One answer per calculator, so the eye lands on it before the supporting numbers. */
.metric.primary {
  grid-column: 1 / -1;
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  background: linear-gradient(180deg, var(--accent-soft), transparent 75%), var(--surface-card);
  padding: 16px 18px;
}

.metric.primary dt {
  color: var(--accent);
}

.metric.primary dd {
  font-size: 1.75rem;
  letter-spacing: -0.01em;
  margin-top: 2px;
}

/* A quantity that belongs to a port carries that port's colour everywhere it appears. */
.metric.port-in {
  border-left: 3px solid var(--port-in);
}

.metric.port-out {
  border-left: 3px solid var(--port-out);
}

.tint-in,
.node-readout strong.tint-in,
.vopp-callout strong.tint-in {
  color: var(--port-in);
}

.tint-out,
.node-readout strong.tint-out,
.vopp-callout strong.tint-out {
  color: var(--port-out);
}

.colour-key {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  align-items: baseline;
}

.colour-key .key {
  font-family: var(--font-mono);
  border-left: 3px solid var(--line-strong);
  padding-left: 7px;
  color: var(--text);
}

.colour-key .key-in {
  border-left-color: var(--port-in);
  color: var(--port-in);
}

.colour-key .key-out {
  border-left-color: var(--port-out);
  color: var(--port-out);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}

.export-tools {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.export-theme {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--dim);
}

/* The image menu: a button that opens a short list beneath it. */
.export-menu {
  position: relative;
  display: inline-block;
}

.export-menu > summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.export-menu > summary::-webkit-details-marker {
  display: none;
}

.export-menu > summary::after {
  content: '';
  width: 6px;
  height: 6px;
  margin-left: 9px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  opacity: 0.6;
}

.export-menu[open] > summary {
  background: var(--bg-elev);
  border-color: var(--line-strong);
}

.menu-list {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 25;
  min-width: 210px;
  padding: 6px;
  display: grid;
  gap: 2px;
  background: var(--surface-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: inset 0 1px 0 var(--edge), var(--shadow-card);
}

.menu-list button {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 0.86rem;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 8px 10px 8px 32px;
  cursor: pointer;
}

.menu-list button:hover {
  background: var(--bg-inset);
}

.menu-list button:disabled {
  opacity: 0.45;
  cursor: default;
}

.menu-list .export-theme {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  padding: 8px 6px 2px 10px;
  border-top: 1px solid var(--line);
}

.export-theme select {
  padding: 5px 8px;
  font-size: 0.8rem;
}

/* ----- Exported images. A header names the page and the DUT, a footer the address and date.
   The light theme redefines the tokens for paper; the few literal colours follow below. */
.snap {
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  padding: 22px 24px 18px;
  box-sizing: border-box;
}

/* Light tokens: the light page, and any light export drawn from a dark page. */
:root[data-theme="light"],
.snap-light {
  --bg: #ffffff;
  --bg-elev: #f6f7f9;
  --bg-inset: #f1f3f6;
  --bg-well: #e7eaef;
  --line: rgba(0, 0, 0, 0.12);
  --line-strong: rgba(0, 0, 0, 0.3);
  --amber: #b45309;
  --amber-soft: rgba(180, 83, 9, 0.12);
  --cyan: #0f766e;
  --cyan-soft: rgba(15, 118, 110, 0.12);
  --text: #161a22;
  --muted: #4a5261;
  --dim: #6b7280;
  --danger: #b42318;
  --plus: #b45309;
  --minus: #2f5fd0;
  --port-in: #b45309;
  --port-out: #0f766e;
  --accent: var(--amber);
  --accent-soft: var(--amber-soft);
  --scroll-fade: rgba(0, 0, 0, 0.22);
  --edge: #ffffff;
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.06), 0 24px 48px -30px rgba(16, 24, 40, 0.28);
  --shadow-control: inset 0 1px 0 #ffffff, 0 1px 1px rgba(16, 24, 40, 0.08);
  --shadow-inset: inset 0 1px 2px rgba(16, 24, 40, 0.06);
  --surface-card: #ffffff;
  --shadow: none;
}

/* Literal colours that the tokens do not reach, in light and dark pairs. The dark pair comes
   last so a dark export from a light page wins over the page's own light rule. */
[data-theme="light"] .blk-shell,
.snap-light .blk-shell {
  background: #ffffff;
}

[data-theme="light"] .schematic-stage,
.snap-light .schematic-stage {
  background:
    linear-gradient(rgba(0, 0, 0, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.05) 1px, transparent 1px),
    var(--bg-inset);
  background-size: 20px 20px, 20px 20px, auto;
}

[data-theme="light"] .seg-btn.is-active,
[data-theme="light"] .chip.is-active,
.snap-light .seg-btn.is-active,
.snap-light .chip.is-active {
  color: #ffffff;
}

.snap-dark .blk-shell {
  background: rgba(23, 27, 36, 0.92);
}

.snap-dark .schematic-stage {
  background:
    linear-gradient(rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    var(--bg-inset);
  background-size: 20px 20px, 20px 20px, auto;
}

.snap-dark .seg-btn.is-active,
.snap-dark .chip.is-active {
  color: #14120c;
}

.snap-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding-bottom: 10px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.snap-brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.16em;
}

.snap-brand span {
  color: var(--amber);
}

.snap-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  text-align: right;
}

.snap-dut,
.snap-caption {
  margin: 0 0 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
}

.snap-label {
  display: inline-block;
  margin-right: 8px;
  font: 600 10px var(--font-display);
  letter-spacing: 0.16em;
  color: var(--dim);
}

.snap-body {
  margin-top: 14px;
}

.snap-body > * + * {
  margin-top: 12px;
}

.snap-body .metrics {
  margin-top: 12px;
}

.snap-body .chain-results,
.snap .equation-math,
.snap .gain-result,
.snap .power-path,
.snap .schematic-stage {
  overflow: visible;
}

.snap-foot {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin: 18px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--dim);
}

.snap-value {
  font-family: var(--font-mono);
}

.calculation-export > p {
  font-size: 14px;
  line-height: 1.7;
}

.copy,
.ghost,
.link-button {
  appearance: none;
  background: var(--bg-well);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 8px 12px;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 500;
  border-radius: 10px;
  box-shadow: var(--shadow-control);
  cursor: pointer;
}

.copy:hover,
.ghost:hover,
.link-button:hover {
  background: var(--bg-elev);
}

/* Icons are masks in the current colour, so they follow the theme and the hover state. */
[data-icon] {
  position: relative;
  padding-left: 32px;
}

[data-icon]::before {
  content: '';
  position: absolute;
  left: 10px;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  background: currentColor;
  opacity: 0.75;
  -webkit-mask: var(--icon) center / contain no-repeat;
  mask: var(--icon) center / contain no-repeat;
}

[data-icon="copy"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='12' height='12' rx='2'/%3E%3Cpath d='M5 15V5a2 2 0 0 1 2-2h10'/%3E%3C/svg%3E"); }
[data-icon="link"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10 13a5 5 0 0 0 7.5.5l3-3a5 5 0 0 0-7-7l-1.5 1.5'/%3E%3Cpath d='M14 11a5 5 0 0 0-7.5-.5l-3 3a5 5 0 0 0 7 7l1.5-1.5'/%3E%3C/svg%3E"); }
[data-icon="image"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='16' rx='2'/%3E%3Ccircle cx='9' cy='10' r='2'/%3E%3Cpath d='M21 16l-5-5-8 8'/%3E%3C/svg%3E"); }
[data-icon="table"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='16' rx='2'/%3E%3Cpath d='M3 10h18M3 15h18M10 4v16'/%3E%3C/svg%3E"); }
[data-icon="math"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 5H8l6 7-6 7h10'/%3E%3C/svg%3E"); }
[data-icon="gain"] { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 18L20 6M13 6h7v7'/%3E%3C/svg%3E"); }

.copy.is-copied {
  color: var(--accent);
  border-color: var(--accent);
}

.layout {
  display: grid;
  gap: 16px;
}

@media (max-width: 700px) {
  .schematic {
    min-width: 0;
    padding: 12px 10px 14px;
  }

  .blk {
    --block-w: 88px;
    --mid-w: 84px;
    --bus-min: 0px;
  }

  .blk[data-blocks="3"] {
    --block-w: 78px;
    --mid-w: 74px;
    --bus-min: 0px;
  }

  .blk[data-mid="wide"] {
    --mid-w: 92px;
  }

  .blk[data-rails="1"] {
    grid-template-rows: auto 92px auto;
  }

  .blk[data-rails="2"] {
    grid-template-rows: auto 70px 70px auto;
  }

  .blk-head {
    padding: 10px 8px 4px;
  }

  .blk-foot {
    padding: 6px 8px 10px;
  }

  .blk-port {
    padding: 0 6px;
    gap: 5px;
    font-size: 0.64rem;
  }

  .src-port .nub {
    margin-right: -11px;
  }

  .dut-port .nub {
    margin-left: -11px;
  }

  .rail-tag,
  .rail-sub {
    font-size: 0.6rem;
    line-height: 1.35;
  }

  .node-title {
    font-size: 0.92rem;
  }

  .node-kicker {
    font-size: 0.55rem;
    letter-spacing: 0.1em;
  }

  .node-sub {
    font-size: 0.66rem;
  }

  .node-z {
    font-size: 0.6rem;
    margin-top: 4px;
  }

  .node-readout strong {
    font-size: 0.86rem;
  }

  .blk-midcap {
    margin-left: 4px;
    font-size: 0.58rem;
    padding: 2px 5px;
    letter-spacing: 0.08em;
  }

  .bus-brace {
    margin-right: 4px;
  }

  .bus-callout {
    font-size: 0.6rem;
  }

  .bus-callout strong {
    font-size: 0.72rem;
  }
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

.panel,
.ref {
  background: var(--surface-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 var(--edge), var(--shadow-card);
  padding: 18px 20px 20px;
}

.panel h2,
.ref h2 {
  font-family: var(--font-display);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  margin: 0 0 12px;
}

.panel p,
.panel li {
  color: var(--muted);
  font-size: 0.92rem;
}

.panel ul {
  margin: 0;
  padding-left: 1.1rem;
}

.formula {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 0 0 12px;
  overflow-x: auto;
}

.formula .sym {
  color: var(--accent);
}

.ref {
  margin-top: 16px;
  padding-bottom: 8px;
}

.ref-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 8px;
}

.ref p {
  margin: 0;
  color: var(--dim);
  font-size: 0.8rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.88rem;
}

/* Columns are centred so a heading sits over its numbers. Prose tables stay left. */
th,
td {
  text-align: center;
  padding: 9px 6px;
  border-bottom: 1px solid var(--line);
}

.thumbs th,
.thumbs td {
  text-align: left;
}

/* A reference table scrolls inside its own frame so the heading above it stays put. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.refs td:first-child {
  white-space: nowrap;
}

@media (max-width: 700px) {
  .phone-hide {
    display: none;
  }

  .refs th,
  .refs td {
    padding-left: 4px;
    padding-right: 4px;
  }

  th {
    font-size: 0.62rem;
    letter-spacing: 0.06em;
  }
}

th {
  color: var(--dim);
  white-space: nowrap;
  font-weight: 500;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

td.num {
  color: var(--text);
  white-space: nowrap;
}

/* Sideways-scroll cue: an inset shadow on the side that has more. It sits on the wrapper
   itself, so it stays put while the table moves. */
@media (max-width: 700px) {
  .ref {
    padding-left: 12px;
    padding-right: 12px;
  }

  table {
    font-size: 0.82rem;
  }

  th,
  td {
    padding: 9px 5px;
  }
}

[data-scroll="right"] {
  box-shadow: inset -34px 0 24px -24px var(--scroll-fade);
}

[data-scroll="left"] {
  box-shadow: inset 34px 0 24px -24px var(--scroll-fade);
}

[data-scroll="left right"] {
  box-shadow: inset 34px 0 24px -24px var(--scroll-fade), inset -34px 0 24px -24px var(--scroll-fade);
}

.foot {
  margin-top: 28px;
  color: var(--dim);
  font-size: 0.8rem;
}

body,
.board,
.panel,
.ref,
.metric,
.field,
.z-block,
.top {
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

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

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: var(--bg-elev);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 10px 14px;
  font-size: 0.85rem;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-on {
  opacity: 1;
  transform: none;
}

.invalid input[type="text"] {
  color: var(--danger);
}

noscript {
  display: block;
  margin: 16px auto;
  width: min(1120px, calc(100% - 32px));
  border: 1px solid var(--danger);
  padding: 12px 14px;
  color: var(--text);
  border-radius: 10px;
}

@media (max-width: 640px) {
  .shell {
    width: min(1120px, calc(100% - 20px));
  }

  .field input[type="text"] {
    font-size: 1.5rem;
  }

  .metrics {
    grid-template-columns: 1fr;
  }

  .board {
    padding: 14px;
  }
}

.field.compact input[type="text"] {
  font-size: 1.45rem;
}

.ls-panel[hidden] {
  display: none;
}

.hint {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 12px 0 0;
}

.board + .board {
  margin-top: 16px;
}

.thumbs td {
  color: var(--muted);
}

.thumbs td.num {
  color: var(--text);
}

/* On a phone a rule of thumb becomes a card: item, the thumb, then why it matters. Three
   narrow columns would wrap every value and unit onto separate lines. */
@media (max-width: 700px) {
  .thumbs thead {
    display: none;
  }

  .thumbs tr {
    display: block;
    padding: 10px 0 12px;
    border-bottom: 1px solid var(--line);
  }

  .thumbs td {
    display: block;
    padding: 2px 0;
    border: 0;
  }

  .thumbs td:first-child {
    font-family: var(--font-display);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
  }

  .thumbs td.num {
    white-space: normal;
    color: var(--accent);
  }
}

.spec-svg {
  width: 100%;
  height: auto;
  margin: 6px 0 14px;
}

.spec-svg .grid {
  stroke: var(--line);
  stroke-width: 1;
}

.spec-svg .baseline {
  stroke: var(--line-strong);
  stroke-width: 1.4;
}

.spec-svg .tone-bar {
  fill: var(--accent);
}

.spec-svg .im3-bar {
  fill: var(--cyan);
}

.spec-svg .tick {
  stroke: var(--muted);
  stroke-width: 2;
}

.spec-svg .delta {
  stroke: var(--cyan);
  stroke-width: 1.2;
  fill: none;
}

.spec-svg text {
  fill: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
}

.spec-svg text.tone {
  fill: var(--accent);
}

.spec-svg text.im3 {
  fill: var(--cyan);
}

.chart-wrap {
  margin-top: 16px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 12px 8px;
}

.chart-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.chart-cap {
  margin: 0;
  color: var(--dim);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chart-wrap svg {
  width: 100%;
  height: auto;
  display: block;
  cursor: crosshair;
}

.chart-wrap svg text {
  fill: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
}

@media (prefers-reduced-motion: reduce) {
  .step:active,
  .chip:active,
  .seg-btn:active,
  .toast {
    transition: none;
    transform: none;
  }
}
