:root {
  color-scheme: light;
  --bg: #f1f6ee;
  --ink: #202918;
  --muted: #4d5843;
  --line: #cbd0bf;
  --field: #eeefe3;
  --accent: #214d3d;
  --on-accent: #fff9e9;
  --canvas: #e9e8db;
  --grid: #abad9b5e;
  --orange: #824324;
  --piece: #edd6b8;
  --piece-ink: #592c1e;
  --focus: #8f451b;
  --shadow: #27271826;
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
  font-weight: 500;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161d18;
  --ink: #f1efdc;
  --muted: #b9c6ad;
  --line: #50604e;
  --field: #243126;
  --accent: #b9d7aa;
  --on-accent: #18261c;
  --canvas: #263329;
  --grid: #899d8352;
  --orange: #f0a982;
  --piece: #63422f;
  --piece-ink: #fff2da;
  --focus: #f1b889;
  --shadow: #0005;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scrollbar-color: var(--line) var(--bg); }
body { margin: 0; color: var(--ink); background: var(--bg); }
::selection { color: var(--on-accent); background: var(--accent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
a { color: inherit; text-underline-offset: 0.24em; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .65; cursor: default; }
input { color: var(--ink); caret-color: var(--focus); }
input::placeholder { color: var(--muted); opacity: .85; }
small { font-size: max(.82em, .72rem); }
.masthead, main, footer { width: min(calc(100% - 96px), 1250px); margin: 0 auto; }
.masthead { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 24px; padding: 22px 0; border-bottom: 1px solid var(--line); }
.brand { display: flex; width: fit-content; align-items: center; text-decoration: none; font-size: 1.2rem; font-weight: 700; letter-spacing: -.04em; }
.mark { display: grid; gap: 2px; transform: rotate(-28deg); width: 23px; margin: 0 10px 0 3px; }
.mark i { height: 3px; background: var(--accent); }
.mark i:nth-child(2) { width: 80%; }
.mark i:nth-child(3) { width: 60%; }
.brand-period { color: var(--orange); }
nav { display: flex; gap: 28px; font-size: .88rem; color: var(--muted); }
nav a { text-decoration: none; }
nav a:hover { color: var(--ink); text-decoration: underline; }
.solid, .quiet { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 9px 16px; border: 1px solid transparent; border-radius: 4px; text-decoration: none; font-size: .86rem; font-weight: 650; }
.solid { color: var(--on-accent); background: var(--accent); }
.solid:hover { box-shadow: 0 3px 8px var(--shadow); }
.quiet { color: var(--ink); background: var(--bg); border-color: var(--line); }
.quiet:hover, .quiet[aria-pressed="true"] { border-color: var(--accent); background: var(--field); }
.theme-toggle { justify-self: end; }
.intro { display: grid; grid-template-columns: 1fr 1.2fr; align-items: center; gap: clamp(30px, 5vw, 72px); padding: 42px 0 48px; border-bottom: 1px solid var(--line); }
h1, h2, figcaption { font-family: Georgia, "Times New Roman", serif; margin: 0; font-weight: 500; letter-spacing: -.035em; }
h1 { font-size: clamp(3rem, 6vw, 5.75rem); line-height: .99; text-wrap: balance; }
.intro-copy p { line-height: 1.65; max-width: 37ch; margin: 22px 0 20px; color: var(--muted); }
.model-frame { margin: 0; position: relative; padding: 20px; min-width: 0; background: var(--canvas); border: 1px solid var(--line); border-radius: 5px; background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px); background-size: 24px 24px; }
.model-top { display: flex; justify-content: space-between; gap: 10px; position: relative; }
.model-kind, .model-dims { color: var(--muted); font-size: .72rem; }
.model-dims { align-self: end; font-variant-numeric: tabular-nums; text-align: right; }
figcaption { font-size: clamp(1.22rem, 2.3vw, 1.75rem); }
#model { display: block; width: 100%; height: auto; }
.model-controls { display: flex; gap: 7px; }
.model-controls button { min-height: 36px; padding: 3px 9px; font-size: .76rem; }
.workspace { display: grid; grid-template-columns: minmax(300px, .85fr) minmax(0, 1.4fr); gap: clamp(28px, 6vw, 85px); padding: 40px 0 52px; }
.stock-panel, .plan-panel { min-width: 0; scroll-margin-top: 20px; }
.section-heading { margin-bottom: 16px; }
h2 { font-size: clamp(2rem, 3.2vw, 3rem); }
.section-heading p { margin: 5px 0; color: var(--muted); line-height: 1.45; font-size: .88rem; }
.stock-tools, .template-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.stock-tools .quiet, .template-buttons .quiet { min-height: 39px; padding: 6px 10px; }
.stock-form { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 8px; margin: 13px 0 0; }
.stock-form label, .kerf-label { display: block; min-width: 0; font-size: .78rem; font-weight: 700; }
.stock-form small, .kerf-label small { color: var(--muted); }
input { display: block; width: 100%; min-width: 0; min-height: 44px; padding: 8px; margin-top: 4px; border: 1px solid var(--line); border-radius: 4px; background: var(--field); font-size: .94rem; }
.form-status, .plan-status { color: var(--muted); font-size: .82rem; margin: 9px 0; min-height: 1.25em; }
.plan-status[data-error="true"] { color: var(--orange); }
.stock-table { width: 100%; border-collapse: collapse; font-size: .87rem; text-align: left; }
.stock-table td, .stock-table th { padding: 7px 0; border-bottom: 1px solid var(--line); }
.stock-table th { color: var(--muted); font-weight: 650; font-size: .78rem; }
.stock-table td { font-variant-numeric: tabular-nums; }
.stock-table td:last-child { text-align: right; }
.remove { border: 0; background: transparent; color: var(--muted); font: inherit; text-decoration: underline; text-underline-offset: .2em; min-height: 30px; }
.remove:hover { color: var(--orange); }
.plan-controls { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.print-details { display: none; }
.kerf-label { width: 72px; }
.stats { display: grid; grid-template-columns: 1fr 1.08fr .7fr; gap: 10px; border-block: 1px solid var(--line); padding: 13px 0 12px; margin: 15px 0 19px; font-variant-numeric: tabular-nums; }
.stats dt { color: var(--muted); font-size: .75rem; line-height: 1.25; }
.stats dd { margin: 3px 0 0; font-size: clamp(1.06rem, 1.8vw, 1.55rem); letter-spacing: -.025em; font-weight: 650; }
.board-plan { border-bottom: 1px solid var(--line); padding: 0 0 16px; margin: 0 0 19px; }
.board-label { display: flex; align-items: baseline; gap: 9px; margin: 0 0 7px; font-size: 1rem; }
.board-label span { color: var(--muted); font-size: .78rem; font-weight: 500; }
.board-shape { width: min(100%, 520px); background: var(--field); outline: 1px solid var(--line); position: relative; }
.board-piece { position: absolute; display: grid; place-items: center; overflow: hidden; box-shadow: inset 0 0 0 1px var(--orange); background: var(--piece); color: var(--piece-ink); font-size: .8rem; font-weight: 800; }
.piece-list { margin: 11px 0 0; padding-left: 18px; color: var(--muted); font-size: .8rem; line-height: 1.65; text-wrap: pretty; }
footer { padding: 8px 0 25px; border-top: 1px solid var(--line); font-size: .84rem; color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media print {
  @page { size: A4; margin: 13mm; }
  html, html[data-theme="dark"] {
    color-scheme: light;
    --bg: #fff;
    --ink: #171c13;
    --muted: #343c30;
    --line: #899184;
    --field: #fff;
    --piece: #ebeedf;
    --piece-ink: #2d3024;
    --orange: #44483b;
  }
  body { print-color-adjust: exact; }
  .masthead, .intro, .stock-panel, .plan-controls, .plan-panel .section-heading p { display: none; }
  main, footer { width: 100%; }
  .workspace { display: block; padding: 0; }
  .print-details { display: block; font-size: 10pt; }
  #board-plans { display: grid; grid-template-columns: 1fr 1fr; gap: 5mm; }
  .board-plan { break-inside: avoid; min-width: 0; }
  .board-shape { width: min(100%, 80mm); }
  .piece-list { font-size: 8.5pt; }
}
@media (max-width: 900px) {
  .masthead, main, footer { width: calc(100% - 54px); }
  .intro { gap: 29px; }
  .workspace { gap: 30px; }
}
@media (max-width: 720px) {
  .masthead, main, footer { width: calc(100% - 36px); }
  .masthead { grid-template-columns: 1fr auto; gap: 12px; padding: 14px 0; }
  nav { grid-column: 1 / -1; grid-row: 2; gap: 20px; }
  .theme-toggle { padding: 4px 9px; min-height: 36px; }
  .intro, .workspace { grid-template-columns: minmax(0, 1fr); gap: 27px; }
  .intro { padding: 27px 0; }
  .intro-copy p { margin: 14px 0; }
  .model-frame { padding: 12px; }
  .workspace { padding: 25px 0; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
