/* ============================================================
   book.css  —  The Context of Life, Web Edition
   Dedicated book stylesheet. Loaded only by book pages.
   Kindle-quiet: one column, comfortable measure, then nothing moving.

   Everything themeable is a custom property so the deferred
   Session-B features (dark mode, adjustable type) become a
   variable swap, not a rewrite.
   ============================================================ */

:root {
  /* Type -------------------------------------------------- */
  --font-body:  "Iowan Old Style", "Palatino Linotype", "Charter",
                Georgia, "Times New Roman", serif;
  --type-scale: 1;           /* reader type control; 1 = approved default */
  --body-size:  calc(1.1875rem * var(--type-scale)); /* 19px base, scales */
  --leading:    1.6;         /* body line-height                  */

  --size-title:  2rem;       /* chapter title — the one loud note */
  --size-header: calc(1.2rem * var(--type-scale)); /* tracks body — PL Q1 */
  --size-label:  0.78rem;    /* "Chapter 2" eyebrow               */
  --size-small:  0.85rem;    /* captions, footer                  */

  /* Measure & rhythm -------------------------------------- */
  --measure: 34em;           /* ~62-70 chars; em keeps it         */
                             /* proportional if type is scaled    */
  --gutter:  1.5rem;         /* side padding, mobile-safe         */
  --indent:  1.4em;          /* first-line paragraph indent       */

  /* Quiet light palette ----------------------------------- */
  --ink:    #1b1b1a;         /* body text — near-black, not #000  */
  --paper:  #faf8f4;         /* warm off-white, low glare         */
  --muted:  #6b6b6b;         /* eyebrow, captions, footer         */
  --rule:   #c9b79c;         /* divider ornament, hairlines       */
  --select: #ece3d4;         /* selection highlight               */
  --quote-ink: #333;         /* block-quote text (was literal #333) */

  color-scheme: light;       /* form controls / scrollbars match  */
}

/* Dark palette — a variable swap, nothing else. Same Kindle-quiet
   principle inverted: warm near-black paper, warm light-grey ink,
   never pure #000 on #fff (halation). The light :root is untouched. */
html[data-theme="dark"] {
  color-scheme: dark;
  --ink:       #dcd6c8;      /* warm light-grey body text         */
  --paper:     #14130e;      /* warm near-black page              */
  --muted:     #8f897b;      /* eyebrow, captions, footer         */
  --rule:      #5a5140;      /* divider, hairlines, progress      */
  --select:    #3a3324;      /* selection highlight               */
  --quote-ink: #c4bfaf;      /* block-quote text                  */
}

/* Reset just enough --------------------------------------- */
* { box-sizing: border-box; }

html { font-size: 100%; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--body-size);
  line-height: var(--leading);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection { background: var(--select); }

/* The reading column: header, prose, and footer share the
   same measure and centering so the page reads as one column. */
