:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --ink: #1d2433;
  --muted: #4a5468;
  --line: #c9d1de;
  --line-strong: #8a96aa;
  --accent: #b03a1f;
  --accent-ink: #ffffff;
  --guide: #2f6fb0;
  --page: #ffffff;
  --cover: #e6e9f0;
  --over-bg: #fbe9e4;
  --focus: #2f6fb0;
  --head: "Futura", "Century Gothic", "Avenir Next", "Trebuchet MS", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181f;
    --surface: #1c222c;
    --ink: #e8ecf3;
    --muted: #aab4c5;
    --line: #334055;
    --line-strong: #5d6b82;
    --accent: #f08a6c;
    --accent-ink: #1a0f0b;
    --guide: #7fb2e8;
    --page: #232a36;
    --cover: #181d25;
    --over-bg: #3a2420;
    --focus: #7fb2e8;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.55 var(--body); }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
a { color: var(--guide); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

.top { border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 10px; padding: 12px 0; font: 600 19px/1 var(--head); color: var(--ink); text-decoration: none; letter-spacing: 0.01em; }
.mark { width: 30px; height: 30px; }
.m-page { fill: var(--page); stroke: var(--ink); stroke-width: 1.6; }
.m-turn { stroke: var(--accent); stroke-width: 2; }
.m-text { stroke: var(--guide); stroke-width: 2; stroke-linecap: round; }

.intro { padding: 22px 0 8px; max-width: 46rem; }
h1 { font: 600 clamp(28px, 4.2vw, 40px)/1.15 var(--head); margin: 0 0 8px; letter-spacing: -0.01em; }
.lede { margin: 0; color: var(--muted); font-size: 18px; }
h2 { font: 600 24px/1.25 var(--head); margin: 0 0 10px; }
h3 { font-size: 18px; margin: 22px 0 4px; }

.tool { display: grid; gap: 28px; padding: 18px 0 36px; }
@media (min-width: 980px) {
  .tool { grid-template-columns: minmax(340px, 410px) minmax(0, 1fr); gap: 40px; align-items: start; }
}
.setup { display: grid; gap: 16px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend, .field > label, .ms-head label { font-weight: 600; padding: 0; margin-bottom: 6px; display: block; }
.field { display: grid; gap: 0; min-width: 0; }
.field.inline { margin-top: 10px; max-width: 12rem; }
input[type=text], select, textarea {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: 4px; padding: 9px 10px; min-height: 44px; width: 100%;
}
textarea { line-height: 1.5; resize: vertical; min-height: 260px; }
select { padding-right: 28px; }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 16px; }
.err { margin: 6px 0 0; color: var(--accent); font-weight: 600; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }

.seg { display: flex; flex-wrap: wrap; border: 1px solid var(--line-strong); border-radius: 4px; overflow: hidden; width: fit-content; max-width: 100%; }
.seg label { position: relative; flex: 1 1 auto; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 44px; min-width: 52px; padding: 0 14px; border-right: 1px solid var(--line); background: var(--surface); white-space: nowrap; }
.seg label:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--ink); color: var(--bg); font-weight: 600; }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: -3px; }
.seg-wide { width: 100%; }
.seg-wide span { white-space: normal; text-align: center; padding: 4px 10px; }

.more { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 2px 0; }
.more summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; gap: 0.3em; font-weight: 600; }
.more[open] { padding-bottom: 14px; }
.more[open] > * + * { margin-top: 10px; }

.trim-row { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr); gap: 10px; align-items: end; }
.trim-row .units { grid-column: 1 / -1; }
.trim-f { padding-bottom: 12px; }
.budget { max-width: 14rem; }
.suffix { position: relative; display: block; }
.suffix input { padding-right: 40px; }
.suffix .unit { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 400; pointer-events: none; }

