:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --panel: #dde5ee;
  --ink: #111820;
  --muted: #3f4a56;
  --line: #b4bfca;
  --accent: #1c4f8c;
  --accent-ink: #ffffff;
  --plate: #b9873f;
  --focus: #b3460b;
  --err: #a3231a;
  --r: 3px;
  --r2: 10px;
  --num: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --head: Futura, "Century Gothic", "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b;
    --surface: #181e26;
    --panel: #1d2631;
    --ink: #e8edf2;
    --muted: #b6c1cc;
    --line: #3a4654;
    --accent: #8fbdf0;
    --accent-ink: #0b1522;
    --plate: #d6a45c;
    --focus: #ffb07a;
    --err: #ff9a8c;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
main { max-width: 1200px; margin: 0 auto; padding: 0 16px 24px; }
a { color: var(--accent); }
h1, h2, h3, legend, .big, .big-label { font-family: var(--head); }
h1 { font-size: 2rem; line-height: 1.15; margin: 0 0 8px; font-weight: 700; }
h2 { font-size: 1.4rem; line-height: 1.2; margin: 0 0 10px; }
h3 { font-size: 1.12rem; margin: 18px 0 6px; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 30; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.top { padding: 18px 0 12px; max-width: 46rem; }
.lede { margin: 0; color: var(--muted); }

/* form */
.tool { display: grid; gap: 14px; }
fieldset { border: 0; padding: 0; margin: 0 0 14px; min-width: 0; }
legend, label { font-weight: 650; }
legend { padding: 0; margin-bottom: 4px; font-size: 1.05rem; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; margin: 0 0 10px; }
.field legend { font-size: inherit; font-family: inherit; }
input[type="text"], select {
  font: inherit; font-size: 16px; min-height: 44px; padding: 8px 10px; width: 100%;
  color: var(--ink); background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--r);
}
input::placeholder { color: var(--muted); opacity: 1; }
input[aria-invalid] { border-color: var(--err); }
.err { color: var(--err); margin: 0; font-size: 1rem; }
.hint { margin: 0 0 4px; color: var(--muted); font-size: 1rem; }
.wide-hint { grid-column: 1 / -1; margin-top: -4px; }
/* one column: keep the balance point hint straight under its box */
.hrow { container-type: inline-size; }
@container (width < 294px) { .hrow > .field:nth-child(2) { order: 2; } .hrow > .wide-hint { order: 1; margin: 2px 0 8px; } }
.wide-field { grid-column: 1 / -1; }
.row2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0 14px; align-items: end; }
.row3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 0 12px; align-items: end; }
.gap-top { margin-top: 10px; }
.with-seg { display: grid; grid-template-columns: minmax(0, 1fr) 104px; gap: 8px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1.5px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--surface); }
.seg label { position: relative; display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 4px 6px; cursor: pointer; font-weight: 600; text-align: center; line-height: 1.2; }
.seg label + label { border-left: 1.5px solid var(--line); }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg label:has(input:checked) { background: var(--accent); color: var(--accent-ink); }
.seg label:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: -3px; }
.seg-field .seg { margin-top: 0; }

