/* =========================================================================
   Le Avventure di Carletto — Premium Reader v6 (ibrido cinematico+editorial)
   v6 = chapter cards cinematiche full-bleed + editoriale McSweeney's nel body.
   Riferimento autoritativo: visual_direction-v2.md + ux_spec-v2.md.

   Allineamento al telaio (sprint home-restyle): allineato `--paper` al token
   crema-carta `#F4ECD8` di `_shared/theme.css`, e `--font-display` portato a
   **Fraunces** (preset display del telaio) con Cormorant come fallback.
   ALTRI token (--ink, --rust, --paper-shadow, --ink-sepia, --ink-marginalia,
   --font-body EB Garamond) intenzionalmente PRESERVATI: il reader è la
   superficie di lettura ed è il pezzo più riuscito del sistema. La sua palette
   warm-cocoa + accenti rust e il body EB Garamond ricaduto sull'opsz sono
   tarati per leggibilità; il telaio è "compatibile per famiglia" ma non
   identico, e questa pagina mantiene la sua voce. La dark mode in
   `_shared/dark-mode.css` resta valida perché i NOMI delle variabili non
   cambiano (solo --paper trasla di 2-4 unità RGB su crema, impercettibile).
   ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght,SOFT,WONK@9..144,400..600,30..100,0..1&display=swap');

/* -- 1. Tokens (AD v2 §2) ------------------------------------------------ */
:root {
  --paper:           #F4ECD8; /* allineato a telaio --carta-500 */
  --paper-shadow:    #EAD9B8; /* preservato: tan caldo per elevazione */
  --ink:             #2A1F17; /* preservato: cocoa warm, ottimo per long-form */
  --ink-sepia:       #5C4632;
  --ink-marginalia:  #8A6F4E; /* deprecato testo, vivo per glyph decorativi */
  --rust:            #A03A2C; /* preservato: identità storica del reader */

  --font-display: 'Fraunces', 'Cormorant Garamond', 'Garamond', serif;
  --font-body:    'EB Garamond', 'Garamond', Georgia, serif;
  --font-hand:    'Caveat', 'Segoe Script', cursive;
  --font-mono:    'Special Elite', 'Courier New', monospace;
}

/* -- 2. Reset / base ---------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; overflow-x: hidden; }
/* Failsafe: <html> overflow-x:hidden clips horizontal overflow from off-screen
   transformed elements (e.g. closed .toc-overlay drawer at translateX(100%)).
   Without this, mobile browsers allow horizontal scroll of the body even with
   body{overflow-x:hidden}, cutting body text on the right edge. */

/* Paper texture SVG noise inline — AD v2 §4.5
   Opacity baked in feColorMatrix (alpha 0.04). ~480 byte, gzip ~280 byte.
   Texture sottile percepibile come trama, invisibile come pattern. */
body {
  margin: 0;
  padding: 0;
  background-color: var(--paper);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240' viewBox='0 0 240 240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch' seed='4'/><feColorMatrix values='0 0 0 0 0.15  0 0 0 0 0.10  0 0 0 0 0.06  0 0 0 0.04 0'/></filter><rect width='240' height='240' filter='url(%23n)'/></svg>");
  background-repeat: repeat;
  background-size: 240px 240px;
  color: var(--ink);
  font-family: var(--font-body);
  /* Body clamp esteso fino a 4K (AD v2 §3.7) */
  font-size: clamp(1.02rem, 0.32vw + 0.96rem, 1.22rem);
  line-height: 1.62;
  font-feature-settings: "liga", "kern", "onum";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden; /* protezione da bleed che genera scroll laterale */
}

img { max-width: 100%; height: auto; display: block; }

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

a:focus-visible, button:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--ink-sepia);
  outline-offset: 2px;
  border-radius: 1px;
}

/* Text-style buttons (no fills, no radii, no shadows) */
.btn-text {
  background: transparent;
  border: 0;
  padding: 0.6rem 0.4rem;
  font-family: var(--font-display);
  font-size: clamp(1.1rem, 0.4vw + 1rem, 1.35rem);
  font-weight: 400;
  font-style: italic;
  color: var(--ink);
  cursor: pointer;
  letter-spacing: 0.01em;
  min-height: 44px;
  line-height: 1.4;
}
.btn-text em { font-style: italic; }
.btn-text:hover { color: var(--rust); }

.btn-icon {
  background: transparent;
  border: 0;
  padding: 0;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--ink-sepia);
  font-size: 1.5rem;
  font-family: var(--font-display);
}
.btn-icon:hover { color: var(--ink); }

[hidden] { display: none !important; }

/* -- 3. Cover screen (splash) ------------------------------------------- */
.cover-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--paper);
  overflow-y: auto;
  display: flex;
  align-items: safe center;
  justify-content: center;
  padding: clamp(1.6rem, 4vw, 4rem) clamp(1rem, 3vw, 3rem);
  transition: opacity 600ms ease, transform 600ms ease;
}
.cover-screen[data-state="dismissing"] {
  opacity: 0;
  transform: scale(1.02);
  pointer-events: none;
}
.cover-screen[data-state="hidden"] { display: none; }

.cover-screen__inner {
  max-width: 520px;
  width: 100%;
  text-align: center;
}

.cover-screen__frame {
  margin: 0 auto 1.8rem;
  max-width: min(360px, 46vh);
  padding: 12px;
  border: 1px solid var(--ink-sepia);
  outline: 1px solid var(--ink-sepia);
  outline-offset: 6px;
  background: var(--paper);
}

