:root {
  --bg: #eef1ec;
  --ink: #17231c;
  --muted: #3c4a41;
  --line: #b9c4bb;
  --card: #ffffff;
  --accent: #9b2f22;
  --accent-ink: #ffffff;
  --accent-soft: #f6e4df;
  --drawer: #26352d;
  --focus: #1f5fbf;
  --warn-bg: #fff3d6;
  --warn-ink: #4f3a00;
  --err-ink: #8f1d12;
  --label: #f8faf7;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151c18;
    --ink: #e6ece6;
    --muted: #b9c5bc;
    --line: #3a4a40;
    --card: #1e2823;
    --accent: #e48a76;
    --accent-ink: #1c0c08;
    --accent-soft: #3a2420;
    --drawer: #0b100d;
    --focus: #8ab4ff;
    --warn-bg: #3a2f12;
    --warn-ink: #f6e2ae;
    --err-ink: #ffb4a6;
    --label: #19221d;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-underline-offset: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; left: -9999px; top: 0; }
.skip:focus { left: 16px; top: 8px; background: var(--card); padding: 8px 12px; z-index: 50; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
[hidden] { display: none !important; }

.hero { padding: 28px 16px 8px; }
h1 { font-size: clamp(28px, 5vw, 42px); line-height: 1.1; margin: 0 0 10px; letter-spacing: -0.02em; font-weight: 800; max-width: 22ch; }
.lede { margin: 0; max-width: 62ch; color: var(--muted); font-size: 18px; }
h2 { font-size: 22px; line-height: 1.25; margin: 0; letter-spacing: -0.01em; }
h3 { font-size: 18px; margin: 22px 0 4px; }

.bar { margin: 12px 0 0; padding: 10px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 6px; }
.bar.warn, .msg.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }

/* label type picker */
.types { border: 0; margin: 18px 0 10px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.types legend { font-weight: 700; padding: 0; margin-bottom: 6px; }
.types label { position: relative; }
.types input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.types span {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 44px; padding: 6px 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--card);
  cursor: pointer; line-height: 1.2;
}
.types input:checked + span { background: var(--ink); color: var(--bg); border-color: var(--ink); font-weight: 700; }
.types input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
@media (max-width: 560px) {
  .types { display: grid; grid-template-columns: repeat(3, 1fr); }
  .types legend { grid-column: 1 / -1; }
  .types span { padding: 6px 4px; height: 100%; }
}

.cols-2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 28px; margin-top: 10px; }
.cols-2 > * { min-width: 0; }
@media (min-width: 960px) {
  .cols-2 { grid-template-columns: minmax(340px, 420px) minmax(0, 1fr); align-items: start; }
}
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; margin-bottom: 8px; border-bottom: 2px solid var(--ink); padding-bottom: 6px; }
.count { color: var(--muted); }

/* specimen list */
.rows { list-style: none; margin: 0; padding: 0; }
.item { border-bottom: 1px solid var(--line); }
.sum {
  width: 100%; display: grid; grid-template-columns: 2.6em 1fr auto; column-gap: 8px; align-items: baseline;
  text-align: left; background: none; border: 0; padding: 10px 4px; min-height: 48px; font: inherit; color: inherit; cursor: pointer;
}
.sum:hover { background: color-mix(in srgb, var(--card) 70%, transparent); }
.sum .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.sum .main { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.sum .sub { grid-column: 2; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.sum .cp { grid-column: 3; grid-row: 1; color: var(--accent); font-weight: 700; }
.item.open { background: var(--card); border: 1px solid var(--line); border-radius: 6px; margin: 6px 0; }
.item.open .sum { border-bottom: 1px solid var(--line); }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; padding: 12px; }
.form .wide { grid-column: 1 / -1; }
.form label, .settings label { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.form label span, .settings label span { font-weight: 600; }
.f-elev { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.f-elev > label { font-weight: 600; }
.elev-in { display: flex; gap: 6px; }
.elev-in input { flex: 1; min-width: 0; }
.elev-in select { width: auto; flex: none; }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 4px;
  min-height: 44px; padding: 8px 10px; width: 100%; min-width: 0;
}
textarea { min-height: 120px; font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 16px; }
input:disabled { opacity: 1; color: var(--muted); }
.row-act { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 0; }
@media (max-width: 420px) { .form { grid-template-columns: 1fr; } }
.empty { margin: 8px 0; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 16px;
  font: inherit; font-weight: 650; color: var(--ink); background: var(--card); border: 1px solid var(--ink); border-radius: 6px; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.quiet { border-color: var(--line); background: transparent; }
.btn:disabled { opacity: 0.45; cursor: default; }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); text-decoration: underline; cursor: pointer; min-height: 0; }
.list-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.list-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin: 14px 0; }
.jump { padding: 10px 0; }
@media (min-width: 960px) { .jump { display: none; } }

