/* =========================================================================
   Énigmes Saga — styles
   Ambiance : aventure (parchemin, bois, or) pour coller aux illustrations.
   ========================================================================= */
:root {
  --ink: #3b2a1a;
  --ink-soft: #6d5640;
  --paper: #fbf3e2;
  --paper-2: #f3e3c3;
  --paper-edge: #d8b98a;
  --wood: #8a5a2b;
  --wood-dark: #5c3a1a;
  --gold: #f6c343;
  --gold-dark: #c98a12;
  --sky: #2f8fd8;
  --sky-dark: #1b5f9e;
  --good: #3aa857;
  --bad: #d64545;
  --night: #1d1633;
  --shadow: 0 6px 18px rgba(30, 15, 0, .35);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --font: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  --font-title: "Georgia", "Times New Roman", serif;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--night); color: var(--ink);
  font-family: var(--font); font-size: 16px;
  overscroll-behavior: none; touch-action: manipulation;
  user-select: none; -webkit-user-select: none;
}
input { user-select: text; -webkit-user-select: text; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
h1, h2, h3 { font-family: var(--font-title); margin: 0 0 .5em; }
.muted { color: var(--ink-soft); opacity: .85; }
.error { color: var(--bad); font-weight: bold; }

#app { position: fixed; inset: 0; overflow: hidden; }

/* ---- Démarrage ---------------------------------------------------------- */
.boot { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; color: #fff; }
.boot-spinner { width: 48px; height: 48px; border-radius: 50%; border: 5px solid rgba(255,255,255,.2); border-top-color: var(--gold); animation: spin 1s linear infinite; }
.boot-bar { width: 200px; height: 6px; background: rgba(255,255,255,.15); border-radius: 3px; overflow: hidden; }
.boot-bar i { display: block; height: 100%; width: 0; background: var(--gold); transition: width .2s; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Scènes ------------------------------------------------------------- */
.scene { position: absolute; inset: 0; overflow: hidden; opacity: 0; transition: opacity .25s ease; }
.scene.entered { opacity: 1; }
.scene.leaving { opacity: 0; transition-duration: .18s; }
.scene-bg { position: absolute; inset: 0; background-size: cover; background-position: center; }
.scene-bg.dim::after { content: ""; position: absolute; inset: 0; background: rgba(20, 12, 40, .45); }

/* ---- Images & placeholders ---------------------------------------------- */
.art { background-size: cover; background-position: center; background-repeat: no-repeat; }
.ph {
  --ph-hue: 260;
  position: relative;
  background-color: hsl(var(--ph-hue) 35% 42%);
  background-image: repeating-linear-gradient(45deg, hsl(var(--ph-hue) 35% 46%) 0 14px, hsl(var(--ph-hue) 35% 40%) 14px 28px);
}
.ph::after {
  content: attr(data-ph);
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  padding: 4px; color: rgba(255,255,255,.85); font: bold 12px/1.2 var(--font);
  text-shadow: 0 1px 2px rgba(0,0,0,.5); overflow: hidden; word-break: break-word;
}
.avatar { width: 44px; height: 44px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.4); flex: none; }
.avatar.ph::after { font-size: 18px; }
.avatar.small { width: 32px; height: 32px; border-width: 2px; }
.avatar.small.ph::after { font-size: 14px; }

/* ---- Boutons ------------------------------------------------------------ */
.btn {
  border: 0; border-radius: 999px; padding: 12px 22px; font-weight: bold; font-size: 1rem;
  min-height: 46px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: transform .08s, filter .15s, box-shadow .15s; letter-spacing: .02em;
}
.btn:active:not(:disabled) { transform: translateY(2px) scale(.98); }
.btn:disabled { filter: grayscale(.8) opacity(.55); }
.btn.primary {
  background: linear-gradient(#ffd866, var(--gold) 55%, var(--gold-dark));
  color: var(--wood-dark); box-shadow: 0 4px 0 #9a6608, var(--shadow);
  text-shadow: 0 1px 0 rgba(255,255,255,.5);
}
.btn.secondary {
  background: linear-gradient(#a87445, var(--wood) 60%, var(--wood-dark));
  color: #fff6e3; box-shadow: 0 4px 0 #3d2610, var(--shadow);
}
.btn.ghost { background: rgba(255,255,255,.18); color: #fff; backdrop-filter: blur(6px); border: 1px solid rgba(255,255,255,.35); }
.btn.danger { background: var(--bad); color: #fff; box-shadow: 0 3px 0 #8e2323; }
.btn.big { font-size: 1.35rem; padding: 16px 40px; min-height: 60px; }
.btn.small { padding: 8px 14px; min-height: 38px; font-size: .9rem; }

/* ---- Toasts, modales, tampons -------------------------------------------- */
#toast-root { position: fixed; z-index: 60; left: 0; right: 0; top: calc(64px + var(--safe-top)); display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast {
  background: rgba(29, 22, 51, .92); color: #fff; padding: 10px 18px; border-radius: 999px;
  box-shadow: var(--shadow); font-size: .92rem; max-width: 520px; text-align: center;
  transform: translateY(-12px); opacity: 0; transition: .3s;
}
.toast.show { transform: none; opacity: 1; }
.toast.good { background: rgba(38, 120, 60, .95); }
.toast.warn { background: rgba(160, 60, 30, .95); }

#overlay-root { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
#overlay-root > * { pointer-events: auto; }
.modal-wrap {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: rgba(15, 8, 30, .55); opacity: 0; transition: opacity .2s;
}
.modal-wrap.show { opacity: 1; }
.modal {
  width: min(480px, 100%); max-height: calc(100dvh - 32px); overflow: auto;
  background: var(--paper); border: 3px solid var(--paper-edge); border-radius: 22px;
  box-shadow: 0 0 0 4px var(--wood), var(--shadow); padding: 20px;
  transform: scale(.92); transition: transform .2s;
}
.modal-wrap.show .modal { transform: none; }
.modal-title { font-size: 1.25rem; color: var(--wood-dark); text-align: center; }
.modal-body p { line-height: 1.45; margin: .4em 0; }
.modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }

.stamp {
  position: fixed; left: 50%; top: 45%; pointer-events: none !important;
  font: bold clamp(48px, 12vmin, 96px) var(--font-title); padding: .1em .5em; border-radius: 18px;
  transform: translate(-50%, -50%) scale(2.2) rotate(-8deg); opacity: 0; transition: .25s cubic-bezier(.2, 1.6, .5, 1);
  border: 6px solid currentColor; background: rgba(255, 250, 235, .92);
}
.stamp.show { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(-8deg); }
.stamp.good { color: var(--good); }
.stamp.bad { color: var(--bad); }

/* ---- Écran titre ---------------------------------------------------------- */
.title-scene .scene-bg { background-position: 30% center; }
.title-scene::before {
  content: ""; position: absolute; inset: 0; z-index: 1;
  background: linear-gradient(to top, rgba(20,10,40,.75), rgba(20,10,40,0) 55%);
}
.title-content {
  position: absolute; z-index: 2; inset: auto 0 0 0;
  padding: 16px 16px calc(28px + var(--safe-bottom));
  display: grid; justify-items: center; gap: 12px;
}
.title-text {
  margin: 0; color: #fff; font-size: clamp(2rem, 7vmin, 3.6rem); text-align: center;
  text-shadow: 0 3px 0 var(--wood-dark), 0 6px 18px rgba(0,0,0,.6);
  -webkit-text-stroke: 1px var(--wood-dark);
}
.title-logo { width: min(70vw, 520px); aspect-ratio: 2; background-size: contain; }
.title-who { margin: 0; color: #fff; text-shadow: 0 1px 4px #000; }
.title-menu { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; max-width: 760px; }
.online-badge {
  position: absolute; z-index: 2; right: calc(12px + var(--safe-right)); top: calc(12px + var(--safe-top));
  color: #fff; font-size: .85rem; background: rgba(0,0,0,.35); padding: 4px 10px; border-radius: 999px;
}
.online-badge:empty { display: none; }
@media (orientation: portrait) {
  .title-menu { flex-direction: column; align-items: stretch; width: min(320px, 100%); }
}

/* ---- HUD -------------------------------------------------------------------- */
.hud {
  position: absolute; z-index: 5; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-top)) calc(10px + var(--safe-right)) 8px calc(10px + var(--safe-left));
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud-spacer { flex: 1; pointer-events: none; }
.hud-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 3px solid #fff3d6; flex: none;
  background: linear-gradient(#a87445, var(--wood-dark)); color: #fff; font-size: 1.15rem;
  box-shadow: 0 3px 8px rgba(0,0,0,.45); display: grid; place-items: center;
}
.hud-btn:disabled { opacity: .35; }
.hud-stat {
  display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px 0 6px;
  background: rgba(40, 22, 8, .72); border: 2px solid rgba(255, 230, 180, .6); border-radius: 999px;
  color: #fff; font-weight: bold;
}
.hud-icon { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 15px; }
.hud-icon.score { background: var(--gold); color: #fff; text-shadow: 0 1px 1px var(--gold-dark); }
.hud-unit { font-size: .72rem; opacity: .8; font-weight: normal; }
.hud-icon.coin { background: radial-gradient(#ffe48a, var(--gold-dark)); color: var(--gold-dark); font-size: 12px; }

/* ---- Carte ------------------------------------------------------------------ */
.map-scene { background: #234; }
.map-viewport {
  position: absolute; inset: 0; overflow: auto; scrollbar-width: none;
  transition: opacity .16s; cursor: grab;
}
.map-viewport::-webkit-scrollbar { display: none; }
.map-viewport.switching { opacity: 0; }
.map-canvas {
  position: relative; container-type: inline-size;
  background-size: 100% 100%;
}
.map-canvas:not(.painted).ph { background-image: linear-gradient(#7cc6e8, #b8e2a0 45%, #6fae55); }
.map-canvas:not(.painted).ph::after { content: none; }

.map-path { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.map-path path { fill: none; stroke-linecap: round; }
.map-path .path-shadow { stroke: rgba(80, 50, 20, .35); stroke-width: 34; }
.map-path .path-main { stroke: #f2d9a6; stroke-width: 22; stroke-dasharray: 2 36; stroke-width: 18; }

/* Nœud de niveau : un cercle de diamètre --node (% de la largeur de la carte). */
.map-node {
  --d: calc(var(--node) * var(--s, 1) * 1cqw);
  position: absolute; width: var(--d); height: var(--d);
  transform: translate(-50%, -50%); border-radius: 50%;
  border: 0; padding: 0; background: none;
  font-size: calc(var(--d) * .42);
}
.map-canvas:not(.painted) .map-node {
  background: radial-gradient(circle at 35% 30%, #9bb0c4, #5a6b7d);
  border: calc(var(--d) * .07) solid #e8eef3; box-shadow: 0 calc(var(--d) * .08) 0 #2c3946, 0 4px 10px rgba(0,0,0,.4);
}
.map-canvas:not(.painted) .map-node.open,
.map-canvas:not(.painted) .map-node.done { background: radial-gradient(circle at 35% 30%, #66b9ff, var(--sky-dark)); }
.map-canvas:not(.painted) .map-node.boss { background: radial-gradient(circle at 35% 30%, #ffe27a, var(--gold-dark)); }
.node-num { color: #fff; font-weight: bold; font-family: var(--font-title); text-shadow: 0 2px 2px rgba(0,0,0,.45); }

/* Sur une carte peinte, les nœuds sont transparents : seuls les états s'affichent. */
.map-canvas.painted .map-node::before {
  content: ""; position: absolute; inset: -6%; border-radius: 50%;
  transition: background .2s, box-shadow .2s;
}
.map-canvas.painted .map-node:hover::before { box-shadow: 0 0 0 calc(var(--d) * .06) rgba(255,255,255,.7); }
.node-lock {
  position: absolute; inset: 0; display: grid; place-items: center; font-size: calc(var(--d) * .38);
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.6));
}
.map-canvas:not(.painted) .map-node.locked .node-num { opacity: .5; }

/* Plaque sous la pastille : recouvre le socle et les étoiles dessinés sur la carte. */
.node-plate {
  position: absolute; left: 50%; top: 92%; width: 136%; height: 50%;
  transform: translate(-50%, -50%); border-radius: 999px; pointer-events: none;
  display: grid; place-items: center; white-space: nowrap;
  font: bold calc(var(--d) * .2) var(--font); color: #e8eef3; letter-spacing: .02em;
  background: var(--plate);
  border: calc(var(--d) * .045) solid var(--rim);
  box-shadow: 0 calc(var(--d) * .05) calc(var(--d) * .08) rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.25);
}
.map-node.locked .node-plate { font-size: calc(var(--d) * .24); color: #aab4bf; }

/* Médaillon redessiné sur la pastille peinte (mesures relevées sur la carte : ovale ≈ 84 × 70 px,
   centre ≈ 5 px au-dessus de pos). Couleur selon la position du joueur :
   terminé = bleu, niveau en cours = or, verrouillé = ardoise. Modifiable via --face / --plate. */
.map-node { --face: radial-gradient(circle at 50% 30%, #77818d, #3c4550 70%); --plate: linear-gradient(#56606d, #2b323c); --rim: #c9d1d9; }
.map-node.done { --face: radial-gradient(circle at 50% 30%, #79c8ff, #1f6fb8 70%); --plate: linear-gradient(#3f86c9, #1c4f86); }
.map-node.current { --face: radial-gradient(circle at 50% 30%, #fff1a8, #f2b21c 55%, #c47a06); --plate: linear-gradient(#f0b53a, #a8650a); }
.map-node.boss { --rim: #ffd95e; }
.node-face {
  position: absolute; left: 50%; top: 44%; width: 100%; height: 84%; z-index: 2;
  transform: translate(-50%, -50%); border-radius: 50%; pointer-events: none;
  display: grid; place-items: center;
  background: var(--face);
  border: calc(var(--d) * .075) solid var(--rim);
  box-shadow: inset 0 calc(var(--d) * .04) calc(var(--d) * .06) rgba(255,255,255,.35),
              inset 0 calc(var(--d) * -.05) calc(var(--d) * .08) rgba(0,0,0,.3),
              0 calc(var(--d) * .05) calc(var(--d) * .08) rgba(0,0,0,.45);
  transition: background .3s;
}
.node-face span {
  font: bold calc(var(--d) * .44) / 1 var(--font-title); color: #fff;
  text-shadow: 0 calc(var(--d) * .03) 0 rgba(0,0,0,.45), 0 0 calc(var(--d) * .08) rgba(0,0,0,.35);
}
.map-node.locked .node-face span { color: #d5dbe1; }
.map-node.current .node-face span { text-shadow: 0 calc(var(--d) * .03) 0 #8a5206, 0 0 calc(var(--d) * .1) rgba(120,60,0,.5); }
.node-plate { z-index: 1; }
/* Carte générée : coche « terminé » ; sans-faute : petit éclat doré en haut à droite. */
.node-check {
  position: absolute; right: -10%; bottom: -10%; width: 42%; aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center; font-size: calc(var(--d) * .26); font-weight: bold;
  background: var(--good); color: #fff; border: calc(var(--d) * .04) solid #fff; box-shadow: 0 2px 4px rgba(0,0,0,.4);
}
.node-perfect {
  position: absolute; right: -14%; top: -14%; width: 40%; aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center; font-size: calc(var(--d) * .24);
  background: radial-gradient(#fff6b0, var(--gold) 60%, var(--gold-dark)); color: var(--wood-dark);
  border: calc(var(--d) * .035) solid #fff; box-shadow: 0 0 calc(var(--d) * .15) var(--gold);
}

/* Niveau courant : halo pulsant. */
.map-node.current::after {
  content: ""; position: absolute; inset: -14%; border-radius: 50%;
  border: calc(var(--d) * .06) solid #fff6c2; box-shadow: 0 0 calc(var(--d) * .3) var(--gold);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(1.12); opacity: .55; } }

.map-me {
  position: absolute; transform: translate(-50%, calc(-100% - var(--node) * .55cqw));
  pointer-events: none; animation: bob 1.6s ease-in-out infinite;
}
.map-me .avatar { width: calc(var(--node) * .8cqw); height: calc(var(--node) * .8cqw); min-width: 36px; min-height: 36px; border-color: var(--gold); }
.map-me::after {
  content: ""; position: absolute; left: 50%; bottom: -8px; transform: translateX(-50%);
  border: 8px solid transparent; border-top-color: var(--gold); border-bottom: 0;
}
@keyframes bob { 50% { margin-top: -6px; } }

.map-friends {
  position: absolute; display: flex; align-items: center; border: 0; background: none; padding: 0;
  transform: translate(calc(var(--node) * .55cqw), -50%);
}
.friend-pin + .friend-pin { margin-left: -10px; }
.friend-more { background: #fff; border-radius: 999px; padding: 2px 6px; font-size: .75rem; font-weight: bold; margin-left: 2px; }

.map-gate {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px;
  background: rgba(20, 12, 40, .55); backdrop-filter: grayscale(.7);
}
.map-gate-box { background: var(--paper); border-radius: var(--radius); padding: 18px 24px; text-align: center; box-shadow: var(--shadow); border: 3px solid var(--paper-edge); }
.map-gate-box p { margin: .4em 0 0; }

.chapter-nav {
  position: absolute; z-index: 5; left: 50%; bottom: calc(10px + var(--safe-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; width: min(520px, calc(100% - 20px));
}
.chapter-title {
  flex: 1; min-width: 0; display: grid; text-align: center; padding: 6px 14px; border-radius: 14px;
  background: linear-gradient(var(--paper), var(--paper-2)); border: 3px solid var(--wood); box-shadow: var(--shadow);
}
.chapter-title strong { font-family: var(--font-title); font-size: .98rem; color: var(--wood-dark); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chapter-title small { color: var(--ink-soft); font-size: .78rem; }

.map-canvas.editing { cursor: crosshair; }
.edit-dot {
  position: absolute; transform: translate(-50%, -50%); width: 22px; height: 22px; border-radius: 50%;
  background: #e0245e; color: #fff; font-size: 11px; display: grid; place-items: center; border: 2px solid #fff; pointer-events: none;
}

/* ---- Ambiance de la carte (maquettes animées : nuages, oiseaux, lucioles) ---------------- */
.map-ambient { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.fx-img { width: 100%; aspect-ratio: var(--ratio, 2); background-size: contain; }

.fx-cloud {
  position: absolute; left: 0; top: var(--top); width: calc(var(--w) * 1cqw); opacity: var(--alpha);
  filter: drop-shadow(0 .5cqw .8cqw rgba(40, 60, 90, .18));
  animation: fx-drift var(--dur) linear var(--delay) infinite;
  will-change: transform;
}
.fx-cloud-art { display: block; width: 100%; }
@keyframes fx-drift { from { transform: translateX(-30cqw); } to { transform: translateX(110cqw); } }

.fx-flock {
  position: absolute; left: 0; top: var(--top); width: 0; height: 0;
  animation: fx-fly var(--dur) linear forwards;
}
@keyframes fx-fly {
  0%   { transform: translate(calc(50cqw - var(--dir) * 65cqw), 0); }
  50%  { transform: translate(50cqw, -2.5cqw); }
  100% { transform: translate(calc(50cqw + var(--dir) * 65cqw), 1cqw); }
}
.fx-bird { position: absolute; left: var(--dx); top: var(--dy); width: calc(var(--size) * 1cqw); transform: scaleX(var(--dir)); }
.fx-bird-art { display: block; width: 100%; overflow: visible; }
.fx-wings { transform-box: fill-box; transform-origin: center 70%; animation: fx-flap var(--flap) ease-in-out infinite alternate; }
@keyframes fx-flap { to { transform: scaleY(-.5); } }

.fx-firefly {
  position: absolute; width: .8cqw; height: .8cqw; min-width: 7px; min-height: 7px; border-radius: 50%;
  background: radial-gradient(#ffffff, #fff3a0 35%, #ffd84a 60%, rgba(255, 220, 80, 0) 75%);
  box-shadow: 0 0 1.4cqw .55cqw rgba(255, 236, 120, .75), 0 0 3cqw 1cqw rgba(255, 210, 60, .3);
  animation: fx-wander var(--dur) ease-in-out var(--delay) infinite alternate,
             fx-blink var(--blink) ease-in-out var(--delay) infinite alternate;
}
@keyframes fx-wander { to { transform: translate(var(--mx), var(--my)); } }
@keyframes fx-blink { from { opacity: .1; } to { opacity: 1; } }

/* Ombre de nuage : grande tache sombre très floue qui glisse lentement en diagonale. */
.fx-shadow {
  position: absolute; left: 0; top: var(--top);
  width: calc(var(--w) * 1cqw); aspect-ratio: 2.2; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(10, 30, 60, var(--alpha)), rgba(10, 30, 60, calc(var(--alpha) * .55)) 55%, transparent);
  mix-blend-mode: multiply; filter: blur(2cqw);
  animation: fx-shadow-drift var(--dur) linear var(--delay) infinite;
  will-change: transform;
}
@keyframes fx-shadow-drift {
  from { transform: translate(-65cqw, 6cqw); }
  to   { transform: translate(110cqw, -6cqw); }
}
/* Reflet sur l'eau : petite étoile à 4 branches qui s'allume puis s'éteint. */
.fx-glint {
  position: absolute; width: calc(var(--s) * 1.3cqw); aspect-ratio: 1; translate: -50% -50%;
  background:
    linear-gradient(90deg, transparent 0 46%, #fff 50%, transparent 54% 100%),
    linear-gradient(0deg, transparent 0 46%, #fff 50%, transparent 54% 100%),
    radial-gradient(circle, rgba(255, 255, 255, .95) 0 12%, rgba(200, 235, 255, .5) 22%, transparent 45%);
  mix-blend-mode: screen; opacity: 0; scale: 0;
  animation: fx-glint var(--dur) ease-in-out var(--delay) infinite;
}
@keyframes fx-glint {
  0%, 62%, 100% { opacity: 0; scale: .2; rotate: 0deg; }
  74%           { opacity: 1; scale: 1; rotate: 45deg; }
  86%           { opacity: 0; scale: .4; rotate: 90deg; }
}

/* Fiche de niveau */
.level-card { display: grid; gap: 6px; }
.level-thumb { width: 100%; aspect-ratio: var(--ratio, 4 / 3); max-height: 30dvh; background-size: contain; }
.level-meta { margin: 0; text-align: center; font-weight: bold; color: var(--wood); }
.level-best { margin: 0; text-align: center; }
.level-card h3 { font-size: 1rem; margin: 8px 0 0; }
.mini-board { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.mini-board li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 10px; border-radius: 8px; background: var(--paper-2); font-size: .9rem; }
.mini-board li.me { background: #ffe8a3; font-weight: bold; }
.mini-board li.muted { justify-content: center; }
.plain { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }

/* ---- Énigme ------------------------------------------------------------------ */
.puzzle-stage { position: absolute; inset: 0; display: flex; flex-direction: column; }

/* Dialogues */
.dialogue { position: absolute; inset: 0; cursor: pointer; }
/* Personnage en pied (image haute, fond transparent) */
.dlg-portrait { position: absolute; bottom: 0; height: min(78%, 620px); aspect-ratio: 2 / 3; }
.dlg-portrait.left { left: max(4%, var(--safe-left)); }
.dlg-portrait.right { right: max(4%, var(--safe-right)); }
.dlg-portrait .portrait { width: 100%; height: 100%; background-size: contain; background-position: bottom center; animation: slide-up .35s ease-out; }
.dlg-portrait .portrait.ph { border-radius: 24px 24px 0 0; opacity: .9; }
/* Médaillon (buste carré) : rond cerclé d'or, posé au-dessus de la boîte de dialogue */
.dlg-portrait.medallion {
  height: auto; width: min(40dvh, 34vw, 320px); aspect-ratio: 1;
  bottom: calc(118px + var(--safe-bottom));
}
.dlg-portrait.medallion.left { left: max(6%, var(--safe-left)); }
.dlg-portrait.medallion.right { right: max(6%, var(--safe-right)); }
.dlg-portrait.medallion .portrait {
  border-radius: 50%; background-size: cover; background-position: center;
  border: 6px solid var(--gold); box-shadow: 0 0 0 4px var(--wood-dark), 0 10px 28px rgba(0,0,0,.5);
  animation: medal-in .4s cubic-bezier(.2, 1.5, .5, 1);
}
@keyframes medal-in { from { transform: scale(.6) rotate(-8deg); opacity: 0; } }
@media (orientation: portrait) { .dlg-portrait.medallion { width: min(60vw, 300px); } }
@keyframes slide-up { from { transform: translateY(30px); opacity: 0; } }
.dlg-box {
  position: absolute; left: 50%; bottom: calc(16px + var(--safe-bottom)); transform: translateX(-50%);
  width: min(860px, calc(100% - 24px)); min-height: 120px;
  background: var(--paper); border: 3px solid var(--paper-edge); border-radius: 18px;
  box-shadow: 0 0 0 4px var(--wood), var(--shadow); padding: 26px 22px 18px;
}
.dlg-name {
  position: absolute; top: -18px; left: 20px; padding: 4px 16px; border-radius: 999px;
  background: var(--wood); color: #fff; font-weight: bold; box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
.dlg-text { margin: 0; font-size: 1.1rem; line-height: 1.5; min-height: 3em; }
.dlg-next { position: absolute; right: 16px; bottom: 8px; color: var(--wood); animation: bob 1s infinite; }
.dlg-skip { position: absolute; top: calc(12px + var(--safe-top)); right: calc(12px + var(--safe-right)); }

/* Vue énigme */
.puzzle-view {
  position: relative; z-index: 1; flex: 1; min-height: 0;
  display: grid; grid-template-rows: auto auto 1fr auto; gap: 10px;
  width: min(1100px, 100%); margin: 0 auto;
  padding: calc(8px + var(--safe-top)) calc(12px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(12px + var(--safe-left));
}
.puzzle-header { display: flex; align-items: center; gap: 10px; }
.puzzle-title {
  flex: 1; display: grid; text-align: center; padding: 6px 12px; border-radius: 14px;
  background: linear-gradient(var(--paper), var(--paper-2)); border: 3px solid var(--wood); min-width: 0;
}
.puzzle-title small { color: var(--wood); font-weight: bold; letter-spacing: .08em; text-transform: uppercase; font-size: .72rem; }
.puzzle-title strong { font-family: var(--font-title); font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.puzzle-value {
  display: grid; justify-items: center; min-width: 64px; padding: 4px 10px; border-radius: 14px;
  background: radial-gradient(#ffe48a, var(--gold) 60%, var(--gold-dark)); color: var(--wood-dark); border: 3px solid #fff3d6;
  box-shadow: var(--shadow); line-height: 1;
}
.puzzle-value .value-num { font: bold 1.4rem var(--font-title); }
.puzzle-value small { font-size: .7rem; font-weight: bold; }
.puzzle-value.drop { animation: drop .6s; }
@keyframes drop { 30% { transform: scale(1.3) rotate(-6deg); background: var(--bad); color: #fff; } }

.puzzle-statement {
  display: flex; gap: 12px; align-items: center;
  background: var(--paper); border: 3px solid var(--paper-edge); border-radius: var(--radius);
  padding: 12px 16px; box-shadow: var(--shadow);
}
.puzzle-statement p { margin: 0; line-height: 1.45; font-size: 1.02rem; }
/* L'illustration garde ses proportions (ronde, carrée, paysage…) sans être recadrée. */
.statement-img { flex: none; width: min(34%, 220px); aspect-ratio: var(--ratio, 4 / 3); border-radius: 10px; background-size: contain; }
.statement-img:not(.ph) { border-radius: 0; filter: drop-shadow(0 4px 8px rgba(60, 30, 0, .25)); }
.modal .statement-img { width: 100%; margin-bottom: 8px; }
/* Modèle du taquin : image pleine, cadre bois comme le plateau. */
.statement-model { margin: 0; flex: none; display: grid; justify-items: center; gap: 4px; width: min(34%, 220px); }
.statement-model .statement-img { width: 100%; }
.statement-img.model { border: 4px solid var(--wood-dark); border-radius: 8px; filter: none; box-shadow: var(--shadow); }
.statement-model figcaption { font-size: .8rem; font-weight: bold; color: var(--wood); }
.zoomable { cursor: zoom-in; }
.zoom-img { width: min(100%, 80dvh); aspect-ratio: var(--ratio, 1); margin: 0 auto; background-size: contain; }
.modal:has(.zoom-img) { width: min(720px, 100%); }

.puzzle-host {
  min-height: 0; overflow: auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: rgba(251, 243, 226, .9); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
}
.puzzle-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.puzzle-timer { color: #fff; font-weight: bold; background: rgba(0,0,0,.4); padding: 6px 14px; border-radius: 999px; font-variant-numeric: tabular-nums; }
.puzzle-counter { font-weight: bold; color: var(--wood); }
.puzzle-help { margin: 0; color: var(--ink-soft); font-size: .9rem; }
.submit { min-width: 180px; }

/* Paysage : énoncé à gauche, mini-jeu à droite. */
@media (orientation: landscape) and (min-width: 720px) {
  .puzzle-view { grid-template-columns: minmax(240px, 2fr) 3fr; grid-template-rows: auto 1fr auto; }
  .puzzle-header, .puzzle-footer { grid-column: 1 / -1; }
  .puzzle-statement { flex-direction: column; align-items: stretch; overflow: auto; }
  .statement-img { width: 100%; max-height: 46dvh; }
  .statement-model { width: min(100%, 46dvh); align-self: center; }
}
@media (max-height: 480px) {
  .dlg-box { min-height: 0; padding: 20px 16px 12px; }
  .dlg-text { font-size: 1rem; }
  .puzzle-view { gap: 6px; }
}

/* Indices */
.hints { display: grid; gap: 8px; }
.hint { background: var(--paper-2); border-radius: 10px; padding: 10px 14px; }
.hint summary { font-weight: bold; cursor: pointer; color: var(--wood-dark); }
.hint p { margin: 8px 0 0; }
.hint.locked { opacity: .55; text-align: center; }

/* ---- Mini-jeux ------------------------------------------------------------ */
/* QCM */
.quiz-grid { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 10px; width: min(560px, 100%); }
.quiz-choice {
  display: grid; justify-items: center; gap: 6px; padding: 14px; border-radius: 14px;
  background: #fff; border: 3px solid var(--paper-edge); font-weight: bold; font-size: 1rem; transition: .15s;
}
.quiz-choice.selected { border-color: var(--sky); background: #e5f3ff; transform: scale(1.02); }
.quiz-choice.eliminated { text-decoration: line-through; opacity: .45; }
.quiz-img { width: 100%; aspect-ratio: 4 / 3; border-radius: 8px; }

/* Réponse libre */
.answer-row { display: flex; align-items: center; gap: 8px; justify-content: center; width: min(420px, 100%); }
.answer-input {
  flex: 1; min-width: 0; font: bold 1.2rem var(--font); padding: 12px 14px; border-radius: 12px;
  border: 3px solid var(--paper-edge); background: #fff; color: var(--ink); text-align: center; width: 100%;
}
.answer-input:focus { outline: none; border-color: var(--sky); }
.answer-display {
  min-width: 160px; padding: 10px 16px; border-radius: 12px; background: #1d2a1f; color: #9cf39a;
  font: bold 2rem/1 "Courier New", monospace; text-align: right; letter-spacing: .1em; box-shadow: inset 0 3px 8px rgba(0,0,0,.6);
}
.answer-unit { font-weight: bold; color: var(--ink-soft); }
.keypad { display: grid; grid-template-columns: repeat(3, 64px); gap: 8px; }
.key {
  height: 52px; border-radius: 12px; border: 0; font: bold 1.3rem var(--font);
  background: linear-gradient(#fff, #eadcc0); box-shadow: 0 3px 0 var(--paper-edge);
}
.key:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--paper-edge); }
@media (max-height: 520px) { .keypad { grid-template-columns: repeat(6, 52px); } .key { height: 42px; } }

/* Taquin */
.sliding {
  --size: min(78vmin, 420px);
  position: relative; width: var(--size); height: var(--size); max-width: 100%;
  background: var(--wood-dark); border-radius: 12px; border: 6px solid var(--wood-dark); box-shadow: var(--shadow);
}
.tile {
  position: absolute; top: 0; left: 0; width: calc(100% / var(--n)); height: calc(100% / var(--n));
  border: 2px solid var(--wood-dark); border-radius: 8px; padding: 0;
  background: linear-gradient(#fff6df, #ecd2a0); font: bold calc(var(--size) / var(--n) * .38) var(--font-title); color: var(--wood-dark);
  transition: transform .14s ease-out;
}
.tile.has-img { background-color: #000; }
.tile.in-place:not(.has-img) { background: linear-gradient(#fff9c4, var(--gold)); }
.sliding.solved .tile { border-color: transparent; border-radius: 0; }
@media (orientation: landscape) { .sliding { --size: min(420px, calc(100dvh - 200px)); } }

/* Interrupteurs */
.lights { display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 8px; width: min(78vmin, 380px); }
@media (orientation: landscape) { .lights { width: min(380px, calc(100dvh - 230px)); } }
.light {
  aspect-ratio: 1; border-radius: 50%; border: 3px solid #4a3a2a; background: radial-gradient(#5a4c3c, #2a2018);
  transition: background .15s, box-shadow .15s;
}
.light.on { background: radial-gradient(#fffbe0, var(--gold) 55%, var(--gold-dark)); box-shadow: 0 0 18px var(--gold); }
.lights.solved .light { border-color: var(--good); }

/* Memory */
.memory { display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: 8px; width: min(100%, 440px); }
/* 4 colonnes de cartes 3:4 -> hauteur ≈ largeur × rangées / 3 ; on borne par la hauteur disponible. */
@media (orientation: landscape) { .memory { width: min(100%, 440px, calc((100dvh - 220px) * .72)); } }
.mcard { aspect-ratio: 3 / 4; border: 0; padding: 0; background: none; perspective: 600px; }
.mcard-inner { position: relative; width: 100%; height: 100%; transition: transform .35s; transform-style: preserve-3d; }
.mcard.flipped .mcard-inner { transform: rotateY(180deg); }
.mcard-back, .mcard-front { position: absolute; inset: 0; border-radius: 10px; backface-visibility: hidden; display: grid; place-items: center; }
.mcard-back { background: repeating-linear-gradient(45deg, var(--wood) 0 8px, var(--wood-dark) 8px 16px); border: 3px solid var(--gold); }
.mcard-front { background: #fff; border: 3px solid var(--paper-edge); transform: rotateY(180deg); font-size: clamp(20px, 6vmin, 38px); }
.mcard.matched .mcard-front { border-color: var(--good); background: #eaffea; }
.mcard-img { width: 100%; height: 100%; border-radius: 7px; }

/* Séquence */
.simon { display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: 12px; width: min(70vmin, 320px); }
@media (orientation: landscape) { .simon { width: min(320px, calc(100dvh - 240px)); } }
.pad {
  aspect-ratio: 1; border-radius: 22px; border: 4px solid rgba(0,0,0,.25);
  background: var(--c); filter: brightness(.6) saturate(.8); transition: filter .1s, transform .1s;
}
.pad.lit { filter: brightness(1.25) saturate(1.2); transform: scale(1.05); box-shadow: 0 0 24px var(--c); }
.simon.watching .pad { pointer-events: none; }

/* Remise en ordre */
.order-list { display: grid; gap: 8px; width: min(420px, 100%); }
.order-list.horizontal { grid-auto-flow: column; }
.order-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px;
  background: #fff; border: 3px solid var(--paper-edge); font-weight: bold; text-align: left; transition: .15s;
}
.order-item.selected { border-color: var(--sky); background: #e5f3ff; transform: scale(1.03); }
.order-pos { width: 28px; height: 28px; border-radius: 50%; background: var(--wood); color: #fff; display: grid; place-items: center; flex: none; }
.order-img { width: 48px; height: 48px; border-radius: 8px; flex: none; }

/* ---- Résultats ------------------------------------------------------------ */
.result-wrap { position: relative; z-index: 1; flex: 1; overflow: auto; display: grid; place-items: center; padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom)); }
.result-panel {
  width: min(480px, 100%); text-align: center; background: var(--paper); border: 3px solid var(--paper-edge);
  border-radius: 24px; box-shadow: 0 0 0 5px var(--wood), var(--shadow); padding: 20px; animation: pop .35s;
}
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.result-score { margin: 4px 0; }
.result-score strong { display: inline-block; font: bold 3.2rem var(--font-title); color: var(--wood-dark); font-variant-numeric: tabular-nums; transition: transform .3s cubic-bezier(.2, 1.8, .5, 1); }
.result-score strong.done { transform: scale(1.15); color: var(--gold-dark); text-shadow: 0 0 16px rgba(246, 195, 67, .7); }
.badge.perfect { animation: pop .4s .9s both; }
.result-stats { list-style: none; padding: 0; margin: 8px 0; display: flex; justify-content: center; gap: 14px; color: var(--ink-soft); }
.badge { display: inline-block; margin: 4px; padding: 4px 12px; border-radius: 999px; background: var(--sky); color: #fff; font-weight: bold; }
.badge.gold { background: var(--gold); color: var(--wood-dark); }
.result-panel h3 { margin-top: 12px; font-size: 1rem; }
.result-panel .mini-board { text-align: left; }
.result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 16px; }

/* ---- Pages (classement, profil) ------------------------------------------- */
.page-scene { background: linear-gradient(#2d5f8a, #1d3a5c); overflow: auto; }
.page-header {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-top)) 16px 10px; background: linear-gradient(#2d5f8a, rgba(45,95,138,.9));
}
.page-header h1 { margin: 0; color: #fff; font-size: 1.4rem; text-shadow: 0 2px 4px rgba(0,0,0,.4); }
.page-body { display: grid; gap: 14px; padding: 0 16px calc(24px + var(--safe-bottom)); width: min(720px, 100%); margin: 0 auto; }
.card { background: var(--paper); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: grid; gap: 10px; border: 3px solid var(--paper-edge); }
.card h2, .card h3 { margin: 0; color: var(--wood-dark); }
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { display: grid; text-align: center; background: var(--paper-2); border-radius: 10px; padding: 8px 4px; }
.stat strong { font: bold 1.3rem var(--font-title); }
.stat small { color: var(--ink-soft); }

.tabs { display: flex; gap: 8px; justify-content: center; padding: 0 16px 12px; }
.tab { border: 0; padding: 8px 20px; border-radius: 999px; background: rgba(255,255,255,.2); color: #fff; font-weight: bold; }
.tab.active { background: var(--gold); color: var(--wood-dark); }
.board { list-style: none; margin: 0 auto; padding: 0 16px calc(24px + var(--safe-bottom)); display: grid; gap: 8px; width: min(720px, 100%); }
.board-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-radius: 14px;
  background: var(--paper); box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.board-row.me { outline: 3px solid var(--gold); background: #fff4cf; }
.board-rank { width: 32px; text-align: center; font: bold 1.2rem var(--font-title); color: var(--wood); }
.board-row.top1 .board-rank { color: #d4a017; font-size: 1.5rem; }
.board-row.top2 .board-rank { color: #9aa4ad; font-size: 1.4rem; }
.board-row.top3 .board-rank { color: #b0703a; font-size: 1.3rem; }
.board-name { flex: 1; display: grid; min-width: 0; }
.board-name strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-name small { color: var(--ink-soft); }
.board-score { font: bold 1.1rem var(--font-title); min-width: 64px; text-align: right; white-space: nowrap; }
.board-empty { list-style: none; text-align: center; color: #fff; padding: 24px; display: grid; gap: 12px; justify-items: center; }

.friend-code { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--paper-2); padding: 10px 14px; border-radius: 12px; }
.friend-code strong { font: bold 1.4rem "Courier New", monospace; letter-spacing: .15em; color: var(--wood-dark); flex: 1; }
.friend-code .btn.ghost { color: var(--wood-dark); border-color: var(--paper-edge); }
.friend-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.friend-list li { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 10px; background: var(--paper-2); }

.avatar-picker { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.avatar-choice { border: 0; padding: 3px; border-radius: 50%; background: none; }
.avatar-choice.selected { box-shadow: 0 0 0 3px var(--sky); }
.profile-form { display: grid; gap: 12px; }
.toggle { display: flex; align-items: center; gap: 10px; font-weight: bold; }
.toggle input { width: 22px; height: 22px; accent-color: var(--wood); }

/* Animations réduites (réglage système, ex. « Effets d'animation » désactivés dans Windows) :
   les animations jouent un seul passage instantané. Sans iteration-count: 1, les boucles
   infinies (halo du niveau courant, avatar) tourneraient à 0,01 ms et clignoteraient. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  /* Exceptions voulues : repères de la carte, doux et lents, identiques au mobile. */
  .map-node.current::after { animation-duration: 1.4s !important; animation-iteration-count: infinite !important; }
  .map-me { animation-duration: 1.6s !important; animation-iteration-count: infinite !important; }
  .fx-cloud { animation-duration: var(--dur) !important; animation-iteration-count: infinite !important; }
  .fx-flock { animation-duration: var(--dur) !important; }
  .fx-wings { animation-duration: var(--flap) !important; animation-iteration-count: infinite !important; }
  .fx-firefly { animation-duration: var(--dur), var(--blink) !important; animation-iteration-count: infinite !important; }
  .fx-shadow, .fx-glint { animation-duration: var(--dur) !important; animation-iteration-count: infinite !important; }
}
