
:root {
  --paper: #f7f2e7;
  --paper-edge: #ede5d1;
  --ink: #1a1714;
  --ink-soft: #4a4338;
  --ink-faint: #8a7f6e;
  --rule: #d8cdb3;
  --accent: #6b2c1f;
  --accent-soft: #a45a47;
  --sidebar-bg: #ede5d1;
  --shadow: 0 1px 0 rgba(0,0,0,.04), 0 16px 40px -28px rgba(40,30,15,.4);
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #18140f;
    --paper-edge: #221c14;
    --ink: #e8e0cf;
    --ink-soft: #c2b89f;
    --ink-faint: #8a7f6e;
    --rule: #3a3225;
    --accent: #c08a6f;
    --accent-soft: #d8a98e;
    --sidebar-bg: #221c14;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Charter", Georgia, serif;
  background: var(--paper-edge);
  color: var(--ink);
  font-size: 19px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; border-bottom: 1px solid rgba(107,44,31,.25); }
a:hover { border-bottom-color: var(--accent); }
.header {
  position: sticky; top: 0; z-index: 10;
  background: var(--paper-edge);
  border-bottom: 1px solid var(--rule);
  padding: 10px 18px;
  display: flex; align-items: center; justify-content: space-between;
  font-family: "Optima", "Avenir Next", system-ui, sans-serif;
  font-size: 13px;
  letter-spacing: .04em;
}
.header .title { color: var(--ink-soft); text-transform: uppercase; }
.header .title a { color: inherit; border: none; }
.header nav { display: flex; gap: 14px; }
.header nav a { color: var(--ink-soft); border: none; }
.header nav a:hover { color: var(--accent); }
.layout { display: grid; grid-template-columns: 260px 1fr; max-width: 1180px; margin: 0 auto; }
@media (max-width: 900px) { .layout { grid-template-columns: 1fr; } .toc { display: none; } }
.toc {
  border-right: 1px solid var(--rule);
  padding: 32px 20px 80px 20px;
  font-family: "Optima", "Avenir Next", system-ui, sans-serif;
  font-size: 13px;
  line-height: 1.4;
  position: sticky; top: 47px; align-self: start;
  max-height: calc(100vh - 47px);
  overflow-y: auto;
}
.toc h4 {
  text-transform: uppercase; letter-spacing: .08em; font-size: 11px;
  color: var(--ink-faint); margin: 22px 0 8px 0; font-weight: 600;
}
.toc h4:first-child { margin-top: 0; }
.toc ol { list-style: none; padding: 0; margin: 0; }
.toc li { margin: 4px 0; }
.toc a { color: var(--ink-soft); border: none; display: block; padding: 3px 0; }
.toc a:hover { color: var(--accent); }
.toc a.current { color: var(--accent); font-weight: 600; }
.toc .num { display: inline-block; width: 22px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.page {
  background: var(--paper);
  min-height: calc(100vh - 47px);
  padding: 56px 64px 120px 64px;
  box-shadow: var(--shadow);
}
@media (max-width: 900px) { .page { padding: 36px 24px 100px 24px; } }
.chapter-meta {
  font-family: "Optima", "Avenir Next", system-ui, sans-serif;
  font-size: 12px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 18px;
}
h1.chapter-title {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 38px; line-height: 1.15; margin: 0 0 10px 0; letter-spacing: -0.01em;
  color: var(--ink);
}
.kicker {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-style: italic; color: var(--ink-soft); font-size: 19px; margin: 0 0 8px 0;
}
.byline { color: var(--ink-faint); font-size: 14px; margin: 0 0 32px 0;
  font-family: "Optima", "Avenir Next", system-ui, sans-serif; letter-spacing: .04em; }
hr.rule { border: none; border-top: 1px solid var(--rule); margin: 28px 0; }
.prose { max-width: 660px; }
.prose h2 {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 22px; margin: 38px 0 14px 0; letter-spacing: -0.005em;
}
.prose h3 {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 18px; font-style: italic; margin: 26px 0 10px 0; color: var(--ink-soft);
}
.prose p { margin: 0 0 1.05em 0; hyphens: auto; text-align: justify; }
.prose p + p { text-indent: 1.4em; }
.prose blockquote {
  margin: 18px 0 18px 0; padding: 4px 0 4px 18px;
  border-left: 3px solid var(--rule); color: var(--ink-soft); font-style: italic;
}
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li { margin: 0 0 .4em 0; }
.prose .first-letter::first-letter {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 3.6em; float: left; line-height: .85; padding: 6px 8px 0 0;
  color: var(--accent); font-weight: 700;
}
.pull {
  margin: 28px 0; padding: 18px 22px;
  background: var(--sidebar-bg); border-left: 3px solid var(--accent);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-style: italic; font-size: 20px; line-height: 1.45;
  color: var(--ink);
}
.pull .attr { display: block; margin-top: 8px; font-size: 13px;
  font-style: normal; color: var(--ink-faint);
  font-family: "Optima", "Avenir Next", system-ui, sans-serif; letter-spacing: .04em; }
.endmatter {
  margin: 56px 0 0 0; padding-top: 28px; border-top: 1px solid var(--rule);
  display: grid; grid-template-columns: 1fr 1fr; gap: 36px; max-width: 760px;
}
@media (max-width: 700px) { .endmatter { grid-template-columns: 1fr; } }
.endmatter h4 {
  font-family: "Optima", "Avenir Next", system-ui, sans-serif;
  font-size: 11px; text-transform: uppercase; letter-spacing: .12em;
  color: var(--ink-faint); margin: 0 0 12px 0;
}
.endmatter ul { padding-left: 0; list-style: none; margin: 0; }
.endmatter li { margin: 0 0 10px 0; font-size: 15px; line-height: 1.5; color: var(--ink-soft); }
.endmatter .term { color: var(--ink); font-weight: 600; }
.pagenav {
  margin-top: 64px; padding-top: 24px; border-top: 1px solid var(--rule);
  display: flex; justify-content: space-between; gap: 18px;
  font-family: "Optima", "Avenir Next", system-ui, sans-serif; font-size: 13px;
}
.pagenav a { color: var(--ink-soft); border: none; max-width: 45%; }
.pagenav a:hover { color: var(--accent); }
.pagenav .dir { display: block; font-size: 11px; text-transform: uppercase;
  letter-spacing: .12em; color: var(--ink-faint); margin-bottom: 4px; }
.pagenav .ttl { display: block; font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif; }
.pagenav .right { text-align: right; margin-left: auto; }
.cover {
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  min-height: calc(100vh - 47px); text-align: center; padding: 0 24px;
}
.cover .stamp {
  font-family: "Optima", "Avenir Next", system-ui, sans-serif;
  font-size: 11px; text-transform: uppercase; letter-spacing: .25em;
  color: var(--ink-faint); margin-bottom: 28px;
}
.cover h1 {
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-size: 64px; line-height: 1.05; margin: 0 0 18px 0; letter-spacing: -0.01em;
  max-width: 760px;
}
.cover .sub {
  font-style: italic; color: var(--ink-soft); font-size: 22px; max-width: 600px;
  line-height: 1.4; margin: 0 0 56px 0;
}
.cover .editors { color: var(--ink-faint); font-size: 14px;
  font-family: "Optima", "Avenir Next", system-ui, sans-serif; letter-spacing: .04em; }
.cover .open {
  margin-top: 56px; padding: 12px 28px; border: 1px solid var(--accent);
  color: var(--accent); border-radius: 2px; text-transform: uppercase;
  letter-spacing: .15em; font-size: 12px;
  font-family: "Optima", "Avenir Next", system-ui, sans-serif;
}
.cover .open:hover { background: var(--accent); color: var(--paper); }
.colophon-grid {
  display: grid; grid-template-columns: 1fr; gap: 22px; max-width: 760px;
}
.colophon-paper {
  padding: 18px 20px; background: var(--sidebar-bg); border-left: 3px solid var(--accent-soft);
}
.colophon-paper .slug {
  font-family: "Optima", "Avenir Next", system-ui, sans-serif;
  font-size: 11px; text-transform: uppercase; letter-spacing: .12em;
  color: var(--ink-faint); margin-bottom: 4px;
}
.colophon-paper .title { font-size: 17px; margin-bottom: 4px; }
.colophon-paper .cite { color: var(--ink-soft); font-size: 14px; font-style: italic; margin-bottom: 6px; }
.colophon-paper .why { color: var(--ink-soft); font-size: 14px; }
.colophon-paper .claims { margin: 8px 0 0 0; padding-left: 1.2em; font-size: 13px; color: var(--ink-soft); }
.progress {
  height: 2px; background: transparent; position: sticky; top: 47px; z-index: 9;
}
.progress-bar {
  height: 100%; background: var(--accent); width: 0%;
  transition: width .15s ease-out;
}

/* ---------- Mobile-first additions. Desktop >=900px untouched. ---------- */

/* 1. Contrast + tap-highlight + smoothing defaults */
:root { --ink-faint: #6f6553; --focus-ring: 0 0 0 2px var(--paper), 0 0 0 4px var(--accent); }
@media (prefers-color-scheme: dark) {
  :root { --ink-faint: #9a8f7a; --focus-ring: 0 0 0 2px var(--paper), 0 0 0 4px var(--accent-soft); }
}
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
a:focus, button:focus { outline: none; }
a:focus-visible, button:focus-visible, .cover .open:focus-visible,
.toc a:focus-visible, .pagenav a:focus-visible, .header a:focus-visible,
.mininav a:focus-visible, .mininav button:focus-visible, .drawer-toggle:focus-visible {
  outline: none; box-shadow: var(--focus-ring); border-radius: 4px;
}

/* 2. Skip link */
.skip { position: absolute; left: -9999px; top: auto; width: 1px; height: 1px; overflow: hidden; }
.skip:focus { position: fixed; left: 8px; top: 8px; width: auto; height: auto; z-index: 100;
  background: var(--paper); color: var(--accent); padding: 10px 14px;
  border: 2px solid var(--accent); border-radius: 4px;
  font-family: "Optima","Avenir Next",system-ui,sans-serif; font-size: 13px; letter-spacing: .04em; }

/* 3. Header touch + safe-area; drawer toggle hidden on desktop */
.header { padding-left: max(18px, env(safe-area-inset-left));
  padding-right: max(18px, env(safe-area-inset-right));
  padding-top: max(10px, env(safe-area-inset-top)); }
.header .title a, .header nav a { display: inline-flex; align-items: center;
  min-height: 44px; padding: 0 10px; border-radius: 6px; }
.header .title a { padding-left: 0; }
.header nav a:active { background: rgba(107,44,31,.08); }
.drawer-toggle { display: none; }

/* 4. Mobile header: drawer toggle in, secondary links out */
@media (max-width: 900px) {
  .drawer-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 44px; height: 44px; padding: 0; margin: 0;
    background: transparent; border: none; color: var(--ink-soft);
    border-radius: 6px; cursor: pointer;
  }
  .drawer-toggle:active { background: rgba(107,44,31,.08); color: var(--accent); }
  .drawer-toggle svg { width: 22px; height: 22px; display: block; }
  .header nav { gap: 2px; }
}
@media (max-width: 560px) {
  .header nav a.nav-secondary { display: none; }
}

/* 5. Fluid body typography (only on narrow widths; desktop keeps 19/1.65) */
@media (max-width: 900px) {
  body { font-size: clamp(16.5px, 0.95rem + 0.4vw, 19px); line-height: 1.55; }
}
@media (min-width: 700px) and (max-width: 900px) { body { line-height: 1.6; } }

/* 6. Ragged-right prose on phones; justify only above 700px */
.prose p { text-align: left; hyphens: manual; -webkit-hyphens: manual; text-wrap: pretty; }
.prose blockquote { text-align: left; hyphens: manual; -webkit-hyphens: manual; }
@media (min-width: 700px) {
  .prose p { text-align: justify; hyphens: auto; -webkit-hyphens: auto; }
}

/* 7. Mobile chapter-meta / title / kicker / byline scale */
@media (max-width: 700px) {
  .chapter-meta { font-size: 11px; letter-spacing: .1em; margin-bottom: 14px; }
  h1.chapter-title { font-size: clamp(26px, 5vw + 8px, 38px); line-height: 1.18; margin: 0 0 8px 0; text-wrap: balance; }
  .kicker { font-size: clamp(16px, 0.5vw + 15px, 19px); line-height: 1.4; margin-bottom: 10px; }
  .byline { font-size: 12.5px; margin-bottom: 22px; line-height: 1.5; }
  .prose h2 { font-size: clamp(20px, 1vw + 18px, 22px); margin: 30px 0 10px; line-height: 1.25; text-wrap: balance; }
  .prose h3 { font-size: clamp(17px, 0.5vw + 16px, 18px); font-style: normal; font-weight: 600;
    color: var(--ink); margin: 22px 0 8px; line-height: 1.3; }
  .prose p + p { text-indent: 1.1em; }
  .prose p { margin-bottom: 0.95em; }
  .prose blockquote { padding: 2px 0 2px 14px; margin: 16px 0; font-size: 0.97em; }
  .pull { font-size: clamp(17px, 1vw + 15px, 20px); line-height: 1.4;
    padding: 14px 16px; margin: 22px -8px; border-left-width: 2px; }
  .pull .attr { font-size: 12px; margin-top: 6px; }
}

/* 8. Drop cap: shrink at 500px, swap to small-caps incipit under 380px */
@media (max-width: 500px) {
  .prose .first-letter::first-letter {
    font-size: 2.6em; line-height: .9; padding: 4px 6px 0 0;
  }
}
@media (max-width: 380px) {
  .prose .first-letter::first-letter {
    float: none; font-size: 1.4em; line-height: inherit; padding: 0 .05em 0 0;
    color: var(--accent); font-variant: small-caps; letter-spacing: .04em; font-weight: 700;
  }
  .prose .first-letter::first-line {
    font-variant: small-caps; letter-spacing: .04em; color: var(--ink-soft);
  }
}

/* 9. Cover: fluid title/sub, 44px CTA, safe areas, svh/dvh chain */
.cover { min-height: 100vh; min-height: 100svh;
  padding: 0 max(24px, env(safe-area-inset-left)) max(0px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-right)); }
@supports (height: 100dvh) { .cover { min-height: 100dvh; } }
.cover h1 { font-size: clamp(36px, 7vw + 12px, 64px); line-height: 1.08; margin: 0 0 clamp(12px, 2vw, 18px) 0; text-wrap: balance; }
.cover .sub { font-size: clamp(17px, 1.2vw + 14px, 22px); margin: 0 0 clamp(32px, 6vw, 56px) 0; }
.cover .stamp { margin-bottom: clamp(18px, 4vw, 28px); }
.cover .open { display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 14px 28px; margin-top: clamp(28px, 6vw, 56px); }

/* 10. Page min-height: replace magic 47px with svh/dvh chain */
.page { min-height: 100vh; min-height: 100svh; }
@supports (height: 100dvh) { .page { min-height: 100dvh; } }

/* 11. Progress bar: transform-driven, no layout writes */
.progress-bar { width: 100%; transform-origin: left center; transform: scaleX(0);
  transition: transform .15s ease-out; will-change: auto; }
html.is-scrolling .progress-bar { will-change: transform; }

/* 12. Drawer (off-canvas TOC, mobile only) */
.drawer { position: fixed; inset: 0 auto 0 0; width: min(86vw, 340px);
  background: var(--paper-edge); z-index: 50;
  transform: translateX(-100%); transition: transform .22s ease;
  box-shadow: 0 0 0 transparent;
  padding-top: max(12px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left)); padding-right: 16px;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  visibility: hidden;
}
.drawer[hidden] { display: block; } /* override [hidden] so transition runs */
.drawer-scrim { position: fixed; inset: 0; background: rgba(20,15,8,.45);
  z-index: 49; opacity: 0; pointer-events: none; transition: opacity .22s ease;
  visibility: hidden;
}
body.drawer-open { overflow: hidden; touch-action: none; }
body.drawer-open .drawer { transform: translateX(0); visibility: visible;
  box-shadow: 0 0 60px rgba(0,0,0,.35); }
