/* === CSS VARIABLES & THEMES === */
:root {
    --bg: #f4f7f6;
    --text: #2c3e50;
    --primary: #3498db;
    --primary-dark: #2980b9;
    --card: #ffffff;
    --border: #e0e0e0;
    --success: #2ecc71;
    --error: #e74c3c;
    --shadow: 0 4px 6px rgba(0,0,0,0.1);
    --node-bg: #ecf0f1;
}

[data-theme="dark"] {
    --bg: #121212;
    --text: #e0e0e0;
    --primary: #2980b9;
    --primary-dark: #3700b3;
    --card: #1e1e1e;
    --border: #333333;
    --node-bg: #2c2c2c;
    --shadow: 0 4px 6px rgba(0,0,0,0.5);
}

/* === RESET & BASICS === */
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; }
body { background-color: var(--bg); color: var(--text); overflow-x: hidden; transition: background-color 0.3s, color 0.3s; display: flex; flex-direction: column; height: 100vh; }

/* === HEADER === */
header { display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; background-color: var(--card); box-shadow: var(--shadow); z-index: 10; }
header h1 { font-size: 1.2rem; margin: 0; }
.menu-btn { background: none; border: none; font-size: 1.5rem; color: var(--text); cursor: pointer; }

/* === SIDE PANEL === */
#side-panel { position: fixed; top: 0; left: -100%; width: 280px; height: 100%; background-color: var(--card); box-shadow: 2px 0 10px rgba(0,0,0,0.2); z-index: 100; transition: left 0.3s ease; padding: 20px; display: flex; flex-direction: column; gap: 20px; }
#side-panel.open { left: 0; }
.close-btn { align-self: flex-end; background: none; border: none; font-size: 1.5rem; color: var(--text); cursor: pointer; }
.setting-group { display: flex; flex-direction: column; gap: 10px; }
.setting-group label { font-weight: bold; font-size: 0.9rem; }
select, button.setting-btn { width: 100%; padding: 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 1rem; }
.about-btn { margin-top: auto; background-color: var(--primary); color: white; border: none; font-weight: bold; }
/* === TOGGLE SWITCH (Bouton coulissant) === */
.setting-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; font-weight: bold; }
.switch { position: relative; display: inline-block; width: 50px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--border); transition: .4s; border-radius: 34px; }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.2); }
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(22px); }        

/* === OVERLAY === */
#overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 50; display: none; }
#overlay.active { display: block; }

