/* Macro Finder: "creek critter" identity.
   Colors are named for specimens in the ODNR photos: pond-skim ground, stonefly ink,
   caddis green, water-penny amber, bloodworm red. The answer trail is drawn as a caddis larva. */

:root {
  --ground: #e6f0d5;        /* pond skim */
  --ground-2: #d8e7c1;
  --surface: #ffffff;
  --ink: #243020;           /* stonefly */
  --ink-2: #55634d;
  --line: #c4d4ad;
  --outline: #243020;
  --caddis: #2e8b47;
  --caddis-ink: #ffffff;
  --caddis-text: #22703a;
  --caddis-soft: #cfe7c3;
  --penny: #f2a516;         /* water penny */
  --penny-text: #845400;
  --penny-soft: #f9e5b3;
  --blood: #b8321f;         /* bloodworm */
  --blood-soft: #f5d4cd;
  --seg-a: #a9d18d;
  --seg-b: #8dbf6f;
  --seg-ink: #1f2a17;
  --head: #3b2b1b;          /* hellgrammite head */
  --head-ink: #ffffff;
  --eye: #f2a516;
  --tray: #ffffff;
  --mesh: rgba(36, 48, 32, 0.07);

  --display: "Sniglet", "Arial Rounded MT Bold", "Nunito", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;

  /* Classical scale: 14 / 17 / 21 / 24 / 30 / 36 / 48 */
  --t-sm: 0.875rem;
  --t-base: 1.0625rem;
  --t-md: 1.3125rem;
  --t-lg: 1.5rem;
  --t-xl: 1.875rem;
  --t-2xl: 2.25rem;
  --t-3xl: 3rem;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #121b0e;
    --ground-2: #1a2715;
    --surface: #1d2a17;
    --ink: #e4eed3;
    --ink-2: #a8b89b;
    --line: #34472b;
    --outline: #070c05;
    --caddis: #5ac272;
    --caddis-ink: #0c1809;
    --caddis-text: #79d58f;
    --caddis-soft: #223d22;
    --penny: #f4b63a;
    --penny-text: #f4b63a;
    --penny-soft: #3a2e10;
    --blood: #ff7a66;
    --blood-soft: #3e1c17;
    --seg-a: #5b8b43;
    --seg-b: #4a7736;
    --seg-ink: #eef6e2;
    --head: #e0c79c;
    --head-ink: #1b1409;
    --eye: #7a3e00;
    --tray: #e7eedd;
    --mesh: rgba(36, 48, 32, 0.09);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --ground: #121b0e;
  --ground-2: #1a2715;
  --surface: #1d2a17;
  --ink: #e4eed3;
  --ink-2: #a8b89b;
  --line: #34472b;
  --outline: #070c05;
  --caddis: #5ac272;
  --caddis-ink: #0c1809;
  --caddis-text: #79d58f;
  --caddis-soft: #223d22;
  --penny: #f4b63a;
  --penny-text: #f4b63a;
  --penny-soft: #3a2e10;
  --blood: #ff7a66;
  --blood-soft: #3e1c17;
  --seg-a: #5b8b43;
  --seg-b: #4a7736;
  --seg-ink: #eef6e2;
  --head: #e0c79c;
  --head-ink: #1b1409;
  --eye: #7a3e00;
  --tray: #e7eedd;
  --mesh: rgba(36, 48, 32, 0.09);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 400 var(--t-base)/1.55 var(--body);
  padding-inline: 16px;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
}

img { max-width: 100%; display: block; }
a { color: var(--caddis-text); text-underline-offset: 0.2em; text-decoration-thickness: 0.08em; }
:focus-visible { outline: 3px solid var(--penny); outline-offset: 3px; border-radius: 8px; }
h1, h2, h3 { text-wrap: balance; margin: 0; }
p { margin: 0; }

.wrap { max-width: 36rem; margin-inline: auto; }

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  margin-inline: -16px;
  padding: calc(6px + env(safe-area-inset-top)) 16px 6px;
  background: var(--ground);
  border-bottom: 2px solid var(--line);
}
.bar-inner { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  font: 800 var(--t-md)/1 var(--display);
  color: var(--ink); text-decoration: none;
}
.brand-mark { width: 40px; height: 20px; overflow: visible; }
.bm-seg { stroke: var(--outline); stroke-width: 1.6; }
.bm-seg.a { fill: var(--seg-a); }
.bm-seg.b { fill: var(--seg-b); }
.bm-head { fill: var(--head); stroke: var(--outline); stroke-width: 1.6; }
.bm-eye { fill: var(--eye); }
.bm-antenna { fill: none; stroke: var(--ink); stroke-width: 1.6; stroke-linecap: round; }
.back {
  display: inline-flex; align-items: center; gap: 2px;
  min-height: 44px; padding: 0 10px 0 4px; margin-left: -4px;
  font: 400 var(--t-base)/1 var(--display);
  border: 0; border-radius: 12px; background: transparent; color: var(--caddis-text); cursor: pointer;
}
.back svg { width: 20px; height: 20px; }

