:root {
  color-scheme: light dark;
  --bg: #e4e7ea;
  --panel: #f4f5f6;
  --ink: #1d2126;
  --muted: #566069;
  --line: #c6ccd2;
  --accent: #f0b800;
  --accent-ink: #1d2126;
  --stage: #c3c9cf;
  --grid-a: #8f98a2;
  --grid-b: #aab1b9;
  --display: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  --text: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121518;
    --panel: #1b1f23;
    --ink: #e8ebee;
    --muted: #98a2ad;
    --line: #30363c;
    --accent: #f3c21a;
    --accent-ink: #15181b;
    --stage: #3a4047;
    --grid-a: #5d656e;
    --grid-b: #4b525a;
  }
}
:root[data-theme="dark"] {
  --bg: #121518;
  --panel: #1b1f23;
  --ink: #e8ebee;
  --muted: #98a2ad;
  --line: #30363c;
  --accent: #f3c21a;
  --accent-ink: #15181b;
  --stage: #3a4047;
  --grid-a: #5d656e;
  --grid-b: #4b525a;
}
html { height: 100%; scroll-padding-top: env(safe-area-inset-top, 0px); }
body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font: 400 15px/1.45 var(--text); }
*, *::before, *::after { box-sizing: border-box; }

.app { height: 100%; display: grid; grid-template-columns: minmax(300px, 372px) minmax(0, 1fr); }
.side { overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); padding: 16px 16px 32px; }
.stage { position: relative; min-width: 0; min-height: 0; background: var(--stage); overflow: hidden; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#gl:active { cursor: grabbing; }
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(250px, 46%) minmax(0, 1fr); }
  .stage { order: -1; }
  .side { border-right: 0; border-top: 1px solid var(--line); padding: 12px 14px 28px; }
  .hint { display: none; }
}

h1 { font: 700 30px/1 var(--display); letter-spacing: 0.01em; margin: 0 0 4px; }
.sub { margin: 0; color: var(--muted); }
section, details { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 14px; }
header + section { margin-top: 16px; }
h2 { font: 600 19px/1.1 var(--display); letter-spacing: 0.01em; margin: 0 0 10px; }
.note { color: var(--muted); font-size: 13.5px; margin: 8px 0 0; }
.status { margin: 10px 0 0; font-size: 14px; min-height: 2.9em; }

