/* Color Puzzle mock — fond PNG + atlas blocs PNG */

:root {
  --cell: 36px;
  /* Doit tenir la pièce la plus longue (i4h/i4v, 4 cellules) sans dépasser
     la hauteur fixe du slot — voir .staging .slot dans game.css. */
  --staging-cell: calc(var(--cell) * 0.62);
  --gap: 3px;
  --cols: 8;
  --rows: 8;
  --ink: #4a3728;
  --wood: #a67c52;
  --wood-dark: #6b4a2e;
  --font: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  /* Typo mobile — échelle Comfy Big (min lisible : 14px) */
  --text-caption: 14px;
  --text-meta: 16px;
  --text-body: 18px;
  --text-body-lg: 20px;
  --text-title: 30px;
  --text-display: 36px;
  --text-btn: 19px;
  --text-label: 16px;
  --text-hud-value: 19px;
  --line-body: 1.45;
  --modal-max-width: 392px;
  --modal-shop-width: min(96vw, 420px);
  --modal-frame-y: 36px;
  --modal-frame-x: 18px;
  --btn-height: 56px;
  --btn-height-compact: 42px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: #87b8e8;
  overflow: hidden;
}

.app {
  position: relative;
  /* 420px laissait un filet de fond bleu visible sur les Pro Max (viewport
     CSS ~430-440pt, ex. iPhone Pro Max), au-dessus du plafond. 480px couvre
     confortablement tous les téléphones actuels tout en restant "mobile"
     sur desktop/tablette. */
  width: min(100vw, 480px);
  height: 100dvh;
  max-height: 900px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto auto auto;
  gap: 8px;
  padding: 10px 12px 14px;
  overflow: hidden;
}

/* —— Scene (PNG + tint) —— */
.scene {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.scene-bg-wrap {
  position: absolute;
  inset: 0;
}

.scene-bg,
.home-bg img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 22%;
  filter: saturate(1.08) brightness(1.03);
  transition: filter 0.6s ease;
}

.scene-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.05) 0%,
    transparent 38%,
    rgba(0, 0, 0, 0.12) 100%
  );
}

.scene-tint {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: background 0.6s ease;
}

/* —— Scenery (stub — assets reportés) —— */
.scenery-layer {
  display: none;
}


/* —— Header : 1 rangée —— */
.hud {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-around;
  width: 100%;
  gap: 6px;
  padding: 4px 10px;
  box-sizing: border-box;
}

.hud-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.hud-level {
  flex-shrink: 0;
  font-size: var(--text-label);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  background: rgba(0, 0, 0, 0.28);
  padding: 8px 24px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  white-space: nowrap;
}

.hud-score {
  display: none;
  font-size: 22px;
  font-weight: 900;
  color: #fff;
  text-shadow:
    0 2px 0 rgba(60, 40, 120, 0.5),
    0 0 14px rgba(255, 255, 255, 0.35);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: transform 180ms ease-out;
}

.hud-score.pop {
  transform: scale(1.25);
}

.pause-btn,
.restart-btn,
.settings-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  background-color: rgba(90, 70, 50, 0.55);
  background-size: 400% 400%;
  background-repeat: no-repeat;
  border-radius: 8px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}

.pause-btn { background-position: 0% 0%; }
.restart-btn { background-position: 33.333% 0%; }
.settings-btn { background-position: 66.667% 0%; }

.pause-btn:active,
.restart-btn:active,
.settings-btn:active {
  transform: scale(0.92);
}

.stat-pill {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px 5px 36px;
  min-height: 38px;
  background: linear-gradient(180deg, #fff9ee 0%, #f5e8c8 100%);
  border: 3px solid var(--wood);
  border-radius: 999px;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.95),
    0 3px 0 var(--wood-dark),
    0 5px 10px rgba(0, 0, 0, 0.15);
}

.coins-pill {
  flex-shrink: 0;
}

.pill-badge {
  position: absolute;
  left: -4px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 900;
  border: 3px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.25);
}

.coin-badge {
  background: url("assets/atlas/home/coin-gold.png") center / contain no-repeat;
  border: none;
  box-shadow: none;
}

.pill-value {
  font-size: var(--text-hud-value);
  font-weight: 900;
  color: var(--ink);
  flex: 1;
}


