:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --ink: #0f1b2d;
  --ink-2: #44526a;
  --muted: #6b7890;
  --line: #d9e0ea;
  --accent: #ea580c;
  --accent-ink: #ffffff;
  --accent-soft: #fff1e7;
  --blue: #2563eb;
  --ok: #15803d;
  --warn-bg: #fff7e6;
  --warn-line: #f5c26b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 27, 45, .06), 0 4px 16px rgba(15, 27, 45, .06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* drawing palette */
  --dw-bg: #f7f9fc;
  --dw-grid: #e3e9f2;
  --dw-wire: #c2410c;
  --dw-wire2: #2563eb;
  --dw-struct: #64748b;
  --dw-feed: #0f172a;
  --dw-ins: #ffffff;
  --dw-box: #fff7ed;
  --dw-ink: #0f172a;
  --dw-dim: #475569;
  --dw-dimbg: #f7f9fc;
  --dw-note: #64748b;
  --dw-accent: #16a34a;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1320;
    --surface: #121c2c;
    --surface-2: #172335;
    --ink: #e7edf6;
    --ink-2: #b6c2d4;
    --muted: #8a98ae;
    --line: #26354b;
    --accent: #fb7a2e;
    --accent-ink: #1a0d03;
    --accent-soft: #2a1a10;
    --blue: #60a5fa;
    --ok: #4ade80;
    --warn-bg: #2a2113;
    --warn-line: #7a5a1e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);

    --dw-bg: #0e1a2b;
    --dw-grid: #1b2a40;
    --dw-wire: #fb923c;
    --dw-wire2: #60a5fa;
    --dw-struct: #8aa0bd;
    --dw-feed: #dbe4f0;
    --dw-ins: #1e2d44;
    --dw-box: #2a1d12;
    --dw-ink: #e7edf6;
    --dw-dim: #a8b6ca;
    --dw-dimbg: #0e1a2b;
    --dw-note: #8a98ae;
    --dw-accent: #4ade80;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 12px 24px;
  background: #0f1b2d;
  color: #e7edf6;
  border-bottom: 1px solid #1d2c44;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand svg { width: 36px; height: 36px; flex: none; background: #17263d; border-radius: 9px; padding: 5px; }
