:root {
  --paper: #edf1ec;
  --card: #f7faf7;
  --ink: #1a2420;
  --muted: #54655c;
  --line: #cfd9d1;
  --accent: #0a6a5a;
  --accent-soft: rgba(10, 106, 90, 0.12);
  --field: #0a6a5a;
  --row-hi: #dfe8df;
  --ok: #0a6a5a;
  --bad: #a4262c;
  --mid: #8a5a00;
  --topbar-h: 52px;
}
[data-theme="dark"] {
  --paper: #0e1512;
  --card: #16211c;
  --ink: #ecf3ee;
  --muted: #a9bbae;
  --line: #24352d;
  --accent: #5bc8a5;
  --accent-soft: rgba(91, 200, 165, 0.14);
  --field: #5bc8a5;
  --row-hi: #1c2a23;
  --ok: #5bc8a5;
  --bad: #ef8f94;
  --mid: #d9a441;
  --topbar-h: 52px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 1.05rem;
  line-height: 1.6;
}
main { max-width: 880px; margin: 0 auto; padding: 0 1.25rem 4rem; }
section { scroll-margin-top: calc(var(--topbar-h) + 12px); padding-top: 2.5rem; }
h1, h2 { font-family: "Fraunces", Georgia, serif; line-height: 1.12; letter-spacing: -0.01em; }
h1 { font-size: clamp(2rem, 5.2vw, 3.1rem); font-weight: 900; margin: 0.6rem 0 1.5rem; max-width: 16em; }
h2 { font-size: clamp(1.5rem, 3.6vw, 2rem); font-weight: 600; margin: 0 0 1rem; }
h3 { font-size: 1.1rem; margin: 1.6rem 0 0.4rem; }
p { margin: 0 0 1rem; max-width: 62ch; }
a { color: var(--field); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

/* ---------- topbar (house pattern) ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 0.9rem;
  height: var(--topbar-h); padding: 0 1rem;
  background: var(--card); border-bottom: 1px solid var(--line);
  font-size: 0.95rem; white-space: nowrap;
}
.topbar .home { color: var(--ink); text-decoration: none; font-weight: 700; }
.topnav { display: flex; gap: 0.9rem; overflow-x: auto; scrollbar-width: none; }
.topnav::-webkit-scrollbar { display: none; }
.topnav a { color: var(--muted); text-decoration: none; }
.topnav a[aria-current="true"] { color: var(--ink); font-weight: 700; }
.topbar .spacer { flex: 1; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); background: transparent; color: var(--ink);
  cursor: pointer; flex: none;
}
.icon-btn svg { display: block; }
.icon-btn svg[hidden] { display: none; }

/* ---------- hero ---------- */
.hero { padding-top: 3rem; }
.dateline {
  font-family: "IBM Plex Mono", monospace; font-size: 0.8rem;
  color: var(--muted); margin: 0; max-width: none;
}
.ledger-answer {
  display: flex; gap: 1.5rem; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 1.5rem 1.75rem; margin: 0 0 1.5rem;
}
.ledger-num {
  font-family: "Fraunces", serif; font-weight: 900;
  font-size: clamp(4.5rem, 12vw, 7rem); line-height: 1; color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.ledger-main { font-size: 1.25rem; margin: 0 0 0.5rem; }
.ledger-sub { color: var(--muted); margin: 0 0 0.5rem; font-size: 1rem; }
.deck { font-size: 1.15rem; }
.hero-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1.25rem; }
.btn {
  display: inline-block; padding: 0.65rem 1.3rem; border-radius: 8px;
  background: var(--accent); color: #fff; text-decoration: none; font-weight: 700;
  border: 1px solid var(--accent); cursor: pointer; font-size: 1rem;
}
[data-theme="dark"] .btn { color: #101915; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
[data-theme="dark"] .btn-ghost { color: var(--ink); }
button.btn { font-family: inherit; }

/* ---------- anatomy tree ---------- */
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { margin: 0.5rem 0 0.5rem 0.4rem; padding-left: 1.1rem; border-left: 2px solid var(--line); }
.tree li { margin: 0 0 0.6rem; max-width: 68ch; }
.tree li:last-child { margin-bottom: 0; }
.t-num { font-family: "IBM Plex Mono", monospace; font-weight: 600; color: var(--accent); white-space: nowrap; }
a .t-num { text-decoration: underline; }

/* ---------- explorer ---------- */
.x-controls { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.x-field { margin: 0; min-width: 220px; flex: 1; }
.x-field label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.25rem; }
.x-field select {
  width: 100%; padding: 0.65rem 0.9rem; font-size: 1rem; min-height: 44px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--ink); font-family: inherit;
}
.x-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-top: 1rem; }
.x-cols h3 { margin-top: 0; }
.x-list {
  list-style: none; margin: 0; padding: 0; max-height: 480px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 8px; background: var(--card);
}
.x-list li { border-bottom: 1px solid var(--line); }
.x-list li:last-child { border-bottom: none; }
.x-list button {
  display: block; width: 100%; text-align: left; padding: 0.55rem 0.8rem;
  background: none; border: none; cursor: pointer; font-family: inherit;
  font-size: 0.95rem; color: var(--ink); min-height: 44px;
}
.x-list button:hover { background: var(--row-hi); }
.x-list button[aria-current="true"] { background: var(--accent-soft); font-weight: 700; }
.x-list .x-sub { display: block; font-size: 0.82rem; color: var(--muted); font-weight: 400; }
.x-group { margin: 0 0 1rem; }
.x-group h4 { font-size: 0.95rem; margin: 0 0 0.35rem; }
.x-group ul { list-style: none; margin: 0; padding: 0; columns: 2; column-gap: 1.5rem; }
.x-group li {
  font-size: 0.92rem; padding: 0.15rem 0; break-inside: avoid;
  border-bottom: 1px dotted var(--line);
}
.x-total { font-family: "IBM Plex Mono", monospace; font-size: 0.9rem; color: var(--muted); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -1.25rem; padding: 0 1.25rem; }
table.ledger { border-collapse: collapse; width: 100%; font-size: 0.95rem; background: var(--card); line-height: 1.35; }
table.ledger caption { text-align: left; padding: 0.5rem 0; color: var(--muted); font-size: 0.85rem; }
table.ledger th, table.ledger td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--line); }
table.ledger thead th {
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted);
  border-bottom: 2px solid var(--line); white-space: nowrap;
}
table.ledger .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.ledger tbody tr:hover { background: var(--row-hi); }
table.ledger .num .num { font-family: "IBM Plex Mono", monospace; }
table.ledger tr.total th, table.ledger tr.total td {
  border-top: 2px solid var(--line); border-bottom: none; font-weight: 700;
}
.verdict-ok { color: var(--ok); font-weight: 700; }
.verdict-bad { color: var(--bad); font-weight: 700; }
.verdict-mid { color: var(--mid); font-weight: 700; }
.table-note { color: var(--muted); font-size: 0.9rem; }

/* ---------- search ---------- */
#search-form { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 0.5rem; }
#search-form label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
#search-input {
  flex: 1; min-width: 220px; padding: 0.65rem 0.9rem; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--ink); font-family: inherit;
}
.examples { color: var(--muted); font-size: 0.95rem; }

/* ---------- prose sections ---------- */
.explainer p, .method li { max-width: 62ch; }
.method ul { padding-left: 1.25rem; }
.method li { margin-bottom: 0.6rem; }

/* ---------- footer ---------- */
footer { border-top: 1px solid var(--line); padding: 1.5rem 1.25rem 3rem; text-align: center; color: var(--muted); font-size: 0.9rem; }
footer p { margin: 0 auto; }

@media (max-width: 640px) {
  .x-cols { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .topbar { font-size: 0.85rem; gap: 0.6rem; padding: 0 0.75rem; }
  .topnav { gap: 0.6rem; }
  .ledger-answer { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .table-wrap table.ledger { font-size: 0.88rem; }
  table.ledger th, table.ledger td { padding: 0.45rem 0.5rem; }
  .x-group ul { columns: 1; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