.ms { display: grid; gap: 10px; }
.ms-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; justify-content: space-between; }
.ms-head label { margin: 0; }
.sample-tag { color: var(--muted); font-size: 16px; }
.clear-row { margin: 0; }
.ask { margin: 0; padding: 10px 12px; background: var(--over-bg); border-radius: 4px; }
.link-btn { font: inherit; background: none; border: 0; padding: 10px 0; min-height: 44px; color: var(--guide); text-decoration: underline; cursor: pointer; }
.btn { font: inherit; font-weight: 600; min-height: 44px; padding: 8px 18px; border-radius: 4px; border: 1px solid var(--ink); background: var(--surface); color: var(--ink); cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { min-height: 40px; padding: 4px 14px; }

/* Result */
.result h2 { margin-bottom: 2px; }
.result h2:focus { outline: none; }
.res-sub { margin: 0 0 14px; color: var(--muted); }
.res-sub b { color: var(--ink); }
.res-sub .over { color: var(--accent); font-weight: 600; }
.res-info { margin: 0 0 14px; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 4px; }
.res-info .btn { margin-top: 8px; display: block; }
.phone-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; display: flex; align-items: center; gap: 8px; padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line-strong); }
.phone-bar span { flex: 1 1 auto; min-width: 0; font-weight: 600; }
.phone-bar .btn { text-decoration: none; display: inline-flex; align-items: center; }
body.has-bar { padding-bottom: 64px; }
body.has-bar .undo-bar { bottom: 76px; }
.res-err { margin: 0 0 14px; padding: 10px 12px; background: var(--over-bg); border-radius: 4px; font-weight: 600; }
.map { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 215px), 1fr)); gap: 14px; }
.op { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 10px 12px 12px; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.op.front { background: transparent; border-style: dashed; }
.op.over { border-color: var(--accent); border-width: 2px; padding: 9px 11px 11px; }
.op.spill { border-color: var(--accent); border-style: dashed; }
.op.drop { outline: 3px dashed var(--guide); outline-offset: 2px; }
.op-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 8px; align-items: baseline; }
.op-head b { white-space: nowrap; }
.op-head b { font-family: var(--head); font-weight: 600; }
.op-head .wc { color: var(--muted); white-space: nowrap; }
.op.over .wc { color: var(--accent); font-weight: 600; }
.mini { display: flex; width: 100%; max-width: 230px; border: 1px solid var(--line-strong); background: var(--page); }
.mini .pg { flex: 1 1 0; position: relative; display: flex; align-items: center; justify-content: center; text-align: center; padding: 4px; color: var(--muted); font-size: 15px; line-height: 1.2; min-width: 0; overflow-wrap: break-word; hyphens: auto; }
.mini .pg + .pg { border-left: 1px dashed var(--line-strong); }
.mini .pg.cover { background: var(--cover); }
.mini .pg.story { color: var(--guide); }
.mini .pn { position: absolute; bottom: 2px; font-size: 13px; color: var(--muted); }
.mini .L .pn { left: 4px; }
.mini .R .pn { right: 4px; }
.op-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 16px; line-height: 1.45; }
.op-text .ln { cursor: grab; border-radius: 3px; }
.op-text .ln:hover { background: var(--over-bg); }
.op-text .note { color: var(--muted); font-style: italic; }
.op-text .none { color: var(--muted); font-style: italic; }
.op-split { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.op-split .op-text + .op-text { border-left: 1px dashed var(--line); padding-left: 8px; }
.op-acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.mv { white-space: nowrap; font: inherit; font-size: 16px; min-height: 44px; padding: 4px 10px; border: 1px solid var(--line-strong); border-radius: 4px; background: var(--bg); color: var(--ink); cursor: pointer; }
.mv:hover { border-color: var(--ink); }
.mv .sm { display: none; }

.printbox { margin-top: 26px; padding-top: 18px; border-top: 2px solid var(--ink); display: grid; gap: 14px; max-width: 40rem; }
.ph2 { margin: 0; }
.guides { display: flex; flex-wrap: wrap; gap: 0 22px; }
.guides legend { width: 100%; }
.scale-note { margin: 0; font-weight: 600; }
.printbox .btn.primary { justify-self: start; min-width: 10rem; }
.earlier { margin-top: 22px; }
.earlier summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; }
.earlier ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.earlier li { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 4px 0; }
.save-off { margin: 18px 0 0; font-weight: 600; }
.undo-bar { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px); background: var(--ink); color: var(--bg); padding: 8px 10px 8px 16px; border-radius: 6px; display: flex; gap: 12px; align-items: center; z-index: 20; box-shadow: 0 4px 18px rgba(0,0,0,.25); }
.undo-bar .btn { background: var(--bg); color: var(--ink); border-color: var(--bg); }

/* Content */
.content { max-width: 46rem; padding: 10px 0 40px; border-top: 1px solid var(--line); }
.content section { margin-top: 30px; }
.content p { margin: 0 0 12px; }
.table-wrap { overflow-x: auto; margin: 6px 0 14px; }
.ref { border-collapse: collapse; width: 100%; font-size: 16px; }
.ref th, .ref td { text-align: left; vertical-align: top; padding: 8px 10px 8px 0; border-bottom: 1px solid var(--line); }
.ref th { font-family: var(--head); font-weight: 600; }
.ref td:last-child { white-space: nowrap; }
@media (max-width: 520px) {
  .ref thead { display: none; }
  .ref tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  .ref td { display: block; border: 0; padding: 2px 0; white-space: normal !important; }
  .ref td:first-child { font-weight: 600; }
}
.sources { color: var(--muted); font-size: 16px; overflow-wrap: anywhere; }
.foot { border-top: 1px solid var(--line); padding: 18px 0 40px; color: var(--muted); font-size: 16px; }
.sb-footer p { margin: 0 0 10px; }
.sb-more { overflow-wrap: anywhere; }
.foot a { color: var(--guide); }

