/* ==========================================================
   Le Grimoire d'Elia · Ley Coffee Halloween
   ========================================================== */
:root {
  /* Charte Ley Coffee Halloween */
  --creme: #F6EFE3;
  --violet: #5B2C82;
  --orange: #E8641C;
  --vert: #7FD13B;
  --noir: #1A1A1A;

  /* Nuances dérivées */
  --violet-fonce: #42205E;
  --nuit: #1C0F27;
  --papier-2: #EFE5D2;
  --papier-clair: #FBF7EF;
  --filet: rgba(91, 44, 130, .2);
  --texte-doux: rgba(26, 26, 26, .78);

  --f-titre: "Chewy", "Comic Sans MS", cursive;
  --f-texte: "Nunito", system-ui, sans-serif;
  --f-prompt: "Patrick Hand", "Comic Sans MS", cursive;

  /* Grain de papier (SVG en ligne, très léger) */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .42 0 0 0 0 .3 0 0 0 0 .16 0 0 0 .1 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
html { scroll-padding-top: 16px; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--f-texte);
  font-size: 18px;
  line-height: 1.65;
  color: var(--noir);
  background: radial-gradient(ellipse 90% 70% at 50% 30%, #2F1B43 0%, var(--nuit) 70%) fixed, var(--nuit);
}
button { font: inherit; cursor: pointer; }
img { max-width: 100%; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 3px; }

/* ---------- Barre du haut ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 1360px; margin: 0 auto; padding: 14px 24px 8px;
}
.topbar-title {
  color: var(--creme); opacity: .8;
  font-weight: 800; font-size: 13px; letter-spacing: .22em; text-transform: uppercase;
}
.btn-ghost {
  background: transparent; color: var(--creme);
  border: 1px solid rgba(246, 239, 227, .35); border-radius: 6px;
  padding: 7px 14px; font-size: 14.5px; font-weight: 700;
}
.btn-ghost:hover { background: rgba(246, 239, 227, .1); border-color: rgba(246, 239, 227, .6); }

/* ---------- Boutons ---------- */
.btn {
  background: var(--orange); color: var(--noir);
  border: 0; border-radius: 6px;
  padding: 10px 18px; font-weight: 800; font-size: 15.5px;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .18), 0 2px 6px rgba(0, 0, 0, .25);
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .35; cursor: default; filter: none; transform: none; }

/* ---------- Scène et livre ---------- */
#stage { display: flex; justify-content: center; padding: 8px 20px 24px; }
.book {
  --page-w: min(620px, calc((100vw - 72px) / 2));
  --min-h: max(540px, min(calc(100vh - 150px), calc(var(--page-w) * 1.42)));
  position: relative;
  width: calc(var(--page-w) * 2);
  min-height: var(--min-h);
  perspective: 2600px;
}
.book.closed { transform: translateX(calc(var(--page-w) * -.5)); height: var(--min-h); }
.book.closed .slot { visibility: hidden; }

