/* ============================================================
   The Compost Almanac — Design System
   ============================================================ */
:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --ink: #23281f;
  --ink-soft: #4c5544;
  --ink-faint: #7a8272;
  --line: #e3ded1;
  --accent: #3e6b34;
  --accent-deep: #2c4d25;
  --accent-soft: #e7efe0;
  --amber: #a9681f;
  --amber-soft: #f6ead6;
  --terra: #9c4424;
  --terra-soft: #f6e3da;
  --blue: #2f5d7c;
  --blue-soft: #e0ebf2;
  --radius: 14px;
  --radius-sm: 8px;
  --maxw: 1180px;
  --serif: Georgia, "Times New Roman", serif;
  --sans: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  --mono: "Cascadia Code", Consolas, monospace;
  --shadow: 0 1px 2px rgba(35, 40, 31, .06), 0 8px 24px rgba(35, 40, 31, .07);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
/* keep deep-linked headings clear of the sticky header */
h2, h3, h4, .fig, table { scroll-margin-top: calc(var(--header-h, 72px) + 18px); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 16.5px;
  line-height: 1.65;
  color: var(--ink);
  background:
    radial-gradient(1200px 400px at 80% -100px, #edf2e4 0%, transparent 60%),
    var(--bg);
}

/* ---------- Header & nav ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(246, 244, 238, .92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.navbar {
  max-width: var(--maxw); margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 18px; min-height: 62px;
}
.brand {
  font-family: var(--serif); font-weight: 700; font-size: 1.25rem;
  color: var(--accent-deep); text-decoration: none; white-space: nowrap;
}
.brand .leaf { color: var(--accent); }
.nav-links { display: flex; gap: 2px; flex-wrap: wrap; margin-left: auto; flex-shrink: 0; }
.nav-links a {
  padding: 8px 11px; border-radius: 8px; text-decoration: none;
  color: var(--ink-soft); font-size: .92rem; font-weight: 500;
}
.nav-links a:hover { background: var(--accent-soft); color: var(--accent-deep); }
.nav-links a.active { background: var(--accent); color: #fff; }
.nav-toggle { display: none; margin-left: auto; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font-size: 1rem; cursor: pointer; color: var(--ink); }

/* ---------- Layout ---------- */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }
.page { padding: 38px 20px 90px; max-width: 1180px; margin: 0 auto; }
.narrow { max-width: 860px; }
.grid { display: grid; gap: 22px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- Hero ---------- */
.hero {
  padding: 64px 20px 56px;
  background: linear-gradient(160deg, #223a1c 0%, #2c4d25 55%, #3e6b34 100%);
  color: #f2f5ec;
  position: relative; overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(600px 300px at 15% 120%, rgba(169, 104, 31, .25), transparent 60%),
    radial-gradient(500px 260px at 90% -20%, rgba(255, 255, 255, .07), transparent 60%);
}
.hero .wrap { position: relative; z-index: 1; }
.hero h1 { font-family: var(--serif); font-size: clamp(2rem, 4.6vw, 3.3rem); margin: 0 0 14px; line-height: 1.12; }
.hero p.lede { font-size: 1.12rem; max-width: 720px; color: #d9e2cf; margin: 0 0 26px; }
.hero .kicker { text-transform: uppercase; letter-spacing: .14em; font-size: .78rem; color: #b9cba6; font-weight: 600; margin-bottom: 12px; }
.btn {
  display: inline-block; padding: 11px 22px; border-radius: 999px;
  text-decoration: none; font-weight: 600; font-size: .95rem; border: none; cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: #d8e6c4; color: #223a1c; }
.btn-ghost { background: rgba(255,255,255,.12); color: #f2f5ec; border: 1px solid rgba(255,255,255,.35); margin-left: 10px; }
.btn-accent { background: var(--accent); color: #fff; }

/* ---------- Typography ---------- */
h1.page-title { font-family: var(--serif); font-size: 2.3rem; margin: 0 0 8px; color: var(--accent-deep); }
.page-sub { color: var(--ink-faint); font-size: 1.05rem; margin: 0 0 34px; max-width: 760px; }
h2 { font-family: var(--serif); font-size: 1.62rem; color: var(--accent-deep); margin: 2.4em 0 .55em; line-height: 1.25; }
h2:first-child { margin-top: 0; }
h3 { font-size: 1.18rem; color: var(--ink); margin: 1.7em 0 .45em; }
h4 { font-size: 1rem; color: var(--ink-soft); margin: 1.4em 0 .35em; text-transform: uppercase; letter-spacing: .04em; }
p { margin: .7em 0; }
a { color: var(--accent); }
a:hover { color: var(--accent-deep); }
ul, ol { padding-left: 1.4em; }
li { margin: .32em 0; }
strong { color: var(--accent-deep); }
.anchor { color: var(--accent); text-decoration: none; opacity: 0; margin-left: 6px; font-size: .85em; }
h2:hover .anchor, h3:hover .anchor { opacity: .7; }
.divider { border: none; border-top: 1px solid var(--line); margin: 44px 0; }
.footnote { font-size: .85rem; color: var(--ink-faint); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px 24px; box-shadow: var(--shadow);
}
.card h3 { margin-top: 0; }
.card-grid a.card { text-decoration: none; display: block; color: inherit; transition: transform .12s ease, border-color .12s ease; }
.card-grid a.card:hover { transform: translateY(-3px); border-color: var(--accent); }
.card .icon { font-size: 1.6rem; display: block; margin-bottom: 8px; }
.card .tagline { color: var(--ink-faint); font-size: .88rem; }
.card ul { margin: .5em 0 0; padding-left: 1.1em; font-size: .93rem; color: var(--ink-soft); }

/* ---------- Callouts ---------- */
.callout {
  border-left: 4px solid var(--accent); background: var(--accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 14px 18px; margin: 1.4em 0; font-size: .97rem;
}
.callout.amber { border-color: var(--amber); background: var(--amber-soft); }
.callout.terra { border-color: var(--terra); background: var(--terra-soft); }
.callout.blue { border-color: var(--blue); background: var(--blue-soft); }
.callout .co-label { font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-soft); display: block; margin-bottom: 4px; }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; margin: 1.4em 0; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .92rem; min-width: 560px; }
th { background: #eef0e4; text-align: left; padding: 10px 14px; font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); border-bottom: 2px solid var(--line); }
td { padding: 9px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #faf9f3; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.good { color: var(--accent); font-weight: 600; }
.warn { color: var(--amber); font-weight: 600; }
.bad { color: var(--terra); font-weight: 600; }

/* ---------- Definition lists / glossary ---------- */
dl.defs dt { font-weight: 700; color: var(--accent-deep); margin-top: 1em; }
dl.defs dd { margin: .2em 0 .6em; color: var(--ink-soft); }

/* ---------- Stat band ---------- */
.stat-band { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; margin: 34px 0; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; text-align: center; }
.stat .num { font-family: var(--serif); font-size: 1.9rem; font-weight: 700; color: var(--accent); display: block; }
.stat .lbl { font-size: .82rem; color: var(--ink-faint); }

/* ---------- Range inputs ---------- */
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="number"], input[type="text"], select {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: #fff; color: var(--ink); width: 100%;
}
input[type="number"]:focus, input[type="text"]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
label { font-size: .88rem; font-weight: 600; color: var(--ink-soft); display: block; margin-bottom: 4px; }
.calc-row { display: grid; grid-template-columns: 1.2fr 80px 110px 110px 36px; gap: 10px; align-items: center; margin-bottom: 10px; font-size: .92rem; }
.calc-row.header-row { grid-template-columns: 1.2fr 80px 110px 110px 36px; }
.calc-row .cname { font-weight: 600; }
.calc-output { background: var(--accent-soft); border: 1px solid var(--accent); border-radius: var(--radius); padding: 18px 22px; margin-top: 16px; }
.calc-output .big { font-family: var(--serif); font-size: 1.7rem; font-weight: 700; color: var(--accent-deep); }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 700; }
.pill.good { background: var(--accent-soft); }
.pill.warn { background: var(--amber-soft); }
.pill.bad { background: var(--terra-soft); }
.meter { height: 10px; border-radius: 999px; background: #e9e6da; overflow: hidden; margin: 6px 0; }
.meter > div { height: 100%; border-radius: 999px; background: var(--accent); transition: width .25s ease; }

/* ---------- Search ---------- */
.search-box { position: relative; width: 100%; max-width: 420px; }
.navbar > .search-box { flex: 1 1 300px; min-width: 190px; }

/* Mid-width laptops: tighten the nav so the header stays on one row,
   letting the search box take the remaining space instead of wrapping. */
@media (max-width: 1340px) {
  .nav-links a { padding: 8px 8px; font-size: .88rem; }
  .brand { font-size: 1.12rem; }
}
.search-box input { padding: 9px 14px 9px 38px; border-radius: 999px; border: 1px solid var(--line); background: #fff; }
.search-box::before { content: "🔍"; position: absolute; left: 13px; top: 50%; transform: translateY(-50%); font-size: .85rem; opacity: .6; }
.search-results {
  position: absolute; top: 110%; right: 0; left: auto; background: #fff; border: 1px solid var(--line);
  width: min(440px, 90vw); border-radius: var(--radius-sm); box-shadow: var(--shadow);
  max-height: 420px; overflow-y: auto; display: none; z-index: 60;
}
.search-results.open { display: block; }
.search-results a { display: block; padding: 10px 14px; text-decoration: none; border-bottom: 1px solid var(--line); }
.search-results a:last-child { border-bottom: none; }
.search-results a:hover,
.search-results a[aria-selected="true"] { background: var(--accent-soft); }
.search-results .sr-title { font-weight: 700; color: var(--ink); font-size: .93rem; }
.search-results .sr-snippet { font-size: .82rem; color: var(--ink-faint); }
.search-results .sr-empty { padding: 11px 14px; font-size: .86rem; color: var(--ink-faint); }
mark { background: #f2e6b8; padding: 0 2px; border-radius: 3px; }

/* ---------- TOC sidebar ---------- */
.with-toc { display: grid; grid-template-columns: 240px 1fr; gap: 44px; }
/* Grid children default to min-width:auto, which lets a wide table (or figure) push the
   whole page sideways instead of scrolling inside its own box. */
.with-toc > * { min-width: 0; }
.toc { position: sticky; top: 86px; align-self: start; font-size: .9rem; max-height: calc(100vh - 110px); overflow-y: auto; }
.toc .toc-title { font-weight: 700; text-transform: uppercase; letter-spacing: .07em; font-size: .74rem; color: var(--ink-faint); margin-bottom: 8px; }
.toc a { display: block; padding: 4px 10px; color: var(--ink-soft); text-decoration: none; border-left: 2px solid var(--line); }
.toc a:hover { color: var(--accent-deep); border-left-color: var(--accent); }
.toc a.toc-current { color: var(--accent-deep); border-left-color: var(--accent); font-weight: 700; }
@media (max-width: 950px) {
  .with-toc { grid-template-columns: 1fr; }
  .toc { position: static; max-height: none; display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; }
  .toc .toc-title { width: 100%; }
  .toc a { border: 1px solid var(--line); border-radius: 999px; padding: 3px 12px; }
  .toc a.toc-current { border-color: var(--accent); background: var(--accent-soft); }
}

/* ---------- Accordion ---------- */
details.acc { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); margin-bottom: 10px; }
details.acc summary { cursor: pointer; padding: 13px 18px; font-weight: 600; color: var(--ink); list-style: none; display: flex; justify-content: space-between; align-items: center; }
details.acc summary::after { content: "+"; color: var(--accent); font-weight: 700; font-size: 1.1rem; }
details.acc[open] summary::after { content: "–"; }
details.acc summary:hover { background: var(--accent-soft); border-radius: var(--radius-sm); }
details.acc .acc-body { padding: 4px 18px 16px; color: var(--ink-soft); font-size: .95rem; }

/* ---------- Timeline / phases ---------- */
.phase { display: grid; grid-template-columns: 130px 1fr; gap: 18px; padding: 18px 0; border-bottom: 1px dashed var(--line); }
.phase:last-child { border-bottom: none; }
.phase .ph-time { font-family: var(--serif); font-weight: 700; color: var(--amber); font-size: 1.02rem; }
.phase .ph-time small { display: block; font-family: var(--sans); font-weight: 500; color: var(--ink-faint); font-size: .78rem; }
@media (max-width: 640px) { .phase { grid-template-columns: 1fr; gap: 4px; } }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--line); background: #eceadf; padding: 34px 20px; margin-top: 40px; }
.site-footer .wrap { display: flex; flex-wrap: wrap; gap: 24px; justify-content: space-between; align-items: flex-start; }
.site-footer p { font-size: .85rem; color: var(--ink-faint); margin: 0; }
.footer-links { display: flex; gap: 16px; flex-wrap: wrap; font-size: .88rem; }
.footer-links a { color: var(--ink-soft); text-decoration: none; }
.footer-links a:hover { color: var(--accent-deep); text-decoration: underline; }

/* ---------- Misc ---------- */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chip { background: var(--accent-soft); color: var(--accent-deep); border-radius: 999px; padding: 4px 13px; font-size: .82rem; font-weight: 600; }
.chip.neutral { background: #edeade; color: var(--ink-soft); }
.kbd { font-family: var(--mono); font-size: .8rem; background: #eceadf; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; }
.small-caps { font-variant: small-caps; letter-spacing: .04em; }
.breadcrumb { font-size: .84rem; color: var(--ink-faint); margin-bottom: 18px; }
.breadcrumb a { color: var(--ink-faint); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent); }
.prev-next { display: flex; justify-content: space-between; gap: 14px; margin-top: 60px; }
.prev-next a { text-decoration: none; flex: 1; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; }
.prev-next a:hover { border-color: var(--accent); }
.prev-next .pn-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-faint); display: block; }
.prev-next .pn-title { font-weight: 700; color: var(--accent-deep); }

@media (max-width: 1060px) {
  .nav-toggle { display: block; }
  .nav-links {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    background: var(--surface); border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow);
    flex-direction: column; padding: 10px 16px; margin: 0;
  }
  .nav-links.open { display: flex; }
  .search-box { max-width: none; margin-top: 10px; width: 100%; }
  .navbar { flex-wrap: wrap; padding-bottom: 10px; }
  .navbar > .search-box { flex: 1 1 100%; }
}
/* ---------- Print / PDF ---------- */
.print-btn { background: var(--surface); color: var(--accent-deep); border: 1px solid var(--accent); }
.print-btn:hover { background: var(--accent-soft); }
@media print {
  .site-header, .site-footer, .toc, .prev-next, .search-box, .no-print, .nav-toggle { display: none !important; }
  .breadcrumb { display: none; }
  body { background: #fff; color: #000; font-size: 11pt; line-height: 1.5; }
  .page { max-width: 100%; padding: 0; margin: 0; }
  .with-toc { display: block; }
  .page-title { font-size: 20pt; color: #000; }
  h1, h2, h3, h4 { break-after: avoid; }
  .callout, table, .card, .phase, .stat, .calc-output, details.acc, .fig { break-inside: avoid; }
  details.acc { display: block; border: 1px solid #ccc; }
  details.acc summary::after { content: ""; }
  details.acc .acc-body { display: block !important; padding: 0 18px 14px; }
  a { color: inherit; text-decoration: none; }
  .gterm .gloss-tip { display: none; }
  .stat-band { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
}

/* ---------- Misc ---------- */
.bad-row td { background: #fdf3ee; color: var(--terra); }
#rate-calc h4, #calc-rows ~ h4 { margin: 0 0 10px; }
#rate-calc input[type="number"], #rate-calc select { padding: 7px 9px; }

/* ---------- Figures, charts & illustrations ---------- */
.fig { margin: 1.8em 0; }
.fig img { display: block; width: 100%; height: auto; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); }
.fig figcaption { font-size: .84rem; color: var(--ink-faint); margin-top: 9px; }
.fig figcaption strong { color: var(--ink-soft); }
.fig-grid { display: grid; gap: 22px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); align-items: start; }
/* On phones the dense charts would render at unreadable sizes, so let them keep a floor
   width and scroll sideways instead of shrinking to 4 px type. */
@media (max-width: 640px) {
  .fig { min-width: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .fig img { min-width: 520px; }
  .fig figcaption { min-width: 0; }
}
.card img { display: block; width: 100%; height: auto; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); margin-bottom: 12px; }
.diagram-card img { display: block; width: 100%; height: auto; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); }
/* ---------- Video (click-to-load YouTube facades) ----------
   Nothing is requested from YouTube until the reader presses play, so a normal page view
   stays third-party-free. The button is the whole poster: no remote thumbnail is fetched. */
.video { margin: 1.8em 0; }
.video-play { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 13px 16px; font: inherit; color: var(--ink); cursor: pointer; background: linear-gradient(135deg, #eef4ea, #f8f6ef); border: 1px solid var(--line); border-radius: var(--radius); transition: border-color .15s, box-shadow .15s, background .15s; }
.video-play:hover { border-color: var(--accent); background: linear-gradient(135deg, #e7efe0, #f4f8f0); box-shadow: var(--shadow); }
.video-play:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.video-glyph { flex: none; width: 42px; height: 42px; border-radius: 50%; background: var(--accent-deep); color: #fff; display: grid; place-items: center; font-size: 14px; line-height: 1; padding-left: 3px; }
.video-play:hover .video-glyph { background: var(--accent); }
.video-label { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.video-label strong { font-size: .97rem; line-height: 1.35; color: var(--accent-deep); }
.video-chan { font-size: .8rem; color: var(--ink-faint); }
.video-hint { margin-left: auto; flex: none; font-size: .7rem; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-faint); }
.video figcaption { font-size: .84rem; color: var(--ink-faint); margin-top: 9px; }
.video figcaption strong { color: var(--ink-soft); }
.video-embed { position: relative; aspect-ratio: 16 / 9; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: #10130d; }
.video-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
@media (max-width: 560px) {
  .video-hint { display: none; }
}
@media print {
  .fig img { border-color: #bbb; }
  .video-play { display: none; }
  .video { break-inside: avoid; }
}
