/* style.css — rendu minimaliste, extensible quand Lucie ajoutera les assets. */

@import url("https://fonts.googleapis.com/css2?family=EB+Garamond:ital,wght@0,400;0,500;0,600;1,400&family=Cinzel+Decorative:wght@700;900&family=IM+Fell+English+SC&display=swap");

:root {
  --bg: #10131a;
  --bg-panel: rgba(12, 14, 20, 0.88);
  --fg: #eceff4;
  --fg-dim: #9aa3b2;
  --accent: #f4b860;
  --accent-hover: #ffc87a;
  --border: rgba(244, 184, 96, 0.35);
  --danger: #ff6b6b;

  /* Polices thématiques. Fallback serif si réseau indisponible. */
  --font-body:    "EB Garamond", "Iowan Old Style", Georgia, serif;
  --font-title:   "Cinzel Decorative", Georgia, serif;
  --font-speaker: "IM Fell English SC", Georgia, serif;

  /* Couleur de glow du speaker actif, overridée par data-speaker. */
  --speaker-glow: rgba(244, 184, 96, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.55;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.scene {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 520px;
}

/* .backdrop = conteneur. Le fond PNG vit dans .backdrop__image (pour pouvoir
 * l'animer en parallaxe sans que l'overlay d'assombrissement ne bouge). Un
 * ::after applique un léger dégradé sombre sur tout le conteneur, garant de
 * la lisibilité du texte.
 */
.backdrop {
  position: absolute;
  inset: 0;
  background: #0a0d14;
  z-index: 0;
  overflow: hidden;
}

.backdrop__image {
  position: absolute;
  inset: -6%; /* déborde plus largement : la parallaxe + le blur ne doivent
               * jamais révéler de vide sur les bords. */
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transition: background-image 400ms ease;
  /* Bokeh VN : fond flouté en permanence pour mettre les personnages en avant. */
  filter: blur(5px) saturate(1.05);
  will-change: transform;
  animation: backdrop-drift 24s ease-in-out infinite alternate;
  animation-play-state: paused;
}

.backdrop::after {
  /* Overlay sombre uniforme pour la lisibilité, indépendant du scroll du fond. */
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to bottom, rgba(5, 8, 12, 0.15) 0%, rgba(5, 8, 12, 0.45) 60%, rgba(0, 0, 0, 0.85) 100%);
  pointer-events: none;
}

@keyframes backdrop-drift {
  from { transform: translate(-1.2%, -0.8%) scale(1.04); }
  to   { transform: translate( 1.2%,  0.8%) scale(1.08); }
}

/* Sylve d'Émeraude — prologue
 * Chaque scène choisit une illustration du pack "Root RPG". Les teintes sont
 * ensuite modulées par l'overlay dark de .backdrop::after. Le data-scene est
 * posé à la fois sur .backdrop (pour les règles d'ambiance plus bas) et sur
 * .backdrop__image (pour choisir le PNG et activer la parallaxe).
 */
.backdrop__image[data-scene] { animation-play-state: running; }

.backdrop__image[data-scene="clairiere"]   { background-image: url("../../assets/backgrounds/Clearing%201.png"); }
.backdrop__image[data-scene="sentier"]     { background-image: url("../../assets/backgrounds/Path%204.png"); }
.backdrop__image[data-scene="bureau"]      { background-image: url("../../assets/backgrounds/Cottage%20Library%201.png"); }
.backdrop__image[data-scene="cabane"]      { background-image: url("../../assets/backgrounds/Cottage%20Bedroom.png"); }
.backdrop__image[data-scene="cabane_nuit"] { background-image: url("../../assets/backgrounds/Dark%202.png"); }

/* Teinte colorée spécifique par scène, posée par .backdrop::after en pass. */
.backdrop[data-scene="clairiere"]::after {
  background:
    linear-gradient(to bottom, rgba(10, 27, 14, 0.12) 0%, rgba(10, 27, 14, 0.45) 75%, rgba(5, 10, 7, 0.85) 100%);
}
.backdrop[data-scene="sentier"]::after {
  background:
    linear-gradient(to bottom, rgba(10, 16, 10, 0.18) 0%, rgba(10, 16, 10, 0.50) 70%, rgba(2, 4, 3, 0.90) 100%);
}
.backdrop[data-scene="bureau"]::after {
  background:
    linear-gradient(to bottom, rgba(17, 12, 6, 0.22) 0%, rgba(17, 12, 6, 0.50) 70%, rgba(5, 4, 2, 0.90) 100%);
}
.backdrop[data-scene="cabane"]::after {
  background:
    linear-gradient(to bottom, rgba(5, 4, 10, 0.28) 0%, rgba(5, 4, 10, 0.55) 70%, rgba(2, 1, 5, 0.92) 100%);
}
.backdrop[data-scene="cabane_nuit"]::after {
  background:
    radial-gradient(ellipse at 70% 45%, rgba(244, 184, 96, 0.25) 0%, rgba(244, 184, 96, 0) 45%),
    linear-gradient(to bottom, rgba(2, 3, 10, 0.55) 0%, rgba(2, 3, 10, 0.78) 70%, rgba(0, 0, 0, 0.95) 100%);
}

/* ---------------------------------------------------------------------------
 * Stage — scène "visual novel" : portraits grands ancrés en bas, qui
 * débordent légèrement sur la boîte de dialogue pour donner de la présence.
 * --------------------------------------------------------------------------- */
.stage {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4; /* au-dessus du backdrop (0) + fx-overlay (3), sous dialogue (5) */
}

.stage__portrait {
  position: absolute;
  bottom: 0;
  max-width: none;
  max-height: 92%;
  width: auto;
  height: 92%;
  object-fit: contain;
  object-position: bottom;
  filter: drop-shadow(0 20px 30px rgba(0, 0, 0, 0.7));
  transition: opacity 320ms ease, filter 320ms ease, transform 320ms ease;
  pointer-events: none;
  will-change: transform, opacity, filter;
  /* Breathing idle : micro-mouvement pour que les persos ne soient pas figés.
   * Durées légèrement différentes entre NPC et player pour éviter le sync. */
  animation: breathe 4.2s ease-in-out infinite;
}

.stage__portrait--player {
  animation: breathe 3.7s ease-in-out infinite 0.6s;
}

@keyframes breathe {
  0%, 100% { transform: translateY(0) scaleY(1); }
  50%      { transform: translateY(-3px) scaleY(1.008); }
}

/* NPC : ancré bas-gauche, légèrement hors cadre pour l'effet "entre en scène". */
.stage__portrait--npc {
  left: -2%;
  transform-origin: bottom left;
}

/* Elio : ancré bas-droit. */
.stage__portrait--player {
  right: -3%;
  transform-origin: bottom right;
  /* Un peu plus petit que les NPC pour que l'image du dos n'écrase pas la scène. */
  height: 82%;
  max-height: 82%;
}

.stage__portrait[hidden] { display: none; }

/* États "speaking / idle" : le personnage qui parle est pleinement visible,
 * l'autre s'efface légèrement en arrière-plan.
 * Note : on utilise la propriété CSS `scale:` individuelle (niveau 4) pour
 * ne pas écraser le `transform` du keyframe `breathe`. */
.stage__portrait.is-idle {
  opacity: 0.45;
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.55)) grayscale(0.35) brightness(0.82);
  scale: 0.97;
}
.stage__portrait.is-speaking {
  opacity: 1;
  scale: 1;
  /* Halo coloré selon le speaker (variable posée par ui.js). */
  filter:
    drop-shadow(0 20px 30px rgba(0, 0, 0, 0.7))
    drop-shadow(0 0 24px var(--speaker-glow, rgba(244, 184, 96, 0.35)));
}

