:root {
  --pink: #ff8fc8;
  --pink-dark: #e46aa9;
  --pink-soft: #ffe0f1;
  --lilac: #b18cf0;
  --lilac-dark: #8f68d6;
  --lilac-soft: #f1e7ff;
  --sky: #8ccfff;
  --sky-soft: #e2f4ff;
  --mint: #7fdcb6;
  --mint-dark: #46b88b;
  --gold: #ffd35c;
  --ink: #4a3a6b;
  --ink-soft: #7a6a99;
  --white: #fff;
  --shadow: 0 10px 24px rgba(74, 58, 107, .16);
  --font: 'Fredoka', 'Baloo 2', 'Nunito', system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(165deg, #ffe4f4 0%, #f1e7ff 45%, #e2f4ff 100%);
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}
button { font-family: inherit; color: inherit; }
svg { display: block; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.screen {
  flex: 1; position: relative; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  overflow: hidden;
}

/* ---------- Décor ---------- */
.cloud {
  position: absolute; background: #fff; border-radius: 999px; opacity: .85;
  filter: drop-shadow(0 6px 10px rgba(143, 104, 214, .12));
  animation: drift 40s linear infinite;
}
.cloud::before, .cloud::after { content: ''; position: absolute; background: #fff; border-radius: 50%; }
.cloud::before { width: 55%; height: 140%; left: 12%; top: -60%; }
.cloud::after { width: 40%; height: 110%; right: 14%; top: -40%; }
@keyframes drift { from { transform: translateX(-12vw); } to { transform: translateX(112vw); } }

/* ---------- Boutons ---------- */
.btn {
  border: none; border-radius: 999px; cursor: pointer;
  padding: 18px 40px; font-size: clamp(24px, 4vw, 40px); font-weight: 700;
  color: #fff; background: var(--pink);
  box-shadow: 0 8px 0 var(--pink-dark), var(--shadow);
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--pink-dark), var(--shadow); }
.btn.lilac { background: var(--lilac); box-shadow: 0 8px 0 var(--lilac-dark), var(--shadow); }
.btn.small { padding: 10px 22px; font-size: 20px; box-shadow: 0 5px 0 var(--pink-dark); }
.btn.small.lilac { box-shadow: 0 5px 0 var(--lilac-dark); }
.btn.ghost { background: #fff; color: var(--ink); box-shadow: 0 5px 0 #d9cdee; }

.icon-btn {
  width: 64px; height: 64px; border-radius: 50%; border: none; cursor: pointer;
  background: #fff; box-shadow: 0 5px 0 #d9cdee, var(--shadow);
  display: grid; place-items: center; padding: 0; flex: none;
}
.icon-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #d9cdee; }
.icon-btn svg { width: 60%; height: 60%; }

/* ---------- Accueil ---------- */
.home-title { font-size: clamp(30px, 5.5vw, 60px); font-weight: 700; margin: 0; text-align: center;
  color: var(--lilac-dark); text-shadow: 0 4px 0 #fff; z-index: 1; }
.home-mascot { width: min(46vh, 52vw); z-index: 1; animation: float 3.2s ease-in-out infinite; cursor: pointer; }
.home-play {
  width: clamp(120px, 20vmin, 180px); height: clamp(120px, 20vmin, 180px); border-radius: 50%;
  border: none; cursor: pointer; z-index: 1;
  background: radial-gradient(circle at 35% 30%, #ffb3dc, var(--pink) 60%);
  box-shadow: 0 10px 0 var(--pink-dark), var(--shadow);
  display: grid; place-items: center; animation: pulse 2s ease-in-out infinite;
}
.home-play:active { transform: translateY(8px); box-shadow: 0 2px 0 var(--pink-dark); }
.home-play svg { width: 48%; height: 48%; margin-left: 8%; }
.home-row { display: flex; align-items: center; gap: 28px; z-index: 1; margin-top: 8px; }
.corner { position: absolute; z-index: 5; }
.corner.tl { top: max(14px, env(safe-area-inset-top)); left: 14px; }
.corner.tr { top: max(14px, env(safe-area-inset-top)); right: 14px; }
.parent-gate { position: relative; width: 52px; height: 52px; opacity: .55; }
.parent-gate .ring { position: absolute; inset: -6px; pointer-events: none; }
.parent-gate .ring circle { transition: stroke-dashoffset linear; }

.map { display: flex; gap: clamp(6px, 1.4vw, 16px); align-items: center; z-index: 1; margin-top: 14px; flex-wrap: wrap; justify-content: center; }
.island {
  width: clamp(38px, 6vmin, 56px); height: clamp(38px, 6vmin, 56px); border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: clamp(16px, 2.6vmin, 24px);
  background: #fff; color: #cbbde3; border: 4px dashed #d9cdee;
}
.island.done { background: var(--mint); color: #fff; border: 4px solid var(--mint-dark); }
.island.current { background: var(--gold); color: var(--ink); border: 4px solid #f0b400; transform: scale(1.25); animation: pulse 1.6s ease-in-out infinite; }

/* ---------- Séance ---------- */
.topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 14px 0;
}
.dots { display: flex; gap: 10px; }
.dot { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 3px solid #d9cdee; }
.dot.on { background: var(--gold); border-color: #f0b400; }
.dot.now { background: var(--pink-soft); border-color: var(--pink); animation: pulse 1.4s infinite; }

.prompt { display: flex; align-items: center; gap: 12px; max-width: 92vw; z-index: 2; margin-top: 64px; }
.prompt .mini-mascot { width: clamp(80px, 13vmin, 130px); flex: none; }
.bubble {
  background: #fff; border-radius: 26px; padding: 14px 22px; box-shadow: var(--shadow);
  font-size: clamp(20px, 3.2vmin, 30px); font-weight: 600; position: relative; min-height: 1.2em;
}
.bubble::before {
  content: ''; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  border: 12px solid transparent; border-right-color: #fff; border-left: 0;
}
.stage-area { flex: 1; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; position: relative; }

/* Choix (bulles) */
.choices { display: flex; flex-wrap: wrap; gap: clamp(16px, 3vw, 40px); justify-content: center; align-items: center; max-width: 96vw; }
.choice {
  border: 6px solid var(--lilac); background: #fff; cursor: pointer;
  width: clamp(110px, 19vmin, 190px); aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center; padding: 10%;
  font-size: clamp(60px, 11vmin, 120px); font-weight: 700; line-height: 1; color: var(--ink);
  box-shadow: 0 8px 0 #d9cdee, var(--shadow);
  animation: appear .45s cubic-bezier(.3, 1.6, .6, 1) backwards;
}
.choice { position: relative; }
.choice > svg { position: absolute; inset: 9%; width: 82%; height: 82%; }
.choice.card { border-radius: 30px; aspect-ratio: auto; width: auto; min-width: 200px; padding: 18px 28px; font-size: clamp(36px, 6.5vmin, 64px); letter-spacing: .06em; }
.choice.plain { border-color: transparent; background: transparent; box-shadow: none; }
.choice:active { transform: scale(.94); }
.choice.wrong { animation: wiggle .5s; border-color: #ffb0b0; }
.choice.dim { opacity: .3; pointer-events: none; filter: grayscale(.6); }
.choice.right { animation: win .7s cubic-bezier(.3, 1.6, .6, 1); border-color: var(--mint-dark); background: #e7fbf2; }
.choice.hint { animation: glow 1.1s ease-in-out infinite; border-color: var(--gold); }

/* Comptage */
.count-field { display: flex; flex-wrap: wrap; gap: clamp(14px, 3vw, 34px); justify-content: center; align-items: center; max-width: 90vw; }
.count-item { width: clamp(90px, 15vmin, 150px); aspect-ratio: 1; position: relative; cursor: pointer; animation: appear .45s cubic-bezier(.3, 1.6, .6, 1) backwards; }
.count-item.counted { animation: bump .45s; }
.count-item.counted::after {
  content: attr(data-n); position: absolute; right: -6px; top: -8px; width: 44%; aspect-ratio: 1;
  border-radius: 50%; background: var(--pink); color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: clamp(20px, 3.6vmin, 34px); box-shadow: 0 3px 0 var(--pink-dark);
}

/* Prénom à remettre dans l'ordre */
.slots { display: flex; gap: clamp(6px, 1.2vw, 14px); flex-wrap: nowrap; }
.slot {
  width: clamp(54px, 9.5vmin, 96px); aspect-ratio: .82; border-radius: 18px; border: 4px dashed #cbbde3;
  display: grid; place-items: center; font-size: clamp(38px, 7vmin, 72px); font-weight: 700; color: #e3d9f3; background: rgba(255, 255, 255, .6);
}
.slot.filled { border: 4px solid var(--mint-dark); background: #fff; color: var(--ink); animation: bump .4s; }
.slot.next { border-color: var(--pink); }
.tiles { display: flex; gap: clamp(10px, 2vw, 22px); flex-wrap: wrap; justify-content: center; max-width: 94vw; }
.tile {
  width: clamp(70px, 12vmin, 116px); aspect-ratio: 1; border-radius: 24px; border: none; cursor: pointer;
  font-size: clamp(44px, 8vmin, 80px); font-weight: 700; color: #fff; background: var(--lilac);
  box-shadow: 0 7px 0 var(--lilac-dark); animation: appear .45s cubic-bezier(.3, 1.6, .6, 1) backwards;
}
.tile.used { visibility: hidden; }
.tile.wrong { animation: wiggle .5s; }
.tile.hint { animation: glow 1.1s infinite; }

/* Tracé au doigt */
.trace-box { display: flex; justify-content: center; align-items: center; }
.trace-box svg { height: min(58vh, 66vw); width: auto; max-width: 92vw; touch-action: none; overflow: visible; }
.trace-box .track { fill: none; stroke: #fff; stroke-width: 30; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 4px 0 #e3d9f3); }
.trace-box .guide { fill: none; stroke: #d2c2f0; stroke-width: 3.4; stroke-linecap: round; stroke-dasharray: 0 8; }
.trace-box .guide.current { stroke: #b18cf0; }
.trace-box .ink { fill: none; stroke-width: 20; stroke-linecap: round; stroke-linejoin: round; }
.trace-box .head polygon { fill: #ffd35c; stroke: #f0a800; stroke-width: 2; stroke-linejoin: round; }
.trace-box .head .halo { fill: rgba(255, 211, 92, .4); animation: halo 1.2s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.trace-box .arrow path { fill: none; stroke: #ff8fc8; stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; }
.trace-box .arrow { transition: opacity .3s; }
.trace-box.done .head, .trace-box.done .arrow, .trace-box.done .guide { display: none; }
.trace-box.done svg { animation: win .7s cubic-bezier(.3, 1.6, .6, 1); }
@keyframes halo { 0%, 100% { transform: scale(1); opacity: .9 } 50% { transform: scale(1.7); opacity: .25 } }

/* Relier chiffre et quantité */
.match-board {
  position: relative; width: min(94vw, 980px); height: min(62vh, 580px);
  display: grid; grid-template-columns: minmax(90px, .7fr) 1.6fr; column-gap: clamp(56px, 15vw, 220px);
}
.match-col { display: flex; flex-direction: column; justify-content: center; gap: clamp(10px, 2vh, 20px); min-height: 0; }
.match-card {
  position: relative; flex: 1 1 0; min-height: 0; max-height: 170px;
  display: flex; align-items: center; justify-content: center;
  background: #fff; border: 5px solid var(--lilac); border-radius: 26px; cursor: pointer; touch-action: none;
  box-shadow: 0 7px 0 #d9cdee, var(--shadow); transition: transform .12s, border-color .12s;
  animation: appear .45s cubic-bezier(.3, 1.6, .6, 1) backwards;
}
.match-digit { font-size: clamp(48px, 9vmin, 100px); font-weight: 700; line-height: 1; }
.match-group { padding: 8px 14px; }
.match-digit::after, .match-group::before {
  content: ''; position: absolute; top: 50%; width: 20px; height: 20px; margin-top: -10px;
  border-radius: 50%; background: var(--ink); border: 4px solid #fff;
}
.match-digit::after { right: -14px; }
.match-group::before { left: -14px; }
.match-items {
  display: grid; grid-template-columns: repeat(var(--cols), auto); grid-template-rows: repeat(var(--rows), 1fr);
  gap: 4px; justify-content: center; align-content: center; width: 100%; height: 100%; pointer-events: none;
}
.match-items svg { height: 100%; width: auto; aspect-ratio: 1; max-height: 78px; }
.match-items svg.flash { animation: bump .45s; }
.match-card.selected { border-color: var(--pink); transform: scale(1.05); }
.match-card.done { border-color: var(--mint-dark); background: #e7fbf2; cursor: default; }
.match-card.wrong { animation: wiggle .5s; }
.match-card.hint { animation: glow 1.1s ease-in-out infinite; border-color: var(--gold); }
.match-lines { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.match-lines svg { position: absolute; inset: 0; overflow: visible; }
.match-lines line { stroke-width: 9; stroke-linecap: round; }
.match-lines .temp { stroke: var(--pink); stroke-dasharray: 2 14; visibility: hidden; }

/* Bulles */
.bubbles-field { position: absolute; inset: 0; overflow: hidden; }
.soap {
  position: absolute; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  font-weight: 700; color: var(--ink); border: none; padding: 0;
  background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, .95) 0 12%, rgba(255, 255, 255, .35) 30%, rgba(177, 140, 240, .28) 70%, rgba(255, 143, 200, .45) 100%);
  box-shadow: inset 0 0 18px rgba(255, 255, 255, .8), 0 6px 14px rgba(143, 104, 214, .18);
}
.soap.popped { animation: popout .35s forwards; pointer-events: none; }

/* Récompense */
.reward-sticker { width: min(44vmin, 360px); animation: sticker 1s cubic-bezier(.3, 1.6, .6, 1) both; filter: drop-shadow(0 12px 18px rgba(74, 58, 107, .25)); }
.reward-title { font-size: clamp(32px, 6vmin, 60px); font-weight: 700; color: var(--pink-dark); margin: 10px 0; text-align: center; }

/* Confettis */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 14px; height: 18px; border-radius: 4px; animation: fall linear forwards; }

/* Mascotte */
.mascot-happy { animation: hop .7s cubic-bezier(.3, 1.6, .6, 1); }
.mascot-sad { animation: tilt .8s ease-in-out; }

/* Repeat */
.repeat-btn { width: 56px; height: 56px; }

/* ---------- Animations ---------- */
@keyframes float { 0%, 100% { transform: translateY(0) } 50% { transform: translateY(-14px) } }
@keyframes pulse { 0%, 100% { transform: scale(1) } 50% { transform: scale(1.06) } }
@keyframes appear { from { transform: scale(0); opacity: 0 } to { transform: scale(1); opacity: 1 } }
@keyframes wiggle { 0%, 100% { transform: translateX(0) } 20% { transform: translateX(-14px) rotate(-6deg) } 40% { transform: translateX(12px) rotate(5deg) } 60% { transform: translateX(-8px) } 80% { transform: translateX(5px) } }
@keyframes win { 0% { transform: scale(1) } 40% { transform: scale(1.25) rotate(-4deg) } 70% { transform: scale(.95) } 100% { transform: scale(1.08) } }
@keyframes glow { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 211, 92, .9), 0 8px 0 #d9cdee } 50% { box-shadow: 0 0 0 22px rgba(255, 211, 92, 0), 0 8px 0 #d9cdee; transform: scale(1.08) } }
@keyframes bump { 0% { transform: scale(1) } 40% { transform: scale(1.22) } 100% { transform: scale(1) } }
@keyframes hop { 0%, 100% { transform: translateY(0) } 40% { transform: translateY(-26px) rotate(-6deg) } }
@keyframes tilt { 0%, 100% { transform: rotate(0) } 30% { transform: rotate(-8deg) } 60% { transform: rotate(5deg) } }
@keyframes popout { to { transform: scale(1.6); opacity: 0 } }
@keyframes sticker { 0% { transform: scale(0) rotate(-200deg) } 100% { transform: scale(1) rotate(0) } }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg) } }

/* ---------- Espace parent ---------- */
.parent { justify-content: flex-start; overflow-y: auto; background: #faf7ff; align-items: stretch; padding-top: max(20px, env(safe-area-inset-top)); }
.parent-inner { width: min(880px, 100%); margin: 0 auto; display: flex; flex-direction: column; gap: 18px; padding-bottom: 40px; }
.parent h1 { margin: 0; font-size: 30px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel { background: #fff; border-radius: 20px; padding: 18px 20px; box-shadow: 0 4px 14px rgba(74, 58, 107, .08); }
.panel h2 { margin: 0 0 12px; font-size: 22px; }
.panel p { margin: 6px 0; color: var(--ink-soft); font-size: 17px; }
.stage-pick { display: flex; flex-wrap: wrap; gap: 10px; }
.stage-pick button { min-width: 54px; height: 54px; border-radius: 14px; border: 3px solid #e3d9f3; background: #fff; font-size: 20px; font-weight: 700; cursor: pointer; }
.stage-pick button.on { background: var(--gold); border-color: #f0b400; }
.skills { display: grid; grid-template-columns: repeat(auto-fill, minmax(74px, 1fr)); gap: 10px; }
.skill { border-radius: 14px; padding: 8px; text-align: center; background: #f6f2fd; font-size: 15px; }
.skill b { display: block; font-size: 26px; }
.bar { height: 8px; border-radius: 4px; background: #e8e0f5; margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--mint-dark); }
.field { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 0; border-bottom: 1px solid #f0eaf9; font-size: 18px; flex-wrap: wrap; }
.field:last-child { border-bottom: none; }
.field select, .field input[type=text] { font: inherit; font-size: 18px; padding: 8px 12px; border-radius: 12px; border: 2px solid #e3d9f3; background: #fff; color: var(--ink); max-width: 100%; }
.seg { display: inline-flex; border-radius: 12px; overflow: hidden; border: 2px solid #e3d9f3; }
.seg button { border: none; background: #fff; padding: 8px 14px; font-size: 17px; cursor: pointer; }
.seg button.on { background: var(--lilac); color: #fff; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 15px; color: var(--ink-soft); }

/* ---------- Album ---------- */
.album-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(90px, 14vmin, 140px), 1fr)); gap: 16px; width: min(1000px, 94vw); margin-top: 80px; overflow-y: auto; padding: 10px; }
.album-slot { aspect-ratio: 1; border-radius: 24px; background: rgba(255, 255, 255, .7); border: 4px dashed #e3d9f3; display: grid; place-items: center; padding: 10%; }
.album-slot.has { background: #fff; border: 4px solid #fff; box-shadow: var(--shadow); }
.album-slot .shadow-shape { opacity: .12; filter: grayscale(1); }
