/* Contes pour grandir : un livre de contes. Papier crème, cuir vert, dorures, onglets de chapitre.
   Couleurs de la charte Platypus + un or doux pour les dorures. */
:root {
  --cream: #F7F2EA; --papier: #FBF6EA; --papier2: #F1E8D4; --sand: #D9CCBA;
  --terracotta-text: #8F4B2E; --brown: #4A3728; --text: #2E2318; --muted: #6B5A48;
  --cuir: #2F4A3E; --cuir-sombre: #1F3329; --or: #E3C77E; --or-sombre: #8A6A1F;
  --table: #241a13;
  --font-display: 'Cormorant Garamond', Georgia, serif; --font-body: 'DM Sans', system-ui, sans-serif;
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .3  0 0 0 0 .2  0 0 0 0 .1  0 0 0 .13 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; color: var(--text); font: 17px/1.6 var(--font-body); -webkit-font-smoothing: antialiased;
  background: radial-gradient(ellipse at 50% 30%, #3a2b20 0%, var(--table) 70%) fixed; }
h1, h2 { font-family: var(--font-display); color: var(--brown); font-weight: 600; line-height: 1.05; margin: 0; }
a { color: inherit; }
main { outline: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.skip { position: absolute; left: -999px; top: 8px; background: var(--or); color: var(--table); padding: 10px 16px; border-radius: 8px; z-index: 100; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--or-sombre); outline-offset: 3px; border-radius: 6px; }

/* barre du haut, discrète */
.barre { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px max(10px, env(safe-area-inset-left)); color: #EFE3C8; }
.barre a { text-decoration: none; padding: 10px 12px; min-height: 44px; display: inline-flex; align-items: center; font-size: .92rem; font-weight: 500; border-radius: 999px; white-space: nowrap; }
.barre a:hover { background: rgba(255, 255, 255, .1); }
.barre .titre-barre { font: 600 1.35rem var(--font-display); letter-spacing: .02em; color: var(--or); }

/* ---------- couverture ---------- */
.fond-couv { display: grid; place-items: center; padding: 10px 16px 40px; perspective: 1800px; }
.couverture { position: relative; width: min(440px, 100%); aspect-ratio: 3 / 4.3; border-radius: 6px 18px 18px 6px; color: var(--or); transform-origin: left center; transition: transform .7s ease-in, opacity .7s;
  background: var(--grain), linear-gradient(105deg, #1a2c23 0%, var(--cuir) 8%, #365548 55%, var(--cuir-sombre) 100%);
  box-shadow: 0 30px 60px rgba(0, 0, 0, .55), inset 0 0 0 2px rgba(227, 199, 126, .35), inset 14px 0 18px -10px rgba(0, 0, 0, .6); }
.couverture.ouvre { transform: rotateY(-115deg); opacity: .2; }
.couverture::before { content: ''; position: absolute; inset: 16px 16px 16px 26px; border: 2px solid rgba(227, 199, 126, .75); border-radius: 4px 12px 12px 4px; pointer-events: none; }
.couverture::after { content: ''; position: absolute; inset: 22px 22px 22px 32px; border: 1px solid rgba(227, 199, 126, .4); border-radius: 3px 10px 10px 3px; pointer-events: none; }
.couverture > .coins { color: var(--or); }
.couv-in { position: absolute; inset: 40px 36px 34px 46px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; z-index: 2; }
.couv-haut { margin: 0; font-size: .78rem; letter-spacing: .28em; text-transform: uppercase; color: var(--or); opacity: .9; }
.couverture h1 { color: var(--or); font-size: clamp(2.5rem, 10vw, 3.6rem); text-shadow: 0 2px 0 rgba(0, 0, 0, .35); letter-spacing: .01em; }
.couverture .fleuron { width: 150px; color: var(--or); margin: 4px auto; }
.vitrail { flex: 1; width: 78%; min-height: 0; border-radius: 999px 999px 10px 10px; overflow: hidden; border: 3px solid var(--or); box-shadow: 0 0 0 5px rgba(227, 199, 126, .25), inset 0 0 24px rgba(0, 0, 0, .35); }
.vitrail .scene { width: 100%; height: 100%; }
.couv-bas { margin: 4px 0 0; font: italic 500 1.25rem var(--font-display); color: #F3E6C2; }
.ouvrir { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 10px 28px; border: 2px solid var(--or); border-radius: 999px; color: var(--cuir-sombre); background: var(--or); font-weight: 600; text-decoration: none; transition: transform .2s, background .2s; }
.ouvrir:hover { background: #F2DA97; transform: translateY(-2px); }
.reprendre { color: #F3E6C2; font-size: .92rem; padding: 8px; min-height: 44px; display: inline-flex; align-items: center; }
.suivi { margin: 0; font-size: .85rem; opacity: .85; }

/* ---------- le livre ouvert ---------- */
.table-livre { display: grid; place-items: center; padding: 6px 12px 28px; }
.livre { position: relative; width: min(1180px, 100%); }
.feuillets { position: relative; display: block; background: var(--papier2); border-radius: 8px; box-shadow: 0 30px 60px rgba(0, 0, 0, .55), 0 0 0 7px var(--cuir), 0 0 0 9px rgba(227, 199, 126, .5); perspective: 2200px; }
.page { position: relative; min-height: calc(100svh - 190px); background: var(--grain), var(--papier); }
.page[hidden] { display: none; }
.p-in { padding: 34px 26px 56px; }
.p-in.centre { text-align: center; display: flex; flex-direction: column; align-items: center; }
.p-in.vertical { justify-content: center; min-height: calc(100svh - 270px); }
.folio { position: absolute; left: 0; right: 0; bottom: 16px; text-align: center; font: italic 500 .95rem var(--font-display); color: var(--muted); }
.surtitre { margin: 0 0 8px; font-size: .78rem; letter-spacing: .2em; text-transform: uppercase; font-weight: 600; color: var(--terracotta-text); }
.p-in h1 { font-size: clamp(2.2rem, 6vw, 3.3rem); }
.fleuron { width: 150px; height: 20px; color: var(--or-sombre); margin: 14px auto; display: block; }

/* planche illustrée (cadre doré, coins ornés) */
.planche { position: relative; margin: 0 0 14px; width: 100%; max-width: 560px; padding: 10px; background: var(--papier2); border: 1px solid rgba(138, 106, 31, .5); border-radius: 4px; box-shadow: 0 8px 18px rgba(74, 55, 40, .2); }
.planche .cadre { position: relative; display: block; aspect-ratio: 8 / 5; overflow: hidden; border: 2px solid var(--or-sombre); }
.planche .scene { position: absolute; inset: 0; width: 100%; height: 100%; }
.planche img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.coins { position: absolute; inset: 2px; pointer-events: none; color: var(--or-sombre); }
.coin { position: absolute; width: 34px; height: 34px; }
.coin:nth-child(1) { top: 0; left: 0; } .coin:nth-child(2) { top: 0; right: 0; transform: scaleX(-1); }
.coin:nth-child(3) { bottom: 0; left: 0; transform: scaleY(-1); } .coin:nth-child(4) { bottom: 0; right: 0; transform: scale(-1); }
.couverture > .coins { position: absolute; inset: 20px 20px 20px 30px; z-index: 3; }
.nuage { animation: derive 40s linear infinite; }
.astre { animation: respire 9s ease-in-out infinite; transform-origin: center; transform-box: fill-box; }
.motif { animation: balance 7s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 100%; }
@keyframes derive { from { transform: translateX(-60px); } to { transform: translateX(120px); } }
@keyframes respire { 50% { transform: scale(1.06); } }
@keyframes balance { 50% { transform: rotate(1.2deg); } }

/* texte des contes */
.titre-conte { font-size: clamp(2.4rem, 7vw, 3.6rem); }
.p-in.texte { padding-top: 30px; }
.mini { font-size: 1.35rem; color: var(--terracotta-text); text-align: center; font-style: italic; font-weight: 500; margin-bottom: 14px; }
.texte p { font-size: 1.12rem; line-height: 1.75; margin: 0 0 .9em; text-align: justify; hyphens: auto; }
.lettrine { float: left; font: 600 3.9rem/.82 var(--font-display); color: var(--c); padding: 7px 10px 0 0; text-shadow: 1px 1px 0 rgba(227, 199, 126, .6); }
.guill { font: 600 7rem/.6 var(--font-display); color: var(--or-sombre); opacity: .55; height: 60px; }
blockquote { margin: 10px 0 0; max-width: 24em; font: italic 500 clamp(1.7rem, 4.5vw, 2.3rem)/1.3 var(--font-display); color: var(--brown); }
.quest { margin: 0 0 22px; max-width: 24em; font: 500 clamp(1.6rem, 4.2vw, 2.1rem)/1.3 var(--font-display); color: var(--brown); }
.bouton { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 10px 26px; border-radius: 999px; background: var(--cuir); color: #fff; border: 2px solid var(--cuir); font: 600 1rem var(--font-body); cursor: pointer; transition: transform .2s; }
.bouton:hover { transform: translateY(-2px); background: var(--cuir-sombre); }
.bouton[aria-pressed="true"] { background: transparent; color: var(--cuir); }
.suite { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; margin-top: 4px; }
.suite a { padding: 12px; min-height: 44px; font: italic 500 1.1rem/1.15 var(--font-display); color: var(--terracotta-text); text-decoration: none; }
.suite a:last-child { text-align: right; }
.suite a:hover { text-decoration: underline; }
.mot { max-width: 26em; font: italic 500 1.25rem/1.45 var(--font-display); color: var(--brown); margin: 8px 0; }
.mot.petit { font: .9rem var(--font-body); color: var(--muted); }
.vide { text-align: center; padding-top: 30px; }

/* sommaire et listes à points de conduite */
.sommaire, .contes { list-style: none; margin: 18px 0 0; padding: 0; width: 100%; text-align: left; }
.sommaire a, .contes a { display: flex; align-items: baseline; gap: 10px; padding: 10px 6px; min-height: 48px; text-decoration: none; border-radius: 8px; }
.sommaire a:hover, .contes a:hover { background: rgba(227, 199, 126, .25); }
.rom { font: 600 1.7rem var(--font-display); color: var(--c); min-width: 2.2em; }
.nom { display: flex; flex-direction: column; line-height: 1.15; }
.nom strong { font: 600 1.5rem var(--font-display); color: var(--brown); }
.nom em { font-size: .95rem; color: var(--muted); }
.pts { flex: 1; border-bottom: 2px dotted rgba(74, 55, 40, .35); transform: translateY(-5px); min-width: 14px; }
.nb, .no { font: 600 1.15rem var(--font-display); color: var(--terracotta-text); }
.no { min-width: 2em; }
.contes .t { font: 500 1.35rem/1.15 var(--font-display); color: var(--brown); }
.contes .t.lu { color: var(--muted); }
.lue { color: var(--cuir); font-weight: 700; min-width: 1em; text-align: right; }
.grand { font-size: clamp(3rem, 9vw, 5rem); color: var(--c); }
.accroche { font: italic 500 1.4rem var(--font-display); color: var(--brown); margin: 8px 0 0; }
.note { border-bottom: 1px solid rgba(74, 55, 40, .18); padding: 14px 4px 10px; }
.note small { color: var(--muted); }
.note p { font: 500 1.4rem/1.3 var(--font-display); color: var(--brown); margin: 4px 0 2px; }
.lien { background: none; border: 0; padding: 10px 10px 10px 0; min-height: 44px; font: 500 .95rem var(--font-body); color: var(--terracotta-text); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* onglets de chapitres (sur le bord) et ruban marque-page */
.onglets { display: flex; justify-content: center; gap: 6px; margin: 0 0 -1px; padding: 0 8px; position: relative; z-index: 3; }
.onglet { display: grid; place-items: center; min-width: 44px; height: 44px; border-radius: 10px 10px 0 0; background: var(--c); color: #fff; text-decoration: none; font: 600 1.15rem var(--font-display); opacity: .82; transition: transform .2s, opacity .2s; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .18); }
.onglet:hover { opacity: 1; transform: translateY(-3px); }
.onglet.actif { opacity: 1; transform: translateY(-5px); }
.ruban { position: absolute; z-index: 4; top: 44px; right: 22px; width: 22px; height: 70px; background: #A8504A; clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 82%, 0 100%); box-shadow: 0 2px 4px rgba(0, 0, 0, .4); transition: height .25s; }
.ruban:hover { height: 92px; }

/* tourner les pages */
.pager { display: flex; align-items: center; justify-content: center; gap: 18px; margin-top: 22px; color: #EFE3C8; }
.pager button { width: 52px; height: 52px; border-radius: 50%; border: 2px solid var(--or); background: transparent; color: var(--or); font: 600 2rem/1 var(--font-display); cursor: pointer; transition: background .2s, transform .2s; }
.pager button:hover { background: rgba(227, 199, 126, .2); transform: scale(1.06); }
.pos { min-width: 70px; text-align: center; font: italic 500 1.1rem var(--font-display); }

/* animation de page tournée */
.tourne-av .page:not([hidden]) { transform-origin: left center; animation: av .55s ease-out; }
.tourne-ar .page:not([hidden]) { transform-origin: right center; animation: ar .55s ease-out; }
@keyframes av { from { transform: rotateY(-50deg); opacity: .25; } to { transform: none; opacity: 1; } }
@keyframes ar { from { transform: rotateY(50deg); opacity: .25; } to { transform: none; opacity: 1; } }

/* grand écran : deux pages face à face, reliure au milieu */
@media (min-width: 900px) {
  .feuillets { display: grid; grid-template-columns: 1fr 1fr; }
  .page { min-height: min(72vh, 700px); }
  .page.gauche { border-radius: 8px 0 0 8px; box-shadow: inset -26px 0 30px -18px rgba(74, 55, 40, .4); }
  .page.droite { border-radius: 0 8px 8px 0; box-shadow: inset 26px 0 30px -18px rgba(74, 55, 40, .4); }
  .page.gauche .folio { text-align: left; padding-left: 34px; }
  .page.droite .folio { text-align: right; padding-right: 34px; }
  .p-in { padding: 44px 52px 64px; }
  .p-in.vertical { min-height: min(72vh, 700px); }
  .texte p { font-size: 1.18rem; }
  .onglets { position: absolute; top: 40px; right: -48px; flex-direction: column; gap: 6px; padding: 0; margin: 0; z-index: 1; }
  .onglet { border-radius: 0 10px 10px 0; min-width: 48px; height: 52px; box-shadow: inset -3px 0 0 rgba(0, 0, 0, .18); }
  .onglet:hover, .onglet.actif { transform: translateX(6px); }
  .ruban { top: -2px; right: calc(50% - 11px); height: 90px; }
  .tourne-av .page.droite:not([hidden]) { animation: av .6s ease-out; }
  .tourne-av .page.gauche:not([hidden]) { animation: none; }
  .tourne-ar .page.gauche:not([hidden]) { animation: ar .6s ease-out; }
  .tourne-ar .page.droite:not([hidden]) { animation: none; }
  .livre { margin-right: 48px; }
  .table-livre { padding-right: 60px; }
}
@media (max-width: 899px) { .page { border-radius: 8px; } }
@media (max-width: 440px) { .barre .titre-barre { font-size: 1.1rem; } .barre a { padding: 10px 8px; font-size: .85rem; } .p-in { padding: 28px 20px 52px; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } html { scroll-behavior: auto; } }

.installer { background: none; border: 1px solid rgba(227, 199, 126, .6); color: #F3E6C2; border-radius: 999px; min-height: 44px; padding: 8px 18px; font: 500 .9rem var(--font-body); cursor: pointer; }
.installer[hidden] { display: none; }
.installer:hover { background: rgba(227, 199, 126, .15); }

/* ---------- pages à hauteur fixe (comme un vrai livre) ---------- */
.page { height: max(480px, calc(100svh - 250px)); min-height: 0; overflow: hidden; }
.p-in { height: 100%; overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgba(138, 106, 31, .4) transparent; }
.p-in.vertical { min-height: 0; }
.sonde { position: absolute; left: 0; right: 0; top: 0; visibility: hidden; pointer-events: none; }
.sonde .page { display: block; }
.texte p.cont { margin-top: -.15em; }
.vide-barre { min-width: 90px; }

/* ---------- marque-pages avec le nom du chapitre ---------- */
.onglets { gap: 4px; padding: 0 4px; }
.onglet { display: flex; align-items: center; justify-content: center; gap: 8px; min-width: 38px; height: 44px; }
.onglet b { font: 600 1.15rem var(--font-display); }
.onglet span { display: none; font: 500 .95rem var(--font-body); white-space: nowrap; }
.onglet.carnet b { font-size: 1.35rem; }
@media (min-width: 900px) {
  .page { height: min(76vh, 740px); }
  .onglets { top: 34px; right: -134px; width: 142px; gap: 6px; padding: 0; }
  .onglet { width: 100%; height: 50px; justify-content: flex-start; padding: 0 12px 0 18px; border-radius: 0 12px 12px 0; }
  .onglet b { min-width: 1.7em; }
  .onglet span { display: inline; }
  .onglet.carnet { margin-top: 12px; }
  .livre { margin-right: 134px; }
  .table-livre { padding-right: 20px; }
}
@media (max-width: 440px) { .vide-barre { min-width: 70px; } }

/* la planche s'adapte à la hauteur de la page (pour que titre + image tiennent toujours) */
:root { --hp: max(480px, calc(100svh - 250px)); }
@media (min-width: 900px) { :root { --hp: min(76vh, 740px); } }
.page { height: var(--hp); }
.planche { max-width: min(560px, calc((var(--hp) - 300px) * 1.55)); }
.titre-conte { font-size: clamp(2rem, 5.2vw, 3.2rem); }

/* ---------- navigation en bas des pages du livre ---------- */
.feuillets { touch-action: pan-y; -webkit-user-select: none; user-select: none; }
.pager { position: absolute; left: 0; right: 0; bottom: 10px; z-index: 7; margin: 0; padding: 0 14px; display: flex; align-items: center; justify-content: space-between; pointer-events: none; color: var(--brown); }
.pager button { pointer-events: auto; width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid var(--or-sombre); background: rgba(251, 246, 234, .92); color: var(--brown); font: 600 1.7rem/1 var(--font-display); padding: 0 0 4px; cursor: pointer; box-shadow: 0 2px 6px rgba(74, 55, 40, .25); transition: background .2s, transform .2s; }
.pager button:hover { background: #fff; transform: scale(1.07); }
.pos { min-width: 0; font: italic 500 1rem var(--font-display); color: var(--muted); }
.p-in { padding-bottom: 92px; }
.folio { bottom: 60px; }
@media (min-width: 900px) {
  .pager { padding: 0 22px; }
  .folio { bottom: 22px; text-align: center !important; padding: 0 !important; }
  .p-in { padding-bottom: 80px; }
}

/* ---------- la feuille qui tourne ---------- */
.tournage { position: absolute; inset: 0; z-index: 5; perspective: 2600px; border-radius: 8px; --o: 0; }
.tournage .sous { position: absolute; inset: 0; }
.tournage .page { position: absolute; top: 0; width: 100%; height: 100%; left: 0; }
.tournage.double .sous .page.droite { left: 50%; width: 50%; }
.tournage.double .sous .page.gauche { left: 0; width: 50%; }
.feuille { position: absolute; top: 0; height: 100%; transform-style: preserve-3d; will-change: transform; }
.feuille.droite { left: 50%; width: 50%; transform-origin: left center; }
.feuille.gauche { left: 0; width: 50%; transform-origin: right center; }
.feuille.plein { left: 0; width: 100%; transform-origin: left center; }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; }
.face.ar { transform: rotateY(180deg); }
.face .page { position: relative; width: 100%; height: 100%; }
.face::after { content: ''; position: absolute; inset: 0; pointer-events: none; opacity: var(--o); background: linear-gradient(90deg, rgba(60, 40, 25, 0), rgba(60, 40, 25, .85)); }
.feuille.gauche .face::after { background: linear-gradient(270deg, rgba(60, 40, 25, 0), rgba(60, 40, 25, .85)); }
.tournage .page { min-height: 0; }

/* ajustements pour que titre + image + sommaire tiennent toujours dans la hauteur fixe */
.planche { max-width: min(560px, calc((var(--hp) - 360px) * 1.55)); }
.titre-conte.long { font-size: clamp(1.7rem, 4vw, 2.4rem); }
.sommaire { margin-top: 6px; }
.sommaire a { min-height: 44px; padding: 3px 6px; }
.nom strong { font-size: 1.35rem; }
.nom em { font-size: .88rem; }
.rom { font-size: 1.5rem; }
.p-in h1 { font-size: clamp(2rem, 5vw, 3rem); }
.p-in .fleuron { margin: 8px auto; }
@media (max-width: 899px) { .sommaire .nom em { display: none; } .sommaire a { align-items: center; } }

/* planche un peu plus large que haute : on garde le haut de l'image (le sujet) */
.planche .cadre { aspect-ratio: 16 / 9; }
.planche img { object-position: 50% 25%; }
.planche { max-width: min(560px, calc((var(--hp) - 340px) * 1.78)); }
