:root {
  color-scheme: light;
  --paper: #f2efe8;
  --panel: #fffefa;
  --ink: #17303b;
  --muted: #66757b;
  --line: #cbd2ce;
  --grid: #e4e7e2;
  --teal: #086b68;
  --teal-soft: #dcecea;
  --yellow: #f5c84c;
  --current: #d94b3d;
  --voltage: #137dbe;
  --voltage-fill: rgba(19, 125, 190, .24);
  --r: #ad5a2a;
  --l: #7c4cac;
  --c: #087f83;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 0%, rgba(255,255,255,.9), transparent 30rem),
    linear-gradient(rgba(23,48,59,.035) 1px, transparent 1px),
    var(--paper);
  background-size: auto, 100% 32px, auto;
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
}

button, input, select { font: inherit; }
button, select, input[type="range"] { cursor: pointer; }

.app-shell { width: min(1500px, 100%); margin: 0 auto; padding: 26px clamp(14px, 3vw, 46px) 30px; }
.hero { display: flex; justify-content: space-between; align-items: end; gap: 30px; margin-bottom: 22px; }
.kicker, .panel-heading p, .data-heading p { margin: 0 0 6px; color: var(--teal); font: 800 .7rem/1 ui-monospace, monospace; letter-spacing: .17em; }
h1 { margin: 0; font-size: clamp(2.3rem, 5vw, 4.5rem); line-height: .92; letter-spacing: -.055em; }
.lead { margin: 12px 0 0; color: var(--muted); }
.legend { display: flex; gap: 18px; flex-wrap: wrap; padding-bottom: 4px; color: var(--muted); font-size: .82rem; font-weight: 700; }
.legend span { display: inline-flex; align-items: center; gap: 8px; }
.legend-current { position: relative; display: inline-block; width: 34px; height: 12px; }
.legend-current::before { content: ""; position: absolute; left: 2px; top: 3px; width: 7px; height: 7px; border-radius: 50%; background: var(--current); box-shadow: 12px 0 var(--current), 24px 0 var(--current); }
.legend-voltage { width: 25px; height: 16px; background: var(--voltage-fill); clip-path: polygon(0 50%, 100% 0, 100% 100%); outline: 1px solid var(--voltage); }