.reader-head,
.reader,
.reader-foot {
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* Chapter opener ------------------------------------------ */
.reader-head {
  margin-top: 4.5rem;
  margin-bottom: 2.75rem;
}

.chapter-number {
  display: block;
  font-size: var(--size-label);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

.chapter-title {
  font-size: var(--size-title);
  font-weight: 600;
  line-height: 1.2;
  margin: 0;
}

/* Prose --------------------------------------------------- */
.reader { padding-bottom: 1rem; }

.reader p {
  margin: 0;                     /* book-style: no inter-para gap */
  text-indent: var(--indent);    /* first-line indent            */
}

/* First paragraph of a section is set flush (no indent):
   the very first paragraph, and any paragraph that opens
   immediately after a section header or a divider. */
.reader p.flush { text-indent: 0; }

.reader em { font-style: italic; }

/* Internal section header — bold italic, quiet, grouped with
   the prose it introduces (more space above than below). */
.section-header {
  font-size: var(--size-header);
  font-weight: 700;
  font-style: italic;
  line-height: 1.3;
  margin: 2.2em 0 0.55em;
  clear: both;                   /* clear any floated image      */
}

/* Block quote — inset, quiet. Chapter 2 has none; ready anyway. */
.block-quote {
  margin: 1.5em 2em;
  padding-left: 1em;
  border-left: 2px solid var(--rule);
  color: var(--quote-ink);
  font-style: italic;
  text-indent: 0;
  clear: both;
}
.block-quote p { margin: 0; text-indent: 0; }
.block-quote em { font-style: normal; }   /* emphasis flips inside italic */
.block-quote .attribution {
  display: block;
  margin-top: 0.6em;
  font-style: normal;
  font-size: var(--size-small);
  color: var(--muted);
}
.block-quote .attribution::before { content: "\2014\00a0"; } /* em dash */

/* Divider ornament — no glyph in the source; the CSS draws it,
   reproducing the manuscript's own motif. */
hr.divider {
  border: 0;
  margin: 2.4em 0;
  text-align: center;
  clear: both;
  line-height: 1;
}
hr.divider::before {
  content: "\2014\2726\2014";     /* —✦— */
  color: var(--rule);
  font-size: 1rem;
  letter-spacing: 0.35em;
}

/* Inline images — desktop floats, mobile stacks. Chapter 2 has
   none; the CSS is proven and ready for later placement. */
figure { margin: 0; }
figure img { display: block; width: 100%; height: auto; }

figure figcaption {
  font-size: var(--size-small);
  color: var(--muted);
  margin-top: 0.5em;
  font-style: normal;
}

.img-center {
  margin: 1.7em auto;
  clear: both;
}
.img-center figcaption { text-align: center; }

.img-left {
  float: left;
  max-width: 45%;
  margin: 0.35em 1.6em 1em 0;
}
.img-right {
  float: right;
  max-width: 45%;
  margin: 0.35em 0 1em 1.6em;
}

/* Footer — placeholder region for the generator-injected
   copyright notice (Phase 3). Empty by design this session. */
.reader-foot {
  margin-top: 4rem;
  margin-bottom: 3rem;
  color: var(--muted);
  font-size: var(--size-small);
}
.reader-foot:not(:empty) {
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
}

/* Dedication ---------------------------------------------- */
/* v4.25.0 (Book Module). The dedication renders through the reader
   shell's own dedication branch: label/caption pairs plus a closing
   line. Quiet and centered — the first page a reader sees. All colors
   are themed properties, so dark mode swaps them for free. */
.dedication {
  padding: 2.5rem 0 1rem;
}
.dedication-entry {
  margin: 0 0 1.7rem;
  text-indent: 0;
  text-align: center;
}
.ded-label {
  display: block;
  font-variant: small-caps;
  letter-spacing: 0.05em;
  font-size: var(--size-header);
  margin-bottom: 0.15rem;
}
.ded-caption {
  display: block;
  font-style: italic;
  color: var(--muted);
}
.dedication-close {
  margin: 3rem auto 0;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  max-width: 22em;
  text-indent: 0;
  text-align: center;
  font-style: italic;
  color: var(--muted);
  font-size: var(--size-small);
}

/* ---------------------------------------------------------- */
/* Reader controls + progress. The 5%. They serve the reading  */
/* and then get out of the way: fixed, muted, outside the      */
/* measure, and — critically — nothing animates on its own.    */
/* All colors are the themed properties, so dark mode swaps     */
/* them for free.                                              */
/* ---------------------------------------------------------- */

/* Progress: a 2px hairline at the very top. No transition, so
   it tracks the reader's scroll exactly instead of lagging. */
.reader-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;                  /* set by script, 0–100%            */
  height: 2px;
  background: var(--rule);
  z-index: 55;
}

/* Controls: a small, quiet cluster in the top corner. */
.reader-controls {
  position: fixed;
  top: 0.85rem;
  right: 0.85rem;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.reader-controls button {
  font-family: var(--font-body);
  font-size: var(--size-small);
  color: var(--muted);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 5px;
  min-width: 1.9rem;
  height: 1.75rem;
  padding: 0 0.4rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.reader-controls button:hover {
  color: var(--ink);
  border-color: var(--muted);
}
.reader-controls button:focus-visible {
  outline: 2px solid var(--muted);
  outline-offset: 1px;
}
.reader-controls .rc-minus { font-size: calc(var(--size-small) * 0.9); }
.reader-controls .rc-plus  { font-size: calc(var(--size-small) * 1.1); }
.reader-controls .rc-sign  { margin-left: 0.08em; }
.reader-controls .rc-theme svg { display: block; }

/* ---------------------------------------------------------- */
/* The one breakpoint that earns its place: below it, every    */
/* image drops out of the float and stacks full-width.         */
/* ---------------------------------------------------------- */
@media (max-width: 640px) {
  :root { --gutter: 1.25rem; }

  .reader-head { margin-top: 3rem; }

  .reader-controls { top: 0.6rem; right: 0.6rem; }

  .img-left,
  .img-right,
  .img-center {
    float: none;
    max-width: 100%;
    margin: 1.4em auto;
  }
}

/* Courtesy: honour reduced-motion (no motion here, but explicit) */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ============================================================
   Navigation layer — table of contents, prev/next, book-level
   position. Added in the reader-shell navigation session.
   Append-only: every rule above is untouched. Built entirely on
   the existing custom properties, so dark mode swaps for free.
   ============================================================ */

/* New themeable token: the modal scrim. Declared append-only so the
   original :root / dark blocks stay byte-for-byte unchanged. */
:root                    { --scrim: rgba(27, 27, 26, 0.45); }
html[data-theme="dark"]  { --scrim: rgba(0, 0, 0, 0.62); }

/* Book-level position — a quiet orienting line at the top of the
   opener. Muted and small; deliberately NOT tracked-uppercase like
   the chapter eyebrow, so the two read as different registers. */
.book-position {
  display: block;
  font-size: var(--size-small);
  color: var(--muted);
  margin-bottom: 0.9rem;
  letter-spacing: 0.01em;
}

/* The Contents button sits in the existing controls cluster and
   inherits .reader-controls button styling; only its icon needs a
   line-up. */
.reader-controls .rc-toc svg { display: block; }

/* Prev / next — a quiet pair at the foot, inside the measure so it
   aligns with the prose. An absent slot (Foreword has no previous,
   Epilogue no next) collapses to a hidden spacer so the present one
   keeps its side. */
.reader-nav {
  max-width: var(--measure);
  margin: 3rem auto 0;
  padding: 1.4rem var(--gutter) 0;
  border-top: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
}
.reader-nav .nav-side {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5em;
  max-width: 46%;
  font-size: var(--size-small);
  color: var(--muted);
  text-decoration: none;
}
.reader-nav a.nav-side { color: var(--ink); }
.reader-nav a.nav-side:hover .nav-label { text-decoration: underline; }
.reader-nav .nav-next { margin-left: auto; text-align: right; }
.reader-nav .nav-dir { color: var(--muted); }
.reader-nav .nav-side.is-unavailable { color: var(--muted); cursor: default; opacity: 0.75; }
.reader-nav .nav-spacer { visibility: hidden; }

/* Table of contents — modal overlay. Above the controls (z 60) and
   the progress hairline (z 55). Quiet: a scrim, a paper panel, one
   column of titles. */
.toc-overlay[hidden] { display: none; }
.toc-overlay { position: fixed; inset: 0; z-index: 80; }
.toc-backdrop { position: absolute; inset: 0; background: var(--scrim); }
.toc-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(30rem, calc(100vw - 2rem));
  max-height: min(80vh, 44rem);
  overflow-y: auto;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  padding: 1.4rem 1.5rem 1.6rem;
  outline: none;
}
.toc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}
.toc-title {
  margin: 0;
  font-size: var(--size-label);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.toc-close {
  font-family: var(--font-body);
  font-size: 1.2rem;
  line-height: 1;
  color: var(--muted);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 5px;
  width: 1.9rem;
  height: 1.75rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.toc-close:hover { color: var(--ink); border-color: var(--muted); }
.toc-close:focus-visible { outline: 2px solid var(--muted); outline-offset: 1px; }

.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-item { margin: 0; }
.toc-link {
  display: block;
  padding: 0.5rem 0.2rem;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
}
.toc-list .toc-item:last-child .toc-link { border-bottom: 0; }
a.toc-link:hover .toc-item-title { text-decoration: underline; }
a.toc-link:focus-visible { outline: 2px solid var(--muted); outline-offset: 2px; }
.toc-row { display: block; }
.toc-num {
  display: block;
  font-size: var(--size-label);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.1rem;
}
.toc-item-title { font-size: 1.02rem; }
.toc-item.is-current > .toc-link { font-weight: 700; cursor: default; }
.toc-item.is-unavailable > .toc-link { color: var(--muted); cursor: default; opacity: 0.7; }

@media (max-width: 640px) {
  .toc-panel {
    top: 0; left: 0;
    transform: none;
    width: 100%;
    height: 100%;
    max-height: 100%;
    border: 0;
    border-radius: 0;
  }
  .reader-nav { gap: 1rem; }
}