/* === MAIN SCREENS === */
main { flex: 1; display: flex; flex-direction: column; padding: 20px; position: relative; }
.screen { display: none; flex-direction: column; align-items: center; justify-content: center; flex: 1; text-align: center; animation: fadeIn 0.3s ease; }
.screen.active { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* === UI ELEMENTS === */
h2 { margin-bottom: 20px; font-size: 1.5rem; }
.btn { padding: 12px 24px; border-radius: 8px; border: none; background-color: var(--primary); color: white; font-size: 1.1rem; font-weight: bold; cursor: pointer; transition: transform 0.1s, background-color 0.2s; box-shadow: var(--shadow); width: 100%; max-width: 300px; margin: 10px 0; }
.btn:active { transform: scale(0.95); }
.btn-outline { background-color: transparent; border: 2px solid var(--primary); color: var(--primary); }

/* Stats Home */
.stats-box { background: var(--card); padding: 20px; border-radius: 12px; box-shadow: var(--shadow); width: 100%; max-width: 300px; margin-bottom: 30px; }
.stats-box p { margin: 10px 0; font-size: 1.1rem; }
.level-badge { display: inline-block; padding: 5px 10px; background: var(--primary); color: white; border-radius: 20px; font-weight: bold; font-size: 0.9rem; }

/* Path View (Memorize) */
.path-container { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px; margin-bottom: 30px; }
.node { background-color: var(--node-bg); padding: 10px 15px; border-radius: 20px; border: 2px solid var(--primary); font-weight: bold; }
.line { width: 20px; height: 3px; background-color: var(--primary); }

/* Timer Bar */
.timer-container { width: 100%; max-width: 300px; height: 10px; background-color: var(--node-bg); border-radius: 5px; overflow: hidden; margin-top: 20px; }
.timer-bar { width: 100%; height: 100%; background-color: var(--primary); transform-origin: left; }

/* Question Screens */
.qcm-grid { display: grid; grid-template-columns: 1fr; gap: 10px; width: 100%; max-width: 300px; }

/* Sequence Builder */
.sequence-slots { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; min-height: 50px; border: 2px dashed var(--border); padding: 15px; border-radius: 12px; margin-bottom: 20px; width: 100%; }
.slot { background-color: var(--primary); color: white; padding: 8px 12px; border-radius: 15px; font-weight: bold; font-size: 0.9rem; cursor: pointer; }
.word-bank { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-bottom: 20px; }
.word-btn { background-color: var(--node-bg); border: 2px solid var(--border); padding: 10px 15px; border-radius: 15px; font-weight: bold; cursor: pointer; color: var(--text); }
.word-btn.hidden { display: none; }

/* Results */
.result-icon { font-size: 4rem; margin-bottom: 15px; }
.success-text { color: var(--success); }
.error-text { color: var(--error); }

/* === CALCUL MENTAL === */
.math-formula { font-size: 3.5rem; font-weight: bold; margin: 30px 0; color: var(--primary); letter-spacing: 5px; }
.shake { animation: shake 0.4s; }
@keyframes shake { 0% { transform: translateX(0); } 25% { transform: translateX(-10px); } 50% { transform: translateX(10px); } 75% { transform: translateX(-10px); } 100% { transform: translateX(0); } }

/* === DASHBOARD & HEATMAP (A+C) === */
.kpi-container { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; width: 100%; max-width: 350px; margin-bottom: 20px; }
.kpi-box { flex: 1; min-width: 45%; background: var(--card); padding: 15px; border-radius: 10px; box-shadow: var(--shadow); text-align: center; }
.kpi-value { font-size: 1.8rem; font-weight: bold; color: var(--primary); }
.kpi-label { font-size: 0.8rem; opacity: 0.8; text-transform: uppercase; }

.heatmap-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; width: 100%; max-width: 350px; margin-bottom: 15px; }
.heat-cell { aspect-ratio: 1; border-radius: 4px; cursor: pointer; transition: transform 0.1s; background-color: var(--node-bg); display: flex; align-items: center; justify-content: center; font-weight: bold; color: white; font-size: 0.85rem; }
.heat-cell.success { background-color: var(--success); }
.heat-cell.fail { background-color: var(--error); }
.heat-cell:active { transform: scale(0.8); }

.heat-details { width: 100%; max-width: 350px; background: var(--card); padding: 15px; border-radius: 10px; border-left: 4px solid var(--primary); font-size: 0.9rem; min-height: 80px; display: flex; flex-direction: column; justify-content: center; }
/* Effet de sélection sur la Heatmap */
.heat-cell.selected {
    outline: 3px solid var(--primary); /* Utilise la couleur du texte (noir ou blanc selon le thème) */
    /*outline-offset: -3px; */
    /*transform: scale(1.1);  Un léger zoom pour bien la voir */
    z-index: 2; /* Pour que le zoom passe au-dessus des voisines */
    box-shadow: 0 0 10px rgba(0,0,0,0.3);
}

/* ========================================== */
/* STYLES MODALE SINAPSIA (LTM) - V2 (Scroll) */
/* ========================================== */

/* L'overlay */
.ltm-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85); /* Un peu plus sombre */
    display: flex; align-items: center; justify-content: center;
    z-index: 9999; padding: 10px; box-sizing: border-box;
}

/* Le conteneur principal : Flex Column pour gérer la hauteur */
.ltm-content {
    background: var(--card); color: var(--text);
    width: 100%; max-width: 500px; 
    /*height: 90vh;  Prend 90% de la hauteur de l'écran */
    max-height: 90vh;
    border-radius: 12px; box-shadow: var(--shadow);
    display: flex; flex-direction: column; /* Important ! */
    overflow: hidden; /* Empêche le débordement global */
}