/* —— Tuiles atlas blocs (background-size/position via JS inline) —— */
.block-sprite {
  background-repeat: no-repeat;
  background-color: transparent;
  border: none;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
  border-radius: 8px;
}

/* —— Board —— */
.board-wrap {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Nine-slice — sprite 88x96, slice en unités source (R1), k = 1 sur les 4 côtés (R2).
   `fill` peint la tuile centrale plate : plus aucune fuite de fond dans les coins (R7).
   border-radius = rx extérieur (20) x k (R8). Voir docs/sprite-design.md. */
.board-frame {
  border-style: solid;
  border-width: 22px 22px 30px 22px;
  border-color: #6b4a2e;
  border-image-slice: var(--gp-frame-slice, 25% 25% 31.25% 25% fill);
  border-image-repeat: stretch;
  border-radius: 20px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.3);
  background: rgba(255, 249, 238, 0.92);
}

.grid,
.ghost-layer {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-template-rows: repeat(var(--rows), var(--cell));
  gap: var(--gap);
  background: linear-gradient(180deg, #3d6a9e 0%, #2a5080 100%);
  /* rayon aligné sur l'ouverture du puits du sprite (rx 4 x k 1) */
  border-radius: 4px;
  padding: 6px;
  /* bordure sombre : une bordure claire ici créait un filet blanc collé au bois */
  border: 2px solid rgba(0, 0, 0, 0.28);
  box-shadow: inset 0 3px 12px rgba(0, 0, 0, 0.25);
}

.ghost-layer {
  position: absolute;
  inset: 11px;
  pointer-events: none;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 6px;
}

.ghost-layer .ghost {
  position: absolute;
  box-sizing: border-box;
  border-radius: 8px;
  overflow: hidden;
  outline: none;
}

.ghost-layer .ghost.block-sprite {
  opacity: 0.42;
  border: 1.5px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.4), inset 0 0 8px rgba(0, 0, 0, 0.25);
}

.ghost-layer .ghost.invalid {
  opacity: 0.85;
  border: 2px solid #e74c3c;
  box-shadow: 0 0 10px rgba(231, 76, 60, 0.5);
}

.cell {
  width: var(--cell);
  height: var(--cell);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.15);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: box-shadow 0.12s ease, border-color 0.12s ease;
}

.cell.highlight-match {
  box-shadow: 0 0 12px var(--match-color, #f1c40f), inset 0 0 10px var(--match-color, #f1c40f) !important;
  border: 2px solid var(--match-color, #ffeaa7) !important;
  animation: lineMatchPulse 0.5s ease-in-out infinite alternate;
  z-index: 2;
}

@keyframes lineMatchPulse {
  0% { filter: brightness(1.2); }
  100% { filter: brightness(1.7); }
}

.cell.clearing {
  animation: pop-clear var(--clear-pop-ms, 640ms) cubic-bezier(0.34, 1.45, 0.64, 1) both;
  z-index: 1;
}

@keyframes pop-clear {
  0% { transform: scale(1) rotate(0deg); opacity: 1; filter: brightness(1); }
  35% { transform: scale(1.28) rotate(-4deg); opacity: 1; filter: brightness(1.65); }
  70% { transform: scale(1.06) rotate(2deg); opacity: 0.95; filter: brightness(1.12); }
  100% { transform: scale(0) rotate(8deg); opacity: 0; filter: brightness(1); }
}

.feedback {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 90%;
  font-size: 28px;
  font-weight: 900;
  color: #fff;
  text-align: center;
  white-space: nowrap;
  line-height: 1.25;
  text-shadow: 0 2px 0 #2c1a6b, 0 6px 16px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  animation: float-up 700ms ease-out forwards;
  z-index: 5;
}

.feedback-nice {
  font-size: 32px;
  color: #fff9c4;
  text-shadow: 0 3px 0 #7d6608, 0 0 12px rgba(255, 241, 118, 0.6);
}

.feedback-combo {
  font-size: 42px;
  font-style: italic;
  font-weight: 900;
  color: #fffbdf;
  -webkit-text-fill-color: #fffbdf;
  background: none;
  text-shadow:
    0 3px 0 #8e3a00,
    0 0 14px #ffea00,
    0 0 28px #ff9900;
  animation: comboPop 900ms cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  letter-spacing: 0.04em;
}

@keyframes comboPop {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.5); }
  30% { opacity: 1; transform: translate(-50%, -50%) scale(1.25); }
  75% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(0.9); }
}

