:root {
  --measure: 68ch;
  --gutter: clamp(1rem, 4vw, 2rem);
  --bg: #fbfaf7;
  --fg: #1c1917;
  --muted: #6b6258;
  --rule: #e7e0d3;
  --accent: #b4441f;
  --accent-soft: #f5e3d7;
  --font-serif: "Iowan Old Style", "Charter", "Source Serif Pro", Georgia, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16140f;
    --fg: #f1ece1;
    --muted: #a39988;
    --rule: #2a2620;
    --accent: #e88864;
    --accent-soft: #3b261c;
  }
}

* { box-sizing: border-box; }
html { font-size: 17px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-serif);
  line-height: 1.65;
  text-rendering: optimizeLegibility;
}

img, picture, video, svg { max-width: 100%; height: auto; display: block; }

/* ----- site header / footer ----- */
.site-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 2rem;
  padding: 1.25rem var(--gutter);
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-sans);
  font-size: 0.875rem;
}
.site-title {
  font-weight: 600;
  text-decoration: none;
  color: var(--fg);
  font-size: 1rem;
}
.chapter-toc {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.chapter-toc a { color: var(--muted); text-decoration: none; }
.chapter-toc a:hover { color: var(--fg); }
.chapter-toc [aria-current="page"] a { color: var(--fg); font-weight: 600; }

.site-footer {
  padding: 3rem var(--gutter) 4rem;
  border-top: 1px solid var(--rule);
  margin-top: 4rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--muted);
}

main { padding: 2rem var(--gutter); }

/* ----- typography ----- */
.chapter {
  max-width: var(--measure);
  margin: 0 auto;
}
.chapter__title {
  font-size: clamp(2rem, 5vw, 2.75rem);
  line-height: 1.15;
  margin: 1rem 0 0.5rem;
}
.chapter__summary {
  font-size: 1.125rem;
  color: var(--muted);
  font-style: italic;
  margin: 0 0 1rem;
}
.chapter__meta {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--muted);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 1.5rem;
  margin-bottom: 2rem;
}
.tag {
  color: var(--muted);
  text-decoration: none;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--accent-soft);
  font-size: 0.75rem;
  font-family: var(--font-sans);
}

.chapter__body p { margin: 1.1em 0; }
.chapter__body h2 { margin: 2.4rem 0 0.5rem; font-size: 1.5rem; }
.chapter__body h3 { margin: 2rem 0 0.5rem; font-size: 1.2rem; }
.chapter__body a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
.chapter__body blockquote {
  margin: 1.5rem 0;
  padding: 0.5rem 0 0.5rem 1.25rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
  font-style: italic;
}
.chapter__body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--accent-soft);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}
.chapter__body pre {
  font-family: var(--font-mono);
  background: var(--accent-soft);
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
}
.chapter__body pre code { background: none; padding: 0; }

/* ----- figure & gallery ----- */
figure { margin: 2rem 0; }
figure figcaption {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.5rem;
  text-align: center;
}

.gallery { display: grid; gap: var(--gallery-gap, 8px); margin: 2rem 0; }
.gallery--single { grid-template-columns: 1fr; }
.gallery--tile {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
}
.gallery--masonry { display: block; column-count: 1; column-gap: var(--gallery-gap, 8px); }
@media (min-width: 700px) { .gallery--masonry { column-count: 2; } }
@media (min-width: 1100px) { .gallery--masonry { column-count: 3; } }
.gallery--masonry figure { break-inside: avoid; margin: 0 0 var(--gallery-gap, 8px); }
.gallery--carousel {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: thin;
  padding-bottom: 0.5rem;
}
.gallery--carousel .gallery__item {
  flex: 0 0 80%;
  scroll-snap-align: center;
  margin: 0;
}
.gallery--fullbleed {
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
  width: 100vw;
  grid-template-columns: 1fr;
}
.gallery__item img { width: 100%; }

