/* ==========================================
   css/scene.css - La scène : décor par chapitre, sol, bâtiments sur l'horizon, fourmis, Gelly et son visage,
   point sucré, météo. (HUD, dock, boutique : style.css)
   ========================================== */

#scene { position: fixed; inset: 0; z-index: 0; overflow: hidden; background: var(--bg-0); }
#bg-sky, #bg-image, #bg-decor, #night { position: absolute; inset: 0; pointer-events: none; }
#bg-sky { transition: background 1.5s; }
#bg-image { background-size: cover; background-position: center bottom; opacity: 0; transform: scale(1.04); transition: opacity 0.45s, transform 0.2s linear; }
#bg-image.has-art { opacity: 1; } #bg-image.fading { opacity: 0 !important; }
#bg-image.has-art ~ #bg-decor { display: none; }
#scene::after { content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 12; background: linear-gradient(180deg, rgba(10, 4, 28, 0.55) 0, rgba(10, 4, 28, 0) 34%); }
#night { background: #0a0428; opacity: 0.1; transition: opacity 4s linear; mix-blend-mode: multiply; }

/* Décors de repli dessinés en CSS (utilisés tant que les images du pack v3 ne sont pas déposées) */
#bg-decor { transition: transform 0.2s linear; }
body[data-chapter="1"] #bg-decor {
    background:
        radial-gradient(circle at 74% 20%, rgba(255, 244, 205, 0.95) 0 5%, rgba(255, 224, 160, 0.35) 9%, transparent 22%),
        conic-gradient(from 200deg at 74% 20%, rgba(255, 240, 200, 0.18) 0 8deg, transparent 8deg 20deg, rgba(255, 240, 200, 0.12) 20deg 28deg, transparent 28deg 40deg, rgba(255, 240, 200, 0.14) 40deg 48deg, transparent 48deg 360deg),
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.05) 0 2px, transparent 2px 90px);
}
body[data-chapter="2"] #bg-decor {
    background:
        radial-gradient(circle at 20px 20px, #ff6aa8 0 13px, transparent 14px) 0 0 / 74px 120px,
        radial-gradient(circle at 20px 20px, #6bd0ff 0 11px, transparent 12px) 37px 0 / 74px 120px,
        repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.28) 0 6px, transparent 6px 120px),
        radial-gradient(circle at 50% 100%, rgba(255, 207, 74, 0.35), transparent 60%);
    -webkit-mask-image: linear-gradient(180deg, #000 0 55%, transparent 80%); mask-image: linear-gradient(180deg, #000 0 55%, transparent 80%); opacity: 0.55;
}
body[data-chapter="3"] #bg-decor {
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='520' height='220' viewBox='0 0 520 220'%3E%3Cg fill='%23140836'%3E%3Crect x='0' y='90' width='60' height='130'/%3E%3Crect x='70' y='40' width='50' height='180'/%3E%3Crect x='130' y='110' width='70' height='110'/%3E%3Crect x='210' y='20' width='55' height='200'/%3E%3Crect x='275' y='80' width='65' height='140'/%3E%3Crect x='350' y='50' width='50' height='170'/%3E%3Crect x='410' y='100' width='60' height='120'/%3E%3Crect x='480' y='60' width='40' height='160'/%3E%3C/g%3E%3Cg fill='%23ffcf4a' opacity='.8'%3E%3Crect x='80' y='60' width='8' height='10'/%3E%3Crect x='96' y='90' width='8' height='10'/%3E%3Crect x='222' y='44' width='8' height='10'/%3E%3Crect x='240' y='80' width='8' height='10'/%3E%3Crect x='360' y='70' width='8' height='10'/%3E%3Crect x='20' y='115' width='8' height='10'/%3E%3Crect x='140' y='135' width='8' height='10'/%3E%3Crect x='425' y='125' width='8' height='10'/%3E%3Crect x='290' y='105' width='8' height='10'/%3E%3C/g%3E%3Cg fill='%23ff4fa3' opacity='.85'%3E%3Crect x='96' y='140' width='8' height='10'/%3E%3Crect x='300' y='150' width='8' height='10'/%3E%3Crect x='440' y='150' width='8' height='10'/%3E%3C/g%3E%3C/svg%3E") bottom left / 520px 220px repeat-x,
        radial-gradient(circle at 12% 20%, #fff 0 1px, transparent 2px) 0 0 / 160px 130px, radial-gradient(circle at 60% 40%, #fff 0 1px, transparent 2px) 0 0 / 210px 150px;
}
body[data-chapter="4"] #bg-decor {
    background:
        radial-gradient(circle at 76% 28%, #ff9ccf 0 7%, #c75bff 12%, #5a3bd6 19%, transparent 20%),
        radial-gradient(circle at 76% 28%, transparent 0 22%, rgba(255, 255, 255, 0.25) 22.5% 23.2%, transparent 24%),
        radial-gradient(circle at 12% 20%, #fff 0 1px, transparent 2px) 0 0 / 110px 90px, radial-gradient(circle at 60% 40%, #bfe8ff 0 1px, transparent 2px) 0 0 / 150px 120px;
}
body[data-chapter="5"] #bg-decor {
    background:
        radial-gradient(circle at 18% 30%, #000 0 4%, #ffd0f0 4.6%, rgba(255, 79, 163, 0.75) 8%, transparent 15%),
        radial-gradient(ellipse at 70% 30%, rgba(31, 214, 176, 0.35), transparent 55%), radial-gradient(ellipse at 40% 70%, rgba(255, 79, 163, 0.3), transparent 55%),
        radial-gradient(circle at 12% 20%, #fff 0 1px, transparent 2px) 0 0 / 90px 80px;
}

/* ---------- Zone de jeu (tout sauf le tiroir) ---------- */
#stage { position: absolute; left: 0; right: var(--shop-w); top: 0; bottom: var(--ticker-h); transition: right 0.35s cubic-bezier(0.2, 0.8, 0.2, 1); }
#world { position: absolute; inset: 0; transition: transform 0.2s linear; }

#ground { position: absolute; left: -5%; right: -5%; bottom: 0; height: 24%; z-index: 20; box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.25); border-top: 3px solid rgba(255, 255, 255, 0.35); }
body[data-chapter="1"] #ground { background: conic-gradient(#e8505b 25%, #fff3e6 0 50%, #e8505b 0 75%, #fff3e6 0) 0 0 / 56px 56px; }
body[data-chapter="1"] #ground::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(255, 224, 160, 0.25), rgba(40, 10, 40, 0.45)); }
body[data-chapter="2"] #ground { background: repeating-linear-gradient(90deg, #8b5a3c 0 90px, #7a4d33 90px 92px, #94613f 92px 180px, #7a4d33 180px 182px); }
body[data-chapter="2"] #ground::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(255, 207, 74, 0.2), rgba(30, 8, 30, 0.5)); }
body[data-chapter="3"] #ground { background: linear-gradient(180deg, #3a2470, #1b0e3d); border-top-color: rgba(255, 79, 163, 0.7); }
body[data-chapter="3"] #ground::after { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(90deg, transparent 0 120px, rgba(255, 207, 74, 0.12) 120px 124px); }
body[data-chapter="4"] #ground { background: linear-gradient(180deg, #2a3a6e, #0f1538); border-top-color: rgba(92, 200, 255, 0.7); }
body[data-chapter="4"] #ground::after { content: ''; position: absolute; inset: 0; background: linear-gradient(rgba(92, 200, 255, 0.15) 1px, transparent 1px) 0 0 / 48px 48px, linear-gradient(90deg, rgba(92, 200, 255, 0.15) 1px, transparent 1px) 0 0 / 48px 48px; }
body[data-chapter="5"] #ground { background: linear-gradient(180deg, rgba(120, 60, 200, 0.85), rgba(20, 20, 80, 0.95)); border-top-color: rgba(70, 240, 193, 0.8); }
body[data-chapter="5"] #ground::after { content: ''; position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 0, rgba(70, 240, 193, 0.35), transparent 70%); }
#bg-image.has-art ~ #stage #ground { opacity: 0.8; }

/* ---------- Bâtiments sur l'horizon ---------- */
#skyline { position: absolute; inset: 0; pointer-events: none; }
.sprite { --u: clamp(54px, 10.5vmin, 128px); --scale: 1; position: absolute; width: var(--u); height: auto; transform: translateX(-50%) scale(var(--scale)); transform-origin: bottom center; filter: drop-shadow(0 6px 5px rgba(0, 0, 0, 0.35)); animation: spriteBob calc(4.5s / var(--anim-speed, 1)) ease-in-out infinite; animation-delay: var(--delay, 0s); will-change: transform; }
.sprite.pop { animation: spritePop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), spriteBob calc(4.5s / var(--anim-speed, 1)) ease-in-out 0.6s infinite; }
@keyframes spriteBob { 0%, 100% { transform: translateX(-50%) scale(var(--scale)) translateY(0); } 50% { transform: translateX(-50%) scale(var(--scale)) translateY(-3px); } }
@keyframes spritePop { from { transform: translateX(-50%) scale(0) translateY(30px); opacity: 0; } to { transform: translateX(-50%) scale(var(--scale)) translateY(0); opacity: 1; } }
.sprite-usine { animation-name: spriteWork; animation-duration: calc(0.9s / var(--anim-speed, 1)); }
.sprite-temple, .sprite-labo { filter: drop-shadow(0 0 14px rgba(255, 215, 120, 0.55)) drop-shadow(0 6px 5px rgba(0, 0, 0, 0.35)); }
.sprite-portail { filter: drop-shadow(0 0 18px rgba(138, 43, 226, 0.8)); }
.sprite-trounoir { filter: drop-shadow(0 0 22px rgba(255, 79, 163, 0.7)); animation-duration: calc(6s / var(--anim-speed, 1)); }
.sprite-matrice { filter: drop-shadow(0 0 16px rgba(70, 240, 193, 0.8)); }
@keyframes spriteWork { 0%, 100% { transform: translateX(-50%) scale(var(--scale)) translateY(0); } 25% { transform: translateX(-50%) scale(var(--scale)) translateY(1px); } 75% { transform: translateX(-50%) scale(var(--scale)) translateY(-1px); } }

#walkers { position: absolute; left: 0; right: 0; bottom: 0; height: 24%; z-index: 22; pointer-events: none; overflow: hidden; }
.ant { position: absolute; left: -50px; height: auto; animation: antPatrol 20s linear infinite; filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.4)); }
@keyframes antPatrol {
    0% { left: -50px; transform: scaleX(-1); } 49% { left: 100%; transform: scaleX(-1); } 50% { left: 100%; transform: scaleX(1); } 99% { left: -50px; transform: scaleX(1); } 100% { left: -50px; transform: scaleX(-1); }
}