.control-deck { display: grid; grid-template-columns: 1.25fr repeat(5, minmax(130px, 1fr)); gap: 1px; background: #49606a; border: 1px solid #49606a; box-shadow: 0 10px 25px rgba(23,48,59,.13); }
.control-deck label { min-width: 0; min-height: 82px; padding: 13px 14px; background: var(--ink); color: #f4f6f3; }
.select-control { display: grid; gap: 8px; align-content: center; }
.select-control span, .range-control b { font-size: .72rem; }
select { width: 100%; min-height: 38px; border: 1px solid #70828a; border-radius: 0; background: #243f4a; color: white; padding: 0 9px; }
.range-control { display: grid; align-content: center; gap: 12px; }
.range-control > span { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.range-control output { color: var(--yellow); font: 700 .75rem/1 ui-monospace, monospace; white-space: nowrap; }
input[type="range"] { width: 100%; accent-color: var(--yellow); }
.range-control.is-unused { opacity: .38; }

.playback-bar { display: flex; align-items: center; gap: 9px; padding: 13px 0; }
button { min-height: 39px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 0 14px; font-weight: 750; }
button:hover { background: #f8faf7; }
button.primary { border-color: var(--teal); background: var(--teal); color: white; }
button:disabled { opacity: .38; cursor: not-allowed; background: var(--panel); color: var(--muted); }
.time-control { display: grid; grid-template-columns: auto minmax(120px, 420px) 45px; align-items: center; gap: 10px; flex: 1; color: var(--muted); font-size: .75rem; font-weight: 700; }
.time-control output { color: var(--ink); font: 700 .75rem/1 ui-monospace, monospace; text-align: right; }
.speed-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .75rem; font-weight: 700; }
.speed-control select { width: 78px; min-height: 39px; background: var(--panel); color: var(--ink); border-color: var(--line); }
.resonance-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .75rem; font-weight: 700; white-space: nowrap; }
.resonance-control select { width: 58px; min-height: 39px; background: var(--panel); color: var(--ink); border-color: var(--line); }

.workspace { display: grid; grid-template-columns: minmax(520px, 1.1fr) minmax(500px, 1fr); gap: 14px; align-items: start; }
.diagram-panel, .data-panel, .analysis-panel { border: 1px solid var(--line); background: rgba(255,254,250,.84); box-shadow: 0 12px 28px rgba(23,48,59,.07); }
.panel-heading { min-height: 71px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 13px 18px; border-bottom: 1px solid var(--line); }
.panel-heading h2, .data-heading h2 { margin: 0; font-size: clamp(1.12rem, 1.7vw, 1.45rem); letter-spacing: -.025em; }
.panel-heading > p { margin: 0; color: var(--muted); font: 500 .76rem/1.5 system-ui, sans-serif; letter-spacing: 0; text-align: right; }
#circuit-svg { display: block; width: 100%; height: 500px; background: linear-gradient(90deg, rgba(23,48,59,.035) 1px, transparent 1px), linear-gradient(rgba(23,48,59,.035) 1px, transparent 1px), #fffefa; background-size: 40px 40px; }
.instant-strip { min-height: 47px; display: flex; align-items: center; gap: 18px; flex-wrap: wrap; padding: 9px 16px; border-top: 1px solid var(--line); color: var(--muted); font: 650 .72rem/1 ui-monospace, monospace; }
.instant-strip b { color: var(--ink); }
.instant-strip .current-value { color: var(--current); }
.instant-strip .voltage-value { color: var(--voltage); }

.data-panel { display: grid; grid-template-columns: 170px minmax(0, 1.5fr) minmax(280px, .8fr); margin-top: 14px; }
.data-heading { display: grid; align-content: center; padding: 14px 18px; border-right: 1px solid var(--line); }
.data-panel dl { display: grid; grid-template-columns: repeat(4, 1fr); margin: 0; }
.data-panel dl > div { display: grid; align-content: center; gap: 5px; padding: 12px 14px; border-right: 1px solid var(--line); }
.data-panel dt { color: var(--muted); font-size: .72rem; font-weight: 700; }
.data-panel dd { margin: 0; font: 750 1.05rem/1.2 ui-monospace, monospace; }
.formula-box { padding: 14px 18px; background: var(--teal-soft); }
.formula-box span { display: block; color: var(--teal); font-size: .68rem; font-weight: 800; }
.formula-box strong { display: block; margin: 9px 0 6px; font: 750 .88rem/1.5 ui-monospace, monospace; overflow-wrap: anywhere; }
.formula-box small { display: block; color: #4d666a; line-height: 1.5; }

.analysis-heading { align-items: center; }
.wave-legend { display: flex; justify-content: flex-end; gap: 9px 15px; flex-wrap: wrap; color: var(--muted); font-size: .7rem; font-weight: 750; }
.wave-legend span { display: inline-flex; align-items: center; gap: 6px; }
.wave-legend i { display: inline-block; width: 20px; height: 3px; background: currentColor; }
#analysis-svg { display: block; width: 100%; height: auto; background: #fffefa; }

footer { display: flex; justify-content: space-between; gap: 20px; padding: 17px 2px 0; color: var(--muted); font-size: .72rem; }
footer p { margin: 0; }

.wire { fill: none; stroke: var(--ink); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.terminal { fill: var(--ink); }
.component-label { fill: var(--ink); font: 750 22px/1 ui-monospace, monospace; text-anchor: middle; }
.component-value { fill: var(--muted); font: 650 15px/1 ui-monospace, monospace; text-anchor: middle; }
.element-value { font-size: 30px; }
.source-label { text-anchor: end; }
.source-circle { fill: #fffefa; stroke: var(--ink); stroke-width: 4; }
.source-wave { fill: none; stroke: var(--ink); stroke-width: 3; }
.resistor { fill: none; stroke: var(--r); stroke-width: 6; stroke-linecap: square; stroke-linejoin: miter; }
.inductor { fill: none; stroke: var(--l); stroke-width: 6; stroke-linecap: round; }
.capacitor { stroke: var(--c); stroke-width: 7; }
.current-particle { fill: var(--current); stroke: #fffefa; stroke-width: 2; filter: url(#soft-shadow); }
.branch-current-label { fill: var(--current); font: 750 14px/1 ui-monospace, monospace; text-anchor: middle; paint-order: stroke; stroke: #fffefa; stroke-width: 4; stroke-linejoin: round; }
.current-label { fill: var(--current); font: 750 16px/1 ui-monospace, monospace; text-anchor: middle; paint-order: stroke; stroke: #fffefa; stroke-width: 4; stroke-linejoin: round; }
.voltage-triangle { fill: var(--voltage-fill); stroke: var(--voltage); stroke-width: 2.4; filter: url(#soft-shadow); }
.voltage-label { fill: var(--voltage); font: 750 15px/1 ui-monospace, monospace; text-anchor: middle; paint-order: stroke; stroke: #fffefa; stroke-width: 4; stroke-linejoin: round; }
.node-label { fill: var(--muted); font: 700 14px/1 ui-monospace, monospace; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.axis-line { stroke: #aab4b1; stroke-width: 1.5; }
.axis-tick-mark { stroke: #7f8c8f; stroke-width: 2; }
.axis-tick-label { fill: var(--ink); font: 700 17px/1 ui-monospace, monospace; text-anchor: end; }
.wave-label { fill: var(--muted); font: 650 18px/1 ui-monospace, monospace; }
.wave-path { fill: none; stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.cursor-line { stroke: var(--ink); stroke-width: 2; stroke-dasharray: 5 5; }
.cursor-dot { stroke: #fffefa; stroke-width: 2; }
.phasor-circle { fill: none; stroke: var(--grid); stroke-width: 1.5; }
.phasor-axis { stroke: #aab4b1; stroke-width: 1.3; }
.phasor-projection { fill: none; stroke-width: 1.2; stroke-dasharray: 4 4; opacity: .55; }
.phasor-arrow { filter: url(#soft-shadow); }
.phasor-dot { stroke: #fffefa; stroke-width: 1.5; }
.phasor-label { font: 750 18px/1 ui-monospace, monospace; text-anchor: middle; paint-order: stroke; stroke: #fffefa; stroke-width: 5; stroke-linejoin: round; }
.phasor-group-label { fill: var(--muted); font: 750 19px/1 ui-monospace, monospace; text-anchor: middle; }
.phasor-zero { fill: var(--muted); font: 650 17px/1 ui-monospace, monospace; text-anchor: middle; }

button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid #51afbf; outline-offset: 2px; }

@media (max-width: 1200px) {
  .control-deck { grid-template-columns: repeat(3, 1fr); }
  .data-panel { display: grid; grid-template-columns: 190px 1fr; }
  .data-heading { border-right: 1px solid var(--line); }
  .data-panel dl { display: grid; grid-template-columns: repeat(4, 1fr); }
  .data-panel dl > div { border-right: 1px solid var(--line); }
  .formula-box { grid-column: 1 / -1; }
}

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; }
  #circuit-svg { height: 480px; }
  #analysis-svg { height: auto; }
}

@media (max-width: 760px) {
  .app-shell { padding: 18px 10px 26px; }
  .hero { align-items: start; flex-direction: column; }
  .control-deck { grid-template-columns: 1fr 1fr; }
  .playback-bar { flex-wrap: wrap; }
  .time-control { order: 3; flex-basis: 100%; }
  .data-panel { display: block; }
  .data-panel dl { grid-template-columns: 1fr 1fr; }
  .data-heading { border-right: 0; border-bottom: 1px solid var(--line); }
  .data-panel dl > div { border-bottom: 1px solid var(--line); }
  .wave-heading { align-items: start; flex-direction: column; }
  .wave-legend { justify-content: flex-start; }
  footer { flex-direction: column; }
}

@media (max-width: 470px) {
  .control-deck { grid-template-columns: 1fr; }
  .panel-heading { align-items: start; flex-direction: column; }
  .panel-heading > p { text-align: left; }
  #circuit-svg { height: 360px; }
  .data-panel dl { grid-template-columns: 1fr; }
  .data-panel dl > div { border-right: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
