/* Importation d'une police ludique depuis Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600&display=swap');

:root {
    --bg-color: #f0f4f8;
    --card-bg: #ffffff;
    --primary-color: #ff6b6b; /* Couleur vive */
    --secondary-color: #4ecdc4;
    --text-color: #2d3436;
    --shadow: 0 10px 20px rgba(0,0,0,0.08);
    --shadow-hover: 0 15px 30px rgba(0,0,0,0.15);
}

/* --- UTILITAIRES --- */
.hidden {
    display: none !important;
}

body {
    font-family: 'Fredoka', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 20px;
}

/* --- EN-TÊTE (HEADER) --- */
.site-header {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 40px;
    gap: 20px;
    padding-top: 20px;
}

.header-logo {
    height: 80px;
    width: auto;
}

.main-title {
    color: var(--text-color);
    font-weight: 600;
    font-size: 2.5rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin: 0;
}

/* --- MENU PRINCIPAL (NOUVEAU) --- */
.menu-container {
    text-align: center;
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
}

.menu-container h2 {
    color: var(--text-color);
    font-size: 2rem;
    margin-bottom: 30px;
}

.menu-buttons {
    display: flex;
    justify-content: center;
    gap: 30px;
    flex-wrap: wrap;
    margin-top: 20px;
}

.menu-btn {
    border: none;
    border-radius: 25px;
    padding: 20px;
    font-size: 1.4rem;
    font-weight: bold;
    cursor: pointer;
    width: 200px;
    height: 200px;
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1), box-shadow 0.3s;
    font-family: 'Fredoka', sans-serif;
    color: white;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.4;
}

.menu-btn:hover {
    transform: translateY(-10px) scale(1.02);
    box-shadow: var(--shadow-hover);
}

.menu-btn span {
    display: block;
    font-size: 0.9rem;
    font-weight: normal;
    opacity: 0.9;
    margin-top: 10px;
}

/* Couleurs spécifiques aux modes */
.mode-free { 
    background: linear-gradient(135deg, #a8e6cf, #1abc9c); 
}
.mode-quiz { 
    background: linear-gradient(135deg, #ff9f43, #ff6b6b); 
}
.mode-focus { 
    background: linear-gradient(135deg, #54a0ff, #5f27cd); 
}

/* --- GRILLES & BOUTONS --- */

.category-section {
    margin-bottom: 60px;
}

.category-title {
    font-size: 1.8rem;
    color: #2c3e50;
    background-color: #fff;
    padding: 15px 25px;
    border-radius: 50px;
    display: inline-block;
    margin-bottom: 25px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    border-left: 5px solid var(--secondary-color);
    transition: transform 0.3s ease;
}

.category-title:hover {
    transform: translateX(10px);
}

.sound-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 20px;
    max-width: 1200px;
    margin: 0 auto;
    padding-bottom: 50px;
}

.sound-btn {
    background-color: #ffffff;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    padding: 10px;
    box-shadow: var(--shadow);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 160px;
    position: relative;
    overflow: hidden;
    outline: none;
}

.sound-btn:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: var(--shadow-hover);
}

.sound-btn:active {
    transform: scale(0.95);
}

.sound-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 10px;
    background-color: transparent;
    user-select: none;
    pointer-events: none;
}

.sound-btn span {
    font-size: 1.1rem;
    font-weight: 600;
    color: #555;
    text-align: center;
    z-index: 2;
}

/* Boutons texte uniquement */
.text-only {
    background: linear-gradient(135deg, #a8e6cf 0%, #dcedc1 100%);
}
.text-only span {
    color: #2d3436;
}

/* --- MODE FOCUS (3 CARTES) --- */
#focus-grid-wrapper {
    text-align: center;
    margin-top: 20px;
}

.focus-grid {
    display: flex;
    justify-content: center;
    gap: 30px;
    flex-wrap: wrap;
    margin-bottom: 30px;
    padding: 20px;
}

/* On force une taille plus grande pour les cartes du mode Focus */
.focus-grid .sound-btn {
    width: 220px;
    height: 220px;
}

.focus-grid .sound-btn img {
    border-radius: 15px;
}

.focus-grid .sound-btn span {
    font-size: 1.5rem;
}

#progress-indicator {
    font-size: 1.5rem;
    color: #7f8c8d;
    font-weight: bold;
    margin-top: 20px;
    background: white;
    padding: 10px 20px;
    border-radius: 20px;
    display: inline-block;
    box-shadow: var(--shadow);
}