/* ---------- Gelly ---------- */
#stage-center { position: absolute; left: 50%; bottom: 16%; transform: translateX(-50%); z-index: 30; display: flex; flex-direction: column; align-items: center; }
#jelly-aura {
    position: absolute; top: 50%; left: 50%; width: min(90vmin, 720px); height: min(90vmin, 720px); transform: translate(-50%, -50%); border-radius: 50%; pointer-events: none; z-index: -1;
    background: radial-gradient(circle, rgba(255, 79, 163, 0.36) 0%, rgba(255, 79, 163, 0.07) 45%, transparent 68%), repeating-conic-gradient(from 0deg, rgba(255, 255, 255, 0.07) 0deg 10deg, transparent 10deg 20deg);
    -webkit-mask-image: radial-gradient(circle, #000 35%, transparent 70%); mask-image: radial-gradient(circle, #000 35%, transparent 70%); animation: spinAura 60s linear infinite;
}
#jelly-aura.frenzy-aura { animation: spinAura 6s linear infinite; filter: hue-rotate(40deg) brightness(1.5); }
@keyframes spinAura { to { transform: translate(-50%, -50%) rotate(360deg); } }

#gelly { position: relative; }
.jelly-btn { padding: 0; touch-action: none; border-radius: 50%; position: relative; display: block; }
.jelly-btn::after { content: ''; position: absolute; left: 10%; right: 10%; bottom: -8px; height: 22px; z-index: -1; background: radial-gradient(ellipse, rgba(0, 0, 0, 0.5), transparent 70%); }
#gelly-img {
    --hue: 0deg; --sat: 1; --bright: 1; --shadow-color: rgba(255, 79, 163, 0.5); --shadow-y: 14px; --shadow-blur: 20px;
    width: clamp(210px, min(36vw, 42dvh), 460px); height: auto; display: block;
    filter: hue-rotate(var(--hue)) saturate(var(--sat)) brightness(var(--bright)) drop-shadow(0 var(--shadow-y) var(--shadow-blur) var(--shadow-color));
    transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.15s ease; transform-origin: bottom center;
}
.jelly-btn:hover #gelly-img { transform: scale(1.03); }
.jelly-btn:active #gelly-img, .jelly-btn.active #gelly-img { transform: scaleX(1.1) scaleY(0.86); --shadow-y: 4px; --shadow-blur: 6px; --bright: 0.92; transition: transform 0.05s ease; animation: none !important; }
.jelly-btn:active #gelly-img.jelly-rainbow, .jelly-btn.active #gelly-img.jelly-rainbow { animation: rainbowMode 3s linear infinite !important; }
.jelly-btn:focus-visible { outline-offset: 10px; border-radius: 50%; }

