/* ===== VARIABLES & RESET ===== */
:root {
    --rose: #ff6b9d;
    --orange: #ff8a50;
    --jaune: #ffd166;
    --vert: #06d6a0;
    --bleu: #118ab2;
    --violet: #7b2ff7;
    --fond: #fef9ef;
    --fond-carte: #ffffff;
    --texte: #2d3047;
    --ombre: rgba(45, 48, 71, 0.1);
    --rayon: 20px;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { overscroll-behavior: none; height: 100%; }

body {
    font-family: 'Quicksand', sans-serif;
    background: var(--fond);
    background-image:
        radial-gradient(circle at 20% 80%, rgba(255, 107, 157, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(17, 138, 178, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(123, 47, 247, 0.05) 0%, transparent 60%);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    overflow-x: hidden;
    color: var(--texte);
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

/* ===== DÉCORATIONS FLOTTANTES ===== */
.decorations-flottantes { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }

.flotteur {
    position: absolute;
    left: var(--x);
    top: -3rem;
    font-size: var(--taille);
    animation: flotter 12s ease-in-out infinite;
    animation-delay: var(--delai);
    opacity: 0.5;
}

@keyframes flotter {
    0%, 100% { transform: translateY(0) rotate(0deg); opacity: 0.3; }
    25% { transform: translateY(30vh) rotate(15deg); opacity: 0.6; }
    50% { transform: translateY(55vh) rotate(-10deg); opacity: 0.5; }
    75% { transform: translateY(80vh) rotate(20deg); opacity: 0.4; }
}

/* ===== ÉCRANS ===== */
.ecran { display: none; min-height: 100vh; min-height: -webkit-fill-available; position: relative; z-index: 1; }

.ecran.actif {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    animation: apparition 0.5s ease-out;
}

@keyframes apparition {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* ===== ÉCRAN CHOIX DE JEU ===== */
.accueil-contenu { text-align: center; padding: 2rem; max-width: 600px; width: 100%; }

.titre-jeu {
    font-family: 'Baloo 2', cursive;
    font-size: clamp(2.5rem, 8vw, 4.5rem);
    font-weight: 800;
    line-height: 1.1;
    background: linear-gradient(135deg, var(--rose), var(--violet), var(--bleu));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
    animation: rebond 2s ease-in-out infinite;
}

.titre-jeu-petit {
    font-size: clamp(2rem, 6vw, 3rem);
}

.titre-emoji {
    -webkit-text-fill-color: initial;
    display: inline-block;
    animation: balancement 2s ease-in-out infinite;
}

.titre-emoji:last-child { animation-delay: 0.5s; }

@keyframes rebond { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes balancement { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } }

.sous-titre {
    font-size: clamp(1rem, 3vw, 1.4rem);
    color: #666;
    font-weight: 600;
    margin-bottom: 2.5rem;
}

/* Grille choix de jeu */
.grille-jeux {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.2rem;
    max-width: 440px;
    margin: 0 auto;
}

.btn-choix-jeu {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    padding: 2rem 1.2rem;
    border: 4px solid transparent;
    border-radius: 24px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    font-family: 'Quicksand', sans-serif;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    overflow: hidden;
}

.btn-choix-jeu::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.5), transparent);
    pointer-events: none;
}

.btn-jeu-mots {
    background: linear-gradient(145deg, #e8f5e9, #c8e6c9);
    box-shadow: 0 6px 20px rgba(6, 214, 160, 0.2), 0 2px 6px rgba(0,0,0,0.06);
}

.btn-jeu-mots:active {
    border-color: var(--vert);
    transform: translateY(-4px) scale(1.03);
    box-shadow: 0 12px 30px rgba(6, 214, 160, 0.3);
}

.btn-jeu-calculs {
    background: linear-gradient(145deg, #e3f2fd, #bbdefb);
    box-shadow: 0 6px 20px rgba(17, 138, 178, 0.2), 0 2px 6px rgba(0,0,0,0.06);
}

.btn-jeu-calculs:active {
    border-color: var(--bleu);
    transform: translateY(-4px) scale(1.03);
    box-shadow: 0 12px 30px rgba(17, 138, 178, 0.3);
}

.choix-jeu-icone { font-size: 3.5rem; }
.choix-jeu-titre { font-family: 'Baloo 2', cursive; font-size: 1.3rem; font-weight: 800; color: var(--texte); }
.choix-jeu-desc { font-size: 0.85rem; font-weight: 600; color: #888; }

/* Bouton retour menu */
.btn-retour-menu {
    display: inline-block;
    margin-top: 2rem;
    font-family: 'Quicksand', sans-serif;
    font-weight: 700;
    font-size: 0.95rem;
    background: none;
    border: 2px solid #ddd;
    border-radius: 50px;
    padding: 0.6rem 1.5rem;
    cursor: pointer;
    color: #888;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.btn-retour-menu:active { background: var(--rose); color: white; border-color: var(--rose); }

/* ===== GRILLE THÈMES ===== */
.label-choix { font-family: 'Baloo 2', cursive; font-size: 1.3rem; font-weight: 700; color: var(--texte); margin-bottom: 1.2rem; }

.grille-themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }

.btn-theme {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1.2rem 0.8rem;
    border: 3px solid transparent;
    border-radius: var(--rayon);
    background: var(--fond-carte);
    box-shadow: 0 4px 15px var(--ombre), 0 2px 4px rgba(0,0,0,0.05);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    font-family: 'Quicksand', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

.btn-theme:active {
    transform: translateY(-4px) scale(1.04);
    box-shadow: 0 12px 30px rgba(123, 47, 247, 0.15);
    border-color: var(--violet);
}

.theme-emoji { font-size: 2.5rem; }
.theme-nom { font-weight: 700; font-size: 0.95rem; color: var(--texte); }

/* ===== ÉCRAN DE JEU ===== */
#ecran-jeu.actif { justify-content: flex-start; }

.jeu-entete {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}

.btn-retour {
    font-family: 'Quicksand', sans-serif;
    font-weight: 700;
    font-size: 0.95rem;
    background: var(--fond-carte);
    border: 2px solid #e0e0e0;
    border-radius: 50px;
    padding: 0.5rem 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--texte);
    -webkit-tap-highlight-color: transparent;
}

.btn-retour:active { background: var(--rose); color: white; border-color: var(--rose); }

.info-theme { font-family: 'Baloo 2', cursive; font-size: 1.1rem; font-weight: 700; display: flex; align-items: center; gap: 0.4rem; }

.compteur-score {
    display: flex; align-items: center; gap: 0.3rem;
    font-family: 'Baloo 2', cursive; font-size: 1.3rem; font-weight: 800;
    color: var(--orange); background: var(--fond-carte);
    padding: 0.4rem 1rem; border-radius: 50px;
    box-shadow: 0 2px 10px var(--ombre);
}

.etoile-score { animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.2); } }

/* Progression */
.progression { width: 100%; max-width: 500px; margin: 0 auto; padding: 0 1.5rem; display: flex; align-items: center; gap: 0.8rem; }

.barre-progression { flex: 1; height: 12px; background: #e8e8e8; border-radius: 50px; overflow: hidden; box-shadow: inset 0 2px 4px rgba(0,0,0,0.08); }

.remplissage-progression {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, var(--vert), var(--bleu));
    border-radius: 50px;
    transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.texte-progression { font-weight: 700; font-size: 0.85rem; color: #999; white-space: nowrap; }

/* Zone de jeu */
.zone-jeu { display: flex; flex-direction: column; align-items: center; padding: 1.5rem; flex: 1; }

.carte-image {
    width: clamp(160px, 42vw, 220px);
    height: clamp(160px, 42vw, 220px);
    background: var(--fond-carte);
    border-radius: 30px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 8px 30px var(--ombre), 0 2px 8px rgba(0,0,0,0.06), inset 0 -3px 0 rgba(0,0,0,0.04);
    border: 4px solid #f0f0f0;
    position: relative; overflow: hidden;
    animation: apparitionCarte 0.6s ease-out;
}

/* Carte calcul : plus large pour l'opération */
.carte-image.carte-calcul {
    width: clamp(240px, 70vw, 340px);
    height: clamp(130px, 30vw, 160px);
    border-radius: 24px;
}

.carte-image::before {
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.4) 0%, transparent 50%);
    border-radius: 26px; pointer-events: none;
}

@keyframes apparitionCarte {
    from { opacity: 0; transform: scale(0.7) rotate(-5deg); }
    to { opacity: 1; transform: scale(1) rotate(0deg); }
}

.emoji-question {
    font-size: clamp(4.5rem, 18vw, 7rem);
    animation: douxRebond 3s ease-in-out infinite;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.1));
}

/* Texte opération dans la carte calcul */
.texte-operation {
    font-family: 'Baloo 2', cursive;
    font-size: clamp(2.5rem, 10vw, 4rem);
    font-weight: 800;
    color: var(--texte);
    animation: douxRebond 3s ease-in-out infinite;
    letter-spacing: 2px;
}

.texte-operation .signe-plus {
    color: var(--bleu);
    margin: 0 0.3rem;
}

.texte-operation .signe-egal {
    color: var(--violet);
    margin: 0 0.2rem;
}

@keyframes douxRebond {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-10px) scale(1.05); }
}