/* --- BARRE DE JEU (GAME BAR) --- */
.game-bar {
    position: sticky;
    top: 0;
    background-color: #2d3436;
    color: white;
    padding: 15px 25px;
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    border-radius: 0 0 15px 15px;
    margin-bottom: 20px;
}

.left-controls {
    display: flex;
    align-items: center;
    gap: 20px;
}

#home-btn {
    background-color: #636e72;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
    font-size: 1rem;
    transition: background 0.2s;
}

#home-btn:hover {
    background-color: #b2bec3;
    color: #2d3436;
}

.score-display {
    font-size: 1.5rem;
    font-weight: bold;
    color: #ffd700; /* Or */
}

.game-controls {
    display: flex;
    align-items: center;
}

#replay-btn {
    display: none; /* géré par JS */
    background-color: #f1c40f;
    color: #2d3436;
    border: none;
    padding: 10px 20px;
    border-radius: 30px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s;
}

#replay-btn:hover {
    transform: scale(1.1);
    background-color: #f39c12;
}

#message-display {
    font-size: 1.2rem;
    font-weight: 600;
}

/* --- ANIMATIONS & FEEDBACK --- */

@keyframes shake {
    0% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
    100% { transform: translateX(0); }
}

@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.correct-answer {
    animation: pop 0.5s ease;
    border: 5px solid #2ecc71 !important;
    box-shadow: 0 0 20px rgba(46, 204, 113, 0.6);
}

.wrong-answer {
    animation: shake 0.4s ease;
    border: 5px solid #e74c3c !important;
}

/* --- ÉCRAN DE FIN (OVERLAY) --- */
.overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(0,0,0,0.85);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.5s;
}

.end-content {
    background: white;
    padding: 40px;
    border-radius: 30px;
    text-align: center;
    box-shadow: 0 0 50px rgba(255, 255, 255, 0.2);
    max-width: 400px;
    width: 90%;
}

.end-content h2 { 
    font-size: 2.5rem; 
    color: #2d3436; 
    margin-bottom: 20px; 
}

.final-score { 
    font-size: 3rem; 
    color: #f1c40f; 
    font-weight: bold; 
    margin-bottom: 30px; 
}

.end-content button {
    background-color: var(--secondary-color);
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: 1.3rem;
    border-radius: 50px;
    cursor: pointer;
    font-weight: bold;
    transition: transform 0.2s;
}

.end-content button:hover {
    transform: scale(1.05);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* --- RESPONSIVE --- */
@media (max-width: 600px) {
    /* On garde tes réglages de base pour le header et la barre de jeu */
    .game-bar {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
    }
    
    .left-controls {
        width: 100%;
        justify-content: space-between;
    }

    /* LA MAGIE ICI : */
    .focus-grid {
        /* On descend le minmax à 140px pour laisser la place à 2 colonnes 
           sur les écrans de ~360px de large */
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important;
        gap: 15px;
        padding: 10px;
    }

    .focus-grid .sound-btn {
        width: 100%;    /* Elle s'adapte à la colonne */
        height: 150px;  /* Hauteur plus raisonnable pour mobile */
    }

    .focus-grid .sound-btn span {
        font-size: 1.1rem;
    }
}

/* Grille spécifique pour le Memory (4x4) */
.memory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr); /* 4 colonnes */
    gap: 10px;
    max-width: 600px;
    margin: 0 auto;
}

/* Style des cartes Memory */
.memory-card {
    aspect-ratio: 1; /* Carré parfait */
    background-color: #2c3e50; /* Couleur dos de carte */
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2rem;
    border: 3px solid #fff;
    transition: transform 0.2s;
}

.memory-card.flipped {
    background-color: #fff; /* Fond blanc quand retournée */
    transform: rotateY(180deg); /* Petit effet sympa (optionnel) */
}

/* Cache l'image quand la carte n'est pas retournée */
.memory-card img {
    display: none;
    width: 80%;
    height: 80%;
    object-fit: contain;
}

/* Affiche l'image quand la classe 'flipped' est là */
.memory-card.flipped img {
    display: block;
}

/* Cache le point d'interrogation quand retournée */
.memory-card.flipped .back-icon {
    display: none;
}

/* Le bouton Memory en NOIR comme demandé ! */
.mode-memory {
    background-color: #000000 !important;
    color: #ffffff; /* Texte en blanc pour qu'on puisse lire */
    border: 2px solid #333;
}