.slot, .flipper { position: absolute; top: 0; bottom: 0; width: 50%; }
.slot-left { left: 0; }
.slot-right { left: 50%; }
/* Tranche des pages et ombre portée */
.book:not(.closed)::before {
  content: ""; position: absolute; inset: 3px -5px -7px -5px; z-index: -1;
  border-radius: 10px;
  background: linear-gradient(180deg, #E4D8C2, #CDBE9F);
  box-shadow: 0 1px 0 #BCA985, 0 30px 60px -12px rgba(0, 0, 0, .65);
}

.flipper { transform-style: preserve-3d; z-index: 4; will-change: transform; }
.flipper.from-right { left: 50%; transform-origin: left center; }
.flipper.from-left { left: 0; transform-origin: right center; }
.flipper .face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.flipper .face.back { transform: rotateY(180deg); }

/* ---------- Couverture ---------- */
.cover {
  position: absolute; top: 0; left: 50%; width: 50%; height: var(--min-h);
  transform-origin: left center; transform-style: preserve-3d;
  z-index: 6;
}
.cover[hidden] { display: none; }
.cover-face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.cover-back { transform: rotateY(180deg); }
.cover-front {
  border-radius: 3px 10px 10px 3px;
  padding: 30px 30px 30px 44px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, .42) 0, rgba(0, 0, 0, .14) 14px, rgba(255, 255, 255, .07) 17px, transparent 26px),
    var(--grain),
    radial-gradient(ellipse 120% 90% at 35% 25%, #6B3896 0%, var(--violet) 45%, var(--violet-fonce) 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, .06),
    inset 0 0 40px rgba(0, 0, 0, .25),
    0 34px 60px -14px rgba(0, 0, 0, .7);
}
.cover-frame {
  position: relative; height: 100%;
  border: 1.5px solid rgba(232, 100, 28, .9);
  outline: 1px solid rgba(232, 100, 28, .5); outline-offset: -8px;
  border-radius: 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 40px 34px; gap: 14px;
  color: var(--creme);
  overflow: hidden;
}
.corner { position: absolute; width: 58px; height: 58px; color: var(--orange); }
.corner.tl { top: 14px; left: 14px; }
.corner.tr { top: 14px; right: 14px; transform: scaleX(-1); }
.corner.bl { bottom: 14px; left: 14px; transform: scaleY(-1); }
.corner.br { bottom: 14px; right: 14px; transform: scale(-1, -1); }
.cover-emblem { width: 112px; height: 112px; color: var(--orange); margin-bottom: 6px; }
.cover-title {
  margin: 0; font-family: var(--f-titre); font-weight: 400;
  font-size: clamp(44px, 4.6vw, 64px); line-height: 1.02; letter-spacing: .01em;
  color: var(--creme);
  text-shadow: 0 2px 0 rgba(0, 0, 0, .28);
}
.cover-rule {
  display: flex; align-items: center; gap: 10px; width: 190px; color: var(--orange);
}
.cover-rule::before, .cover-rule::after { content: ""; flex: 1; height: 1px; background: currentColor; opacity: .85; }
.cover-rule { background: radial-gradient(circle, var(--orange) 0 3px, transparent 3.5px) center / 12px 12px no-repeat; height: 12px; }
.cover-rule::before { margin-right: 10px; }
.cover-rule::after { margin-left: 10px; }
.cover-sub { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: .01em; color: var(--creme); max-width: 26ch; line-height: 1.5; }
.btn-open {
  margin-top: 16px;
  background: var(--orange); color: var(--noir);
  border: 0; border-radius: 4px;
  padding: 13px 26px;
  font-weight: 800; font-size: 14.5px; letter-spacing: .16em; text-transform: uppercase;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .2), 0 8px 20px -6px rgba(0, 0, 0, .5);
  transition: filter .15s, transform .15s;
}
.btn-open:hover { filter: brightness(1.08); transform: translateY(-1px); }
.cover-mention {
  margin: 18px 0 0; font-size: 13.5px; letter-spacing: .03em; line-height: 1.5;
  color: var(--creme); opacity: .78; max-width: 34ch;
}

/* ---------- Pages (papier) ---------- */
.page {
  position: relative;
  background-color: var(--creme);
  background-image: var(--grain), radial-gradient(ellipse at 50% 40%, transparent 55%, rgba(150, 110, 60, .1) 100%);
  color: var(--noir);
}
/* Double filet d'encadrement façon livre ancien */
.page::after {
  content: ""; position: absolute; inset: 18px; pointer-events: none;
  border: 1px solid var(--filet); border-radius: 3px;
  box-shadow: inset 0 0 0 3px var(--creme), inset 0 0 0 4px rgba(91, 44, 130, .1);
}
.slot > .page, .face > .page, .cover-back > .page {
  position: absolute; inset: 0;
  padding: 72px 62px 78px;
}
.slot-left > .page, .face.left > .page, .cover-back > .page {
  border-radius: 8px 2px 2px 8px;
  background-image: linear-gradient(to left, rgba(80, 50, 20, .2), rgba(80, 50, 20, .05) 4%, transparent 9%), var(--grain), radial-gradient(ellipse at 50% 40%, transparent 55%, rgba(150, 110, 60, .1) 100%);
}
.slot-right > .page, .face.right > .page {
  border-radius: 2px 8px 8px 2px;
  background-image: linear-gradient(to right, rgba(80, 50, 20, .2), rgba(80, 50, 20, .05) 4%, transparent 9%), var(--grain), radial-gradient(ellipse at 50% 40%, transparent 55%, rgba(150, 110, 60, .1) 100%);
}

