/* Six-Legged Lodgers - a naturalist's specimen cabinet: linen-backed drawers in a walnut frame, brass pins, typed
 * museum labels, and a fishbone drawn in pencil-grey ink. */
:root {
  --bg: #efe9dc; --paper: #fbf8f1; --ink: #22262b; --muted: #585c63; --line: #d6ccb8; --linen: #f3eee2; --linen2: #e9e2d2;
  --walnut: #5a3d27; --walnut-dk: #3b2717; --brass: #a8822f; --brass-lt: #e2c57c; --accent: #24594f; --accent-ink: #ffffff; --label: #fffdf6;
  --bone: #4b4f56; --seal: #1d6650; --seal-bg: #dcefe6; --wait: #845500; --wait-bg: #f7ead0; --checkid: #7a2856; --checkid-bg: #f4dfea; --open: #585c63; --open-bg: #ebe6db;
  --note-bg: #fbf3d9; --note-line: #e6d59c; --focus: #1f5fa8; --shadow: 0 1px 2px rgba(40, 30, 15, 0.08), 0 6px 18px rgba(40, 30, 15, 0.07);
  --warn: #9a2a1a; --info: #4b4f56; --warning-bg: #f7e1dc; --warning-ink: #7a2412;
  --b-stink: #8a6a4a; --b-stink-mk: #4f3b26; --b-lady: #cf4a2b; --b-spot: #1d1d1d; --b-box: #2a2a2a; --b-box-mk: #e0632a; --b-fly: #474c54; --b-wing: rgba(150, 175, 200, 0.45); --b-eye: #8b2a1d; --b-q: #cfc8b8; --b-leg: #3a3a3a;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", serif; --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; --type: "Courier New", ui-monospace, Menlo, Consolas, monospace;
}
:root[data-theme="dark"] {
  --bg: #16130f; --paper: #211c16; --ink: #ece6da; --muted: #b5ad9f; --line: #3d3529; --linen: #2a251e; --linen2: #252019;
  --walnut: #3a2716; --walnut-dk: #24170c; --brass: #d5ad57; --brass-lt: #f0d58f; --accent: #6fc3ad; --accent-ink: #0b1d18; --label: #2f2a22;
  --bone: #b9b3a8; --seal: #8fdcc1; --seal-bg: #173229; --wait: #f2c46a; --wait-bg: #382a10; --checkid: #f0a6cd; --checkid-bg: #3b1a2c; --open: #c9c0b0; --open-bg: #2c271f;
  --note-bg: #2d2717; --note-line: #4c4226; --focus: #8fb8ff; --shadow: 0 1px 2px rgba(0, 0, 0, 0.45), 0 6px 18px rgba(0, 0, 0, 0.35);
  --warn: #f3a08a; --info: #d6cfc2; --warning-bg: #3d1f17; --warning-ink: #ffc8b8;
  --b-stink: #b08c66; --b-stink-mk: #6b5136; --b-lady: #e45b3a; --b-spot: #141414; --b-box: #565656; --b-box-mk: #f08048; --b-fly: #8a919b; --b-wing: rgba(170, 195, 220, 0.4); --b-eye: #d0503b; --b-q: #6d665a; --b-leg: #cfc8bb;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.55 var(--sans); overflow-x: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.small { font-size: 0.86rem; }
.muted { color: var(--muted); }
.mono { font-family: var(--type); }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* Header */
.bar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--paper); border-bottom: 3px solid var(--walnut); flex-wrap: wrap; }
.back { text-decoration: none; color: var(--muted); font-size: 0.9rem; white-space: nowrap; }
.brand { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.brand strong { font: 700 1.05rem var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo { width: 28px; height: 28px; flex: none; }
.lg-frame { fill: var(--walnut); } .lg-linen { fill: var(--linen); } .lg-bug { fill: var(--b-stink); } .lg-pin { fill: var(--brass); }
.session { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.pill { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); border-radius: 6px; padding: 6px 14px; cursor: pointer; text-decoration: none; font: 0.9rem/1.2 var(--sans); }
.pill:hover { border-color: var(--accent); }
.pill.solid { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pill.solid:hover { filter: brightness(1.07); }
.pill.ghost { cursor: default; background: transparent; }
.pill.big { padding: 11px 22px; font-size: 1rem; }
.pill.tiny { padding: 3px 10px; font-size: 0.8rem; }
.pill:disabled { opacity: 0.5; cursor: not-allowed; }

/* Layout */
main { max-width: 1060px; margin: 0 auto; padding: 16px; }
.hero { padding: 18px 4px 8px; }
.kicker { display: inline-block; margin: 0 0 10px; font-size: 0.86rem; line-height: 1.45; color: var(--muted); border-left: 4px solid var(--brass); padding: 2px 0 2px 10px; }
h1 { font: 700 clamp(1.8rem, 5vw, 2.8rem)/1.1 var(--serif); margin: 4px 0 10px; letter-spacing: -0.01em; overflow-wrap: break-word; }
h2 { font: 700 1.3rem var(--serif); margin: 0 0 12px; }
h3 { font: 700 1.05rem var(--serif); margin: 18px 0 8px; }
.lede { font-size: 1.06rem; max-width: 70ch; margin: 0 0 12px; }
.samples { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip { border: 1px dashed var(--walnut); background: var(--paper); border-radius: 4px; padding: 6px 12px; cursor: pointer; font: 0.88rem var(--sans); color: var(--ink); }
.chip.on { border-style: solid; background: var(--wait-bg); border-color: var(--brass); }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin: 16px 0; box-shadow: var(--shadow); }
.ph { display: flex; align-items: center; gap: 10px; }
.step-no { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--brass); color: #1d1406; font: 700 0.95rem var(--sans); flex: none; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18); }
.lbl { display: block; font: 600 0.88rem var(--sans); margin: 10px 0 4px; }
textarea, input[type="text"], select { width: 100%; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); padding: 9px 11px; }
textarea { resize: vertical; min-height: 64px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.check { display: flex; gap: 8px; align-items: flex-start; margin-top: 14px; font-size: 0.95rem; }
.check input { margin-top: 5px; }
.warning { background: var(--warning-bg); color: var(--warning-ink); border-radius: 8px; padding: 10px 12px; margin: 10px 0 0; }
.note { background: var(--note-bg); border: 1px solid var(--note-line); border-radius: 8px; padding: 8px 12px; }

/* The specimen drawer */
.case { display: grid; grid-template-columns: minmax(0, 2.1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.drawer-host { border: 10px solid var(--walnut); border-radius: 6px; padding: 14px; box-shadow: inset 0 0 0 2px var(--walnut-dk), inset 0 6px 14px rgba(0, 0, 0, 0.12);
  background: repeating-linear-gradient(0deg, var(--linen) 0 2px, var(--linen2) 2px 3px), var(--linen); min-height: 160px; }
.drawer-empty { margin: 30px 0; text-align: center; color: var(--muted); font-family: var(--type); }
.drawer { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 14px; }
.specimen { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.mount { position: relative; width: 84px; height: 84px; display: grid; place-items: center; }
.pinhead { position: absolute; top: 18px; left: 50%; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, var(--brass-lt), var(--brass) 60%, #6b501a); z-index: 2; box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3); }
.bug { width: 64px; height: 64px; filter: drop-shadow(1px 3px 2px rgba(0, 0, 0, 0.22)); }
.bug.big { width: 72px; height: 72px; }
.count { position: absolute; right: -2px; bottom: 2px; font: 700 0.8rem var(--type); background: var(--label); border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; color: var(--ink); }
.label { width: 100%; background: var(--label); border: 1px solid var(--line); border-radius: 2px; padding: 5px 7px; font: 0.74rem/1.3 var(--type); display: flex; flex-direction: column; gap: 1px; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06); }
.lab-no { font-weight: 700; overflow-wrap: anywhere; }
.lab-kind { color: var(--muted); }
.lab-note { font-family: var(--serif); font-size: 0.76rem; color: var(--muted); overflow-wrap: anywhere; }
.tallybox .sub { margin-top: 0; }
.tally-bars { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 8px; }
.trow { display: grid; grid-template-columns: minmax(0, 7.5em) minmax(0, 1fr) auto; gap: 8px; align-items: center; font-size: 0.88rem; }
.tname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ttrack { height: 12px; background: var(--linen2); border-radius: 2px; overflow: hidden; border: 1px solid var(--line); }
.tfill { display: block; height: 100%; background: var(--bone); }
.trow.top .tfill { background: var(--brass); }
.tcount { font-family: var(--type); }

/* Bug glyph colours. The glyphs are <use> clones of the <g id="bug-..."> groups in index.html's defs, and CSS matches a
 * clone against its original, so the rules are keyed on those ids (a class on the outer <svg> cannot reach inside). */
[id^="bug-"] .lg { fill: none; stroke: var(--b-leg); stroke-width: 1.6; stroke-linecap: round; }
#bug-stink-bug .bd { fill: var(--b-stink); } #bug-stink-bug .hd { fill: var(--b-stink-mk); } #bug-stink-bug .mk { fill: none; stroke: var(--b-stink-mk); stroke-width: 1.4; }
#bug-lady-beetle .bd { fill: var(--b-lady); } #bug-lady-beetle .hd, #bug-lady-beetle .spot { fill: var(--b-spot); } #bug-lady-beetle .mk-line { stroke: var(--b-spot); stroke-width: 1.2; }
#bug-boxelder-bug .bd, #bug-boxelder-bug .hd { fill: var(--b-box); } #bug-boxelder-bug .mk-red { fill: none; stroke: var(--b-box-mk); stroke-width: 2; }
#bug-cluster-fly .bd, #bug-cluster-fly .hd { fill: var(--b-fly); } #bug-cluster-fly .wing { fill: var(--b-wing); stroke: var(--b-fly); stroke-width: 0.8; } #bug-cluster-fly .eye { fill: var(--b-eye); }
#bug-not-sure .bd, #bug-not-sure .hd { fill: var(--b-q); stroke: var(--bone); stroke-width: 1.4; stroke-dasharray: 3 2; } #bug-not-sure .qm { fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; }

/* Verdict badge and tiles */
.verdict-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
.badge { display: inline-block; border-radius: 4px; padding: 4px 10px; font: 700 0.82rem var(--sans); letter-spacing: 0.02em; background: var(--open-bg); color: var(--open); border: 1px solid currentColor; white-space: nowrap; }
.badge.v-seal-now { background: var(--seal-bg); color: var(--seal); }
.badge.v-wait-them-out { background: var(--wait-bg); color: var(--wait); }
.badge.v-check-id { background: var(--checkid-bg); color: var(--checkid); }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 6px 0 16px; }
.tile { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; min-width: 0; }
.tile b { font: 700 1.2rem var(--type); overflow-wrap: anywhere; }

/* The fishbone */
.fish-host { overflow: hidden; }
.fish { position: relative; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) 128px; grid-template-rows: auto 34px auto; column-gap: 14px; row-gap: 0; }
.bone { position: relative; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-width: 0; }
.bone.up { grid-row: 1; margin-bottom: 26px; border-bottom: 3px solid var(--bone); }
.bone.down { grid-row: 3; margin-top: 26px; border-top: 3px solid var(--bone); }
.bone.c0 { grid-column: 1; } .bone.c1 { grid-column: 2; } .bone.c2 { grid-column: 3; }
.rib { position: absolute; left: 62%; width: 3px; height: 46px; background: var(--bone); border-radius: 2px; }
.bone.up .rib { bottom: -48px; transform: skewX(32deg); transform-origin: top; }
.bone.down .rib { top: -48px; transform: skewX(-32deg); transform-origin: bottom; }
.spine { grid-row: 2; grid-column: 1 / 4; align-self: center; position: relative; height: 6px; background: var(--bone); border-radius: 3px; margin-left: 18px; }
.tail { position: absolute; left: -20px; top: -11px; width: 0; height: 0; border-top: 14px solid transparent; border-bottom: 14px solid transparent; border-right: 22px solid var(--bone); }
.fhead { grid-row: 1 / 4; grid-column: 4; align-self: center; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 2px;
  min-height: 112px; padding: 12px 10px; background: var(--walnut); color: #f6efe2; border-radius: 30% 60% 60% 30% / 50%; font-family: var(--serif); }
.fhead b { font-size: 1rem; line-height: 1.2; }
.fhead .small { color: #e6d8bd; }
.bname { margin: 0 0 6px; font: 700 0.95rem var(--serif); }
.clues { margin: 0 0 6px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 0.78rem; }
.clue-l { color: var(--muted); }
.clue { background: var(--label); border: 1px dashed var(--brass); border-radius: 3px; padding: 0 5px; font-family: var(--type); color: var(--ink); }
.causes { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.causes .none { color: var(--muted); font-size: 0.84rem; font-style: italic; }
.cause { display: grid; grid-template-columns: 14px minmax(0, 1fr); gap: 6px; align-items: start; }
.dot, .dot-s { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--ink); margin-top: 4px; }
.w-strong .dot, .dot-s.w-strong { background: var(--ink); }
.w-possible .dot, .dot-s.w-possible { background: linear-gradient(90deg, var(--ink) 50%, transparent 50%); }
.w-check .dot, .dot-s.w-check { background: transparent; border-style: dashed; }
.ctext { margin: 0; font-size: 0.9rem; line-height: 1.35; }
.cev { margin: 2px 0 0; color: var(--muted); font-size: 0.78rem; overflow-wrap: anywhere; }
.cause.root .ctext { font-weight: 700; }
.rootbadge { display: inline-block; margin-right: 6px; padding: 0 6px; border-radius: 3px; background: var(--brass); color: #1d1406; font: 700 0.72rem var(--sans); font-style: normal; white-space: nowrap; vertical-align: 1px; }
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; margin-top: 10px; }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.legend .dot-s { margin-top: 0; }

/* Ask + progress */
.runrow { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: 12px 0 6px; }
.gate { background: var(--note-bg); border: 1px solid var(--note-line); border-radius: 8px; padding: 8px 12px; }
.gate .pill { margin-left: 4px; }
.steps { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 4px; }
.step { color: var(--muted); font-size: 0.92rem; }
.step.active { color: var(--ink); font-weight: 700; }
.step.done { color: var(--seal); }
.step-ic { display: inline-block; width: 1.2em; font-family: var(--type); }
.raw { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--bg); padding: 10px; border-radius: 8px; max-height: 400px; overflow: auto; font: 0.8rem var(--type); }

/* Result */
.res-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.res-head h2 { margin: 0; overflow-wrap: anywhere; }
.summary { font-size: 1.04rem; }
.idcard { position: relative; display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 12px; align-items: center; background: var(--label); border: 1px solid var(--line); border-left: 6px solid var(--seal); border-radius: 4px; padding: 12px 14px; margin: 12px 0; }
.idcard.m-unsure { border-left-color: var(--checkid); }
.idpin { position: absolute; top: -6px; left: 50%; width: 12px; height: 12px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, var(--brass-lt), var(--brass) 60%, #6b501a); }
.idglyph { display: grid; place-items: center; }
.idhead { margin: 0; font: 700 0.72rem var(--type); text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.idname { margin: 2px 0 4px; font: 700 1.05rem var(--serif); }
.idcard .small { margin: 0; }
.roots { margin: 0; padding-left: 1.4em; display: grid; gap: 8px; }
.rootrow b { margin-right: 8px; }
.rootrow p { margin: 2px 0 0; }
.bone-tag { display: inline-block; font: 0.74rem var(--type); border: 1px solid var(--line); border-radius: 3px; padding: 0 5px; color: var(--muted); background: var(--bg); white-space: nowrap; }
.plan { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.plan-col { background: var(--bg); border: 1px solid var(--line); border-top: 4px solid var(--bone); border-radius: 6px; padding: 10px 12px; min-width: 0; }
.plan-col.w-today { border-top-color: var(--checkid); } .plan-col.w-this-week { border-top-color: var(--seal); } .plan-col.w-before-next-autumn { border-top-color: var(--brass); }
.plan-h { margin: 0 0 8px; font: 700 0.95rem var(--serif); }
.ticks { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.tick { display: grid; grid-template-columns: 16px minmax(0, 1fr); gap: 4px 8px; font-size: 0.9rem; }
.tick-l { display: contents; cursor: pointer; }
.tick .box { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--ink); cursor: pointer; }
.tick.done .tick-l > span { text-decoration: line-through; opacity: 0.7; }
.tick .bone-tag { grid-column: 2; justify-self: start; }
.cardrow, .exports { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.plain { margin: 0; padding-left: 1.2em; }
.recon { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.recon li { padding: 6px 10px; border-radius: 6px; background: var(--bg); font-size: 0.9rem; border-left: 4px solid var(--info); }
.recon li.warn { border-left-color: var(--warn); }
.recon li.none { border-left-color: var(--seal); }
.none { color: var(--muted); }

/* Saved traces + field notes */
.saved { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 8px; }
.hrow { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 10px; align-items: center; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.mini-bug { width: 36px; height: 36px; }
.hinfo { display: flex; flex-direction: column; min-width: 0; }
.hinfo b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbtns { display: flex; gap: 6px; }
.field { list-style: none; padding: 0; margin: 0 0 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; }
.field li { display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 10px; align-items: center; }
.field .bug { width: 46px; height: 46px; }
.foot { max-width: 1060px; margin: 0 auto; padding: 8px 16px 40px; font-size: 0.86rem; color: var(--muted); }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 20; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--paper); border: 1px solid var(--line); border-left: 4px solid var(--seal); border-radius: 6px; padding: 10px 12px; box-shadow: var(--shadow); font-size: 0.9rem; transition: opacity 0.5s; }
.toast.err { border-left-color: var(--warn); }
.toast.gone { opacity: 0; }

/* Phone: the spine turns vertical and the bones stack beside it */
@media (max-width: 760px) {
  .two, .case, .cols, .plan, .field { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fish { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; row-gap: 12px; padding-left: 30px; }
  .bone.up, .bone.down, .bone.c0, .bone.c1, .bone.c2 { grid-row: auto; grid-column: 1; margin: 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); border-left: 3px solid var(--bone); }
  .bone.up .rib, .bone.down .rib { left: -24px; top: 18px; bottom: auto; width: 22px; height: 3px; transform: none; }
  .spine { position: absolute; grid-row: auto; left: 0; top: 74px; bottom: 6px; width: 6px; height: auto; margin: 0 0 0 8px; }
  .tail { left: -11px; top: auto; bottom: -20px; border-left: 14px solid transparent; border-right: 14px solid transparent; border-top: 22px solid var(--bone); border-bottom: 0; }
  .fhead { grid-row: auto; grid-column: 1; order: -1; min-height: 0; margin-left: -30px; border-radius: 40px 40px 10px 10px; flex-direction: row; gap: 8px; flex-wrap: wrap; }
  .back-t { display: none; }
  .bar { padding: 8px 12px; gap: 8px; }
  .brand strong { font-size: 0.98rem; }
  .pill { padding: 6px 10px; }
  main { padding: 12px 16px; }
  .panel { padding: 14px; }
  .drawer-host { border-width: 7px; padding: 10px; }
  .drawer { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .hrow { grid-template-columns: 36px minmax(0, 1fr); }
  .hbtns { grid-column: 1 / -1; }
}
@media print {
  .bar, .samples, .askbox, .histbox, .exports, .cardrow, .toasts, #progressPanel, .foot p:last-child { display: none !important; }
  body { background: #fff; }
  .panel { box-shadow: none; break-inside: avoid; }
}