/* Visage dessiné en CSS (repli) : posé sur le dôme, jamais teinté */
#gelly-face { position: absolute; inset: 0; pointer-events: none; transform-origin: bottom center; transition: transform 0.15s; }
body.mascot-art #gelly-face { display: none; }
#gelly:has(.jelly-btn.active) #gelly-face { transform: scaleX(1.1) scaleY(0.86); }
#gelly-face .eye { position: absolute; top: 47%; width: 5.4%; height: 15%; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff 0 14%, #1a0a22 16%); box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25); transition: height 0.08s, top 0.08s, border-radius 0.1s; }
#gelly-face .eye.l { left: 36%; } #gelly-face .eye.r { left: 58.6%; }
#gelly-face .cheek { position: absolute; top: 62%; width: 7%; height: 6%; border-radius: 50%; background: rgba(255, 150, 190, 0.6); filter: blur(1px); }
#gelly-face .cheek.l { left: 29%; } #gelly-face .cheek.r { left: 64%; }
#gelly-face .mouth { position: absolute; left: 46%; top: 63%; width: 8%; height: 6%; border-bottom: 3px solid #2a0a1e; border-radius: 0 0 50% 50%; transition: all 0.1s; }
#gelly[data-mood="blink"] .eye { height: 2.5%; top: 54%; border-radius: 4px; background: #1a0a22; }
#gelly[data-mood="happy"] .eye { height: 7%; top: 50%; border-radius: 50% 50% 0 0; background: none; border-top: 4px solid #1a0a22; box-shadow: none; }
#gelly[data-mood="happy"] .mouth, #gelly[data-mood="excited"] .mouth { left: 44%; width: 12%; height: 9%; background: #6b0f36; border: 0; border-radius: 0 0 60% 60%; }
#gelly[data-mood="excited"] .eye { background: radial-gradient(circle, #fff 0 12%, #ffd84a 14% 45%, #1a0a22 47%); height: 17%; top: 45%; animation: pulseBanner 0.4s infinite; }
#gelly[data-mood="sleepy"] .eye { height: 5%; top: 52%; border-radius: 0 0 50% 50%; background: none; border-bottom: 4px solid #1a0a22; box-shadow: none; }
#gelly[data-mood="sleepy"] .mouth { width: 5%; left: 47.5%; height: 4%; border-radius: 50%; border: 3px solid #2a0a1e; }
#gelly[data-mood="surprised"] .eye { height: 18%; width: 6.6%; top: 44%; }
#gelly[data-mood="surprised"] .mouth { left: 47%; width: 6%; height: 8%; border: 3px solid #2a0a1e; border-radius: 50%; background: #6b0f36; }