.feedback-excellent {
  font-size: 34px;
  color: #ff9ff3;
  text-shadow: 0 3px 0 #8e1874, 0 0 16px rgba(255, 159, 243, 0.7);
  animation: float-up 900ms ease-out forwards;
}

.feedback-amazing {
  font-size: 38px;
  color: #ffd6ff;
  text-shadow: 0 3px 0 #6c3483, 0 0 20px rgba(255, 180, 255, 0.6);
  animation: float-up-amazing 900ms ease-out forwards;
}

@keyframes float-up-amazing {
  from { opacity: 0; transform: translate(-50%, -40%) scale(0.7); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -90%) scale(1.05); }
}

@keyframes float-up {
  from { opacity: 0; transform: translate(-50%, -40%) scale(0.85); }
  30% { opacity: 1; }
  to { opacity: 0; transform: translate(-50%, -85%) scale(1.05); }
}

/* —— Particules de clear vers le header —— */
.particle-layer {
  position: fixed;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

.clear-particle {
  position: fixed;
  z-index: 6;
  width: 16px;
  height: 16px;
  background: var(--gp-coin) center / contain no-repeat;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.45));
  pointer-events: none;
  transition:
    transform var(--clear-flight-ms, 920ms) var(--clear-flight-ease, cubic-bezier(0.12, 0.78, 0.18, 1)),
    opacity var(--clear-flight-ms, 920ms) ease-in;
  will-change: transform, opacity;
}

.clear-chip {
  position: fixed;
  z-index: 6;
  border-radius: 4px;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  transition:
    transform var(--clear-flight-ms, 920ms) var(--clear-flight-ease, cubic-bezier(0.12, 0.78, 0.18, 1)),
    opacity var(--clear-flight-ms, 920ms) ease-in;
  will-change: transform, opacity;
}

/* —— Staging —— */
.staging-wrap {
  position: relative;
  margin-top: 0;
}

.wave-tag {
  position: absolute;
  top: -11px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  font-size: var(--text-label);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  background: rgba(0, 0, 0, 0.3);
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  white-space: nowrap;
}

.staging {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  /* gap: 10px; */
  min-height: 100px;
  padding: 11px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(235, 248, 235, 0.95));
  border: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: 16px;
  box-shadow:
    inset 0 2px 0 #fff,
    0 5px 0 rgba(70, 110, 70, 0.35),
    0 8px 18px rgba(0, 0, 0, 0.18);
}

.slot {
  display: grid;
  place-items: center;
  min-height: 86px;
  border-radius: 12px;
  border: 2px solid rgba(120, 160, 120, 0.3);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.85), rgba(230, 240, 230, 0.6));
  box-shadow: inset 0 2px 5px rgba(255, 255, 255, 0.9);
  touch-action: none;
}

.slot.empty { opacity: 0.45; }

.slot:not(.empty) {
  cursor: grab;
}

.slot:not(.empty):active,
.slot.dragging {
  cursor: grabbing;
}

.piece {
  display: grid;
  gap: 3px;
  cursor: grab;
  touch-action: none;
  margin: auto;
}

.piece:active,
.piece.dragging {
  cursor: grabbing;
}

.piece-cell {
  border-radius: 8px;
  overflow: hidden;
}

.staging .piece-cell {
  width: var(--staging-cell);
  height: var(--staging-cell);
  border-radius: 6px;
}

.drag-ghost {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  opacity: 0.95;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.35));
}

.drag-ghost .piece-cell {
  width: var(--cell);
  height: var(--cell);
  border-radius: 8px;
  overflow: hidden;
}

/* —— Level rail —— */
.level-rail {
  position: relative;
  z-index: 3;
  display: flex;
  justify-content: center;
}