/* Titre courant et folio */
.page[data-head]::before {
  content: attr(data-head);
  position: absolute; top: 32px; left: 62px; right: 62px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 11.5px; font-weight: 800; letter-spacing: .2em; text-transform: uppercase;
  color: var(--violet); opacity: .7;
}
.page .folio {
  position: absolute; bottom: 30px; left: 0; right: 0; text-align: center;
  font-weight: 800; font-size: 13px; letter-spacing: .12em; color: var(--violet); opacity: .8;
}
.page .folio::before { content: "— "; }
.page .folio::after { content: " —"; }

/* Ornements au trait, discrets */
.deco { position: absolute; width: 22px; height: 22px; pointer-events: none; color: var(--violet); opacity: .32; }
.d-tr { top: 28px; right: 30px; }
.d-tl { top: 28px; left: 30px; }
.d-br { bottom: 26px; right: 30px; }
.d-bl { bottom: 26px; left: 30px; }

/* ---------- Typographie ---------- */
.chap-title {
  font-family: var(--f-titre); font-weight: 400; color: var(--violet);
  font-size: clamp(32px, 2.8vw, 42px); line-height: 1.08; letter-spacing: .005em;
  margin: 0 0 14px;
}
.chap-sub { margin: -6px 0 24px; font-style: italic; color: var(--texte-doux); font-size: 18px; }
.recipe-num {
  display: flex; align-items: center; gap: 12px; margin: 0 0 8px;
  font-weight: 800; font-size: 12.5px; letter-spacing: .24em; text-transform: uppercase;
  color: var(--violet);
}
.recipe-num::after { content: ""; width: 44px; height: 2px; background: var(--orange); }
.case-tag {
  display: inline-block; margin: 0 0 6px;
  padding: 5px 14px 5px 12px;
  border-left: 3px solid var(--orange);
  background: rgba(91, 44, 130, .07);
  color: var(--violet); font-weight: 800; font-size: 16.5px; line-height: 1.4;
}
.sec-title {
  display: flex; align-items: center; gap: 14px;
  margin: 36px 0 14px;
  font-family: var(--f-texte); font-weight: 800; font-size: 13.5px; line-height: 1.3;
  letter-spacing: .2em; text-transform: uppercase; color: var(--violet);
}
.sec-title::after { content: ""; flex: 1; height: 1px; background: var(--filet); }
.page-body > .sec-title:first-child, .page > .sec-title:first-child { margin-top: 0; }
.prose p { margin: 0 0 1em; }
.prose p:last-child { margin-bottom: 0; }

/* ---------- Sommaire ---------- */
.toc { list-style: none; padding: 0; margin: 28px 0 0; counter-reset: toc; border-top: 1px solid var(--filet); }
.toc li { counter-increment: toc; padding: 14px 0; border-bottom: 1px solid var(--filet); }
.toc a {
  display: flex; align-items: baseline; gap: 12px;
  color: var(--noir); text-decoration: none; font-weight: 700; font-size: 18px; line-height: 1.4;
}
.toc a::before {
  content: counter(toc, upper-roman) "."; flex: 0 0 2.4em;
  font-weight: 800; color: var(--violet); font-size: 15px; letter-spacing: .04em;
}
.toc a:hover .toc-name, .toc a:focus-visible .toc-name {
  text-decoration: underline; text-decoration-color: var(--orange);
  text-decoration-thickness: 2px; text-underline-offset: 4px;
}
.toc-dots { flex: 1 1 auto; min-width: 16px; border-bottom: 1px dotted rgba(91, 44, 130, .45); transform: translateY(-5px); }
.toc-num { font-weight: 800; color: var(--violet); font-variant-numeric: tabular-nums; }
.toc-cases { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 8px 0 0 calc(2.4em + 12px); }
.toc-cases .case {
  padding-left: 9px; border-left: 2px solid var(--orange);
  color: var(--violet); font-weight: 700; font-size: 16px; line-height: 1.35;
}