#sweet-spot { position: absolute; z-index: 4; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.8rem; color: #fff6c9; background: radial-gradient(circle, rgba(255, 246, 201, 0.95), rgba(255, 207, 74, 0.55) 55%, transparent 72%); box-shadow: 0 0 26px 8px rgba(255, 207, 74, 0.7); animation: sweetPulse 0.7s ease-in-out infinite; touch-action: none; }
@keyframes sweetPulse { 50% { transform: scale(1.25) rotate(20deg); } }

#combo-meter { position: absolute; left: 50%; bottom: -40px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; z-index: 40; white-space: nowrap; }
#combo-label { font-weight: 700; letter-spacing: 1px; color: var(--gold); text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7); font-variant-numeric: tabular-nums; }
.combo-bar { width: 150px; height: 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.2); overflow: hidden; }
#combo-fill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--mint), var(--gold), var(--pink)); transition: width 0.12s linear; }
#combo-meter.max #combo-label { animation: pulseBanner 0.5s infinite; color: #fff; }

#speech { position: absolute; left: 50%; top: -6px; transform: translate(-50%, -100%); width: max-content; max-width: min(300px, 80vw); padding: 10px 16px; border-radius: 18px; text-align: center; font-weight: 600; font-size: 0.95rem; line-height: 1.35; color: #2a1245; background: #fff; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); z-index: 45; animation: speechIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }
#speech::after { content: ''; position: absolute; left: 50%; bottom: -8px; margin-left: -9px; border: 9px solid transparent; border-top-color: #fff; border-bottom: 0; }
@keyframes speechIn { from { opacity: 0; transform: translate(-50%, -80%) scale(0.8); } to { opacity: 1; transform: translate(-50%, -100%) scale(1); } }

