:root {
  --paper: #f3eee4;
  --card: #fffdf8;
  --ink: #1e1912;
  --muted: #6a5f51;
  --line: #e2d8c7;
  --line-strong: #cbbda6;
  --accent: #a8431c;
  --accent-ink: #fff;
  --accent-soft: #f6e3d6;
  --field: #fff;
  --stamp: #2a221a;
  --stamp-ink: #f7efe1;
  --stamp-muted: #c9b99f;
  --focus: #1f6feb;
  --ok: #2f6b4f;
  --radius: 10px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #17130f;
    --card: #211b15;
    --ink: #f1e9dc;
    --muted: #b3a48f;
    --line: #3a3027;
    --line-strong: #54473a;
    --accent: #e0814f;
    --accent-ink: #1b130d;
    --accent-soft: #3a2417;
    --field: #1a1511;
    --stamp: #0f0c09;
    --stamp-ink: #f7efe1;
    --stamp-muted: #b3a48f;
    --focus: #6aa8ff;
    --ok: #7cc29e;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.6 var(--sans);
}
img, svg { max-width: 100%; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.prose { max-width: 720px; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--card); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header */
.top { border-bottom: 1px solid var(--line); background: var(--paper); }
.top .wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-family: var(--serif); font-weight: 700; font-size: 1.15rem; }
.brand svg { width: 30px; height: 30px; flex: none; }
.nav { display: flex; gap: 4px 18px; flex-wrap: wrap; font-size: .95rem; }
.nav a { color: var(--muted); text-decoration: none; padding: 4px 0; border-bottom: 2px solid transparent; }
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

/* Headings & text */
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: clamp(2rem, 4.6vw, 2.9rem); margin: 32px 0 8px; }
h2 { font-size: 1.6rem; margin: 48px 0 12px; }
h3 { font-size: 1.2rem; margin: 28px 0 8px; }
.lead { font-size: 1.12rem; color: var(--muted); margin: 0 0 24px; max-width: 640px; }
.crumbs { font-size: .88rem; color: var(--muted); margin-top: 20px; }
.crumbs a { color: var(--muted); }
.crumbs + h1 { margin-top: 8px; }
code, .mono { font-family: var(--mono); font-size: .92em; }
.formula {
  font-family: var(--mono);
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  padding: 14px 16px;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 1rem;
}
.note { color: var(--muted); font-size: .95rem; }
.callout { background: var(--accent-soft); border-radius: var(--radius); padding: 14px 18px; }

/* Card with ruler ticks */
.bench {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 var(--line), 0 12px 30px -18px rgba(60, 40, 20, .35);
  padding: 22px 18px 18px;
  overflow: hidden;
}
.bench::before {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 10px;
  background:
    repeating-linear-gradient(90deg, var(--line-strong) 0 1px, transparent 1px 64px) 0 0 / 100% 10px no-repeat,
    repeating-linear-gradient(90deg, var(--line-strong) 0 1px, transparent 1px 32px) 0 0 / 100% 7px no-repeat,
    repeating-linear-gradient(90deg, var(--line) 0 1px, transparent 1px 8px) 0 0 / 100% 4px no-repeat;
}

/* Toolbar */
.toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: 14px 22px; margin-bottom: 16px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span, .lbl { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; padding: 7px 14px; font-size: .95rem; }
.seg input:checked + span { background: var(--ink); color: var(--paper); }
.seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: -2px; }