/* result */
.result { background: var(--panel); border-radius: var(--r2); padding: 16px; min-width: 0; }
.bigs { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 6px 18px; }
.big-label { margin: 0; font-weight: 700; color: var(--muted); }
.big { margin: 0; font-size: 2.2rem; line-height: 1.1; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); overflow-wrap: anywhere; }
.big-sub { margin: 2px 0 0; font-weight: 650; color: var(--ink); }
.big.big-s { font-size: 1.3rem; padding-top: 8px; }
.big-d { font-size: 1.8rem; }
.fix { margin: 0; font-weight: 650; color: var(--err); }
.problems, .notes { margin: 10px 0 0; padding-left: 1.2em; }
.problems li, .notes li { margin-bottom: 6px; }
.notes { color: var(--ink); }
.diagram { margin: 12px 0 4px; }
.diagram svg { width: 100%; height: auto; max-height: 320px; display: block; }
.diagram figcaption { margin-top: 4px; color: var(--muted); }
@media (min-width: 900px) { .preview { align-items: start; } }
svg .gb { fill: var(--line); }
svg .top { fill: var(--plate); }
svg .axis { stroke: var(--accent); fill: none; }
svg .plate { stroke: var(--plate); stroke-linecap: round; fill: none; }
svg .roller { fill: var(--surface); stroke: var(--ink); }
svg .pivot { fill: var(--ink); }
svg .cg { fill: var(--accent); }
svg .dim { stroke: var(--muted); fill: none; }
svg .lb { fill: var(--ink); font-family: system-ui, sans-serif; font-weight: 600; paint-order: stroke; stroke: var(--panel); stroke-width: 0.3em; stroke-linejoin: round; }
.nums { width: 100%; border-collapse: collapse; margin: 10px 0 6px; font-variant-numeric: tabular-nums; }
.nums th, .nums td { text-align: left; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.nums thead th { font-family: var(--head); font-weight: 700; }
.nums tbody th { font-weight: 600; color: var(--muted); }
.nums tbody tr:last-child > * { border-bottom: 0; }
.nums td.n { white-space: nowrap; }
.line { margin: 8px 0 0; }

.more { min-width: 0; }

/* disclosures: help that most visitors skip */
.help { margin: 4px 0 12px; }
.help summary { cursor: pointer; font-weight: 650; color: var(--accent); min-height: 44px; display: flex; align-items: center; }
.help[open] { padding-bottom: 4px; }
.help p, .help ul { margin: 0 0 8px; }
.help ul { padding-left: 1.2em; }
.help dl { margin: 0; }
.help dt { font-weight: 650; margin-top: 6px; }
.help dd { margin: 0; }
.bal-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 14px; align-items: end; }
.bal-out { font-weight: 650; margin: 4px 0 8px; }
.bal-out:empty { display: none; }
#bal-use { margin-bottom: 10px; }
.acts { margin: 10px 0 4px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.acts p { margin: 0; flex-basis: 100%; }
svg .rad { stroke: var(--ink); fill: none; }

/* drive */
.drive { margin-top: 36px; }
.drive-grid { display: grid; gap: 16px; }
.drive-out { min-width: 0; }
.drive-out:empty { display: none; }

/* templates */
.tpl { margin-top: 36px; }
.tpl-head { display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: center; justify-content: space-between; }
.tpl-head h2 { margin: 0; }
.tpl-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.tpl-actions select { width: auto; }
.inline { font-weight: 650; }
.btn { font: inherit; font-weight: 650; min-height: 44px; padding: 8px 16px; border-radius: var(--r); border: 1.5px solid var(--ink); background: transparent; color: var(--ink); cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.small { min-height: 40px; padding: 4px 12px; }
.note { margin: 10px 0 0; }
.note:empty { display: none; }
.link-out { margin: 8px 0 0; font: 1rem/1.4 var(--num); background: var(--surface); padding: 10px; border-radius: var(--r); overflow-wrap: anywhere; }
.ask { margin-top: 12px; padding: 12px 14px; border: 1.5px solid var(--err); border-radius: var(--r); background: var(--surface); }
.ask p { margin: 0 0 10px; }
.ask .btn { margin: 0 8px 4px 0; }
.earlier { margin-top: 12px; }
.earlier summary { cursor: pointer; font-weight: 650; min-height: 44px; display: flex; align-items: center; color: var(--accent); }
.earlier ul { list-style: none; padding: 0; margin: 0; }
.earlier li { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--line); }
.earlier li span { overflow-wrap: anywhere; }
.preview { display: grid; gap: 18px; margin-top: 14px; }
.pv { margin: 0; background: #fff; color: #000; padding: 8px; border-radius: var(--r); }
.pv svg { width: 100%; height: auto; display: block; }
.pv figcaption { margin-top: 6px; font-weight: 600; }
.pv .tile-r, .mapsvg .tile-r { fill: none; stroke: #6d7c8c; stroke-width: 1; stroke-dasharray: 4 3; }
.pv .tile-n, .mapsvg .tile-n { fill: #3a4654; font: 700 11px system-ui, sans-serif; }
.cut { fill: #f4e9d6; stroke: #000; stroke-width: 0.5; }
.pv .cut { stroke-width: 1.4; }
.cut-l { fill: none; stroke: #000; stroke-width: 0.45; }
.face { fill: none; stroke: #000; stroke-width: 0.3; stroke-dasharray: 2 1.5; }
.cl { stroke: #1c4f8c; stroke-width: 0.35; stroke-dasharray: 6 2 1 2; fill: none; }
.roll { stroke: #b3460b; stroke-width: 0.5; fill: none; }
.rolldot { fill: #b3460b; }
.end { stroke: #000; stroke-width: 0.35; fill: none; }
.lbl { fill: #000; font: 3.6px system-ui, Arial, sans-serif; }
.name { fill: #000; font: 700 4.4px system-ui, Arial, sans-serif; }
@media (min-width: 900px) { .preview { grid-template-columns: repeat(auto-fill, minmax(460px, 1fr)); } }

/* content */
.content { margin-top: 48px; max-width: 70ch; }
.content section { margin-bottom: 30px; }
.content ol { padding-left: 1.3em; }
.content li { margin-bottom: 6px; }
.formula { font-family: var(--num); font-size: 1.05rem; overflow-wrap: anywhere; }
.faq p { margin: 0 0 8px; }
.faq .qa { border-top: 1px solid var(--line); }
.faq .qa summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; padding: 6px 0; }
.faq .qa summary h3 { margin: 0; font-size: 1.05rem; color: var(--accent); }
.sources { color: var(--muted); overflow-wrap: anywhere; }

/* footer */
.foot { border-top: 1px solid var(--line); margin-top: 24px; padding: 20px 16px 32px; color: var(--muted); font-size: 1rem; }
.foot .wrap { max-width: 1200px; margin: 0 auto; }
.sb-footer p { margin: 0 0 10px; }
.sb-more { line-height: 1.9; }
.sb-footer a { color: var(--accent); }
.sb-credit { color: var(--ink); }

#print-root { display: none; }

@media (min-width: 900px) {
  h1 { font-size: 2.5rem; }
  .tool { grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); grid-template-areas: "setup result" "more result"; grid-template-rows: auto 1fr; gap: 8px 40px; align-items: start; }
  .setup { grid-area: setup; }
  .more { grid-area: more; }
  .result { grid-area: result; padding: 20px 22px; }
  .big { font-size: 2.7rem; }
  .drive-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 40px; }
}
@media (max-width: 480px) {
  .big { font-size: 1.75rem; }
  .nums, .nums thead, .nums tbody { display: block; }
  .nums tr { display: grid; grid-template-columns: 1fr 1fr; column-gap: 10px; border-bottom: 1px solid var(--line); padding: 4px 0; }
  .nums.one tr { grid-template-columns: 1fr; }
  .nums tbody tr:last-child { border-bottom: 0; }
  .nums th, .nums td { border-bottom: 0; padding: 2px 0; }
  .nums thead th:first-child { display: none; }
  .nums tbody th { grid-column: 1 / -1; }
  .nums td.n { white-space: normal; }
}
@media (max-width: 380px) {
  h1 { font-size: 1.75rem; }
  .big { font-size: 1.55rem; }
  .with-seg { grid-template-columns: minmax(0, 1fr) 92px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }

/* print: a page of numbers, then the template sheets at true size */
@media print {
  body { background: #fff; color: #000; font-size: 10.5pt; }
  main > *, .foot, .skip { display: none !important; }
  main { padding: 0; max-width: none; }
  main > #print-root { display: block !important; }
  .ppage { break-after: page; page-break-after: always; }
  .ppage.port { page: port; }
  .ppage:last-child { break-after: auto; page-break-after: auto; }
  .tilepage svg.tile { display: block; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .summary { font: 10.5pt/1.35 Helvetica, Arial, sans-serif; color: #000; }
  .summary h2 { font: 700 15pt/1.2 Helvetica, Arial, sans-serif; margin: 0 0 4pt; }
  .summary p { margin: 0 0 5pt; }
  .summary ul { margin: 0 0 5pt; padding-left: 14pt; }
  .summary table { border-collapse: collapse; margin: 4pt 0 7pt; font-variant-numeric: tabular-nums; }
  .summary th, .summary td { text-align: left; padding: 2pt 10pt 2pt 0; border-bottom: 0.5pt solid #888; vertical-align: top; }
  .summary tbody th { font-weight: 400; }
  .summary .howto { margin-top: 6pt; break-inside: avoid; }
  .summary .checkbar { display: block; margin: 2pt 0 6pt; }
  .summary .checkbar rect { fill: #000; }
  .summary .checkbar path { stroke: #000; stroke-width: 0.3; }
  .summary .sumtop { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 3mm 10mm; }
  .summary .sumtop table { flex: 0 1 auto; max-width: 100%; }
  .summary .maps { flex: 1 1 60mm; min-width: 0; display: flex; flex-wrap: wrap; gap: 3mm 8mm; margin-top: 4pt; }
  .summary .map { flex: 1 1 45mm; min-width: 0; break-inside: avoid; }
  .summary .map p { margin: 0 0 2pt; }
  .summary .mapsvg { width: 100%; max-width: 100%; height: auto; max-height: 32mm; display: block; }
  .tile .head text { fill: #000; font-family: Helvetica, Arial, sans-serif; }
  .tile .tname { font-size: 4.6px; font-weight: 700; }
  .tile .tsub { font-size: 3.6px; }
  .tile .bar { fill: #000; }
  .tile .ticks path { stroke: #000; stroke-width: 0.3; }
  .tile .cut { fill: none; stroke-width: 0.45; }
  .tile .frame { fill: none; stroke: #888; stroke-width: 0.3; }
  .tile .ovl { stroke: #555; stroke-width: 0.3; stroke-dasharray: 3 2; fill: none; }
  .tile .reg { stroke: #000; stroke-width: 0.35; }
  .tile .ovt { fill: #444; font: 3.6px Helvetica, Arial, sans-serif; }
}
