/* PanPhyCircuits: layout and interface. Colors map onto the Spectrum tokens in
   /assets/design.css; component artwork carries its own physical colors. */

:root {
  --bench: #E7EAF0;
  --bench-dot: rgba(40, 52, 84, 0.16);
  --sch-paper: #FFFFFF;
  --sch-grid: rgba(40, 60, 120, 0.07);
  --sch-grid-major: rgba(40, 60, 120, 0.13);
  --sch-ink: #1B2230;
  --sch-wire-black: #2A2D33;
  --sch-wire-white: #697386;
  --sch-accent: #1C64D8;
  --select: #1C64D8;
  --select-soft: rgba(28, 100, 216, 0.14);
  --target: #0F9D58;
  --warn-ring: #D9480F;
  --appbar-h: 56px;
  --panel-w: 264px;
  --insp-w: 300px;
  --tool-size: 38px;
  /* Graph paper behind the panes, as in PanPhyTrack and PanPhyPlot. */
  --paper-minor: rgba(28, 40, 90, 0.035);
  --paper-major: rgba(28, 40, 90, 0.075);
}

[data-theme="dark"] {
  --bench: #171B23;
  --bench-dot: rgba(170, 190, 255, 0.13);
  --sch-paper: #0F1218;
  --sch-grid: rgba(150, 175, 255, 0.06);
  --sch-grid-major: rgba(150, 175, 255, 0.11);
  --sch-ink: #E3E8F2;
  --sch-wire-black: #8993A3;
  --sch-wire-white: #F2F4F7;
  --sch-accent: #54A6FF;
  --select: #54A6FF;
  --select-soft: rgba(84, 166, 255, 0.18);
  --target: #4FDB98;
  --warn-ring: #FF8A4C;
  --paper-minor: rgba(150, 175, 255, 0.03);
  --paper-major: rgba(150, 175, 255, 0.065);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  overflow: hidden; color: var(--ink); font-family: var(--font-body); -webkit-font-smoothing: antialiased;
  background-color: var(--bg);
  background-image: linear-gradient(var(--paper-major) 1px, transparent 1px), linear-gradient(90deg, var(--paper-major) 1px, transparent 1px),
    linear-gradient(var(--paper-minor) 1px, transparent 1px), linear-gradient(90deg, var(--paper-minor) 1px, transparent 1px);
  background-size: 30px 30px, 30px 30px, 6px 6px, 6px 6px;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.defs-host { position: absolute; width: 0; height: 0; overflow: hidden; }

/* The suite shell: app bar, panes on graph paper, one status bar. */
.app { --statusbar-h: 32px; height: 100%; display: flex; flex-direction: column; }

/* ---------- App bar ---------- */

.appbar {
  position: relative; flex: none; display: flex; align-items: center; gap: 14px; z-index: 20;
  min-height: calc(var(--appbar-h) + var(--standalone-top, 0px));
  padding: var(--standalone-top, 0px) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
/* One thin spectrum line under the app bar marks the app as PanPhy. */
.appbar::after { content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--spectrum); opacity: 0.85; pointer-events: none; }
.brand { display: inline-flex; align-items: center; gap: 9px; min-width: 0; }
.brand a { display: inline-flex; }
.brand img { display: block; width: 30px; height: 30px; }
.wordmark { margin: 0; font-family: var(--font-display); font-size: 1.02rem; font-weight: 600; letter-spacing: -0.03em; white-space: nowrap; }
.appbar-actions { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.appbar-group { display: flex; align-items: center; gap: 2px; margin-right: 6px; padding-right: 6px; border-right: 1px solid var(--line); }
a.atool { text-decoration: none; }
.atool {
  display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 6px 9px; border: 1px solid transparent; border-radius: 10px;
  background: none; color: var(--ink); font-weight: 600; font-size: 0.86rem; white-space: nowrap; cursor: pointer;
}
.atool:hover, .atool[aria-expanded="true"] { background: var(--surface-3); }
.atool .icon { width: 18px; height: 18px; color: var(--accent); }
.atool-quiet { color: var(--ink-2); }
.atool-quiet .icon { color: inherit; }
.atool .icon-chevron { width: 14px; height: 14px; margin-left: -3px; color: var(--ink-3); }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-2); z-index: 50; }
.menu button { display: block; width: 100%; text-align: left; min-height: 40px; padding: 8px 12px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; font-size: 0.9rem; }
.menu button:hover, .menu button:focus-visible { background: var(--accent-soft); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 4px; }

/* ---------- Panes ---------- */

