:root {
  --bg: #e9ece8;
  --surface: #fbfcfa;
  --ink: #18201d;
  --muted: #3f4b46;
  --line: #b9c2bc;
  --field: #6f7b75;
  --accent: #1e5a4b;
  --accent-ink: #ffffff;
  --accent-soft: #d6e5de;
  --score: #a8431a;
  --card: #d9d2bf;
  --err: #a1251a;
  --r: 3px;
  --head: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151b19;
    --surface: #1d2522;
    --ink: #e6ece8;
    --muted: #b8c3bd;
    --line: #3d4a45;
    --field: #7e8b85;
    --accent: #7fcab2;
    --accent-ink: #0f1a16;
    --accent-soft: #24392f;
    --score: #f19a6c;
    --card: #3b3a31;
    --err: #ff9b8c;
  }
}
* { 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 var(--body); }
a { color: var(--accent); text-underline-offset: 2px; }
.wrap { max-width: 1140px; margin: 0 auto; padding: 0 16px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -9999px; top: 0; background: var(--surface); color: var(--ink); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; top: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.nw { white-space: nowrap; }

.top { border-bottom: 3px solid var(--accent); background: var(--surface); }
.top-in { display: flex; align-items: center; min-height: 56px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font: 700 20px/1.2 var(--head); color: var(--ink); text-decoration: none; }
.mark { width: 30px; height: 30px; flex: none; }
.m-board { fill: var(--card); stroke: var(--ink); stroke-width: 1.4; }
.m-fold { stroke: var(--score); stroke-width: 1.4; stroke-dasharray: 2.2 1.6; fill: none; }
.m-book { fill: var(--accent); }

.intro { padding: 24px 0 2px; max-width: 44rem; }
h1 { font: 700 clamp(28px, 4.6vw, 40px)/1.12 var(--head); margin: 0 0 8px; letter-spacing: -0.01em; }
.lede { margin: 0; color: var(--muted); font-size: 18px; }
h2 { font: 700 24px/1.25 var(--head); margin: 0 0 12px; }
h3 { font: 700 18px/1.3 var(--head); margin: 20px 0 6px; }

.tool { display: grid; gap: 22px; margin: 18px 0 8px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) {
  .tool { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); align-items: start; }
  .result { position: sticky; top: 14px; }
}
.inputs { min-width: 0; }
.result { min-width: 0; background: var(--surface); border-top: 4px solid var(--accent); padding: 16px 18px 18px; min-height: 280px; }

.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 14px; min-width: 0; }
.field > label { font-weight: 600; }
fieldset { border: 0; margin: 0 0 14px; padding: 0; min-width: 0; }
legend { font-weight: 600; padding: 0; margin-bottom: 4px; }
input[type=text], select { font: inherit; font-size: 17px; min-height: 44px; padding: 8px 10px; border: 1.5px solid var(--field); border-radius: var(--r); background: var(--surface); color: var(--ink); width: 100%; }
input[aria-invalid="true"] { border-color: var(--err); }
.suffix { display: flex; align-items: stretch; }
.suffix input { border-radius: var(--r) 0 0 var(--r); min-width: 0; }
.suffix b { display: inline-flex; align-items: center; justify-content: center; padding: 0 8px; min-width: 40px; border: 1.5px solid var(--field); border-left: 0; border-radius: 0 var(--r) var(--r) 0; background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.lab-u { display: none; }
.sizes legend { font-weight: 600; }
.sizes .field > label { font-weight: 400; }
.trio { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 10px; }
.row2 { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0 16px; align-items: start; }
.seg { display: flex; flex-wrap: wrap; }
.seg legend { width: 100%; }
.seg-opt { position: relative; }
.seg-opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg-opt span { display: inline-flex; align-items: center; min-height: 44px; padding: 6px 12px; border: 1.5px solid var(--field); margin: 0 -1.5px -1.5px 0; background: var(--surface); color: var(--ink); font-size: 16px; white-space: nowrap; cursor: pointer; }
.seg-opt input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); position: relative; z-index: 1; }
.seg-opt input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; z-index: 2; }
.board-note, .al-src { margin: 0 0 14px; color: var(--muted); }
.more summary, .steps-d summary, #earlier summary, .where summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; color: var(--accent); }
.more { border-top: 1px solid var(--line); }
.al .src { margin: 0; color: var(--muted); font-size: 16px; }
.err { color: var(--err); margin: -6px 0 12px; font-weight: 600; }
.field .err { margin: 2px 0 0; }