.cover-screen__img {
  display: block;
  width: 100%;
  height: auto;
}

.cover-screen__eyebrow {
  font-family: var(--font-body);
  font-size: 0.78rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  font-feature-settings: "smcp", "c2sc";
  color: var(--ink-sepia);
  margin: 1.6rem 0 0.4rem;
}

.cover-screen__title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(2rem, 3.4vw + 1rem, 3.4rem);
  letter-spacing: 0.01em;
  line-height: 1.05;
  color: var(--ink);
  margin: 0.4rem auto 0.2rem;
  max-width: 16ch;
}

.cover-screen__subtitle {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 1.1rem;
  letter-spacing: 0.18em;
  color: var(--ink-sepia);
  margin: 0.4rem 0 1.2rem;
}

.cover-screen__dedication {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--ink-sepia);
  margin: 0 0 2rem;
}

.cover-screen__actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  margin-bottom: 2rem;
}

.cover-resume {
  margin-top: 1.4rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--ink-sepia);
  border-top-style: dotted;
}
.cover-resume__text {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 0.98rem;
  color: var(--ink-sepia);
  margin: 0 0 0.6rem;
}
.cover-resume__title { font-style: italic; color: var(--ink); }
.cover-resume__actions {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* -- 4. Scroll progress + sticky band (v6: folio in title, blur) -------- */
.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 1.5px;
  width: 0%;
  background: var(--rust);
  z-index: 201; /* sopra la sticky band */
  transition: width 100ms linear;
}

.sticky-band {
  position: fixed;
  top: 1.5px; /* lascia respiro alla progress bar */
  left: 0;
  right: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem clamp(0.8rem, 2vw, 1.6rem);
  background: rgba(242, 232, 213, 0.92);
  /* AD v2 §6.10 — eccezione don't glassmorphism (unica, documentata) */
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(92, 70, 50, 0.25);
  min-height: 48px;
  transition: opacity 250ms ease;
}
.sticky-band[data-state="hidden"] { display: none; }
.sticky-band__title {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  color: var(--ink);
  opacity: 0;
  transition: opacity 250ms ease;
  text-align: center;
  flex: 1;
  padding: 0 0.6rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.sticky-band.show-chapter-title .sticky-band__title { opacity: 1; }

/* Accessibility — degrade blur on reduced-transparency (Safari iOS) */
@media (prefers-reduced-transparency: reduce) {
  .sticky-band {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(242, 232, 213, 0.98);
  }
}

/* -- 5. ToC overlay (invariato) ---------------------------------------- */
.toc-overlay {
  position: fixed;
  inset: 0;
  z-index: 220;
  pointer-events: none;
}
.toc-overlay[data-state="open"] { pointer-events: auto; visibility: visible; }
.toc-overlay[data-state="closed"] { visibility: hidden; }

.toc-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(42, 31, 23, 0.42);
  opacity: 0;
  transition: opacity 300ms ease;
}
.toc-overlay[data-state="open"] .toc-backdrop { opacity: 1; }

.toc-panel {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: min(88vw, 380px);
  background: var(--paper);
  border-left: 1px solid var(--ink-sepia);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 350ms ease;
  overflow: hidden;
}
.toc-overlay[data-state="open"] .toc-panel { transform: translateX(0); }

.toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.2rem 0.6rem;
  border-bottom: 1px solid rgba(92, 70, 50, 0.3);
}
.toc-title {
  font-family: var(--font-body);
  font-size: 0.78rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  font-feature-settings: "smcp", "c2sc";
  color: var(--ink-sepia);
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0.4rem 0 2rem;
  overflow-y: auto;
  flex: 1;
}
.toc-item {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
  width: 100%;
  background: transparent;
  border: 0;
  border-bottom: 1px solid rgba(92, 70, 50, 0.18);
  text-align: left;
  padding: 0.85rem 1.2rem;
  cursor: pointer;
  font-family: var(--font-body);
  color: var(--ink);
  min-height: 56px;
}
.toc-item:hover { background: var(--paper-shadow); }
.toc-item--active { border-left: 2px solid var(--rust); padding-left: calc(1.2rem - 2px); }

.toc-item__cover {
  width: 56px;
  height: 72px;
  flex-shrink: 0;
  border: 1px solid var(--ink-sepia);
  background: var(--paper-shadow);
  overflow: hidden;
}
.toc-item__cover img { width: 100%; height: 100%; object-fit: cover; }

.toc-item__body { flex: 1; min-width: 0; }
.toc-item__folio {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 1rem;
  letter-spacing: 0.18em;
  color: var(--ink-sepia);
  margin: 0 0 0.15rem;
}
.toc-item__title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.2;
  margin: 0 0 0.2rem;
}
.toc-item__meta {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 0.82rem;
  color: var(--ink-sepia);
}

.toc-item--mini { min-height: 44px; }
.toc-item--mini .toc-item__title {
  font-style: italic;
  font-size: 1rem;
}

/* -- 6. Reader layout — multi-viewport (AD v2 §7, UX v2 §6) ------------- */
.reader {
  /* Fluid: 720px su laptop piccoli → 1400px su 4K (AD v2 §7.1) */
  max-width: clamp(720px, 90vw, 1400px);
  margin: 0 auto;
  padding: clamp(2rem, 5vw, 5rem) clamp(1.2rem, 4vw, 3rem) 5rem;
}

