/* Cut List: stevensbored navy and mint. Mint is material you keep, warm is what the saw eats. */
:root {
  --bg: #0c1020;
  --panel: #171b2b;
  --field: #0f1426;
  --line: #2a3048;
  --ink: #f4ede6;
  --dim: #a9adc0;
  --mint: #acf8b4;
  --warm: #ffa470;
  --bad: #ff8f8f;
  --focus: #ffffff;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: dark; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: rgba(172, 248, 180, .2); }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink);
  font: 17px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
.skip { position: absolute; left: 12px; top: -80px; z-index: 5; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; }
.skip:focus { top: 12px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
html { scroll-behavior: smooth; scroll-padding-bottom: 96px; } /* keep a focused box clear of the Solve bar */

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 16px; border-bottom: 1px solid var(--line); }
.home { display: inline-flex; align-items: center; min-height: 44px; color: var(--ink); text-decoration: none; font-weight: 700; }
.home b { color: var(--mint); }
.home:hover { text-decoration: underline; text-underline-offset: 4px; }
h1 { margin: 0; font-size: 1.05rem; font-weight: 600; color: var(--dim); }
h2, .h2 { margin: 0; font-size: 1.2rem; font-weight: 700; line-height: 1.3; }
h3 { margin: 18px 0 6px; font-size: 1rem; }

main { width: min(100%, 1240px); margin: 0 auto; padding: 18px 16px 0; display: grid; gap: 20px; }
.lead { margin: 0 0 16px; max-width: 60ch; color: var(--dim); }
.hint { margin: 6px 0 0; font-size: .86rem; color: var(--dim); max-width: 62ch; }
.hint:empty { display: none; }
.nw { white-space: nowrap; }

.block { padding: 0 0 18px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.block h2 { margin-bottom: 8px; }
.fold > summary {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; min-height: 44px; padding: 8px 0; cursor: pointer; list-style: none;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::before { content: "+"; width: 1ch; color: var(--mint); font-weight: 700; }
.fold[open] > summary::before { content: "\2212"; }
.sum { font-size: .9rem; color: var(--dim); overflow-wrap: anywhere; }

/* inputs */
input, select, textarea { font: inherit; font-size: 16px; color: var(--ink); }
.row input, .row select, .inp input, .inp select, textarea {
  width: 100%; min-width: 0; min-height: 44px; padding: 6px 10px; border-radius: 8px; background: var(--field);
  border: 1px solid var(--line);
  border-color: color-mix(in srgb, var(--dim) 60%, var(--field)); /* 3.7:1; --line alone is too faint to find a box in glare */
}
.inp { display: flex; }
.inp input, .inp select { flex: 1; }
.row input:focus-visible, .row select:focus-visible, .inp input:focus-visible, .inp select:focus-visible, textarea:focus-visible { outline: 2px solid var(--mint); outline-offset: 1px; }
[aria-invalid="true"], .row [aria-invalid="true"]:focus-visible, .inp [aria-invalid="true"]:focus-visible { border-color: var(--bad) !important; outline: 2px solid var(--bad); }
select { appearance: none; padding-right: 20px !important; cursor: pointer;
  background: var(--field) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23a9adc0' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 8px center; }
textarea { resize: vertical; line-height: 1.4; }
::placeholder { color: color-mix(in srgb, var(--dim) 70%, var(--field)); }

.row, .phead, .shead { display: grid; gap: 4px; align-items: center; }
.row { margin-bottom: 4px; }
.row.pieces, .phead { grid-template-columns: 44px minmax(0, 1fr) 50px 102px 44px; }
.row.pieces select { padding-left: 8px; }
.row.stock, .row.remnants, .shead { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px; }
.row [data-k="qty"] { text-align: center; padding: 6px 4px; }
.shead:has(+ div:empty) { display: none; }
.phead, .shead { font-size: .8rem; font-weight: 600; color: var(--dim); margin-bottom: 2px; }
.ferr { margin: 4px 0 8px; padding: 8px 12px; border-left: 4px solid var(--bad); background: var(--panel); border-radius: 0 8px 8px 0; font-size: .92rem; }
.del { min-height: 44px; min-width: 44px; border: 0; border-radius: 8px; background: none; color: var(--dim); font: inherit; font-size: 1.3rem; cursor: pointer; }

.field { display: grid; gap: 4px; min-width: 0; }
.field .name { font-size: .88rem; font-weight: 600; color: var(--dim); }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.field.wide { grid-column: 1 / -1; }
#stock > .field { margin-bottom: 4px; }

.acts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px;
  border: 1px solid var(--mint); border-radius: 10px; background: var(--mint); color: #0c1020; font: inherit; font-weight: 700; cursor: pointer;
}
.btn.ghost { background: none; color: var(--ink); border-color: var(--line); font-weight: 600; }
.btn:disabled { opacity: .6; cursor: progress; }
#import:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; }
.paste { margin-top: 12px; }
.paste > summary { display: inline-flex; align-items: center; min-height: 44px; cursor: pointer; color: var(--mint); font-weight: 600; }
.paste .field { margin: 4px 0 8px; }

.saved { list-style: none; margin: 10px 0 0; padding: 0; }
.saved li { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-top: 1px solid var(--line); }
.saved .jn { flex: 1; min-width: 0; overflow-wrap: anywhere; }

/* the bar that keeps Solve and the answer in reach */
.bar {
  position: sticky; bottom: 0; z-index: 3; display: flex; align-items: center; gap: 12px;
  margin: 0 -16px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--line);
}
.solve { flex: none; min-width: 96px; }
.barsum { flex: 1; min-width: 0; min-height: 44px; display: flex; align-items: center; color: var(--ink); font-size: .92rem; line-height: 1.3; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }

/* results */
.results { min-width: 0; scroll-margin-top: 8px; outline: none; }
.results.stale #out { opacity: .5; }
.empty { color: var(--dim); }
.err { margin: 0; padding: 12px 14px; border-left: 4px solid var(--bad); background: var(--panel); border-radius: 0 8px 8px 0; }
.sheet-head .ptitle { margin: 4px 0 0; font-weight: 700; overflow-wrap: anywhere; }
.status { margin: 2px 0 10px; color: var(--dim); }
.status.ok { color: var(--mint); }
.sum-dl { margin: 0; display: grid; }
.line { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 14px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.line dt { color: var(--dim); font-size: .92rem; }
.line dd { margin: 0 0 0 auto; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.line.big dd { font-size: 1.3rem; color: var(--mint); }

.stick { margin-top: 22px; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.stick h3 { margin: 0 0 10px; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; font-size: 1.05rem; }
.stick .what { color: var(--dim); font-weight: 600; font-size: .92rem; }

/* one stick, drawn to scale: mint pieces, warm kerf and trim, outlined drop */
.diagram { display: flex; height: 46px; border-radius: 4px; overflow: hidden; background: var(--field); }
.seg { flex: 0 1 0; min-width: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; white-space: nowrap; font-size: 1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.seg.piece { background: var(--mint); color: #0c1020; box-shadow: inset -1px 0 0 var(--bg); }
.seg.kerf { min-width: 2px; background: var(--warm); }
.seg.trim { min-width: 3px; background: var(--warm); }
.seg.drop { border: 2px solid var(--warm); border-left: 0; border-radius: 0 4px 4px 0; }
.seg.scrap { border: 2px dashed var(--dim); border-left: 0; }

.cuts { list-style: none; margin: 10px 0 0; padding: 0; }
.cuts .cutrow { display: grid; grid-template-columns: 44px 2.2ch auto minmax(0, 1fr); align-items: center; gap: 2px 10px; min-height: 48px; border-bottom: 1px solid var(--line); }
.cuts label.cutrow { cursor: pointer; }
.stick input {
  appearance: none; width: 26px; height: 26px; margin: 0 9px; border: 2px solid var(--dim); border-radius: 5px; background: var(--field); cursor: pointer;
}
.stick input:checked { background: var(--mint); border-color: var(--mint); box-shadow: inset 0 0 0 4px var(--panel); }
.cuts .no { color: var(--dim); font-size: .85rem; text-align: right; font-variant-numeric: tabular-nums; }
.cuts .len { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cuts .len.small { font-size: 1rem; color: var(--warm); }
.cuts .mk { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 10px; color: var(--dim); font-size: .92rem; min-width: 0; }
.cuts .pm { color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.cuts .en, .cuts .ft { white-space: nowrap; }
.cuts li.cut .len, .cuts li.cut .mk { text-decoration: line-through; opacity: .55; }
/* a group: the cuts once, then a box per stick */
.like { margin: 0 0 10px; font-size: 1.15rem; font-weight: 700; color: var(--mint); }
.prog { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 10px; padding-top: 6px; border-top: 1px solid var(--line); }
.plabel { font-weight: 600; }
.pboxes { display: flex; flex-wrap: wrap; }
.pbox { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; cursor: pointer; }
.pbox input { margin: 0; }
.pcount { color: var(--dim); font-variant-numeric: tabular-nums; }
.drop { margin: 10px 0 0; font-weight: 600; color: var(--dim); }
.drop.keep { color: var(--warm); }

/* phone: a piece takes two lines so the mark has room (qty, length / mark, ends) */
@media (max-width: 599px) {
  .phead { display: none; }
  .row.pieces { grid-template-columns: 56px minmax(0, 1fr) minmax(0, 1fr) 44px; grid-template-areas: "q l l x" "m m e e"; margin-bottom: 12px; }
  .row.pieces [data-k="qty"] { grid-area: q; }
  .row.pieces [data-k="len"] { grid-area: l; }
  .row.pieces [data-k="mark"] { grid-area: m; }
  .row.pieces [data-k="ends"] { grid-area: e; }
  .row.pieces .del { grid-area: x; }
}

/* laptop: inputs on the left, cuts on the right */
@media (min-width: 900px) {
  main { grid-template-columns: minmax(0, 440px) minmax(0, 1fr); grid-template-rows: auto 1fr; column-gap: 36px; padding-top: 24px; }
  .inputs { grid-column: 1; grid-row: 1; }
  .row.pieces, .phead { grid-template-columns: 52px minmax(0, 1fr) 92px 112px 44px; }
  .bar { grid-column: 1; grid-row: 2; align-self: end; margin: 0; border: 1px solid var(--line); border-bottom: 0; border-radius: 12px 12px 0 0; }
  .results { grid-column: 2; grid-row: 1 / span 2; padding-bottom: 40px; }
  .stick { padding: 16px 18px; }
}
@media (max-width: 899px) {
  .results { padding-bottom: 12px; }
}

/* the sheet that gets taped to the saw */
@media print {
  @page { margin: 12mm; }
  :root { --bg: #fff; --panel: #fff; --field: #fff; --line: #000; --ink: #000; --dim: #000; --mint: #000; --warm: #000; }
  body { background: #fff; color: #000; font-size: 12pt; padding: 0; }
  .top, .inputs, .bar, .noprint, .skip, .results > h2 { display: none !important; }
  main { display: block; padding: 0; width: 100%; }
  .results.stale #out { opacity: 1; }
  .sheet-head .ptitle { font-size: 16pt; }
  .status { margin-bottom: 4px; }
  .line { padding: 2px 0; border-color: #999; }
  .line.big dd { font-size: 14pt; }
  .stick { break-inside: avoid; margin-top: 10pt; padding: 8pt 10pt; border: 1.5pt solid #000; border-radius: 0; }
  .diagram { height: 22pt; border: 1pt solid #000; border-radius: 0; }
  .seg.piece { background: #fff; color: #000; box-shadow: inset -1pt 0 0 #000; }
  .seg.kerf, .seg.trim { background: #000; }
  .cuts .cutrow { min-height: 26pt; border-color: #999; }
  .like { font-size: 14pt; }
  .prog .pcount { display: none; }
  .stick input, .stick input:checked { width: 16pt; height: 16pt; border: 1.5pt solid #000; background: #fff; box-shadow: none; }
  .cuts .len { font-size: 16pt; }
  .cuts .len.small { font-size: 12pt; }
  .cuts li.cut .len, .cuts li.cut .mk { text-decoration: none; opacity: 1; }
  .drop { font-size: 13pt; }
}
.grid > .ferr { grid-column: 1 / -1; margin: 0; }
