/* =========================================================
   Nouvelles immersives : base commune
   Chaque thème (styles/themes/*.css) ne fait que redéfinir
   les variables ci-dessous et ajouter ses effets propres.
   ========================================================= */

:root {
  --bg: #121722;
  --surface: #1a2130;
  --ink: #ebe5d8;
  --ink-muted: #a7a194;
  --accent: #e8c46b;
  --accent-2: #9fd3c0;
  --line: color-mix(in srgb, var(--ink) 16%, transparent);

  --font-display: "Instrument Serif", Georgia, "Times New Roman", serif;
  --font-body: "Literata", Georgia, "Times New Roman", serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* Échelle typographique (rapport 1,25, base 1,125 rem) */
  --step--1: 0.9rem;
  --step-0: clamp(1rem, 0.97rem + 0.15vw, 1.0625rem);
  --step-1: clamp(1.15rem, 1.08rem + 0.3vw, 1.3rem);
  --step-2: clamp(1.4rem, 1.25rem + 0.7vw, 1.75rem);
  --step-3: clamp(1.75rem, 1.4rem + 1.6vw, 2.5rem);
  --step-4: clamp(2.4rem, 1.6rem + 3.6vw, 4.5rem);

  --measure: 34em;           /* ~62 caractères : confortable sans être étroit */
  --illu-max: 46rem;         /* largeur maximale des illustrations */
  --reader-scale: 1;         /* réglé par le bouton « Texte » */
  --gutter: clamp(1.25rem, 4vw, 3rem);
  --radius-sm: 3px;
  --ease-out: cubic-bezier(.2, .7, .2, 1);

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: 4.5rem; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.65;
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

img { display: block; max-width: 100%; height: auto; }
a { color: inherit; text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { line-height: 1.1; margin: 0; font-weight: 400; text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }

:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 1rem; top: -4rem; z-index: 100;
  padding: .6rem 1rem;
  background: var(--ink); color: var(--bg);
  font-family: var(--font-ui); font-size: var(--step--1);
  text-decoration: none; border-radius: var(--radius-sm);
  transition: top .2s;
}
.skip-link:focus { top: 1rem; }

/* =========================================================
   Lecteur d'histoire (partagé par toutes les nouvelles)
   ========================================================= */

.reader-bar {
  position: fixed; inset: 0 0 auto 0; z-index: 50;
  display: flex; align-items: center; gap: 1rem;
  padding: .7rem var(--gutter);
  font-family: var(--font-ui); font-size: var(--step--1);
  background: linear-gradient(to bottom, color-mix(in srgb, var(--bg) 92%, transparent), transparent);
  transition: transform .35s var(--ease-out);
}
.reader-bar.is-hidden { transform: translateY(-110%); }
.reader-bar__home { text-decoration: none; margin-right: auto; opacity: .85; }
.reader-bar__home:hover { opacity: 1; text-decoration: underline; }

.reader-bar__controls { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }

.toggle {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .4rem .75rem;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  border: 1px solid var(--line); border-radius: 99px;
  font-size: inherit;
}
.toggle[aria-pressed="true"] { border-color: var(--accent-2); }
.toggle__dot {
  width: .5rem; height: .5rem; border-radius: 50%;
  background: var(--ink-muted);
}
/* Bouton de taille : affiche la taille courante */
.toggle__size { font-variant-numeric: tabular-nums; color: var(--ink-muted); }
.toggle[aria-pressed="true"] .toggle__dot { background: var(--accent-2); box-shadow: 0 0 8px var(--accent-2); }

.progress {
  position: fixed; inset: 0 0 auto 0; z-index: 60;
  height: 2px; transform-origin: 0 50%; transform: scaleX(0);
  background: var(--accent);
}

/* Sommaire : les pages sont une vraie séquence, la numérotation a du sens */
.toc { max-width: var(--measure); margin: 0 auto; padding: 0 var(--gutter); }
.toc ol { list-style: none; margin: 0; padding: 0; display: grid; gap: .1rem; counter-reset: page; }
.toc li { counter-increment: page; }
.toc a {
  display: grid; grid-template-columns: 2.25rem 1fr; align-items: baseline;
  padding: .55rem 0; text-decoration: none; color: var(--ink-muted);
  border-bottom: 1px solid var(--line);
}
.toc a::before { content: counter(page); font-variant-numeric: tabular-nums; color: var(--accent); }
.toc a:hover, .toc a[aria-current="true"] { color: var(--ink); }

.story { padding: 0 var(--gutter); }

.chapter {
  max-width: var(--measure); margin: 0 auto;
  padding-block: clamp(3rem, 8vh, 5rem);
  font-size: calc(var(--step-0) * var(--reader-scale));
  hyphens: auto; -webkit-hyphens: auto;
}
.chapter > * + * { margin-top: 1em; }
.chapter__title { font-family: var(--font-display); font-size: var(--step-3); margin-bottom: 1.2em; hyphens: none; }
.chapter + .chapter { border-top: 1px solid var(--line); }
.chapter__num { display: block; font-size: var(--step--1); font-family: var(--font-ui); color: var(--accent); margin-bottom: .6em; letter-spacing: .02em; }

.dialogue { padding-left: 1.1em; text-indent: -1.1em; }
.beat { margin-top: 1.7em !important; }   /* phrase isolée = respiration du récit */

/* Illustrations */
.illu {
  margin-block: 2.4rem !important;
  position: relative;
  font-size: var(--step-0);
}
/* Les illustrations larges débordent un peu de la colonne, sans dépasser --illu-max */
.illu--wide {
  margin-inline: calc((min(var(--illu-max), 100vw - 2 * var(--gutter)) - 100%) / -2) !important;
}
.illu--tall { max-width: 24rem; margin-inline: auto !important; }
.illu__frame { overflow: hidden; position: relative; background: var(--surface); border-radius: 4px; }
.illu__frame img { width: 100%; max-height: 72vh; object-fit: cover; }
.illu figcaption {
  margin-top: .6rem; text-align: center;
  font-family: var(--font-ui); font-size: var(--step--1); color: var(--ink-muted);
}
.illu[data-placeholder] .illu__frame::after {
  content: "Illustration provisoire";
  position: absolute; right: .75rem; bottom: .75rem;
  padding: .2rem .55rem; border-radius: 99px;
  background: rgb(0 0 0 / .6); color: #fff;
  font: 500 .75rem/1.4 var(--font-ui);
}

/* Mode « page par page » */
.pager {
  display: none;
  max-width: var(--measure); margin: 0 auto 6rem; padding: 0 var(--gutter);
  justify-content: space-between; gap: 1rem;
  font-family: var(--font-ui);
}
.is-paged .pager { display: flex; }
.pager button {
  padding: .8rem 1.2rem; background: transparent;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.pager button:hover:not(:disabled) { border-color: var(--accent); }
.pager button:disabled { opacity: .35; cursor: default; }
.pager__status { align-self: center; color: var(--ink-muted); font-size: var(--step--1); }

.is-paged .chapter[hidden] { display: none; }

.story-end { text-align: center; padding: 4rem var(--gutter) 6rem; }
.story-end a { font-family: var(--font-ui); }

/* Respect des préférences de mouvement : coupe toute animation */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
.fx-off *, .fx-off *::before, .fx-off *::after { animation: none !important; }

/* Les chapitres reçoivent le focus pour les lecteurs d'écran, sans cadre visible */
.chapter:focus { outline: none; }

/* Crédits des auteurs */
.hero__author { margin-top: .7rem; font-family: var(--font-ui); font-size: var(--step--1); color: var(--ink); opacity: .85; }
.hero__author a { text-underline-offset: .2em; }
.story-credit {
  max-width: 40em; margin: 2.5rem auto 0;
  font-family: var(--font-ui); font-size: .82rem; line-height: 1.55;
  color: var(--ink-muted);
}
.story-credit a { color: inherit; }

/* Langue : lien dans la barre et encart de traduction */
.toggle--lang { text-decoration: none; }
.toggle--lang:hover { border-color: var(--accent); }
.lang-box {
  display: flex; flex-wrap: wrap; align-items: center; gap: .6rem 1rem;
  width: calc(100% - 2 * var(--gutter)); max-width: var(--measure);
  margin: 2.5rem auto 0; padding: .9rem 1.1rem;
  font-family: var(--font-ui); font-size: .92rem; line-height: 1.45;
  border: 1px solid var(--line); border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 65%, transparent);
}
.lang-box__badge {
  padding: .15rem .5rem; border: 1px solid var(--accent); border-radius: 4px;
  font-size: .72rem; font-weight: 700; letter-spacing: .06em; color: var(--ink);
}
.lang-box__text { flex: 1 1 14rem; color: var(--ink); }
.lang-box__note { flex-basis: 100%; font-size: .82rem; color: var(--ink-muted); }
.lang-box__note a { color: inherit; }
.lang-box__link {
  padding: .5rem 1rem; border: 1px solid var(--accent); border-radius: 99px;
  color: var(--ink); font-weight: 600; text-decoration: none; white-space: nowrap;
}
.lang-box__link:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }

