@font-face { font-family: 'Baloo 2'; font-weight: 600; font-display: swap; src: url(../fonts/baloo-2-latin-600-normal.woff2) format('woff2'); }
@font-face { font-family: 'Baloo 2'; font-weight: 800; font-display: swap; src: url(../fonts/baloo-2-latin-800-normal.woff2) format('woff2'); }
@font-face { font-family: 'Baloo Bhaijaan 2'; font-weight: 700; font-display: swap; src: url(../fonts/baloo-bhaijaan-2-arabic-700-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF; }
@font-face { font-family: 'Baloo Bhaijaan 2'; font-weight: 800; font-display: swap; src: url(../fonts/baloo-bhaijaan-2-arabic-800-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+FB50-FDFF, U+FE70-FEFF; }

:root {
  --ink: #2b2140; --violet: #8E6CCF; --sun: #FFD93D; --sky1: #BFE6FF; --sky2: #FFF3D6;
  --vvh: 100dvh; --kb: 0px;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  --radius: 28px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  touch-action: manipulation; -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
body {
  position: fixed; inset: 0;
  font-family: 'Baloo 2', 'Baloo Bhaijaan 2', ui-rounded, 'Arial Rounded MT Bold', system-ui, sans-serif;
  color: var(--ink); background: linear-gradient(180deg, var(--sky1) 0%, #E4F4FF 55%, var(--sky2) 100%);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 4px solid var(--violet); outline-offset: 4px; }
svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* ---------- Décor ---------- */
.sky { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.cloud { position: absolute; background: #fff; border-radius: 999px; opacity: .85; width: 140px; height: 44px; animation: drift 40s linear infinite; }
.cloud::before, .cloud::after { content: ''; position: absolute; background: #fff; border-radius: 50%; }
.cloud::before { width: 64px; height: 64px; left: 22px; top: -30px; }
.cloud::after { width: 48px; height: 48px; left: 70px; top: -20px; }
.c1 { top: 12%; left: -160px; } .c2 { top: 28%; left: -160px; animation-delay: -18s; transform: scale(.7); animation-duration: 55s; }
.c3 { top: 6%; left: -160px; animation-delay: -32s; animation-duration: 48s; }
.hill { position: absolute; bottom: -18vh; border-radius: 50%; }
.h1 { width: 90vw; height: 38vh; left: -20vw; background: #B6E7A6; }
.h2 { width: 100vw; height: 34vh; right: -30vw; background: #9EDB8C; }
@keyframes drift { to { transform: translateX(calc(100vw + 320px)); } }

/* ---------- Écrans ---------- */
.screen {
  position: absolute; left: 0; right: 0; top: 0; height: var(--vvh);
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 12px) calc(var(--safe-b) + 10px) calc(var(--safe-l) + 12px);
  display: none; flex-direction: column; align-items: center;
}
.screen.active { display: flex; animation: screenIn .35s ease both; }
@keyframes screenIn { from { opacity: 0; transform: scale(.97); } }

/* Splash */
#splash { justify-content: center; gap: 2vh; }
.logo-word { font-weight: 800; font-size: clamp(44px, 11vw, 96px); line-height: 1; letter-spacing: -1px; text-align: center;
  color: #fff; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 6px 0 var(--ink); }
.logo-word span:first-child { color: var(--sun); }
.logo-word span:last-child { color: #fff; }
.owl { width: min(46vw, 34vh, 260px); aspect-ratio: 1; }
.owl.small { width: 64px; cursor: pointer; }
.owl.tiny { width: 70px; cursor: pointer; }
.float { animation: float 3s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-12px) rotate(-2deg); } }
.play-btn { display: flex; align-items: center; gap: 12px; padding: 14px 40px 14px 24px; border-radius: 999px;
  background: #FF9F45; border: 4px solid var(--ink); box-shadow: 0 8px 0 var(--ink); font-weight: 800; font-size: 34px; color: #fff;
  -webkit-text-stroke: 1.5px var(--ink); paint-order: stroke fill; animation: pulse 1.6s ease-in-out infinite; }
.play-btn svg { width: 56px; height: 56px; }
.play-btn:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--ink); }
@keyframes pulse { 50% { transform: scale(1.06); } }

/* Barre du haut */
.bar { width: 100%; max-width: 1100px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex: 0 0 auto; z-index: 2; }
.stars { display: flex; align-items: center; gap: 6px; background: #fff; border: 3px solid var(--ink); border-radius: 999px; padding: 4px 16px 4px 6px; box-shadow: 0 4px 0 var(--ink); }
.stars svg { width: 38px; height: 38px; }
.stars b { font-size: 26px; font-weight: 800; min-width: 1.2em; text-align: center; }
.icon-btn { position: relative; width: 60px; height: 60px; padding: 9px; border-radius: 20px; background: #fff; border: 3px solid var(--ink); box-shadow: 0 5px 0 var(--ink); flex: 0 0 auto; }
.icon-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.parent { width: 48px; height: 48px; padding: 8px; opacity: .75; }
.parent .ring { position: absolute; inset: -7px; border-radius: 24px; border: 5px solid var(--violet); clip-path: inset(0 100% 0 0); }
.parent.holding .ring { animation: ring 2s linear forwards; }
@keyframes ring { to { clip-path: inset(0 0 0 0); } }

/* Niveaux */
.levels { display: flex; gap: 10px; margin: 12px 0 8px; flex: 0 0 auto; }
.lvl { display: flex; align-items: center; gap: 6px; background: #fff; border: 3px solid var(--ink); border-radius: 22px; padding: 4px 14px 4px 6px; box-shadow: 0 4px 0 var(--ink); opacity: .7; transition: transform .2s, opacity .2s; }
.lvl.on { background: var(--sun); opacity: 1; transform: scale(1.07); }
.lvl:active { transform: translateY(3px); }
.lvl-owl { width: 44px; height: 44px; display: grid; place-items: center; }
.lvl-owl svg { width: calc(44px * var(--o)); height: calc(44px * var(--o)); }
.lvl-txt { display: flex; flex-direction: column; line-height: 1; text-align: start; white-space: nowrap; }
.lvl-txt b { font-size: 19px; } .lvl-txt small { font-size: 13px; font-weight: 600; opacity: .75; }

/* Tuiles des jeux */
.tiles { flex: 1 1 auto; width: 100%; max-width: 1100px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; padding: 8px 2px 6px; overflow-y: auto; -webkit-overflow-scrolling: touch; align-content: start; }
@media (min-aspect-ratio: 4/3) { .tiles { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 700px) and (max-aspect-ratio: 4/3) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tile { background: var(--c); border: 4px solid var(--ink); border-radius: var(--radius); box-shadow: 0 7px 0 var(--ink); padding: 10px 8px 6px;
  display: flex; flex-direction: column; align-items: center; animation: popIn .45s cubic-bezier(.3,1.6,.5,1) both; }
.tile:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--ink); }
.tile-art { width: 100%; aspect-ratio: 1.25; max-height: 22vh; background: rgba(255,255,255,.55); border-radius: 20px; padding: 6px; }
.tile-name { font-weight: 800; font-size: clamp(17px, 2.6vw, 24px); color: #fff; -webkit-text-stroke: 1.2px var(--ink); paint-order: stroke fill; margin-top: 4px; line-height: 1.15; text-align: center; }
@keyframes popIn { from { opacity: 0; transform: scale(.4); } }

/* ---------- Jeu ---------- */
#game { --accent: #9B6CFF; }
#game::before { content: ''; position: fixed; inset: 0; background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%); pointer-events: none; }
.game-title { display: flex; align-items: center; gap: 8px; background: #fff; border: 3px solid var(--ink); border-radius: 999px; padding: 4px 14px 4px 6px; box-shadow: 0 4px 0 var(--ink); min-width: 0; }
#gameIcon { width: 42px; height: 42px; flex: 0 0 auto; }
#gameName { font-size: 21px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dots { display: flex; gap: 3px; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: #ddd; border: 1.5px solid var(--ink); }
.dots i.on { background: var(--accent); }
@media (max-width: 430px) { #gameName { display: none; } }

.stage { flex: 1 1 auto; width: 100%; max-width: 1100px; display: flex; flex-direction: column; align-items: center; justify-content: space-evenly; gap: 12px; min-height: 0; position: relative; }
.stage.locked { pointer-events: none; }
.game-foot { width: 100%; max-width: 1100px; display: flex; justify-content: space-between; align-items: flex-end; flex: 0 0 auto; }
.speak { width: 68px; height: 68px; background: var(--sun); }

.choices { display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(10px, 3vw, 26px); }
.choice { width: clamp(92px, min(26vw, 22vh), 190px); aspect-ratio: 1; padding: 12px; background: #fff; border: 4px solid var(--ink); border-radius: var(--radius); box-shadow: 0 7px 0 var(--ink); animation: popIn .45s cubic-bezier(.3,1.6,.5,1) both; }
.choice:nth-child(2) { animation-delay: .06s; } .choice:nth-child(3) { animation-delay: .12s; } .choice:nth-child(4) { animation-delay: .18s; } .choice:nth-child(5) { animation-delay: .24s; }
.choice:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--ink); }
.choice.num { display: grid; place-items: center; background: var(--accent); }
.choice.num span { font-size: clamp(48px, 10vw, 90px); font-weight: 800; color: #fff; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; line-height: 1; }
.numbers .choice { width: clamp(84px, min(24vw, 16vh), 150px); }

/* Mémoire */
.mem-grid { display: grid; gap: 12px; justify-content: center; }
.card { width: var(--size); height: var(--size); perspective: 800px; animation: popIn .4s cubic-bezier(.3,1.6,.5,1) both; }
.card-inner { position: relative; width: 100%; height: 100%; transition: transform .45s cubic-bezier(.4,1.4,.5,1); transform-style: preserve-3d; }
.card.flipped .card-inner { transform: rotateY(180deg); }
.card-face { position: absolute; inset: 0; border: 4px solid var(--ink); border-radius: 22px; box-shadow: 0 6px 0 var(--ink); backface-visibility: hidden; -webkit-backface-visibility: hidden; padding: 12%; }
.card-back { background: repeating-linear-gradient(45deg, #9B6CFF 0 14px, #A97EFF 14px 28px); }
.card-back svg { opacity: .9; }
.card-front { background: #fff; transform: rotateY(180deg); }
.card.matched .card-front { background: #E6FFE3; animation: bounce .5s; }
.card.matched .card-inner { transform: rotateY(180deg) scale(.94); }

/* Ombres */
.shadow-box { width: min(48vw, 34vh, 280px); aspect-ratio: 1; background: rgba(255,255,255,.7); border: 4px dashed var(--ink); border-radius: 50%; padding: 6%; }
.shadow-box .art { width: 100%; height: 100%; transition: filter .6s, opacity .6s; }
.silhouette { filter: brightness(0); opacity: .82; }

/* Compter */
.count-field { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.count-item { position: relative; width: var(--size); height: var(--size); transform: rotate(var(--rot)); animation: popIn .45s cubic-bezier(.3,1.6,.5,1) both; }
.count-item.counted { animation: bounce .4s; }
.count-item.counted svg { opacity: .55; }
.badge { position: absolute; top: -4px; inset-inline-end: -4px; width: 40%; aspect-ratio: 1; display: grid; place-items: center; border-radius: 50%; background: #4D96FF; color: #fff; font-weight: 800; font-size: calc(var(--size) * .26); border: 3px solid var(--ink); animation: popIn .3s both; }

/* Couleurs */
.balloons .choice.balloon { background: transparent; border: 0; box-shadow: none; padding: 0; width: clamp(80px, min(22vw, 30vh), 180px); aspect-ratio: .8; animation: bob 2.4s ease-in-out infinite; }
.balloon.popped { animation: popBalloon .45s forwards !important; }
@keyframes bob { 50% { transform: translateY(-14px) rotate(3deg); } }
@keyframes popBalloon { 40% { transform: scale(1.3); } 100% { transform: scale(0); opacity: 0; } }

/* Suites */
.seq-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; background: rgba(255,255,255,.75); border: 4px solid var(--ink); border-radius: 26px; padding: 12px; }
.seq-item { width: var(--size); height: var(--size); animation: popIn .4s both; }
.seq-item.slot { display: grid; place-items: center; border: 4px dashed var(--ink); border-radius: 18px; background: #fff; animation: pulse 1.2s ease-in-out infinite; }
.seq-item.slot span { font-size: calc(var(--size) * .6); font-weight: 800; color: var(--accent); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; }
.seq-item.slot.filled { border-style: solid; animation: bounce .5s; }

/* Tailles */
.sizes { align-items: flex-end; }
.choice.size { display: flex; align-items: flex-end; justify-content: center; width: clamp(96px, min(28vw, 30vh), 220px); }
.choice.size svg { width: calc(100% * var(--s)); height: calc(100% * var(--s)); }

/* Cris */
.speaker-big { width: min(36vw, 24vh, 170px); aspect-ratio: 1; padding: 22px; border-radius: 50%; background: var(--accent); border: 4px solid var(--ink); box-shadow: 0 7px 0 var(--ink); animation: pulse 1.4s ease-in-out infinite; }

/* ---------- Animations de retour ---------- */
.bounce { animation: bounce .5s !important; }
.wobble { animation: wobble .5s !important; }
.jump { animation: jump .7s !important; }
.wiggle { animation: wiggle .6s !important; }
@keyframes bounce { 30% { transform: scale(1.18); } 60% { transform: scale(.94); } }
@keyframes wobble { 20%, 60% { transform: translateX(-10px) rotate(-4deg); } 40%, 80% { transform: translateX(10px) rotate(4deg); } }
@keyframes jump { 40% { transform: translateY(-40px) rotate(-8deg); } 70% { transform: translateY(0) scale(1.1, .9); } }
@keyframes wiggle { 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }

#fx { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
.confetti { position: absolute; top: -20px; width: 12px; height: 18px; border-radius: 3px; animation: fall 1.6s ease-in forwards; }
@keyframes fall { to { transform: translate(var(--dx), 110vh) rotate(var(--r)); } }
.big-star { position: absolute; left: 50%; top: 45%; width: 180px; height: 180px; margin: -90px 0 0 -90px; animation: starFly 1.3s cubic-bezier(.3,1.5,.5,1) forwards; }
@keyframes starFly { 0% { transform: scale(0) rotate(-90deg); } 40% { transform: scale(1.1) rotate(0); } 70% { transform: scale(1); opacity: 1; } 100% { transform: translate(30vw, -45vh) scale(.2); opacity: 0; } }

/* ---------- Espace parents + clavier ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: none; align-items: flex-end; justify-content: center; background: rgba(43,33,64,.45);
  padding: 0 0 var(--kb) 0; transition: padding .25s ease; }
.modal.open { display: flex; animation: screenIn .25s both; }
.sheet { width: min(560px, 100%); max-height: calc(var(--vvh) - var(--safe-t) - 12px); overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  background: #fff; border: 4px solid var(--ink); border-bottom: 0; border-radius: 30px 30px 0 0; padding: 18px 20px calc(var(--safe-b) + 18px);
  display: flex; flex-direction: column; gap: 14px; -webkit-user-select: text; user-select: text; animation: sheetUp .3s cubic-bezier(.3,1.3,.5,1) both; }
@keyframes sheetUp { from { transform: translateY(100%); } }
body.kb-open .sheet { border-radius: 30px; border-bottom: 4px solid var(--ink); padding-bottom: 18px; }
.sheet h2 { margin: 0; font-size: 26px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 800; font-size: 17px; }
.field input { font: inherit; font-size: 18px; /* ≥16px : évite le zoom auto d'iOS */ font-weight: 600; padding: 12px 14px; border: 3px solid var(--ink); border-radius: 14px; outline: none; background: #F7F3FF; color: var(--ink); -webkit-user-select: text; user-select: text; touch-action: manipulation; }
.field input:focus { border-color: var(--violet); box-shadow: 0 0 0 4px rgba(142,108,207,.25); }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button { padding: 8px 14px; border-radius: 999px; border: 3px solid var(--ink); font-weight: 800; font-size: 16px; background: #fff; }
.seg button.on { background: var(--sun); }
.switch { display: flex; align-items: center; justify-content: space-between; font-weight: 800; font-size: 18px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i { width: 58px; height: 34px; border-radius: 999px; background: #ccc; border: 3px solid var(--ink); position: relative; transition: background .2s; }
.switch i::after { content: ''; position: absolute; top: 2px; inset-inline-start: 2px; width: 24px; height: 24px; border-radius: 50%; background: #fff; border: 2px solid var(--ink); transition: transform .2s; }
.switch input:checked + i { background: #6BCB77; }
.switch input:checked + i::after { transform: translateX(24px); }
[dir=rtl] .switch input:checked + i::after { transform: translateX(-24px); }
.ghost { padding: 10px; border: 3px dashed var(--ink); border-radius: 14px; font-weight: 800; }
.primary { padding: 12px; border: 3px solid var(--ink); border-radius: 16px; background: var(--violet); color: #fff; font-weight: 800; font-size: 20px; box-shadow: 0 4px 0 var(--ink); }
.note { margin: 0; font-size: 14px; opacity: .75; }

[dir=rtl] body, [dir=rtl] { font-family: 'Baloo Bhaijaan 2', 'Baloo 2', system-ui, sans-serif; }
[dir=rtl] .big-star { animation-name: starFlyRtl; }
@keyframes starFlyRtl { 0% { transform: scale(0) rotate(90deg); } 40% { transform: scale(1.1); } 70% { transform: scale(1); opacity: 1; } 100% { transform: translate(-30vw, -45vh) scale(.2); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .cloud, .float, .play-btn, .balloon, .speaker-big, .seq-item.slot { animation: none !important; } }