.answer { margin: 0 0 12px; font: 400 21px/1.3 var(--head); }
.answer b { font-weight: 700; }
.pic { background: var(--bg); padding: 10px; margin: 0 0 6px; }
.flat-svg { display: block; width: 100%; height: auto; max-height: 340px; color: var(--ink); }
.card-fill { fill: var(--card); }
.waste-fill { fill: var(--bg); }
.pieces-svg { display: block; width: 100%; height: auto; max-height: 240px; color: var(--ink); }
.buy { margin: 0 0 10px; }
.score-line { stroke: var(--score); }
.legend { margin: 0 0 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lg { display: inline-block; width: 28px; height: 0; border-top: 2.5px solid var(--ink); }
.lg.score { border-top: 2.5px dashed var(--score); margin-left: 10px; }
.cuts { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; margin: 0 0 10px; }
.cuts th, .cuts td { text-align: left; padding: 6px 10px 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.cuts th { font-weight: 600; color: var(--muted); }
.cuts td:last-child { font-weight: 600; }
.inside, .prints { margin: 0 0 10px; }
.where p { margin: 0 0 8px; }
.lay-h { font-weight: 600; margin: 10px 0 2px !important; }
.lay { margin: 0; padding-left: 1.6em; }
.lay li { padding: 2px 0; }
.lay span { color: var(--muted); }
.note { margin: 10px 0; padding: 8px 12px; background: var(--accent-soft); }
.res-wait { font-size: 18px; margin: 6px 0; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 14px 0 0; }
.btn { font: inherit; font-size: 17px; min-height: 44px; padding: 8px 18px; border: 1.5px solid var(--accent); border-radius: var(--r); background: var(--surface); color: var(--accent); font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.small { min-height: 44px; padding: 4px 12px; font-size: 16px; }
.link-btn { font: inherit; background: none; border: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; padding: 10px 4px; min-height: 44px; }
.save-note { margin: 12px 0 0; padding: 8px 12px; background: var(--accent-soft); overflow-wrap: anywhere; }
.jump { display: inline-flex; align-items: center; min-height: 44px; }
@media (min-width: 900px) { .jump { display: none; } }

.steps-d, .saved-sec { max-width: 44rem; }
.steps-d ol { padding-left: 1.4em; margin: 0 0 8px; }
.steps-d li { margin: 0 0 6px; }
.steps-d h3 { margin-top: 8px; }
#earlier-list { list-style: none; padding: 0; margin: 0 0 10px; }
#earlier-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.reset-row, .reset-ask { margin: 0; }
.reset-row .link-btn { padding-left: 0; }

.content { max-width: 44rem; margin: 30px 0 40px; }
.content section { margin: 0 0 30px; }
.content p { margin: 0 0 12px; }
.steps { padding-left: 1.4em; margin: 0; }
.steps li { margin: 0 0 6px; }
.sources { color: var(--muted); }

.foot { border-top: 1px solid var(--line); padding: 22px 0 30px; background: var(--surface); }
.sb-footer { font-size: 16px; color: var(--muted); }
.sb-more { margin: 0 0 10px; line-height: 1.7; }
.sb-privacy, .sb-credit { margin: 0 0 6px; }
.sb-footer a { color: var(--ink); }

@media (max-width: 420px) {
  .trio { gap: 0 8px; align-items: end; }
  .suffix b { display: none; }
  .suffix input { border-radius: var(--r); }
  .lab-u { display: inline; }
  .seg-ty { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .seg-ty .seg-opt span { white-space: normal; text-align: center; justify-content: center; width: 100%; height: 100%; line-height: 1.25; }
  .row2 { grid-template-columns: minmax(0, 1fr); }
  .seg-opt span { padding: 6px 9px; }
  .cuts th, .cuts td { padding-right: 6px; }
}

#print-root { display: none; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

@page { margin: 10mm; }
@media print {
  body { background: #fff; color: #000; font: 10.5pt/1.4 Arial, Helvetica, sans-serif; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block; color: #000; }
  #print-root svg.sheet { display: block; break-before: page; page-break-before: always; overflow: hidden; }
  .pnotes h2 { font: 700 13pt/1.25 Arial, sans-serif; margin: 0 0 2mm; }
  .pnotes h3 { font: 700 11pt/1.25 Arial, sans-serif; margin: 3mm 0 1mm; }
  .pnotes .pnum { margin: 0 0 2mm; font-size: 10pt; }
  .pnotes .pmap-row { display: flex; gap: 5mm; align-items: flex-start; margin: 2mm 0 3mm; break-inside: avoid; }
  .pnotes .pmap-row > svg { flex: none; }
  .pnotes .pmap-row > svg.pmap:not([width]) { width: 55mm; height: auto; color: #000; }
  .pnotes .pwarn { border: 0.3mm solid #000; padding: 1.5mm 2.5mm; font-weight: 700; }
  .pnotes .pl { margin: 0 0 2mm; }
  .pnotes ol { margin: 0; padding-left: 6mm; }
  .pnotes li { margin: 0 0 1.4mm; }
  .pnotes .cuts { width: 100%; margin: 1mm 0 3mm; border-collapse: collapse; }
  .pnotes .cuts th, .pnotes .cuts td { border-bottom: 0.3mm solid #999; padding: 1.2mm 3mm 1.2mm 0; text-align: left; color: #000; }
  .print-msg { font: 13pt Arial, sans-serif; }
}