.brand svg path { stroke: #f97316; stroke-width: 2.6; fill: none; stroke-linecap: round; }
.brand h1 { font-size: 18px; letter-spacing: .2px; }
.brand p { margin: 2px 0 0; font-size: 13px; color: #93a3bb; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.btn {
  border: 1px solid transparent; border-radius: 9px; padding: 8px 14px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.btn:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; color: #e7edf6; border-color: #33465f; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.outline { background: transparent; color: var(--ink); border-color: var(--line); }
.btn:focus-visible, .chip:focus-visible, .design:focus-visible, .seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.seg { display: inline-flex; background: #17263d; border: 1px solid #2a3b55; border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: transparent; color: #a7b6cb; padding: 6px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; font-weight: 600; }
.seg button[aria-pressed="true"] { background: #e7edf6; color: #0f1b2d; }

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 20px;
  max-width: 1440px; margin: 0 auto; padding: 20px 24px;
  align-items: start;
}
.panel {
  position: sticky; top: 84px;
  max-height: calc(100vh - 100px); overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.ctl { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.ctl:last-child { border-bottom: 0; }
.ctl h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-2); display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.step { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 11px; letter-spacing: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  padding: 5px 10px; border-radius: 999px; cursor: pointer; font-size: 13px; font-weight: 600;
  font-family: var(--mono);
}
.chip:hover { border-color: var(--accent); }
.chip[aria-checked="true"], .chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chips.small { margin-top: 8px; }
.chips.small .chip { font-family: var(--sans); font-weight: 500; font-size: 12px; padding: 3px 9px; }

.freq-row { margin-top: 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.freq-row label { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.freq-input { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); overflow: hidden; }
.freq-input input { width: 120px; border: 0; background: transparent; padding: 7px 10px; font-family: var(--mono); font-weight: 600; text-align: right; }
.freq-input input:focus { outline: none; }
.freq-input:focus-within { border-color: var(--accent); }
.freq-input span { padding: 0 10px; color: var(--muted); font-size: 13px; }
.hint { margin: 8px 0 0; font-size: 12.5px; color: var(--muted); }
.hint.bad { color: #dc2626; font-weight: 600; }

.designs { display: grid; gap: 8px; }
.design {
  text-align: left; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px;
  padding: 10px 12px; cursor: pointer; display: grid; gap: 2px;
}
.design:hover:not([disabled]) { border-color: var(--accent); }
.design[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.design[disabled] { opacity: .45; cursor: not-allowed; }
.design .row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.design strong { font-size: 14px; }
.design .tag { font-size: 11px; color: var(--muted); white-space: nowrap; }
.design .blurb { font-size: 12.5px; color: var(--ink-2); }

.fields { display: grid; gap: 12px; margin-bottom: 12px; }
.field { display: grid; gap: 4px; }
.field label { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.field select, .field input {
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); padding: 7px 10px; width: 100%;
}
.field select:focus, .field input:focus { outline: none; border-color: var(--accent); }
.field .unit-input { display: flex; align-items: center; gap: 8px; }
.field .unit-input span { color: var(--muted); font-size: 13px; }

/* ---------- results ---------- */
.results { display: grid; gap: 16px; min-width: 0; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; min-width: 0;
}
.card h3 { font-size: 15px; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card h3 small { font-weight: 500; color: var(--muted); font-size: 12.5px; }

.hero { display: grid; gap: 12px; }
.hero .kicker { font-family: var(--mono); font-size: 12px; color: var(--accent); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.hero h2 { font-size: 26px; }
.hero p { margin: 0; color: var(--ink-2); }
.specs { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.spec { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.spec span { display: block; font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.spec b { font-size: 13.5px; }

.alert { border: 1px solid var(--warn-line); background: var(--warn-bg); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.alert + .alert { margin-top: 8px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
td.key { font-family: var(--mono); font-weight: 700; color: var(--accent); width: 56px; }
td.num { font-family: var(--mono); font-weight: 700; white-space: nowrap; }
td.alt { font-family: var(--mono); color: var(--muted); white-space: nowrap; }
td.cut { font-family: var(--mono); font-weight: 700; color: var(--ok); white-space: nowrap; }
.table-wrap { overflow-x: auto; }

.drawing { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.drawing svg { display: block; width: 100%; height: auto; }
.drawing + .drawing { margin-top: 12px; }
.drawing-bar { display: flex; justify-content: flex-end; gap: 6px; padding: 6px 8px; background: var(--surface-2); border-top: 1px solid var(--line); }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; counter-reset: s; }
.steps li { display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; }
.steps input { width: 20px; height: 20px; margin: 3px 0 0; accent-color: var(--accent); }
.steps .t { font-weight: 700; }
.steps .b { color: var(--ink-2); margin-top: 2px; }
.steps li.done .t, .steps li.done .b { text-decoration: line-through; opacity: .55; }
.steps b { color: var(--ink); font-family: var(--mono); }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
ul.plain { margin: 0; padding-left: 18px; color: var(--ink-2); }
ul.plain li + li { margin-top: 4px; }

.tuner { display: grid; gap: 12px; }
.tuner .row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.tuner .row .field { min-width: 170px; }
.tuner output { display: block; }
.tune-result { font-size: 14px; }
.tune-result td.delta-short { color: #dc2626; font-family: var(--mono); font-weight: 700; }
.tune-result td.delta-long { color: var(--blue); font-family: var(--mono); font-weight: 700; }

.empty { padding: 60px 20px; text-align: center; color: var(--muted); }

.foot { max-width: 1440px; margin: 0 auto; padding: 4px 24px 32px; color: var(--muted); font-size: 12.5px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: #0f1b2d; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.print-only { display: none; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .panel { position: static; max-height: none; }
  .two { grid-template-columns: 1fr; }
  .topbar { padding: 10px 16px; position: static; }
}
@media (max-width: 520px) {
  .hero h2 { font-size: 21px; }
  .card { padding: 14px; }
  .brand p { display: none; }
  .freq-input input { width: 100px; }
  th, td { padding: 6px; }
}

/* ---------- print ---------- */
@media print {
  @page { margin: 0.5in; }
  :root {
    --bg: #fff; --surface: #fff; --surface-2: #fff; --ink: #000; --ink-2: #222; --muted: #555; --line: #bbb;
    --dw-bg: #fff; --dw-dimbg: #fff; --dw-ins: #fff; --dw-box: #fff;
  }
  body { background: #fff; font-size: 11pt; }
  .topbar, .panel, .foot .no-print, .drawing-bar, .toast, .no-print, .tuner .row { display: none !important; }
  .layout { display: block; padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; padding: 0 0 12pt; break-inside: avoid-page; }
  .card.drawings { break-inside: auto; }
  .drawing { break-inside: avoid; border-color: #999; }
  .steps input { appearance: none; -webkit-appearance: none; border: 1px solid #000; width: 12pt; height: 12pt; border-radius: 2px; }
  .print-only { display: block; }
  .two { grid-template-columns: 1fr 1fr; }
  a { color: inherit; text-decoration: none; }
}

/* ---------- tuning verdicts ---------- */
.verdict { border-radius: 10px; padding: 10px 12px; font-weight: 600; border: 1px solid var(--line); background: var(--surface-2); margin-top: 4px; }
.verdict + .verdict { margin-top: 8px; }
.verdict.small { font-weight: 500; font-size: 14px; }
.verdict.ok { border-color: #22c55e; background: color-mix(in srgb, #22c55e 12%, var(--surface)); }
.verdict.warn { border-color: var(--warn-line); background: var(--warn-bg); }
.verdict.bad { border-color: #ef4444; background: color-mix(in srgb, #ef4444 10%, var(--surface)); }
.match-tip { margin: 10px 0 0; padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 8px 8px 0; color: var(--ink-2); }
.tune-result .table-wrap { margin-top: 10px; }

/* ---------- analyzer ---------- */
.tuner .row .field.grow { flex: 1 1 260px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-top: 4px; }
.tab {
  border: 1px solid transparent; border-bottom: 0; background: transparent; color: var(--ink-2);
  padding: 8px 14px; border-radius: 9px 9px 0 0; cursor: pointer; font-weight: 600; font-size: 14px; margin-bottom: -1px;
}
.tab:hover:not([disabled]) { color: var(--ink); }
.tab[aria-selected="true"] { background: var(--surface); border-color: var(--line); color: var(--accent); }
.tab[disabled] { opacity: .4; cursor: not-allowed; }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#anPane { display: grid; gap: 10px; padding-top: 4px; }
#anPane .hint { margin: 0; }
#anPane code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; }
.signcheck { display: grid; gap: 6px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: 10px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
textarea#sweepText {
  width: 100%; font-family: var(--mono); font-size: 13px; line-height: 1.5;
  border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); padding: 8px 10px; resize: vertical; color: var(--ink);
}
textarea#sweepText:focus { outline: none; border-color: var(--accent); }
.row.tight { gap: 6px; align-items: center; }
.btn.file { position: relative; overflow: hidden; display: inline-block; }
.btn.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.verdict.info { border-color: var(--blue); background: color-mix(in srgb, var(--blue) 8%, var(--surface)); }
.drawing.chart svg { display: block; width: 100%; height: auto; }
#tuneOut { display: grid; gap: 8px; }
#tuneOut > .verdict + .verdict { margin-top: 0; }
@media print { #anTabs, #anPane, #anModelInfo, .tuner .row { display: none !important; } }
