:root {
  --paper: #faf7f2;
  --surface: #ffffff;
  --ink: #1f1b16;
  --muted: #5c5346;
  --rule: #dfd7c8;
  --accent: #9a3412;
  --accent-soft: #fff7ed;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.72;
}

.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { position: fixed; left: 1rem; top: 1rem; background: var(--accent); color: #fff; padding: 0.5rem 0.9rem; z-index: 100; }

.folio-topbar {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  border-bottom: 1px solid var(--rule);
  font-family: system-ui, -apple-system, sans-serif;
}
.brand { text-decoration: none; color: var(--ink); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; font-size: 0.88rem; }

.theme-switcher { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; font-size: 0.82rem; }
.theme-switcher-label { color: var(--muted); }
.theme-list { display: flex; flex-wrap: wrap; gap: 0.35rem; list-style: none; margin: 0; padding: 0; }
.theme-list a, .xml-inspect-link {
  padding: 0.22rem 0.6rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  text-decoration: none;
  color: var(--ink);
  background: var(--surface);
}
.theme-list a.is-active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.folio-spread {
  background: var(--ink);
  color: var(--paper);
  padding: 3rem 1.5rem 2.5rem;
}
.folio-spread-inner, .folio-main, .folio-footer-inner {
  max-width: 960px;
  margin: 0 auto;
}
.folio-kicker {
  font-family: system-ui, -apple-system, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.78rem;
  color: #fdba74;
  margin: 0 0 0.65rem;
}
.page-title { margin: 0 0 0.75rem; font-size: 2.5rem; line-height: 1.15; font-weight: 700; }
.folio-deck { font-size: 1.2rem; color: #e7e0d6; max-width: 65ch; margin: 0 0 1.25rem; }
.folio-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.84rem;
  color: #d6cec2;
  margin-bottom: 1.25rem;
}
.folio-library summary {
  cursor: pointer;
  display: inline-block;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 0.88rem;
  padding: 0.45rem 0.85rem;
  border: 1px solid #575046;
  border-radius: 6px;
  background: #2b2620;
}
.folio-library-drawer {
  margin-top: 1rem;
  padding: 1.25rem;
  background: #27221d;
  border: 1px solid #443d34;
  border-radius: 8px;
  font-family: system-ui, -apple-system, sans-serif;
}
.site-nav {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1.25rem;
}
.nav-section-title { margin: 0 0 0.4rem; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: #fdba74; }
.site-nav ul { list-style: none; margin: 0; padding: 0; }
.site-nav li a { display: block; padding: 0.22rem 0; color: #f5efe6; text-decoration: none; font-size: 0.9rem; }
.site-nav li a.is-active { color: #fdba74; font-weight: 700; text-decoration: underline; }

.folio-main { padding: 2.5rem 1.5rem 3.5rem; }
.folio-prologue {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-left: 4px solid var(--accent);
  padding: 1.25rem 1.5rem;
  margin-bottom: 2rem;
}
.folio-chapter {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 1.5rem;
  padding: 2rem 0;
  border-top: 2px solid var(--ink);
}
.chapter-num {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}
.chapter-content h2 { margin-top: 0; font-size: 1.6rem; }
.chapter-content a { color: var(--accent); }
.chapter-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.86em;
  background: #efe9de;
  padding: 0.1rem 0.32rem;
  border-radius: 3px;
}
.chapter-content pre.code-block, .folio-prologue pre.code-block {
  background: #1f1b16;
  color: #f8f3eb;
  padding: 1rem 1.2rem;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.88rem;
}
.chapter-content pre.code-block code { background: transparent; color: inherit; padding: 0; }
.table-wrap { overflow-x: auto; margin: 1.25rem 0; }
table { width: 100%; border-collapse: collapse; font-family: system-ui, -apple-system, sans-serif; font-size: 0.9rem; background: var(--surface); }
th, td { border: 1px solid var(--rule); padding: 0.55rem 0.75rem; text-align: left; }
th { background: #efe9de; }
blockquote { margin: 1rem 0; padding: 0.65rem 1rem; border-left: 3px solid var(--accent); background: var(--accent-soft); }

.page-neighbors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  font-family: system-ui, -apple-system, sans-serif;
}
.page-neighbors a {
  overflow-wrap: anywhere;
  display: block;
  padding: 0.9rem 1rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  text-decoration: none;
  color: var(--ink);
}
.neighbor-next { text-align: right; }
.neighbor-dir { display: block; font-size: 0.75rem; text-transform: uppercase; color: var(--muted); }

.folio-footer { border-top: 1px solid var(--rule); background: #efe9de; padding: 2rem 1.5rem; }
.folio-chapter-index ol { columns: 2; padding-left: 1.25rem; }
.folio-chapter-index a { color: var(--ink); }
.folio-colophon { font-family: system-ui, -apple-system, sans-serif; font-size: 0.85rem; color: var(--muted); margin-top: 1.5rem; }

@media (max-width: 720px) {
  .folio-chapter { grid-template-columns: minmax(0, 1fr); gap: 0.5rem; }
  .folio-chapter-index ol { columns: 1; }
}