/* -- robustness hardening (text-scaling/viewport safe) --
   Root cause: at ≥190% OS text scaling on narrow viewport (393px), the single
   1fr track can be blown out by a wide child. minmax(0,1fr) constrains it.
   Consistent with the ≥1024 two-column rule which already uses minmax(0,1fr). */
.chapter {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  position: relative;
}

/* desktop two-column with marginalia rail (≥1024 ora, era 900 in v5) */
@media (min-width: 1024px) {
  .chapter {
    grid-template-columns: minmax(0, 1fr) 232px;
    column-gap: 32px;
  }
  /* full-width descendants span both columns */
  .chapter > .chapter-hero,
  .chapter > .frontispiece,
  .chapter > .culdelampe-wrap,
  .chapter > .chapter-nav,
  .chapter > .illustration--full {
    grid-column: 1 / -1;
  }
  .chapter > aside.marginalia {
    grid-column: 2;
    align-self: start;
  }
  .chapter > h2,
  .chapter > .folio,
  .chapter > .reading-time,
  .chapter > p,
  .chapter > blockquote.pull-quote,
  .chapter > .illustration--right-bleed,
  .chapter > .illustration--centered,
  .chapter > .illustration,
  .chapter > hr.break,
  .chapter > .marginalia-inline {
    grid-column: 1;
  }
}

/* Marginalia rail collapse — sotto 1024 marginalia diventa <details> inline */
@media (max-width: 1023px) {
  .chapter > aside.marginalia { display: none; }
}

/* -- 6b. Chapter hero wrapper full-bleed (AD v2 §6.1, UX v2 §5) -------- */
/* L'engine wrappa section.chapter-cover + h1 dentro div.chapter-hero.
   100vw bleed via left: 50% + transform — robusto a ogni padding del reader. */
.chapter-hero {
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  width: 100vw;
  max-width: 100vw;
  margin: 0 0 0; /* il frontispizio sotto gestisce il bottom rhythm */
  overflow: hidden;
  background-color: var(--ink); /* fallback durante il load dell'immagine */
}

.chapter-hero .chapter-cover {
  /* Override stili v5: niente cornice, niente max-width, full-bleed reale. */
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  width: 100%;
  height: clamp(50vh, 65vh, 75vh);
  max-height: 1080px;
  position: relative;
}
.chapter-hero .chapter-cover::after { content: none; } /* rimuove hairline v5 */

.chapter-hero .chapter-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 30%; /* favorisce la parte alta della tavola */
}

/* Overlay gradient bottom — eccezione don't gradient AD v2 §10
   leggibility del titolo sopraimpresso. */
.chapter-hero .chapter-cover__overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(42, 31, 23, 0) 0%,
    rgba(42, 31, 23, 0) 55%,
    rgba(42, 31, 23, 0.5) 90%,
    rgba(42, 31, 23, 0.65) 100%
  );
  pointer-events: none;
}

/* Titolo H1 sopraimpresso — bottom-center, cream, text-shadow legibility */
.chapter-hero .chapter-cover__title {
  position: absolute;
  left: 0;
  right: 0;
  bottom: clamp(2rem, 5vh, 5rem);
  padding: 0 clamp(1.2rem, 6vw, 5rem);
  text-align: center;
  z-index: 2;
}

.chapter-hero .chapter-cover__title h1 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(2.6rem, 5vw + 1rem, 5.4rem);
  line-height: 1.05;
  letter-spacing: 0.01em;
  color: var(--paper);
  /* AD v2 §3.8 — eccezione don't shadow (unica, legibility booster) */
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6), 0 1px 0 rgba(42, 31, 23, 0.25);
  margin: 0 auto;
  max-width: 22ch;
}

/* -- 6c. Frontispizio sotto-cover (AD v2 §6.2-bis) --------------------- */
.frontispiece {
  text-align: center;
  margin: clamp(2rem, 4vw, 3.2rem) auto clamp(2.4rem, 5vw, 4rem);
  max-width: 32ch;
  padding: clamp(0.4rem, 1vw, 1rem) 0;
}

.frontispiece .folio {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 1.1rem;
  letter-spacing: 0.22em;
  color: var(--ink-sepia);
  margin: 0 0 0.8rem;
}

.frontispiece .eyebrow--small {
  font-family: var(--font-body);
  font-size: 0.72rem;
  letter-spacing: 0.36em;
  text-transform: uppercase;
  font-feature-settings: "smcp", "c2sc";
  color: var(--ink-sepia);
  margin: 0 0 0.9rem;
}

.frontispiece .readtime {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 0.92rem;
  color: var(--ink-sepia);
  opacity: 0.75;
  margin: 0;
}

/* H2 / folio / reading-time della v5 vengono nascosti quando esiste .frontispiece
   (l'engine v6 inietta il frontispizio e marca col data-attr per stile) */
.chapter[data-has-frontispiece="true"] > h2,
.chapter[data-has-frontispiece="true"] > .folio,
.chapter[data-has-frontispiece="true"] > .reading-time { display: none; }

/* -- 7. Headings (legacy v5 — usati solo per intro/colophon) ----------- */
.chapter h1 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(2.4rem, 4.2vw + 1rem, 4.2rem);
  letter-spacing: 0.01em;
  line-height: 1.05;
  color: var(--ink);
  text-align: center;
  margin: 0.6rem auto 0;
  max-width: 18ch;
}