/* ---------------------------------------------------------------------------
 * Boîte de dialogue — ancrée en bas-droite, ne prend pas toute la largeur.
 * Cadre chaud, petit onglet pour le nom du speaker. Inspirée de l'exemple
 * "Lot" fourni par Johan.
 * --------------------------------------------------------------------------- */
.dialogue-box {
  position: absolute;
  right: 2%;
  bottom: 3%;
  left: auto;
  width: min(62%, 780px);
  z-index: 5;
  pointer-events: auto;
  /* on réserve un peu d'espace en haut pour l'onglet qui "sort" de la boîte. */
  padding-top: 20px;
}

.dialogue-box__tab {
  position: absolute;
  top: -6px;
  left: 32px;
  padding: 6px 28px 6px 16px;
  background: linear-gradient(180deg, #4a3520 0%, #3a2615 100%);
  border: 1px solid rgba(244, 184, 96, 0.55);
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  color: var(--speaker-color, #f5e6c6);
  font-family: var(--font-speaker);
  font-size: 1.25rem;
  letter-spacing: 0.08em;
  transform: translateY(-100%);
  box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  gap: 10px;
}
.dialogue-box__tab[hidden] { display: none; }

.dialogue-box__mini {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  object-position: top center; /* cadrer sur le visage */
  border: 1px solid rgba(244, 184, 96, 0.55);
  background: #1a130a;
  flex-shrink: 0;
}
.dialogue-box__mini[hidden] { display: none; }

.dialogue-box__inner {
  background:
    linear-gradient(180deg, rgba(28, 20, 12, 0.88) 0%, rgba(16, 12, 8, 0.92) 100%);
  border: 1px solid rgba(244, 184, 96, 0.55);
  border-radius: 8px;
  box-shadow:
    0 8px 28px rgba(0, 0, 0, 0.55),
    inset 0 0 0 2px rgba(244, 184, 96, 0.12),
    inset 0 0 40px rgba(244, 184, 96, 0.06);
  padding: 20px 28px 24px;
  backdrop-filter: blur(4px);
  position: relative; /* ancre les pseudo-éléments d'ornement */
}

/* ---------------------------------------------------------------------------
 * Ornements botaniques — coins haut-gauche et haut-droit de la boîte.
 *
 * Chaque ornement est un SVG inline (data-URL) : un crochet courbe qui suit
 * le border-radius, deux petites feuilles qui s'en échappent, et un point
 * central à la jonction. Couleurs accordées à la bordure ambrée existante.
 *
 * L'ornement droit est le miroir horizontal de l'ornement gauche via
 * `scaleX(-1)` — un seul SVG à maintenir.
 *
 * Animation : léger pulse d'opacité (4.5 s) décalé par rapport au breathing
 * des portraits pour ne pas créer de synchronisation perceptible.
 * --------------------------------------------------------------------------- */

@keyframes ornament-pulse {
  0%, 100% { opacity: 0.75; }
  50%      { opacity: 1; }
}

/* SVG partagé : coin haut-gauche. Dessine depuis (5,48) → (5,13) → courbe
 * → (13,5) → (48,5) en suivant le border-radius de la boîte, plus deux
 * petites feuilles et un point de jonction à l'intérieur du coin. */
.dialogue-box__inner::before,
.dialogue-box__inner::after {
  content: "";
  position: absolute;
  top:  -1px; /* légèrement hors bord pour chevaucher la bordure */
  width:  54px;
  height: 54px;
  pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='54' height='54' viewBox='0 0 54 54'><path d='M5,50 L5,14 Q5,5 14,5 L50,5' fill='none' stroke='rgba(244,184,96,0.6)' stroke-width='1.4' stroke-linecap='round'/><path d='M5,31 Q-1,25 2,18 Q9,22 5,31Z' fill='rgba(244,184,96,0.3)'/><path d='M31,5 Q25,-1 18,2 Q22,9 31,5Z' fill='rgba(244,184,96,0.3)'/><path d='M5,48 Q9,47 11,43' fill='none' stroke='rgba(244,184,96,0.35)' stroke-width='1' stroke-linecap='round'/><path d='M48,5 Q47,9 43,11' fill='none' stroke='rgba(244,184,96,0.35)' stroke-width='1' stroke-linecap='round'/><circle cx='8' cy='8' r='2.2' fill='rgba(244,184,96,0.5)'/></svg>");
  background-repeat: no-repeat;
  background-size: contain;
  animation: ornament-pulse 4.5s ease-in-out infinite;
  z-index: 1; /* au-dessus du fond, sous le texte */
}

.dialogue-box__inner::before {
  left: -1px;
}

.dialogue-box__inner::after {
  right: -1px;
  /* Miroir horizontal : le coin haut-gauche devient un coin haut-droit. */
  transform: scaleX(-1);
  animation-delay: 2.25s; /* décalage demi-période pour une respiration alternée */
}

.speaker {
  /* Le nom est désormais dans l'onglet, plus besoin de l'espacer dans la box. */
  display: inline;
}

.text {
  font-family: var(--font-body);
  font-size: 1.2rem;
  line-height: 1.55;
  margin: 0 0 18px;
  min-height: 2.8em;
  white-space: pre-wrap;
  color: #f4ecdb;
}

.choices {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.choices li.end {
  color: var(--fg-dim);
  font-style: italic;
  padding: 8px 2px;
}

.choice {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  /* padding-left augmenté pour réserver l'espace du préfixe même au repos. */
  padding: 10px 14px 10px 32px;
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
  position: relative; /* ancre le ::before */
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

/* Préfixe décoratif : un ✦ ambré qui glisse vers la droite au hover.
 * Au repos il est transparent et décalé à gauche ; le joueur le découvre
 * en survolant le choix. Le translateX du parent complète le mouvement. */
.choice::before {
  content: "✦";
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%) translateX(-4px);
  color: var(--accent);
  font-size: 0.7em;
  opacity: 0;
  transition: opacity 140ms ease, transform 140ms ease;
  pointer-events: none;
  line-height: 1;
}

.choice:hover {
  background: rgba(244, 184, 96, 0.08);
  border-color: var(--accent-hover);
  transform: translateX(2px);
}
.choice:hover::before {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

.choice:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
/* Le focus clavier révèle aussi le préfixe, pour la cohérence. */
.choice:focus-visible::before {
  opacity: 0.7;
  transform: translateY(-50%) translateX(0);
}

/* Bouton Suivant : narration linéaire, plus subtil et aligné à droite.
 * Pas de préfixe ✦ : il a sa propre identité visuelle (▸ dans le texte). */
.choice--advance {
  align-self: flex-end;
  width: auto;
  min-width: 140px;
  text-align: center;
  padding: 10px 20px; /* reset : le padding-left spécial ne s'applique pas */
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(244, 184, 96, 0.06);
  font-variant: small-caps;
  letter-spacing: 0.12em;
}
.choice--advance::before { display: none; } /* supprime le ✦ sur ce bouton */
.choice--advance:hover {
  background: rgba(244, 184, 96, 0.15);
  transform: translateX(0);
}

.wait-panel {
  text-align: center;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
}
.wait-panel.hidden { display: none; }

.wait-label {
  color: var(--fg-dim);
  font-variant: small-caps;
  letter-spacing: 0.1em;
  margin-bottom: 6px;
}

.wait-timer {
  font-size: 2rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.wait-skip {
  margin-top: 10px;
  background: transparent;
  color: var(--fg-dim);
  border: 1px dashed var(--border);
  padding: 4px 10px;
  font-size: 0.85rem;
  border-radius: 4px;
  cursor: pointer;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  background: #0a0c12;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 0.82rem;
  color: var(--fg-dim);
}

.toolbar button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 4px 10px;
  font: inherit;
  font-size: 0.82rem;
  border-radius: 4px;
  cursor: pointer;
}
.toolbar button:hover { border-color: var(--accent-hover); }

.toolbar .hint { margin-right: auto; }

.debug-flags {
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.75rem;
  color: var(--fg-dim);
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------------------------------------------------------------------
 * Notifications de Relation
 * --------------------------------------------------------------------------- */
.notifications {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.notification {
  background: rgba(28, 20, 12, 0.95);
  border: 1px solid var(--accent);
  border-left: 4px solid var(--accent);
  color: #f4ecdb;
  padding: 10px 20px;
  border-radius: 4px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.5);
  animation: notify-in 0.5s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards,
             notify-out 0.5s 3s ease forwards;
}

@keyframes notify-in {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes notify-out {
  to { transform: translateY(-20px); opacity: 0; }
}

/* ---------------------------------------------------------------------------
 * Menu des Options (Overlay)
 * --------------------------------------------------------------------------- */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.settings-panel {
  background: linear-gradient(180deg, #1c140c 0%, #100c08 100%);
  border: 1px solid var(--accent);
  padding: 40px;
  border-radius: 12px;
  width: min(90%, 500px);
}

.setting-group {
  margin-bottom: 25px;
}

.setting-group label {
  display: block;
  margin-bottom: 10px;
  color: var(--accent);
  font-variant: small-caps;
}

.setting-group input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.setting-group label span {
  color: #d7c79a;
  margin-left: 6px;
  font-variant: normal;
}

.settings-panel h2 {
  margin: 0 0 20px 0;
  color: var(--accent);
  font-variant: small-caps;
  letter-spacing: 0.08em;
  border-bottom: 1px solid rgba(196, 167, 104, 0.3);
  padding-bottom: 10px;
}

.setting-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.setting-actions button {
  background: var(--accent);
  color: #1a130a;
  border: none;
  padding: 8px 20px;
  border-radius: 4px;
  font-variant: small-caps;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: filter 0.2s;
}

.setting-actions button:hover {
  filter: brightness(1.15);
}

.settings-overlay.hidden {
  display: none;
}

.toolbar__icon {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  margin-left: 8px;
  transition: background 0.2s, color 0.2s;
}

.toolbar__icon:hover {
  background: var(--accent);
  color: #1a130a;
}

.error {
  color: var(--danger);
  padding: 24px;
  white-space: pre-wrap;
  font-family: Menlo, Consolas, monospace;
}

/* ---------------------------------------------------------------------------
 * FX — overlay décoratif + keyframes
 * ---------------------------------------------------------------------------
 * .fx-overlay est une couche plein écran au-dessus du décor mais sous le
 * dialogue. Ses enfants (branches, lianes, feuillage, pollen) sont des PNG
 * transparents. Par défaut ils sont invisibles (opacity:0) et ne sont révélés
 * que par l'une des classes .fx-<name>.is-active appliquées par fx.js.
 * --------------------------------------------------------------------------- */

.fx-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3; /* au-dessus du backdrop (0) et des personnages (1) */
  overflow: hidden;
}

/* Transition de scène : l'overlay monte temporairement au-dessus des portraits
 * (z-index 4) ET de la boîte de dialogue (z-index 5) pour masquer la scène
 * entière pendant le swap de fond et les animations de portrait.
 * La classe est posée/retirée dynamiquement par ui.js dans renderNode(). */
.fx-overlay--scene-active {
  z-index: 6;
}

.fx-overlay > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  will-change: opacity, transform, filter;
}

/* couches nommées — positionnement/scale de base */
.fx-overlay__branches { object-position: top center; transform: translateY(-4%) scale(1.02); }
.fx-overlay__vines    { object-position: center;     transform: scale(1.0); }
.fx-overlay__foliage  { object-position: center;     transform: scale(1.05); }
.fx-overlay__pollen   { object-position: center;     mix-blend-mode: screen; }

/* couche noire pour fx-fade-black : un simple div, pas de PNG externe */
.fx-overlay__dark {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  will-change: opacity;
}

/* ------------- fade dialogue (texte) -------------------------------------- */
.fx-fade-out.is-active {
  animation: fx-fade-out var(--fx-duration, 180ms) ease forwards;
}
.fx-fade-in.is-active {
  animation: fx-fade-in var(--fx-duration, 260ms) ease forwards;
}
@keyframes fx-fade-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(6px); }
}
@keyframes fx-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}


/* ------------- pollen-puff : pollen léger qui monte ----------------------- */
.fx-pollen-puff.is-active .fx-overlay__pollen {
  animation: fx-pollen-puff var(--fx-duration, 1200ms) ease-out forwards;
}
@keyframes fx-pollen-puff {
  0%   { opacity: 0; transform: translateY(20%) scale(1.0); }
  30%  { opacity: 0.8; }
  100% { opacity: 0; transform: translateY(-10%) scale(1.1); }
}

/* ------------- fade-black : fondu au noir cinématique --------------------- */
/* Remplace curtain-night et vine-reveal dont les PNG-cadres rendaient mal.
 * Utilise une couche div noire (.fx-overlay__dark) sans image externe.
 * Plateau central (35%→65%) = fenêtre pendant laquelle le fond est swappé. */
.fx-fade-black.is-active .fx-overlay__dark {
  animation: fx-fade-black var(--fx-duration, 800ms) ease forwards;
}
@keyframes fx-fade-black {
  0%   { opacity: 0; }
  35%  { opacity: 1; }
  65%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ------------- head-lift : Elio redresse la tête -------------------------- */
.fx-head-lift.is-active {
  animation: fx-head-lift var(--fx-duration, 600ms) cubic-bezier(0.3, 1.4, 0.5, 1) forwards;
  transform-origin: bottom center;
}
@keyframes fx-head-lift {
  0%   { transform: translateY(0)    rotate(0deg); }
  50%  { transform: translateY(-6px) rotate(-1deg); }
  100% { transform: translateY(0)    rotate(0deg); }
}

/* ------------- portrait-out / portrait-in : crossfade PNG personnage ------ */
.fx-portrait-out.is-active {
  animation: fx-portrait-out var(--fx-duration, 180ms) ease forwards;
}
.fx-portrait-in.is-active {
  animation: fx-portrait-in var(--fx-duration, 260ms) ease forwards;
}
@keyframes fx-portrait-out {
  from { opacity: 1; transform: translateY(0)   scale(1); }
  to   { opacity: 0; transform: translateY(4px) scale(0.98); }
}
@keyframes fx-portrait-in {
  from { opacity: 0; transform: translateY(4px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

/* ------------- slide lateral NPC : entrée/sortie horizontale -------------- */
.fx-slide-out-right.is-active {
  animation: fx-slide-out-right var(--fx-duration, 260ms) cubic-bezier(0.55, 0, 0.7, 0.2) forwards;
}
.fx-slide-in-left.is-active {
  animation: fx-slide-in-left var(--fx-duration, 340ms) cubic-bezier(0.18, 0.9, 0.3, 1) forwards;
}
@keyframes fx-slide-out-right {
  from { opacity: 1; transform: translateX(0)     scale(1); }
  to   { opacity: 0; transform: translateX(80px)  scale(0.96); }
}
@keyframes fx-slide-in-left {
  from { opacity: 0; transform: translateX(-80px) scale(0.96); }
  to   { opacity: 1; transform: translateX(0)     scale(1); }
}

/* ------------- shake : moments forts (surprise, colère, gravité) ---------- */
.fx-shake.is-active {
  animation: fx-shake var(--fx-duration, 420ms) cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
  transform-origin: center;
}
@keyframes fx-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX( 3px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX( 6px); }
  0%, 100% { transform: translateX(0); }
}

/* ------------- ambiances scéniques (permanent, décoratif) ----------------- */
/* Clairière : feuillage lumineux qui dérive tranquillement. */
.backdrop[data-scene="clairiere"] ~ .fx-overlay .fx-overlay__foliage {
  animation: ambient-leaves 22s ease-in-out infinite alternate;
  opacity: 0.28;
}
@keyframes ambient-leaves {
  from { transform: translate(-4%, -2%) scale(1.03); opacity: 0.22; }
  to   { transform: translate( 3%,  2%) scale(1.06); opacity: 0.35; }
}

/* Sentier : brume discrète, utilise les branches comme masque flou. */
.backdrop[data-scene="sentier"] ~ .fx-overlay .fx-overlay__branches {
  animation: ambient-mist 30s ease-in-out infinite alternate;
  opacity: 0.18;
  filter: blur(6px);
}
@keyframes ambient-mist {
  from { transform: translate(-2%,  1%) scale(1.02); opacity: 0.14; }
  to   { transform: translate( 2%, -1%) scale(1.05); opacity: 0.22; }
}

/* Bureau : poussière ambrée, pollen ralenti et plus chaud. */
.backdrop[data-scene="bureau"] ~ .fx-overlay .fx-overlay__pollen {
  animation: ambient-dust 14s ease-in-out infinite alternate;
  opacity: 0.20;
  filter: hue-rotate(-8deg) brightness(1.1);
}
@keyframes ambient-dust {
  from { transform: translateY( 3%) scale(1.00); opacity: 0.15; }
  to   { transform: translateY(-2%) scale(1.03); opacity: 0.26; }
}

/* ------------- ambiance : pollen flottant permanent dans cabane_nuit ------ */
.backdrop[data-scene="cabane_nuit"] ~ .fx-overlay .fx-overlay__pollen {
  animation: fx-pollen-drift 8s ease-in-out infinite alternate;
  opacity: 0.25;
}
@keyframes fx-pollen-drift {
  from { transform: translateY(2%)  scale(1.00); opacity: 0.20; }
  to   { transform: translateY(-2%) scale(1.03); opacity: 0.35; }
}

/* ---------------------------------------------------------------------------
 * Post-processing : vignetting + film grain.
 * Le grain est généré par un SVG feTurbulence (data-URL) — aucun PNG externe.
 * On le pose en dernier dans la scène pour qu'il recouvre tout sauf le dialogue.
 * --------------------------------------------------------------------------- */

.scene::before {
  /* Vignetting : assombrit les bords pour focaliser l'œil sur le centre.
   * z-index 4 → passe sous la dialogue-box (5) mais sur backdrop/fx (0-3). */
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  background: radial-gradient(
    ellipse at center,
    transparent 50%,
    rgba(0, 0, 0, 0.18) 80%,
    rgba(0, 0, 0, 0.55) 100%
  );
  mix-blend-mode: multiply;
}

.scene::after {
  /* Film grain animé. L'image SVG est une seule tile 200×200 ; on l'animation
   * en translation courte pour que le bruit "crépite" comme sur pellicule.
   * z-index élevé mais opacity très basse : le grain passe partout sans
   * abîmer la lisibilité. */
  content: "";
  position: absolute;
  inset: -10%;
  pointer-events: none;
  z-index: 10;
  opacity: 0.06;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.9  0 0 0 0 0.85  0 0 0 0 0.8  0 0 0 0.8 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-size: 200px 200px;
  animation: grain-jitter 0.7s steps(6) infinite;
}

@keyframes grain-jitter {
  0%   { transform: translate(0,0); }
  10%  { transform: translate(-2%, -1%); }
  20%  { transform: translate( 1%, -2%); }
  30%  { transform: translate( 2%,  1%); }
  40%  { transform: translate(-1%,  2%); }
  50%  { transform: translate(-3%,  0); }
  60%  { transform: translate( 2%,  2%); }
  70%  { transform: translate(-1%, -3%); }
  80%  { transform: translate( 1%,  1%); }
  90%  { transform: translate( 0,  -1%); }
  100% { transform: translate(0,0); }
}

/* ---------------------------------------------------------------------------
 * Mini-jeux interactifs — .mg
 *
 * Superposition plein-écran par-dessus la scène. Le panneau est centré et
 * dimensionné pour être lisible aussi bien sur mobile (380 px) que desktop.
 * Chaque mini-jeu partage ce conteneur ; des classes modificatrices (ex.
 * .mg--labeur) permettent de personnaliser l'apparence par jeu.
 * --------------------------------------------------------------------------- */

/* ── Conteneur principal ──────────────────────────────────────────────────── */
.mg-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 8, 12, 0.82);
  backdrop-filter: blur(4px);
  padding: 16px;
}

.mg-overlay.hidden { display: none; }

/* ── Panneau centré ──────────────────────────────────────────────────────── */
.mg {
  position: relative;
  width: min(480px, 100%);
  background: rgba(14, 18, 26, 0.97);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 0 40px rgba(0,0,0,0.7), 0 0 0 1px rgba(244,184,96,0.08);
  overflow: hidden; /* pour les particules */
  user-select: none;
  -webkit-user-select: none;
}

/* ── En-tête ─────────────────────────────────────────────────────────────── */
.mg__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.mg__title {
  font-family: var(--font-speaker);
  font-size: 1.1rem;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.mg__timer {
  font-family: var(--font-speaker);
  font-size: 1.4rem;
  color: var(--fg);
  min-width: 2.8ch;
  text-align: right;
  transition: color 0.3s;
}

/* Dernières secondes : timer rouge */
.mg__timer--urgent { color: #ff6b6b; }

/* ── Description ─────────────────────────────────────────────────────────── */
.mg__desc {
  margin: 0;
  font-size: 0.92rem;
  color: var(--fg-dim);
  text-align: center;
  line-height: 1.4;
}

/* ── Barre de progression ─────────────────────────────────────────────────── */
.mg__bar-wrap {
  height: 12px;
  background: rgba(255,255,255,0.06);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.08);
}

.mg__bar {
  height: 100%;
  width: 0%;
  border-radius: 6px;
  background: linear-gradient(90deg, #5a9e6a, #a3d07a);
  transition: width 0.1s ease-out;
}

/* Couleur selon résultat */
.mg__bar[data-result="success"] { background: linear-gradient(90deg, #5a9e6a, #a3d07a); }
.mg__bar[data-result="partial"] { background: linear-gradient(90deg, #b8860b, var(--accent)); }
.mg__bar[data-result="fail"]    { background: linear-gradient(90deg, #8b2020, #c05050); }

/* ── Zone de tap ──────────────────────────────────────────────────────────── */
.mg__tap-zone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 140px;
  border: 2px dashed rgba(244,184,96,0.25);
  border-radius: 10px;
  background: rgba(244,184,96,0.04);
  cursor: pointer;
  font-family: var(--font-body);
  color: var(--fg-dim);
  transition: border-color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  outline: none;
}

.mg__tap-zone--active {
  border-color: rgba(244,184,96,0.55);
  background: rgba(244,184,96,0.07);
}

.mg__tap-zone--active:hover,
.mg__tap-zone--active:focus-visible {
  border-color: var(--accent);
  background: rgba(244,184,96,0.12);
}

.mg__tap-zone:disabled {
  cursor: default;
  opacity: 0.6;
}

/* ── Icône pioche ─────────────────────────────────────────────────────────── */
.mg__tap-icon {
  font-size: 3rem;
  display: block;
  transition: transform 0.05s;
}

.mg__tap-icon--hit {
  animation: mg-hit 0.12s ease-out;
}

@keyframes mg-hit {
  0%   { transform: rotate(-20deg) scale(1.3); }
  60%  { transform: rotate(5deg)   scale(0.95); }
  100% { transform: rotate(0deg)   scale(1); }
}

.mg__tap-label {
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  pointer-events: none;
}

/* ── Compteur ─────────────────────────────────────────────────────────────── */
.mg__count {
  text-align: center;
  font-size: 0.9rem;
  color: var(--fg-dim);
  min-height: 1.3em;
}

/* ── Particules ───────────────────────────────────────────────────────────── */
.mg__particle {
  position: absolute;
  pointer-events: none;
  font-size: 0.9rem;
  color: var(--accent);
  animation: mg-particle 0.55s ease-out forwards;
  z-index: 10;
}

@keyframes mg-particle {
  0%   { opacity: 1; transform: translateY(0)    scale(1); }
  100% { opacity: 0; transform: translateY(-40px) scale(0.5); }
}

/* ── Résultat (affiché après fin du timer) ────────────────────────────────── */
.mg__result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding-top: 4px;
}

.mg__result.hidden { display: none; }

.mg__result-text {
  margin: 0;
  text-align: center;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--fg);
}

.mg__continue {
  background: var(--accent);
  color: #1a130a;
  border: none;
  padding: 10px 28px;
  border-radius: 6px;
  font-family: var(--font-speaker);
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: filter 0.2s;
}

.mg__continue:hover { filter: brightness(1.15); }

/* ── Responsive mobile (tap game) ────────────────────────────────────────── */
@media (max-width: 600px) {
  .mg {
    padding: 20px 16px 20px;
    gap: 12px;
  }
  .mg__tap-zone { min-height: 120px; }
  .mg__tap-icon { font-size: 2.4rem; }
}

/* ---------------------------------------------------------------------------
 * Jeu de rythme — .rg-*
 *
 * Un cercle-cible fixe (.rg-target) au centre d'une zone cliquable (.rg-stage).
 * À chaque beat, un anneau (.rg-ring) apparaît large et se réduit vers la
 * cible. Le joueur doit taper au moment où l'anneau coïncide avec la cible.
 * --------------------------------------------------------------------------- */

/* ── Beat count dans le header ───────────────────────────────────────────── */
.mg__beat-count {
  font-family: var(--font-speaker);
  font-size: 1rem;
  color: var(--fg-dim);
  min-width: 4ch;
  text-align: right;
}

/* ── Indicateurs de progression (petits points) ──────────────────────────── */
.rg-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}

.rg-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  transition: background 0.2s, border-color 0.2s;
}

.rg-dot[data-judgment="perfect"] {
  background: #a3d07a;
  border-color: #a3d07a;
  box-shadow: 0 0 6px rgba(163,208,122,0.6);
}
.rg-dot[data-judgment="good"] {
  background: var(--accent);
  border-color: var(--accent);
}
.rg-dot[data-judgment="miss"] {
  background: #c05050;
  border-color: #c05050;
}

/* ── Zone de jeu principale ──────────────────────────────────────────────── */
.rg-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  min-height: 180px;
  border: 2px solid rgba(244,184,96,0.18);
  border-radius: 10px;
  background: rgba(255,255,255,0.025);
  cursor: pointer;
  font-family: var(--font-body);
  color: var(--fg-dim);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  outline: none;
  transition: border-color 0.2s;
}

.rg-stage:hover,
.rg-stage:focus-visible { border-color: rgba(244,184,96,0.4); }
.rg-stage:disabled { cursor: default; opacity: 0.7; }

/* ── Cercle-cible ────────────────────────────────────────────────────────── */
.rg-target {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  background: rgba(244,184,96,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 0 16px rgba(244,184,96,0.2);
}

/* Conteneur de l'anneau centré sur la cible */
.rg-ring-wrap {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* ── Anneau animé ────────────────────────────────────────────────────────── */
.rg-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid rgba(163, 208, 122, 0.85);
  /* Commence grand (scale 3.5) et se réduit à 1 (la taille de la cible) */
  animation: rg-close linear forwards;
  /* animation-duration défini inline via JS */
}

@keyframes rg-close {
  from { transform: scale(3.5); opacity: 0.9; }
  to   { transform: scale(1);   opacity: 1;   }
}

/* ── Icône dans la cible ─────────────────────────────────────────────────── */
.rg-icon {
  font-size: 1.6rem;
  pointer-events: none;
  user-select: none;
}

/* ── Texte d'indication ──────────────────────────────────────────────────── */
.rg-hint {
  font-size: 0.88rem;
  letter-spacing: 0.05em;
  color: var(--fg-dim);
  pointer-events: none;
}

/* ── Feedback par beat ───────────────────────────────────────────────────── */
.rg-feedback {
  text-align: center;
  font-family: var(--font-speaker);
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  min-height: 1.6em;
  opacity: 0;
}

.rg-feedback--show {
  animation: rg-feedback-pop 0.6s ease-out forwards;
}

.rg-feedback[data-type="perfect"] { color: #a3d07a; }
.rg-feedback[data-type="good"]    { color: var(--accent); }
.rg-feedback[data-type="miss"]    { color: #c05050; }
.rg-feedback[data-type="early"]   { color: var(--fg-dim); font-size: 0.85rem; }

@keyframes rg-feedback-pop {
  0%   { opacity: 1; transform: translateY(0)    scale(1.15); }
  60%  { opacity: 1; transform: translateY(-6px) scale(1); }
  100% { opacity: 0; transform: translateY(-12px) scale(0.9); }
}

/* ── Responsive mobile ───────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .rg-stage   { min-height: 150px; }
  .rg-target  { width: 60px; height: 60px; }
  .rg-icon    { font-size: 1.3rem; }
  .rg-dot     { width: 8px; height: 8px; }
}

/* --------------------------------------------------------------------------- */

/* ---------------------------------------------------------------------------
 * Responsive — mobile (≤ 600 px) et tablette étroite (≤ 900 px)
 *
 * Stratégie :
 *  - Boîte de dialogue : plein-largeur, collée en bas comme un "drawer".
 *  - Portraits : réduits pour laisser voir le décor au-dessus de la boîte.
 *  - Toolbar : compacte, texte superflu masqué.
 *  - Notifications toast : replacées en bas à gauche pour ne pas couvrir les
 *    portraits et rester lisibles.
 * --------------------------------------------------------------------------- */

@media (max-width: 900px) {
  /* Légère réduction de la boîte sur tablette — elle reste ancrée à droite. */
  .dialogue-box { width: min(76%, 780px); }
}

@media (max-width: 600px) {
  /* ── Base ─────────────────────────────────────────────────────────────── */
  html, body { font-size: 16px; }

  .scene { min-height: 0; } /* laisse le viewport décider de la hauteur */

  /* ── Boîte de dialogue : drawer plein-largeur ancré en bas ────────────── */
  .dialogue-box {
    right:  0;
    left:   0;
    bottom: 0;
    width:  100%;
    /* On augmente le padding-top pour l'onglet speaker qui dépasse. */
    padding-top: 26px;
  }

  .dialogue-box__inner {
    /* Angles hauts arrondis, bas droits : effet "tiroir" qui sort du bord. */
    border-radius: 14px 14px 0 0;
    border-bottom: none;
    border-left:   none;
    border-right:  none;
    padding: 14px 16px 18px;
  }

  /* L'onglet reste ancré à gauche dans la boîte désormais pleine largeur. */
  .dialogue-box__tab { left: 16px; }

  .text { font-size: 1.05rem; }

  /* Choix : plus denses sur petit écran. */
  .choice { padding: 9px 14px 9px 30px; }

  /* ── Portraits : réduits pour laisser respirer le décor ──────────────── */
  .stage__portrait {
    height:     62%;
    max-height: 62%;
  }
  .stage__portrait--npc {
    /* Légèrement plus hors cadre pour compenser la boîte plein-largeur. */
    left: -6%;
  }
  .stage__portrait--player {
    right:      -6%;
    height:     52%;
    max-height: 52%;
  }

  /* ── Toolbar : compacte ────────────────────────────────────────────────── */
  .toolbar {
    gap: 10px;
    padding: 5px 12px;
    flex-wrap: wrap;
  }
  /* "Sauvegarde locale automatique" est peu utile à lire en permanence. */
  .toolbar .hint  { display: none; }
  /* Les flags de debug ne servent pas sur mobile. */
  .debug-flags    { display: none; }

  /* ── Notifications toast : en bas à gauche ─────────────────────────────
   * On les sort du coin haut-droit pour qu'elles ne couvrent pas le portrait
   * NPC et qu'elles restent lisibles au-dessus de la boîte de dialogue.      */
  .notifications {
    top:    auto;
    bottom: 48px; /* au-dessus de la toolbar (~40px) + marge */
    right:  auto;
    left:   12px;
    align-items: flex-start;
    max-width: calc(100vw - 24px);
  }
  .notification {
    font-size: 0.82rem;
    padding:   8px 14px;
  }

  /* ── Menu Options : déjà responsive (width: min(90%, 500px)) ─────────── */
  .settings-panel { padding: 28px 22px; }

  /* ── Ornements : masqués sur mobile (drawer style ≠ cadre flottant) ──── */
  .dialogue-box__inner::before,
  .dialogue-box__inner::after { display: none; }
}

/* ------------- accessibilité : respecte prefers-reduced-motion ------------ */
@media (prefers-reduced-motion: reduce) {
  .fx-fade-out.is-active,
  .fx-fade-in.is-active,
  .fx-pollen-puff.is-active  .fx-overlay__pollen,
  .fx-fade-black.is-active   .fx-overlay__dark,
  .fx-head-lift.is-active,
  .fx-portrait-out.is-active,
  .fx-portrait-in.is-active,
  .fx-slide-out-right.is-active,
  .fx-slide-in-left.is-active,
  .fx-shake.is-active,
  .backdrop__image,
  .stage__portrait,
  .stage__portrait--player,
  .scene::after,
  .backdrop[data-scene="cabane_nuit"] ~ .fx-overlay .fx-overlay__pollen,
  .backdrop[data-scene="clairiere"]   ~ .fx-overlay .fx-overlay__foliage,
  .backdrop[data-scene="sentier"]     ~ .fx-overlay .fx-overlay__branches,
  .backdrop[data-scene="bureau"]      ~ .fx-overlay .fx-overlay__pollen {
    animation: none !important;
    opacity: 1;
    transform: none;
  }
}