.main { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: var(--panel-w) minmax(0, 1fr) var(--insp-w); gap: 12px; padding: 12px; }
.pane {
  position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-1); overflow: hidden;
}
.pane-head { flex: none; display: flex; align-items: center; gap: 12px; min-width: 0; min-height: 52px; padding: 8px 12px 8px 16px; border-bottom: 1px solid var(--line); }
.pane-title { display: flex; align-items: baseline; gap: 12px; min-width: 0; flex: 1; }
.pane-heading { margin: 0; font-family: var(--font-display); font-weight: 500; font-size: 0.98rem; letter-spacing: -0.02em; white-space: nowrap; }
.pane-hint { margin: 0; min-width: 0; font-size: 0.8rem; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-spacer { flex: 1; }
.panel-top { display: none; align-items: center; justify-content: space-between; padding: 4px 4px 8px; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn.panel-close { display: none; }

/* View toggle: a segmented control with a sliding accent thumb. Both halves
   share one width, so the thumb slides without anything resizing. */
.view-switch {
  position: relative; display: inline-grid; grid-template-columns: 1fr 1fr; padding: 3px; border-radius: 999px;
  background: var(--surface-3); border: 1px solid var(--line); box-shadow: inset 0 1px 3px rgba(11, 13, 20, 0.08);
}
.view-switch::before {
  content: ''; position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc(50% - 3px); border-radius: 999px;
  background: var(--accent); box-shadow: 0 2px 10px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: transform 0.22s cubic-bezier(0.3, 0.7, 0.3, 1);
}
.view-switch[data-view="schematic"]::before { transform: translateX(100%); }
.view-switch button {
  position: relative; z-index: 1; display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 34px; padding: 4px 14px;
  border: 0; border-radius: 999px; background: transparent; color: var(--ink-2); font-weight: 700; font-size: 0.84rem; cursor: pointer; white-space: nowrap;
  transition: color 0.18s;
}
.view-switch button .icon { width: 18px; height: 18px; }
.view-switch button[aria-pressed="true"] { color: var(--accent-ink); }
.view-switch button:hover:not([aria-pressed="true"]) { color: var(--ink); }
.view-switch button:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

.flow-note { position: absolute; right: 12px; bottom: 54px; z-index: 4; max-width: calc(100% - 24px); padding: 4px 8px; border-radius: 6px; background: var(--surface); color: var(--ink-2); font-size: 0.7rem; pointer-events: auto; }

/* Pause/resume control and live or paused state in the canvas corner. */
.sim-status {
  position: absolute; right: 12px; bottom: 12px; z-index: 4; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 4px 8px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-1);
  font-size: 0.75rem; color: var(--ink-2);
}
/* With nothing to pause, the chip is a plain status label, not a button. */
.sim-status[data-state="live"] { background: transparent; border-color: transparent; box-shadow: none; cursor: help; }
/* Fixed widths so changing text never shifts anything. */
.sim-state { display: inline-block; width: 3.9em; }
.chip-btn { display: inline-grid; place-items: center; width: 24px; height: 24px; flex: 0 0 24px; margin: 0; padding: 0; line-height: 1; border: 0; border-radius: 50%; background: none; color: var(--ink-2); cursor: pointer; }
.chip-btn .icon { display: block; width: 18px; height: 18px; }
.chip-btn:hover { background: var(--surface-3); color: var(--ink); }
.chip-btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.chip-pause { background: var(--good); color: #fff; }
.chip-pause:hover { background: color-mix(in srgb, var(--good) 85%, #000); color: #fff; }
[data-theme="dark"] .chip-pause { color: #04150C; }
.chip-pause[aria-pressed="false"] { background: var(--warn); }
.chip-pause .icon { width: 14px; height: 14px; stroke: none; }
/* The inspector uses a plain status/action row, separate from the canvas pill. */
.sim-controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; padding-bottom: 12px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.sim-summary { display: inline-flex; align-items: center; gap: 8px; font-size: 0.9rem; font-weight: 600; color: var(--ink); }
.sim-run { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-width: 104px; min-height: 48px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--surface-2); color: var(--ink); font-size: 0.84rem; font-weight: 600; cursor: pointer; }
.sim-run .icon { width: 16px; height: 16px; stroke: none; color: var(--accent); }
.sim-run:hover { background: var(--surface-3); border-color: var(--accent); }
.sim-run:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.simulation-card .row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 16px; min-height: 48px; }
.simulation-card .row select { justify-self: stretch; width: 100%; max-width: none; }
.simulation-card .row > label { min-width: 5em; }
.simulation-card .btn-secondary { margin-top: 10px; width: 100%; min-height: 40px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2, var(--panel)); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.simulation-card .btn-secondary:hover { border-color: var(--ink-3); }
.sim-paused .ppc-spin, .sim-paused .ppc-buzz, .sim-paused .ppc-waves { animation-play-state: paused; }
.status-dot { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; background: var(--ink-3); }
:is(.sim-status, .sim-controls)[data-state="running"] .status-dot { background: var(--good); box-shadow: 0 0 0 2px color-mix(in srgb, var(--good) 25%, transparent); animation: pulse 1.4s ease-in-out infinite; }
:is(.sim-status, .sim-controls)[data-state="behind"] .status-dot { background: var(--warn); }
:is(.sim-status, .sim-controls)[data-state="live"] .status-dot { background: var(--accent); }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--good) 0%, transparent); } }

/* Library */
.lib-head { padding: 10px 12px; display: grid; gap: 10px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.search { display: flex; align-items: center; gap: 8px; padding: 0 12px; min-height: 42px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-3); }
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; color: var(--ink); font-size: 0.92rem; }
.lib-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.lib-filters .ds-chip { cursor: pointer; min-height: 32px; padding: 0.3rem 0.7rem; font-size: 0.64rem; }
.lib-list { flex: 1; overflow-y: auto; padding: 4px 12px 16px; overscroll-behavior: contain; }
.lib-group h2 { margin: 14px 2px 8px; }
.lib-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 6px 7px; min-height: 92px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
  transition: border-color 0.12s, background-color 0.12s, transform 0.12s;
}
.card:hover { border-color: var(--line-strong); background: var(--surface); }
.card:active { cursor: grabbing; }
.card.is-armed { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent-soft); }
.card-art { width: 100%; height: 56px; overflow: visible; }
.card-name { font-size: 0.74rem; font-weight: 650; text-align: center; line-height: 1.15; color: var(--ink); }
.lib-empty { color: var(--ink-3); font-size: 0.88rem; padding: 14px 2px; }
.drag-ghost { position: fixed; left: 0; top: 0; width: 80px; height: 60px; pointer-events: none; z-index: 100; opacity: 0.85; filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.25)); }
.drag-ghost svg { width: 100%; height: 100%; overflow: visible; }

/* ---------- Stage and workspace ---------- */