.chapter h2 {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.78rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  font-feature-settings: "smcp", "c2sc";
  color: var(--ink-sepia);
  text-align: center;
  margin: 0.6rem 0 1.6rem;
}
.chapter h2::before, .chapter h2::after {
  content: "—";
  display: inline-block;
  margin: 0 0.6em;
  opacity: 0.6;
}

/* Folio + reading-time legacy (mostrate solo se manca frontispizio) */
.chapter .folio {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 1.05rem;
  letter-spacing: 0.18em;
  text-align: center;
  color: var(--ink-sepia);
  margin: 1.6rem 0 0.4rem;
}
.chapter .reading-time {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 0.92rem;
  color: var(--ink-sepia);
  text-align: center;
  margin: 0 0 2.4rem;
}

/* -- 8. Body paragraphs (AD v2 §7.2) ----------------------------------- */
/* -- robustness hardening (text-scaling/viewport safe) --
   text-align:justify causes word-scatter at narrow/scaled columns (2–3 words
   spanning full line width). Replaced with left for robustness.
   overflow-wrap:anywhere + hyphens:auto prevent long uppercase tokens
   (FRITTATA STREGATAAAA, QUARANTASETTE, onomatopoeia) from clipping/overflowing
   the right edge at 190% text scaling. -webkit-hyphens kept for Safari/iOS. */
.chapter p {
  max-width: 64ch;
  margin: 0 0 1rem;
  text-align: left;
  hyphens: auto;
  -webkit-hyphens: auto;
  hyphenate-limit-chars: 6 3 3;
  hyphenate-limit-lines: 2;
  overflow-wrap: anywhere;
  text-indent: 0;
}
@supports not (hyphens: auto) {
  .chapter p { text-align: left; }
}

/* indent on consecutive narrative paragraphs */
.chapter p + p:not(.sound):not(.dialogue):not(.folio):not(.reading-time) {
  text-indent: 1.6em;
}
.chapter aside.marginalia + p:not(.sound):not(.dialogue):not(.folio):not(.reading-time) {
  text-indent: 1.6em;
}
.chapter p.dialogue + p:not(.dialogue):not(.sound) { text-indent: 0; }
.chapter p.sound + p:not(.sound):not(.dialogue) { text-indent: 0; }

/* Reset indent dopo elementi a piena larghezza (AD v2 §7.3) */
.pull-quote + p,
.illustration--full + p,
.illustration--right-bleed + p,
.illustration--centered + p,
.chapter > .illustration + p {
  text-indent: 0;
}

/* drop cap target paragraph: no indent */
.chapter > p.dropcap-target { text-indent: 0 !important; }

.chapter strong { font-weight: 600; }
.chapter em { font-style: italic; }

/* -- 9. Drop cap — fill cream-shadow DEFAULT (AD v2 §4.1-bis) ---------- */
.chapter > p.dropcap-target::first-letter {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(4.6rem, 8vw + 1rem, 7.8rem);
  line-height: 0.82;
  float: left;
  padding: 0.14em 0.18em 0.04em 0.14em;
  margin: 0.04em 0.14em 0 0;
  color: var(--ink);
  background: var(--paper-shadow); /* peso ottico subliminale */
}

/* -- 10. Dialogue with speaker medallion -------------------------------- */
/* -- robustness hardening (text-scaling/viewport safe) --
   overflow-wrap:anywhere inherited from .chapter p but restated explicitly
   here for clarity — dialogue bold text contains long uppercase onomatopoeia. */
.chapter p.dialogue {
  position: relative;
  margin: 1rem 0;
  padding-left: 2.4rem;
  text-indent: 0;
  line-height: 1.7;
  overflow-wrap: anywhere;
  hyphens: auto;
  -webkit-hyphens: auto;
}
.chapter p.dialogue::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.35em;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--ink-sepia);
  background-image: var(--speaker-img);
  background-size: cover;
  background-position: center;
  background-color: var(--paper-shadow);
}
/* Failsafe: dialoghi senza speaker (orphan all'inizio capitolo o cori di gruppo).
   Nasconde badge + rimuove padding-left per evitare il cerchio vuoto outlined. */
.chapter p.dialogue.dialogue--no-speaker {
  padding-left: 0;
}
.chapter p.dialogue.dialogue--no-speaker::before {
  display: none;
}

/* -- 11. Sound effect -------------------------------------------------- */
/* -- robustness hardening (text-scaling/viewport safe) --
   .sound is uppercase centered mono — no justify issue. However uppercase
   onomatopoeia tokens (STREGATAAAA, QUARANTASETTE) can overflow right edge at
   190% text scaling without overflow-wrap. Added to prevent horizontal clip. */
.chapter p.sound {
  font-family: var(--font-mono);
  font-size: clamp(1.4rem, 1.5vw + 1rem, 2rem);
  letter-spacing: 0.08em;
  color: var(--rust);
  text-align: center;
  margin: 1.6rem 0;
  text-transform: uppercase;
  text-indent: 0;
  line-height: 1.2;
  max-width: none;
  overflow-wrap: anywhere;
}

/* -- 12. Illustration — tre varianti regia (AD v2 §6.6, UX v2 §2) ----- */

/* Base reset: rimuove cornice double-rule v5 per chiunque non abbia ancora
   ricevuto una classe modifier (early paint state, sicurezza). */
