/* ==========================================================================
   read.css — chapter content: prose, equations, tables, images
   ========================================================================== */

.chapter {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) var(--space-3);
}

.chapter-head {
  margin-bottom: var(--space-4);
}

.chapter-head .eyebrow { margin-bottom: var(--space-2); }

.chapter-body h2 {
  margin-top: var(--space-5);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-rule);
}

.chapter-body h3 { margin-top: var(--space-4); }

.chapter-body p,
.chapter-body li {
  font-size: var(--step-0);
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
}

.chapter-body ul,
.chapter-body ol {
  max-width: 68ch;
  padding-left: 1.3em;
}

/* ---- Equations ---- */
.equation {
  margin: var(--space-3) 0;
  padding: var(--space-2) var(--space-3);
  background: var(--color-bg-raised);
  border-left: 3px solid var(--color-brass);
}

.equation-inline {
  font-family: var(--font-mono);
}

/* Standalone display-equation paragraph (whole line is math) */
.chapter-body p.equation-line {
  text-align: center;
  margin: var(--space-3) 0;
}

.chapter-body p.equation-line.equation-line--left {
  text-align: left;
}

.chapter-body p.equation-line .katex-display,
.chapter-body p.equation-line .katex {
  white-space: normal;
}

/* Forces a single equation to stay on one physical line — used for long
   equations where shrinking alone isn't enough, since normal white-space
   lets the browser wrap at any operator regardless of font-size. */
.chapter-body p.equation-line.equation-line--nowrap .katex-display,
.chapter-body p.equation-line.equation-line--nowrap .katex {
  white-space: nowrap;
}

/* KaTeX display blocks get a little breathing room, no scrollbars — shrink-to-fit JS handles overflow */
.katex-display {
  margin: 0 !important;
}


/* ---- Inline data (replaces <table> for short recaps/lookups, keeps the
   immersive feel instead of a boxed grid — mirrors the cipher-sample
   label/text flex pattern used elsewhere) ---- */
.chapter-body .timeline {
  margin: var(--space-4) 0;
  max-width: 68ch;
  margin-left: auto;
  margin-right: auto;
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 1em;
  row-gap: var(--space-2);
}

.chapter-body .timeline-row {
  display: contents;
}

.chapter-body .timeline-year {
  grid-column: 1;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.85em;
  color: var(--color-brass);
  white-space: nowrap;
  align-self: baseline;
}

.chapter-body .timeline-desc {
  grid-column: 2;
  min-width: 0;
  text-align: justify;
  align-self: baseline;
}

.chapter-body .stat-pairs {
  display: grid;
  grid-template-columns: max-content max-content max-content;
  justify-content: center;
  align-items: baseline;
  column-gap: 0.6em;
  row-gap: 0.35em;
  margin: var(--space-3) auto;
  font-family: var(--font-mono);
  font-size: var(--step--1);
}

.chapter-body .stat-pairs:not(.stat-pairs--inline) .stat-row {
  display: contents;
}

.chapter-body .stat-pairs--inline {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: baseline;
  gap: 0.5em 2.5em;
}

.chapter-body .stat-pairs--inline .stat-row {
  display: flex;
  gap: 0.6em;
  margin: 0;
  white-space: nowrap;
}

.chapter-body .stat-pairs .stat-key {
  justify-self: end;
  font-weight: 700;
  color: var(--color-ink);
}

.chapter-body .stat-pairs .stat-arrow {
  justify-self: center;
  color: var(--color-ink-soft);
}

.chapter-body .stat-pairs .stat-value {
  justify-self: start;
  color: var(--color-accent);
}

.chapter-body .stat-lines {
  width: fit-content;
  margin: var(--space-3) auto;
  font-family: var(--font-mono);
  font-size: var(--step--1);
}

.chapter-body .stat-lines p {
  margin: 0;
  text-align: left;
}

.chapter-body .stat-lines p + p {
  margin-top: 0.35em;
}

/* Label/equation pairs, one <li> per label and one per value, laid out via
   grid on the <ul> itself — a grid container's children keep their own
   display (list-item), so the label items still get real, native bullets;
   only the value items opt out with list-style: none. The value column
   naturally lines up because it's a real grid column, sized to the
   longest label, rather than a per-row layout. */
.chapter-body ul.property-list {
  display: grid;
  grid-template-columns: max-content max-content;
  column-gap: 0.6em;
  row-gap: var(--space-2);
}

.chapter-body .property-list .property-label {
  grid-column: 1;
  align-self: baseline;
  text-align: left;
}

