@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600&display=swap');

/* Variables scopées au conteneur du jeu */
#gameCanvas {
    --bg-color: #e0f7fa;
    --primary: #43a047;
    --primary-dark: #2e7d32;
    --secondary: #a5d6a7;
    --accent: #ffca28;
    --text: #263238;
    --board-bg: #795548;
    --board-border: #5d4037;
    --cell-bg: #d7ccc8;
    --cell-shadow: inset 2px 2px 5px rgba(0,0,0,0.2);
    --cell-size: clamp(35px, 13vw, 60px);

    font-family: 'Fredoka', sans-serif;
    background: var(--bg-color);
    background-image: radial-gradient(#b2ebf2 15%, transparent 16%), radial-gradient(#b2ebf2 15%, transparent 16%);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
    color: var(--text);
    /* On force le conteneur à prendre de la place et à être relatif pour positionner les modales */
    width: 100%;
    min-height: 600px; /* Hauteur min pour le confort */
    position: relative;
    overflow: hidden; /* Important pour les confettis */
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    box-sizing: border-box;
}

#gameCanvas * { box-sizing: border-box; touch-action: manipulation; }

#gameCanvas h1 { 
    color: var(--primary-dark); margin: 5px 0; text-align: center; font-size: 2rem; 
    text-shadow: 2px 2px 0px rgba(255,255,255,0.5);
    line-height: 1.2;
}

#gameCanvas .subtitle { margin-bottom: 20px; color: #546e7a; text-align: center; font-size: 1rem; }

/* Boutons */
#gameCanvas .btn {
    background-color: var(--primary); color: white; border: none; padding: 12px 25px;
    border-radius: 15px; font-size: 1.1rem; font-family: 'Fredoka', sans-serif; cursor: pointer;
    box-shadow: 0 4px 0px var(--primary-dark); transition: transform 0.1s;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    text-decoration: none;
}
#gameCanvas .btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--primary-dark); }
#gameCanvas .btn-outline { background: white; color: var(--primary-dark); box-shadow: 0 4px 0 #ccc; border: 2px solid var(--primary-dark); }
#gameCanvas .btn-accent { background: var(--accent); color: #5d4037; box-shadow: 0 4px 0 #f57f17; }
#gameCanvas .btn-danger { background: #ef5350; box-shadow: 0 4px 0 #c62828; font-size: 0.9rem; margin-top: 40px;}

#gameCanvas .screen { display: none; width: 100%; max-width: 800px; flex-direction: column; align-items: center; animation: fadeIn 0.3s; z-index: 10; position: relative;}
#gameCanvas .screen.active { display: flex; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* --- Menu --- */
#gameCanvas .level-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(85px, 1fr)); gap: 12px; width: 100%; padding: 10px;
}
#gameCanvas .level-card {
    background: white; border-radius: 15px; padding: 10px 5px; text-align: center;
    box-shadow: 0 4px 0 rgba(0,0,0,0.1); cursor: pointer; border: 3px solid transparent; transition: all 0.2s;
}
#gameCanvas .level-card.unlocked:hover { transform: translateY(-3px); border-color: var(--primary); }
#gameCanvas .level-card.locked { opacity: 0.5; filter: grayscale(1); background: #eceff1; cursor: default; }
#gameCanvas .level-card.completed { border-color: var(--secondary); background: #f1f8e9; }
#gameCanvas .level-num { font-size: 1.4rem; font-weight: 600; color: var(--primary-dark); display: block; }
#gameCanvas .level-stars { font-size: 0.9rem; margin-top: 2px; height: 1.2em; letter-spacing: -2px; }
#gameCanvas .level-type { font-size: 0.7rem; color: #78909c; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block;}

/* --- Jeu --- */
#gameCanvas .game-header {
    display: flex; justify-content: space-between; align-items: center; width: 100%; margin-bottom: 15px;
    background: rgba(255,255,255,0.9); padding: 10px 20px; border-radius: 20px; box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}

#gameCanvas .timer-container { width: 100%; height: 8px; background: #ddd; border-radius: 4px; margin-bottom: 10px; overflow: hidden; display: none; }
#gameCanvas .timer-bar { height: 100%; background: linear-gradient(90deg, #ffeb3b, #f44336); width: 100%; transition: width linear; }

#gameCanvas .instruction-box {
    background-color: white; color: var(--text); padding: 10px 20px; border-radius: 15px; margin-bottom: 15px;
    font-weight: 600; text-align: center; width: 100%; border-bottom: 4px solid var(--secondary);
    display: flex; align-items: center; justify-content: center; gap: 10px;
}

#gameCanvas .game-board-area {
    display: flex; flex-wrap: nowrap; justify-content: center; align-items: stretch; gap: 0; margin-bottom: 20px;
}