input, select, button { font: inherit; color: inherit; }
input[type="text"], input[type="number"], select {
  background: var(--field);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 7px 9px;
  min-height: 40px;
  width: 100%;
  min-width: 0;
}
input::placeholder { color: var(--muted); opacity: .7; }
input:focus, select:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
input[aria-invalid="true"] { border-color: #c0392b; background: color-mix(in srgb, #c0392b 6%, var(--field)); }
select { padding-right: 4px; }
.small { width: 84px; }
.tiny { width: 70px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line-strong);
  background: var(--card);
  border-radius: 8px;
  padding: 8px 14px;
  min-height: 40px;
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.quiet { border-color: transparent; color: var(--muted); }
.btn.quiet:hover { color: var(--ink); border-color: var(--line-strong); }

/* Lumber list */
.head, .row {
  display: grid;
  grid-template-columns: minmax(0,1.5fr) minmax(0,.55fr) minmax(0,.75fr) minmax(0,.75fr) minmax(0,1.25fr) minmax(0,1.7fr) minmax(0,.8fr) minmax(0,.85fr) 34px;
  gap: 8px;
  align-items: center;
}
.head { padding: 0 10px 6px; border-bottom: 2px solid var(--ink); }
.head span { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.head .num { text-align: right; }
.rows { min-height: 96px; }
.row { padding: 10px; border-bottom: 1px dashed var(--line-strong); position: relative; }
.row .cell { min-width: 0; }
.row label.lab { display: none; }
.join { display: flex; align-items: stretch; }
.join > * { border-radius: 0 !important; }
.join > :first-child { border-radius: 6px 0 0 6px !important; }
.join > :last-child { border-radius: 0 6px 6px 0 !important; }
.join > * + * { margin-left: -1px; }
.join select { width: auto; flex: none; background: var(--paper); font-size: .9rem; }
.join .cur { display: flex; align-items: center; padding: 0 8px; border: 1px solid var(--line-strong); background: var(--paper); color: var(--muted); flex: none; }
.join input { flex: 1; }
.out { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.out .k { display: none; }
.out.cost { font-weight: 600; }
.out.empty { color: var(--muted); font-weight: 400; }
.del {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid transparent; background: none;
  color: var(--muted); cursor: pointer; font-size: 1.3rem; line-height: 1;
}
.del:hover { color: var(--accent); border-color: var(--line-strong); }
.math {
  grid-column: 1 / -1;
  margin: 0;
  font-family: var(--mono);
  font-size: .8rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.math b { color: var(--ink); font-weight: 600; }

.addbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 14px 0 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chips .lbl { margin-right: 4px; }
.chip {
  border: 1px solid var(--line-strong); background: var(--paper); border-radius: 999px;
  padding: 4px 11px; font-size: .88rem; cursor: pointer; font-variant-numeric: tabular-nums;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* Totals stamp */
.totals {
  margin-top: 18px;
  background: var(--stamp);
  color: var(--stamp-ink);
  border-radius: var(--radius);
  padding: 18px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
.totals .t { min-width: 0; }
.totals .t span { display: block; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--stamp-muted); }
.totals .t strong { display: block; font-family: var(--serif); font-size: 1.9rem; line-height: 1.15; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.totals .t small { color: var(--stamp-muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.totals .t.big strong { color: #ffc89e; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Log calculator */
.loggrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.joinfield .join input { width: 100%; }
.rules { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
.rule { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; background: var(--paper); }
.rule h3 { margin: 0 0 4px; font-size: 1.05rem; }
.rule .v { font-family: var(--serif); font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.rule .v small { font-family: var(--sans); font-size: .9rem; font-weight: 400; color: var(--muted); }
.rule .bar { height: 8px; border-radius: 4px; background: var(--line); margin: 10px 0 8px; overflow: hidden; }
.rule .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .25s; }
.rule p { margin: 0; font-size: .88rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Tables */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: .95rem; }
th, td { padding: 8px 12px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { background: var(--paper); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); position: sticky; top: 0; }
tbody th { font-weight: 600; }
tbody tr:hover { background: var(--accent-soft); }
tr.hl { background: var(--accent-soft); }
caption { caption-side: bottom; text-align: left; padding: 10px 12px; color: var(--muted); font-size: .88rem; }

/* FAQ */
details { border-bottom: 1px solid var(--line); padding: 12px 0; }
details summary { cursor: pointer; font-weight: 600; font-size: 1.05rem; list-style-position: outside; }
details p { margin: 8px 0 0; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-top: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; text-decoration: none; color: var(--ink); }
.card:hover { border-color: var(--accent); }
.card strong { display: block; font-family: var(--serif); font-size: 1.1rem; }
.card span { color: var(--muted); font-size: .93rem; }

/* Footer */
.foot { margin-top: 64px; border-top: 1px solid var(--line); padding: 24px 0 40px; color: var(--muted); font-size: .92rem; }
.foot .wrap { display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: space-between; }
.foot nav { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.foot a { color: var(--muted); }

.legal h2 { font-size: 1.25rem; margin-top: 32px; }

/* Tablet and phone */
@media (max-width: 900px) {
  .head { display: none; }
  .row {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 10px;
    padding: 14px 4px;
  }
  .row label.lab { display: block; font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 3px; }
  .c-name { grid-column: span 4; }
  .c-qty { grid-column: span 2; }
  .c-t, .c-w, .c-l, .c-price { grid-column: span 3; }
  .c-bf, .c-cost { grid-column: span 3; text-align: left; }
  .out .k { display: block; font-size: .74rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
  .out { font-size: 1.2rem; }
  .del { position: absolute; top: 6px; right: 0; }
  .c-name { padding-right: 30px; }
  .totals { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .loggrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rules { grid-template-columns: 1fr; }
}
@media (max-width: 360px) {
  .c-l, .c-price { grid-column: span 6; }
}
@media (max-width: 440px) {
  .row { gap: 8px; }
  .join .cur { padding: 0 6px; }
  .join select { padding-left: 4px; padding-right: 0; font-size: .85rem; }
  .bench { padding: 20px 12px 14px; }
  .totals .t strong { font-size: 1.5rem; }
  .actions .btn { flex: 1 1 auto; }
}

@media print {
  .top, .foot, .content, .addbar, .actions, .del, .toolbar .seg, .skip, .lead, .crumbs { display: none !important; }
  body { background: #fff; color: #000; font-size: 12px; }
  .bench { box-shadow: none; border: 0; padding: 0; }
  .bench::before { display: none; }
  .totals { background: #fff; color: #000; border: 1px solid #000; }
  .totals .t span, .totals .t small { color: #333; }
  .totals .t.big strong { color: #000; }
  input, select { border: 0 !important; background: none !important; padding: 0; min-height: 0; appearance: none; }
  .join .cur { border: 0; background: none; }
}
