:root {
  --bg: #f6f3ec;
  --paper: #fffdf8;
  --ink: #23201b;
  --ink-soft: #5b554a;
  --rule: #e3dccd;
  --accent: #7b5e3b;
  --accent-soft: #b89b6f;
  --proven: #2f7d4f;
  --plausible: #b8860b;
  --contemplative: #6a4c93;
  --sidebar-w: 320px;
  --measure: 38rem;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Fraunces", Georgia, "Times New Roman", serif;
  font-size: 1.12rem;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Sidebar ---------- */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  overflow-y: auto;
  background: #2a2620;
  color: #e8e1d3;
  padding: 2.2rem 1.6rem 3rem;
  border-right: 1px solid #1d1a15;
}

.sidebar-head { margin-bottom: 1.6rem; }

.brand {
  display: block;
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1.2;
  color: #f4ecdc;
  text-decoration: none;
  letter-spacing: 0.01em;
}

.brand-sub {
  margin: 0.5rem 0 0;
  font-family: "Inter", system-ui, sans-serif;
  font-size: 0.82rem;
  font-style: italic;
  color: #b7ad99;
  line-height: 1.4;
}

.toc ol {
  list-style: none;
  counter-reset: toc;
  margin: 0;
  padding: 0;
}

.toc li {
  counter-increment: toc;
  margin: 0.15rem 0;
}

.toc a {
  display: block;
  padding: 0.4rem 0.6rem 0.4rem 2.2rem;
  position: relative;
  color: #cfc6b4;
  text-decoration: none;
  font-family: "Inter", system-ui, sans-serif;
  font-size: 0.9rem;
  line-height: 1.35;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}

.toc a::before {
  content: counter(toc) ".";
  position: absolute;
  left: 0.6rem;
  color: var(--accent-soft);
  font-variant-numeric: tabular-nums;
}

.toc a:hover { background: #38332b; color: #fff; }
.toc li.active a { background: var(--accent); color: #fff; }
.toc li.active a::before { color: #f0e2c8; }

/* ---------- Main ---------- */
main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 2rem;
}

.page {
  background: var(--paper);
  width: 100%;
  max-width: calc(var(--measure) + 6rem);
  margin: 3.5rem 0 0;
  padding: 4rem 3rem 3rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  box-shadow: 0 1px 2px rgba(40, 30, 10, 0.04), 0 12px 40px rgba(40, 30, 10, 0.06);
}

.page > * { max-width: var(--measure); margin-left: auto; margin-right: auto; }

h1, h2, h3, h4 {
  line-height: 1.2;
  font-weight: 600;
  color: var(--ink);
}

h1 {
  font-size: 2.3rem;
  margin: 0 0 1.6rem;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 1.6rem;
  margin: 2.8rem auto 1rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--rule);
}

h3 { font-size: 1.25rem; margin: 2rem auto 0.6rem; color: var(--accent); }
h4 { font-size: 1.05rem; margin: 1.6rem auto 0.4rem; font-style: italic; }

p { margin: 0 auto 1.2rem; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }

blockquote {
  margin: 1.8rem auto;
  padding: 0.4rem 0 0.4rem 1.4rem;
  border-left: 3px solid var(--accent-soft);
  color: var(--ink-soft);
  font-style: italic;
}

blockquote p:last-child { margin-bottom: 0; }

ul, ol { margin: 0 auto 1.3rem; padding-left: 1.4rem; max-width: var(--measure); }
li { margin: 0.35rem 0; }

hr { border: none; border-top: 1px solid var(--rule); margin: 2.6rem auto; max-width: var(--measure); }

code {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: #efe9dc;
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

pre {
  max-width: var(--measure);
  margin: 1.5rem auto;
  background: #2a2620;
  color: #e8e1d3;
  padding: 1.1rem 1.3rem;
  border-radius: 8px;
  overflow-x: auto;
  line-height: 1.5;
}
pre code { background: none; color: inherit; font-size: 0.82rem; }

table {
  width: 100%;
  max-width: var(--measure);
  margin: 1.6rem auto;
  border-collapse: collapse;
  font-family: "Inter", system-ui, sans-serif;
  font-size: 0.92rem;
}
th, td { text-align: left; padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { background: #efe9dc; font-weight: 600; }

/* ---------- Evidence labels ---------- */
.label {
  display: inline-block;
  font-family: "Inter", system-ui, sans-serif;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.12em 0.5em;
  border-radius: 999px;
  vertical-align: middle;
  color: #fff;
}
.label-proven { background: var(--proven); }
.label-plausible { background: var(--plausible); }
.label-contemplative { background: var(--contemplative); }

.label-group { margin-right: 0.5rem; }
.label-group .label + .label { margin-left: 0.25rem; }

/* ---------- Chapter nav ---------- */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin: 3.5rem auto 0;
  padding-top: 1.6rem;
  border-top: 1px solid var(--rule);
  max-width: var(--measure);
  font-family: "Inter", system-ui, sans-serif;
  font-size: 0.9rem;
}
.chapter-nav a { text-decoration: none; color: var(--accent); font-weight: 500; }
.chapter-nav a:hover { color: var(--ink); }
.nav-top { color: var(--ink-soft) !important; }

.site-footer {
  max-width: calc(var(--measure) + 6rem);
  width: 100%;
  margin: 2rem 0 3rem;
  padding: 0 3rem;
  font-family: "Inter", system-ui, sans-serif;
  font-size: 0.78rem;
  color: var(--ink-soft);
}
.site-footer .label { font-size: 0.55rem; }

/* ---------- Home / cover ---------- */
body.home .page { text-align: center; padding-top: 5rem; }
body.home .page > * { margin-left: auto; margin-right: auto; }
body.home h1 { font-size: 3rem; }
body.home .toc { text-align: left; }

#menu-toggle {
  display: none;
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 50;
  background: #2a2620;
  color: #f4ecdc;
  border: none;
  border-radius: 8px;
  width: 44px;
  height: 44px;
  font-size: 1.3rem;
  cursor: pointer;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  #menu-toggle { display: block; }
  #sidebar { transform: translateX(-100%); transition: transform 0.25s ease; z-index: 40; box-shadow: 0 0 40px rgba(0,0,0,0.4); }
  body.menu-open #sidebar { transform: translateX(0); }
  main { margin-left: 0; padding: 0 1rem; }
  .page { padding: 3rem 1.3rem 2rem; margin-top: 4.5rem; }
  .site-footer { padding: 0 1.3rem; }
  body.home h1 { font-size: 2.2rem; }
}
