:root {
  --bg: #f7f4ee;
  --surface: #ffffff;
  --surface-2: #efeae1;
  --text: #1f2421;
  --muted: #6b6f6a;
  --line: #e2ddd3;
  --accent: #2f5d50;
  --accent-soft: #dfeae5;
  --accent-ink: #1d3f36;
  --mark: #ffe58a;
  --shadow: 0 1px 2px rgba(30, 30, 20, .05), 0 8px 24px -16px rgba(30, 30, 20, .25);
  --radius: 14px;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --topbar: 64px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181a;
    --surface: #1d2124;
    --surface-2: #23282c;
    --text: #e8e6e1;
    --muted: #9a9e99;
    --line: #2e3438;
    --accent: #8fc3b2;
    --accent-soft: #24352f;
    --accent-ink: #b9dccf;
    --mark: #7a6414;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -16px rgba(0, 0, 0, .6);
  }
}
:root[data-theme="dark"] {
  --bg: #15181a;
  --surface: #1d2124;
  --surface-2: #23282c;
  --text: #e8e6e1;
  --muted: #9a9e99;
  --line: #2e3438;
  --accent: #8fc3b2;
  --accent-soft: #24352f;
  --accent-ink: #b9dccf;
  --mark: #7a6414;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--topbar) + 76px); }
@media (max-width: 900px) { html { scroll-padding-top: calc(var(--topbar) + 12px); } }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }
code { font-size: .9em; background: var(--surface-2); padding: .1em .4em; border-radius: 6px; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 .1em; }

.skip {
  position: absolute; left: -999px; top: 8px; background: var(--accent); color: #fff; padding: 8px 12px; border-radius: 8px; z-index: 100;
}
.skip:focus { left: 8px; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; height: 100%;
  padding: 0 16px;
  display: flex; align-items: center; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; border: 0; background: none; padding: 0; cursor: pointer; color: var(--text); white-space: nowrap; }
