@font-face {
  font-family: "Artful Dodger";
  src: url("/fonts/ArtfulDodger-Regular.otf") format("opentype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Artful Dodger";
  src: url("/fonts/ArtfulDodger-Italic.otf") format("opentype");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Retrokia Caps Rough";
  src: url("/fonts/RetrokiaCapsRough.otf") format("opentype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Marxiana Grotesque";
  src: url("/fonts/MarxianaGrotesque.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --body-font: "Artful Dodger", "Iowan Old Style", Georgia, serif;
  --heading-font: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --h2-font: "Retrokia Caps Rough", "Iowan Old Style", Georgia, serif;
  --h5-font: "Marxiana Grotesque", "Iowan Old Style", Georgia, sans-serif;
  /* Sticky-heading offsets: each level stacks below the prior. Each value is
     the *exact* rendered height of that heading when sticky, so backgrounds
     tile flush with no gap between levels. */
  --header-h: 3rem;
  --h1-stick-h: 2.4rem;
  --h2-stick-h: 1.8rem;
  --h3-stick-h: 1.5rem;
  --h4-stick-h: 1.4rem;
  --h5-stick-h: 1.5rem;
  --fg: #1c1a17;
  --fg-soft: #4a463f;
  --muted: #8a857b;
  --bg: #faf7f1;
  --paper: #fffcf5;
  --rule: #d8d0bf;
  --accent: #6b3a1a;
  --accent-soft: #b07a4a;
  --aside-bg: #f0eadb;
  --aside-border: #c8b88a;
  --max: 44rem;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { font-size: 20px; }
body {
  font-family: var(--heading-font);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--fg);
  background: var(--bg);
}

/* Body prose and aside notes use the book's display face. */
.prose,
.prose p,
.prose li,
.prose blockquote,
aside.info-note,
aside.info-note p {
  font-family: var(--body-font);
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand {
  font-weight: 700;
  font-variant: small-caps;
  letter-spacing: 0.04em;
  color: var(--fg);
  text-decoration: none;
}
.site-nav a {
  color: var(--fg-soft);
  text-decoration: none;
  margin-left: 1rem;
  font-size: 0.95rem;
}
.site-nav a:hover { color: var(--accent); }

.page {
  max-width: var(--max);
  margin: 2rem auto;
  padding: 0 1.25rem 4rem;
}
.page-sub {
  max-width: var(--max);
  margin: 0.25rem auto 0;
  padding: 0 1.25rem;
  color: var(--muted);
  font-style: italic;
}
.site-footer {
  border-top: 1px solid var(--rule);
  padding: 1rem 1.25rem;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--heading-font);
  color: var(--fg);
  line-height: 1.25;
}
h1 {
  font-family: var(--body-font);
  font-variant: small-caps;
  font-size: 2.4rem;
  letter-spacing: 0.02em;
  margin: 0 0 0.75rem;
  line-height: 1.15;
}
h2 {
  font-family: var(--h2-font);
  font-size: 1.6rem;
  letter-spacing: 0.02em;
  margin: 2rem 0 0.5rem;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.25rem;
}
h3 { font-size: 1.15rem; margin: 1.5rem 0 0.4rem; }
h4 { font-size: 1.05rem; margin: 1.25rem 0 0.4rem; }
h5, h5.rule, h6 {
  font-family: var(--h5-font);
}
h6 {
  font-size: 1rem;
  margin: 1rem 0 0.4rem;
}
h5.rule {
  font-size: 1.2rem;
  margin: 2rem 0 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--rule);
  scroll-margin-top: 4rem;
}
h5.rule .rule-num {
  color: var(--accent);
  margin-right: 0.25rem;
}

a { color: var(--accent); }
a:hover { color: var(--accent-soft); }
a.xref {
  color: var(--accent);
  text-decoration-style: dotted;
  text-decoration-thickness: 1px;
}

aside.info-note {
  background: var(--aside-bg);
  border-left: 3px solid var(--aside-border);
  padding: 0.5rem 0.85rem;
  margin: 0.75rem 0;
  font-size: 0.92rem;
  color: var(--fg-soft);
}
aside.info-note p { margin: 0.4rem 0; }

blockquote {
  border-left: 3px solid var(--rule);
  padding-left: 0.85rem;
  color: var(--fg-soft);
  margin: 0.75rem 0;
}

hr { border: 0; border-top: 1px solid var(--rule); margin: 1.5rem 0; }

.year-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.year-card {
  display: block;
  padding: 1rem;
  border: 1px solid var(--rule);
  background: var(--paper);
  text-decoration: none;
  color: var(--fg);
}
.year-card:hover {
  border-color: var(--accent-soft);
}
.year-card .year-num {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.year-card .year-status {
  display: inline-block;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.year-card .year-status.in-progress { color: var(--accent); }
.year-card .year-status.paused { color: #8a6f33; }

.section-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}
.section-list li {
  border-bottom: 1px solid var(--rule);
}
.section-list a {
  display: flex;
  justify-content: space-between;
  padding: 0.6rem 0;
  text-decoration: none;
  color: var(--fg);
}
.section-list a:hover { color: var(--accent); }
.section-list .section-meta {
  color: var(--muted);
  font-size: 0.85rem;
}

.version-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.75rem;
  align-items: baseline;
  padding: 0.6rem 0.75rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  margin: 1rem 0 1.5rem;
  font-size: 0.92rem;
}
.version-bar .label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.75rem;
}
.version-bar a { text-decoration: none; }
.version-bar .current {
  font-weight: 700;
  color: var(--fg);
}
.version-bar .unavailable {
  color: var(--muted);
  text-decoration: line-through;
}

.section-status-banner {
  background: var(--aside-bg);
  border: 1px solid var(--aside-border);
  padding: 0.5rem 0.75rem;
  margin: 0.5rem 0 1rem;
  font-size: 0.9rem;
  color: var(--fg-soft);
}

/* Stacking sticky headings: h1–h5 inside the article each pin to a stacked
   offset that's computed at runtime in JS based on actual rendered heights.
   We deliberately do NOT set fixed heights here so multi-line headings
   render at their natural height and subsequent levels stack flush below. */
article h1,
article h2,
article h3,
article h4,
article h5,
.book-title {
  position: sticky;
  background: var(--bg);
  /* Bleed background into the gutter on each side so masking covers the
     whole content column when stuck. */
  margin-left: -0.5rem;
  margin-right: -0.5rem;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
  /* Tight stack: small bottom margin, no top margin. */
  margin-top: 0;
  margin-bottom: 0.25rem;
  /* JS sets per-element `top` inline; this is a fallback. */
  top: 0;
}
article h1,
.book-title { z-index: 5; border-bottom: 1px solid var(--rule); }
article h2 { z-index: 4; border-bottom: 1px solid var(--rule); padding-bottom: 0; }
article h3 { z-index: 3; border-bottom: 1px solid var(--rule); }
article h4 { z-index: 2; border-bottom: 1px solid var(--rule); }
article h5 { z-index: 1; border-bottom: 1px solid var(--rule); }
article h5.rule {
  border-top: 0;
  padding-top: 0;
}

img { max-width: 100%; height: auto; }
figure { margin: 1.25rem 0; }
figcaption { font-size: 0.85rem; color: var(--muted); }

.toc {
  border: 1px solid var(--rule);
  background: var(--paper);
  padding: 0.75rem 1rem;
  margin: 1rem 0 2rem;
  font-size: 0.95rem;
}
.toc h3 { margin: 0 0 0.4rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.toc ol { margin: 0; padding-left: 1.25rem; }
.toc li { margin: 0.15rem 0; }
.toc a { text-decoration: none; }

.breadcrumb {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.breadcrumb a { color: var(--muted); }

/* Full-edition reader: sidebar TOC + body */
.book-layout {
  display: grid;
  grid-template-columns: 16rem 1fr;
  gap: 2.5rem;
  align-items: start;
}
.book-toc {
  position: sticky;
  top: 4rem;
  align-self: start;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
  padding-right: 0.5rem;
  font-size: 0.92rem;
  border-right: 1px solid var(--rule);
}
.book-toc h3 {
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}
.book-toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.book-toc-list > li {
  margin: 0.45rem 0;
}
.book-toc-list > li > a {
  display: block;
  text-decoration: none;
  color: var(--fg);
  font-weight: 600;
  padding: 0.1rem 0;
}
.book-toc-list > li > a:hover { color: var(--accent); }
.book-toc-rules {
  list-style: none;
  padding: 0 0 0 0.75rem;
  margin: 0.25rem 0 0.5rem;
  border-left: 1px solid var(--rule);
}
.book-toc-rules li { margin: 0.1rem 0; }
.book-toc-rules a {
  display: block;
  font-weight: 400;
  font-size: 0.88rem;
  color: var(--fg-soft);
  text-decoration: none;
  padding: 0.05rem 0 0.05rem 0.5rem;
  line-height: 1.35;
}
.book-toc-rules a:hover { color: var(--accent); }
.book-toc-rules .rule-num {
  color: var(--muted);
  margin-right: 0.25rem;
}

.book-toc a.active,
.book-toc-rules a.active {
  color: var(--accent);
  font-weight: 700;
  background: rgba(176, 122, 74, 0.10);
  border-left: 2px solid var(--accent);
  padding-left: 0.4rem;
  margin-left: -0.4rem;
}
.book-toc-list > li > a.active {
  padding-left: 0.4rem;
  margin-left: -0.4rem;
}
.book-toc-list > li.active-section > a {
  color: var(--accent);
}

.book-body {
  min-width: 0;
  max-width: var(--max);
}
.book-title {
  font-size: 2.2rem;
  margin: 0 0 1.5rem;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.5rem;
}
.book-section {
  scroll-margin-top: 4rem;
  margin: 2.5rem 0;
}
.book-section + .book-section {
  border-top: 1px solid var(--rule);
  padding-top: 1.5rem;
}

.read-link {
  display: inline-block;
  margin: 0.5rem 0 1rem;
  padding: 0.5rem 0.85rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  text-decoration: none;
  color: var(--fg);
  font-size: 0.95rem;
}
.read-link:hover {
  border-color: var(--accent-soft);
  color: var(--accent);
}

/* The full-edition page wants more horizontal room than .page allows. */
body:has(.book-layout) main.page {
  max-width: 78rem;
}

@media (max-width: 60rem) {
  .book-layout {
    grid-template-columns: 1fr;
  }
  .book-toc {
    position: static;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--rule);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
  }
}
