/* Shared design tokens and base typography for the whole site.
   Concatenated ahead of reader.css (the /  card reader) and ahead of
   book.css (every regular URL) so both experiences are one book:
   same paper, same ink, same serif, same ochre. */

:root {
  color-scheme: light dark;

  /* paper — the default */
  --bg:        #faf7f1;
  --fg:        #211f1b;
  --muted:     #6f6b62;
  --accent:    #9a6b12;   /* ochre — rules, marks, hover */
  --accent-fg: #7c550c;   /* ochre as link text: a touch darker to hold contrast on paper */
  --panel:     #efe8da;   /* sunk surfaces: code, quotes, cover */
  --line:      #ddd5c5;
  --sel:       rgba(154,107,18,0.20);

  --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --sans:  -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  /* regular-page reading type — calmer than the reader's card type */
  --fs: clamp(1.16rem, 1.05rem + 0.6vw, 1.38rem);
  --lh: 1.68;
  --measure: 36rem;                 /* ~65 characters of Georgia */
  --pad-x: max(6vw, 1.15rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0e0f12;
    --fg:        #ececec;
    --muted:     #9aa0a6;
    --accent:    #e7b74b;
    --accent-fg: #e7b74b;
    --panel:     #17191d;
    --line:      #2a2d33;
    --sel:       rgba(231,183,75,0.24);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  font-size: var(--fs);
  line-height: var(--lh);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
::selection { background: var(--sel); }

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

h1, h2, h3, h4 { line-height: 1.22; text-wrap: balance; font-weight: 700; }
img { max-width: 100%; height: auto; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition-duration: 0.01s !important; } }
/* Every regular URL: a chapter of the book, read on its own page.
   Mobile-first single column; a capped measure on wider screens.
   Palette, serif and base typography come from tokens.css ahead of this. */

body.page {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ---- masthead ---- */
.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem var(--pad-x);
  padding-top: calc(env(safe-area-inset-top, 0px) + 0.85rem);
  border-bottom: 1px solid var(--line);
  font: 500 0.8rem/1.3 var(--sans);
}
.masthead a { text-decoration: none; }
.masthead .brand {
  color: var(--fg);
  font-weight: 600;
  letter-spacing: 0.01em;
}
.masthead .to-reader {
  color: var(--accent-fg);
  white-space: nowrap;
}

/* ---- page body ---- */
main.page-body {
  flex: 1 0 auto;
  width: 100%;
  /* the measure plus a calm, bounded gutter — not the full-bleed 6vw the
     masthead and colophon use */
  --gutter: clamp(1.15rem, 4vw, 2.25rem);
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin: 0 auto;
  padding: clamp(1.6rem, 5vw, 3.2rem) var(--gutter) 4rem;
}

.kicker {
  margin: 0 0 0.7rem;
  font: 500 0.72rem/1.4 var(--sans);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.page-title {
  font-size: clamp(1.65rem, 1.3rem + 1.9vw, 2.3rem);
  letter-spacing: -0.012em;
  margin: 0;
}
.title-rule {
  width: 2.6rem;
  height: 2px;
  background: var(--accent);
  border: 0;
  margin: 1rem 0 1.9rem;
}

/* ---- prose ---- */
.prose > * { margin: 0; }
.prose > * + * { margin-top: 1.05rem; }
.prose h2 { font-size: 1.28em; margin-top: 2.3rem; }
.prose h3 { font-size: 1.08em; margin-top: 1.8rem; }
.prose h4 { font-size: 1em; margin-top: 1.4rem; letter-spacing: 0.01em; }
.prose h2 + *, .prose h3 + *, .prose h4 + * { margin-top: 0.5rem; }
.prose ul, .prose ol { padding-left: 1.35em; }
.prose li + li { margin-top: 0.3em; }
.prose li > ul, .prose li > ol { margin-top: 0.3em; }

.prose a { text-decoration: underline; }

.prose figure {
  margin: 1.9rem 0;
  text-align: center;
}
.prose figure img {
  border-radius: 6px;
  background: #fff;
}
.prose figcaption {
  margin-top: 0.55rem;
  font: 400 0.82rem/1.5 var(--sans);
  color: var(--muted);
}
.prose figcaption h4 { font: inherit; font-weight: 600; margin: 0 0 0.15rem; }
.prose figcaption p { margin: 0; }

.prose blockquote {
  margin: 1.7rem 0;
  padding-left: 1rem;
  border-left: 3px solid var(--line);
  color: var(--muted);
  font-style: italic;
}

.prose pre {
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.9rem 1rem;
  font-size: 0.82em;
  line-height: 1.55;
}
.prose code {
  font-size: 0.86em;
  background: var(--panel);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}
.prose pre code { background: none; padding: 0; font-size: inherit; }

.prose table {
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 0.92em;
}
.prose th, .prose td {
  border: 1px solid var(--line);
  padding: 0.4em 0.6em;
  text-align: left;
  vertical-align: top;
}
.prose th { background: var(--panel); }

.prose hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 2.2rem 0;
}

/* ---- prev / next along the spine ---- */
.pagenav {
  display: flex;
  gap: 1.2rem;
  margin-top: 3.2rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--line);
}
.pagenav a {
  flex: 1 1 0;
  max-width: 48%;
  text-decoration: none;
  font: 500 0.9rem/1.35 var(--serif);
  color: var(--accent-fg);
}
.pagenav .next { text-align: right; margin-left: auto; }
.pagenav .lbl {
  display: block;
  margin-bottom: 0.2rem;
  font: 500 0.66rem/1.4 var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

/* ---- generated table of contents ---- */
.toc {
  margin: 0;
  padding-left: 0;
  list-style: none;
}
.toc li {
  margin: 0.5rem 0;
}
.toc a {
  text-decoration: none;
}
.toc a:hover {
  text-decoration: underline;
}

/* ---- index / list pages ---- */
.index-list {
  columns: 16rem 2;
  column-gap: 2rem;
}
.index-list a {
  display: block;
  padding: 0.28rem 0;
  break-inside: avoid;
}

/* ---- colophon ---- */
.colophon {
  flex-shrink: 0;
  padding: 1.5rem var(--pad-x) calc(env(safe-area-inset-bottom, 0px) + 2rem);
  border-top: 1px solid var(--line);
  font: 400 0.78rem/1.65 var(--sans);
  color: var(--muted);
}
.colophon p { margin: 0 0 0.4rem; }
.colophon .terms a { color: var(--muted); }
.colophon .terms a + a { margin-left: 0.1rem; }

@media (min-width: 48rem) {
  .masthead { font-size: 0.84rem; }
}