/* ---------- Cartes mascottes ---------- */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px 14px; margin-top: 4px; }
.card {
  margin: 0; padding: 7px 7px 0;
  background: var(--papier-clair);
  border: 1px solid rgba(91, 44, 130, .35); border-radius: 5px;
  box-shadow: 0 1px 2px rgba(60, 30, 10, .08), 0 8px 16px -10px rgba(60, 30, 10, .35);
}
.card img {
  display: block; width: 100%; aspect-ratio: 1; object-fit: contain;
  background: var(--creme); mix-blend-mode: multiply;
  border-radius: 3px; padding: 8px; cursor: zoom-in;
  outline: 1px solid rgba(232, 100, 28, .5); outline-offset: -4px;
}
.card figcaption {
  padding: 6px 2px 7px; text-align: center;
  font-weight: 800; font-size: 15px; letter-spacing: .02em; white-space: nowrap;
  color: var(--violet);
}

/* ---------- Logos ---------- */
.logos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-top: 30px; align-items: start; }
.logo { margin: 0; position: relative; text-align: center; }
.logo img {
  display: block; width: 100%; aspect-ratio: 606 / 790; object-fit: contain;
  background: var(--papier-clair); mix-blend-mode: multiply;
  border: 1px solid rgba(91, 44, 130, .35); border-radius: 4px; padding: 12px;
  cursor: zoom-in;
}
.logo figcaption { margin-top: 10px; font-weight: 700; font-size: 16.5px; line-height: 1.3; }
.logo.kept img { border: 2px solid var(--orange); }
.badge {
  position: absolute; top: -12px; left: 50%; transform: translateX(-50%);
  z-index: 2; white-space: nowrap;
  background: var(--orange); color: var(--noir);
  border-radius: 3px; padding: 3px 10px;
  font-weight: 800; font-size: 12.5px; letter-spacing: .06em; text-transform: uppercase;
  box-shadow: 0 3px 8px -3px rgba(0, 0, 0, .35);
}

/* ---------- Ingrédients ---------- */
.ingredients { margin: 0; border-top: 1px solid var(--filet); }
.ingredients > div {
  display: grid; grid-template-columns: 96px 1fr; gap: 16px; align-items: baseline;
  padding: 11px 0; border-bottom: 1px solid var(--filet);
}
.ingredients dt {
  font-weight: 800; font-size: 12.5px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--violet);
}
.ingredients dd { margin: 0; font-size: 17px; line-height: 1.6; }

/* ---------- Incantations (prompts) ---------- */
.parchment {
  margin: 6px 0 18px; padding: 20px 24px 20px 22px;
  background: var(--grain), var(--papier-2);
  border-left: 3px solid var(--orange); border-radius: 0 4px 4px 0;
  box-shadow: inset 0 0 0 1px rgba(150, 110, 60, .16);
  font-family: var(--f-prompt); font-size: 20.5px; line-height: 1.5;
  overflow-wrap: anywhere;
}
.spell-label {
  margin: 18px 0 6px;
  font-weight: 800; font-size: 13px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--violet);
}