.chapter-body .property-list .property-value {
  grid-column: 2;
  align-self: baseline;
  list-style: none;
  text-align: left;
}

/* ---- Tables ---- */
.chapter-body table {
  width: auto;
  min-width: 40%;
  margin: var(--space-4) auto;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--step--1);
  border: 1px solid var(--color-rule);
  border-radius: var(--radius);
  overflow: hidden;
}

.chapter-body caption {
  text-align: center;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--color-ink-soft);
  margin-bottom: var(--space-1);
}

.chapter-body th,
.chapter-body td {
  padding: 0.55em 1.4em;
  border-bottom: 1px solid var(--color-rule);
  text-align: center;
}

.chapter-body th {
  font-family: var(--font-mono);
  text-transform: uppercase;
  font-size: 0.78em;
  letter-spacing: 0.05em;
  color: var(--color-header-ink);
  background: var(--color-header-bg);
  border-bottom: none;
}

.chapter-body tbody tr:nth-child(even) td {
  background: var(--color-bg-raised);
}

.chapter-body tbody tr:last-child td {
  border-bottom: none;
}

/* ---- Figures / images ---- */
.chapter-body figure {
  margin: var(--space-4) auto;
  max-width: 380px;
}

.chapter-body figure img {
  width: 100%;
  border: 1px solid var(--color-rule);
  border-radius: 2px;
}

.chapter-body figcaption {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--color-ink-soft);
  margin-top: var(--space-1);
  text-align: center;
}

/* ---- Cipher / code snippets ---- */
.chapter-body code,
.chapter-body pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.chapter-body pre {
  background: var(--color-bg-raised);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  overflow-x: auto;
  border: 1px solid var(--color-rule);
}

.chapter-body :not(pre) > code {
  background: var(--color-brass-soft);
  padding: 0.15em 0.4em;
  border-radius: 3px;
}

/* ---- Dialogue (Alice / Bob / Hanne script format) ---- */
.chapter-body p.dialogue {
  margin: 0 0 var(--space-2);
}

.chapter-body p.dialogue .speaker {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--color-ink);
  margin-right: 0.4em;
}

/* Stage directions / bracketed asides — left-justified, not centered */
.chapter-body p.stage-direction {
  font-style: italic;
  color: var(--color-ink-soft);
  text-align: left;
  margin: var(--space-2) 0;
}

/* ---- Song verses (e.g. Bob singing) — centred, tighter line spacing
   so consecutive verse lines read as one stanza. ---- */
.chapter-body p.dialogue.song {
  text-align: center;
  margin: var(--space-1) auto;
  max-width: 52ch;
}

.chapter-body p.dialogue.song .speaker {
  display: none;
}

/* ---- Cipher samples (plaintext/ciphertext demonstration lines) ---- */
/* Inline with the surrounding prose — monospace to mark it as cipher/plain text,
   but no box or background, so it reads as part of the scene rather than a code sample.
   Label sits in the normal text flow, same left margin as everything else. */
.chapter-body p.cipher-sample {
  font-family: var(--font-mono);
  font-size: 0.92em;
  color: var(--color-ink);
  text-align: justify;
  hyphens: none;
  -webkit-hyphens: none;
  font-feature-settings: "calt" 0, "liga" 0;
  font-variant-ligatures: none;
  line-height: 1.65;
  margin: var(--space-2) 0;
}

.chapter-body p.cipher-sample.cipher-sample--center {
  text-align: center;
}

.chapter-body p.cipher-sample.has-label {
  display: flex;
  align-items: baseline;
  gap: 0.5em;
}

.chapter-body p.cipher-sample .cipher-label {
  flex: 0 0 6.5em;
  font-weight: 700;
  color: var(--color-accent);
  white-space: nowrap;
}

.chapter-body p.cipher-sample .cipher-text {
  flex: 1 1 auto;
  min-width: 0;
  text-align: justify;
}

/* In-world quotes and epigraphs — light touch, no box, feels like part of the story */
.chapter-body p.quote,
.chapter-body div.quote {
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
  font-style: italic;
  font-weight: 400;
  font-family: var(--font-body);
  font-size: var(--step-0);
  color: var(--color-ink-soft);
  margin: var(--space-3) auto;
  max-width: 58ch;
  padding: 0 var(--space-2);
}

/* When a quote is a multi-paragraph block (div.quote with inner <p>s),
   give the inner paragraphs a small gap instead of the full paragraph
   margin, so multiple short lines don't stack a huge gap between them. */
.chapter-body div.quote p {
  margin: 0 0 var(--space-2);
  text-align: justify;
}