.chapter .illustration {
  margin: 2.4rem auto;
  max-width: 100%;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
}
.chapter .illustration img {
  display: block;
  width: 100%;
  height: auto;
}
.chapter .illustration figcaption,
.chapter .illustration + p.caption {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 0.92rem;
  color: var(--ink-sepia);
  text-align: center;
  margin: 0.6rem auto 0;
  max-width: 64ch;
}

/* 12.A — full-bleed 100vw — sfora il reader column */
.chapter .illustration--full {
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  width: 100vw;
  max-width: 100vw;
  margin-top: 3.6rem;
  margin-bottom: 3.6rem;
  padding: 0;
  border: 0;
  background: var(--paper);
}
.chapter .illustration--full img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 80vh;
  object-fit: contain;
  background: var(--paper);
}
.chapter .illustration--full figcaption,
.chapter .illustration--full + p.caption {
  text-align: center;
  max-width: 64ch;
  margin: 0.8rem auto 0;
  padding: 0 clamp(1.2rem, 4vw, 3rem);
}

/* 12.B — right-bleed asymmetric, body wrap left */
.chapter .illustration--right-bleed {
  float: right;
  width: 60%;
  max-width: 720px;
  margin: 0.6rem -4rem 1.4rem 2rem;
  background: transparent;
  border: 0;
  padding: 0;
}
.chapter .illustration--right-bleed img {
  display: block;
  width: 100%;
  height: auto;
  background: var(--paper);
  filter: saturate(0.95);
}
.chapter .illustration--right-bleed figcaption {
  text-align: right;
  margin: 0.4rem 0 0;
  padding-right: 0.4rem;
}

/* Su 4K il bleed verso destra è più drammatico */
@media (min-width: 1440px) {
  .chapter .illustration--right-bleed {
    margin-right: -8rem;
  }
}

/* Sotto 1024 il right-bleed perde drama → diventa centered */
@media (max-width: 1023px) {
  .chapter .illustration--right-bleed {
    float: none;
    width: 100%;
    max-width: 720px;
    margin: 2rem auto;
  }
  .chapter .illustration--right-bleed figcaption { text-align: center; }
}

/* 12.C — centered sobrio: hairline 30% sepia sopra/sotto, NO double-rule */
.chapter .illustration--centered {
  margin: 3rem auto;
  max-width: 720px;
  padding: 0;
  background: transparent;
  border: 0;
  position: relative;
}
.chapter .illustration--centered::before,
.chapter .illustration--centered::after {
  content: "";
  display: block;
  height: 1px;
  background: var(--ink-sepia);
  opacity: 0.4;
  margin: 0 auto;
}
.chapter .illustration--centered::before { margin-bottom: 1rem; width: 30%; }
.chapter .illustration--centered::after { margin-top: 1rem; width: 30%; }
.chapter .illustration--centered img {
  display: block;
  width: 100%;
  height: auto;
  background: var(--paper);
  filter: saturate(0.95) contrast(1.01);
}
.chapter .illustration--centered figcaption,
.chapter .illustration--centered + p.caption {
  text-align: center;
  margin: 0.8rem auto 0;
  max-width: 56ch;
}

/* Mobile <600 illustration regia: tutte diventano "tavole editoriali" con
   hairline top/bottom + max-height per non bombardare scroll + spacing ampio.
   Era "block full-width senza ancore" v6 — sembravano foto. */
@media (max-width: 599px) {
  .chapter .illustration,
  .chapter .illustration--full,
  .chapter .illustration--right-bleed,
  .chapter .illustration--centered {
    margin: 2.6rem auto;
    width: 100%;
    max-width: 100%;
    padding: 0;
    position: relative;
    left: auto;
    transform: none;
    float: none;
  }
  .chapter .illustration::before,
  .chapter .illustration--full::before,
  .chapter .illustration--right-bleed::before,
  .chapter .illustration--centered::before {
    content: "";
    display: block;
    height: 1px;
    background: var(--ink-sepia);
    opacity: 0.4;
    width: 30%;
    margin: 0 auto 1rem;
  }
  .chapter .illustration::after,
  .chapter .illustration--full::after,
  .chapter .illustration--right-bleed::after,
  .chapter .illustration--centered::after {
    content: "";
    display: block;
    height: 1px;
    background: var(--ink-sepia);
    opacity: 0.4;
    width: 30%;
    margin: 1rem auto 0;
  }
  .chapter .illustration img {
    max-height: 50vh; /* limit verticale: lo scroll non si fa bombardare */
    object-fit: contain;
    background: var(--paper);
    width: 100%;
    height: auto;
  }
}

/* -- 13. Vignette — regia rotazione CSS pure (AD v2 §6.7) -------------- */
/* Nota: l'xhtml ha già class="vignette vignette--right" hardcoded. La
   rotazione qui sotto sovrascrive via specificità + nth-of-type — no JS. */

.chapter span.vignette {
  display: block;
  margin: 0.2em 0 0.4em 1em;
  width: 33%;
  max-width: 220px;
  clear: both;
}
.chapter span.vignette img {
  display: block;
  width: 100%;
  height: auto;
  filter: saturate(0.92) contrast(1.02);
}

