:root {
  --bg: #fbfaf7;
  --panel: #ffffff;
  --ink: #1f1d1a;
  --muted: #6b665e;
  --line: #e2ddd3;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --stock: #ecdcbd;
  --stock-edge: #7a6a50;
  --trim: #d9c49c;
  --part: #ffffff;
  --part-edge: #2b2925;
  --keep: #cfe8d6;
  --keep-edge: #3f8a5a;
  --hl: #d3ebe2;
  --v3-bg: #efeae1;
  --v3-edge: rgba(60, 45, 25, 0.5);
  --band: #f1ece2;
  --bd: #d0312d;
  --warn-bg: #fdf0e6;
  --warn-edge: #c46a2b;
  --bad: #b3261e;
  --frame: #cfc7b8;
  --tab-idle: #f0ece4;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #181715; --panel: #211f1c; --ink: #ece8e1; --muted: #a39d93; --line: #39352f;
    --accent: #5fb39a; --accent-ink: #10201b;
    --stock: #5b4d36; --stock-edge: #b8a27a; --trim: #4a3f2c; --part: #2c2a26; --part-edge: #d8d2c6;
    --keep: #24402f; --keep-edge: #6cc08a; --warn-bg: #3a2a1d; --warn-edge: #e0904f; --bad: #ff8a80;
    --hl: #33604f;
    --v3-bg: #1c1b18;
    --v3-edge: rgba(0, 0, 0, 0.65);
    --band: #2e2b26;
    --bd: #ff5a4f;
    --frame: #4d483f; --tab-idle: #1c1b18;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #181715; --panel: #211f1c; --ink: #ece8e1; --muted: #a39d93; --line: #39352f;
  --accent: #5fb39a; --accent-ink: #10201b;
  --stock: #5b4d36; --stock-edge: #b8a27a; --trim: #4a3f2c; --part: #2c2a26; --part-edge: #d8d2c6;
  --keep: #24402f; --keep-edge: #6cc08a; --warn-bg: #3a2a1d; --warn-edge: #e0904f; --bad: #ff8a80;
  --frame: #4d483f; --tab-idle: #1c1b18; --hl: #33604f; --v3-bg: #1c1b18; --v3-edge: rgba(0, 0, 0, 0.65); --band: #2e2b26; --bd: #ff5a4f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* Component display rules (.btn is inline-flex) must not undo the hidden attribute. */
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; }
h1, h2, h3 { line-height: 1.2; }
code { font-size: 0.95em; }
.hint { color: var(--muted); font-size: 13px; }

.bar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 2;
}
.bar-end { display: flex; align-items: center; gap: 12px; justify-self: end; }
.bar h1 { justify-self: start; }