.stage { min-width: 0; min-height: 0; }
.stage-head { gap: 14px; }
.stage-head .tool-panel { flex: 0 0 var(--tool-size); }
.workspace {
  --grid: 20px; --grid5: 100px;
  position: relative; flex: 1 1 auto; min-height: 220px; overflow: hidden; outline: none; touch-action: none;
  background-color: var(--bench);
}
.workspace.view-realistic { background-image: radial-gradient(circle, var(--bench-dot) 1.1px, transparent 1.4px); background-size: var(--grid) var(--grid); }
.workspace.view-schematic {
  background-color: var(--sch-paper);
  background-image: linear-gradient(var(--sch-grid-major) 1px, transparent 1px), linear-gradient(90deg, var(--sch-grid-major) 1px, transparent 1px),
    linear-gradient(var(--sch-grid) 1px, transparent 1px), linear-gradient(90deg, var(--sch-grid) 1px, transparent 1px);
  background-size: var(--grid5) var(--grid5), var(--grid5) var(--grid5), var(--grid) var(--grid), var(--grid) var(--grid);
}
.workspace[data-zoom="far"].view-realistic { background-image: none; }
.workspace:focus-visible { box-shadow: inset 0 0 0 3px var(--focus); }
.ws-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; user-select: none; -webkit-user-select: none; }
.workspace[data-active-tool="pan"] .ws-svg, .workspace.is-panning .ws-svg { cursor: grab; }
.workspace.is-panning .ws-svg { cursor: grabbing; }
.workspace.is-placing .ws-svg, .workspace.is-wiring .ws-svg, .workspace[data-active-tool="wire"] .ws-svg { cursor: crosshair; }