/* 1ª vignette del capitolo: float LEFT */
.chapter span.vignette:nth-of-type(3n+1) {
  float: left;
  margin: 0.2em 1em 0.4em 0;
  width: 33%;
  max-width: 220px;
  clear: left;
}
/* 2ª vignette: float RIGHT (standard) */
.chapter span.vignette:nth-of-type(3n+2) {
  float: right;
  margin: 0.2em 0 0.4em 1em;
  width: 33%;
  max-width: 220px;
  clear: right;
}
/* 3ª vignette: drop-block centered con hairline sotto */
.chapter span.vignette:nth-of-type(3n+3) {
  float: none;
  display: block;
  margin: 1.6rem auto;
  width: 50%;
  max-width: 320px;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid rgba(92, 70, 50, 0.35);
  clear: both;
}

.chapter span.vignette + span.vignette { margin-top: 0.4em; }

/* Mobile <600: vignette restano accent inline float, side-by-side se consecutive.
   Era block 70% centered v5 — troppo dominanti, sembravano foto. Ora 45% float right.
   Doppie consecutive (es. cap_01 cappello+bacchetta) si dispongono fianco a fianco. */
@media (max-width: 599px) {
  .chapter span.vignette,
  .chapter span.vignette:nth-of-type(3n+1),
  .chapter span.vignette:nth-of-type(3n+2),
  .chapter span.vignette:nth-of-type(3n+3) {
    float: right;
    display: block;
    margin: 0.3em 0 0.6em 0.6em;
    width: 45%;
    max-width: 150px;
    border-bottom: 0;
    padding-bottom: 0;
    clear: none;
  }
  /* due vignette consecutive nello stesso <p>: side-by-side */
  .chapter span.vignette + span.vignette {
    margin-left: 0.4em;
    margin-top: 0.3em;
  }
  /* il paragrafo dopo le vignette deve consentire il flow */
  .chapter span.vignette:last-of-type {
    margin-bottom: 0.4em;
  }

  /* Paragrafo con 2+ vignette: le vignette diventano "riga" sopra il testo.
     Float a 90% combinato schiacciava il body in colonnina inutilizzabile.
     Soluzione: float left 47% cad → 2 affiancate top + clear:both per il testo. */
  .chapter .p--multi-vignette {
    overflow: hidden; /* clearfix container */
  }
  .chapter .p--multi-vignette span.vignette,
  .chapter .p--multi-vignette span.vignette:nth-of-type(3n+1),
  .chapter .p--multi-vignette span.vignette:nth-of-type(3n+2),
  .chapter .p--multi-vignette span.vignette:nth-of-type(3n+3) {
    float: left;
    display: block;
    width: 47%;
    max-width: 47%;
    margin: 0 1.5% 0.8em 1.5%;
    clear: none;
  }
  .chapter .p--multi-vignette span.vignette:first-of-type {
    margin-left: 0;
  }
  .chapter .p--multi-vignette span.vignette:last-of-type {
    margin-right: 0;
  }
}

/* -- 14. hr.break — scene-divider rotazione (invariato v5) ------------- */
.chapter hr.break {
  border: 0;
  text-align: center;
  margin: 2.4rem 0;
  height: auto;
  overflow: visible;
  max-width: 64ch;
}
.chapter hr.break::before {
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--ink-sepia);
  letter-spacing: 0.4em;
  display: inline-block;
}
.chapter hr.break:nth-of-type(3n+1)::before { content: "❦"; }
.chapter hr.break:nth-of-type(3n+2)::before { content: "⁂"; }
.chapter hr.break:nth-of-type(3n+3)::before { content: "❧"; }

/* -- 15. Marginalia v6 — rinforzate (AD v2 §5) ------------------------- */
/* -- robustness hardening (text-scaling/viewport safe) --
   Marginalia rail is 200px max-width — at high text scaling long handwritten
   words can overflow its narrow column. overflow-wrap:anywhere + hyphens prevent
   horizontal clip. */
.chapter aside.marginalia {
  font-family: var(--font-hand);
  font-weight: 400;
  font-size: clamp(1.02rem, 0.32vw + 0.94rem, 1.18rem);
  line-height: 1.45;
  color: var(--ink-sepia); /* promosso da --ink-marginalia faded → 6.9:1 */
  max-width: 200px;
  padding-left: 1.4em;
  border-left: 2px solid var(--rust); /* anchor visivo */
  margin: 0.4rem 0;
  position: relative;
  overflow-wrap: anywhere;
  hyphens: auto;
  -webkit-hyphens: auto;
}
.chapter aside.marginalia::before {
  content: "※";
  position: absolute;
  left: -1.6em;
  top: 0.08em;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--ink-marginalia); /* ok faded — è solo glyph decorativo */
  opacity: 0.5;
}
.chapter aside.marginalia cite {
  display: block;
  margin-top: 0.3em;
  font-style: italic;
  font-size: 0.88rem;
  color: var(--ink-sepia);
  opacity: 0.85;
  font-family: var(--font-body);
}