.level-rail-inner {
  display: flex;
  align-items: center;
  padding: 4px 14px;
  border-radius: 999px;
  background: linear-gradient(180deg, #b88850, #7a5228);
  border: 3px solid #f0d4a8;
  box-shadow: 0 5px 0 #3d2410, 0 8px 16px rgba(0, 0, 0, 0.25);
}

.level-connector {
  width: 18px;
  height: 4px;
  background: #e8c49a;
  border-radius: 2px;
}

.level-medal {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  background: radial-gradient(circle at 35% 30%, #f5e8c8 0%, #d4a574 72%, #8b6914 100%);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  cursor: pointer;
  color: #2d3436;
  padding: 0;
  vertical-align: middle;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
}

.level-medal:disabled { cursor: default; }

/* Chiffre centré sur le disque crème du sprite brand */
.level-medal .medal-num {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: block;
  line-height: 1;
  font-size: var(--text-label);
  font-weight: 900;
  font-variant-numeric: lining-nums tabular-nums;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
  padding: 0;
  margin: 0;
}

.level-medal .medal-lock {
  position: absolute;
  top: -1px;
  right: -1px;
  width: 15px;
  height: 15px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #636e72;
  color: #fff;
  font-size: 10px;
}

.level-medal.current {
  background: radial-gradient(circle at 35% 30%, #fff4c8 0%, #ffd56a 55%, #c9922a 100%);
  color: #5d3a00;
  animation: medal-pulse 2s ease-in-out infinite;
}

.level-medal.locked {
  background: radial-gradient(circle at 35% 30%, #b8b8b8 0%, #787878 72%, #4a4a4a 100%);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
}

@keyframes medal-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

/* —— Overlays —— */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 20, 30, 0.55);
  backdrop-filter: blur(3px);
  padding: 20px;
  box-sizing: border-box;
}

.overlay[hidden] { display: none !important; }

/* Nine-slice — Rouleau Parchemin Pur (Option E) */
.overlay-card {
  position: relative;
  width: min(94vw, var(--modal-max-width));
  border-style: solid;
  border-image-slice: 15% 10% 15% 10% fill;
  border-image-repeat: stretch;
  border-width: 3px;
  border-radius: 20px;
  border-color: #dfc49c;
  background: radial-gradient(ellipse at center, #fdfaf0 0%, #f4e8d0 75%, #e9d5b5 100%);
  box-shadow: none;
  filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.45));
  padding: 18px 16px 20px;
  text-align: center;
  color: #3b2314;
}

.overlay-close {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.28);
  color: #fff;
  font-size: var(--text-meta);
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  z-index: 1;
}

.overlay-close:active {
  transform: scale(0.92);
}