/* Components */
.comp .hit { fill: transparent; }
.comp { cursor: move; }
.workspace[data-active-tool="wire"] .comp, .workspace.is-wiring .comp { cursor: crosshair; }
.comp .act { fill: transparent; cursor: pointer; }
.comp .act-slider, .comp .act-knob { cursor: ew-resize; }
.comp:hover .act { fill: var(--select-soft); stroke: var(--select); stroke-width: 1; stroke-dasharray: 3 3; }
.comp.is-problem .art { filter: url(#ppc-glow-problem); }
.comp.is-note .art { filter: url(#ppc-glow-note); }
.meter-note { margin: 8px 0 0; padding: 8px 10px; border-radius: 8px; background: color-mix(in srgb, #F08C00 12%, transparent); color: var(--ink); font-size: 0.8rem; line-height: 1.4; }
.ppc-glow { pointer-events: none; mix-blend-mode: screen; }
/* Motor rotor and loudspeaker cone: visual cues only, independent of sim time. */
.ppc-spin { transform-box: fill-box; transform-origin: center; animation: ppc-spin 1s linear infinite; }
@keyframes ppc-spin { to { transform: rotate(360deg); } }
.ppc-buzz { transform-box: fill-box; transform-origin: center; animation: ppc-buzz 0.08s ease-in-out infinite alternate; }
@keyframes ppc-buzz { to { transform: scale(1.05); } }
.ppc-waves { animation: ppc-waves 0.6s ease-in-out infinite alternate; }
@keyframes ppc-waves { from { opacity: 0.35; } to { opacity: 1; } }
[data-theme="light"] .view-schematic .ppc-glow { mix-blend-mode: multiply; }

/* Text inside artwork */
.ws-svg text, .card-art text, .insp-art text { font-family: var(--font-body); user-select: none; pointer-events: none; }
.ppc-print { font-size: 9px; font-weight: 700; fill: #fff; }
.ppc-print-dark { fill: #3A1F08; }
.ppc-print-tiny { font-size: 7px; }
.ppc-turns-tag { fill: #F6EEDD; stroke: #4A2A12; stroke-width: 0.8; }
.ppc-turns { font-family: var(--font-mono); font-size: 8.5px; font-weight: 700; fill: #1E1408; }
.ppc-pol { font-size: 13px; font-weight: 800; }
.ppc-pol-pos { fill: #D7372B; }
.ppc-pol-neg { fill: #20242B; }
[data-theme="dark"] .ppc-pol-neg { fill: #E8ECF3; }
[data-theme="dark"] .ppc-pin { fill: #B9C1CE; }
.ppc-mark { font-size: 12px; font-weight: 800; }
.ppc-mark-dark { fill: #4A3310; }
.ppc-seg { font-family: var(--font-mono); font-size: 14px; font-weight: 600; fill: #7CFFB2; }
.ppc-seg-small { font-size: 9px; fill: #5FD99A; }
.ppc-panel-mark { font-size: 13px; font-weight: 800; fill: #fff; }
.ppc-panel-mark-small { font-size: 11px; }
.ppc-panel-label { font-size: 8px; font-weight: 800; letter-spacing: 0.08em; fill: #C9CFD8; }
.ppc-panel-tiny { font-size: 6px; font-weight: 700; letter-spacing: 0.06em; fill: #C9CFD8; }
.ppc-dark { fill: #3A404B; }
.ppc-lcd { font-family: var(--font-mono); font-size: 14px; font-weight: 600; fill: #16210F; }
.ppc-lcd-note { font-family: var(--font-mono); font-size: 6px; font-weight: 600; fill: #33452A; }
.ppc-meter-letter { font-size: 13px; font-weight: 800; fill: #fff; }
.ppc-pin { font-size: 8px; font-weight: 700; fill: #596170; }
.ppc-pin-light { fill: #fff; }
.ppc-pin-dark { fill: #5A3D15; }
.ppc-face { font-size: 7px; font-weight: 800; fill: #E9ECF0; }
.ppc-badge { fill: #fff; stroke: #B9C0CB; stroke-width: 1; }
.ppc-badge-text { font-size: 8px; font-weight: 700; fill: #2A3140; font-family: var(--font-mono); }
.ppc-badge-icon { fill: #D9480F; }
.ppc-badge-stroke { stroke: #D9480F; stroke-width: 1.3; }
.ppc-badge-track { fill: #DDE1E7; }
.ppc-badge-level { fill: #D9480F; }
.ppc-silk .sch-line, .ppc-silk .sch-body, .ppc-silk .sch-fill { stroke: #EAF2FF; fill: none; stroke-width: 2.6; }
.ppc-silk-text { font-size: 8px; font-weight: 800; fill: #EAF2FF; }
.ppc-silk-title { font-size: 11px; font-weight: 800; fill: #fff; letter-spacing: 0.04em; }
.ppc-silk-tiny { font-size: 5.5px; font-weight: 700; fill: #B8CCE4; letter-spacing: 0.05em; }
.ppc-silk-strong { font-size: 7px; fill: #EAF2FF; }
.ppc-trace { stroke: #C9A13B; stroke-width: 2; fill: none; }
.ppc-rail-label { font-size: 9px; font-weight: 800; fill: #3A404B; }
[data-theme="dark"] .ppc-rail-label { fill: #DDE3EC; }
.ppc-scope-text { font-family: var(--font-mono); font-size: 6px; fill: #9EF0C8; }
.ppc-scope-ch1 { fill: #FFE14D; }
.ppc-scope-ch2 { fill: #4FE3FF; }

/* Circuit diagram symbols */
.sch-line { fill: none; stroke: var(--sch-ink); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.sch-thick { stroke-width: 5; stroke-linecap: butt; }
.sch-plate { stroke-width: 3; stroke-linecap: butt; }
.sch-body { fill: var(--sch-paper); stroke: var(--sch-ink); stroke-width: 2.4; stroke-linejoin: round; }
.sch-fill { fill: var(--sch-ink); }
.sch-screen { fill: none; stroke: var(--sch-ink); stroke-width: 1; opacity: 0.6; }
.sch-pol { font-size: 13px; font-weight: 800; fill: var(--sch-ink); }
.sch-pin { font-size: 9px; font-weight: 700; fill: var(--sch-ink); opacity: 0.75; }
.sch-tag { font-size: 10px; font-style: italic; font-weight: 600; fill: var(--sch-ink); }
.sch-letter { font-size: 16px; font-weight: 800; fill: var(--sch-ink); }
.sch-iec { font-size: 13px; font-weight: 800; fill: var(--sch-ink); font-family: var(--font-body); }
.sch-level { font-size: 9px; font-weight: 700; font-family: var(--font-mono); fill: var(--ink-3); }
.sch-level-on { fill: #D7372B; }
.sch-level-lit { fill: #fff; }
.sch-pill { fill: var(--sch-paper); stroke: var(--sch-accent); stroke-width: 1.4; }
.sch-pill-warn { stroke: var(--warn-ring); }
.sch-pill-text { font-family: var(--font-mono); font-size: 11px; font-weight: 600; fill: var(--sch-ink); }
.card-art .sch-pill, .card-art .sch-pill-text { display: none; }
.sch-wire { fill: none; stroke: var(--sch-ink); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.jdot { fill: var(--sch-ink); }

/* Wires */
.wire-hit { fill: none; stroke: transparent; stroke-width: 16; pointer-events: stroke; cursor: pointer; }
.workspace[data-active-tool="wire"] .wire-hit { cursor: copy; }
.wire-sel { fill: none; stroke: transparent; stroke-width: 11; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.wire:hover .wire-sel { stroke: var(--select-soft); }
.wire.is-selected .wire-sel { stroke: var(--select); opacity: 0.45; }
.view-schematic .wire.is-selected .sch-wire { stroke: var(--select); }
.wire-preview { fill: none; pointer-events: none; stroke-linecap: round; stroke-linejoin: round; }
.wire-preview-realistic { stroke: var(--select); stroke-width: 4; opacity: 0.7; }
.wire-preview-schematic { stroke: var(--select); stroke-width: 2.2; stroke-dasharray: 6 4; }
.wire-target { fill: none; stroke: var(--target); stroke-width: 3; pointer-events: none; }
.wire-target-dot { fill: var(--target); pointer-events: none; }
.wire-bend { fill: var(--select); pointer-events: none; }
.flow { fill: none; stroke: #FFD43B; stroke-width: 3.2; stroke-dasharray: 3 21; stroke-linecap: round; pointer-events: none; filter: drop-shadow(0 0 1.5px rgba(120, 80, 0, 0.8)); }
.dangling circle { fill: color-mix(in srgb, var(--warn-ring) 18%, transparent); stroke: var(--warn-ring); stroke-width: 2.2; stroke-dasharray: 3 2; }

/* Terminals */
.term { cursor: crosshair; }
.term-hit { fill: transparent; }
.term-ring { fill: none; stroke: transparent; stroke-width: 2; pointer-events: none; }
.term.is-open .term-ring { stroke: var(--select); stroke-opacity: 0.45; stroke-dasharray: 2.5 2; }
.term.is-junction .term-ring { stroke: none; }
.term:hover .term-ring { stroke: var(--target); stroke-opacity: 1; stroke-dasharray: none; fill: color-mix(in srgb, var(--target) 22%, transparent); }
.is-wiring .term.is-target .term-ring { stroke: var(--target); stroke-opacity: 0.85; stroke-dasharray: none; }
.term.is-from .term-ring { stroke: var(--select); stroke-opacity: 1; stroke-dasharray: none; fill: var(--select-soft); }

/* Labels, selection and handles */
.clabel { font-size: 11px; font-weight: 700; fill: var(--ink-2); pointer-events: none; paint-order: stroke; stroke: var(--bench); stroke-width: 3px; stroke-linejoin: round; }
.clabel-schematic { fill: var(--sch-ink); stroke: var(--sch-paper); font-size: 11.5px; }
.sel-box { fill: var(--select-soft); stroke: var(--select); stroke-width: 1.6; stroke-dasharray: 5 4; pointer-events: none; vector-effect: non-scaling-stroke; }
.handle { cursor: pointer; }
.handle .handle-hit { fill: transparent; stroke: none; }
.handle circle:not(.handle-hit), .handle rect { fill: var(--surface); stroke: var(--select); stroke-width: 2; }
.handle-mid circle:not(.handle-hit) { fill: var(--select); stroke: var(--surface); }
.handle-mid path { stroke: #fff; stroke-width: 1.6; }
.handle-end circle:not(.handle-hit) { fill: var(--select); }
.handle-wp { cursor: move; }
.marquee { fill: var(--select-soft); stroke: var(--select); stroke-width: 1; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }
.ghost { opacity: 0.6; pointer-events: none; }

/* Toolbar: the row under the circuit pane's heading. */
.toolbar { flex: none; display: flex; align-items: center; flex-wrap: wrap; gap: 2px; padding: 5px 8px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.tool-group { display: flex; gap: 2px; padding-right: 4px; border-right: 1px solid var(--line); flex: 0 0 auto; }
.tool-group:last-of-type { border-right: 0; }
.tool { display: inline-grid; place-items: center; width: var(--tool-size); height: var(--tool-size); border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--ink-2); cursor: pointer; }
.tool:hover:not(:disabled) { background: var(--surface-3); color: var(--ink); }
.tool[aria-pressed="true"], .tool-panel[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.tool:disabled { opacity: 0.35; cursor: default; }
.tool-panel { display: none; }
#btn-show-inspector { margin-left: auto; }

/* Display settings: an icon tool with a drop-down, left of Clear. */
/* Display and Clear stay together at the right end, even when the toolbar wraps. */
.toolbar-end { display: flex; align-items: center; gap: 2px; margin-left: auto; flex: none; }
.tool-display { flex: none; }
.tool-display[aria-expanded="true"] { background: var(--surface-3); }
.display-menu { width: 280px; padding: 12px 14px 10px; }
.display-menu .icard-label { margin-bottom: 4px; }
.display-menu .row select { max-width: 58%; }
.menu-note { margin: 8px 0 0; padding-top: 8px; border-top: 1px solid var(--line); font-size: 0.74rem; color: var(--ink-3); line-height: 1.4; }

/* Clear circuit: red text at the right end of the toolbar, as in PanPhyPlot. */
.tool-clear {
  display: inline-flex; align-items: center; gap: 5px; flex: none; min-height: var(--tool-size); padding: 6px 8px;
  border: 1px solid transparent; border-radius: 10px; background: none; color: var(--danger); font-weight: 600; font-size: 0.86rem; cursor: pointer; white-space: nowrap;
}
.tool-clear .icon { width: 18px; height: 18px; }
.tool-clear:hover:not(:disabled) { background: var(--danger-soft); }
.tool-clear:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.tool-clear:disabled { opacity: 0.4; cursor: default; }

.error-banner {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 5; display: flex; align-items: center; gap: 8px; max-width: min(640px, calc(100% - 24px));
  padding: 9px 14px; border-radius: 12px; border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); background: var(--surface); color: var(--danger);
  box-shadow: var(--shadow-1); font-size: 0.84rem; font-weight: 600; text-align: left; cursor: pointer;
}
.error-banner span { color: var(--ink); font-weight: 500; }

/* Empty state */
.empty-state {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -46%); width: min(460px, calc(100% - 32px)); padding: 24px 26px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-2); z-index: 4;
}
.empty-state h2 { margin: 0 0 12px; font-size: 1.3rem; }
.empty-state ol { margin: 0 0 12px; padding-left: 1.2rem; display: grid; gap: 6px; color: var(--ink-2); font-size: 0.92rem; line-height: 1.4; }
.empty-state p { margin: 0 0 16px; color: var(--ink-2); font-size: 0.9rem; }
.empty-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.empty-state[hidden] { display: none; }

/* Problems popover */
.problems-pop {
  position: absolute; right: 12px; bottom: 56px; width: min(420px, calc(100% - 24px)); max-height: 50%; overflow: auto; z-index: 8;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-2); padding: 8px 12px 12px;
}
.pop-head { display: flex; justify-content: space-between; align-items: center; }
.problems-pop ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.prob button { width: 100%; text-align: left; border: 0; border-left: 4px solid; border-radius: 8px; padding: 9px 10px; background: var(--surface-2); cursor: pointer; font-size: 0.85rem; line-height: 1.35; }
.prob-error button { border-color: var(--danger); }
.prob-warn button { border-color: var(--warn); }

/* Graph */
.graph-panel { flex: 0 1 230px; min-height: 150px; display: flex; flex-direction: column; border-top: 1px solid var(--line); background: var(--surface); min-height: 0; }
.graph-title { font-family: var(--font-display); font-weight: 500; letter-spacing: -0.02em; }
.graph-head { display: flex; align-items: center; gap: 12px; padding: 4px 8px 0 14px; height: 48px; flex: 0 0 auto; }
.graph-title { font-size: 0.9rem; }
.graph-legend { flex: 1; min-width: 0; display: flex; flex-wrap: nowrap; gap: 14px; overflow-x: auto; scrollbar-width: none; font-size: 0.78rem; color: var(--ink-2); font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.graph-legend::-webkit-scrollbar { display: none; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.legend-value { display: inline-block; min-width: 9ch; text-align: right; color: var(--ink); }
.legend-swatch { width: 18px; height: 0; border-top: 3px solid var(--c); }
.legend-swatch.is-dashed { border-top-style: dashed; }
.field select { min-height: 36px; border-radius: 9px; border: 1px solid var(--line-strong); background: var(--surface-2); padding: 4px 8px; }
.graph-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.graph-exports { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.graph-exports[hidden] { display: none !important; }

/* View reset is separate from the export pills. */
.graph-view-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: none;
  min-height: 32px; margin-right: 8px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: transparent; color: var(--ink); font: 600 0.74rem var(--font-body); cursor: pointer; white-space: nowrap;
}
.graph-view-button .icon { width: 16px; height: 16px; }
.graph-view-button:hover:not(:disabled) { background: var(--surface-3); border-color: var(--accent); }
.graph-view-button:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.graph-view-button:disabled { opacity: 0.45; cursor: default; }

.graph-export-pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 32px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--surface-2); color: var(--ink); font: 600 0.72rem var(--font-body); cursor: pointer; white-space: nowrap;
}
.graph-export-pill:hover:not(:disabled) { background: var(--surface-3); border-color: var(--accent); }
.graph-export-pill:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.graph-export-pill:disabled { opacity: 0.45; cursor: not-allowed; }
.graph-canvas { flex: 1; width: 100%; min-height: 0; display: block; }

/* Status on the left and legal/support links on the right, stacked on phones.
   Reserve the footer height so changing status never moves the panes. */
.statusbar {
  flex: none; display: flex; align-items: center; gap: 12px; height: calc(var(--statusbar-h) + env(safe-area-inset-bottom, 0px));
  padding: 4px max(14px, env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom, 0px)) max(14px, env(safe-area-inset-left));
  border-top: 1px solid var(--line); background: var(--surface-2); font-size: 0.76rem; color: var(--ink-3);
}
.statusbar-status { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; }
.hint { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); text-align: left; }
.problems-btn { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; white-space: nowrap; border-radius: 999px; border: 1px solid; cursor: pointer; font-size: 0.74rem; font-weight: 700; background: var(--surface); }
.problems-btn .icon { width: 14px; height: 14px; }
.problems-btn[data-level="error"] { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); background: var(--danger-soft); }
.problems-btn[data-level="warn"] { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.zoom-readout { flex: none; color: var(--ink-3); width: 12ch; text-align: right; }
.statusbar-legal { white-space: nowrap; }
.statusbar a { color: var(--ink-2); }
.statusbar a:hover { text-decoration: underline; }

/* ---------- Inspector: a column of cards, as in PanPhyPlot ---------- */

.inspector { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.inspector-body { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; overscroll-behavior: contain; padding-bottom: 2px; }
.icard { flex: none; padding: 14px 16px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-1); }
.icard-label { margin: 0 0 10px; font-family: var(--font-mono); font-weight: 600; font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); }
/* Live readings get the spectrum as a hairline on the top edge (inset, not clipped). */
.readings-card { position: relative; }
.readings-card::before { content: ''; position: absolute; top: -1px; left: var(--radius); right: var(--radius); height: 2px; border-radius: 2px; background: var(--spectrum); opacity: 0.8; pointer-events: none; }
.icard-note { margin: 10px 0 0; font-size: 0.8rem; color: var(--ink-3); line-height: 1.45; }

.insp-head { display: flex; align-items: center; gap: 12px; }
.insp-art { width: 60px; height: 46px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.insp-art svg { width: 52px; height: 38px; overflow: visible; }
.insp-head .icard-label { margin: 0 0 2px; }
.insp-title { margin: 0; font-family: var(--font-display); font-weight: 500; font-size: 1.02rem; letter-spacing: -0.02em; line-height: 1.25; }
.wire-ends { margin: 10px 0 0; font-size: 0.84rem; color: var(--ink-2); }
.label-row { margin-top: 10px; border-top: 1px solid var(--line); }

/* Compact rows: a label on the left, its control on the right. */
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.row + .row, .row + .field, .field + .row { border-top: 1px solid var(--line); }
.row > label, .row-label { font-size: 0.86rem; font-weight: 600; color: var(--ink); white-space: nowrap; }
.row select { min-width: 0; max-width: 62%; }
.row input[type="text"] { width: 120px; }
.field { padding: 10px 0; }
.icard > .field:first-of-type, .icard-label + .field { padding-top: 0; }
.field:last-child { padding-bottom: 0; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.field-row > label { font-size: 0.86rem; font-weight: 600; color: var(--ink); }
.field-stack > label { display: block; font-size: 0.86rem; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.field input[type="text"], .row input[type="text"] { min-height: 38px; padding: 6px 10px; border-radius: 9px; border: 1px solid var(--line-strong); background: var(--surface-2); font-family: var(--font-mono); font-size: 0.88rem; }
.field input[type="text"]:focus, .row input[type="text"]:focus { outline: 2px solid var(--focus); border-color: var(--accent); }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.icard select { min-height: 36px; border-radius: 9px; border: 1px solid var(--line-strong); background: var(--surface-2); padding: 4px 8px; font-size: 0.84rem; }
.field-stack select { width: 100%; }
.num { flex: 0 0 136px; display: flex; align-items: center; position: relative; }
.num input[type="text"] { width: 100%; padding-right: 34px; }
.num .unit { position: absolute; right: 10px; font-family: var(--font-mono); font-size: 0.8rem; color: var(--ink-3); pointer-events: none; }
.slider { display: block; width: 100%; margin: 8px 0 0; accent-color: var(--accent); height: 28px; }
.field-range { display: flex; justify-content: space-between; margin: 0; font-size: 0.68rem; color: var(--ink-3); font-family: var(--font-mono); }
.field-err { margin: 4px 0 0; font-size: 0.76rem; color: var(--danger); }
.field-err:empty { display: none; }
.field-help { margin: 6px 0 0; font-size: 0.76rem; color: var(--ink-3); line-height: 1.4; }
.toggle { display: flex; width: 100%; margin: 0; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; cursor: pointer; font-size: 0.86rem; font-weight: 600; color: var(--ink); }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-track { display: inline-block; position: relative; width: 40px; height: 24px; border-radius: 999px; background: var(--line-strong); flex: 0 0 auto; transition: background 0.15s; }
.toggle-track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.15s; }
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(16px); }
.toggle input:focus-visible + .toggle-track { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Readings */
.readings-card dl { margin: 0; display: grid; }
.reading { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 0.84rem; padding: 6px 0; border-bottom: 1px solid var(--line); }
.reading:last-child { border-bottom: 0; }
.reading dt { color: var(--ink-2); }
.reading dd { margin: 0; text-align: right; font-size: 0.88rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.reading.is-direction { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; line-height: 1.4; }
.reading.is-direction dd { text-align: left; min-height: 1.4em; }
.reading.is-strong { padding: 2px 0 8px; }
.reading.is-strong dd { font-size: 1.25rem; font-weight: 600; }
.readings-card .toggle { border-top: 1px solid var(--line); margin-top: 6px; }
.readings-empty { margin: 0; font-size: 0.84rem; color: var(--ink-3); }

/* Shown above the settings when nothing is selected. */
/* Live displays: a selected meter or scope, and pinned ones above the cards. */
.pinned-displays { flex: 0 1 auto; min-height: 0; max-height: 45%; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 2px; overscroll-behavior: contain; scrollbar-gutter: stable; }
/* Drag (or use the arrow keys) to set how tall the pinned area may grow. */
.pinned-resize { flex: none; position: relative; display: flex; align-items: center; justify-content: center; height: 20px; margin: 0 0 4px; border-radius: 999px; cursor: row-resize; touch-action: none; }
.pinned-resize::before { content: ''; position: absolute; inset: -6px 0; }
.pinned-resize::after { content: ''; width: 44px; height: 4px; border-radius: 2px; background: var(--line-strong); transition: background 0.15s, width 0.15s; }
.pinned-resize:hover::after, .pinned-resize.is-dragging::after { width: 64px; background: var(--accent); }
.pinned-resize:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
@media (pointer: coarse) { .pinned-resize { height: 28px; } .pinned-resize::before { inset: -10px 0; } }
.pinned-displays:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; border-radius: var(--radius); }
.live-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: -4px 0 8px; }
.live-head .icard-label { margin: 0; }
.pin-btn { display: inline-flex; align-items: center; gap: 4px; min-height: 30px; padding: 2px 10px 2px 8px; border: 1px solid var(--line); border-radius: 999px; background: none; color: var(--ink-2); font-size: 0.76rem; font-weight: 600; cursor: pointer; }
.pin-btn .icon { width: 15px; height: 15px; }
.pin-btn:hover { background: var(--surface-3); color: var(--ink); }
.pin-btn[aria-pressed="true"] { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); color: var(--accent); }
.meter-view { border-radius: 10px; background: var(--bench); padding: 6px; }
.meter-view svg { display: block; width: 100%; height: auto; max-height: 220px; }
.meter-view text { font-family: var(--font-body); }
.scope-screen { display: block; width: 100%; aspect-ratio: 10 / 8; border-radius: 8px; background: #071712; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.4); }
.scope-legend { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 10px; margin: 8px 0 0; font: 600 0.72rem var(--font-mono); color: var(--ink-2); }
.scope-ch1 { color: #B08A00; }
.scope-ch2 { color: #0B8BA8; }
[data-theme="dark"] .scope-ch1 { color: #FFD43B; }
[data-theme="dark"] .scope-ch2 { color: #3BD8FF; }
.insp-hint { flex: none; margin: 2px 4px 0; font-size: 0.8rem; color: var(--ink-3); line-height: 1.45; }

/* Actions on the selection: icon over a short label, one row. */
.mini-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(48px, 1fr)); gap: 4px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.mini-tool { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 52px; padding: 6px 0; white-space: nowrap; border: 0; border-radius: 10px; background: none; color: var(--ink-2); font-size: 0.72rem; font-weight: 600; cursor: pointer; }
.mini-tool .icon { width: 18px; height: 18px; color: var(--accent); }
.mini-tool:hover:not(:disabled) { background: var(--surface-3); color: var(--ink); }
.mini-tool:disabled { opacity: 0.35; cursor: default; }
.mini-tool.danger, .mini-tool.danger .icon { color: var(--danger); }
.mini-tool.danger:hover { background: var(--danger-soft); }

.truth table { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 0.85rem; text-align: center; }
.truth th, .truth td { padding: 5px; border-bottom: 1px solid var(--line); }
.truth tr:last-child td { border-bottom: 0; }
.truth tr.is-now td { background: var(--accent-soft); font-weight: 700; }

.model-note { font-size: 0.82rem; color: var(--ink-2); line-height: 1.5; padding-top: 4px; padding-bottom: 4px; }
.model-note summary { cursor: pointer; font-weight: 700; color: var(--ink); min-height: 40px; display: flex; align-items: center; }
.model-note[open] { padding-bottom: 14px; }
.model-note p { margin: 6px 0 0; }
.model-note .terms { font-size: 0.76rem; color: var(--ink-3); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line-strong); background: var(--c); cursor: pointer; }
.swatch.is-on { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--accent); }

/* ---------- Dialogs and toast ---------- */

.dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); padding: 20px 22px; max-width: min(460px, calc(100vw - 24px)); box-shadow: var(--shadow-2); }
.dialog-wide { max-width: min(880px, calc(100vw - 24px)); max-height: calc(100vh - 48px); }
.dialog::backdrop { background: rgba(8, 12, 24, 0.45); }
.dialog h2 { margin: 0 0 8px; font-size: 1.2rem; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.dialog-sub { color: var(--ink-2); font-size: 0.9rem; margin: 0 0 14px; }
.dialog p { line-height: 1.45; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.danger-fill { background: var(--danger); }
.examples-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; }
.example { position: relative; width: 100%; height: 100%; display: flex; gap: 12px; align-items: flex-start; text-align: left; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; }
.example:hover { border-color: var(--accent); }
.example strong { display: block; font-size: 0.92rem; margin-bottom: 3px; }
.example span span { display: block; font-size: 0.8rem; color: var(--ink-2); line-height: 1.35; }
.ex-num { flex: 0 0 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font: 700 0.8rem var(--font-mono); }
.toast { position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); z-index: 200; display: flex; align-items: center; gap: 12px; max-width: min(560px, calc(100vw - 24px));
  padding: 10px 16px; border-radius: 12px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow-2); font-size: 0.86rem; }
.toast-btn { border: 0; background: transparent; color: var(--accent-hover); font-weight: 700; cursor: pointer; }
[data-theme="dark"] .toast-btn { color: #1550B3; }

/* ---------- Responsive ---------- */

@media (max-width: 1180px) {
  :root { --panel-w: 232px; --insp-w: 280px; }
  .main { gap: 10px; padding: 10px; }
}

@media (max-width: 1100px) {
  .view-switch button span { display: none; }
  .view-switch button { padding: 4px 12px; }
  .stage-head .pane-heading { display: none; }
}

/* Tablets and phones: the circuit fills the width; Components and the
   inspector slide in over it. */
@media (max-width: 900px) {
  .main { grid-template-columns: minmax(0, 1fr); padding: 8px; }
  .library, .inspector {
    position: fixed; top: calc(var(--appbar-h) + var(--standalone-top, 0px) + 8px); bottom: calc(var(--statusbar-h) + env(safe-area-inset-bottom, 0px) + 8px); z-index: 30; width: min(340px, 88vw);
    box-shadow: var(--shadow-2); transition: transform 0.2s ease; visibility: hidden;
  }
  .library { left: 8px; transform: translateX(-110%); }
  .inspector { right: 8px; transform: translateX(110%); padding: 12px; border-radius: var(--radius); background: var(--bg); border: 1px solid var(--line); }
  body.show-library .library, body.show-inspector .inspector { transform: none; visibility: visible; }
  .icon-btn.panel-close { display: inline-grid; }
  .panel-top { display: flex; }
  .tool-panel { display: inline-grid; }
  .tool-group { padding-right: 4px; }
}

@media (max-width: 760px) {
  .app { --statusbar-h: 68px; }
  .statusbar { flex-direction: column; align-items: stretch; gap: 2px; }
  .statusbar-status { flex: none; width: 100%; min-height: 20px; }
  .statusbar-legal { white-space: normal; line-height: 1.3; }
}

@media (max-width: 640px) {
  .appbar { gap: 8px; }
  .atool span { display: none; }
  .atool .icon-chevron { display: none; }
  .appbar-group { margin-right: 2px; padding-right: 2px; }
  .stage-head { padding-left: 10px; gap: 8px; }
}

@media (max-width: 440px) {
  .wordmark { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .status-dot, .ppc-spin, .ppc-buzz, .ppc-waves { animation: none !important; }
  .view-switch::before, .view-switch button { transition: none; }
  .library, .inspector { transition: none; }
}

/* Selection shortcuts: 22 world units, smaller than a 32-unit diagram meter. */
.selection-delete { cursor: pointer; }
.selection-delete circle { fill: var(--surface); stroke: var(--select); stroke-width: 1.5; }
.selection-delete path { fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; pointer-events: none; }
.selection-delete:hover circle, .selection-delete:focus-visible circle { fill: var(--accent-soft); stroke-width: 2.5; }
/* Settings only: compact rows in the same solid surfaces and type. */
.quick-settings { position: fixed; z-index: 100; width: min(196px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); overflow-y: auto; padding: 4px 6px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow-2); }
.quick-settings .field { margin: 0; padding: 1px 0; }
.quick-settings .field-row, .quick-settings .field-stack { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.quick-settings .field-row > label, .quick-settings .field-stack > label, .quick-settings .toggle { margin: 0; min-height: 22px; color: var(--ink-2); font-size: .7rem; font-weight: 500; line-height: 1.25; }
.quick-settings .field-stack > label { display: flex; align-items: center; }
.quick-settings .num { flex: 0 0 68px; min-width: 0; }
.quick-settings .field input[type="text"], .quick-settings .field select { min-height: 22px; height: 22px; padding: 2px 5px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-2); font-size: .72rem; }
.quick-settings .num input[type="text"] { padding-right: 26px; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.quick-settings .num .unit { right: 6px; font-size: .65rem; }
.quick-settings .field input[type="text"]:hover, .quick-settings .field select:hover { border-color: var(--line-strong); }
.quick-settings .field input[type="text"]:focus, .quick-settings .field select:focus-visible { border-color: var(--accent); outline: 2px solid var(--focus); }
.quick-settings .field input[aria-invalid="true"] { border-color: var(--danger); }
/* Dim the whole manual setting, including its label, while automatic control is on. */
.field:has(input:disabled, select:disabled) { opacity: .35; }
/* Native selects size to their longest option, including the arrow space. */
.quick-settings:has(select) { width: max-content; min-width: min(196px, calc(100vw - 16px)); max-width: calc(100vw - 16px); }
.quick-settings .field select { flex: 0 1 auto; width: auto; min-width: 0; max-width: 100%; }
.quick-settings .field-err { margin: 2px 0; font-size: .65rem; }
.quick-settings .toggle { gap: 8px; }
.quick-settings .toggle-track { width: 28px; height: 16px; }
.quick-settings .toggle-track::after { top: 2px; left: 2px; width: 12px; height: 12px; }
.quick-settings .toggle input:checked + .toggle-track::after { transform: translateX(12px); }

.quick-settings .slider { appearance: none; -webkit-appearance: none; height: 14px; margin: 1px 0; background: transparent; cursor: pointer; }
.quick-settings .slider::-webkit-slider-runnable-track { height: 3px; border-radius: 3px; background: var(--line-strong); }
.quick-settings .slider::-webkit-slider-thumb { appearance: none; -webkit-appearance: none; width: 10px; height: 10px; margin-top: -3.5px; border: 0; border-radius: 50%; background: var(--accent); }
.quick-settings .slider::-moz-range-track { height: 3px; border-radius: 3px; background: var(--line-strong); }
.quick-settings .slider::-moz-range-thumb { width: 10px; height: 10px; border: 0; border-radius: 50%; background: var(--accent); }
.quick-settings .slider:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; border-radius: 4px; }

/* Use our touch-and-hold menu instead of the iOS SVG callout. */
.ws-svg { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }

/* Select a time range without scrolling the page on touch screens. */
.graph-canvas { touch-action: none; cursor: crosshair; }
.graph-canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

@media (max-width: 640px) {
  .graph-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; height: auto; gap: 6px; padding: 6px 8px; }
  .graph-title { grid-column: 1; grid-row: 1; }
  .graph-legend { grid-column: 2; grid-row: 1; }
  .graph-actions { grid-column: 1 / -1; grid-row: 2; flex-wrap: wrap; }
  #graph-close { grid-column: 3; grid-row: 1; width: 32px; min-width: 32px; height: 32px; }
}