/* Marginalia inline su mobile/tablet (details) */
.chapter details.marginalia-inline {
  margin: 1rem 0;
  padding: 0.6rem 0.9rem 0.6rem 1rem;
  background: var(--paper-shadow);
  border-left: 2px solid var(--rust);
  font-family: var(--font-hand);
  font-size: 1.08rem;
  color: var(--ink-sepia);
  line-height: 1.45;
  max-width: 64ch;
}
.chapter details.marginalia-inline summary {
  cursor: pointer;
  font-family: var(--font-body);
  font-style: italic;
  font-size: 0.92rem;
  color: var(--ink-sepia);
  list-style: none;
  padding: 0.2rem 0;
}
.chapter details.marginalia-inline summary::-webkit-details-marker { display: none; }
.chapter details.marginalia-inline summary::before {
  content: "※ ";
  font-family: var(--font-body);
  margin-right: 0.3em;
}
.chapter details.marginalia-inline[open] summary { margin-bottom: 0.4rem; }
.chapter details.marginalia-inline cite {
  display: block;
  margin-top: 0.4em;
  font-family: var(--font-body);
  font-style: italic;
  font-size: 0.88rem;
  color: var(--ink-sepia);
  opacity: 0.85;
}

/* -- robustness hardening (text-scaling/viewport safe) --
   .chapter blockquote covers .verse (incantation blocks) and any future blockquote
   variant. The specific .pull-quote rule below overrides where needed.
   overflow-wrap:anywhere prevents single long-token overflow (SOTTOSPAZIAMARINO). */
.chapter blockquote {
  overflow-wrap: anywhere;
  hyphens: auto;
  -webkit-hyphens: auto;
}

/* -- 16. Pull-quote (AD v2 §6.9, UX v2 §4) ----------------------------- */
.chapter blockquote.pull-quote {
  margin: 3.6rem auto;
  padding: 1.4rem 1.6rem;
  max-width: 60ch;
  text-align: center;
  border-top: 1px solid rgba(92, 70, 50, 0.35);
  border-bottom: 1px solid rgba(92, 70, 50, 0.35);
  background: transparent; /* la texture body traspare */
  clear: both; /* scavalca eventuali float di vignette/right-bleed */
}

/* -- robustness hardening (text-scaling/viewport safe) --
   Pull-quote is centered/italic prose: no justify issue. Added overflow-wrap
   so a long quote word doesn't clip at high text-scaling on narrow viewports. */
.chapter blockquote.pull-quote p {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(1.7rem, 2.2vw + 0.8rem, 2.6rem);
  line-height: 1.25;
  color: var(--ink-sepia);
  margin: 0 0 0.8rem;
  max-width: none;
  text-align: center;
  text-indent: 0;
  hyphens: none;
  overflow-wrap: anywhere;
  letter-spacing: 0.005em;
}

.chapter blockquote.pull-quote cite {
  display: block;
  font-family: var(--font-body);
  font-style: normal;
  font-weight: 500;
  font-size: clamp(0.85rem, 0.4vw + 0.7rem, 1rem);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-feature-settings: "smcp", "c2sc";
  color: var(--ink-sepia);
  opacity: 0.85;
}

@media (max-width: 599px) {
  .chapter blockquote.pull-quote {
    padding: 1.6rem 1.2rem;
    margin: 2.8rem auto;
    /* tint sottile per spezzare monotonia scroll */
    background: var(--paper-shadow);
    border-top: 1px solid var(--ink-sepia);
    border-bottom: 1px solid var(--ink-sepia);
    border-image: none;
  }
}

/* -- 17. Cul-de-lampe (invariato v5) ----------------------------------- */
.chapter .culdelampe-wrap {
  display: flex;
  justify-content: center;
  margin: 3.6rem 0 1rem;
  clear: both;
}
.chapter .culdelampe {
  width: clamp(110px, 14vw, 160px);
  height: auto;
}

/* -- 18. Chapter nav footer (invariato v5) ----------------------------- */
.chapter .chapter-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 2rem 0 1rem;
  margin-top: 1.6rem;
  border-top: 1px solid rgba(92, 70, 50, 0.25);
  flex-wrap: wrap;
  clear: both;
}
.chapter .chapter-nav__prev,
.chapter .chapter-nav__next {
  flex: 1 1 0;
  min-height: 44px;
  background: transparent;
  border: 0;
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(1rem, 0.4vw + 0.95rem, 1.15rem);
  color: var(--ink);
  cursor: pointer;
  padding: 0.6rem 0.4rem;
  line-height: 1.3;
  letter-spacing: 0.01em;
}
.chapter .chapter-nav__prev { text-align: left; }
.chapter .chapter-nav__next { text-align: right; }
.chapter .chapter-nav__prev:hover,
.chapter .chapter-nav__next:hover { color: var(--rust); }
.chapter .chapter-nav__folio {
  flex: 0 0 auto;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 1.05rem;
  letter-spacing: 0.18em;
  color: var(--ink-sepia);
  text-align: center;
  padding: 0 0.8rem;
}
.chapter .chapter-nav__prev[data-disabled="true"] { visibility: hidden; }

/* -- 19. Intro and colophon variants (invariato v5) -------------------- */
.chapter.chapter--intro { text-align: center; }
.chapter.chapter--intro p {
  max-width: 60ch;
  margin-left: auto;
  margin-right: auto;
  text-align: center;
  text-indent: 0 !important;
}
.chapter.chapter--colophon { text-align: center; }
.chapter.chapter--colophon p {
  max-width: 60ch;
  margin-left: auto;
  margin-right: auto;
  text-align: center;
  text-indent: 0 !important;
  font-style: italic;
}
.chapter.chapter--colophon h1 { max-width: 30ch; }