/* ---------- bottom tabs ---------- */
.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 5;
  background: var(--surface);
  border-top: 2px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs ul {
  list-style: none; margin: 0 auto; padding: 0 6px; max-width: 36rem;
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: 62px;
  font: 400 0.8125rem/1 var(--display);
  color: var(--ink-2); text-decoration: none;
}
.tabs svg { width: 26px; height: 26px; padding: 2px; border-radius: 10px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tabs svg.filled { fill: currentColor; stroke: none; }
.tabs svg.filled use { stroke: currentColor; }
.tabs a[aria-current="page"] { color: var(--caddis-text); }
.tabs a[aria-current="page"] svg { background: var(--caddis-soft); width: 44px; }

main { display: flex; flex-direction: column; gap: 26px; padding-block: 20px 16px; }
/* Let wide children (the larva, galleries) scroll inside their own row instead of widening the page. */
main > *, .larva { min-width: 0; }
.trail, .gallery-wrap, .group-section { grid-template-columns: minmax(0, 1fr); }

/* ---------- type ---------- */
.page-title, .question, .tag h1, .sec, .group-head h2 { font-family: var(--display); font-weight: 800; }
.page-title { font-size: var(--t-2xl); line-height: 1.05; }
.question { font-size: var(--t-xl); line-height: 1.12; }
.sec { font-size: var(--t-md); line-height: 1.2; margin-bottom: 10px; }
.lede { font-size: var(--t-md); line-height: 1.45; color: var(--ink-2); max-width: 36ch; }
.note, .credit, .unsure, .trail-note, .gallery-hint { font-size: var(--t-sm); color: var(--ink-2); line-height: 1.45; }
.page-title + .lede { margin-top: -14px; }
.block > p { max-width: 64ch; }
.more { margin-top: 10px; }

/* ---------- buttons ---------- */
.button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 52px; padding: 0 24px; border-radius: 999px;
  font: 400 var(--t-md)/1 var(--display);
  background: var(--caddis); color: var(--caddis-ink); text-decoration: none;
  border: 2.5px solid var(--outline);
}
.button.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.button:active { transform: scale(0.97); }
.next-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- the larva (answer trail) ---------- */
.trail { display: grid; gap: 4px; }
.larva-body {
  display: flex; align-items: center;
  overflow-x: auto; scrollbar-width: none;
  margin-inline: -16px; padding: 18px 16px 16px;
}
.larva-body::-webkit-scrollbar { display: none; }
.tail {
  flex: none; width: 26px; height: 34px; margin-right: -4px;
  fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round;
}
.larva ol { display: flex; list-style: none; margin: 0; padding: 0; flex: none; }
.seg { flex: none; margin-left: -12px; position: relative; }
.seg:first-child { margin-left: 0; }
.seg > a, .seg > span {
  position: relative;
  display: flex; align-items: center;
  height: 46px; padding: 0 16px 0 24px;
  border: 2.5px solid var(--outline); border-radius: 23px;
  background: var(--seg-a); color: var(--seg-ink);
  font: 400 var(--t-sm)/1 var(--display); white-space: nowrap; text-decoration: none;
}
.seg:first-child > * { padding-left: 16px; }
.seg:nth-child(even) > * { background: var(--seg-b); }
/* prolegs */
.seg > *::after {
  content: ""; position: absolute; bottom: -8px; left: calc(50% - 5px);
  width: 10px; height: 7px; border-radius: 0 0 5px 5px; background: var(--outline);
}
.seg > a:hover { filter: brightness(1.06); }
.head {
  position: relative; flex: none; margin-left: -12px;
  display: inline-flex; align-items: center; gap: 10px;
  height: 54px; padding: 0 14px 0 26px;
  border: 2.5px solid var(--outline); border-radius: 22px 30px 30px 22px;
  background: var(--head); color: var(--head-ink);
  font: 800 var(--t-base)/1 var(--display); white-space: nowrap; text-decoration: none;
}
.larva ol + .head, .tail + .head { margin-left: -12px; }
.tail + .head { margin-left: -2px; padding-left: 18px; }
.eyes {
  width: 20px; height: 12px; flex: none;
  background:
    radial-gradient(circle at 5px 6px, var(--eye) 0 4px, transparent 4.6px),
    radial-gradient(circle at 15px 6px, var(--eye) 0 4px, transparent 4.6px);
}
/* antennae */
.head::before, .head::after {
  content: ""; position: absolute; top: -15px;
  width: 16px; height: 16px;
  border: 2.5px solid var(--ink); border-left: 0; border-bottom: 0; border-radius: 0 16px 0 0;
}
.head::before { right: 20px; transform: rotate(-12deg); }
.head::after { right: 6px; transform: rotate(14deg); }
.head.found { background: var(--caddis); color: var(--caddis-ink); }
.head.go { background: var(--caddis); color: var(--caddis-ink); }
a.head:active { transform: scale(0.97); }