body.drawer-open .drawer-scrim { opacity: 1; pointer-events: auto; visibility: visible; }

.drawer .drawer-head { display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--rule); padding: 4px 0 10px 0; margin-bottom: 12px; }
.drawer .drawer-head h2 { margin: 0; font-family: "Optima","Avenir Next",system-ui,sans-serif;
  font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-faint); font-weight: 600; }
.drawer .drawer-close { width: 44px; height: 44px; background: transparent; border: none;
  color: var(--ink-soft); border-radius: 6px; cursor: pointer; display: inline-flex;
  align-items: center; justify-content: center; }
.drawer .drawer-close:active { background: rgba(107,44,31,.08); color: var(--accent); }
.drawer .drawer-close svg { width: 22px; height: 22px; }

.drawer nav { font-family: "Optima","Avenir Next",system-ui,sans-serif; font-size: 14px; line-height: 1.4; }
.drawer nav h4 { text-transform: uppercase; letter-spacing: .08em; font-size: 11px;
  color: var(--ink-faint); margin: 18px 0 6px 0; font-weight: 600; }
.drawer nav h4:first-child { margin-top: 0; }
.drawer nav ol { list-style: none; padding: 0; margin: 0; }
.drawer nav li { margin: 0; }
.drawer nav a { color: var(--ink-soft); border: none; display: block;
  padding: 11px 8px; min-height: 44px; border-radius: 6px; }