/* -- 20. Mobile degradation (AD v2 §8) --------------------------------- */
@media (max-width: 599px) {
  /* Reader fluid su mobile: max-width 100% (era clamp(720,90vw,1400) → 720 min
     vinceva su mobile 390, allargando il reader oltre viewport e shiftando tutto
     a sinistra). */
  .reader {
    max-width: 100%;
    padding-top: 4rem;
    padding-left: clamp(1.2rem, 4vw, 1.6rem);
    padding-right: clamp(1.2rem, 4vw, 1.6rem);
  }

  /* Chapter hero: torna full-width senza il bleed trick.
     Su mobile il reader è già viewport-wide quindi width:100% + margin negativo
     copre l'effetto edge-to-edge senza translateX trickery. */
  .chapter-hero {
    position: relative;
    left: auto;
    transform: none;
    width: auto;
    max-width: none;
    margin-left: calc(-1 * clamp(1.2rem, 4vw, 1.6rem));
    margin-right: calc(-1 * clamp(1.2rem, 4vw, 1.6rem));
  }
  .chapter-hero .chapter-cover {
    height: clamp(45vh, 55vh, 65vh);
  }
}

@media (max-width: 359px) {
  .chapter span.vignette,
  .chapter span.vignette:nth-of-type(3n+1),
  .chapter span.vignette:nth-of-type(3n+2),
  .chapter span.vignette:nth-of-type(3n+3) {
    width: 80%;
  }
}

/* -- 21. Reduced motion ------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
}

/* ============================================================
   Audiolibro — FAB + dock flottante (usa le variabili tema,
   quindi segue automaticamente la modalità notte)
   ============================================================ */
.audio-fab {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 60;
  width: 3.2rem; height: 3.2rem; border-radius: 50%; border: none; cursor: pointer;
  background: var(--rust); color: #fff; font-size: 1.4rem; line-height: 1;
  box-shadow: 0 4px 14px rgba(42,31,23,.28); transition: transform .15s ease, opacity .2s ease;
}
.audio-fab:hover { transform: scale(1.06); }
.audio-fab[data-state="open"] { opacity: 0; pointer-events: none; }

.audio-dock {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 61;
  display: flex; align-items: center; gap: .7rem;
  width: min(92vw, 380px);
  background: var(--paper); border: 1px solid var(--paper-shadow); border-radius: 14px;
  padding: .6rem .7rem; box-shadow: 0 8px 28px rgba(42,31,23,.30);
  transform: translateY(140%); opacity: 0; pointer-events: none;
  transition: transform .25s ease, opacity .25s ease;
}
.audio-dock[data-state="open"] { transform: translateY(0); opacity: 1; pointer-events: auto; }
.audio-dock__play {
  flex: 0 0 auto; width: 2.6rem; height: 2.6rem; border-radius: 50%; border: none; cursor: pointer;
  background: var(--rust); color: #fff; font-size: 1.1rem; line-height: 1;
}
.audio-dock__body { flex: 1 1 auto; min-width: 0; }
.audio-dock__meta { display: flex; flex-direction: column; line-height: 1.2; margin-bottom: .3rem; }
.audio-dock__label { font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-marginalia); }
.audio-dock__title {
  font-family: var(--font-display); font-size: .95rem; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.audio-dock__bar { display: flex; align-items: center; gap: .5rem; }
.audio-dock__seek { flex: 1 1 auto; accent-color: var(--rust); height: 1.1rem; }
.audio-dock__time { flex: 0 0 auto; font-size: .75rem; color: var(--ink-sepia); font-variant-numeric: tabular-nums; }
.audio-dock__close {
  flex: 0 0 auto; background: none; border: none; cursor: pointer;
  color: var(--ink-sepia); font-size: 1.3rem; line-height: 1; padding: 0 .2rem;
}

/* ---------------------------------------------------------------------------
   Read-along: evidenziazione del paragrafo in lettura + toggle "segui"
   --------------------------------------------------------------------------- */
.audio-dock__follow {
  flex: 0 0 auto; width: 1.9rem; height: 1.9rem; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--rust); background: var(--rust); color: #fff;
  font-family: var(--font-display); font-size: 1rem; line-height: 1; padding: 0;
}
.audio-dock__follow.is-off { background: transparent; color: var(--ink-sepia); border-color: var(--paper-shadow); }

.ra-active {
  background: rgba(196, 90, 56, .12);
  border-radius: .35em;
  box-shadow: 0 0 0 .3em rgba(196, 90, 56, .12);
  transition: background .35s ease, box-shadow .35s ease;
}
@supports (background: color-mix(in srgb, red 10%, transparent)) {
  .ra-active {
    background: color-mix(in srgb, var(--rust) 14%, transparent);
    box-shadow: 0 0 0 .3em color-mix(in srgb, var(--rust) 14%, transparent);
  }
}
blockquote.verse.ra-active { box-shadow: 0 0 0 .5em color-mix(in srgb, var(--rust) 14%, transparent); }

/* Read-along livello parola: il paragrafo resta tinto leggero, la parola
   corrente si accende piu' forte. */
.ra-w { border-radius: .25em; }
.ra-w.ra-on {
  background: rgba(196, 90, 56, .32);
  box-shadow: 0 0 0 .12em rgba(196, 90, 56, .32);
  transition: background .12s ease;
}
@supports (background: color-mix(in srgb, red 10%, transparent)) {
  .ra-w.ra-on {
    background: color-mix(in srgb, var(--rust) 30%, transparent);
    box-shadow: 0 0 0 .12em color-mix(in srgb, var(--rust) 30%, transparent);
  }
}