#gameCanvas .board-container { 
    display: flex; flex-direction: column; align-items: center; 
    background: rgba(255,255,255,0.5); padding: 10px; border-radius: 20px;
    transition: background 0.3s;
}
#gameCanvas .board-label { font-weight: 600; margin-bottom: 8px; color: var(--primary-dark); text-transform: uppercase; letter-spacing: 1px; font-size: 0.8rem; }

#gameCanvas .grid {
    display: grid; gap: 4px; background-color: var(--board-bg); padding: 8px; border-radius: 12px;
    border-bottom: 6px solid var(--board-border); position: relative; box-shadow: 0 10px 20px rgba(0,0,0,0.2);
}

#gameCanvas .cell {
    width: var(--cell-size); height: var(--cell-size); background-color: var(--cell-bg);
    border-radius: 8px; display: flex; justify-content: center; align-items: center;
    font-size: calc(var(--cell-size) * 0.65); cursor: default; user-select: none;
    box-shadow: var(--cell-shadow); transition: transform 0.1s;
}

#gameCanvas .player-grid .cell { cursor: pointer; background-color: #efebe9; }
#gameCanvas .player-grid .cell:hover { background-color: #fff; }
#gameCanvas .player-grid .cell:active { transform: scale(0.9); }
#gameCanvas .pop-anim { animation: pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
@keyframes pop { 0% { transform: scale(0.5); } 100% { transform: scale(1); } }

#gameCanvas .hidden-model .cell { 
    color: transparent !important; text-shadow: none !important; 
    background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%239e9e9e' fill-opacity='0.2' fill-rule='evenodd'%3E%3Ccircle cx='3' cy='3' r='3'/%3E%3Ccircle cx='13' cy='13' r='3'/%3E%3C/g%3E%3C/svg%3E");
}

/* --- SEPARATEUR MIROIR ENTRE LES GRILLES --- */
#gameCanvas #mirror-separator {
    display: none;
    width: 6px;
    background: repeating-linear-gradient(180deg, #ffca28, #ffca28 10px, transparent 10px, transparent 20px);
    border-radius: 5px;
    margin: 40px 15px 10px 15px; 
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.2));
}
#gameCanvas .mode-mirror #mirror-separator { display: block; }

/* Toolbar */
#gameCanvas .toolbar {
    background: white; padding: 10px 15px; border-radius: 50px; box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; max-width: 100%;
    /* Modif: sticky relative to game container */
    position: sticky; bottom: 20px; z-index: 50;
}
#gameCanvas .tool {
    width: 50px; height: 50px; font-size: 28px; border: 2px solid #eee; border-radius: 50%;
    display: flex; justify-content: center; align-items: center; cursor: pointer; background: #fafafa;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
#gameCanvas .tool:hover { transform: scale(1.1); background: #fff; }
#gameCanvas .tool.active { border-color: var(--primary); background: #e8f5e9; transform: translateY(-10px) scale(1.1); box-shadow: 0 5px 10px rgba(0,0,0,0.2); }
#gameCanvas .cell.error { background-color: #ffcdd2 !important; animation: shake 0.4s; box-shadow: inset 0 0 0 2px #d32f2f; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* Modal - Modifié pour être absolute dans le conteneur et pas fixed */
#gameCanvas .modal-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px); display: none; justify-content: center; align-items: center; z-index: 100;
}
#gameCanvas .modal {
    background: white; padding: 40px 30px; border-radius: 30px; text-align: center; max-width: 400px; width: 90%;
    animation: popupModal 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
@keyframes popupModal { from {transform: scale(0.5); opacity: 0;} to {transform: scale(1); opacity: 1;} }
#gameCanvas .stars-result { font-size: 4rem; margin: 15px 0; text-shadow: 0 5px 0 rgba(0,0,0,0.1); }
#gameCanvas #modal-title { color: var(--primary-dark); margin: 0; font-size: 2rem; }

/* Canvas confettis en absolute */
#gameCanvas #confetti-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 99; }

/* --- RESPONSIVE : Passage en mode Mobile --- */
/* Note: J'applique le CSS responsive si l'écran est petit, mais aussi une classe de sécurité si besoin */
@media (max-width: 600px) {
    #gameCanvas .game-board-area { flex-direction: column; align-items: center; gap: 5px; }
    #gameCanvas .board-container { width: 100%; max-width: 350px; }
    
    #gameCanvas #mirror-separator {
        width: 60%; height: 6px; margin: 5px 0;
        background: repeating-linear-gradient(90deg, #ffca28, #ffca28 10px, transparent 10px, transparent 20px);
    }
    
    #gameCanvas .toolbar { padding: 8px 10px; gap: 5px; bottom: 10px; }
    #gameCanvas .tool { width: 42px; height: 42px; font-size: 22px; }
    #gameCanvas h1 { font-size: 1.5rem; }
}