.drawer nav a:active { background: rgba(107,44,31,.08); }
.drawer nav a[aria-current="page"], .drawer nav a.current {
  color: var(--accent); font-weight: 600; background: rgba(107,44,31,.06); }
.drawer nav .num { display: inline-block; width: 22px; color: var(--ink-faint);
  font-variant-numeric: tabular-nums; }

@media (min-width: 901px) {
  .drawer, .drawer-scrim { display: none !important; }
  body.drawer-open { overflow: auto; touch-action: auto; }
}

/* 13. Mini-nav (bottom prev/TOC/next, chapter & matter pages, mobile only) */
.mininav { display: none; }
@media (max-width: 700px) {
  .mininav {
    display: grid; grid-template-columns: 1fr auto 1fr;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
    background: var(--paper-edge);
    border-top: 1px solid var(--rule);
    padding: 6px 8px;
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    font-family: "Optima","Avenir Next",system-ui,sans-serif;
    font-size: 12px; letter-spacing: .04em;
  }
  @supports (backdrop-filter: blur(10px)) or (-webkit-backdrop-filter: blur(10px)) {
    .mininav { background: color-mix(in srgb, var(--paper-edge) 88%, transparent);
      -webkit-backdrop-filter: saturate(160%) blur(10px); backdrop-filter: saturate(160%) blur(10px); }
  }
  .mininav a, .mininav button {
    min-height: 44px; min-width: 44px; display: inline-flex; align-items: center;
    justify-content: center; gap: 6px; color: var(--ink-soft); border: none;
    background: transparent; padding: 0 10px; border-radius: 6px; cursor: pointer;
    text-decoration: none;
  }
  .mininav a[aria-disabled="true"] { color: var(--ink-faint); pointer-events: none; }
  .mininav a:active, .mininav button:active { background: rgba(107,44,31,.08); color: var(--accent); }
  .mininav .mn-prev { justify-content: flex-start; }
  .mininav .mn-next { justify-content: flex-end; }
  .mininav .mn-toc { padding: 0 16px; color: var(--accent); }
  .mininav svg { width: 18px; height: 18px; }
  .mininav .mn-label { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; }

  /* Keep content clear of fixed bar */
  .page { padding-bottom: 140px; }
  html { scroll-padding-bottom: 80px; }
  /* Foot pagenav is redundant on mobile; hide visually + from AT */
  .pagenav { display: none; }
}

/* 14. Reduced-motion: kill all transitions/animations we introduced */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important;
  }
  .drawer { transition: none; }
  .drawer-scrim { transition: none; }
  .progress-bar { transition: none; }
}