/* ---------- Images : cadres dorés ---------- */
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: start; margin: 8px 6px 12px; }
.solo { display: flex; justify-content: center; margin: 8px 0 22px; }
.solo .polaroid { width: 50%; }
.polaroid {
  margin: 0; padding: 8px;
  background: var(--papier-clair);
  border: 1px solid rgba(91, 44, 130, .16); border-radius: 2px;
  box-shadow:
    0 0 0 4px var(--creme),
    0 0 0 5px rgba(232, 100, 28, .6),
    0 12px 24px -12px rgba(60, 30, 10, .4);
}
.polaroid img {
  display: block; width: 100%; height: auto; max-height: 360px;
  object-fit: contain; background: #EFE6D6; cursor: zoom-in;
}
.polaroid img.drawing { background: var(--creme); mix-blend-mode: multiply; }
.polaroid figcaption { text-align: center; font-style: italic; font-size: 16.5px; line-height: 1.35; padding: 10px 4px 3px; }

/* ---------- Effet inattendu ---------- */
.unexpected {
  margin: 28px 0 6px; padding: 18px 22px 16px;
  border: 2px solid var(--vert); border-radius: 6px;
  background: rgba(251, 247, 239, .8);
  color: var(--noir);
}
.unexpected h4 { margin: 0 0 10px; font-weight: 800; font-size: 19px; line-height: 1.3; color: var(--violet); }
.unexpected .case-tag { margin-bottom: 10px; }
.unexpected p:last-child { margin: 0; }

/* ---------- Le sort raté : page tachée et roussie ---------- */
.page.burnt,
.slot > .page.burnt, .face > .page.burnt {
  background-image:
    radial-gradient(circle at 84% 13%, transparent 0 38px, rgba(110, 80, 35, .2) 39px 42px, rgba(110, 80, 35, .07) 43px 46px, transparent 47px),
    radial-gradient(ellipse at 100% 100%, rgba(70, 40, 10, .4) 0, rgba(110, 70, 25, .16) 90px, transparent 190px),
    radial-gradient(ellipse at 0% 0%, rgba(70, 40, 10, .22) 0, transparent 120px),
    radial-gradient(ellipse at 50% 45%, transparent 48%, rgba(120, 80, 30, .24) 100%),
    var(--grain);
}

/* ---------- Deux langues ---------- */
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.cols .sec-title { margin-top: 22px; letter-spacing: .1em; }
.cols .sec-title::after { display: none; }
.cols .parchment { font-size: 19px; padding: 18px 18px 18px 18px; }

/* ---------- Fin ---------- */
.page-end { text-align: center; }
.waving { display: flex; justify-content: center; margin: 2px 0 4px; }
.ghost-wave { width: 92px; height: 92px; }
.ghost-wave path, .ghost-wave circle { stroke: var(--violet); stroke-width: 2.4; }
.ghost-wave > path:first-of-type { fill: var(--papier-clair); }
.ghost-wave circle[fill="#F4A6A0"] { display: none; }
.ghost-wave .wave-arm circle { fill: var(--papier-clair); }
.wave-arm { transform-origin: 84px 58px; animation: wave 1.6s ease-in-out infinite; }
@keyframes wave { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-16deg); } }
.after-spells {
  text-align: left; margin: 18px 0 24px; padding: 22px 26px 22px;
  background: rgba(251, 247, 239, .85);
  border: 2px solid var(--orange); border-radius: 6px;
}
.after-spells h3 { margin: 0 0 10px; font-family: var(--f-titre); font-weight: 400; font-size: 28px; line-height: 1.15; color: var(--violet); }
.after-spells p { margin: 0; }
.credits { font-style: italic; margin: 0 auto 24px; max-width: 46ch; color: var(--texte-doux); }
.restart-wrap { margin: 0; }

/* Garde de fin (page de droite de la dernière double page) */
.page.endpaper,
.slot > .page.endpaper {
  background-color: var(--violet);
  background-image:
    var(--grain),
    radial-gradient(circle, rgba(232, 100, 28, .55) 0 1.5px, transparent 2px),
    linear-gradient(to right, rgba(0, 0, 0, .3), transparent 8%);
  background-size: auto, 34px 34px, auto;
}
.page.endpaper::after { border-color: rgba(232, 100, 28, .45); box-shadow: none; }
.page.endpaper .deco { color: var(--orange); opacity: .6; }