/* Un petit effet gris foncé quand on passe la souris dessus */
.mode-memory:hover {
    background-color: #333333 !important;
    transform: scale(1.05);
}



/* Ajustement pour que la grille s'adapte au nombre de cartes */
.focus-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    max-width: 1000px;
    margin: 0 auto;
}

/* Amélioration du conteneur pour mobile */
.quiz-difficulty-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 200px; /* Aligné sur la largeur de tes boutons .menu-btn */
}

/* Le sélecteur de difficulté */
.difficulty-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #ffffff;
    padding: 15px;
    border-radius: 20px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    
    /* Positionnement corrigé */
    position: absolute;
    top: 50%; /* On le fait apparaître un peu par-dessus le bouton */
    left: 50%;
    transform: translateX(-50%);
    width: 180px;
    z-index: 100; /* Force l'affichage au-dessus de tout */
    border: 3px solid #ff9f43;
}

/* On ajoute un petit fondu pour l'apparition */
.difficulty-options.hidden {
    display: none !important;
}

/* Style des boutons de difficulté pour qu'ils soient faciles à cliquer au doigt */
.diff-btn {
    border: none;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    font-family: 'Fredoka', sans-serif;
    font-weight: bold;
    font-size: 1rem;
    color: white;
    box-shadow: 0 4px 0 rgba(0,0,0,0.1);
}

/* --- Couleurs des niveaux de difficulté --- */

/* Niveau Débutant (Vert) */
.diff-btn.easy {
    background-color: #2ecc71; 
}
.diff-btn.easy:hover {
    background-color: #27ae60;
}

/* Niveau Intermédiaire (Orange) */
.diff-btn.medium {
    background-color: #f39c12; 
}
.diff-btn.medium:hover {
    background-color: #d35400;
}

/* Niveau Expert (Rouge) */
.diff-btn.expert {
    background-color: #e74c3c; 
}
.diff-btn.expert:hover {
    background-color: #c0392b;
}

/* Ajustement spécifique pour mobile */
@media (max-width: 600px) {
    .difficulty-options {
        top: 10%; /* Remonte le menu pour qu'il ne sorte pas du bas de l'écran */
        width: 160px;
    }
}

/* --- Styles des boutons de fin --- */

.end-buttons-wrapper {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap; /* Pour passer à la ligne sur petit écran */
}

.action-btn {
    border: none;
    padding: 15px 25px;
    font-size: 1.1rem;
    border-radius: 50px;
    cursor: pointer;
    font-weight: bold;
    transition: transform 0.2s;
    font-family: 'Fredoka', sans-serif;
    color: white;
}

.action-btn:hover {
    transform: scale(1.05);
}

/* Bouton Rejouer (Jaune/Orange) */
.action-btn.replay {
    background-color: #f1c40f; 
}

/* Bouton Menu (Gris/Bleu) */
.action-btn.home {
    background-color: #34495e; 
}

/* On s'assure que le wrapper du memory se comporte comme celui du quiz */
.memory-difficulty-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 200px;
}

/* On applique le style memory-selector identique au difficulty-selector */
#memory-selector {
    border: 3px solid #333; /* Bordure foncée pour rappeler le thème Memory */
}

/* --- MODE STAND DE TIR (SHOOTING) --- */

.mode-shooting {
    background: linear-gradient(135deg, #eb3b5a, #fa8231);
}

/* Le conteneur de la scène avec perspective 3D */
#shooting-stage-wrapper {
    position: relative;
    width: 100%;
    height: 60vh; /* Prend une bonne partie de l'écran */
    overflow: hidden;
    margin-top: 20px;
}

#shooting-stage {
    position: relative;
    width: 100%;
    height: 100%;
    /* Perspective pour l'effet 3D */
    perspective: 800px;
    background-color: #dfe6e9; /* Fond du stand */
    border-radius: 20px;
    border-bottom: 10px solid #b2bec3; /* Effet de sol */
    box-shadow: inset 0 0 50px rgba(0,0,0,0.1);
    cursor: crosshair; /* Curseur en forme de viseur */
}

/* Barre de temps */
#time-bar-container {
    width: 80%;
    height: 10px;
    background: #bdc3c7;
    border-radius: 5px;
    margin: 0 auto 15px auto;
    overflow: hidden;
}