.restart { justify-self: end; font-size: var(--t-sm); margin-top: -6px; }

@media (prefers-reduced-motion: no-preference) {
  .seg.fresh > * { animation: grow 420ms cubic-bezier(0.3, 1.5, 0.5, 1) both; transform-origin: left center; }
  @keyframes grow { from { transform: scaleX(0.2); opacity: 0.4; } }
}

/* ---------- definition rows (tips) ---------- */
.bees { margin: 0; display: grid; }
.bees div { display: grid; grid-template-columns: 6.5rem 1fr; gap: 12px; padding: 11px 0; border-top: 2px dotted var(--line); }
.bees div:last-child { border-bottom: 2px dotted var(--line); }
.bees dt { font: 800 var(--t-base)/1.45 var(--display); }
.bees dd { margin: 0; }

/* ---------- key: question and options ---------- */
.question { margin-top: -8px; }
.hint {
  background: var(--penny-soft);
  border-radius: 18px;
  padding: 12px 16px 14px;
  line-height: 1.5;
}
.hint-label { display: block; font: 800 var(--t-sm)/1.4 var(--display); color: var(--penny-text); }

.options { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.option {
  display: grid; overflow: hidden;
  background: var(--surface); color: var(--ink); text-decoration: none;
  border: 2px solid var(--line); border-radius: 24px;
  transition: border-color 120ms ease;
}
.option:hover { border-color: var(--caddis); }
.option:active { transform: scale(0.985); }
.dish {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  height: 116px; padding: 12px 16px;
  background-color: var(--tray);
  background-image:
    linear-gradient(var(--mesh) 1px, transparent 1px),
    linear-gradient(90deg, var(--mesh) 1px, transparent 1px);
  background-size: 10px 10px;
  border-bottom: 2px solid var(--line);
}
.dish img { max-height: 100%; max-width: 40%; width: auto; min-width: 0; mix-blend-mode: multiply; }
.option-text { position: relative; display: grid; gap: 4px; padding: 14px 18px 18px; }
.option-text strong { font-size: var(--t-md); line-height: 1.3; padding-right: 2.25rem; }
.code {
  position: absolute; top: 15px; right: 16px;
  font: 400 var(--t-sm)/1 var(--display); color: var(--ink-2);
}
.sub { display: block; color: var(--ink-2); line-height: 1.45; }
.leads {
  justify-self: start; margin-top: 8px; padding: 6px 12px 6px 10px;
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 999px; background: var(--caddis-soft); color: var(--caddis-text);
  font: 400 var(--t-sm)/1.2 var(--display);
}
.leads::before {
  content: ""; width: 14px; height: 14px; flex: none;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cellipse cx='12' cy='14.6' rx='5.2' ry='6.6'/%3E%3Ccircle cx='12' cy='6.2' r='2.9'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cellipse cx='12' cy='14.6' rx='5.2' ry='6.6'/%3E%3Ccircle cx='12' cy='6.2' r='2.9'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* ---------- critter page: specimen label ---------- */
.tag {
  position: relative;
  background: var(--surface);
  border: 2px solid var(--outline);
  border-radius: 8px;
  padding: 26px 18px 14px;
  transform: rotate(-1deg);
  margin-top: 6px;
}
.pin {
  position: absolute; top: -10px; left: calc(50% - 10px);
  width: 20px; height: 20px; border-radius: 50%;
  background: radial-gradient(circle at 7px 7px, rgba(255, 255, 255, 0.55) 0 3px, transparent 3.5px), var(--blood);
  border: 2px solid var(--outline);
}
.tag h1 { font-size: var(--t-2xl); line-height: 1.02; }
.aka { color: var(--ink-2); font-style: italic; margin-top: 2px; }
.tag-rows { margin: 12px 0 0; display: grid; }
.tag-rows div { display: grid; grid-template-columns: 6.75rem 1fr; gap: 10px; padding: 7px 0; border-top: 1px dashed var(--line); }
.tag-rows dt { color: var(--ink-2); font-size: var(--t-sm); line-height: 1.6; }
.tag-rows dd { margin: 0; font-weight: 700; }
.count-row { display: flex; align-items: center; gap: 8px; }

.counts { display: inline-flex; gap: 1px; vertical-align: -3px; }
.bug { width: 22px; height: 22px; }
.bug.on { color: var(--g); fill: var(--g); }
.bug.off { color: var(--line); fill: var(--line); }
.g1 { --g: var(--caddis-text); }
.g2 { --g: var(--penny-text); }
.g3 { --g: var(--blood); }

.gallery-wrap { display: grid; gap: 8px; }
.gallery {
  display: grid; grid-auto-flow: column; grid-auto-columns: 84%;
  gap: 12px; overflow-x: auto; overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory; scrollbar-width: none;
  margin-inline: -16px; padding-inline: 16px; scroll-padding-inline: 16px;
}
.gallery::-webkit-scrollbar { display: none; }
.gallery figure { margin: 0; scroll-snap-align: start; display: grid; gap: 6px; align-content: start; }
.shot { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; border-radius: 20px; }
.tray {
  display: grid; place-items: center; overflow: hidden;
  background-color: var(--tray); border-radius: 20px;
}
.tray img.photo { width: 100%; height: 100%; object-fit: cover; }
.tray img.cutout { object-fit: contain; mix-blend-mode: multiply; }
.shot .tray { aspect-ratio: 4 / 3; width: 100%; border: 2px solid var(--line); }
.shot .tray img.cutout { max-width: 86%; max-height: 86%; }
figcaption { font-size: var(--t-sm); line-height: 1.35; padding-inline: 4px; }
.credit { display: block; font-size: 0.75rem; }

.ruler { width: 100%; max-width: 420px; height: auto; display: block; overflow: visible; }
.ruler .range { fill: var(--seg-a); stroke: var(--outline); stroke-width: 2; }
.ruler .ticks line, .ruler .edge { stroke: var(--ink); stroke-width: 1.2; }
.ruler text { fill: var(--ink-2); font: 400 12px var(--display); }
.ruler + .note { margin-top: 8px; }

.facts { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; max-width: 64ch; }
.facts li { position: relative; padding-left: 24px; }
.facts li::before {
  content: ""; position: absolute; left: 1px; top: 0.5em;
  width: 13px; height: 9px; border-radius: 5px;
  background: var(--seg-a); border: 1.5px solid var(--outline);
}
.facts li.warn::before { background: var(--blood); }
.facts li.warn strong { color: var(--blood); }

.lookalikes { list-style: none; margin: 0; padding: 0; display: grid; }
.lookalikes li { border-top: 2px dotted var(--line); }
.lookalikes li:last-child { border-bottom: 2px dotted var(--line); }
.alike { display: grid; grid-template-columns: 76px 1fr; gap: 14px; padding: 12px 0; color: var(--ink); text-decoration: none; align-items: start; }
a.alike strong { color: var(--caddis-text); }
.alike-text strong { font-size: var(--t-base); }
.tray.mini { width: 76px; height: 64px; border-radius: 16px; border: 2px solid var(--line); }
.tray.mini img.cutout { max-width: 86%; max-height: 86%; }
.tray.blank { font: 800 var(--t-lg)/1 var(--display); color: #8a9a80; }
.gtext { font: 400 0.8125rem/1 var(--display); color: var(--g, var(--ink-2)); white-space: nowrap; }

/* ---------- critters list ---------- */
.group-section { display: grid; gap: 14px; }
.group-head { display: grid; gap: 4px; }
.group-head h2 { font-size: var(--t-xl); line-height: 1.1; display: flex; align-items: center; gap: 10px; }
.group-head h2 .bug { width: 26px; height: 26px; }
.group-head p { color: var(--ink-2); }
.grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (max-width: 559px) {
  .grid li:last-child:nth-child(odd) { grid-column: span 2; }
  .grid li:last-child:nth-child(odd) .tray { aspect-ratio: 8 / 3; }
}
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.card {
  display: grid; overflow: hidden; height: 100%;
  background: var(--surface); border: 2px solid var(--line); border-radius: 22px;
  color: var(--ink); text-decoration: none;
}
.card .tray { aspect-ratio: 4 / 3; border-radius: 0; }
.card-name { padding: 9px 12px 11px; font: 400 var(--t-base)/1.2 var(--display); }
.card:hover { border-color: var(--caddis); }

.refs { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 12px; }
.refs figure { margin: 0; display: grid; gap: 6px; }
.shot.ref img { border: 2px solid var(--line); border-radius: 14px; background: #fff; aspect-ratio: 4 / 3; object-fit: cover; object-position: top; width: 100%; }

/* ---------- key intro ---------- */
.intro { font-size: var(--t-md); line-height: 1.4; color: var(--ink-2); max-width: 36ch; margin-bottom: -18px; }

/* ---------- tools ---------- */
.tool-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.tool {
  display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 16px; align-items: center;
  padding: 16px; background: var(--surface); border: 2px solid var(--line); border-radius: 22px;
  color: var(--ink); text-decoration: none;
}
.tool:hover { border-color: var(--caddis); }
.tool-text { display: grid; gap: 4px; }
.tool-text strong { font: 800 var(--t-md)/1.2 var(--display); color: var(--caddis-text); }
.tool-icon { width: 40px; height: 96px; }
.ti-tube { fill: none; stroke: var(--outline); stroke-width: 2.5; }
.ti-water { fill: #b98c4f; opacity: 0.55; }
.ti-ticks { stroke: var(--ink); stroke-width: 2; }
.ti-dot { fill: #111; }

.calc { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr); }
.calc-card {
  display: grid; gap: 12px; padding: 16px;
  background: var(--surface); border: 2px solid var(--line); border-radius: 22px;
}
.calc-card .sec { margin-bottom: 0; }
.units { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.units legend { width: 100%; padding: 0; margin-bottom: 6px; font-size: var(--t-sm); color: var(--ink-2); }
.units label {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border: 2px solid var(--line); border-radius: 999px; font: 400 var(--t-base)/1 var(--display); cursor: pointer;
}
.units label:has(input:checked) { background: var(--caddis-soft); border-color: var(--caddis); color: var(--caddis-text); }
.units input { accent-color: var(--caddis); width: 18px; height: 18px; margin: 0; }
.field { display: grid; gap: 6px; }
.field > label { font: 800 var(--t-base)/1.2 var(--display); }
.stepper {
  display: grid; grid-template-columns: 56px minmax(0, 1fr) auto 56px; align-items: center;
  border: 2px solid var(--line); border-radius: 18px; overflow: hidden; background: var(--ground);
}
.stepper:focus-within { border-color: var(--caddis); }
.stepper input {
  width: 100%; min-width: 0; border: 0; background: transparent; color: var(--ink); text-align: right;
  font: 800 var(--t-2xl)/1 var(--display); font-variant-numeric: tabular-nums; padding: 8px 6px;
}
.stepper input:focus { outline: none; }
.stepper .unit { padding-right: 10px; color: var(--ink-2); font: 400 var(--t-md)/1 var(--display); }
.step-btn {
  height: 60px; border: 0; background: var(--ground-2); color: var(--ink); cursor: pointer;
  font: 800 var(--t-xl)/1 var(--display);
}
.step-btn:active { background: var(--caddis-soft); }
.input-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.input-row.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.small-field { display: grid; gap: 4px; min-width: 0; }
.small-field label { font-size: var(--t-sm); color: var(--ink-2); line-height: 1.25; }
.small-input {
  display: flex; align-items: center; gap: 4px; padding-right: 10px;
  border: 2px solid var(--line); border-radius: 14px; background: var(--ground);
}
.small-input:focus-within { border-color: var(--caddis); }
.small-input input {
  flex: 1; width: 100%; min-width: 0; border: 0; background: transparent; color: var(--ink);
  font: 700 var(--t-md)/1 var(--body); font-variant-numeric: tabular-nums; padding: 10px;
}
.small-input input:focus { outline: none; }
.small-input span { font-size: var(--t-sm); color: var(--ink-2); }
.step { font: 800 var(--t-base)/1.3 var(--display); margin: 6px 0 -4px; }
.calc-line {
  margin: 0; padding: 9px 12px; border-radius: 12px; background: var(--ground);
  font-size: var(--t-sm); font-variant-numeric: tabular-nums; line-height: 1.4;
}
.calc-line.big { font-size: var(--t-base); font-weight: 700; }

.result {
  display: grid; gap: 10px; padding: 18px;
  background: var(--surface); border: 2.5px solid var(--outline); border-radius: 24px;
}
.result-label { font: 400 var(--t-base)/1 var(--display); color: var(--ink-2); }
.result-value { font: 800 var(--t-3xl)/1 var(--display); font-variant-numeric: tabular-nums; }
.result-value span { font-size: var(--t-md); color: var(--ink-2); }
.result-empty { font: 800 var(--t-lg)/1.2 var(--display); color: var(--ink-2); }
.rating { font-size: var(--t-md); }
.rating strong { color: var(--rt); }
.scale { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
.scale li {
  display: grid; gap: 2px; align-content: start; padding: 8px 7px; border-radius: 12px;
  background: var(--r); color: var(--rt); border: 2px solid transparent;
  font-size: 0.75rem; line-height: 1.2; opacity: 0.5;
}
.scale li strong { font: 800 0.8125rem/1.1 var(--display); }
.scale li.on { opacity: 1; border-color: var(--outline); }
.r-excellent { --r: var(--caddis-soft); --rt: var(--caddis-text); }
.r-normal { --r: var(--ground-2); --rt: var(--ink); }
.r-impaired { --r: var(--penny-soft); --rt: var(--penny-text); }
.r-severe { --r: var(--blood-soft); --rt: var(--blood); }
.form-rows { margin: 0; display: grid; }
.form-rows div { display: grid; grid-template-columns: 7rem 1fr; gap: 10px; padding: 7px 0; border-top: 1px dashed var(--line); }
.form-rows dt { color: var(--ink-2); font-size: var(--t-sm); line-height: 1.6; }
.form-rows dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }

details.how { background: var(--surface); border: 2px solid var(--line); border-radius: 18px; padding: 12px 16px; }
details.how summary { font: 800 var(--t-base)/1.3 var(--display); cursor: pointer; min-height: 28px; }
details.how ol { margin: 10px 0 4px; padding-left: 1.3rem; display: grid; gap: 8px; }
.table-wrap { overflow-x: auto; margin-top: 8px; }
.stick-table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); font-variant-numeric: tabular-nums; }
.stick-table th { text-align: left; font: 800 var(--t-sm)/1.2 var(--display); padding: 6px 8px; border-bottom: 2px solid var(--line); }
.stick-table td { padding: 5px 8px; border-bottom: 1px dotted var(--line); }
.stick-table tr.on td { background: var(--caddis-soft); color: var(--caddis-text); font-weight: 700; }

/* ---------- documents ---------- */
.doc-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.doc-item {
  background: var(--surface); border: 2px solid var(--line); border-radius: 22px; overflow: hidden;
}
.doc-item:hover { border-color: var(--caddis); }
.doc {
  display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 14px; align-items: start;
  padding: 12px; color: var(--ink); text-decoration: none;
}
.doc-thumb {
  display: block; aspect-ratio: 3 / 4; overflow: hidden;
  background: #ffffff; border: 1.5px solid var(--line); border-radius: 8px;
  transform: rotate(-1.5deg);
}
.doc-item:nth-child(even) .doc-thumb { transform: rotate(1.2deg); }
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.doc-text { display: grid; gap: 3px; }
.doc-text strong { font: 800 var(--t-base)/1.25 var(--display); color: var(--caddis-text); }
.doc-text .sub { font-size: var(--t-sm); }
.doc-meta { font-size: var(--t-sm); color: var(--ink); font-weight: 700; margin-top: 2px; }
.doc-name { font-size: 0.75rem; color: var(--ink-2); overflow-wrap: anywhere; }
.doc-alt {
  display: block; padding: 10px 16px 12px 110px;
  border-top: 1px dashed var(--line); font-size: var(--t-sm);
}

/* ---------- zoom ---------- */
dialog#zoom {
  width: min(100vw - 24px, 980px); max-height: calc(100vh - 24px);
  padding: 0; border: 0; border-radius: 22px; background: #ffffff; color: #243020;
}
dialog#zoom::backdrop { background: rgba(10, 18, 7, 0.84); }
dialog#zoom figure { margin: 0; display: grid; }
dialog#zoom img { width: 100%; max-height: calc(100vh - 96px); object-fit: contain; background: #ffffff; }
dialog#zoom p { padding: 10px 16px 14px; font-size: var(--t-sm); display: flex; justify-content: space-between; gap: 12px; }
dialog#zoom p::after { content: "Tap to close"; color: #55634d; }