/* ---------- Pagination (reste visible en bas) ---------- */
.pager {
  position: sticky; bottom: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center; gap: 16px;
  padding: 18px 16px 16px;
  background: linear-gradient(to top, var(--nuit) 72%, rgba(28, 15, 39, 0));
}
.indicator { color: var(--creme); font-weight: 800; min-width: 128px; text-align: center; font-size: 15px; letter-spacing: .04em; }

/* Indice « la page continue » */
.scroll-hint {
  position: fixed; left: 50%; bottom: 82px; z-index: 12;
  transform: translate(-50%, 8px);
  background: var(--creme); color: var(--violet);
  border: 1px solid rgba(91, 44, 130, .3); border-radius: 999px;
  padding: 7px 16px; font-weight: 800; font-size: 14px;
  box-shadow: 0 8px 20px -6px rgba(0, 0, 0, .5);
  opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s;
}
.scroll-hint.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }

/* ---------- Mode « Tout lire » ---------- */
#pages { display: none; }
.read-bar { display: none; }
body.reading #stage, body.reading .pager, body.reading .scroll-hint { display: none; }
body.reading #pages { display: block; padding: 10px 16px 100px; }
body.reading #pages > .page {
  max-width: 860px; margin: 0 auto 32px;
  padding: 76px 64px 84px; border-radius: 6px;
  box-shadow: 0 24px 50px -16px rgba(0, 0, 0, .6);
}
body.reading .read-bar {
  display: flex; justify-content: center;
  position: fixed; left: 0; right: 0; bottom: 16px; z-index: 20; pointer-events: none;
}
body.reading .read-bar .btn { pointer-events: auto; }
body.reading #toggle-read { visibility: hidden; }
#pages > .titlepage {
  background: radial-gradient(ellipse 120% 90% at 35% 25%, #6B3896 0%, var(--violet) 45%, var(--violet-fonce) 100%);
  color: var(--creme); text-align: center;
}
#pages > .titlepage::after { border-color: rgba(232, 100, 28, .7); box-shadow: inset 0 0 0 4px transparent, inset 0 0 0 5px rgba(232, 100, 28, .4); }
.titlepage-inner { display: grid; gap: 14px; justify-items: center; padding: 30px 10px; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 10, 28, .9);
  display: grid; place-items: center; padding: 56px 16px 20px;
}
.lightbox[hidden] { display: none; }
.lightbox figure { margin: 0; max-width: 100%; max-height: 100%; display: grid; justify-items: center; gap: 12px; }
.lightbox img {
  max-width: min(94vw, 1200px); max-height: calc(100dvh - 130px);
  object-fit: contain; background: var(--creme);
  border: 6px solid var(--papier-clair); border-radius: 3px;
}
.lightbox figcaption { color: var(--creme); font-style: italic; font-size: 18px; text-align: center; }
.lb-close {
  position: absolute; top: 14px; right: 16px;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--creme); color: var(--noir); border: 0;
  font-size: 20px; font-weight: 800; line-height: 1;
}
.lb-close:hover { background: var(--orange); }

