/* SheetMill: a drafting table with paper-mill swatch sheets lying on a cutting mat.
   Serif headings (Iowan Old Style), sans body, mono for every measurement. One accent: red pencil. */
:root {
  --mat: #d9e0d6;
  --mat-ink: #c4cdc1;
  --paper: #fbfaf4;
  --paper-2: #f3f1e8;
  --ink: #1c221f;
  --muted: #545d57;
  --rule: #cfd2c6;
  --rule-strong: #9aa197;
  --accent: #b02e1c;
  --accent-ink: #ffffff;
  --accent-soft: #f6e3dc;
  --tick: #6a746c;
  --ok: #2d6a45;
  --head: "Iowan Old Style", Charter, Georgia, "Times New Roman", serif;
  --body: ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --num: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --mat-img: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cpath d='M0 .5H40M.5 0V40' stroke='%23c4cdc1' fill='none'/%3E%3Cpath d='M0 20.5H40M20.5 0V40' stroke='%23ccd4c9' stroke-dasharray='2 3' fill='none'/%3E%3C/svg%3E");
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --mat: #141a17; --mat-ink: #222b26; --paper: #1c211e; --paper-2: #232a26; --ink: #eceae2; --muted: #a9b2ab;
    --rule: #343d38; --rule-strong: #56605a; --accent: #ff8f78; --accent-ink: #1a0d09; --accent-soft: #3a2420; --tick: #8b958e; --ok: #8fd3a7;
    --mat-img: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cpath d='M0 .5H40M.5 0V40' stroke='%23222b26' fill='none'/%3E%3Cpath d='M0 20.5H40M20.5 0V40' stroke='%231d2521' stroke-dasharray='2 3' fill='none'/%3E%3C/svg%3E");
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --mat: #141a17; --mat-ink: #222b26; --paper: #1c211e; --paper-2: #232a26; --ink: #eceae2; --muted: #a9b2ab;
  --rule: #343d38; --rule-strong: #56605a; --accent: #ff8f78; --accent-ink: #1a0d09; --accent-soft: #3a2420; --tick: #8b958e; --ok: #8fd3a7;
  --mat-img: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cpath d='M0 .5H40M.5 0V40' stroke='%23222b26' fill='none'/%3E%3Cpath d='M0 20.5H40M20.5 0V40' stroke='%231d2521' stroke-dasharray='2 3' fill='none'/%3E%3C/svg%3E");
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 12px; }
body {
  margin: 0; color: var(--ink); background-color: var(--mat); background-image: var(--mat-img);
  font: 400 1rem/1.6 var(--body);
}
a { color: var(--accent); text-underline-offset: .16em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
img, svg { max-width: 100%; }
h1, h2, h3 { font-family: var(--head); font-weight: 700; line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: clamp(1.75rem, 4.2vw, 2.6rem); letter-spacing: -.01em; }
h2 { font-size: clamp(1.4rem, 3vw, 1.85rem); margin-top: 0; }
h3 { font-size: 1.2rem; margin-top: 1.6em; }
p, ul, ol, table { margin: 0 0 1em; }
.mono, code, .num { font-family: var(--num); font-variant-numeric: tabular-nums; }
code { font-size: .92em; background: var(--paper-2); padding: 0 .25em; border-radius: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -60px; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; z-index: 10; }
.skip:focus { top: 8px; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; }

/* Header: a paper strip pinned at the top edge of the mat */
.site-header { background: var(--paper); border-bottom: 1px solid var(--rule-strong); }
.header-row { display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap; min-height: 60px; }
.brand { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; color: var(--ink); text-decoration: none; margin-right: auto; }
.logo { flex: none; }
.logo .lg-sheet { fill: var(--paper); stroke: var(--ink); }
.logo .lg-grid { stroke: var(--tick); }
.logo .lg-pencil { stroke: var(--accent); }
.wordmark { font: 700 1.35rem/1 var(--head); letter-spacing: -.01em; }
.wordmark em { font-style: italic; color: var(--accent); }
.nav { display: flex; flex-wrap: wrap; gap: 0 4px; list-style: none; margin: 0; padding: 0; }
.nav a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 10px; color: var(--ink); text-decoration: none; font-size: .95rem; }
.nav a:hover { text-decoration: underline; }
.theme-toggle { min-height: 44px; min-width: 64px; padding: 0 12px; background: transparent; color: var(--ink); border: 1px solid var(--rule-strong); border-radius: 2px; font: 500 .9rem var(--body); cursor: pointer; }
@media (max-width: 560px) { .nav a { padding: 0 8px; font-size: .9rem; } .nav-long { display: none; } }
@media (min-width: 561px) { .nav-short { display: none; } }

