@import url("fonts.css");

:root {
  --ground: #E9EDEA; --surface: #F7F9F7; --paper: #FCFCFA; --sunk: #DFE5E1;
  --ink: #18221E; --muted: #56655E; --line: #C3CEC8;
  --accent: #2C6A55; --accent-ink: #FFFFFF;
  --gold: #E69F00; --death: #1E1E1E; --death-ink: #FFFFFF; --combat: #D55E00; --spell: #0072B2; --normal: #7A8781;
  --loss: #A12A1F; --gain: #1F6B4F;
  --display: "Alegreya SC", "Palatino Linotype", Georgia, serif;
  --serif: "Alegreya", "Palatino Linotype", Georgia, serif;
  --sans: "Alegreya Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --read-size: 19px;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ground: #0F1513; --surface: #161E1B; --paper: #131A17; --sunk: #1D2723;
    --ink: #E1E9E5; --muted: #93A39B; --line: #2C3833;
    --accent: #72C2A2; --accent-ink: #0F1513;
    --death: #EDEDED; --death-ink: #111111; --combat: #E8773A; --spell: #56B4E9; --normal: #7D8D86;
    --loss: #FF8A7A; --gain: #7DD3AE;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ground: #0F1513; --surface: #161E1B; --paper: #131A17; --sunk: #1D2723;
  --ink: #E1E9E5; --muted: #93A39B; --line: #2C3833;
  --accent: #72C2A2; --accent-ink: #0F1513;
  --death: #EDEDED; --death-ink: #111111; --combat: #E8773A; --spell: #56B4E9; --normal: #7D8D86;
  --loss: #FF8A7A; --gain: #7DD3AE;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--ground); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
a { color: var(--accent); }
img { max-width: 100%; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }

/* ---------- barre du haut ---------- */
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { font-family: var(--display); font-weight: 700; font-size: 22px; text-decoration: none; color: var(--ink); letter-spacing: .01em; }
.topbar .spacer { flex: 1; }
/* Barre de l'éditeur : collée sous la barre principale (hauteur réelle mesurée par app.js) ; sur un petit écran,
   elle défile avec la page pour laisser la place au texte. */
.ed-bar { top: calc(env(safe-area-inset-top, 0px) + var(--topbar-h, 61px)); z-index: 15; border-top: 0; }
@media (max-width: 800px) { .ed-bar { position: static; } }
.topbar .crumb { font-family: var(--display); font-size: 18px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

/* ---------- boutons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 8px 14px; font-weight: 500; text-decoration: none; color: var(--ink); min-height: 40px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.btn.danger { color: var(--loss); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 14px; }
.btn.ghost { background: none; border-color: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; flex: none; }
.ico { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; }
.ending .mark .ico { width: 72px; height: 72px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
/* Case à cocher et son texte : toujours côte à côte (le texte passe à la ligne à droite de la case). */
label.row:has(> input[type=checkbox]), label.row:has(> input[type=radio]) { flex-wrap: nowrap; align-items: flex-start; }
label.row:has(> input[type=checkbox]) > input, label.row:has(> input[type=radio]) > input { flex: none; margin-top: .2em; }
.stack { display: grid; gap: 12px; }
.muted { color: var(--muted); }
/* Texte réservé aux lecteurs d'écran. */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- formulaires ---------- */
label.field { display: grid; gap: 4px; font-size: 14px; color: var(--muted); font-weight: 500; }
input[type=text], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); color: var(--ink); min-height: 38px;
}
textarea { resize: vertical; line-height: 1.5; }
input[type=number] { font-family: var(--mono); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }

/* ---------- page ---------- */
.page { max-width: 1100px; margin: 0 auto; padding: 24px 16px 64px; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; line-height: 1.15; text-wrap: balance; margin: 0; }
h1 { font-size: 34px; }
h2 { font-size: 24px; }
h3 { font-size: 18px; }
.eyebrow { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 700; }

/* ---------- bibliothèque ---------- */
.lib-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: grid; grid-template-rows: auto 1fr auto; }
.card .cover { aspect-ratio: 3 / 2; background: var(--sunk); display: grid; place-items: center; overflow: hidden; }
.card .cover img { width: 100%; height: 100%; object-fit: cover; }
.card .cover .ph { font-family: var(--display); font-size: 42px; color: var(--muted); }
.card .body { padding: 14px 16px 8px; display: grid; gap: 6px; align-content: start; }
.card .foot { padding: 10px 16px 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; color: var(--muted); width: fit-content; }
/* Pastille cliquable (ex. objet de départ à retirer) : couleurs de l'application, jamais le gris natif des boutons. */
button.badge { background: var(--paper); color: var(--ink); cursor: pointer; font-family: inherit; }
button.badge:hover { border-color: var(--accent); }