/* En-tête (Fixe) */
.ltm-header {
    flex: 0 0 auto; /* Ne rétrécit pas */
    display: flex; justify-content: space-between; align-items: center;
    padding: 5px 20px; border-bottom: 1px solid var(--border);
    background: var(--node-bg); 
}
.ltm-header h2 { margin: 0; font-size: 1.2em; color: var(--primary-dark); }
.ltm-close-btn { background: none; border: none; font-size: 1.8em; color: var(--text); cursor: pointer; padding: 0; line-height: 1; }

/* Zone de l'application (Flexible) */
#ltm-app-container { 
    flex: 1; /* Prend tout l'espace restant */
    padding: 20px; 
    overflow-y: auto; /* Scrolle si le contenu (Quiz/Pres) est trop grand */
    display: flex; 
    flex-direction: column;
}

/* Stimulus et Images */
.ltm-stimulus { width: 100%; min-height: 100px; background: var(--node-bg); border-radius: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 1.2em; font-weight: bold; margin-bottom: 20px; text-align: center; overflow: hidden; flex: 0 0 auto;}
.ltm-stimulus img { height: 200px; object-fit: cover; }
.ltm-fallback-div { width: 100%; height: 200px; display: flex; align-items: center; justify-content: center; background: var(--node-bg); color: var(--text); }

/* Grille de choix */
.ltm-choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; flex: 0 0 auto; }
.ltm-choice-btn { 
    background: var(--card); border: 2px solid var(--primary); color: var(--primary); 
    padding: 10px; font-size: 1em; border-radius: 8px; cursor: pointer; transition: 0.2s; font-weight: bold; 
    display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 60px; overflow: hidden;
}
.ltm-choice-btn:hover:not(:disabled) { background: var(--primary); color: var(--card); }
.ltm-choice-btn img { height: 100px; aspect-ratio: 1 / 1; object-fit: cover; border-radius: 6px; margin: 0 auto; }

/* Feedback */
.ltm-choice-btn.correct { background: var(--success) !important; border-color: var(--success) !important; color: white !important; }
.ltm-choice-btn.wrong { background: var(--error) !important; border-color: var(--error) !important; color: white !important; }

/* Layout Spécifique ECRAN DE FIN (Fixe haut/bas, scroll milieu) */
#ltm-done-screen {
    display: none; /* Caché par défaut */
    flex-direction: column;
    height: 100%; /* Remplit le conteneur parent */
}

/* Partie haute du résumé (Fixe) */
.ltm-summary-top { flex: 0 0 auto; }
.ltm-summary-box { background: var(--node-bg); padding: 15px; border-radius: 8px; margin: 15px 0; border-left: 4px solid var(--success); }

/* Zone scrollable (Liste historique) */
.ltm-scrollable-list {
    flex: 1; /* Prend l'espace restant */
    overflow-y: auto; /* SCROLL ICI */
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 15px;
    background: var(--bg);
}

/* Bouton du bas (Fixe) */
.ltm-bottom-actions { flex: 0 0 auto; margin-top: auto; }

/* Liste Items */
#ltm-history-list { border-top: 1px solid var(--border) }
.ltm-history-item { padding: 10px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.ltm-history-item:last-child { border-bottom: none; }
.ltm-history-img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--node-bg); }
.ltm-badge { background: var(--primary); color: white; padding: 2px 6px; border-radius: 4px; font-size: 0.75em; margin-right: 5px;}

/* Divers */
.ltm-btn-large { background: var(--primary); color: white; border: none; padding: 15px; width: 100%; font-size: 1.1em; border-radius: 8px; cursor: pointer; font-weight: bold; }
.ltm-cheat { margin-top: 15px; padding: 8px; background: #dff0d8; color: #3c763d; border: 1px solid #d6e9c6; border-radius: 4px; font-size: 0.9em; text-align: center; }

        
/* --- TOAST NOTIFICATION --- */
.toast {
    position: fixed;
    bottom: 30px; /* Juste au dessus du footer */
    left: 50%;
    transform: translateX(-50%);
    background: var(--card);
    color: var(--text);
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease-in-out;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    text-align: center;
    white-space: nowrap;
}
.toast.show {
    opacity: 1;
}  
