@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap');

#gameCanvas #kb-game-wrapper {
    --primary: #667eea;
    --secondary: #764ba2;
    --accent: #48bb78; 
    --accent-hover: #38a169;
    --bg-grad: linear-gradient(135deg, #a18cd1 0%, #fbc2eb 100%);
    --text: #2d3748;
    --bg-card: rgba(255, 255, 255, 0.96);

    font-family: 'Poppins', sans-serif;
    background: var(--bg-grad);
    min-height: 650px;
    padding: 20px;
    display: flex; justify-content: center; align-items: center;
    width: 100%; position: relative;
    overflow: hidden;
}

#gameCanvas #kb-game-wrapper:fullscreen {
    width: 100vw; height: 100vh;
    border-radius: 0;
    align-items: center; justify-content: center;
    overflow-y: auto;
}

#gameCanvas .kb-container {
    width: 100%; max-width: 600px;
    display: flex; flex-direction: column; gap: 15px;
    position: relative; z-index: 2;
}

#gameCanvas .kb-screen { animation: fadeIn 0.4s ease; display: flex; flex-direction: column; align-items: center; width: 100%; }
#gameCanvas .hidden { display: none !important; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* HEADER */
#gameCanvas .kb-main-header { text-align: center; color: white; text-shadow: 0 2px 4px rgba(0,0,0,0.1); }
#gameCanvas .kb-title { font-size: 2rem; margin: 0; font-weight: 700; }
#gameCanvas .kb-subtitle { font-size: 1rem; opacity: 0.9; margin: 0; }

/* CARTES & EDITOR */
#gameCanvas .kb-card {
    background: var(--bg-card); padding: 30px; border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15); text-align: center;
    width: 100%; border: 1px solid rgba(255,255,255,0.5);
}
#gameCanvas .emoji-logo { font-size: 4rem; display: block; margin-bottom: 10px; animation: bounce 2s infinite; }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }

#gameCanvas .level-badges { display: flex; gap: 8px; justify-content: center; margin: 20px 0; flex-wrap: wrap; }
#gameCanvas .badge { padding: 5px 12px; border-radius: 15px; font-size: 0.8rem; font-weight: bold; color: white; }
#gameCanvas .badge.green { background: #48bb78; }
#gameCanvas .badge.yellow { background: #ecc94b; color: #744210; }
#gameCanvas .badge.red { background: #f56565; }

/* EDITOR STYLES */
#gameCanvas .editor-card { padding: 20px; text-align: left; }
#gameCanvas .editor-card h2 { text-align: center; margin-top: 0; color: var(--secondary); }
#gameCanvas .editor-inputs { background: #f7fafc; padding: 15px; border-radius: 12px; border: 1px solid #e2e8f0; margin-bottom: 15px; }
#gameCanvas .input-row { display: flex; gap: 10px; }
#gameCanvas .input-group { display: flex; flex-direction: column; margin-bottom: 10px; width: 100%; }
#gameCanvas .input-group.small { width: 80px; flex-shrink: 0; }
#gameCanvas .input-group label { font-size: 0.8rem; font-weight: 600; color: #718096; margin-bottom: 4px; }
#gameCanvas .kb-input {
    padding: 8px 12px; border: 2px solid #cbd5e0; border-radius: 8px;
    font-size: 1rem; outline: none; transition: 0.2s; font-family: inherit;
}
#gameCanvas .kb-input:focus { border-color: var(--primary); background: white; }
#gameCanvas .kb-input.center-text { text-align: center; }
#gameCanvas .cursor-pointer { cursor: pointer; background-color: #fff; }
#gameCanvas .cursor-pointer:hover { background-color: #ebf4ff; border-color: var(--primary); }