.overlay-card.success {
  background: linear-gradient(180deg, #7b68ee, #5a4fcf);
}

.overlay-card.fail {
  background: linear-gradient(180deg, #e74c3c, #922b21);
}

.overlay-fail-msg {
  margin: 0 0 6px;
  font-size: var(--text-body);
  line-height: 1.35;
}

.overlay-fail-detail {
  margin: 0;
  font-size: var(--text-meta);
  opacity: 0.9;
}

/* ============================================================
   Écran de résultats (Game Over) — chrome bois + carte bleue imbriquée.
   Composant réutilisable pour l'écran de victoire plus tard.
   ============================================================ */

/* Coque bois : frame-wood.svg n'a PAS de fill, donc le centre laisse voir
   la carte bleue imbriquée. Même géométrie que .board-frame (R2 k=1, R8). */
/* k = 18/22 = 0.818 sur les côtés → bas = 30 x 0.818 = 24.5 (R2 : k identique
   sur les 4 côtés). border-radius = rx 20 x 0.818 = 16.4 (R8). */
.results-shell {
  position: relative;
  width: min(100%, 330px);
  border-style: solid;
  border-width: 22px 22px 30px 22px;
  border-color: #6b4a2e;
  border-image-slice: 25% 25% 31.25% 25% fill;
  border-image-repeat: stretch;
  border-radius: 20px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
}

/* Carte bleue intérieure — réutilise le sprite de carte existant */
.results-inner {
  border-style: solid;
  border-width: 3px;
  border-color: #dfc49c;
  border-image-slice: 24% 20% 24% 20% fill;
  border-image-repeat: stretch;
  border-radius: 28px;
  background: radial-gradient(ellipse at center, #fdfaf0 0%, #f4e8d0 100%);
  padding: 16px 12px 12px;
  text-align: center;
  color: #3b2314;
}

.results-crest {
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  width: 56px;
  height: 56px;
  background: radial-gradient(circle, #ffd56a 0%, #c9922a 100%);
  border-radius: 50%;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.45));
  pointer-events: none;
  z-index: 2;
}

/* Bandeau de titre — nine-slice horizontal, R10 : 40 x 34 / 64 = 21px.
   Non utilisé par l'écran d'échec (retiré : le titre suffit). Conservé pour
   la variante « niveau réussi », comme .results-crest. */
.results-ribbon {
  margin: 0 0 10px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-caption);
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #eaf4ff;
  text-shadow: 0 1px 2px rgba(8, 28, 52, 0.8);
  white-space: nowrap;
}

/* Titre display : dégradé clair clippé au texte + contour peint DERRIÈRE
   (paint-order), puis une ombre dure pour l'épaisseur.

   ATTENTION au ratio contour/fût : `-webkit-text-stroke` est centré sur le
   contour du glyphe, donc il ronge la moitié de son épaisseur VERS L'INTÉRIEUR.
   À 40px, un fût de 900 fait ~7px : un contour de 5px n'en laissait que ~2px
   de dégradé visible et le titre lisait bleu foncé. 2.5px en laisse ~5px.
   Régler via --title-stroke plutôt qu'en dur. */
.fail-title {
  --title-stroke: 3px;
  --title-stroke-color: #1e5391;
  margin: 2px 0 10px;
  font-size: 43px;
  line-height: 1.08;
  font-weight: 900;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  color: #eaf7ff;
  background: linear-gradient(180deg,
    #ffffff 0%,
    #f2fbff 26%,
    #b7e4fd 62%,
    #86ccf5 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  -webkit-text-stroke: var(--title-stroke) var(--title-stroke-color);
  paint-order: stroke fill;
  /* Grossir SANS manger le dégradé : `font-weight` est déjà à 900 (plafond, et
     Trebuchet n'a pas de coupe plus lourde), et épaissir le contour rongerait
     l'intérieur. Ces `drop-shadow` à décalage nul dilatent la silhouette vers
     l'EXTÉRIEUR seulement — l'empilement rend le bord net alors qu'une seule
     passe resterait floue. Puis l'ombre dure pour l'épaisseur, la douce pour
     le détachement. */
  filter:
    drop-shadow(0 0 0.7px var(--title-stroke-color))
    drop-shadow(0 0 0.7px var(--title-stroke-color))
    drop-shadow(0 0 0.7px var(--title-stroke-color))
    drop-shadow(0 2px 0 #16406f)
    drop-shadow(0 6px 10px rgba(4, 20, 42, 0.45));
}

/* Repli si le navigateur ne sait pas peindre le contour derrière le texte :
   sans paint-order le contour recouvrirait le dégradé. */
@supports not (paint-order: stroke) {
  .fail-title {
    -webkit-text-stroke: 0;
    -webkit-text-fill-color: #eaf7ff;
    background: none;
    /* anneau de contour simulé par 8 décalages + l'épaisseur + le détachement */
    text-shadow:
      -2px 0 0 #1e5391, 2px 0 0 #1e5391, 0 -2px 0 #1e5391, 0 2px 0 #1e5391,
      -1.5px -1.5px 0 #1e5391, 1.5px -1.5px 0 #1e5391,
      -1.5px 1.5px 0 #1e5391, 1.5px 1.5px 0 #1e5391,
      0 4px 0 #16406f, 0 8px 12px rgba(4, 20, 42, 0.45);
  }
}

.results-msg {
  margin: 0 0 12px;
  font-size: var(--text-body-lg);
  font-weight: 700;
  line-height: 1.4;
  color: #fff;
  /* text-shadow: 0 1px 2px rgba(8, 28, 52, 0.75); */
}

/* Bloc de stats encastré — panel-inset.svg, k = 1, fill */
.results-stats {
  margin: 0 0 14px;
  border-style: solid;
  border-width: 14px;
  border-color: transparent;
  /* border-image-source: url("assets/ui/panel-inset.svg"); */
  border-image-slice: 18 fill;
  border-image-repeat: stretch;
  /* k = 14/18 = 0.778 uniforme ; border-radius = rx 14 x 0.778 = 10.9 (R8) */
  border-radius: 10.9px;
  padding: 2px 4px;
  display: grid;
  gap: 7px;
}

.results-stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.fail-stat-label {
  font-size: 13px;
  font-weight: 800;
  color: #eaf4ff;
  text-shadow: 0 1px 1px rgba(8, 28, 52, 0.8);
  text-align: left;
}

.fail-stat-value {
  font-size: 17px;
  font-weight: 900;
  color: #ffce33;
  text-shadow: 0 1px 0 #5c3a21, 0 2px 2px rgba(0, 0, 0, 0.75);
  white-space: nowrap;
}

.overlay-card.intro {
  background: linear-gradient(180deg, #7eb8f0, #2c5f8a);
}

.overlay-card.pause {
  background: linear-gradient(180deg, #a0aec0, #4a5568);
}

/* Actions secondaires de la pause (Réglages, Accueil) — sous le bouton
   Reprendre, en icône + libellé pour rester lisibles à petite taille. */
.pause-actions {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin-top: 14px;
}

.pause-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  color: inherit;
  font: inherit;
}

.pause-action:active {
  transform: scale(0.92);
}

/* Reprend le sprite pierre de .settings-btn ; sur un <span> il faut rétablir
   l'affichage en bloc que le bouton d'origine avait par défaut. */
.pause-action-icon {
  display: block;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
}

.pause-action-icon.home-btn,
.home-btn {
  background-color: rgba(90, 70, 50, 0.45);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  border-radius: 8px;
}

.pause-action-emoji {
  font-size: 27px;
  line-height: 34px;
  text-align: center;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}

/* Texte sombre : l'intérieur de la carte est le parchemin clair du frame-modal,
   pas le dégradé ardoise de .overlay-card.pause (masqué par le border-image). */
.pause-action-label {
  font-size: var(--text-meta);
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #5c3d1e;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
  white-space: nowrap;
}

/* ==========================================================================
   Variantes de Parchemin pour Modales (Validation Visuelle)
   ========================================================================== */

/* Option A: Cadre Bois / Parchemin Original (Nine-Slice Frame) */
.overlay-card.parchment-frame-wood {
  border-image-slice: 24% 20% 24% 20% fill;
  border-width: 28px 22px 28px 22px;
  background: transparent;
  border-radius: 28px;
}

/* Option B: Parchemin Épuré (Bordure Dorée & Fond Papier Chaud) */
.overlay-card.parchment-clean {
  border-image-source: none !important;
  border: 3px solid #dfc49c !important;
  border-radius: 24px !important;
  background: radial-gradient(ellipse at center, #fdfaf0 0%, #f4e8d0 75%, #e9d5b5 100%) !important;
  box-shadow: inset 0 0 16px rgba(180, 130, 70, 0.25), 0 10px 28px rgba(0, 0, 0, 0.4) !important;
  padding: 22px 18px 18px !important;
}

/* Option C: Parchemin Multi-Couches (Feuilles Superposées Vintage) */
.overlay-card.parchment-layered {
  border-image-source: none !important;
  border: 2px solid #d4b896 !important;
  border-radius: 22px !important;
  background: radial-gradient(ellipse at center, #fdf8e8 0%, #f3e5c8 70%, #e8d0a2 100%) !important;
  box-shadow: inset 0 0 18px rgba(160, 115, 60, 0.22), 0 12px 32px rgba(0, 0, 0, 0.45) !important;
  padding: 22px 18px 18px !important;
  position: relative !important;
}

.overlay-card.parchment-layered::before {
  content: "";
  position: absolute;
  inset: 5px;
  background: #f7ebcf;
  border-radius: 18px;
  transform: rotate(-1.5deg);
  z-index: -1;
  border: 1px solid #dfc7a1;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
  pointer-events: none;
}

.overlay-card.parchment-layered::after {
  content: "";
  position: absolute;
  inset: 5px;
  background: #fffdf5;
  border-radius: 18px;
  transform: rotate(1deg);
  z-index: -1;
  border: 1px solid #ebd8c0;
  pointer-events: none;
}

/* Option D: Rouleau Parchemin 3D avec Embouts Bois (9-Slice dynamique) */
.overlay-card.parchment-scroll-wooden {
  border-style: solid !important;
  border-image-slice: 18% 18% 18% 18% fill !important;
  border-image-repeat: stretch !important;
  border-width: 44px 38px 44px 38px !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.45));
  padding: 8px 12px 10px !important;
  color: #3b2314 !important;
  height: auto !important;
}

/* Option E: Rouleau Parchemin Pur (9-Slice dynamique - Ajusté au contenu) */
.overlay-card.parchment-scroll-paper {
  border-style: solid !important;
  border-image-slice: 15% 10% 15% 10% fill !important;
  border-image-repeat: stretch !important;
  border-width: 44px 22px 44px 22px !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  filter: drop-shadow(0 10px 24px rgba(0, 0, 0, 0.45));
  padding: 18px 16px 20px !important;
  color: #3b2314 !important;
  height: auto !important;
}

.overlay-card.settings {
  background: transparent !important;
}

.overlay-objective {
  margin: 0 0 6px;
  font-size: var(--text-body-lg);
  font-weight: 700;
}

.overlay-eyebrow {
  margin: 0 0 4px;
  font-size: var(--text-meta);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.9;
}

.overlay-card h1 {
  margin: 0 0 8px;
  font-size: var(--text-title);
}

.overlay-coins {
  margin: 0 0 10px;
  font-size: 20px;
  color: #ffeaa7;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.inline-coin {
  width: 20px;
  height: 20px;
  object-fit: contain;
  vertical-align: middle;
  display: inline-block;
}

.overlay-coins .inline-coin {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.overlay-record {
  margin: 0 0 8px;
  font-size: var(--text-body);
  font-weight: 800;
  color: #ffeaa7;
}

.settings-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  text-align: left;
}

.settings-list li + li {
  margin-top: 10px;
}

.settings-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--text-body);
  font-weight: 700;
  cursor: pointer;
}

.settings-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #27ae60;
  flex-shrink: 0;
}

.settings-volume {
  flex-wrap: wrap;
  gap: 8px 10px;
}

.settings-volume span:first-child {
  flex: 1 1 100%;
}

.settings-volume input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
  accent-color: #27ae60;
}