/* ---------- lecture ---------- */
.play { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; max-width: 1180px; margin: 0 auto; padding: 20px 16px 80px; align-items: start; }
.reader { scroll-margin-top: 76px; background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 28px clamp(16px, 4vw, 48px) 36px; min-width: 0; }
.sec-num { font-family: var(--mono); font-weight: 700; font-size: 44px; line-height: 1; text-align: center; margin-bottom: 18px; }
.sec-num small { display: block; font-family: var(--display); font-size: 18px; font-weight: 500; color: var(--muted); margin-top: 6px; }
/* La télé (meta.tele) : pleine largeur ; numéro, titre et boutons, petits, à gauche, la télé à droite ; l'une sous l'autre sur téléphone. */
.play.with-tele { max-width: none; }
.sec-top { display: grid; grid-template-columns: minmax(150px, 1fr) minmax(0, 3fr); gap: 14px 24px; align-items: start; margin-bottom: 20px; }
.sec-top-left { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; min-width: 0; }
.sec-top .sec-num { text-align: left; margin-bottom: 0; font-size: 28px; }
.sec-top .sec-num small { font-size: 14px; margin-top: 4px; }
.sec-top .btn.small { min-height: 28px; padding: 2px 9px; font-size: 13px; }
.with-tele .choice { padding: 8px 12px; font-size: calc(var(--read-size) - 3px); }
.with-tele .choices { gap: 6px; }
/* La télé garde sa place dans la page ; au défilement, elle s'envole en vignette en haut à droite, réductible en pastille. */
.tele-dock { position: relative; aspect-ratio: 16 / 9; max-width: 100%; }
.tele { position: absolute; inset: 0; margin: 0; border-radius: 12px; overflow: hidden; background: #0d1a15; border: 1px solid var(--line); box-shadow: 0 6px 24px rgb(0 0 0 / .12); }
.tele.is-floating { position: fixed; inset: auto; top: calc(env(safe-area-inset-top, 0px) + var(--topbar-h, 61px) + 10px); right: max(12px, env(safe-area-inset-right, 0px)); width: min(440px, 42vw); aspect-ratio: 16 / 9; z-index: 30; box-shadow: 0 14px 40px rgb(0 0 0 / .35); animation: tele-fly .3s ease; }
.tele.is-floating .tele-sub .prose { font-size: 13px; }
.tele.is-floating .tele-sub { max-height: 5.5em; }
.tele.is-mini { width: auto; aspect-ratio: auto; height: 42px; background: transparent; border: 0; box-shadow: none; overflow: visible; }
.tele.is-mini iframe, .tele.is-mini .tele-subs { visibility: hidden; }
.tele.is-mini .tele-bar { position: static; padding: 4px; }
.tele-bar .tele-pill { width: auto; height: 34px; padding: 0 12px; display: inline-flex; gap: 6px; align-items: center; font-size: 13px; background: rgb(10 20 16 / .82); }
@keyframes tele-fly { from { transform: scale(.92); transform-origin: top right; } to { transform: none; } }
.tele iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; }
.tele-bar { position: absolute; top: 8px; right: 8px; display: flex; align-items: center; gap: 6px; font-size: 12px; z-index: 2; }
.tele-bar span { padding: 4px 9px; border-radius: 999px; background: rgb(10 20 16 / .62); color: #f4f7ef; }
.tele-bar button { width: 30px; height: 30px; border: 0; border-radius: 8px; background: rgb(10 20 16 / .62); color: #f4f7ef; font-size: 16px; line-height: 1; cursor: pointer; }
.tele-bar button:hover, .tele-bar button:focus-visible { background: rgb(10 20 16 / .85); }
.tele-bar button.tele-view.on { background: #ffd54a; color: #2a2008; }
.tele-bar button:disabled { opacity: .4; cursor: default; }
/* Plein écran de toute la page (cinéma) : plus de barre du haut, le monde jusqu'au bord. */
html.lh-full { --topbar-h: 0px; }
html.lh-full .topbar { display: none; }
.tele-off { display: flex; justify-content: flex-end; }
/* La légende en bas de la télé ; les boutons de la page compagnon juste au-dessus (elle reçoit la hauteur de la
   légende) ; toucher l'écran fait avancer la légende (Florian, 18/10, après essai des deux dispositions). */
.tele-subs { position: absolute; left: 0; right: 0; bottom: 0; padding: 30px 14px 8px; background: linear-gradient(to top, rgb(5 12 9 / .9) 60%, rgb(5 12 9 / 0)); color: #f7f5ec; display: grid; gap: 4px; }
@media (pointer: coarse) { .tele-subs-nav button { width: 44px; height: 36px; font-size: 22px; } .tele-subs-nav .tele-skip { font-size: 13px; } }
.tele-sub { cursor: pointer; max-height: 9.5em; overflow-y: auto; text-align: center; text-shadow: 0 1px 3px rgb(0 0 0 / .7); animation: tele-sub-in .35s ease; }
.tele-sub .prose { font-size: clamp(14px, 1.3vw, 19px); line-height: 1.45; max-width: 62ch; margin: 0 auto; }
.tele-sub .prose p, .tele-sub .prose blockquote, .tele-sub .prose ul { margin: 0 0 .35em; }
.tele-sub .prose blockquote { border: 0; padding: 0; font-style: italic; color: inherit; }
.tele-sub .prose strong { color: #ffe08a; }
.tele-subs-nav { display: flex; justify-content: center; align-items: center; gap: 10px; font-size: 12px; opacity: .85; }
.tele-subs-nav button { width: 28px; height: 24px; border: 0; border-radius: 6px; background: rgb(255 255 255 / .16); color: inherit; font-size: 16px; line-height: 1; cursor: pointer; }
.tele-subs-nav button:disabled { opacity: .35; cursor: default; }
.tele-subs-nav .tele-skip { width: auto; padding: 0 10px; font-size: 12px; margin-left: 6px; }
@keyframes tele-sub-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
/* La télé en plein écran : le monde, les sous-titres en grand, et les boutons du livre dans la barre du monde. */
html.lh-full .play.cinema .tele-subs { padding: 60px 6vw 18px; }
html.lh-full .play.cinema .tele-sub { max-height: 32vh; }
html.lh-full .play.cinema .tele-sub .prose { font-size: clamp(18px, 2vw, 30px); max-width: 70ch; }
html.lh-full .play.cinema .tele-subs-nav { font-size: 15px; }
/* Sur téléphone, en cinéma, la barre de la télé (vues, plein écran) se range en colonne à droite : la pastille garde la gauche. */
@media (max-width: 600px) { .play.cinema .tele-bar { flex-direction: column; align-items: flex-end; } }
/* Le cinéma (`meta.tele.cinema`, bouton « Cinéma ») : le monde en 3D en grand sous la barre du haut, le livre par-dessus. */
html.lh-cinema, html.lh-cinema body { overflow: hidden; }
.play.cinema { display: block; padding: 0; max-width: none; }
.play.cinema .reader { border: 0; padding: 0; background: transparent; }
.play.cinema .tele { position: fixed; inset: calc(env(safe-area-inset-top, 0px) + var(--topbar-h, 61px)) 0 0 0; border: 0; border-radius: 0; z-index: 20; box-shadow: none; }
.play.cinema .tele-dock { width: 0; height: 0; aspect-ratio: auto; }
.play.cinema .tele { pointer-events: auto; } /* la pastille laisse passer les clics ; la télé, elle, les reçoit */
.play.cinema .sec-top { position: fixed; z-index: 22; top: calc(env(safe-area-inset-top, 0px) + var(--topbar-h, 61px) + 10px); left: max(10px, env(safe-area-inset-left, 0px)); display: block; margin: 0; pointer-events: none; }
.play.cinema .sec-top-left { position: relative; z-index: 25; pointer-events: auto; max-width: min(380px, calc(100vw - 20px)); gap: 6px; padding: 8px 10px; border-radius: 12px; background: rgb(10 20 16 / .66); color: #f4f7ef; backdrop-filter: blur(6px); }
.play.cinema .sec-top .sec-num { color: inherit; font-size: 22px; }
.play.cinema .sec-top .sec-num small { color: #dfe7da; font-size: 13px; }
.sec-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.sec-progress { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; font-variant-numeric: tabular-nums; }
.sec-progress > span { white-space: nowrap; }
.play.cinema .sec-top .btn.small { background: rgb(255 255 255 / .12); border-color: rgb(255 255 255 / .28); color: inherit; }
.play.cinema .sec-top .btn.small:hover { background: rgb(255 255 255 / .24); }
.play.cinema .play-fab { display: none; }
.play.cinema.popping .sec-top-left { visibility: hidden; } /* le défi ouvert passe devant tout */
/* En cinéma, la légende laisse la place à la pastille du livre (à gauche) et à la barre de la télé (à droite). */
@media (max-width: 900px) { .play.cinema .tele-bar span { display: none; } }
/* Le défi et les messages vivent dans la télé : au-dessus du monde, des sous-titres et de la barre. */
.tele > .block-pop, .tele > .block-pop-pill, .tele > .msgs.toasts { z-index: 5; }
/* Dans la fenêtre du défi, la barre du jeu (Recommencer, Agrandir) reste en haut sous « Voir la télé » quand on fait défiler. */
.block-pop .zf-stage-wrap { overflow: clip; }
.block-pop .zf-frame-bar { position: sticky; top: 38px; z-index: 2; }
.tele .block-pop-card { color: var(--ink); text-shadow: none; }
/* La feuille d'aventure : un tiroir, comme sur téléphone, ouvert par « Feuille ». */
.play.cinema .sheet { position: fixed; inset: auto 0 0 auto; top: calc(env(safe-area-inset-top, 0px) + var(--topbar-h, 61px)); width: min(380px, 100vw); max-height: none; border-radius: 16px 0 0 0; z-index: 30; transform: translateX(105%); transition: transform .25s; box-shadow: -8px 0 30px rgb(0 0 0 / .25); }
.play.cinema .sheet.open { transform: none; }
.play.cinema .sheet .sheet-toggle { display: inline-flex; }
@media (max-width: 600px) { .play.cinema .sec-top .sec-num small { display: none; } .play.cinema .sec-top .btn.small { padding: 2px 7px; font-size: 12px; } }
/* Un défi facultatif (« pour réfléchir en marchant ») : un panneau sur le côté, la télé continue. */
.block-pop.side { background: transparent; backdrop-filter: none; place-items: end; pointer-events: none; animation: none; }
.block-pop.side { place-items: center end; }
.block-pop.side .block-pop-card { pointer-events: auto; width: min(560px, 100%); max-height: calc(100% - 200px); margin: 10px 0 170px; animation: side-in .3s ease; }
/* Sur téléphone, le panneau « pour réfléchir en marchant » prend tout l'écran : il cache la pastille comme les autres
   défis, au lieu de passer dessous (Florian, 18/10 : « les défis sont sous le menu »). */
@media (max-width: 760px) {
  .play.cinema.popping-side .sec-top-left { visibility: hidden; }
  .block-pop.side { place-items: center; pointer-events: auto; background: rgb(8 16 12 / .45); }
  .block-pop.side .block-pop-card { width: 100%; max-height: 100%; margin: 0; }
}
@keyframes side-in { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
/* Le défi surgit dans une fenêtre au-dessus de la télé, en pause derrière ; « Voir la télé » la cache, une pastille la rappelle. */
.block-pop { position: fixed; inset: 0; z-index: 35; display: grid; place-items: center; padding: calc(var(--topbar-h, 61px) + 12px) max(12px, env(safe-area-inset-right, 0px)) 16px max(12px, env(safe-area-inset-left, 0px)); background: rgb(8 16 12 / .55); backdrop-filter: blur(3px); animation: pop-in .28s ease; }
.block-pop.is-hidden { display: none; }
.block-pop-card { width: min(1080px, 100%); max-height: 100%; overflow: auto; overscroll-behavior: contain; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 24px 70px rgb(0 0 0 / .4); padding: 12px clamp(10px, 2vw, 22px) 18px; }
.block-pop-bar { position: sticky; top: -12px; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: -12px calc(-1 * clamp(10px, 2vw, 22px)) 10px; padding: 10px clamp(10px, 2vw, 22px); background: var(--paper); border-bottom: 1px solid var(--line); }
.block-pop-pill { position: fixed; z-index: 36; left: 50%; transform: translateX(-50%); bottom: max(18px, env(safe-area-inset-bottom, 0px)); box-shadow: 0 10px 30px rgb(0 0 0 / .3); }
@keyframes pop-in { from { opacity: 0; } to { opacity: 1; } }
@media (max-width: 760px) { .block-pop { padding: calc(var(--topbar-h, 61px) + 4px) 4px 4px; } .block-pop-card { border-radius: 10px; } }
/* Le défi et les choix attendent la fin du récit. */
.read-gate { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; margin: 18px auto; color: var(--muted); font-size: 14px; }
/* Messages évanescents : ils surgissent, restent le temps d'être lus, puis s'effacent (une alerte reste plus longtemps). */
.update-banner { position: fixed; z-index: 60; left: 50%; top: max(10px, env(safe-area-inset-top, 0px)); transform: translateX(-50%); width: min(560px, calc(100vw - 32px));
  display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 14px; border-radius: 12px; background: var(--paper, #fff); color: var(--ink, #222);
  border: 1px solid var(--line); box-shadow: 0 10px 30px rgb(0 0 0 / .18); font-family: var(--sans); font-size: 15px; }
.update-banner span { flex: 1; }
.msgs.toasts { position: fixed; z-index: 40; left: 50%; bottom: max(24px, env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); width: min(560px, calc(100vw - 32px)); margin: 0; pointer-events: none; }
.msgs.toasts .msg { box-shadow: 0 10px 30px rgb(0 0 0 / .18); animation: msg-pop 3.6s ease forwards; }
.msgs.toasts .msg:nth-child(2) { animation-delay: .15s; } .msgs.toasts .msg:nth-child(3) { animation-delay: .3s; } .msgs.toasts .msg:nth-child(n+4) { animation-delay: .45s; }
.msgs.toasts .msg.alert { animation-duration: 7s; }
/* Une pile qui ne mange pas l'écran : les plus récents seulement, compacts, en un tiers de hauteur au plus. */
.msgs.toasts { display: flex; flex-direction: column; justify-content: flex-end; top: auto; height: auto; max-height: none; }
.msgs.toasts .msg:nth-last-child(n+6) { display: none; }
@media (max-width: 600px) {
  .msgs.toasts { width: calc(100vw - 20px); gap: 4px; bottom: max(10px, env(safe-area-inset-bottom, 0px)); }
  .msgs.toasts .msg { padding: 3px 8px; font-size: 13px; line-height: 1.3; }
  .msgs.toasts .msg svg { width: 14px; height: 14px; flex: none; }
  .msgs.toasts .msg:nth-last-child(n+4) { display: none; }
}
/* Dans la télé (cinéma, qui couvre l'écran sous la barre du haut), défi et messages sont placés par rapport à elle :
   les messages au-dessus de la légende et des boutons (--legend : hauteur de la légende). */
.tele > .msgs.toasts { position: absolute; top: auto; bottom: calc(var(--legend, 0px) + 84px); }
@media (max-width: 600px) { .tele > .msgs.toasts { bottom: calc(var(--legend, 0px) + 150px); } } /* les boutons du monde passent sur deux lignes */
.tele > .block-pop { position: absolute; padding: 10px max(10px, env(safe-area-inset-right, 0px)) 12px max(10px, env(safe-area-inset-left, 0px)); }
.tele > .block-pop-pill { position: absolute; bottom: calc(var(--legend, 0px) + 16px); }
@media (max-width: 760px) { .tele > .block-pop { padding: 4px; } }
@keyframes msg-pop { 0% { opacity: 0; transform: translateY(14px) scale(.96); } 8% { opacity: 1; transform: none; } 82% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-8px); visibility: hidden; } }
@media (prefers-reduced-motion: reduce) { .tele-sub, .tele.is-floating { animation: none; } .msgs.toasts .msg { animation: msg-fade 4s steps(1, end) forwards; } }
@keyframes msg-fade { to { visibility: hidden; } }
@media (max-width: 760px) { .sec-top { grid-template-columns: 1fr; } }
.illus { margin: 0 0 20px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: var(--sunk); }
.illus img { display: block; width: 100%; max-height: 60vh; object-fit: contain; background: var(--sunk); cursor: zoom-in; }
.prose { font-family: var(--serif); font-size: var(--read-size); line-height: 1.65; max-width: 66ch; margin: 0 auto; text-align: var(--align, justify); hyphens: auto; -webkit-hyphens: auto; }
.prose p { margin: 0 0 1em; }
.prose h3 { font-size: 1.15em; margin: 1.2em 0 .4em; }
.msgs { display: grid; gap: 6px; margin: 16px auto 0; max-width: 66ch; }
.msg { display: flex; gap: 8px; align-items: center; padding: 6px 10px; border-radius: 6px; font-weight: 500; border: 1px solid var(--line); background: var(--surface); }
.msg.loss { color: var(--loss); } .msg.gain { color: var(--gain); }
.msg.alert { border: 2px solid var(--accent); font-weight: 700; }
.msg svg { width: 16px; height: 16px; flex: none; }

.choices { display: grid; gap: 8px; max-width: 66ch; margin: 24px auto 0; }
.choice { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; text-align: left; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-family: var(--serif); font-size: calc(var(--read-size) - 1px); }
.choice:hover:not(:disabled) { border-color: var(--accent); box-shadow: inset 4px 0 0 var(--accent); }
.choice .go { font-family: var(--mono); font-weight: 700; font-size: 15px; color: var(--muted); }
.choice:disabled { cursor: not-allowed; opacity: .6; border-style: dashed; }
.choice .why { grid-column: 1 / -1; font-family: var(--sans); font-size: 14px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.choice .why svg { width: 14px; height: 14px; }
/* Choix regroupés (sections[n].choices[i].group) ; en colonnes avec sections[n].choiceLayout = "columns" */
.choices.grouped { gap: 16px; }
.choice-group { display: grid; gap: 6px; align-content: start; min-width: 0; }
.choice-group-title { margin: 0; font-family: var(--sans); font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.choices.cols { max-width: none; grid-template-columns: repeat(auto-fit, minmax(12.5rem, 1fr)); align-items: start; }
.choices.cols .choice-group.free { grid-column: 1 / -1; }
.choices.cols .choice { padding: 8px 10px; gap: 8px; font-size: calc(var(--read-size) - 3px); line-height: 1.25; }
.choice .go.stay { font-size: 18px; font-weight: 400; }

.block { max-width: 66ch; margin: 24px auto 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 16px; display: grid; gap: 12px; }
.block h3 { display: flex; gap: 8px; align-items: center; font-size: 18px; }
.block h3 svg { width: 22px; height: 22px; }
.outcome { display: flex; gap: 10px; align-items: center; font-weight: 700; font-size: 17px; }
.outcome.ok::before { content: "✓"; } .outcome.ko::before { content: "✗"; }
.table-roll { width: 100%; border-collapse: collapse; font-size: 15px; }
.table-roll td { padding: 4px 8px; border-top: 1px solid var(--line); }
.table-roll tr.hit td { font-weight: 700; background: color-mix(in srgb, var(--accent) 12%, transparent); }
.table-roll tr.hit td:first-child::before { content: "▶ "; }

.ending { text-align: center; max-width: 60ch; margin: 28px auto 0; display: grid; gap: 12px; justify-items: center; }
.ending .mark { display: block; }
.ending h2 { font-size: 30px; }

/* ---------- dés ---------- */
.dice { display: inline-flex; gap: 8px; align-items: center; }
.die { width: 46px; height: 46px; border-radius: 10px; background: var(--paper); border: 2px solid var(--ink); display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); padding: 6px; box-shadow: 0 2px 0 var(--line); }
.die i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink); place-self: center; visibility: hidden; }
.die.rolling { animation: tumble .6s cubic-bezier(.3,.7,.4,1); }
@keyframes tumble { 0% { transform: rotate(-200deg) scale(.6) translateY(-18px); } 60% { transform: rotate(20deg) scale(1.08); } 100% { transform: none; } }
.dice-total { font-family: var(--mono); font-weight: 700; font-size: 22px; }
.die.num { display: grid; grid-template-columns: 1fr; grid-template-rows: 1fr; place-items: center; padding: 0; }
.die.num b { font: 700 20px/1 var(--mono); }
.die.poly { border-radius: 16px 5px 16px 5px; }

/* ---------- dés de la feuille (repliables, plus vivants une fois ouverts) ---------- */
.sheet-fold { border: 1px solid var(--line); border-radius: 10px; background: var(--paper); }
.sheet-fold > summary { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; cursor: pointer; list-style: none; }
.sheet-fold > summary::-webkit-details-marker { display: none; }
.sheet-fold > summary::after { content: '▸'; color: var(--muted); transition: transform .15s; }
.sheet-fold[open] > summary::after { transform: rotate(90deg); }
.sheet-fold > summary .subtle { margin-left: auto; font-size: 13px; }
.sheet-fold > textarea { display: block; width: calc(100% - 20px); margin: 0 10px 10px; }
.dicebox { display: grid; gap: 10px; padding: 10px; margin: 0 8px 8px; border-radius: 10px;
  background: radial-gradient(120% 90% at 0% 0%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%),
              radial-gradient(120% 90% at 100% 100%, color-mix(in srgb, var(--gold, #E0B040) 26%, transparent), transparent 60%), var(--surface);
  border: 1px solid var(--line); }
.dice-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.dice-chip { padding: 3px 9px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--paper); color: var(--ink);
  font: 700 13px/1.4 var(--mono); cursor: pointer; transition: transform .1s; }
.dice-chip:hover { border-color: var(--accent); transform: translateY(-1px); }
.dice-chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.dicebox #free-dice { width: 0; flex: 1; min-width: 70px; font-family: var(--mono); text-transform: uppercase; }
.dice-go { font-size: 16px; padding-inline: 14px; }
.dice-go:hover .ico { animation: dice-wiggle .5s ease-in-out; }
@keyframes dice-wiggle { 25% { transform: rotate(-18deg); } 75% { transform: rotate(18deg); } }
.dice-stage { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; min-height: 64px; }
.dicebox .dice { flex-wrap: wrap; }
.dicebox .die { width: 52px; height: 52px; background: var(--accent); border-color: color-mix(in srgb, var(--accent) 60%, #000);
  box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 55%, #000), 0 8px 16px rgb(0 0 0 / .18); }
.dicebox .die i { width: 8px; height: 8px; background: var(--accent-ink); }
.dicebox .die.num b { color: var(--accent-ink); font-size: 22px; }
.dicebox .dice-total { font-size: 34px; }
.dice-hype .ico, .sheet-fold summary .ico { width: 15px; height: 15px; vertical-align: -2px; }
.dice-hype { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font: 700 14px/1.5 var(--sans); border: 2px solid var(--ink); background: var(--paper); }
.dice-hype.top { border-color: var(--accent); }
.dice-hist { margin: 0; display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; color: var(--muted); }
@media (prefers-reduced-motion: no-preference) {
  .dicebox .dice-total { animation: dice-pop .45s .55s both cubic-bezier(.3, 1.6, .5, 1); }
  .dice-hype { animation: dice-pop .4s .65s both cubic-bezier(.3, 1.6, .5, 1); }
  @keyframes dice-pop { from { transform: scale(.3); opacity: 0; } to { transform: none; opacity: 1; } }
}

/* ---------- lecture continue, numéros cachés ---------- */
.sec-num.titled small { font-size: 15px; letter-spacing: .08em; }
.sec-num.stepped { display: grid; justify-items: center; gap: 6px; }
.sec-step { font: 700 44px/1 var(--mono); }
.sec-step .of { font-size: 20px; color: var(--muted); margin-left: 2px; }
.sec-gauge { display: inline-flex; gap: 4px; }
.sec-gauge i { width: 18px; height: 6px; border-radius: 3px; border: 1.5px solid var(--ink); }
.sec-gauge i.on { background: var(--accent); border-color: var(--accent); }
.sec-num.stepped small { margin-top: 0; font-size: 15px; letter-spacing: .08em; }
.choice .go.step { font: 700 15px/1 var(--mono); min-width: 1.8em; height: 1.8em; display: inline-grid; place-items: center; border: 1.5px solid currentColor; border-radius: 50%; }
.choice .go.next { font-size: 22px; font-weight: 400; color: var(--muted); }
.reader.continuous .feed-current { scroll-margin-top: 72px; min-height: calc(100dvh - 90px); } /* même court, le paragraphe peut remonter en haut */
/* L'encre qui apparaît : chaque morceau du nouveau paragraphe se dévoile de gauche à droite, flou puis net, l'un après
   l'autre. En pause pendant un moment plein écran (trophée, plateau : html.lh-stage), joué ensuite. */
@media (prefers-reduced-motion: no-preference) {
  .feed-current.ink > .sec-num, .feed-current.ink > .prose > *, .feed-current.ink > .illus, .feed-current.ink > .msgs, .feed-current.ink > .choices {
    --ink-d: 0s; animation: ink-in 1.15s var(--ink-d) cubic-bezier(.25, .6, .25, 1) backwards; }
  .feed-current.ink > .illus { --ink-d: .1s; }
  .feed-current.ink > .prose > :nth-child(1) { --ink-d: .18s; } .feed-current.ink > .prose > :nth-child(2) { --ink-d: .32s; }
  .feed-current.ink > .prose > :nth-child(3) { --ink-d: .46s; } .feed-current.ink > .prose > :nth-child(4) { --ink-d: .6s; }
  .feed-current.ink > .prose > :nth-child(5) { --ink-d: .72s; } .feed-current.ink > .prose > :nth-child(n+6) { --ink-d: .84s; }
  .feed-current.ink > .msgs { --ink-d: .5s; } .feed-current.ink > .choices { --ink-d: .7s; }
  html.lh-stage .feed-current.ink > *, html.lh-stage .feed-current.ink > .prose > * { animation-play-state: paused; }
  /* Le masque (dégradé qui glisse de gauche à droite) n'existe que pendant l'animation : rien n'est rogné ensuite. */
  @keyframes ink-in {
    0% { opacity: 0; filter: blur(5px); color: var(--accent);
      -webkit-mask-image: linear-gradient(100deg, #000 0 38%, transparent 62%); mask-image: linear-gradient(100deg, #000 0 38%, transparent 62%);
      -webkit-mask-size: 270% 100%; mask-size: 270% 100%; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat; -webkit-mask-position: 100% 0; mask-position: 100% 0; }
    55% { opacity: 1; filter: blur(1px); }
    99% { filter: blur(0);
      -webkit-mask-image: linear-gradient(100deg, #000 0 38%, transparent 62%); mask-image: linear-gradient(100deg, #000 0 38%, transparent 62%);
      -webkit-mask-size: 270% 100%; mask-size: 270% 100%; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat; -webkit-mask-position: 0 0; mask-position: 0 0; }
  }
}
.feed { display: grid; gap: 0; }
.feed-past { padding-bottom: 18px; margin-bottom: 22px; border-bottom: 1px solid var(--line); color: color-mix(in srgb, var(--ink) 82%, var(--paper)); }
.feed-past .illus { max-width: 70%; margin-inline: auto; }
.feed-choice { margin: 12px 0 0; display: flex; gap: 8px; align-items: baseline; font-family: var(--sans); font-weight: 700; font-size: 15px; color: var(--ink);
  padding: 6px 10px; border-left: 3px solid var(--accent); background: var(--paper); border-radius: 0 6px 6px 0; }
.feed-more { text-align: center; margin: 0 0 18px; }
.feed-current::before { content: ''; }

/* ---------- icônes des livres (Glyph) : émoji, SVG dans la couleur du texte, ou pictogramme PNG ---------- */
.glyph.mask, .glyph.pic { display: inline-block; width: 1em; height: 1em; vertical-align: -0.14em; }
.glyph.mask { background: currentColor; -webkit-mask-size: contain; mask-size: contain; -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  -webkit-mask-position: center; mask-position: center; }
.glyph.pic { object-fit: contain; }

/* ---------- saisie rapide : un groupe à la fois (onglets), et le mode saisie ---------- */
.focus-bar { display: flex; justify-content: center; margin: -6px 0 14px; }
.focus-toggle { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--ink); font: 600 14px/1.3 var(--sans); cursor: pointer; }
.focus-toggle .ico { width: 16px; height: 16px; }
.focus-toggle .focus-state { font-weight: 400; color: var(--muted); }
.focus-toggle.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.focus-toggle.on .focus-state { color: inherit; opacity: .85; }
.choices.capture { display: grid; gap: 10px; max-width: none; }
.capture-tabs { position: sticky; top: calc(env(safe-area-inset-top, 0px) + var(--topbar-h, 61px)); z-index: 6; display: grid;
  grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; padding: 6px 0; background: var(--surface); }
.capture-tab { min-height: 48px; padding: 6px 10px; border-radius: 12px; border: 2px solid var(--line); background: var(--paper); color: var(--ink);
  font: 700 17px/1.2 var(--sans); cursor: pointer; }
.capture-tab[aria-selected="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.capture-tab:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.capture-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); gap: 8px; touch-action: pan-y; }
.capture-grid .choice { min-height: 56px; padding: 10px 12px; font-size: 16px; line-height: 1.25; }
.choices.capture .choice-group.free { display: grid; gap: 6px; }
.choices.capture.focus .capture-grid .choice { min-height: 64px; font-size: 17px; }
.capture-grid .choice .go.stay { display: none; } /* toutes les observations restent sur place : la marque n'apprend rien ici */
@media (max-width: 900px) { .play { padding-bottom: 84px; } } /* les boutons Sac et Feuille ne cachent pas le dernier choix */
html.lh-focus .feed-current.ink > *, html.lh-focus .feed-current.ink > .prose > * { animation: none; }
/* Mode saisie : en-tête et minuteur compacts, messages courts au-dessus des boutons (tout tient sur un téléphone). */
.reader.focus .sec-num.stepped { grid-auto-flow: column; justify-content: center; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.reader.focus .sec-step { font-size: 24px; }
.reader.focus .sec-step .of { font-size: 14px; }
.reader.focus .sec-gauge { display: none; }
.reader.focus .focus-bar { margin: 0 0 8px; }
.reader.focus .timer-block { margin: 4px 0; }
.reader.focus .timer-ring { width: 36px; height: 36px; }
.reader.focus .timer-ring b { width: 28px; height: 28px; font-size: 14px; }
.reader.focus .timer-go { padding: 4px 12px 4px 4px; font-size: 14px; }
.msgs.compact { margin: 0; gap: 4px; max-width: none; }
.msgs.compact .msg { padding: 4px 8px; font-size: 13px; font-weight: 500; }
.msgs.compact .msg:not(.alert) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.msgs.compact .msg:not(.alert) svg { display: none; }
.msgs.compact .msg.alert { font-size: 14px; }

/* ---------- bibliothèque rangée par rayons (séries) ---------- */
.shelf-nav { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 18px; }
.shelf-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--ink); font: 600 14px/1.3 var(--sans); text-decoration: none; }
.shelf-chip:hover { border-color: var(--accent); }
.shelf-chip .mono { font-size: 12px; color: var(--muted); }
.shelf { margin: 8px 0 30px; scroll-margin-top: 80px; }
.shelf-head { display: flex; align-items: baseline; gap: 10px; border-bottom: 2px solid var(--ink); padding-bottom: 4px; margin-bottom: 8px; }
.shelf-head h2 { margin: 0; font-size: 24px; }
.shelf-note { margin: 0 0 12px; max-width: 75ch; }
/* Rayons de documents (scans PDF) : petites cartes au format livre, la couverture entière. */
.shelf.docs .cards { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.card.doc .cover { aspect-ratio: 2 / 3; }
.card.doc .cover img { width: 100%; height: 100%; object-fit: cover; }
.card.doc .body { padding: 8px 10px 4px; gap: 4px; }
.card.doc .body h2 { font-size: 15px !important; line-height: 1.25; }
.card.doc .body .badge { display: none; }
.card.doc .foot { padding: 4px 10px 10px; }

/* ---------- avatar ---------- */
.avatar { display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none; border-radius: 50%; border: 2px solid var(--line);
  background: var(--paper); font-size: 26px; line-height: 1; cursor: pointer; padding: 0; color: var(--muted); }
.avatar:hover { border-color: var(--accent); }
.avatar.on { border: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--paper)); }
.avatar.empty { border-style: dashed; font: 700 20px/1 var(--sans); }
.avatar.initials { --av: #2C6A55; background: var(--av); border-color: var(--av); color: #fff; font: 700 17px/1 var(--sans); letter-spacing: .02em; }
.avatar.initials.on { outline: 3px solid var(--ink); outline-offset: 2px; border-color: #fff; }
.avatar-pick { display: grid; gap: 10px; }
.avatar-group { display: grid; gap: 4px; }
.avatar-row { display: flex; flex-wrap: wrap; gap: 6px; }
.sheet h2 .avatar { align-self: center; }
.sheet h2 .hero-name { margin-right: auto; }
.sheet-tools { display: flex; align-items: center; gap: 6px; }
.sheet-icons { display: inline-flex; gap: 4px; margin-left: auto; }
.sheet-icons .btn { padding: 4px 8px; }

/* ---------- combat ---------- */
.fighters { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.fighter { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 6px; background: var(--paper); }
.fighter.target { border: 2px solid var(--ink); }
.fighter.down { opacity: .5; }
.fighter.down .fname::after { content: " — vaincu"; font-weight: 400; color: var(--muted); }
.fighter .fname { font-weight: 700; display: flex; gap: 6px; align-items: center; }
.fighter img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 6px; }
.bar { height: 10px; border-radius: 5px; background: var(--sunk); overflow: hidden; border: 1px solid var(--line); }
.bar > span { display: block; height: 100%; background: var(--ink); }
.bar.me > span { background: var(--accent); }
.statline { display: flex; justify-content: space-between; font-size: 14px; }
.round { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 6px; background: var(--paper); }
.round .vs { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 15px; }
.round .vs b { font-family: var(--mono); font-size: 18px; }
/* Un assaut : une ligne par combattant (dés + Habileté = total), la gagnante en couleur, puis le verdict. */
.assaut { display: grid; gap: 4px; }
.assaut-side { display: grid; grid-template-columns: minmax(4.5em, auto) auto 1fr auto; align-items: center; gap: 8px 10px;
  padding: 4px 10px; border-radius: 6px; border: 1px solid transparent; }
.assaut-side .who { font-weight: 600; }
.assaut-side .calc { color: var(--muted); font-size: 15px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; }
.assaut-side .calc .n { font-family: var(--mono); color: var(--ink); }
.assaut-side .calc small { font-size: 12px; }
.assaut-side .tot { font-family: var(--mono); font-size: 24px; min-width: 2ch; text-align: right; }
.assaut-side.win { border-color: var(--gain); background: color-mix(in srgb, var(--gain) 10%, transparent); }
.assaut-side.win .tot { color: var(--gain); }
.assaut-side.lose { opacity: .72; }
.assaut .verdict { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 4px 10px; font-weight: 600; }
.assaut .verdict .cmp { font-weight: 500; }
.assaut .verdict.gain { color: var(--gain); } .assaut .verdict.loss { color: var(--loss); }
@media (max-width: 480px) {
  .assaut-side { grid-template-columns: auto 1fr auto; }
  .assaut-side .who { grid-column: 1 / -1; }
}
.log { max-height: 180px; overflow-y: auto; font-size: 14px; color: var(--muted); display: grid; gap: 2px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); }

/* ---------- feuille d'aventure ---------- */
.sheet { position: sticky; top: 72px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: grid; gap: 14px; max-height: calc(100vh - 90px); overflow-y: auto; }
.sheet h2 { font-size: 20px; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 8px; }
.sheet h2 .badge { white-space: nowrap; }
.stats { display: grid; gap: 8px; }
.stat { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 4px 8px; }
.stat .label { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; color: var(--muted); }
.stat .val { font-family: var(--mono); font-weight: 700; font-size: 22px; }
.stat .val small { font-size: 14px; color: var(--muted); font-weight: 500; }
.stat .bar { grid-column: 1 / -1; }
.stat.flash .val { animation: flash .9s; }
@keyframes flash { 0% { transform: scale(1.35); } 100% { transform: none; } }
.inv { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.inv li { display: flex; justify-content: space-between; gap: 8px; align-items: center; font-size: 15px; }
.sheet-toggle { display: none; }
/* La feuille repliable (grand écran) : un bouton au-dessus d'elle, et la lecture en pleine largeur quand elle est repliée. */
.play { position: relative; }
.sheet-fold-toggle { position: absolute; top: 2px; right: 16px; z-index: 5; min-height: 26px; padding: 1px 9px; font-size: 13px; }
.play.sheet-folded { grid-template-columns: minmax(0, 1fr); }
.play.sheet-folded > .sheet { display: none; }
.play.sheet-folded .sheet-fold-toggle { position: fixed; top: calc(env(safe-area-inset-top, 0px) + var(--topbar-h, 61px) + 10px); right: max(12px, env(safe-area-inset-right, 0px)); box-shadow: 0 4px 14px rgb(0 0 0 / .12); }
/* Boutons flottants du jeu (téléphone) : le sac et la Feuille d'Aventure. */
.play-fab { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 25; display: flex; gap: 8px; }
.pill { font-family: var(--mono); font-weight: 700; border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; background: var(--paper); }

@media (max-width: 900px) {
  .sheet-fold-toggle { display: none; }
  .play.sheet-folded > .sheet { display: grid; }
  .play { grid-template-columns: 1fr; }
  .sheet { position: fixed; inset: auto 0 0 0; top: auto; max-height: 78vh; border-radius: 16px 16px 0 0; z-index: 30; transform: translateY(105%); transition: transform .25s; padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); box-shadow: 0 -8px 30px rgb(0 0 0 / .2); }
  .sheet.open { transform: none; }
  .sheet-toggle { display: inline-flex; }
  .reader { padding-inline: 16px; }
}

/* ---------- création du héros ---------- */
.creator { max-width: 760px; margin: 0 auto; padding: 24px 16px 64px; display: grid; gap: 20px; }
.classes { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.class-opt { text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 12px 14px; display: grid; gap: 4px; }
.class-opt[aria-pressed="true"] { border: 2px solid var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.class-opt[aria-pressed="true"] b::before { content: "✓ "; }
.rolls { display: grid; gap: 10px; }
.rollrow { display: grid; grid-template-columns: 140px 1fr auto; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.rollrow .formula { font-family: var(--mono); color: var(--muted); font-size: 14px; }

/* ---------- modales et notifications ---------- */
.overlay { position: fixed; inset: 0; background: rgb(0 0 0 / .45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; width: min(720px, 100%); max-height: 88vh; overflow: auto; padding: 18px; display: grid; gap: 14px; }
.modal.wide { width: min(1100px, 100%); }
.modal header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.toasts { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); z-index: 60; display: grid; gap: 6px; width: min(460px, calc(100% - 32px)); pointer-events: none; }
/* Messages d'état, jamais cliquables : sur téléphone, en haut de l'écran pour ne pas cacher « Feuille » ni les boutons du bas. */
@media (max-width: 900px) { .toasts { bottom: auto; top: calc(12px + env(safe-area-inset-top, 0px)); } }
.toast { background: var(--ink); color: var(--surface); border-radius: 8px; padding: 10px 14px; font-weight: 500; box-shadow: 0 6px 20px rgb(0 0 0 / .25); }
.lightbox img { max-height: 84vh; width: auto; margin: 0 auto; display: block; }

/* ---------- éditeur ---------- */
.editor { display: grid; grid-template-columns: 260px minmax(0, 1fr); height: calc(100vh - 61px); min-height: 0; }
.ed-side { border-right: 1px solid var(--line); background: var(--surface); display: grid; grid-template-rows: auto auto 1fr auto; min-height: 0; }
.ed-side .head { padding: 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.ed-list { overflow-y: auto; padding: 6px; display: grid; gap: 2px; align-content: start; }
.ed-item { display: grid; grid-template-columns: 44px 1fr auto; gap: 8px; align-items: center; text-align: left; border: 1px solid transparent; background: none; border-radius: 6px; padding: 6px 8px; font-size: 14px; }
.ed-item:hover { background: var(--sunk); }
.ed-item[aria-current="true"] { background: var(--paper); border-color: var(--ink); }
.ed-item .n { font-family: var(--mono); font-weight: 700; }
.ed-item .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.ed-item .k { display: flex; gap: 3px; }
.ed-main { display: grid; grid-template-rows: auto 1fr; min-height: 0; min-width: 0; }
.tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--line); background: var(--surface); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 12px 12px 10px; font-weight: 700; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.ed-pane { overflow-y: auto; padding: 20px; min-height: 0; }
.ed-form { max-width: 900px; display: grid; gap: 18px; }
.panel { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 14px; display: grid; gap: 12px; }
.panel > header { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.panel > header h3 { font-size: 17px; }
.rowline { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); align-items: end; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
.rowline .rm { justify-self: end; }
.subtle { font-size: 13px; color: var(--muted); }
.problems { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.problems li { display: grid; grid-template-columns: auto auto 1fr; gap: 10px; align-items: baseline; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.lvl { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--line); }
.lvl.error { border: 2px solid var(--loss); color: var(--loss); }
.lvl.error::before { content: "✗ "; }
.lvl.warning::before { content: "⚠ "; }
.lvl.info::before { content: "i "; }
.graph-wrap { position: relative; height: 100%; min-height: 420px; }
#graph { position: absolute; inset: 0; }
.graph-tools { position: absolute; top: 10px; left: 10px; right: 10px; z-index: 2; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; pointer-events: none; }
.graph-tools > * { pointer-events: auto; }
.graph-actions { position: absolute; right: 10px; bottom: 10px; z-index: 2; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 6px 12px; font-weight: 500; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.chk { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); font-weight: 500; cursor: pointer; user-select: none; font-size: 15px; }
.chk input { accent-color: var(--accent); margin: 0; }
.legend { position: absolute; left: 10px; bottom: 10px; max-width: calc(100% - 330px); z-index: 2; display: flex; gap: 12px; flex-wrap: wrap; padding: 6px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.legend svg { width: 16px; height: 16px; }
.img-slot { display: grid; grid-template-columns: 160px 1fr; gap: 12px; align-items: center; }
.img-slot .thumb { aspect-ratio: 4/3; border: 1px dashed var(--line); border-radius: 8px; display: grid; place-items: center; overflow: hidden; background: var(--sunk); color: var(--muted); font-size: 13px; }
.img-slot .thumb img { width: 100%; height: 100%; object-fit: cover; }
.saved { font-size: 13px; color: var(--muted); }

@media (max-width: 800px) {
  .editor { grid-template-columns: 1fr; height: auto; }
  .ed-side { max-height: 40vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .img-slot { grid-template-columns: 1fr; }
  .rollrow { grid-template-columns: 1fr auto; }
  .rollrow .formula { display: none; }
}

/* ---------- version imprimable ---------- */
.print-controls { display: grid; gap: 12px; }
.print-book { background: #fff; color: #111; max-width: 820px; margin: 0 auto 64px; padding: 32px clamp(16px, 5vw, 56px); border: 1px solid var(--line); font-family: var(--serif); font-size: 15px; line-height: 1.5; }
.print-root.A5 .print-book { max-width: 600px; font-size: 13.5px; }
.print-book h1, .print-book h2, .print-book h3 { font-family: var(--display); color: #111; }
.print-book h2 { font-size: 26px; margin: 0 0 12px; text-align: center; }
.print-book h3 { font-size: 17px; margin: 14px 0 6px; }
.print-book p, .print-book li { text-align: justify; hyphens: auto; -webkit-hyphens: auto; }
.pr-page { break-after: page; page-break-after: always; padding-bottom: 24px; }
.pr-cover { text-align: center; display: grid; gap: 14px; justify-items: center; align-content: center; min-height: 60vh; }
.pr-cover h1 { font-size: 40px; }
.pr-cover-img { width: 100%; }
.pr-cover-img img { width: 100%; max-height: 90mm; object-fit: contain; }
.pr-author { font-family: var(--display); font-size: 20px; margin: 0; }
.pr-desc { font-style: italic; max-width: 50ch; text-align: center !important; }
.pr-small { font-size: .82em; color: #444; }
.pr-sections { padding-top: 8px; }
.print-root.cols .pr-sections { column-count: 2; column-gap: 8mm; column-rule: 1px solid #ccc; }
.pr-start { text-align: center !important; font-style: italic; column-span: all; }
.pr-sec { break-inside: auto; margin: 0 0 14px; }
.pr-num { font-family: var(--mono) !important; font-size: 22px !important; text-align: center; margin: 10px 0 4px !important; break-after: avoid; }
.pr-num::before, .pr-num::after { content: "—"; margin: 0 8px; color: #999; font-weight: 400; }
.pr-img img { display: block; width: 100%; max-height: 70mm; object-fit: contain; margin: 4px 0; break-inside: avoid; }
.pr-text p { margin: 0 0 .6em; }
.pr-fx, .pr-block { border-left: 3px solid #111; padding-left: 8px; }
.pr-block { break-inside: avoid; margin: .6em 0; }
.pr-table { border-collapse: collapse; width: 100%; margin: 4px 0; font-size: .95em; }
.pr-table td { border: 1px solid #999; padding: 2px 6px; }
.pr-spells td { text-align: center; font-family: var(--mono); }
.pr-choices { padding-left: 1.1em; margin: .4em 0; }
.pr-choices li { margin: .2em 0; }
.pr-go { font-style: italic; }
.pr-end { text-align: center !important; font-family: var(--display); font-weight: 700; letter-spacing: .3em; margin: .6em 0; }
.pr-sheet .pr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.pr-box { border: 2px solid #111; border-radius: 6px; min-height: 18mm; padding: 6px 8px; display: flex; flex-direction: column; gap: 2px; font-family: var(--sans); }
.pr-wide { margin-bottom: 8px; }
.pr-tall { min-height: 45mm; }
.pr-boxes { display: inline-flex; gap: 4px; vertical-align: middle; }
.pr-boxes i { width: 12px; height: 12px; border: 1.5px solid #111; display: inline-block; }
.pr-foes-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 6px; }
.pr-foe { border: 1px solid #111; border-radius: 4px; min-height: 16mm; padding: 4px; font-size: 11px; line-height: 1.8; }
.pr-code { font-family: var(--mono); letter-spacing: .1em; margin-right: 6px; }
.pr-spellbook p { margin: 0 0 .7em; }
.print-root.A5 .pr-box { min-height: 12mm; }
.print-root.A5 .pr-tall { min-height: 26mm; }
.print-root.A5 .pr-foe { min-height: 12mm; }
.print-root.A5 .pr-sheet h2 { margin-bottom: 6px; }
/* Pagination : ni case coupée entre deux pages, ni intertitre seul en bas de page. */
.pr-box, .pr-foe, .eq-pr-slot { break-inside: avoid; page-break-inside: avoid; }
.print-book h2, .print-book h3, .pr-defi-title { break-after: avoid; page-break-after: avoid; }
/* En colonnes, un tableau ou un bloc ne doit jamais dépasser sa colonne (Chrome réduirait tout le livre). */
.pr-sections .pr-block { max-width: 100%; overflow-wrap: anywhere; }
.pr-sections .pr-table { table-layout: fixed; overflow-wrap: anywhere; }
@media print {
  body { background: #fff; }
  .no-print, .topbar, .toasts { display: none !important; }
  .print-book { border: 0; padding: 0; max-width: none; margin: 0; }
  .print-root.A5 .print-book { max-width: none; }
  a { color: inherit; }
}

/* Emoji de contenu (objets, or, repas) et règles spéciales de combat */
.emoji { font-size: 18px; line-height: 1; display: inline-block; min-width: 22px; text-align: center; }
.rule { margin: 0; padding: 8px 12px; border-left: 3px solid var(--accent); border-radius: 0 8px 8px 0; background: var(--paper); font-size: 15px; display: flex; gap: 8px; align-items: flex-start; }
.history { margin: 0; padding: 0 0 0 20px; font-size: 14px; color: var(--muted); display: grid; gap: 2px; }