@media (max-width: 600px) {
  textarea { min-height: 190px; height: 15em; }
  .intro { padding-top: 14px; }
  .lede { font-size: 17px; }
  .op.front { padding: 8px 10px; flex-direction: row; align-items: center; justify-content: space-between; }
  .op.front .mini { max-width: 150px; }
  .op:not(.front) .mini { display: none; }
  .mv .lg { display: none; }
  .mv .sm { display: inline; }
  .map { gap: 10px; }
}
@media (max-width: 420px) {
  .trim-row { grid-template-columns: 1fr 1fr; }
  .trim-row > .field:first-child { grid-column: 1 / -1; }
  .seg span { min-width: 44px; padding: 0 10px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }

/* Print root: laid out off screen (for measuring), printed alone. */
#print-root { position: absolute; left: -30000px; top: 0; visibility: hidden; color: #000; font-family: var(--body); }
@page { margin: 0.4in; }
@page port { size: portrait; }
@page land { size: landscape; }
.psheet { position: relative; margin: 0 auto; width: 7.4in; height: 10.15in; overflow: hidden; background: #fff; color: #000; page: port; break-after: page; }
.psheet.land { width: 10.15in; height: 7.4in; page: land; }
.psheet:last-child { break-after: auto; }
.phead { display: flex; justify-content: space-between; align-items: baseline; gap: 0.2in; border-bottom: 1pt solid #000; padding-bottom: 3pt; margin-bottom: 8pt; }
.phead h2 { font: 600 14pt/1.2 var(--head); margin: 0; }
.phead p { margin: 0; font-size: 9pt; }
.phead.stack { display: block; }
.phead.stack h2.long { font-size: 11.5pt; }
.phead.stack p { margin-top: 1pt; }
.dhead h2 { flex: 0 0 auto; white-space: nowrap; }
.dhead p { flex: 1 1 0; min-width: 0; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pfoot { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; gap: 0.2in; font-size: 8pt; color: #333; border-top: 0.5pt solid #999; padding-top: 2pt; }
.tgrid { display: flex; flex-wrap: wrap; column-gap: 0.25in; row-gap: 0.16in; align-content: flex-start; }
.tcell { width: var(--cw); }
.tbox { display: flex; border: 0.75pt solid #000; }
.tbox .tp { flex: 1 1 0; position: relative; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 7.5pt; line-height: 1.15; color: #444; padding: 2pt; overflow: hidden; }
.tbox .tp + .tp { border-left: 0.75pt dashed #777; }
.tbox .tp.cover { background: repeating-linear-gradient(45deg, #fff 0 3pt, #ccc 3pt 3.6pt); -webkit-print-color-adjust: exact; print-color-adjust: exact; color: #333; }
.tnums { display: flex; justify-content: space-between; font-size: 8pt; margin-top: 1pt; }
.tmeta { font-size: 8pt; font-weight: 600; margin: 2pt 0 1pt; }
.tmeta .ov { text-decoration: underline; }
.tcell.spill { border: 0.75pt dashed #000; padding: 3pt; align-self: flex-start; }
.ttext { font-size: 7.5pt; line-height: 1.25; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.ttext .note { font-style: italic; color: #444; }
.ttext.sp { display: grid; grid-template-columns: 1fr 1fr; gap: 4pt; }
.blankgrid .tp { font-size: 8pt; }
.dz { position: absolute; }
.dz .bleed { position: absolute; border: 0.75pt dashed #c0392b; }
.dz .trim { position: absolute; border: 0.9pt solid #000; }
.dz .gut { position: absolute; border-left: 0.75pt dashed #000; }
.dz .safe { position: absolute; border: 0.75pt dotted #1f5fa8; }
.dz .nocover { position: absolute; background: repeating-linear-gradient(45deg, #fff 0 6pt, #ddd 6pt 7pt); -webkit-print-color-adjust: exact; print-color-adjust: exact; display: flex; align-items: center; justify-content: center; font-size: 10pt; color: #333; }
.dz .lab { position: absolute; display: flex; align-items: center; justify-content: center; text-align: center; color: #555; font: 600 12pt/1.2 var(--head); }
.dz .txt { position: absolute; border: 0.75pt solid #888; padding: 4pt 6pt; overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.3; color: #000; }
.dz .txt .note { font-style: italic; color: #555; }
.dz .pnum { position: absolute; font-size: 9pt; }
.dz .side { position: absolute; font-size: 8pt; color: #555; }
@media print {
  body { background: #fff; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { position: static; visibility: visible; }
}