/* Leaves: the sheets lying on the mat */
.leaf { background: var(--paper); border: 1px solid var(--rule-strong); margin: 20px 0; padding: 22px 18px; }
@media (min-width: 760px) { .leaf { padding: 32px 36px; margin: 28px 0; } }
.leaf-tab { font: 600 12px/1.3 var(--num); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
.lede { font-size: 1.1rem; max-width: 70ch; }
.note { color: var(--muted); font-size: .95rem; }
.crumb { font-size: .95rem; color: var(--muted); margin-bottom: 14px; }
.crumb a { display: inline-flex; align-items: center; min-height: 44px; }
.meta { color: var(--muted); font-size: .95rem; }
.noscript { border-left: 3px solid var(--accent); padding: 8px 12px; background: var(--paper-2); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border: 1px solid var(--rule-strong); background: var(--paper); color: var(--ink); border-radius: 2px; font: 600 1rem/1.2 var(--body); text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { text-decoration: underline; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.small { font-size: .92rem; padding: 0 12px; }
.btn.quiet { border-color: transparent; text-decoration: underline; }

/* Generator */
.gen-grid { display: grid; gap: 24px; }
@media (min-width: 1000px) { .gen-grid { grid-template-columns: minmax(330px, 380px) minmax(0, 1fr); align-items: start; } }
.controls fieldset { border: 0; border-top: 1px solid var(--rule); margin: 0; padding: 14px 0 12px; min-width: 0; }
.controls fieldset:first-child { border-top: 0; padding-top: 0; }
.controls legend, .lbl { font: 600 12px/1.3 var(--num); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 0; margin-bottom: 8px; }
.lbl { display: block; }
.field { margin: 0 0 12px; }
.field label { display: block; font-weight: 600; font-size: .95rem; margin-bottom: 4px; }
.field .unit { font: 400 .9rem var(--num); color: var(--muted); }
.hint { font-size: .88rem; color: var(--muted); margin: 4px 0 0; }
.err { color: var(--accent); font-size: .92rem; font-weight: 600; margin: 4px 0 0; }
input[type="text"], input[type="number"] {
  width: 100%; max-width: 12rem; min-height: 44px; padding: 8px 10px; font: 400 16px/1.2 var(--num); font-variant-numeric: tabular-nums;
  color: var(--ink); background: var(--paper); border: 1px solid var(--rule-strong); border-radius: 2px; text-align: right;
}
input#preset-name { text-align: left; font-family: var(--body); max-width: none; }
input[aria-invalid="true"] { border-color: var(--accent); border-width: 2px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { position: relative; display: inline-flex; flex-direction: column; justify-content: center; min-height: 44px; min-width: 44px; padding: 4px 12px; border: 1px solid var(--rule-strong); border-radius: 2px; background: var(--paper); cursor: pointer; font-size: .95rem; line-height: 1.25; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg label:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); }
.seg label:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.seg small { font: 400 .8rem var(--num); color: var(--muted); }
.types { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.types label { align-items: flex-start; padding: 6px 8px 8px; }
.types svg { width: 100%; height: 34px; display: block; margin-bottom: 4px; background: #fff; border: 1px solid var(--rule); }
.swatch-c { display: inline-block; width: 18px; height: 18px; border: 1px solid var(--rule-strong); vertical-align: -4px; margin-right: 6px; }
.colours label { flex-direction: row; align-items: center; }
.colours input[type="color"] { position: static; opacity: 1; width: 44px; height: 44px; padding: 0; border: 1px solid var(--rule-strong); background: none; margin-left: 6px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; font-size: .95rem; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.stage { min-width: 0; }
.stage-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 10px; }
.sheet-dim { font: 400 .9rem var(--num); color: var(--muted); margin: 0; }
.preview { overflow: auto; background: var(--mat); background-image: var(--mat-img); border: 1px solid var(--rule-strong); padding: 14px; max-height: 92vh; }
.preview.is-fit { display: flex; justify-content: center; }
.desk-svg { display: block; height: auto; }
.is-actual .desk-svg { max-width: none; }
.desk-svg .mat { fill: var(--paper-2); }
.desk-svg .tick { stroke: var(--tick); }
.desk-svg .paper { stroke: var(--rule-strong); stroke-width: .15; }
.scale-note { font-size: .9rem; color: var(--muted); margin: 8px 0 0; }
.gen-status { font: 400 .95rem/1.45 var(--num); margin: 12px 0 0; padding: 10px 12px; border-left: 3px solid var(--rule-strong); background: var(--paper-2); }
.gen-status.is-error { border-left-color: var(--accent); color: var(--accent); font-weight: 600; }
.out { display: grid; gap: 16px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--rule); }
@media (min-width: 720px) { .out { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center; } }
.out-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.dl-name { font: 400 .88rem var(--num); color: var(--muted); margin: 6px 0 0; overflow-wrap: anywhere; }
.ruler-test { border: 1px dashed var(--rule-strong); padding: 10px 12px; background: var(--paper); }
.ruler-test p { margin: 0 0 6px; font-size: .95rem; }
.ruler-test strong { font-family: var(--head); }
.ruler-sample { display: block; width: 100%; max-width: 440px; height: auto; color: var(--ink); background: #fff0; }
.ruler-sample text { font-family: var(--num); fill: currentColor; }
.status-line { font-size: .95rem; min-height: 1.5em; margin: 6px 0 0; }
details.cal { margin-top: 10px; }
details.cal summary { display: flex; align-items: center; min-height: 44px; cursor: pointer; font-weight: 600; color: var(--ink); }
.cal-card { border: 1.5px solid var(--ink); border-radius: 3mm; margin: 10px 0; background: var(--paper-2); }
.cal input[type="range"] { width: 100%; max-width: 360px; min-height: 44px; accent-color: var(--accent); }
.link-note { border: 1px solid var(--accent); background: var(--accent-soft); padding: 10px 12px; margin: 0 0 16px; display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.link-note p { margin: 0; }

/* Saved presets */
.presets-grid { display: grid; gap: 24px; }
@media (min-width: 900px) { .presets-grid { grid-template-columns: 1fr 1fr; } }
.save-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.save-row .field { flex: 1 1 220px; margin: 0; }
.preset-list { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--rule); }
.preset-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 8px 0; border-bottom: 1px solid var(--rule); }
.pl-text { flex: 1 1 220px; display: flex; flex-direction: column; min-width: 0; }
.pl-name { font-weight: 600; overflow-wrap: anywhere; }
.pl-spec { font: 400 .85rem var(--num); color: var(--muted); }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.file-btn:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.io-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* Specimen swatch book */
.specimens { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); gap: 18px; }
.specimen { display: flex; flex-direction: column; border: 1px solid var(--rule-strong); border-left: 6px solid var(--ink); background: var(--paper); }
.specimen a { color: var(--ink); text-decoration: none; display: flex; flex-direction: column; height: 100%; }
.specimen a:hover .sp-name { text-decoration: underline; color: var(--accent); }
.sp-swatch { display: block; background: #fff; border-bottom: 1px solid var(--rule); aspect-ratio: 40 / 30; overflow: hidden; }
.sp-swatch svg { display: block; width: 100%; height: 100%; }
.sp-body { padding: 10px 12px 12px; }
.sp-name { font: 700 1.1rem/1.25 var(--head); display: block; }
.sp-spec { font: 400 .85rem/1.4 var(--num); color: var(--muted); display: block; margin-top: 4px; }
.sp-no { font: 600 12px var(--num); color: var(--accent); letter-spacing: .08em; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
caption { text-align: left; font-family: var(--head); font-weight: 700; font-size: 1.05rem; padding-bottom: 6px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
thead th { font: 600 12px/1.3 var(--num); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--rule-strong); }
td.n, th.n { text-align: right; font-family: var(--num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.spec-table { max-width: 560px; }
.spec-table th { font: 600 .95rem var(--body); text-transform: none; letter-spacing: 0; color: var(--ink); width: 45%; }

/* Prose */
.prose { max-width: 74ch; overflow-wrap: break-word; }
.prose a { overflow-wrap: anywhere; }
.prose li { margin-bottom: .35em; }
.two-col { display: grid; gap: 28px; }
@media (min-width: 900px) { .two-col { grid-template-columns: 1fr 1fr; } }
.two-col > *, .gen-grid > *, .presets-grid > * { min-width: 0; }
.guides { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--rule); }
.guides li { border-bottom: 1px solid var(--rule); padding: 6px 0; }
.guides a { display: inline-flex; align-items: center; min-height: 44px; font: 600 1.08rem/1.3 var(--head); }
.guides span { display: block; color: var(--muted); font-size: .95rem; }
.faq details { border-bottom: 1px solid var(--rule); }
.faq summary { display: flex; align-items: center; min-height: 48px; padding: 6px 0; cursor: pointer; font: 700 1.08rem/1.3 var(--head); }
.faq details > div { padding: 0 0 12px; max-width: 74ch; }
.formula { font-family: var(--num); font-size: .95rem; background: var(--paper-2); border-left: 3px solid var(--rule-strong); padding: 10px 12px; overflow-x: auto; }
.callout { border: 1px dashed var(--rule-strong); padding: 12px 14px; background: var(--paper-2); }
.siblings { display: flex; flex-wrap: wrap; gap: 6px 8px; list-style: none; padding: 0; }
.siblings a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; border: 1px solid var(--rule-strong); border-radius: 2px; text-decoration: none; color: var(--ink); background: var(--paper); }
.siblings a:hover { border-color: var(--accent); color: var(--accent); }
.article h2 { margin-top: 1.6em; }

/* Ads (off by default) */
.ad-slot { margin: 20px 0; }
.ad-slot .ad-label { font: 600 12px var(--num); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 4px; }
.ad-slot .ad-box { min-height: 280px; background: var(--paper); border: 1px solid var(--rule); }
@media (min-width: 600px) { .ad-slot .ad-box { min-height: 120px; } }

/* Footer */
.site-footer { background: var(--paper); border-top: 1px solid var(--rule-strong); padding: 24px 0 32px; margin-top: 28px; font-size: .95rem; }
.footer-brand { font: 700 1.2rem var(--head); margin-bottom: 8px; }
.footer-brand em { color: var(--accent); }
.footer-nav { display: flex; flex-wrap: wrap; gap: 0 6px; list-style: none; padding: 0; margin: 8px 0; }
.footer-nav a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 6px; }
.copyright { color: var(--muted); margin: 0; }

#print-area { display: none; }

/* Browser Print: only the sheet, at 100%. The @page size is written by app.js for the chosen paper. */
@media print {
  html, body { background: #fff !important; margin: 0; padding: 0; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  .print-page { break-after: page; page-break-after: always; margin: 0; padding: 0; }
  .print-page:last-child { break-after: auto; page-break-after: auto; }
  .print-page svg { display: block; max-width: none; }
}