button, select, input[type="text"] { font: inherit; color: inherit; }
.btn, .part, .chip, .mini {
  background: var(--bg); border: 1px solid var(--line); border-radius: 3px; cursor: pointer;
  padding: 7px 10px; line-height: 1.2;
}
.btn:hover, .part:hover:not(:disabled), .chip:hover, .mini:hover { border-color: var(--ink); }
button:disabled { opacity: 0.38; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { border-color: var(--ink); }
.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.part { display: flex; align-items: center; gap: 9px; text-align: left; padding: 8px 9px; }
.badge {
  display: inline-block; min-width: 26px; text-align: center; padding: 1px 6px 0; border-radius: 2px;
  background: var(--accent); color: var(--accent-ink); font: 700 15px/1.45 var(--display); letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}
.ptitle { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; font-size: 16px; }
.field { display: grid; gap: 4px; margin: 8px 0; }
.field > span { color: var(--muted); font-size: 13.5px; }
.field input, .field select, .dim input {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 3px; padding: 7px 9px;
}
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.fitlabel { margin-top: 18px; }
.chip, .mini { padding: 3px 8px; font-size: 13.5px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 10px 0; }
.row > span { flex: 1 1 100%; color: var(--muted); font-size: 13.5px; }
.view-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.view-row input[type="range"] { flex: 1; accent-color: var(--ink); }
.view-row output { min-width: 3.5em; text-align: right; font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.check input { accent-color: var(--ink); width: 16px; height: 16px; }

.bomrow { display: grid; grid-template-columns: 2.2em 1fr; gap: 2px 8px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.bomrow .qty { font: 700 18px/1.2 var(--display); font-variant-numeric: tabular-nums; }
.bomrow .what { font-weight: 500; }
.bomrow .codes { grid-column: 2; display: flex; flex-wrap: wrap; gap: 4px; }
.bomhead { margin: 12px 0 0; font: 600 15px/1.2 var(--display); }
.totals { margin: 10px 0 0; font-variant-numeric: tabular-nums; }
.dims { display: grid; gap: 8px; margin-top: 10px; }
.dim { display: grid; grid-template-columns: 1fr 92px; gap: 8px; align-items: center; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pair.three { grid-template-columns: 1fr 1fr 1fr; }
.propadd select { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 3px; padding: 7px 9px; }
.gchip { display: inline-flex; gap: 2px; }
.gchip .chip:first-child { border-radius: 3px 0 0 3px; }
.gchip .chip:last-child { border-radius: 0 3px 3px 0; font-weight: 700; min-width: 2em; }
.librow { display: grid; grid-template-columns: 1fr auto auto auto; gap: 6px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); }
.librow input { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 3px; padding: 5px 8px; }
.librow .msg { grid-column: 1 / -1; }
.mstep { display: flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--muted); }
.mstep input { width: 4.5em; background: var(--bg); border: 1px solid var(--line); border-radius: 3px; padding: 3px 6px; color: var(--ink); }
#pieceBtn[aria-pressed="true"] { background: var(--ink); color: var(--panel); border-color: var(--ink); }
summary { cursor: pointer; font: 600 19px/1.1 var(--display); }
details[open] summary { margin-bottom: 4px; }

.tools { position: absolute; left: 10px; top: 10px; right: 10px; display: flex; flex-wrap: wrap; gap: 6px; pointer-events: none; }
.tools .btn { pointer-events: auto; background: var(--panel); }
.tools .btn.primary { background: var(--accent); }
.tools .btn[aria-pressed="true"] { background: var(--ink); color: var(--panel); border-color: var(--ink); }
.warn { margin: 8px 0 0; padding: 6px 8px 6px 24px; border-left: 3px solid var(--accent); background: var(--bg); font-size: 13.5px; }
p.warn, .warn.viewing { padding-left: 10px; }
.warn.viewing p { margin: 0; }
.warn.viewing .row { margin: 8px 0 2px; }
.warn[hidden] { display: none; }
.alignbar { position: absolute; left: 10px; right: 10px; bottom: 10px; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; pointer-events: none; }
.alignbar[hidden], .alignbar:not([hidden]) ~ .hint { display: none; }
.aset { display: flex; align-items: center; gap: 4px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 3px; pointer-events: auto; }
.aset span { padding: 0 4px; font: 600 15px/1 var(--display); }
.hint { position: absolute; left: 12px; bottom: 10px; margin: 0; font-size: 13px; color: var(--ink); opacity: 0.75; pointer-events: none; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; pointer-events: none; }
.empty p { margin: 0; max-width: 24em; font: 600 26px/1.15 var(--display); color: var(--ink); opacity: 0.8; }
.empty[hidden] { display: none; }

dialog { background: var(--panel); color: var(--ink); border: 1px solid var(--ink); border-radius: 4px; padding: 16px; width: min(560px, calc(100vw - 28px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog h3 { font: 700 22px/1.1 var(--display); margin: 0 0 10px; }
dialog img { display: block; width: 100%; height: auto; border: 1px solid var(--line); background: #fff; }
dialog textarea { width: 100%; height: 240px; resize: vertical; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 3px; padding: 8px; font: 13px/1.4 ui-monospace, Menlo, Consolas, monospace; }
.dlg-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; align-items: center; }
.dlg-actions .spacer { flex: 1; }
.msg { color: var(--muted); font-size: 13.5px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.dname { margin-top: 12px; }
.linkbox { width: 100%; margin-top: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 3px; padding: 7px 9px; font: 13px/1.4 ui-monospace, Menlo, Consolas, monospace; color: var(--ink); }
.sharetext { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 10px; }
dialog.wide { width: min(760px, calc(100vw - 28px)); }
.filebtn { position: relative; overflow: hidden; }
.filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.filebtn:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; }
.dlist { display: grid; align-items: start; grid-template-columns: repeat(auto-fill, minmax(min(160px, 38vw), 1fr)); gap: 10px; margin: 12px 0 4px; max-height: 40vh; overflow-y: auto; }
.dcard { display: grid; gap: 6px; padding: 6px; border: 1px solid var(--line); border-radius: 4px; background: var(--bg); }
.dcard.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.dopen { display: grid; gap: 4px; padding: 0; border: 0; background: none; color: inherit; text-align: left; cursor: pointer; font: inherit; }
.dopen img, .dblank { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 2px; }
.dblank { display: grid; place-items: center; color: #6b7280; font-size: 13px; }
.dopen strong { font-weight: 600; overflow-wrap: anywhere; }
.dacts { display: flex; gap: 5px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
.steps { margin: 0 0 12px; padding-left: 22px; }
.steps li { margin: 0 0 8px; }
.privacy { margin-top: 22px; }

/* Printing shows a sheet of its own: the design, a picture and the parts list. */
#printSheet { display: none; }
@media print {
  body { background: #fff; color: #000; height: auto; }
  .app, dialog { display: none !important; }
  #printSheet { display: block; font: 400 11pt/1.4 var(--text); color: #000; }
  #printSheet h1 { margin: 0 0 2pt; }
  #printSheet > img { display: block; max-width: 100%; max-height: 4in; margin: 10pt auto; }
  #printSheet .printbom { columns: 2; column-gap: 24pt; }
  #printSheet .bomrow { break-inside: avoid; border-color: #bbb; }
  #printSheet .codes { display: none; }
  #printSheet .msg, #printSheet .note { color: #333; }
  #printSheet .warn { border-left-color: #000; background: none; }
}