/* Anglais : les répliques entre guillemets n'ont pas besoin du retrait des tirets français */
:lang(en) .dialogue { padding-left: 0; text-indent: 0; }
:lang(en) .illu[data-placeholder] .illu__frame::after { content: "Placeholder illustration"; }

/* Immersion progressive des illustrations narratives */
.js .illu[data-immersive] .illu__frame { isolation:isolate; box-shadow:0 1.4rem 4rem rgb(0 0 0 / .28); }
.js .illu[data-immersive] .illu__frame::after { content:""; position:absolute; inset:0; pointer-events:none; background:linear-gradient(180deg,transparent 55%,rgb(0 0 0 / .22)); opacity:.85; transition:opacity 1.2s ease; }
.js .illu[data-immersive] img { transform:scale(1.055); opacity:.72; filter:saturate(.7) contrast(1.08) brightness(.82); transition:transform 2.2s cubic-bezier(.2,.7,.2,1),opacity 1.25s ease,filter 1.8s ease; will-change:transform; }
.js .illu[data-immersive].is-revealed img { transform:scale(1); opacity:1; filter:saturate(.92) contrast(1.06) brightness(.96); }
.js .illu[data-immersive].is-revealed .illu__frame::after { opacity:.25; }
.fx-off .illu[data-immersive] img { transform:none !important; opacity:1 !important; filter:none !important; }
@media (prefers-reduced-motion:reduce){.js .illu[data-immersive] img{transform:none;opacity:1;filter:none}.js .illu[data-immersive] .illu__frame::after{opacity:.25}}
/* V2: le bouton Effets neutralise aussi les couches d'ambiance des thèmes. */
.fx-off.theme-le-coeur-revelateur::before,.fx-off.theme-apparition::before,.fx-off.theme-apparition::after,.fx-off.theme-la-cafetiere::before,.fx-off.theme-vera::before,.fx-off.theme-la-peur::before,.fx-off.theme-la-peur::after{display:none!important}
.fx-off .illu[data-immersive] .illu__frame::before{display:none!important}
@media (prefers-reduced-motion:reduce){.theme-le-coeur-revelateur::before,.theme-apparition::before,.theme-apparition::after,.theme-la-cafetiere::before,.theme-vera::before,.theme-la-peur::before,.theme-la-peur::after{animation:none!important}.illu[data-immersive] .illu__frame::before{animation:none!important}}

/* SQ rollout: pages awaiting linguistic review */
.ni-sq-pending{min-height:100vh;display:grid;place-items:center;padding:var(--gutter,2rem)}
.ni-sq-pending .chapter{max-width:46rem}
.review-badge{display:inline-block;border:1px solid currentColor;border-radius:999px;padding:.35rem .7rem;font-size:.8rem;letter-spacing:.04em}
