:root {
  color-scheme: dark;
  --bg: #07111f;
  --panel: #0d1b2d;
  --card: #13263d;
  --card-2: #192f49;
  --border: #5d7894;
  --text: #ffffff;
  --muted: #c8d8e8;
  --cyan: #00d8ff;
  --blue: #36a7ff;
  --amber: #ffc400;
  --green: #52f578;
  --pink: #ff5f87;
  --red: #ff5964;
  --ink: #06101b;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}
button, input, select { font: inherit; }
.topbar {
  min-height: 92px;
  padding: 18px clamp(18px, 3vw, 48px);
  display: flex;
  align-items: center;
  gap: 16px;
  background: #0b192a;
  border-bottom: 2px solid #294765;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0,0,0,.34);
}
.brand-mark {
  width: 52px; height: 52px; flex: 0 0 52px;
  display: grid; place-items: center;
  border: 3px solid var(--cyan);
  color: var(--cyan); font-weight: 950; letter-spacing: -.04em;
  border-radius: 12px;
  background: #0d2638;
}
.topbar h1 { margin: 0; font-size: clamp(1.25rem, 2.1vw, 1.8rem); line-height: 1.1; letter-spacing: -.025em; }
.eyebrow { margin: 0 0 3px; color: var(--cyan); font-size: .75rem; font-weight: 900; letter-spacing: .13em; }
.subtitle { color: var(--muted); margin: 5px 0 0; font-size: .9rem; font-weight: 650; }
.live-pill { margin-left: auto; border: 2px solid #4d6985; padding: 7px 11px; border-radius: 999px; font-size: .74rem; font-weight: 900; color: var(--muted); }
.live-pill span { display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: var(--green); box-shadow: 0 0 10px var(--green); }

.app-shell { display: grid; grid-template-columns: 330px minmax(0, 1fr); min-height: calc(100vh - 92px); }
.controls {
  padding: 24px 22px 40px;
  background: #0b192a;
  border-right: 2px solid #294765;
  position: sticky;
  top: 92px;
  align-self: start;
  max-height: calc(100vh - 92px);
  overflow-y: auto;
}
.panel-title { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 17px; }
.panel-title.compact { margin-top: 17px; }
.panel-title h2 { font-size: 1.08rem; margin: 0; }
.panel-title p { font-size: .78rem; color: var(--muted); margin: 1px 0; }
.step { display: grid; place-items: center; width: 32px; height: 32px; flex: 0 0 32px; border-radius: 8px; color: var(--ink); background: var(--cyan); font-weight: 950; font-size: .75rem; }
label { display: block; margin: 12px 0 6px; color: #e5f0fa; font-weight: 800; font-size: .82rem; }
input[type="number"], select {
  width: 100%; min-height: 43px; padding: 9px 10px;
  border: 2px solid #78a1c5; border-radius: 7px;
  background: #f8fbff; color: #06101b; font-weight: 800;
  outline: none;
}
input[type="number"]:focus, select:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(0,216,255,.25); }
.input-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.impedance-preview { margin-top: 14px; padding: 10px 12px; border-radius: 7px; border: 1px solid #4e718e; background: #142941; color: var(--muted); }
.impedance-preview strong { color: var(--amber); margin-left: 5px; }
.mode-options { margin-top: 14px; padding: 12px; border: 1px solid #4e718e; border-radius: 8px; background: #10243a; }
.mode-options label:first-child { margin-top: 0; }
.field-help { margin: 7px 0 0; color: var(--muted); font-size: .72rem; font-weight: 650; }
hr { margin: 23px 0 0; border: 0; border-top: 1px solid #42617d; }
input[type="range"] { width: 100%; accent-color: var(--cyan); }
output { float: right; color: var(--cyan); }
button { cursor: pointer; border: 2px solid #6f91ae; border-radius: 7px; color: var(--text); background: #193652; padding: 8px 12px; font-weight: 900; }
button:hover { border-color: var(--cyan); background: #214968; }
button:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
button.primary { width: 100%; margin-top: 22px; padding: 13px; background: var(--cyan); color: var(--ink); border-color: #9cf1ff; box-shadow: 0 5px 18px rgba(0,216,255,.22); }
.error { background: #641d29; border: 2px solid var(--red); color: white; border-radius: 7px; padding: 10px; font-weight: 750; }

.workspace { padding: 24px clamp(16px, 2.2vw, 34px) 52px; min-width: 0; }
.problem-banner {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 15px;
  min-height: 58px; padding: 10px 15px; margin-bottom: 16px;
  border: 2px solid #43708f; border-left: 5px solid var(--cyan); border-radius: 8px;
  background: #10263d;
}
.problem-banner p { margin: 0; color: var(--muted); font-weight: 700; }
.banner-tag { margin-right: 8px; padding: 4px 6px; background: var(--cyan); color: var(--ink); border-radius: 4px; font-size: .65rem; font-weight: 950; }
.path-count { padding: 5px 9px; border: 1px solid #8ba8c1; border-radius: 5px; color: #e5f3ff; font-size: .75rem; font-weight: 850; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; margin-bottom: 18px; }
.metrics article { min-height: 105px; padding: 14px 16px; background: var(--card); border: 2px solid var(--border); border-radius: 9px; box-shadow: 0 6px 17px rgba(0,0,0,.23); }
.metrics span { display: block; color: var(--muted); font-size: .75rem; font-weight: 900; letter-spacing: .07em; }
.metrics strong { display: block; margin: 4px 0 1px; font-size: clamp(1.12rem, 1.7vw, 1.55rem); color: var(--text); white-space: nowrap; }
.metrics small { color: var(--muted); font-weight: 600; }
.metrics article.pass { background: #125b2e; border-color: var(--green); }
.metrics article.fail { background: #6d202c; border-color: var(--red); }

.solution-panel, .card { background: var(--panel); border: 2px solid #3c5e7b; border-radius: 10px; }
.solution-panel { padding: 18px; margin-bottom: 18px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.section-heading h2 { margin: 0; font-size: 1.16rem; }
.solution-tabs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.solution-tabs button { padding: 7px 11px; min-width: 42px; }
.solution-tabs button[aria-selected="true"] { color: var(--ink); background: var(--amber); border-color: #ffe07a; }
.three-column { display: grid; grid-template-columns: .95fr 1.45fr 1.05fr; gap: 13px; }
.card { padding: 16px; min-width: 0; background: var(--card); }
.card h3 { margin: 2px 0 12px; font-size: 1rem; }
.card-kicker { color: var(--cyan); font-size: .68rem; letter-spacing: .13em; font-weight: 950; }
.circuit-diagram { height: 190px; display: grid; place-items: center; margin: 5px 0 9px; border-radius: 7px; background: #091625; border: 1px solid #3e607c; overflow: hidden; }
.circuit-diagram svg { width: 100%; height: 100%; }
.component-value { display: flex; justify-content: space-between; gap: 8px; padding: 9px 0; border-top: 1px solid #486681; color: var(--muted); font-size: .82rem; }
.component-value strong { color: var(--text); }
.circuit-card.stub-mode .component-value { display: block; }
.circuit-card.stub-mode .component-value strong { display: block; margin-top: 3px; overflow-wrap: anywhere; }
.note { color: var(--muted); font-size: .75rem; }
.smith-card canvas { display: block; width: 100%; aspect-ratio: 1.55 / 1; min-height: 300px; }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; color: var(--muted); font-size: .72rem; font-weight: 800; }
.legend .load { color: var(--amber); } .legend .first { color: var(--cyan); } .legend .second { color: var(--pink); } .legend .match { color: var(--green); }
.verify-card dl { margin: 0; }
.verify-card dl div { display: flex; justify-content: space-between; gap: 8px; padding: 9px 0; border-bottom: 1px solid #486681; }
.verify-card dt { color: var(--muted); } .verify-card dd { margin: 0; font-weight: 850; text-align: right; }
.derivation { margin-top: 13px; padding: 10px; border: 1px solid #55748e; background: #091625; border-radius: 6px; color: #e9f5ff; font: 600 .75rem/1.65 ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }

.sweep-card { margin-bottom: 18px; }
.sweep-card canvas { display: block; width: 100%; height: 310px; }
.passband { padding: 7px 10px; border: 1px solid #5d7c98; border-radius: 6px; color: var(--muted); font-size: .78rem; font-weight: 750; text-align: right; }
.sweep-legend { margin-top: 6px; }
.s11-line { color: var(--cyan); } .r-line { color: var(--amber); } .x-line { color: var(--pink); } .target-line { color: #d9e8f4; }
.lower-grid { display: grid; grid-template-columns: .95fr 1.25fr; gap: 18px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .78rem; }
th { color: #d9e8f4; background: #0b192a; text-align: left; }
th, td { padding: 9px 8px; border: 1px solid #486681; }
tbody tr.selected { background: #294763; outline: 2px solid var(--cyan); outline-offset: -2px; }
.actions { display: flex; gap: 6px; }
.actions button { font-size: .68rem; padding: 6px 8px; }
pre { max-height: 370px; overflow: auto; white-space: pre-wrap; margin: 0; padding: 12px; background: #06111f; border: 1px solid #527491; border-radius: 7px; color: #f3f9ff; font: 600 .73rem/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; }
.copy-status { min-height: 1.2em; margin: 6px 0 0; color: var(--green); font-size: .75rem; font-weight: 800; }
footer { padding: 20px; text-align: center; border-top: 1px solid #31516d; color: #aebfd0; font-size: .75rem; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 290px minmax(0,1fr); }
  .three-column { grid-template-columns: 1fr 1.5fr; }
  .verify-card { grid-column: 1 / -1; }
  .verify-card dl { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; }
  .verify-card dl div { display: block; }
  .verify-card dd { text-align: left; }
}
@media (max-width: 880px) {
  .topbar { position: static; }
  .app-shell { display: block; }
  .controls { position: static; max-height: none; border-right: 0; border-bottom: 2px solid #294765; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .three-column, .lower-grid { grid-template-columns: 1fr; }
  .verify-card { grid-column: auto; }
  .problem-banner { grid-template-columns: 1fr auto; }
  .problem-banner p { grid-column: 1 / -1; }
}
@media (max-width: 540px) {
  .topbar { padding: 14px; }
  .brand-mark { width: 42px; height: 42px; flex-basis: 42px; }
  .live-pill { display: none; }
  .subtitle { display: none; }
  .workspace { padding: 14px 10px 35px; }
  .metrics { grid-template-columns: 1fr; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .solution-tabs { justify-content: flex-start; }
  .verify-card dl { display: block; }
  .smith-card canvas { min-height: 260px; }
}