.chapter-body div.quote p:last-child {
  margin-bottom: 0;
}

/* ---- Speech excerpts (e.g. Churchill quotations) — indented block,
   left-aligned, with an ellipsis marker between non-contiguous passages ---- */
.chapter-body .speech-excerpt {
  margin: var(--space-4) auto;
  max-width: 62ch;
  padding: var(--space-3) var(--space-4);
  border-left: 3px solid var(--color-brass);
  background: var(--color-bg-raised);
}

.chapter-body .speech-excerpt p {
  text-align: left;
  font-style: italic;
  color: var(--color-ink-soft);
  margin: 0 0 var(--space-2);
}

.chapter-body .speech-excerpt p:last-child { margin-bottom: 0; }

.chapter-body .speech-excerpt .excerpt-ellipsis {
  text-align: center;
  font-style: normal;
  color: var(--color-ink-soft);
  opacity: 0.6;
  margin: var(--space-1) 0;
}

/* ---- Prompt suggestions (e.g. "try asking your chatbot this") —
   distinct from speech-excerpt: not a quotation, so no italic voice.
   Subtle neutral tint (not brass, not loud accent) so it reads as a
   distinct block without a meta label breaking the story's voice. ---- */
.chapter-body .prompt-suggestion {
  margin: var(--space-4) auto;
  max-width: 62ch;
  padding: var(--space-3) var(--space-4);
  border-left: 3px solid var(--color-rule);
  background: var(--color-bg-raised);
}

.chapter-body .prompt-suggestion p {
  text-align: left;
  font-style: normal;
  color: var(--color-ink);
  margin: 0 0 var(--space-2);
}

.chapter-body .prompt-suggestion p:last-child { margin-bottom: 0; }

/* ---- Chat transcripts (e.g. ELIZA/PARRY excerpts) — same indented-block
   treatment as speech-excerpt, but each line pairs a speaker label with
   their text so it reads like a transcript rather than a run-on paragraph ---- */
.chapter-body .chat-transcript {
  margin: var(--space-4) auto;
  max-width: 62ch;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  background: var(--color-bg-raised);
  font-family: var(--font-mono);
  font-size: 0.85em;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.chapter-body .chat-transcript .ct-line {
  display: flex;
  gap: 0.7em;
  align-items: baseline;
}

.chapter-body .chat-transcript .ct-speaker {
  flex: 0 0 var(--speaker-col-width, auto);
  font-weight: 700;
  color: var(--color-accent);
  white-space: nowrap;
}

.chapter-body .chat-transcript .ct-text {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--color-ink);
  text-align: left;
}

.chapter-body .chat-transcript .ct-line:has(.ct-ellipsis) {
  justify-content: center;
}

.chapter-body .chat-transcript .ct-ellipsis {
  color: var(--color-ink-soft);
  opacity: 0.6;
}

/* Scene-setting narrative prose — subtly softer than dialogue, a small breath before/after */
.chapter-body p.narrative {
  color: var(--color-ink-soft);
  line-height: 1.75;
  margin: var(--space-2) 0;
}

/* ---- Short inscriptions (e.g. words appearing in flame, carved text) —
   centred rather than justified, and tighter spacing when several
   appear consecutively (like a short list of words). ---- */
.chapter-body p.quote.quote--inscription {
  text-align: center;
  padding: 0;
  margin: var(--space-2) auto;
}

.chapter-body p.quote.quote--inscription + p.quote.quote--inscription {
  margin-top: var(--space-1);
}

.table-row-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-4);
  margin: var(--space-4) 0;
}

.table-row-group table {
  margin: 0;
}

/* ---- Callouts (definitions, notes, worked examples) ---- */
.callout {
  margin: var(--space-4) 0;
  padding: var(--space-3);
  border: 1px solid var(--color-rule);
  border-left: 3px solid var(--color-accent);
  background: var(--color-bg-raised);
  border-radius: var(--radius);
}

.callout .eyebrow { margin-bottom: 0.4em; }
.callout p:last-child { margin-bottom: 0; }


/* ---- References section ---- */
.references {
  text-align: left;
}

.references h2,
.references h3 {
  text-align: left;
  margin-top: var(--space-5);
  margin-bottom: var(--space-3);
}

.references h3:first-child {
  margin-top: 0;
}

.references ol {
  padding-left: 1.5rem;
  margin: 0 0 var(--space-4);
}

.references li {
  margin-bottom: var(--space-2);
  line-height: 1.7;
  text-align: left;
}

.references a {
  word-break: normal;
  overflow-wrap: break-word;
}