/* ---------- Météo : pluie de sucre pendant la frénésie ---------- */
#weather { position: absolute; inset: 0; pointer-events: none; z-index: 25; overflow: hidden; }
.drop { position: absolute; top: -8%; animation: dropFall linear infinite; opacity: 0.85; }
@keyframes dropFall { to { transform: translateY(115vh) rotate(360deg); } }
body.frenzy #bg-sky { filter: hue-rotate(25deg) saturate(1.4); }


/* =========================================
   ÉVOLUTION DU JELLY (COULEURS & ÉNERGIE)
   ========================================= */

/* --- 1. LES COULEURS (Basées sur le Total Gagné) --- */

/* Palier 1 : Vert Pâle (Débutant) */
#gelly-img.jelly-pale-green {
    --hue: 80deg;
    --sat: 0.6; /* Couleurs un peu passées */
    --bright: 1.1;
    --shadow-color: rgba(100, 200, 100, 0.3);
}

/* Palier 2 : Vert Vif (Ça reprend des couleurs !) */
#gelly-img.jelly-vibrant-green {
    --hue: 110deg;
    --sat: 2.5; /* Très saturé ! */
    --bright: 1.1;
    --shadow-color: rgba(50, 255, 50, 0.4);
}

/* Palier 3 : Bleu Électrique */
#gelly-img.jelly-blue {
    --hue: 210deg;
    --sat: 2.0;
    --bright: 1.1;
    --shadow-color: rgba(50, 100, 255, 0.4);
}