/* LISTE PERSO */
#gameCanvas .custom-list-container { 
    max-height: 150px; overflow-y: auto; 
    border: 1px solid #e2e8f0; border-radius: 8px; margin-bottom: 15px;
    background: white; 
}
#gameCanvas #custom-list-view { list-style: none; padding: 0; margin: 0; }
#gameCanvas .custom-item { 
    display: flex; justify-content: space-between; align-items: center; 
    padding: 8px 12px; border-bottom: 1px solid #f1f5f9; 
}
#gameCanvas .custom-item:last-child { border-bottom: none; }
#gameCanvas .custom-item span { font-weight: 600; color: var(--text); }
#gameCanvas .btn-del { background: none; border: none; cursor: pointer; font-size: 1rem; opacity: 0.6; }
#gameCanvas .btn-del:hover { opacity: 1; transform: scale(1.1); }
#gameCanvas .empty-msg { padding: 15px; text-align: center; color: #a0aec0; font-style: italic; font-size: 0.9rem; }
#gameCanvas .editor-actions { display: flex; flex-direction: column; gap: 10px; }

/* EMOJI PICKER FLOTTANT (AMÉLIORÉ) */
#gameCanvas .emoji-picker {
    position: absolute;
    top: 75px; left: 0;
    width: 280px;
    background: white;
    border: 1px solid #cbd5e0;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.25);
    z-index: 100;
    padding: 10px;
}
#gameCanvas .picker-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 8px; border-bottom: 1px solid #f1f5f9; padding-bottom: 5px;
    font-size: 0.8rem; font-weight: bold; color: #718096;
}
#gameCanvas .picker-close { background: none; border: none; color: #e53e3e; cursor: pointer; font-weight: bold; }

/* BARRE DE RECHERCHE EMOJI */
#gameCanvas .emoji-search-input {
    width: 100%;
    padding: 6px 10px;
    margin-bottom: 8px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font-size: 0.9rem;
    outline: none;
}
#gameCanvas .emoji-search-input:focus { border-color: var(--primary); }

/* GRILLE FLEXIBLE (Règle le problème de scroll horizontal) */
#gameCanvas .emoji-grid {
    display: grid;
    /* Adapte le nombre de colonnes à la largeur dispo. Min 36px par emoji */
    grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); 
    gap: 5px;
    max-height: 200px;
    overflow-y: auto;
    overflow-x: hidden; /* Empêche le scroll latéral */
    padding-right: 2px; /* Pour l'ascenseur */
}

#gameCanvas .emoji-btn {
    background: #f7fafc; border: 1px solid #edf2f7; border-radius: 8px;
    font-size: 1.4rem; cursor: pointer; padding: 4px;
    display: flex; justify-content: center; align-items: center;
    transition: transform 0.1s;
}
#gameCanvas .emoji-btn:hover { background: #ebf4ff; transform: scale(1.15); border-color: #bee3f8; }

/* BOUTONS */
#gameCanvas button { font-family: 'Poppins', sans-serif; cursor: pointer; transition: 0.2s; }
#gameCanvas .kb-btn-primary {
    background: linear-gradient(to right, var(--primary), var(--secondary));
    color: white; border: none; padding: 12px 30px; border-radius: 50px;
    font-size: 1.1rem; font-weight: bold; box-shadow: 0 4px 15px rgba(118, 75, 162, 0.3);
}
#gameCanvas .kb-btn-primary:hover { transform: translateY(-2px); }
#gameCanvas .kb-btn-primary.big { width: 100%; margin-top: 5px; }

#gameCanvas .kb-btn-secondary {
    background: white; border: 2px solid var(--primary); color: var(--primary);
    padding: 10px 25px; border-radius: 50px; font-weight: bold;
}
#gameCanvas .kb-btn-secondary:hover { background: #ebf4ff; }
#gameCanvas .kb-btn-secondary.big { width: 100%; }

#gameCanvas .kb-btn-success {
    background: var(--accent); color: white; border: none;
    padding: 8px 20px; border-radius: 12px; font-weight: bold;
}
#gameCanvas .kb-btn-success.small { width: 100%; padding: 8px; border-radius: 8px; font-size: 0.9rem; }
#gameCanvas .kb-btn-success:hover { background: var(--accent-hover); }

#gameCanvas .kb-btn-icon-abs {
    position: absolute; top: 10px; right: 10px;
    background: rgba(255,255,255,0.2); border: 1px solid rgba(255,255,255,0.4);
    color: var(--secondary); width: 36px; height: 36px; border-radius: 50%;
    display: flex; justify-content: center; align-items: center; font-size: 1.2rem;
}
#gameCanvas .kb-btn-icon {
    background: rgba(255,255,255,0.5); border: none; width: 32px; height: 32px; 
    border-radius: 50%; color: var(--text);
}
#gameCanvas .kb-btn-text { background: none; border: none; color: white; text-decoration: underline; margin-top: 10px; opacity: 0.8; font-size: 0.9rem; }