details > summary { cursor: pointer; font-weight: 650; min-height: 44px; display: flex; align-items: center; gap: 8px; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: ""; width: 0; height: 0; border-style: solid; border-width: 5px 0 5px 8px; border-color: transparent transparent transparent currentColor; transition: transform 0.15s; }
details[open] > summary::before { transform: rotate(90deg); }
#paste { margin: 4px 0 8px; }
#paste label { display: block; margin: 6px 0 4px; }
.map { margin-top: 8px; }
.map .check { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.map .check input { width: 22px; min-height: 22px; height: 22px; }
.map-scroll { overflow-x: auto; }
.map-t { border-collapse: collapse; width: 100%; }
.map-t th, .map-t td { text-align: left; padding: 6px 6px 6px 0; border-bottom: 1px solid var(--line); vertical-align: middle; overflow-wrap: break-word; }
.map-t th { min-width: 7em; hyphens: none; }
.map-t td:nth-child(2) { color: var(--muted); min-width: 6em; max-width: 12em; overflow-wrap: anywhere; }
.map-t select { min-width: 9.5em; }
@media (max-width: 600px) {
  .map-t thead { display: none; }
  .map-t tr { display: block; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .map-t th, .map-t td { display: block; border: 0; padding: 2px 0; min-width: 0; max-width: none; }
  .map-t td[data-cap]:not(:empty)::before { content: attr(data-cap) ": "; }
  .map-t select { width: 100%; }
}
.map-act { display: flex; flex-wrap: wrap; gap: 8px; }
.msg { margin: 10px 0; padding: 10px 12px; border-radius: 6px; background: var(--card); border: 1px solid var(--line); overflow-wrap: anywhere; }
.msg.err { color: var(--err-ink); }
.issues { margin: 10px 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); }
.issues p { margin: 0 0 4px; font-weight: 650; }
.issues ul { margin: 0; padding-left: 20px; overflow-wrap: anywhere; }
.earlier { margin: 8px 0; }
.kept-list { list-style: none; padding: 0; margin: 0; }
.kept-list li { border-top: 1px solid var(--line); padding: 8px 0; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; align-items: center; }
.kept-list p { margin: 0; overflow-wrap: anywhere; }
.when { color: var(--muted); }

/* settings and preview */
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 12px; margin-bottom: 10px; }
.settings .wide, .settings .custom { grid-column: 1 / -1; }
.settings .plain { margin: -4px 0 0; }
.custom { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
#more label { margin-top: 8px; }
.summary { font-size: 19px; font-weight: 650; margin: 6px 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.pager { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.viewer { background: var(--drawer); border-radius: 6px; padding: 1px; overflow: hidden; position: relative; min-height: 120px; }
#sheets { transform: scale(var(--k, 0.4)); transform-origin: 0 0; width: max-content; }
.sheet { display: none; position: relative; background: #fff; color: #000; overflow: hidden; }
.sheet.cur { display: block; }
.sheet-err p { position: absolute; left: 20mm; top: 20mm; right: 20mm; font: 12pt/1.4 system-ui, sans-serif; }
.sh-head { position: absolute; top: 4.5mm; display: flex; justify-content: space-between; align-items: center; gap: 4mm; font: 7.5pt/1.2 system-ui, -apple-system, "Segoe UI", Arial, sans-serif; color: #222; }
.sh-check { display: inline-flex; align-items: center; gap: 1.5mm; white-space: nowrap; }
.sh-check svg line { stroke: #000; stroke-width: 0.3; }
.cuts { position: absolute; left: 0; top: 0; pointer-events: none; }
.cuts line { stroke: #8c8c8c; stroke-width: 0.15; }

/* the printed labels (also drawn off screen to measure) */
.lab { position: absolute; overflow: hidden; color: #000; }
.lab-in {
  position: absolute; inset: 4mm 4.5mm; overflow: hidden;
  font-family: "Times New Roman", Tinos, "Liberation Serif", Times, "Nimbus Roman", serif; line-height: 1.2; color: #000;
}
.lab-in p { margin: 0; }
.turn { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.t-insect .lab-in { inset: 0.5mm 0.6mm; line-height: 0.98; }
.t-mineral .lab-in, .t-fossil .lab-in, .t-seed .lab-in { inset: 3mm 3.5mm; }
.t-shell .lab-in { inset: 2.2mm 2.8mm; }
.b-hd { text-align: center; font-weight: 700; margin-bottom: 0.3em !important; }
.b-fam { text-align: center; text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.86em; }
.t-fossil .b-fam, .t-shell .b-fam { text-align: left; text-transform: none; letter-spacing: 0; font-size: 1em; }
.b-nm { margin: 0.25em 0 0.3em !important; }
.b-nm i, .b-big i { font-weight: 700; }
.b-big { font-size: 1.4em; font-weight: 700; line-height: 1.15; margin-bottom: 0.15em !important; }
.b-p { margin-top: 0.2em !important; }
.b-row { display: flex; justify-content: space-between; gap: 1em; margin-top: 0.45em !important; }
.b-row span:last-child { text-align: right; white-space: nowrap; }
.b-det, .b-cat { margin-top: 0.25em !important; }
.b-no { float: right; font-weight: 700; margin-left: 0.6em !important; }
.b-ln { overflow-wrap: anywhere; }
.k-det .b-ln:first-child i { font-weight: 700; }
.b-w { display: flex; align-items: baseline; gap: 0.4em; margin: 0.7em 0 0 !important; }
.b-w span { font-size: 0.85em; }
.b-w i { flex: 1; border-bottom: 0.2mm solid #666; }
.k-blank .lab-in { display: flex; flex-direction: column; justify-content: space-evenly; }
.k-blank .b-w { margin: 0 !important; }
.lab.over::after { content: ""; position: absolute; inset: 0.3mm; border: 0.6mm dashed #c0392b; }
#measure { position: absolute; left: -20000px; top: 0; visibility: hidden; }
#measure .lab { position: relative; }

/* explainer */
.info { padding-top: 36px; padding-bottom: 24px; max-width: 760px; margin-left: 0; }
@media (min-width: 1232px) { .info { margin-left: calc((100vw - 1200px) / 2); } }
.info h2 { margin-top: 30px; }
.info p, .rules { max-width: 68ch; }
.rules { padding-left: 20px; }
.rules li { margin: 6px 0; }
.faq h3 { margin-top: 18px; }
.faq p { margin: 2px 0 0; }

/* dialog and toast */
.ask { position: fixed; left: 50%; top: 30%; transform: translateX(-50%); width: min(440px, calc(100vw - 32px)); background: var(--card); border: 2px solid var(--ink); border-radius: 8px; padding: 16px 18px; z-index: 40; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3); }
.ask p { margin: 0 0 10px; }
.ask p:last-child { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; }
.toast { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px); background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 6px; z-index: 30; pointer-events: none; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.toast .undo { pointer-events: auto; background: none; border: 1px solid var(--bg); color: var(--bg); font: inherit; font-weight: 700; border-radius: 4px; min-height: 40px; padding: 4px 12px; cursor: pointer; }

/* footer */
footer { border-top: 1px solid var(--line); margin-top: 24px; padding: 18px 0 30px; color: var(--muted); }
.sb-footer p { margin: 6px 0; }
.sb-more { overflow-wrap: anywhere; }
.sb-footer a { color: var(--ink); }

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

@media print {
  html, body { background: #fff !important; color: #000; margin: 0; padding: 0; }
  .skip, .hero, .info, footer, main > .wrap:not(.tool), .ask, .toast, #example-bar, #store-note, .types, #list-sec, .sec-head, .settings, #size-err, #result, #measure { display: none !important; }
  main, .tool, .cols-2, #labels-sec { display: block !important; margin: 0 !important; padding: 0 !important; max-width: none !important; width: auto !important; border: 0 !important; }
  .viewer { background: none !important; height: auto !important; padding: 0 !important; overflow: visible !important; border-radius: 0; }
  #sheets { transform: none !important; width: auto; }
  .sheet { display: block !important; break-after: page; page-break-after: always; }
  .sheet:last-child { break-after: auto; page-break-after: auto; }
  .lab.over::after { display: none; }
}