/* ----- video ----- */
.video video { width: 100%; border-radius: 4px; background: #000; }

/* ----- map ----- */
.map { position: relative; }
.map img { width: 100%; border-radius: 4px; background: var(--accent-soft); }
.map__activate {
  position: absolute;
  bottom: 0.5rem;
  right: 0.5rem;
  padding: 0.4rem 0.75rem;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: 0;
  border-radius: 4px;
  font: inherit;
  font-size: 0.85rem;
  font-family: var(--font-sans);
  cursor: pointer;
}

/* ----- quote-card ----- */
.quote-card {
  margin: 2rem 0;
  padding: 1.25rem 1.5rem;
  border-left: none;
  font-style: normal;
  color: var(--fg);
}
.quote-card--plain { border-left: 3px solid var(--accent); padding-left: 1.25rem; font-style: italic; }
.quote-card--pulled {
  font-size: 1.3rem;
  line-height: 1.45;
  text-align: center;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding: 1.5rem 0;
  margin: 2.5rem 0;
  font-style: italic;
}
.quote-card--framed {
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--accent-soft);
}
.quote-card__body p { margin: 0.25rem 0; }
.quote-card__attr {
  margin-top: 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--muted);
}
.quote-card__author { font-weight: 600; color: var(--fg); }
.quote-card__source { margin-left: 0.5rem; }

/* ----- chapter-link card ----- */
.chapter-link--card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin: 2.5rem 0;
  padding: 1.25rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s;
}
.chapter-link--card:hover { background: var(--accent-soft); }
@media (min-width: 700px) {
  .chapter-link--card { grid-template-columns: 240px 1fr; align-items: center; }
}
.chapter-link__cover img { border-radius: 4px; }
.chapter-link__eyebrow {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}
.chapter-link__title { margin: 0.25rem 0; font-size: 1.25rem; }
.chapter-link__summary { color: var(--muted); margin: 0; }

/* ----- wikilink ----- */
.wikilink {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}
.wikilink:hover { background: var(--accent-soft); }
.wikilink--broken { color: var(--muted); border-bottom-style: dashed; cursor: not-allowed; }

/* ----- chapter nav + backlinks ----- */
.chapter-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 3rem 0 2rem;
  padding-top: 2rem;
  border-top: 1px solid var(--rule);
}
.chapter-nav__prev, .chapter-nav__next {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  text-decoration: none;
  color: inherit;
}
.chapter-nav__next { text-align: right; grid-column: 2; }
.chapter-nav__label { font-family: var(--font-sans); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.chapter-nav__title { font-weight: 600; margin-top: 0.25rem; }

.backlinks {
  margin: 2rem 0;
  padding: 1rem 1.25rem;
  background: var(--accent-soft);
  border-radius: 6px;
  font-family: var(--font-sans);
}
.backlinks__heading { margin: 0 0 0.5rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.backlinks ul { margin: 0; padding-left: 1.25rem; }
.backlinks a { color: var(--accent); text-decoration: none; }

/* ----- series landing ----- */
.series-intro { max-width: var(--measure); margin: 0 auto 3rem; text-align: center; }
.series-intro .hero { margin: 0 0 2rem; }
.series-intro h1 { font-size: clamp(2rem, 6vw, 3rem); }
.series-description { font-size: 1.15rem; color: var(--muted); }
.series-meta { font-family: var(--font-sans); font-size: 0.9rem; color: var(--muted); }
.chapter-list { list-style: none; padding: 0; max-width: 56rem; margin: 0 auto; display: grid; gap: 1.25rem; }
.chapter-card { border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; }
.chapter-card a { display: grid; grid-template-columns: 1fr; text-decoration: none; color: inherit; }
@media (min-width: 700px) { .chapter-card a { grid-template-columns: 280px 1fr; } }
.chapter-card .thumb img { aspect-ratio: 16/10; object-fit: cover; }
.chapter-card__body { padding: 1.25rem 1.5rem; }
.chapter-card__title { margin: 0 0 0.5rem; }
.chapter-card__summary { color: var(--muted); margin: 0 0 0.5rem; }
.chapter-card time { font-family: var(--font-sans); font-size: 0.85rem; color: var(--muted); }

.related-series { max-width: 56rem; margin: 3rem auto; padding: 1.25rem; border: 1px solid var(--rule); border-radius: 8px; }
.related-series h2 { margin: 0 0 0.5rem; font-size: 1rem; font-family: var(--font-sans); text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }

/* ----- preview popover injected by viewer.js ----- */
.preview-popover {
  position: absolute;
  z-index: 50;
  max-width: 320px;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  font-family: var(--font-sans);
  font-size: 0.85rem;
}
.preview-popover h3 { margin: 0 0 0.25rem; font-size: 0.95rem; font-family: var(--font-serif); }
.preview-popover p { margin: 0; color: var(--muted); }