/* Sun | moon theme toggle, centred in the header. */
.theme-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; background: var(--bg); }
.theme-toggle button {
  display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 28px;
  border: 0; border-radius: 999px; background: none; color: var(--muted); cursor: pointer;
}
.theme-toggle button:hover { color: var(--ink); }
.theme-toggle button[aria-pressed="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }
.theme-toggle button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.theme-toggle svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle button[data-theme-pick="dark"] svg { fill: currentColor; stroke-width: 1.2; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.bar h1 { font-size: 18px; margin: 0 8px 0 0; letter-spacing: 0.02em; }
.file-name { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40ch; }
.unit { display: flex; align-items: center; gap: 6px; color: var(--muted); }

.btn { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--ink); font: inherit; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.small { padding: 2px 8px; font-size: 13px; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }

main { padding: 16px; max-width: 1400px; margin: 0 auto; }
.tab-panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.tab-panel[hidden] { display: none; }

/* Folder tabs: the active tab joins the outlined frame below it. */
.tabs { display: flex; align-items: flex-end; gap: 4px; padding: 0 12px; position: relative; z-index: 1; margin-bottom: -1px; overflow-x: auto; }
.tabs button {
  font: inherit; color: var(--muted); background: var(--tab-idle); cursor: pointer; white-space: nowrap;
  border: 1px solid var(--frame); border-radius: 8px 8px 0 0; padding: 8px 20px; margin-top: 4px;
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] {
  color: var(--ink); font-weight: 600; background: var(--panel);
  border-bottom-color: var(--panel); margin-top: 0; padding-bottom: 12px;
}
.tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; }
.tab-frame { border: 1px solid var(--frame); border-radius: 10px; background: var(--panel); padding: 20px; min-width: 0; }
/* Sections inside the frame are separated by space and a rule, not boxed again. */
.tab-frame .panel { border: 0; border-radius: 0; padding: 0; background: none; }
.tab-frame .panel + .panel { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 4px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; min-width: 0; }
.panel h2 { font-size: 15px; margin: 0 0 8px; }
.panel h3 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.scroll { overflow-x: auto; }
table { border-collapse: collapse; }
.tab-panel .panel table { width: 100%; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; }
td, th { padding: 3px 6px 3px 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
td.num, th.num { text-align: right; padding-right: 10px; }
tr.off td { color: var(--muted); }
tr.off td.name { text-decoration: line-through; }

input, select { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 3px 5px; min-width: 0; }
/* Our own caret: the native one ignores padding and hugs the edge. */
select {
  appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 55%, calc(100% - 12px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
select:hover { border-color: var(--muted); }
select, input { max-width: 100%; }
input.len { width: 7.5em; }
input.short { width: 5em; }
input.name { width: 9em; }
input.wide { width: 100%; }
input.bad { border-color: var(--bad); outline: 1px solid var(--bad); }
input[type="checkbox"] { width: auto; }
.badge { display: inline-block; font-size: 11px; padding: 0 5px; border-radius: 3px; border: 1px solid var(--line); color: var(--muted); margin-left: 4px; }
.badge.warn { border-color: var(--warn-edge); color: var(--warn-edge); }

.form-grid { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 12px; align-items: center; }
.form-grid label { color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mat-block { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; }
.mat-block:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.mat-block strong { margin-right: 6px; }
.field-error { color: var(--bad); font-size: 12px; }

.report { min-width: 0; }
.empty { border: 2px dashed var(--line); border-radius: 10px; padding: 48px 16px; margin-top: 12px; text-align: center; color: var(--muted); }
.empty[hidden] { display: none; }
.empty .sample { margin: 18px 0 0; display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
body.dragging .empty { border-color: var(--accent); }
.report-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 4px; }
.report-head h1 { margin: 0; font-size: 22px; min-width: 0; overflow-wrap: anywhere; }
.headline { font-size: 17px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 16px; }
.report h2 { font-size: 16px; margin: 24px 0 8px; }
.report h2.material { border-bottom: 2px solid var(--ink); padding-bottom: 4px; }
.report h2 small, .report h3 small { color: var(--muted); font-weight: normal; }
.report h3 { font-size: 15px; margin: 0 0 2px; }
/* Each sheet opens with a full-width band naming it. */
.sheet-group > h3 {
  font-size: 20px; margin: 0 0 12px; padding: 10px 14px; border-radius: 6px;
  background: var(--band); border: 1px solid var(--line);
}
.sheet-group > h3 small { font-size: 16px; margin-left: 6px; }
.sheet-group > h3 { display: flex; align-items: center; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; }

/* Track-saw breakdown cuts, numbered in cutting order. */
svg .bd-cut { stroke: var(--bd); stroke-width: 3px; vector-effect: non-scaling-stroke; }
svg .bd-badge circle { fill: var(--bd); }
svg .bd-badge text { fill: #fff; font-weight: 700; }
/* Candidates: a wide invisible hit line, and a dashed line shown on hover. */
svg .bd-hit { stroke: transparent; stroke-width: 18px; vector-effect: non-scaling-stroke; pointer-events: stroke; cursor: pointer; }
svg .bd-vis { stroke: var(--bd); stroke-width: 2px; stroke-dasharray: 7 5; vector-effect: non-scaling-stroke; opacity: 0; pointer-events: none; transition: opacity 0.12s; }
svg.sheet:hover .bd-cand:not(.on) .bd-vis { opacity: 0.4; }
svg .bd-cand:not(.on):hover .bd-vis { opacity: 1; stroke-width: 3px; }
svg .bd-cand.on .bd-vis { stroke: var(--panel); }
svg .bd-cand.on:hover .bd-vis { opacity: 0.9; }
svg .bd-dim line { stroke: var(--bd); stroke-width: 1.5px; vector-effect: non-scaling-stroke; }
svg .bd-dim polygon { fill: var(--bd); }
svg .bd-dim rect { fill: var(--panel); stroke: var(--bd); stroke-width: 1px; vector-effect: non-scaling-stroke; }
svg .bd-dim text { fill: var(--ink); font-weight: 600; }
.bd-num { display: inline-flex; align-items: center; justify-content: center; width: 1.35em; height: 1.35em; border-radius: 50%;
  background: var(--bd); color: #fff; font-size: 12px; font-weight: 700; margin-right: 2px; }
.bd-hint { grid-column: 1 / -1; color: var(--muted); font-size: 13px; margin-top: 6px; }
@media (prefers-reduced-motion: reduce) { svg .bd-vis { transition: none; } }
.report table { font-size: 15px; margin-bottom: 4px; }
.report .summary table, .report .warn table { font-size: 14px; }
.report th { font-size: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.report td, .report th { padding: 6px 24px 6px 0; }
.report td:first-child, .report th:first-child { padding-left: 8px; }
.report td:last-child, .report th:last-child { padding-right: 8px; }
.report td.num { padding-right: 16px; }
.sheet-stats .hint { font-size: 14px; }
.report td.same { color: var(--muted); }
.summary table, .warn table { width: 100%; }
.warn { background: var(--warn-bg); border: 1px solid var(--warn-edge); border-radius: 8px; padding: 8px 12px; margin: 0 0 16px; }
.warn h2 { margin: 0 0 6px; color: var(--warn-edge); }
.sheet-group { margin: 20px 0 32px; break-inside: avoid; }
/* Drawing, then parts table and details; the latter move beside a drawing
   that leaves room (an offcut) and drop below a full-width sheet. */
.sheet-body { display: flex; flex-wrap: wrap; gap: 8px 32px; align-items: flex-start; }
.sheet-body > svg.sheet { flex: 0 0 auto; margin: 4px 0 0; }
.sheet-foot { flex: 1 1 480px; display: flex; flex-wrap: wrap; gap: 12px 64px; align-items: flex-start; }
.sheet-foot table.parts { flex: 0 1 auto; }
.sheet-stats { flex: 1 1 260px; max-width: 460px; margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; font-size: 15px;
  border-left: 2px solid var(--line); padding-left: 14px; }
.sheet-stats dt { color: var(--muted); }
.sheet-stats dd { margin: 0; }
.swatch { display: inline-block; width: 12px; height: 12px; vertical-align: -2px; border: 1px solid var(--keep-edge); background: var(--keep); }

svg.sheet { display: block; height: auto; max-width: 100%; margin: 4px 0 8px; }
svg .stock { fill: var(--stock); stroke: var(--stock-edge); stroke-width: 1px; vector-effect: non-scaling-stroke; }
svg .trim { fill: url(#hatch); }
.hatch-bg { fill: var(--trim); }
.hatch-line { stroke: var(--stock-edge); stroke-width: 2; opacity: 0.5; }
svg .part { fill: var(--part); stroke: var(--part-edge); stroke-width: 1px; vector-effect: non-scaling-stroke; transition: fill 0.12s; }
/* Hover link between a sheet's parts table and its drawing. */
svg .piece.hl .part { fill: var(--hl); stroke: var(--accent); stroke-width: 2.5px; }
.report tr[data-part] { cursor: default; }
.report tr.hl td { background: var(--hl); }
@media (prefers-reduced-motion: reduce) { svg .part { transition: none; } }
svg .keep { fill: var(--keep); stroke: var(--keep-edge); stroke-width: 1px; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }
svg text { text-anchor: middle; dominant-baseline: central; font-weight: 650; fill: var(--ink); }
svg text.dims { font-weight: 400; fill: var(--muted); }
svg .keep-label text { fill: var(--keep-edge); font-weight: 500; }

.error { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); max-width: min(640px, calc(100vw - 32px)); background: var(--warn-bg); color: var(--ink); border: 1px solid var(--warn-edge); border-radius: 8px; padding: 10px 14px; box-shadow: 0 4px 16px rgb(0 0 0 / 0.15); }

@media (max-width: 720px) {
  main { padding: 10px; }
  .tabs { padding: 0 4px; }
  .tabs button { padding: 8px 12px; }
  .tabs button[aria-selected="true"] { padding-bottom: 12px; }
  .tab-frame { padding: 14px; }
}

/* Model, Stock and Cutting tabs: the same roomy type as the layout's tables. */
#tab-model, #tab-settings { max-width: 1100px; font-size: 15px; gap: 20px; }
:is(#tab-model, #tab-settings) .panel h2 { font-size: 19px; margin: 0 0 14px; }
:is(#tab-model, #tab-settings) .panel h3 { font-size: 14px; font-weight: 700; margin: 26px 0 10px; }
:is(#tab-model, #tab-settings) .panel + .panel { padding-top: 22px; margin-top: 2px; }
:is(#tab-model, #tab-settings) .hint { font-size: 14px; line-height: 1.5; }
:is(#tab-model, #tab-settings) table { font-size: 15px; }
:is(#tab-model, #tab-settings) th {
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding-top: 4px; padding-bottom: 8px;
}
:is(#tab-model, #tab-settings) td, :is(#tab-model, #tab-settings) th { padding: 8px 16px 8px 0; }
:is(#tab-model, #tab-settings) td:first-child, :is(#tab-model, #tab-settings) th:first-child { padding-left: 4px; }
:is(#tab-model, #tab-settings) td:last-child, :is(#tab-model, #tab-settings) th:last-child { padding-right: 4px; }
:is(#tab-model, #tab-settings) td.num, :is(#tab-model, #tab-settings) th.num { padding-right: 16px; }
:is(#tab-model, #tab-settings) input:not([type="checkbox"]),
:is(#tab-model, #tab-settings) select { font-size: 15px; padding: 7px 10px; border-radius: 6px; min-height: 36px; }
:is(#tab-model, #tab-settings) select { padding-right: 36px; background-position: calc(100% - 20px) 55%, calc(100% - 15px) 55%; }
:is(#tab-model, #tab-settings) input[type="checkbox"] { width: 17px; height: 17px; vertical-align: middle; accent-color: var(--accent); }
:is(#tab-model, #tab-settings) .btn { padding: 8px 16px; }
:is(#tab-model, #tab-settings) .btn.small { padding: 6px 12px; font-size: 14px; }
:is(#tab-model, #tab-settings) .scroll + .btn { margin-top: 12px; }
/* Tabs reserve the width of their bold (selected) label, so selecting one
   changes only its weight and nothing beside it shifts. */
.tabs button, .subtabs button { display: inline-flex; flex-direction: column; align-items: center; }
.tabs button::after, .subtabs button::after {
  content: attr(data-label); height: 0; overflow: hidden; visibility: hidden; font-weight: 600; pointer-events: none;
}
@media speech { .tabs button::after, .subtabs button::after { display: none; } }

/* Stock sub-tabs: underlined text, a level below the folder tabs. */
.subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px 0 18px; overflow-x: auto; }
.subtabs button {
  font: inherit; font-size: 15px; color: var(--muted); background: none; border: 0; border-bottom: 2px solid transparent;
  padding: 8px 14px 10px; margin-bottom: -1px; cursor: pointer; white-space: nowrap;
}
.subtabs button:hover { color: var(--ink); }
.subtabs button[aria-selected="true"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
.subtabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.subtab-panel > .hint:first-child { margin-top: 0; }
.library-foot { border-top: 1px solid var(--line); margin: 28px 0 0; padding-top: 14px; }
.backup-actions { display: grid; gap: 14px; margin-top: 16px; }
.backup-actions > div { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.backup-actions .btn { min-width: 11em; justify-content: center; }
.h3-row { justify-content: space-between; margin: 0 0 12px; }
:is(#tab-model, #tab-settings) .h3-row h3 { margin: 0; }
:is(#tab-model, #tab-settings) .form-grid { gap: 12px 20px; }
/* One label column width, so the cutting and breakdown grids line up. */
#tab-settings .form-grid { grid-template-columns: 15.5em minmax(0, 1fr); }
:is(#tab-model, #tab-settings) .row { gap: 10px 16px; }
:is(#tab-model, #tab-settings) .mat-block { padding-top: 14px; margin-top: 14px; }
:is(#tab-model, #tab-settings) .mat-block .row + .row { margin-top: 8px; }
:is(#tab-model, #tab-settings) .badge { font-size: 12px; padding: 1px 6px; margin-left: 6px; }
:is(#tab-model, #tab-settings) .field-error { font-size: 14px; }
:is(#tab-model, #tab-settings) input.len { width: 8em; }
:is(#tab-model, #tab-settings) input.short { width: 5.5em; }
:is(#tab-model, #tab-settings) input.name { width: 10em; }

/* Build stamp, written in by tools/deploy.py. */
.build { margin: 14px 4px 0; color: var(--muted); font-size: 12px; text-align: right; }

/* Help glyphs and their popover. */
.help {
  display: inline-flex; align-items: center; justify-content: center; width: 17px; height: 17px; margin-left: 4px;
  border-radius: 50%; border: 1px solid var(--muted); background: none; color: var(--muted);
  font: 700 11px/1 -apple-system, system-ui, sans-serif; text-transform: none; letter-spacing: 0; cursor: help; vertical-align: 1px; padding: 0;
}
.help:hover, .help:focus-visible, .help.pinned { color: var(--panel); background: var(--accent); border-color: var(--accent); outline: none; }
.tip {
  position: absolute; z-index: 20; max-width: 300px; padding: 10px 12px; border-radius: 8px;
  background: var(--panel); color: var(--ink); border: 1px solid var(--frame); box-shadow: 0 6px 24px rgb(0 0 0 / 0.25);
  font-size: 14px; font-weight: 400; line-height: 1.45; text-transform: none; letter-spacing: 0;
}
.tip::before {
  content: ''; position: absolute; top: -6px; left: calc(var(--arrow-x, 50%) - 6px); width: 10px; height: 10px;
  background: var(--panel); border-left: 1px solid var(--frame); border-top: 1px solid var(--frame); transform: rotate(45deg);
}
.tip.above::before { top: auto; bottom: -6px; transform: rotate(225deg); }

/* Wide tables scroll inside their box; their identifying column stays put. */
#parts td.name, #parts th:nth-child(3),
#library .scroll td:first-child, #library .scroll th:first-child,
.report .parts-scroll td:nth-child(2), .report .parts-scroll th:nth-child(2) {
  position: sticky; left: 0; z-index: 1; background: var(--panel);
}
.report tr.hl td:nth-child(2) { background: var(--hl); }
.sheet-actions { display: inline-flex; align-items: center; gap: 14px; }
.sheet-body > *, .sheet-foot > * { min-width: 0; }
.parts-scroll { max-width: 100%; }
#parts td:nth-child(5), .report .parts-scroll td:nth-child(4), .report .parts-scroll td:nth-child(5) { white-space: nowrap; }

/* Full-screen sheet viewer. */
dialog.viewer { padding: 0; border: 0; width: 100vw; height: 100dvh; max-width: none; max-height: none; background: var(--bg); color: var(--ink); }
dialog.viewer::backdrop { background: rgb(0 0 0 / 0.6); }
.viewer-close { position: fixed; top: 10px; right: 10px; z-index: 2; }
.viewer-hint { position: fixed; top: 10px; left: 12px; right: 96px; margin: 0; min-height: 36px; display: flex; align-items: center; color: var(--muted); font-size: 14px; }
.viewer-msg { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 2; margin: 0; max-width: calc(100vw - 32px);
  padding: 10px 14px; border-radius: 8px; background: var(--ink); color: var(--bg); font-size: 14px; }
/* Every candidate cut shows in full screen, not just on hover. */
.viewer-stage .bd-cand:not(.on) .bd-vis { opacity: 0.8; }
.viewer-stage { position: fixed; top: 56px; left: 10px; right: 10px; bottom: 10px; display: flex; align-items: center; justify-content: center; }
.viewer-stage svg { width: 100%; height: 100%; max-width: none; margin: 0; }
@media (orientation: portrait) {
  /* Turn the sheet so its long side runs down the screen. */
  .viewer-stage {
    right: auto; bottom: auto; top: 56px; left: calc(100vw - 10px);
    width: calc(100dvh - 66px); height: calc(100vw - 20px);
    transform-origin: top left; transform: rotate(90deg);
  }
}

/* Layout tab: the per-project sheet choices above the report. */
.project-stock {
  display: flex; flex-direction: column; gap: 8px; margin: 0 0 18px; padding: 12px 14px;
  background: var(--band); border: 1px solid var(--line); border-radius: 8px; font-size: 15px;
}
.ps-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.ps-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; }
.ps-row strong { min-width: 5.5em; }
.ps-row label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.project-stock input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); }

/* 3D tab. */
.v3 { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; }
.v3-stage { position: relative; height: min(74vh, 780px); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--v3-bg); }
#v3-canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#v3-canvas:active { cursor: grabbing; }
.v3-tools { position: absolute; top: 10px; left: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.v3-help { position: absolute; left: 12px; bottom: 8px; margin: 0; color: var(--muted); font-size: 12px; pointer-events: none; }
.v3-tip {
  position: absolute; z-index: 3; max-width: 280px; padding: 8px 10px; border-radius: 8px; pointer-events: none;
  background: var(--panel); color: var(--ink); border: 1px solid var(--frame); box-shadow: 0 6px 20px rgb(0 0 0 / 0.25); font-size: 13px; line-height: 1.45;
}
.v3-list { max-height: min(74vh, 780px); overflow: auto; }
.v3-list h2 { font-size: 16px; margin: 4px 0 8px; }
.v3-row { display: grid; grid-template-columns: 14px 2em minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 7px 8px; border-radius: 6px; font-size: 14px; cursor: default; }
.v3-row .num { text-align: right; color: var(--muted); }
.v3-row .v3-name { display: flex; flex-direction: column; }
.v3-row .v3-name .hint { font-size: 12px; }
.v3-row .v3-sheets { font-size: 12px; white-space: nowrap; }
.v3-row.hl { background: var(--hl); }
.v3-row.off { opacity: 0.55; }
.v3-swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--line); }
@media (max-width: 900px) {
  .v3 { grid-template-columns: minmax(0, 1fr); }
  .v3-stage { height: 62vh; }
  .v3-list { max-height: none; }
}

/* Phones. */
@media (max-width: 640px) {
  .bar { padding: 8px 10px; gap: 8px; }
  .bar h1 { font-size: 17px; }
  .unit-label { display: none; }
  .tab-frame { padding: 12px; }
  :is(#tab-model, #tab-settings) .form-grid { grid-template-columns: minmax(0, 1fr); gap: 4px 0; }
  :is(#tab-model, #tab-settings) .form-grid > label { margin-top: 12px; }
  :is(#tab-model, #tab-settings) .h3-row { align-items: flex-start; }
  .sheet-group > h3 { font-size: 17px; }
  .sheet-group > h3 small { font-size: 14px; margin-left: 0; display: block; }
  .sheet-foot { flex-basis: 100%; }
  .sheet-stats { max-width: none; flex-basis: 100%; border-left: 0; border-top: 2px solid var(--line); padding: 12px 0 0; }
  .report-head h1 { font-size: 20px; }
  .report td, .report th { padding: 6px 12px 6px 0; }
  .report td:first-child, .report th:first-child { padding-left: 4px; }
  #parts td.name { min-width: 9em; }
  .subtabs button { font-size: 14px; padding-left: 9px; padding-right: 9px; }
  .v3-stage { height: 50vh; }
}

/* The breakdown hint names the way to edit this screen offers. */
.on-touch { display: none; }
@media (hover: none) {
  .on-hover { display: none; }
  .on-touch { display: inline; }
  /* Edited in full screen; inline, a stray tap while scrolling would toggle a cut. */
  .report .bd-cand { display: none; }
}

/* Touch screens: bigger targets. */
@media (pointer: coarse) {
  .viewer-stage .bd-hit { stroke-width: 30px; }
  .help { width: 26px; height: 26px; font-size: 14px; }
  input[type="checkbox"], :is(#tab-model, #tab-settings) input[type="checkbox"] { width: 22px; height: 22px; }
  .theme-toggle button { width: 40px; height: 34px; }
  .subtabs button { padding: 12px 14px; }
  .tabs button { padding-top: 10px; padding-bottom: 10px; }
}

@media print {
  :root { --bd: #c62828; --band: #efeae0; --bg: #fff; --panel: #fff; --ink: #000; --muted: #444; --line: #bbb; --stock: #f1e4c8; --trim: #e0cfa8; --part: #fff; --part-edge: #000; --keep: #dcefe2; color-scheme: light; }
  .no-print, .tip { display: none !important; }
  .bd-num { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  /* The layout prints whichever tab is showing. */
  #tab-layout { display: block !important; }
  .tab-frame { border: 0; padding: 0; background: none; }
  body { background: #fff; font-size: 11pt; }
  main { display: block; padding: 0; }
  .sheet-group { break-inside: avoid; }
  .sheet-group > h3 { font-size: 14pt; padding: 6px 10px; margin-bottom: 8px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sheet-group > h3 small { font-size: 11pt; }
  .report h2.material { break-after: avoid; }
  .sheet-foot { gap: 8px 16px; }
  .report table { font-size: 10pt; }
  .report th { font-size: 8.5pt; }
  .report td, .report th { padding: 3px 9px 3px 0; }
  .report td:first-child, .report th:first-child { padding-left: 2px; }
  .report td:last-child, .report th:last-child { padding-right: 2px; }
  .sheet-stats { flex: 0 1 190px; font-size: 10pt; gap: 1px 10px; padding-left: 10px; }
  svg.sheet { max-width: 100%; }
}