/* ---------- Téléphone ---------- */
@media (max-width: 767.98px) {
  body { font-size: 17.5px; }
  .topbar { padding: 10px 16px 6px; }
  .topbar-title { font-size: 11.5px; letter-spacing: .16em; }
  .btn-ghost { font-size: 13.5px; padding: 6px 10px; }
  #stage { padding: 4px 12px 14px; }
  .book { --min-h: max(520px, calc(100dvh - 140px)); width: 100%; max-width: 560px; perspective: 1600px; }
  .book.closed { transform: none; }
  .book:not(.closed)::before { inset: 3px -3px -6px -3px; }
  .slot { left: 0; width: 100%; }
  .slot-left { display: none; }
  .cover { left: 0; width: 100%; }
  .cover-front { padding: 18px 18px 18px 30px; }
  .cover-frame { padding: 30px 18px; gap: 12px; }
  .corner { width: 42px; height: 42px; }
  .cover-emblem { width: 92px; height: 92px; }
  .cover-title { font-size: 46px; }
  .slot > .page { padding: 60px 24px 70px; border-radius: 6px !important; background-image: var(--grain), radial-gradient(ellipse at 50% 40%, transparent 55%, rgba(150, 110, 60, .1) 100%); }
  .page::after { inset: 10px; }
  .page[data-head]::before { top: 26px; left: 24px; right: 48px; }
  .d-tr { top: 22px; right: 20px; }
  .d-br { bottom: 22px; right: 20px; }
  .d-bl { bottom: 22px; left: 20px; }
  .page .folio { bottom: 26px; }
  .chap-title { font-size: 32px; }
  .ingredients > div { grid-template-columns: 1fr; gap: 3px; }
  .duo { gap: 18px; margin: 8px 4px 12px; }
  .cols { grid-template-columns: 1fr; gap: 0; }
  .cards { grid-template-columns: repeat(2, 1fr); gap: 14px 12px; }
  .logos { gap: 10px; }
  .logo img { padding: 6px; }
  .logo figcaption { font-size: 15px; }
  .badge { font-size: 10.5px; padding: 2px 6px; letter-spacing: .03em; }
  .solo .polaroid { width: 66%; }
  .polaroid img { max-height: 300px; }
  .toc-cases { margin-left: 8px; }
  .pager { gap: 6px; padding: 16px 8px 12px; }
  .pager .btn { padding: 9px 10px; font-size: 13.5px; white-space: nowrap; }
  .indicator { min-width: 0; font-size: 13.5px; white-space: nowrap; }
  .scroll-hint { bottom: 70px; }
  body.reading #pages { padding: 8px 10px 90px; }
  body.reading #pages > .page { padding: 60px 22px 70px; }
}

/* ---------- Sans animation ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}

/* ---------- Impression / PDF ---------- */
@media print {
  @page { size: A4; margin: 12mm 14mm; }
  html, body { height: auto; background: #fff !important; font-size: 12pt; line-height: 1.5; }
  .topbar, #stage, .pager, .read-bar, .lightbox, .deco, .restart-wrap, .waving, .scroll-hint { display: none !important; }
  #pages { display: block !important; padding: 0 !important; }
  #pages > .page {
    break-after: page; page-break-after: always;
    margin: 0 !important; padding: 0 0 8mm !important; max-width: none !important;
    box-shadow: none !important; border-radius: 0 !important;
    background: #fff !important; min-height: 0;
  }
  #pages > .page:last-child { break-after: auto; page-break-after: auto; }
  #pages > .page::after { display: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #pages > .titlepage {
    background: var(--violet) !important; min-height: 270mm;
    display: grid; align-content: center; padding: 10mm !important;
    outline: 1.5px solid var(--orange); outline-offset: -8mm;
  }
  .titlepage-inner { padding: 50mm 10mm; }
  .cover-emblem { width: 34mm; height: 34mm; }
  .page[data-head]::before { position: static; display: block; margin: 0 0 3mm; font-size: 8pt; }
  .page .folio { position: static; display: block; margin-top: 4mm; font-size: 9pt; }
  .chap-title { font-size: 22pt; }
  .sec-title { font-size: 9.5pt; margin: 5mm 0 2mm; }
  .parchment { font-size: 13pt; padding: 3mm 4mm; margin: 2mm 0 3mm; box-shadow: none; }
  .cols .parchment { font-size: 12pt; }
  .polaroid { box-shadow: 0 0 0 1px #ccc; break-inside: avoid; }
  .polaroid img { max-height: 70mm; }
  .solo .polaroid { width: 40%; }
  .polaroid figcaption { font-size: 10.5pt; padding: 1mm 0 1mm; }
  .duo { gap: 6mm; }
  .cards { grid-template-columns: repeat(4, 1fr); gap: 4mm; }
  .card { box-shadow: none; }
  .logos { margin-top: 8mm; }
  .unexpected, .after-spells { break-inside: avoid; }
  .ingredients > div { padding: 1mm 0; }
  .toc a { font-size: 12pt; }
}