#time-bar {
    height: 100%;
    background: #e74c3c;
    width: 100%;
    /* L'animation sera gérée par JS ou CSS class */
    transform-origin: left;
}

/* La Cible (carte style carton) */
.target-card {
    position: absolute;
    width: 120px;
    height: 120px;
    background: white;
    border: 4px solid white;
    border-radius: 10px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
    cursor: crosshair;
    
    /* Centrer l'image */
    display: flex;
    justify-content: center;
    align-items: center;
    
    /* Animation d'apparition 3D */
    transform-origin: bottom center; /* Ça pivote depuis le bas */
    animation: popUp3D 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    touch-action: none;          /* Empêche le scroll sur la cible */
    user-select: none;           /* Empêche de sélectionner l'image */
    -webkit-tap-highlight-color: transparent; /* Retire le carré bleu au clic sur iPhone */
}

.target-card img {
    width: 90%;
    height: 90%;
    object-fit: contain;
    pointer-events: none;        /* Important pour que le clic touche la carte et non l'image */

}

/* Animation d'apparition : Couché -> Debout */
@keyframes popUp3D {
    0% { transform: rotateX(90deg) scale(0.5); opacity: 0; }
    100% { transform: rotateX(0deg) scale(1); opacity: 1; }
}

/* Animation de disparition (quand touché) */
@keyframes fallDown {
    0% { transform: rotateX(0deg); }
    100% { transform: rotateX(-90deg); opacity: 0; }
}

.hit-target {
    border-color: #2ecc71 !important;
    background-color: #2ecc71 !important;
    animation: fallDown 0.3s forwards !important;
}

.missed-target {
    filter: grayscale(100%);
    opacity: 0.5;
}

/* Responsive pour mobile */
@media (max-width: 600px) {
    .target-card {
        width: 80px;
        height: 80px;
    }
}

/* --- NOUVEAUX EFFETS VISUELS TIR --- */

/* 1. L'effet d'impact "POW!" */
.impact-puff {
    position: absolute;
    width: 40px;
    height: 40px;
    background: radial-gradient(circle, #fff 30%, #f1c40f 70%); /* Blanc au centre, jaune autour */
    border-radius: 50%; /* Rond */
    transform: translate(-50%, -50%) scale(0); /* Centré sur le clic, commence petit */
    pointer-events: none; /* Le clic passe au travers */
    z-index: 100; /* Devant tout */
    animation: bangEffect 0.4s ease-out forwards;
    box-shadow: 0 0 10px #f1c40f;
}

@keyframes bangEffect {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(2.5); opacity: 0; } /* Grossit et disparaît */
}

/* 2. La secousse d'écran (Screen Shake) */
.shake-stage {
    animation: shakeAnim 0.3s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shakeAnim {
  10%, 90% { transform: translate3d(-3px, 0, 0); }
  20%, 80% { transform: translate3d(3px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-5px, 0, 0); }
  40%, 60% { transform: translate3d(5px, 0, 0); }
}

/* 3. Amélioration de l'animation de chute de la cible */
/* Remplace l'ancienne @keyframes fallDown par celle-ci : */
@keyframes fallDown {
    0% { transform: rotateX(0deg) translateY(0); }
    30% { transform: rotateX(-30deg) translateY(-15px); } /* Petit saut vers le haut au début */
    100% { transform: rotateX(-100deg) translateY(30px); opacity: 0; } /* Tombe plus loin en arrière */
}

/* Effet de vitre brisée */
.shatter {
    animation: shatter-effect 0.5s ease-out forwards;
    pointer-events: none; /* Empêche de cliquer deux fois */
}

@keyframes shatter-effect {
    0% {
        transform: scale(1);
        opacity: 1;
        filter: contrast(1.5) brightness(1.2);
    }
    20% {
        transform: scale(1.1) rotate(2deg);
        clip-path: polygon(50% 50%, 0% 0%, 100% 0%, 100% 100%, 0% 100%, 0% 0%);
    }
    100% {
        transform: scale(1.5);
        opacity: 0;
        filter: blur(5px);
    }
}

/* Optionnel : ajout d'un flash blanc au moment du tir */
.flash {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: white;
    opacity: 0;
    pointer-events: none;
    z-index: 10;
}
.flash-active {
    animation: flash-anim 0.2s ease-out;
}
@keyframes flash-anim {
    0% { opacity: 0.8; }
    100% { opacity: 0; }
}