:root {
  --bg: #f2f4f1;
  --surface: #ffffff;
  --ink: #1b211e;
  --muted: #47524c;
  --line: #c3ccc5;
  --accent: #1d5a48;
  --accent-ink: #ffffff;
  --accent-soft: #dce9e2;
  --err: #a1261d;
  --plank: #7a5233;
  --r: 4px;
  --head: "Avenir Next", Avenir, "Segoe UI", system-ui, -apple-system, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --surface: #1b201d;
    --ink: #e5ebe6;
    --muted: #aab6ae;
    --line: #3a4640;
    --accent: #8fd1b6;
    --accent-ink: #0e1a15;
    --accent-soft: #233a31;
    --err: #ff9a8f;
    --plank: #a57a52;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.55 var(--body);
}
main { max-width: 1120px; margin: 0 auto; padding: 0 16px 48px; }
a { color: var(--accent); }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 16px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
[hidden] { display: none !important; }

h1, h2, h3 { font-family: var(--head); line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.75rem, 4.5vw, 2.6rem); margin: 28px 0 6px; font-weight: 800; }
h2 { font-size: 1.4rem; margin: 0 0 12px; font-weight: 750; }
h3 { font-size: 1.1rem; margin: 22px 0 4px; }
.lede { margin: 0 0 18px; max-width: 62ch; color: var(--muted); font-size: 1.08rem; }

/* form basics */
label { font-weight: 600; font-size: 0.95rem; display: block; margin-bottom: 4px; }
input[type="text"], input[type="number"], select, textarea {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r); padding: 9px 10px; min-height: 44px; width: 100%;
}
textarea { min-height: 96px; resize: vertical; }
input[type="color"] {
  width: 100%; min-width: 56px; height: 44px; padding: 3px; border: 1px solid var(--line);
  border-radius: var(--r); background: var(--surface); cursor: pointer;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible, .file-btn:focus-within, a:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
input[aria-invalid] { border-color: var(--err); }
.err { color: var(--err); font-size: 0.95rem; margin: 4px 0 0; }
.note { color: var(--muted); font-size: 0.95rem; margin: 8px 0 0; overflow-wrap: anywhere; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; min-height: 44px; margin: 0; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.btn {
  font: inherit; font-weight: 600; font-size: 1rem; min-height: 44px; padding: 8px 16px; border-radius: var(--r);
  border: 1.5px solid var(--accent); background: transparent; color: var(--accent); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { background: var(--accent-soft); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.quiet { border-color: transparent; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.btn.danger { border-color: var(--err); color: var(--err); }
.btn.small { font-size: 0.95rem; padding: 6px 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* tool */
.setbar { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-start; }
.setbar .field { flex: 1 1 150px; max-width: 240px; }
.setbar .err { flex-basis: 100%; }

.shelf-wrap { margin: 20px 0 8px; }
.shelf { min-height: 164px; display: flex; align-items: flex-end; }
.shelf-svg { display: block; max-width: 100%; height: auto; }
.shelf-svg .plank { fill: var(--plank); }
.summary { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-top: 10px; }
.summary p { margin: 0; font-weight: 650; font-size: 1.1rem; }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 0.95rem; }

.books { margin-top: 28px; }
.books:focus { outline: none; }
.book {
  border: 0; border-top: 2px solid var(--ink); margin: 0; padding: 14px 0 18px; min-width: 0;
}
.book-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); grid-auto-flow: row dense; gap: 10px 12px; }
.book-grid .field { min-width: 0; }
.f-title, .f-author { grid-column: span 3; }
.f-size { grid-column: span 6; }
.f-w, .f-h { grid-column: span 3; }
.f-pages, .f-spine { grid-column: span 2; }
.f-color { grid-column: span 3; }
.f-copies { grid-column: span 2; }
.book-grid label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 380px) { .book-grid { align-items: end; } .f-spine label { white-space: normal; } }
.prints { margin: 10px 0 0; font-size: 0.98rem; }
.pic-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; margin-top: 10px; }
.pic-row .field { flex: 1 1 220px; max-width: 300px; }
.file-btn { margin: 0; }
.thumb { width: 44px; height: 60px; object-fit: cover; border: 1px solid var(--line); }
.rm { margin-left: auto; }
.row-actions { margin: 12px 0; }
.paste summary, .more summary, .earlier summary {
  cursor: pointer; font-weight: 650; min-height: 44px; display: flex; align-items: center; color: var(--accent);
}
.paste textarea { margin-bottom: 8px; }
.paste-size { max-width: 240px; margin-bottom: 12px; }
.more { margin: 20px 0 0; border-top: 1px solid var(--line); padding-top: 4px; }
.more-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 16px; align-items: end; padding-bottom: 8px; }