/* JEU UI */
#gameCanvas .kb-game-bar {
    display: flex; align-items: center; gap: 10px;
    background: rgba(255,255,255,0.9); padding: 10px 20px; border-radius: 15px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1); width: 100%;
}
#gameCanvas .kb-level-display { font-weight: bold; color: var(--secondary); font-size: 0.9rem; }
#gameCanvas .kb-score-box { font-weight: bold; color: #d69e2e; display: flex; align-items: center; gap: 5px; }

#gameCanvas .kb-progress-container { flex-grow: 1; height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden; }
#gameCanvas .kb-progress-bar { height: 100%; background: var(--accent); width: 0%; transition: width 0.3s; }

/* ZONE JEU */
#gameCanvas .kb-game-area {
    background: white; border-radius: 20px; padding: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    display: flex; flex-direction: column; align-items: center;
    width: 100%; border: 2px solid #e2e8f0;
}

#gameCanvas .kb-card-display { text-align: center; margin-bottom: 20px; }
#gameCanvas .kb-emoji-huge { font-size: 4rem; line-height: 1; animation: float 3s infinite ease-in-out; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

#gameCanvas .kb-hint-box {
    background: #edf2f7; padding: 5px 15px; border-radius: 20px;
    display: inline-flex; align-items: center; gap: 8px;
    color: #718096; font-size: 0.9rem; margin-top: 10px;
}

/* GRILLE MOTS */
#gameCanvas .word-grid { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-bottom: 20px; min-height: 50px; }
#gameCanvas .letter-box {
    width: 40px; height: 50px;
    background: #f7fafc; border-bottom: 4px solid #cbd5e0; border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; font-weight: bold; color: #a0aec0;
    transition: all 0.2s;
}
#gameCanvas .letter-box.active { background: white; border-color: var(--primary); color: var(--primary); transform: translateY(-2px); box-shadow: 0 4px 10px rgba(102, 126, 234, 0.2); }
#gameCanvas .letter-box.correct { background: var(--accent); border-color: #2f855a; color: white; transform: translateY(0); }

/* BOUTON SUIVANT */
#gameCanvas .kb-action-area { height: 50px; display: flex; align-items: center; justify-content: center; width: 100%; margin-bottom: 10px; }
#gameCanvas .kb-btn-success.hidden { display: none; }

/* CLAVIER */
#gameCanvas .keyboard-area { width: 100%; max-width: 500px; display: flex; flex-direction: column; gap: 5px; }
#gameCanvas .kb-row { display: flex; justify-content: center; gap: 4px; width: 100%; }
#gameCanvas .key-btn {
    width: 32px; height: 42px;
    background: white; border: 1px solid #cbd5e0; border-bottom-width: 3px;
    border-radius: 6px; font-size: 1rem; font-weight: bold; color: var(--text);
    padding: 0; display: flex; align-items: center; justify-content: center;
}
#gameCanvas .key-btn:active { border-bottom-width: 0px; transform: translateY(3px); }
#gameCanvas .key-btn.current { background: var(--primary); color: white; border-color: var(--primary-dark); }

/* CONFETTI & FINAL */
#gameCanvas #kb-confetti-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }
#gameCanvas .kb-final-score { font-size: 1.5rem; font-weight: bold; color: var(--primary); margin: 20px 0; }

.shake { animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both; }
@keyframes shake { 10%, 90% { transform: translateX(-1px); } 20%, 80% { transform: translateX(2px); } 30%, 50%, 70% { transform: translateX(-4px); } 40%, 60% { transform: translateX(4px); } }

@media (max-width: 500px) {
    #gameCanvas .kb-emoji-huge { font-size: 3rem; }
    #gameCanvas .key-btn { width: 28px; height: 38px; font-size: 0.9rem; }
    #gameCanvas .letter-box { width: 32px; height: 42px; font-size: 1.2rem; }
    #gameCanvas .emoji-picker { width: 220px; }
}