/* Palier 4 : Violet Mystique */
#gelly-img.jelly-violet {
    --hue: 260deg;
    --sat: 1.8;
    --bright: 1.0;
    --shadow-color: rgba(180, 50, 255, 0.4);
}

/* Palier 5 : Rouge Énervé (Retour aux sources mais puissant) */
#gelly-img.jelly-red {
    --hue: 340deg; /* Un rouge profond un peu magenta */
    --sat: 3.0;
    --bright: 0.9;
    --shadow-color: rgba(255, 0, 0, 0.5);
}

/* Palier 6 : MASTERCLASS (Multicolore) */
#gelly-img.jelly-rainbow {
    --bright: 1.2; /* On définit la luminosité de base ici pour l'animation */
    animation: rainbowMode 3s linear infinite;
}

/* Si on a le mode Rainbow ET le Pulse en même temps, on combine les animations */
#gelly-img.jelly-rainbow.energy-pulse {
    animation: rainbowMode 3s linear infinite, jellyPulse 2s infinite ease-in-out;
}

/* --- 2. L'ÉNERGIE (Basée sur le GPS - Gummies par seconde) --- */
/* Énergie 1 : Respiration lente (Le Jelly s'éveille) */
#gelly-img.energy-pulse {
    animation: jellyPulse 2s infinite ease-in-out;
}

/* Énergie 2 : Lévitation instable (Les usines tournent à fond) */
.energy-float {
    /* Animation supprimée pour un meilleur ressenti du clic */
}

/* Les moteurs d'animation (Keyframes) */
@keyframes jellyPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.04); } 
    100% { transform: scale(1); }
}

@keyframes rainbowMode {
    /* On utilise les variables (--bright, --shadow-y, etc.) pour que le clic (qui les modifie) marche aussi ici ! */
    0% { filter: hue-rotate(0deg) saturate(2) brightness(var(--bright)) drop-shadow(0 var(--shadow-y) var(--shadow-blur) rgba(255,0,0,0.4)); }
    25% { filter: hue-rotate(90deg) saturate(2) brightness(var(--bright)) drop-shadow(0 var(--shadow-y) var(--shadow-blur) rgba(0,255,0,0.4)); }
    50% { filter: hue-rotate(180deg) saturate(2) brightness(var(--bright)) drop-shadow(0 var(--shadow-y) var(--shadow-blur) rgba(0,0,255,0.4)); }
    75% { filter: hue-rotate(270deg) saturate(2) brightness(var(--bright)) drop-shadow(0 var(--shadow-y) var(--shadow-blur) rgba(255,0,255,0.4)); }
    100% { filter: hue-rotate(360deg) saturate(2) brightness(var(--bright)) drop-shadow(0 var(--shadow-y) var(--shadow-blur) rgba(255,0,0,0.4)); }
}

@keyframes antPatrol {
    0% { left: -50px; transform: scaleX(-1); } /* On retourne l'image pour qu'elle regarde à droite */
    49% { left: 100%; transform: scaleX(-1); } /* Arrivée à droite */
    50% { left: 100%; transform: scaleX(1); } /* Demi-tour instantané (miroir) */
    99% { left: -50px; transform: scaleX(1); } /* Retour à gauche */
    100% { left: -50px; transform: scaleX(-1); } /* Remise à l'endroit pour le prochain tour */
}



/* Mobile : la scène s'arrête au-dessus du dock et de la feuille inférieure */
@media (max-width: 900px) {
    #stage { bottom: calc(var(--sheet-h) + var(--dock-h)); }
    #stage-center { bottom: 14%; }
    #gelly-img { width: clamp(150px, min(52vw, 26dvh), 300px); }
    #ground { height: 28%; } #walkers { height: 28%; }
    #combo-meter { bottom: -34px; }
    .sprite { --u: clamp(40px, 11vmin, 90px); }
}