.brand-mark {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-display); font-weight: 700; font-size: 15px; letter-spacing: .04em;
  background: var(--accent); color: #fff; padding: 4px 10px; border-radius: 8px;
  transition: background .15s;
}
.brand:hover .brand-mark { background: var(--accent-ink); }
.brand-menu { display: none; width: 14px; height: 14px; stroke: #fff; stroke-width: 2; stroke-linecap: round; fill: none; }
.brand[aria-expanded="true"] .brand-mark { background: var(--accent-ink); }
.brand-text { font-weight: 600; }
.search {
  flex: 1; display: flex; align-items: center; gap: 8px;
  max-width: 520px; margin-left: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 0 12px; height: 40px;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-icon { width: 18px; height: 18px; stroke: var(--muted); fill: none; stroke-width: 2; stroke-linecap: round; flex: none; }
.search input { flex: 1; border: 0; background: transparent; outline: 0; font: inherit; color: var(--text); min-width: 0; }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.search kbd { font: 12px var(--font-body); color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 0 6px; }

/* ---------- Layout ---------- */
.layout { max-width: 1200px; margin: 0 auto; padding: 0 16px; display: grid; grid-template-columns: 272px minmax(0, 1fr); gap: 40px; }
.sidebar { position: sticky; top: var(--topbar); align-self: start; height: calc(100vh - var(--topbar)); overflow-y: auto; padding: 28px 12px 40px 0; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar-label { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 0 0 8px; }
.drawer-head { display: none; }
.sidebar-meta { font-size: 12px; color: var(--muted); margin: 20px 0 0; line-height: 1.5; }
.nav, .nav ol { list-style: none; margin: 0; padding: 0; }
.nav > li { margin-bottom: 6px; }
.nav a { display: flex; gap: 8px; padding: 5px 8px; border-radius: 8px; color: var(--text); text-decoration: none; font-size: 14px; line-height: 1.35; }
.nav a:hover { background: var(--surface-2); }
.nav a.is-current { background: var(--accent-soft); color: var(--accent-ink); }
.nav-part > a { font-weight: 600; }
.nav ol a { color: var(--muted); }
.nav ol a.is-current, .nav ol a:hover { color: var(--text); }
.nav ol li.is-hidden { display: none; }
.nav-num { flex: none; min-width: 2.2em; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; padding-top: 2px; }
.nav-part > a .nav-num { color: var(--accent); font-weight: 700; }

.content { padding: 28px 0 80px; min-width: 0; }

/* ---------- Hero ---------- */
.hero { padding: 24px 0 8px; }
.hero-kicker { color: var(--accent); font-weight: 600; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; margin: 0 0 8px; }
.hero h1 { font-family: var(--font-display); font-weight: 700; font-size: clamp(34px, 5vw, 52px); line-height: 1.05; margin: 0 0 8px; letter-spacing: -.01em; }
.hero-sub { font-size: 20px; color: var(--muted); margin: 0 0 24px; font-family: var(--font-display); font-weight: 500; }
.hero-intro { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px 28px; box-shadow: var(--shadow); }
.hero-intro > :first-child { margin-top: 0; }
.hero-intro > :last-child { margin-bottom: 0; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin: 28px 0 8px; position: sticky; top: var(--topbar); z-index: 10; background: var(--bg); padding: 10px 0; }
.filter { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.filter-label { font-size: 13px; color: var(--muted); margin-right: 4px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 14px; cursor: pointer; font-size: 14px; }
.chip:hover { border-color: var(--accent); }
.chip.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.toolbar-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 14px; cursor: pointer; font-size: 14px; }
.btn:hover { border-color: var(--accent); }
.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; }
.result-count { font-size: 13px; color: var(--muted); margin: 4px 0 0; min-height: 1.4em; }
.no-results { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 20px; color: var(--muted); }

/* ---------- Parts ---------- */
.part { margin-top: 44px; }
.part.is-hidden { display: none; }
.part-header { margin-bottom: 14px; }
.part-num { color: var(--accent); font-weight: 600; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; }
.part-header h2 { font-family: var(--font-display); font-weight: 700; font-size: clamp(26px, 3vw, 34px); margin: 2px 0 6px; line-height: 1.15; }
.part-header p { color: var(--muted); margin: 0; max-width: 62ch; }
.part-header blockquote { margin: 10px 0 0; }
.chapters { display: grid; gap: 10px; }

/* ---------- Chapters (details) ---------- */
.chapter { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.chapter.is-hidden { display: none; }
.chapter[open] { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.chapter summary {
  list-style: none; cursor: pointer;
  display: grid; grid-template-columns: auto 1fr auto auto; grid-template-areas: "num title ages chev" "num teaser ages chev";
  column-gap: 14px; row-gap: 2px; align-items: center;
  padding: 16px 18px;
}
.chapter summary::-webkit-details-marker { display: none; }
.chapter summary:hover { background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); }
.ch-num { grid-area: num; align-self: start; font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 700; font-size: 14px; padding-top: 3px; min-width: 2.4em; }
.ch-title { grid-area: title; font-weight: 600; font-size: 17px; line-height: 1.3; }
.ch-teaser { grid-area: teaser; color: var(--muted); font-size: 14px; line-height: 1.4; }
.chapter[open] .ch-teaser { display: none; }
.ch-ages { grid-area: ages; display: flex; gap: 4px; }
.age-tag { font-size: 11px; font-weight: 600; background: var(--accent-soft); color: var(--accent-ink); border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.ch-chevron { grid-area: chev; width: 10px; height: 10px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .2s; margin-right: 4px; }
.chapter[open] .ch-chevron { transform: rotate(-135deg); }
.ch-body { padding: 4px 18px 20px calc(18px + 2.4em + 14px); border-top: 1px solid var(--line); position: relative; }
.ch-body > :first-child { margin-top: 16px; }
.ch-body h3 { font-size: 15px; text-transform: uppercase; letter-spacing: .05em; color: var(--accent-ink); margin: 22px 0 6px; }
.ch-body h3 + p { margin-top: 0; }
.ch-body p { margin: 10px 0; max-width: 68ch; }
.ch-body ul, .ch-body ol { padding-left: 1.4em; margin: 8px 0; max-width: 68ch; }
.ch-body li { margin: 3px 0; }
.ch-body li::marker { color: var(--accent); }
.ch-body table { border-collapse: collapse; width: 100%; max-width: 68ch; margin: 12px 0; font-size: 15px; }
.ch-body th, .ch-body td { border: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.ch-body th { background: var(--surface-2); font-weight: 600; }
.ch-link { position: absolute; right: 16px; bottom: 10px; font-size: 12px; color: var(--muted); text-decoration: none; opacity: 0; transition: opacity .2s; }
.chapter:hover .ch-link { opacity: 1; }

blockquote {
  margin: 14px 0; padding: 12px 18px;
  border-left: 3px solid var(--accent); background: var(--accent-soft);
  border-radius: 0 10px 10px 0; max-width: 68ch;
  font-family: var(--font-display); font-size: 1.08em; line-height: 1.45;
}
blockquote p { margin: 6px 0; }
blockquote strong { font-weight: 700; color: var(--accent-ink); }

/* ---------- Til print ---------- */
.print-label { margin-top: 22px; }
.print-links { list-style: none; margin: 0; padding: 0; }
.print-links a { display: block; padding: 6px 8px; border-radius: 8px; color: var(--text); text-decoration: none; font-size: 14px; font-weight: 500; }
.print-links a:hover { background: var(--surface-2); }
.print-links a span { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.print-cards { margin-top: 56px; }
.print-cards h2 { font-family: var(--font-display); font-weight: 700; font-size: clamp(26px, 3vw, 34px); margin: 0 0 12px; }
.print-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.print-card { display: grid; grid-template-columns: auto 1fr; grid-template-areas: "icon title" "icon desc"; column-gap: 14px; row-gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; color: var(--text); text-decoration: none; }
.print-card:hover { border-color: var(--accent); }
.print-icon { grid-area: icon; font-size: 26px; align-self: start; }
.print-title { grid-area: title; font-weight: 600; font-size: 17px; }
.print-desc { grid-area: desc; color: var(--muted); font-size: 14px; }
.footer { margin-top: 60px; padding-top: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.footer p { margin: 4px 0; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; gap: 0; }
  .brand-text { display: none; }
  .brand-menu { display: block; }
  .search kbd { display: none; }
  .sidebar { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: var(--bg); z-index: 60; height: auto; padding: 0 16px 24px; overflow-y: auto; }
  .sidebar.is-open { display: block; }
  .drawer-head { display: flex; align-items: center; gap: 10px; height: var(--topbar); position: sticky; top: 0; background: var(--bg); border-bottom: 1px solid var(--line); margin: 0 0 12px; }
  .drawer-title { font-weight: 600; flex: 1; }
  .drawer-close { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; width: 36px; height: 36px; cursor: pointer; font-size: 14px; line-height: 1; }
  .sidebar-label { display: none; }
  .sidebar-label.print-label { display: block; }
  body.nav-open { overflow: hidden; }
  .toolbar { position: static; }
  .chapter summary { grid-template-columns: auto 1fr auto; grid-template-areas: "num title chev" "num teaser chev" "num ages chev"; }
  .ch-ages { margin-top: 4px; }
  .ch-body { padding-left: 18px; }
  .hero-intro { padding: 18px; }
}

/* ---------- Print ---------- */
@media print {
  .topbar, .sidebar, .toolbar, .result-count, .no-results, .ch-link, .ch-chevron, .skip { display: none !important; }
  .layout { display: block; max-width: none; padding: 0; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .chapter { break-inside: avoid; box-shadow: none; border-color: #bbb; }
  .chapter .ch-body { display: block !important; }
  .chapter summary { padding: 10px 12px; }
  .ch-teaser { display: none; }
  .part { break-before: page; margin-top: 0; }
  .part:first-of-type { break-before: auto; }
  blockquote { background: #f0f0f0; }
  mark { background: none; font-weight: 600; }
}
