:root {
  color-scheme: light;
  --bg: #f7f1e3;
  --surface: #fffdf5;
  --surface-2: #efe5cd;
  --ink: #231c10;
  --muted: #5e543f;
  --line: #d3c4a1;
  --accent: #6d1f14;
  --accent-ink: #ffffff;
  --focus: #1a4fd6;
  --ok: #1e6b2e;
  --bad: #a31616;
  --radius: 10px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12100a;
  --surface: #1d1810;
  --surface-2: #2a2314;
  --ink: #f2e8d2;
  --muted: #c2b48f;
  --line: #4c4128;
  --accent: #eda07a;
  --accent-ink: #241105;
  --focus: #9db9ff;
  --ok: #8fd694;
  --bad: #ff9d9d;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", "DejaVu Serif", serif;
  line-height: 1.6;
  font-size: 1.0625rem;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: 3rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  white-space: nowrap;
}

.topbar .home { font-weight: bold; color: var(--ink); text-decoration: none; flex: none; }
.topnav { display: flex; gap: 0.25rem; overflow-x: auto; scrollbar-width: none; }
.topnav::-webkit-scrollbar { display: none; }
.topnav a { flex: none; padding: 0.5rem 0.6rem; color: var(--muted); text-decoration: none; border-radius: 6px; }
.topnav a[aria-current="true"] { color: var(--ink); font-weight: bold; }
.topbar .spacer { flex: 1; }
.topbar .chip { flex: none; color: var(--accent); }
.icon-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.icon-btn svg { display: block; }
.icon-btn svg[hidden] { display: none; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

main {
  max-width: 60rem;
  margin: 0 auto;
  padding: 0 1.25rem 4rem;
}

section { scroll-margin-top: 3.75rem; }

.hero { padding: 2.5rem 0 1rem; max-width: 44rem; }
.hero h1 {
  font-size: clamp(2rem, 5vw, 3.1rem);
  line-height: 1.12;
  margin: 0 0 1rem;
  text-wrap: balance;
}
.deck { font-size: 1.2rem; color: var(--muted); margin: 0 0 1rem; }
.deck strong { color: var(--ink); }
.answer-line {
  font-size: 1.15rem;
  border-left: 4px solid var(--accent);
  padding: 0.5rem 0 0.5rem 1rem;
  margin: 1.25rem 0 0;
}
.answer-line strong { font-variant-numeric: tabular-nums; }

/* ---------- calculator ---------- */
.calc {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-top: 1.5rem;
}
@media (max-width: 46rem) {
  .calc { grid-template-columns: 1fr; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.25rem 1.5rem;
}

.field { margin-bottom: 1.25rem; }
.field:last-child { margin-bottom: 0; }
.field > label, .legend {
  display: block;
  font-weight: bold;
  margin-bottom: 0.4rem;
}
.hint { color: var(--muted); font-size: 0.95rem; margin: 0.35rem 0 0; }
.parsed { color: var(--muted); font-size: 0.95rem; min-height: 1.5em; margin: 0.2rem 0 0; font-variant-numeric: tabular-nums; }

.presets { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.6rem; }
.presets button {
  font: inherit;
  font-variant-numeric: tabular-nums;
  min-width: 3.5rem;
  min-height: 44px;
  padding: 0.35rem 0.7rem;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
}
.presets button.on {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: bold;
}

input[type="text"], input[type="number"] {
  font: inherit;
  font-variant-numeric: tabular-nums;
  width: 100%;
  max-width: 16rem;
  padding: 0.6rem 0.75rem;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
}
input[aria-invalid="true"] { border-color: var(--bad); }

.w-row { display: flex; align-items: center; gap: 0.5rem; }
.w-row input { max-width: 9rem; }
.unit { color: var(--muted); font-weight: bold; }

/* ---------- decoder ---------- */
.decode-grid {
  display: grid;
  grid-template-columns: auto auto auto;
  justify-content: start;
  column-gap: 2rem;
  row-gap: 0.75rem;
  align-items: end;
}
@media (max-width: 40rem) {
  .decode-grid { grid-template-columns: 1fr; }
  .swap-wrap { justify-content: start; }
}
.swap-wrap { display: flex; justify-content: center; padding-bottom: 0.35rem; }

.error {
  color: var(--bad);
  font-weight: bold;
  margin: 0.75rem 0 0;
  min-height: 1.5em;
}

.btn-row { display: flex; gap: 0.6rem; margin-top: 1rem; flex-wrap: wrap; }
.btn {
  font: inherit;
  font-weight: bold;
  min-height: 44px;
  padding: 0.5rem 1.1rem;
  border-radius: 8px;
  border: 2px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}
.copy-status { color: var(--muted); font-size: 0.95rem; align-self: center; margin: 0; }
.btn-ghost {
  font: inherit;
  font-weight: bold;
  min-height: 44px;
  min-width: 44px;
  padding: 0.5rem 0.8rem;
  border-radius: 8px;
  border: 2px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
}

.cell-card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin-top: 1rem;
}
.cell-code {
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  font-size: 1.9rem;
  font-weight: bold;
  letter-spacing: 0.03em;
  margin: 0;
  font-variant-numeric: tabular-nums;
}
.cell-spec { font-size: 1.12rem; margin: 0.2rem 0 0; font-variant-numeric: tabular-nums; }
.cell-spec strong { font-size: 1.3rem; }
.cell-chem { color: var(--muted); margin: 0.25rem 0 0; }

.verdict {
  margin-top: 1rem;
  padding: 0.9rem 1rem;
  border-radius: var(--radius);
  border: 2px solid var(--line);
  background: var(--surface-2);
  font-size: 1.08rem;
}
.verdict[data-verdict="same"],
.verdict[data-verdict="same-size"],
.verdict[data-verdict="chemistry"] { border-color: var(--ok); }
.verdict[data-verdict="voltage"],
.verdict[data-verdict="diameter"],
.verdict[data-verdict="thinner"],
.verdict[data-verdict="thicker"] { border-color: var(--bad); }

.compare-fig { margin-top: 1.25rem; }
.compare-fig h3 { font-size: 1.05rem; margin: 0 0 0.25rem; }
.compare-fig svg { width: 100%; height: auto; display: block; }
.compare-fig .cell-main { fill: var(--accent); }
.compare-fig .cell-side { fill: var(--muted); opacity: 0.55; }
.compare-fig .cell-cap {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
  fill: var(--muted);
}
.compare-note { color: var(--muted); font-size: 0.95rem; margin: 0.4rem 0 0; }

.quick-compare { margin-top: 0.9rem; display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.qc-label { color: var(--muted); }
.qc-btn {
  font: inherit;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  min-height: 44px;
  padding: 0.35rem 0.8rem;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
}
.qc-btn[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: bold;
}

/* ---------- prose sections ---------- */
.prose { max-width: 44rem; }
.prose h2 { font-size: 1.7rem; margin: 3rem 0 0.75rem; line-height: 1.25; }
.prose p { margin: 0 0 1rem; }
.prose a { color: var(--accent); }
.formula {
  font-size: 1.25rem;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  font-variant-numeric: tabular-nums;
}

table.times {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-variant-numeric: tabular-nums;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
table.times caption { text-align: left; padding: 0 0 0.5rem; color: var(--muted); }
table.times th, table.times td {
  padding: 0.55rem 0.75rem;
  text-align: right;
  border-bottom: 1px solid var(--line);
}
table.times th:first-child, table.times td:first-child { text-align: left; }
table.times thead th { background: var(--surface-2); }
table.times tbody tr:last-child th, table.times tbody tr:last-child td { border-bottom: none; }
table.times td.hl { font-weight: bold; color: var(--accent); }
.table-wrap { overflow-x: auto; }

details.faq {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 0.6rem;
  padding: 0.75rem 1rem;
}
details.faq summary {
  font-weight: bold;
  cursor: pointer;
  min-height: 44px;
}
details.faq p { margin: 0.5rem 0 0; }

.sources ul { padding-left: 1.25rem; }
.sources li { margin-bottom: 0.5rem; }
.sources a { color: var(--accent); overflow-wrap: anywhere; }

footer.site {
  display: flex;
  align-items: center;
  gap: 1rem;
  max-width: 60rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2.5rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
}
footer.site a { color: var(--accent); }
footer.site .spacer { flex: 1; }

.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;
}