.instruction {
    font-family: 'Baloo 2', cursive;
    font-size: clamp(1.1rem, 4vw, 1.5rem);
    font-weight: 700;
    margin: 1rem 0;
    color: var(--texte);
}

/* Boutons de réponse */
.conteneur-boutons { display: flex; flex-direction: column; gap: 0.7rem; width: 100%; max-width: 360px; }

.btn-reponse {
    font-family: 'Baloo 2', cursive;
    font-size: clamp(1.1rem, 3.5vw, 1.4rem);
    font-weight: 700;
    padding: 0.9rem 1.5rem;
    border: 3px solid #e8e8e8;
    border-radius: 16px;
    background: var(--fond-carte);
    color: var(--texte);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 3px 12px var(--ombre);
    position: relative; overflow: hidden;
    letter-spacing: 0.5px;
    -webkit-tap-highlight-color: transparent;
}

.btn-reponse::before {
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.6), transparent);
    pointer-events: none;
}

.btn-reponse:active:not(.desactive) { transform: translateY(0) scale(0.97); border-color: var(--violet); }

.btn-reponse.correct {
    background: linear-gradient(135deg, #a8edce, #06d6a0) !important;
    border-color: var(--vert) !important;
    color: #065f46 !important;
    transform: scale(1.05);
    animation: succes 0.5s ease-out;
}

.btn-reponse.incorrect {
    background: linear-gradient(135deg, #fecaca, #fca5a5) !important;
    border-color: #ef4444 !important;
    color: #991b1b !important;
    animation: trembler 0.5s ease-out;
}

.btn-reponse.desactive { opacity: 0.5; cursor: not-allowed; transform: none !important; }

@keyframes succes { 0% { transform: scale(1); } 30% { transform: scale(1.12); } 60% { transform: scale(0.98); } 100% { transform: scale(1.05); } }
@keyframes trembler { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }

/* Message résultat */
.message-resultat {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
    animation: fondu 0.3s ease-out;
}

.message-resultat.cache { display: none !important; }

@keyframes fondu { from { opacity: 0; } to { opacity: 1; } }

.contenu-resultat {
    background: var(--fond-carte);
    border-radius: 30px;
    padding: 2.5rem 2rem;
    text-align: center;
    max-width: 340px; width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    animation: popResultat 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popResultat {
    from { transform: scale(0.5) translateY(30px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}

.emoji-resultat { font-size: 4rem; display: block; margin-bottom: 0.8rem; animation: douxRebond 2s ease-in-out infinite; }

.texte-resultat { font-family: 'Baloo 2', cursive; font-size: 1.4rem; font-weight: 700; margin-bottom: 1.5rem; color: var(--texte); }

.btn-suivant {
    font-family: 'Baloo 2', cursive; font-size: 1.1rem; font-weight: 700;
    padding: 0.8rem 2.5rem; border: none; border-radius: 50px;
    background: linear-gradient(135deg, var(--violet), var(--bleu));
    color: white; cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(123, 47, 247, 0.3);
    -webkit-tap-highlight-color: transparent;
}

.btn-suivant:active { transform: scale(0.96); }

/* ===== ÉCRAN DE FIN ===== */
.contenu-fin { text-align: center; padding: 2rem; max-width: 450px; }

.feux-artifice { font-size: 3rem; display: flex; justify-content: center; gap: 1rem; margin-bottom: 1rem; }
.feux-artifice span { animation: rebond 1.5s ease-in-out infinite; }
.feux-artifice span:nth-child(2) { animation-delay: 0.3s; }
.feux-artifice span:nth-child(3) { animation-delay: 0.6s; }

.titre-bravo {
    font-family: 'Baloo 2', cursive;
    font-size: clamp(2rem, 7vw, 3rem); font-weight: 800;
    background: linear-gradient(135deg, var(--jaune), var(--orange));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text; margin-bottom: 0.5rem;
}

.message-fin { font-size: 1.2rem; font-weight: 600; color: #666; margin-bottom: 2rem; }

.score-final { display: flex; align-items: baseline; justify-content: center; gap: 0.3rem; margin-bottom: 1.5rem; }
.label-score-final { font-family: 'Quicksand', sans-serif; font-size: 1.1rem; font-weight: 600; color: #888; }
.valeur-score-final { font-family: 'Baloo 2', cursive; font-size: 3.5rem; font-weight: 800; color: var(--orange); line-height: 1; }

.etoiles-fin { font-size: 2.5rem; margin-bottom: 2rem; display: flex; justify-content: center; gap: 0.5rem; }
.etoiles-fin span { display: inline-block; animation: apparitionEtoile 0.4s ease-out both; }
.etoiles-fin span:nth-child(1) { animation-delay: 0.2s; }
.etoiles-fin span:nth-child(2) { animation-delay: 0.4s; }
.etoiles-fin span:nth-child(3) { animation-delay: 0.6s; }

@keyframes apparitionEtoile {
    from { transform: scale(0) rotate(-90deg); opacity: 0; }
    to { transform: scale(1) rotate(0deg); opacity: 1; }
}

.boutons-fin { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }

.btn-rejouer, .btn-autre-theme {
    font-family: 'Baloo 2', cursive; font-size: 1.1rem; font-weight: 700;
    padding: 0.8rem 2rem; border: none; border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 4px 15px var(--ombre);
    -webkit-tap-highlight-color: transparent;
}

.btn-rejouer { background: linear-gradient(135deg, var(--vert), #04b890); color: white; }
.btn-rejouer:active { transform: scale(0.96); }

.btn-autre-theme { background: linear-gradient(135deg, var(--violet), var(--bleu)); color: white; }
.btn-autre-theme:active { transform: scale(0.96); }

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
    .grille-themes { grid-template-columns: repeat(2, 1fr); }
    .jeu-entete { padding: 0.8rem 1rem; }
    .btn-retour { font-size: 0.8rem; padding: 0.4rem 0.8rem; }
    .zone-jeu { padding: 1rem; }
    .boutons-fin { flex-direction: column; align-items: center; }
}

@media (max-height: 600px) {
    .carte-image { width: 140px; height: 140px; }
    .carte-image.carte-calcul { width: clamp(200px, 60vw, 280px); height: 110px; }
    .emoji-question { font-size: 4rem; }
    .texte-operation { font-size: 2.2rem; }
    .instruction { margin: 0.6rem 0; }
    .btn-reponse { padding: 0.7rem 1rem; }
}

@media (min-width: 768px) {
    .conteneur-boutons { flex-direction: row; max-width: 560px; }
    .btn-reponse { flex: 1; }
}