@media (min-width: 760px) {
  .book-grid { grid-template-columns: repeat(12, minmax(0, 1fr)); grid-auto-flow: row; }
  .f-copies { order: 1; }
  .f-size, .f-w, .f-h, .f-pages, .f-spine, .f-color { order: 2; }
  .f-title { grid-column: span 5; }
  .f-author { grid-column: span 4; }
  .f-copies { grid-column: span 3; }
  .f-size { grid-column: span 4; }
  .f-w, .f-h { grid-column: span 2; }
  .f-pages, .f-spine { grid-column: span 2; }
  .f-color { grid-column: span 2; }
}
@media (min-width: 1000px) {
  .tool { display: grid; grid-template-columns: minmax(0, 1fr) 340px; grid-template-areas: "set shelf" "books shelf" "more shelf"; column-gap: 40px; align-items: start; }
  .setbar { grid-area: set; }
  .books { grid-area: books; margin-top: 20px; }
  .more { grid-area: more; }
  .shelf-wrap { grid-area: shelf; position: sticky; top: 16px; margin-top: 0; }
  .summary { flex-direction: column; align-items: stretch; }
}

/* sheets */
.sheets-sec { margin-top: 36px; }
.messages .msg { margin: 0 0 8px; }
.messages .msg.info { color: var(--ink); }
.sheets { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 20px; margin: 12px 0 16px; }
/* the preview shows the page margin too (--pad = 10 mm as a share of the paper width), so labels sit inset as on paper */
.sheet-wrap { background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 0.25); padding: var(--pad, 0); }
.sheet-wrap svg { display: block; }
@media screen { .sheet-wrap svg { width: 100%; height: auto; } }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.ask { margin-top: 12px; padding: 12px 14px; border: 1.5px solid var(--err); border-radius: var(--r); background: var(--surface); }
.ask p { margin: 0 0 10px; }
.ask .btn { margin-right: 8px; }
.earlier { margin-top: 12px; }
.earlier ul { list-style: none; padding: 0; margin: 0; }
.earlier li { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--line); }
.earlier li span { overflow-wrap: anywhere; }

.undo {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 20;
  background: var(--ink); color: var(--bg); padding: 8px 8px 8px 16px; border-radius: var(--r);
  display: flex; align-items: center; gap: 12px; max-width: calc(100% - 32px); box-shadow: 0 2px 8px rgb(0 0 0 / 0.3);
}
.undo .btn { color: var(--bg); border-color: var(--bg); }
.undo .btn:hover { background: transparent; }

/* content */
.content { margin-top: 48px; max-width: 70ch; }
.content section { margin-bottom: 32px; }
.content ol { padding-left: 1.3em; }
.content li { margin-bottom: 6px; }
.faq p { margin: 0 0 8px; }

/* footer */
.foot { border-top: 1px solid var(--line); margin-top: 24px; padding: 20px 16px 32px; color: var(--muted); font-size: 0.95rem; }
.foot .wrap { max-width: 1120px; margin: 0 auto; }
.sb-footer p { margin: 0 0 10px; }
.sb-more { line-height: 1.9; }
.sb-footer a { color: var(--accent); }
.sb-credit { color: var(--ink); }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }

/* print: only the sheets, at exact size */
@media print {
  body { background: #fff; color: #000; }
  main > *:not(.sheets-sec), .foot, .undo, .skip, .sheets-sec > *:not(.sheets) { display: none !important; }
  main { padding: 0; max-width: none; }
  .sheets-sec { margin: 0; }
  .sheets { display: block; margin: 0; }
  .sheet-wrap { box-shadow: none; padding: 0; break-after: page; page-break-after: always; break-inside: avoid; }
  .sheet-wrap:last-child { break-after: auto; page-break-after: auto; }
  .sheet-wrap svg { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