.settings-volume .volume-val {
  flex: 0 0 28px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}

#btnResetProgress {
  margin-top: 0;
  margin-bottom: 8px;
}

/* Sprite 240×100 : capsule (rx 37 sur 74 de haut).
   Slice horizontal seul (R1, unités source : 43.2 sur 240) → les embouts arrondis sont
   préservés, la composition verticale (reflet en haut, épaisseur en bas) suit la hauteur.
   R10 : B_lateral = S_lateral × H_el / H_sprite = 43.2 × 52 / 100 = 22.5 → 23px.
   Le coefficient réel est 0.432, pas 0.44 : c'est la formule qu'il faut retenir,
   la constante change dès que le sprite ou le slice change. */
.btn-primary {
  margin-top: 12px;
  width: 100%;
  height: var(--btn-height);
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  background: linear-gradient(180deg, #5ecc7a 0%, #2d9a4a 100%);
  border-style: solid;
  border-width: 0 23px;
  border-color: transparent;
  border-image-slice: 0 18.6% fill;
  border-image-repeat: stretch;
  border-radius: 999px;
  font-family: var(--font);
  font-size: var(--text-btn);
  font-weight: 800;
  color: #ffffff;
  text-shadow: 0 2px 0 #073516, 0 1px 2px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

.btn-retry,
.btn-rate {
  color: #fff;
  text-shadow: 0 1px 2px rgba(90, 36, 0, 0.6);
  background: linear-gradient(180deg, #ffb347 0%, #e67e22 100%);
  border-image-slice: 0 18.6% fill;
}

.btn-secondary {
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  background: linear-gradient(180deg, #9aa3ad 0%, #636e72 100%);
  border-image-slice: 0 18.6% fill;
}

.btn-primary:active {
  filter: brightness(0.92);
}

@media (max-height: 720px) {
  :root {--cell: 30px;}
  .level-medal { width: 34px; height: 34px; }
  /* R2 : les 4 côtés doivent garder le même k. Facteur 18/22 = 0.818 → bas 30 x 0.818 = 24.5,
     et border-radius rééchelonné du même facteur (20 x 0.818). */
  .board-frame { border-width: 18px 18px 24.5px 18px; border-radius: 16.4px; }
  /* R10 : B_lateral = S_lateral x H_el / H_sprite = 43.2 x 46 / 100 = 19.9 */
  .btn-primary { height: 50px; border-width: 0 20px; font-size: 17px; }
}

@media (max-width: 380px) {
  .hud-level { font-size: var(--text-label); }
  .hud-score { font-size: 18px; }
  .stat-pill { padding: 4px 10px 4px 32px; min-height: 30px; }
  .pill-badge { width: 32px; height: 32px; }
  .results-shell { width: min(100%, 300px); }
  .fail-title { font-size: 33px; --title-stroke: 2.2px; }
  .fail-stat-label { font-size: var(--text-meta); }
  .fail-stat-value { font-size: var(--text-body-lg); }
  .results-msg { font-size: var(--text-body); }
  .feedback {
    white-space: normal;
    max-width: 92%;
  }
}

/* —— Pause : gèle les animations en boucle —— */
.app.paused .pausable-anim {
  animation-play-state: paused;
}

@media (prefers-reduced-motion: reduce),
html.reduce-motion {
  .cloud-a, .cloud-b,
  .tree-sway-left, .tree-sway-right,
  .flower-left, .flower-right,
  .river-shine-inline,
  .level-medal.current,
  .cell.clearing,
  .feedback,
  .clear-particle,
  .clear-chip {
    animation: none !important;
    transition: none !important;
  }
}

/* —— Settings (parchemin + dropdown langue) —— */
.overlay-card.settings {
  width: min(96vw, var(--modal-max-width));
  max-height: min(92vh, 720px);
  overflow-y: auto;
  text-align: left;
}

.overlay-card.settings h1 {
  text-align: center;
  margin-top: 0;
}

.settings-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-card {
  background: rgba(255, 248, 230, 0.42);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(59, 35, 20, 0.1);
}

.settings-item,
label.settings-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: none;
  background: none;
  text-align: left;
  font: inherit;
  font-size: var(--text-body);
  font-weight: 600;
  color: #3b2314;
  box-sizing: border-box;
  cursor: pointer;
  text-decoration: none;
}

.settings-item + .settings-item,
.settings-item + label.settings-item,
label.settings-item + .settings-item,
label.settings-item + label.settings-item,
.settings-language-dropdown {
  border-top: 1px solid rgba(59, 35, 20, 0.1);
}

.settings-item-icon {
  display: inline-block;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  vertical-align: middle;
}

.settings-item-label {
  flex: 1;
  min-width: 0;
}

.settings-item-value {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-meta);
  font-weight: 600;
  color: #6b4f38;
}

.settings-item-chevron::after {
  content: "›";
  font-size: 20px;
  line-height: 1;
  color: #9a7b62;
  margin-left: 2px;
  transition: transform 0.15s ease;
}

.settings-language-wrap.is-open .settings-item-chevron::after {
  transform: rotate(90deg);
}

.settings-toggle {
  position: relative;
  width: 50px;
  height: 30px;
  flex-shrink: 0;
}

.settings-toggle input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  z-index: 1;
}

.settings-toggle-track {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: #c4b5a3;
  transition: background 0.18s ease;
}

.settings-toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  transition: transform 0.18s ease;
}

