:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --ink: #151515;
  --muted: #4a4a4a;
  --line: #2a2a2a;
  --soft: #d9d6cf;
  --accent: #b5301a;
  --accent-ink: #ffffff;
  --err: #a8200d;
  --err-bg: #fbe9e5;
  --note-bg: #ecebe5;
  --band: #151515;
  --band-ink: #f6f5f1;
  --r: 3px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --surface: #1b1b1b;
    --ink: #ececea;
    --muted: #c4c2bd;
    --line: #8d8a84;
    --soft: #3a3936;
    --accent: #ff8a6b;
    --accent-ink: #151515;
    --err: #ff9b85;
    --err-bg: #3a1d17;
    --note-bg: #26251f;
    --band: #000;
    --band-ink: #ececea;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
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, Arial, sans-serif; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
a { color: var(--accent); text-underline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); color: var(--ink); padding: 10px 14px; z-index: 10; }
.skip:focus { left: 8px; top: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.top { background: var(--band); color: var(--band-ink); padding: 22px 0 20px; border-bottom: 6px solid var(--accent); }
h1 { font-size: clamp(1.75rem, 1.2rem + 2.2vw, 2.6rem); line-height: 1.1; margin: 0 0 8px; font-weight: 850; letter-spacing: -0.02em; }
.lede { margin: 0; max-width: 62ch; font-size: 1.05rem; }
h2 { font-size: 1.35rem; line-height: 1.25; margin: 0 0 12px; font-weight: 800; letter-spacing: -0.01em; }
h3 { font-size: 1.08rem; margin: 22px 0 4px; }

.tool { display: grid; gap: 24px 28px; padding-top: 18px; padding-bottom: 28px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) {
  .tool { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); grid-template-rows: auto auto auto 1fr auto; grid-template-areas: "notes notes" "jig res" "reg res" ". res" "run run"; align-items: start; }
  .notes { grid-area: notes; } #jig { grid-area: jig; } #reg { grid-area: reg; } .result { grid-area: res; } .run { grid-area: run; }
}
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { font-weight: 800; font-size: 1.15rem; padding: 0; margin-bottom: 8px; }
.grp { margin-top: 18px; }
.grp.first { margin-top: 0; }
.headrow { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 4px; }
.legend { font-weight: 800; font-size: 1.15rem; }
.seg { display: inline-flex; border: 2px solid var(--line); border-radius: var(--r); overflow: hidden; }
.seg.units label { min-width: 56px; }
.seg.wide { display: flex; margin-bottom: 10px; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg label { flex: 1 1 0; min-height: 44px; display: flex; align-items: center; justify-content: center; text-align: center; padding: 6px 14px; cursor: pointer; font-weight: 650; line-height: 1.2; }
.seg label + input + label { border-left: 2px solid var(--line); }
.seg input:checked + label { background: var(--ink); color: var(--bg); }
.seg input:focus-visible + label { outline: 3px solid var(--accent); outline-offset: -5px; }
.reg .grp { margin-top: 0; }

.pair { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; }
.pair + .pair { margin-top: 10px; }
.fld { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.fld.grow { flex: 1 1 150px; }
.fld label { font-size: 0.95rem; font-weight: 600; color: var(--muted); }
.x { padding-bottom: 10px; font-weight: 700; }
.pair.wh { flex-wrap: nowrap; }
.pair.wh .fld { flex: 0 1 auto; }
.pair.wh .box { max-width: 100%; }
.pair.wh .box input { flex: 1 1 auto; width: 5.6em; min-width: 3.2em; }
input[type=text], select, textarea {
  font: inherit; font-size: 17px; color: var(--ink); background: var(--surface); border: 1.5px solid var(--line);
  border-radius: var(--r); min-height: 44px; padding: 7px 10px;
}
select { padding-right: 28px; max-width: 100%; }
.box { display: inline-flex; align-items: center; border: 1.5px solid var(--line); border-radius: var(--r); background: var(--surface); }
.box input { border: 0; width: 5.6em; min-width: 0; background: transparent; }
.box .u { padding-right: 10px; color: var(--muted); font-size: 0.95rem; }
.box:focus-within { outline: 3px solid var(--accent); outline-offset: 1px; }
.box input:focus-visible { outline: none; }
.box:has(input[aria-invalid=true]) { border-color: var(--err); border-width: 2px; }
input[aria-invalid=true], select[aria-invalid=true] { border-color: var(--err); border-width: 2px; }
.err { color: var(--err); margin: 4px 0 0; font-weight: 600; }
.err:empty { display: none; }

.result { background: var(--surface); border: 2px solid var(--line); border-radius: var(--r); padding: 16px; }
.big { font-size: 1.2rem; font-weight: 750; margin: 0 0 10px; line-height: 1.35; }
.facts { margin: 0 0 12px; display: grid; grid-template-columns: minmax(0, 11em) minmax(0, 1fr); gap: 6px 14px; }
.facts dt { font-weight: 650; color: var(--muted); }
.facts dd { margin: 0; }
@media (max-width: 520px) { .facts { grid-template-columns: minmax(0, 1fr); gap: 0; } .facts dd { margin-bottom: 8px; } }
.ov { border: 1px solid var(--soft); background: #fff; padding: 6px; margin-top: 14px; }
.ov svg { display: block; width: 100%; height: auto; max-height: 380px; }
.sheets-line { font-weight: 650; margin: 12px 0 8px; }
.problem { background: var(--err-bg); color: var(--err); font-weight: 650; padding: 10px 12px; border-radius: var(--r); margin: 0 0 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin: 10px 0; }
.tip { margin: 6px 0 0; }
.note { background: var(--note-bg); padding: 10px 12px; border-radius: var(--r); margin: 8px 0; overflow-wrap: anywhere; }

.btn { font: inherit; font-weight: 700; min-height: 44px; padding: 8px 16px; border: 2px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--ink); cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.quiet { border-color: transparent; background: transparent; text-decoration: underline; padding-left: 4px; padding-right: 4px; }
.btn.danger { border-color: var(--err); color: var(--err); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.link-btn { font: inherit; background: none; border: 0; color: var(--accent); text-decoration: underline; cursor: pointer; padding: 4px 2px; min-height: 44px; }

.run { border-top: 6px solid var(--ink); padding-top: 16px; }
.sub { margin: -4px 0 12px; }
.run-top input#title { width: 100%; }
.run-top input#ed, .run-top input#spare { width: 6em; }
.pull { font-weight: 700; margin: 12px 0; }
.pull:empty { display: none; }
.layers { list-style: none; margin: 0; padding: 0; border-top: 1.5px solid var(--line); }
.layer { display: grid; grid-template-columns: 1.8em minmax(0, 1fr); gap: 6px 8px; align-items: center; padding: 10px 0; border-bottom: 1.5px solid var(--soft); }
.layer .num { grid-row: 1 / span 2; font-weight: 800; font-size: 1.15rem; align-self: start; padding-top: 8px; }
.ltop, .lmeta { display: flex; align-items: center; gap: 8px; min-width: 0; }
.lmeta { flex-wrap: wrap; gap: 4px 14px; }
.layer .col { flex: none; width: 48px; height: 44px; padding: 2px; border: 1.5px solid var(--line); border-radius: var(--r); background: var(--surface); cursor: pointer; }
.layer .name { flex: 1 1 auto; min-width: 0; width: 100%; }
.layer .done { display: flex; align-items: center; gap: 8px; min-height: 44px; font-weight: 650; cursor: pointer; white-space: nowrap; }
.layer .done input { width: 22px; height: 22px; accent-color: var(--accent); }
.layer .tools { display: flex; gap: 4px; margin-left: auto; }
.layer .tb { flex: none; min-width: 44px; min-height: 44px; font: inherit; font-weight: 700; background: var(--surface); color: var(--ink); border: 1.5px solid var(--soft); border-radius: var(--r); cursor: pointer; }
.layer .tb:disabled { opacity: 0.4; cursor: default; }
@media (min-width: 760px) {
  .layer { grid-template-columns: 1.8em minmax(0, 1fr) auto; }
  .layer .num { grid-row: auto; padding-top: 0; align-self: center; }
  .ltop { grid-column: 2; } .lmeta { grid-column: 3; flex-wrap: nowrap; }
  .ltop .tb { order: 3; }
}
.layer .when { color: var(--muted); font-weight: 500; font-size: 0.95rem; }
.empty { margin: 10px 0; }
.clear-row { margin-top: 8px; }
.earlier { margin-top: 14px; }
.earlier summary { cursor: pointer; font-weight: 700; min-height: 44px; display: flex; align-items: center; }
.earlier ul { padding-left: 18px; }
.earlier li { margin: 6px 0; }

.undo-bar { position: fixed; left: 50%; transform: translateX(-50%); bottom: 14px; z-index: 20; background: var(--ink); color: var(--bg); padding: 8px 10px 8px 16px; border-radius: var(--r); display: flex; gap: 10px; align-items: center; max-width: calc(100% - 24px); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); }
.undo-bar[hidden] { display: none; }
.undo-bar .btn { background: var(--bg); color: var(--ink); border-color: var(--bg); }
.undo-bar .btn.quiet { background: transparent; color: var(--bg); text-decoration: none; }
[hidden] { display: none !important; }

.about { padding-bottom: 36px; }
.about > * { max-width: 760px; }
.about h2 { margin-top: 30px; }
.steps { padding-left: 1.3em; }
.steps li { margin-bottom: 8px; }
.faq p { margin: 0 0 6px; }
.sources { margin-top: 26px; font-size: 1rem; color: var(--muted); overflow-wrap: anywhere; }

.site-foot { border-top: 2px solid var(--line); padding: 18px 0 30px; }
.sb-footer p { margin: 8px 0; }
.sb-more { line-height: 1.9; }
.sb-privacy, .sb-credit { color: var(--muted); }

.print-root { display: none; }

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

@media print {
  body { background: #fff; color: #000; font: 10.5pt/1.4 Helvetica, Arial, sans-serif; }
  body > *:not(.print-root) { display: none !important; }
  .print-root { display: block !important; }
  .print-root[data-what=jig] .pr-run, .print-root[data-what=run] .pr-jig { display: none !important; }
  .sheet-svg { display: block; break-after: page; }
  .pr-jig > .sheet-svg:last-child { break-after: auto; }
  .setup { break-after: page; }
  .ptitle { font-size: 17pt; font-weight: 700; margin: 0 0 3mm; }
  .setup p, .runsheet p { margin: 0 0 2.5mm; }
  .setup table { border-collapse: collapse; width: calc(100% - 1px); margin: 0 0 4mm; }
  .setup td, .setup th { border-bottom: 0.3mm solid #999; padding: 1.2mm 2mm 1.2mm 0; text-align: left; vertical-align: top; font-size: 10pt; }
  .setup th { width: 46mm; }
  .setup .ovp svg { display: block; width: 100%; height: auto; max-height: 105mm; }
  .setup.land { display: grid; grid-template-columns: minmax(0, 1fr) 100mm; column-gap: 8mm; align-items: start; }
  .setup.land > * { grid-column: 1; }
  .setup.land > .ovp { grid-column: 2; grid-row: 1 / span 5; }
  .setup.land .ovp svg { max-height: 165mm; }
  .setup ol { margin: 3mm 0 0; padding-left: 5mm; font-size: 10pt; }
  .setup li { margin-bottom: 1mm; }
  .runsheet table { border-collapse: collapse; width: calc(100% - 1px); table-layout: fixed; }
  .runsheet .c-n { width: 8mm; } .runsheet .c-col { width: 46mm; } .runsheet .c-date { width: 16mm; } .runsheet .c-good { width: 19mm; }
  .runsheet th, .runsheet td { border: 0.3mm solid #444; padding: 1.6mm 2mm; text-align: left; vertical-align: top; font-size: 10pt; }
  .runsheet thead th { background: none; }
  .runsheet tbody tr { break-inside: avoid; }
  .runsheet .sw { display: inline-block; width: 7mm; height: 7mm; border: 0.3mm solid #000; vertical-align: middle; margin-right: 2mm; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .runsheet .boxes { display: grid; gap: 1mm; }
  .runsheet .boxes span { display: inline-block; width: 6.2mm; height: 6.2mm; border: 0.3mm solid #000; font-size: 7pt; line-height: 1; padding: 0.4mm; color: #222; }
  .runsheet .blank { height: 12mm; }
  .runsheet .tally { padding: 3mm 0; font-size: 10.5pt; }
}