.settings-toggle input:checked + .settings-toggle-track {
  background: #5a9fd4;
}

.settings-toggle input:checked + .settings-toggle-track::after {
  transform: translateX(20px);
}

/* Une seule ligne, comme Musique et Effets sonores : avec flex-wrap et un label
   en flex-basis 100%, l'icône restait seule sur la première ligne et le curseur
   passait sur une troisième — la rangée cassait l'alignement de la carte. */
.settings-volume-row {
  cursor: default;
}

/* Le label garde sa largeur naturelle et laisse le reste au curseur. */
.settings-volume-row .settings-item-label {
  flex: 0 0 auto;
}

.settings-volume-row input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
  accent-color: #5a9fd4;
}

.settings-volume-row .volume-val {
  flex: 0 0 32px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  color: #6b4f38;
}

.settings-language-dropdown {
  max-height: 220px;
  overflow-y: auto;
}

.settings-language-dropdown[hidden] {
  display: none !important;
}

.settings-footer {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-footer .btn-primary {
  width: 100%;
}

#btnResetProgress {
  margin: 0;
}

.language-list {
  list-style: none;
  margin: 0;
  padding: 0;
  text-align: left;
}

.language-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-top: 1px solid rgba(59, 35, 20, 0.08);
  background: none;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: #3b2314;
  cursor: pointer;
}

.language-list li:first-child .language-option {
  border-top: none;
}

.language-option.is-selected {
  color: #2f7fd4;
}

.language-option-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  display: grid;
  place-items: center;
  font-size: 13px;
  line-height: 1;
}

.language-option.is-selected .language-option-check {
  border-color: #2f7fd4;
  background: #2f7fd4;
  color: #fff;
}

