:root { 
    --accent: #198754; 
    --accent-hover: #157347;
    --bg: #f4f7f9; 
    --gray: #495057; 
    --card-bg: #ffffff;
    --star-gold: #ffc107;
    --fire-orange: #fd7e14;
    --heart-red: #dc3545;
    --level-easy: #20c997;
    --level-medium: #ffc107;
    --level-hard: #fd7e14;
    --level-genius: #d63384;
}

* {
    box-sizing: border-box;
}

body { 
    background-color: var(--bg); 
    font-family: 'Poppins', 'Tajawal', 'Segoe UI', Tahoma, sans-serif; 
    display: flex; 
    flex-direction: column; 
    min-height: 100vh; 
    margin: 0; 
    padding: 15px; 
    box-sizing: border-box; 
    color: #2d3748;
}

.main-content { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    justify-content: center; 
    align-items: center; 
    margin-top: 85px !important;
    width: 100%;
}

.card { 
    background: var(--card-bg); 
    padding: 35px 25px; 
    border-radius: 25px; 
    box-shadow: 0 10px 40px rgba(0,0,0,0.06); 
    width: 100%; 
    max-width: 950px; 
    text-align: center; 
    border-top: 6px solid var(--accent); 
    box-sizing: border-box; 
    position: relative; 
    overflow: hidden;
}

.logo { 
    max-width: 100%; 
    width: 420px; 
    height: auto; 
    margin: 0 auto 15px auto; 
    display: block; 
}

.page-title { 
    font-family: 'Poppins', 'Tajawal', sans-serif; 
    color: #212529 !important; 
    margin: 0 auto 10px auto; 
    font-weight: 700; 
    font-size: clamp(22px, 5vw, 32px); 
    line-height: 1.3; 
    letter-spacing: -0.2px; 
}

.page-subtitle {
    font-size: 16px;
    color: #6c757d;
    margin-top: 0;
    margin-bottom: 25px;
    font-weight: 500;
}

/* --- HUD TOP BAR (Vies, Étoiles, Combo, Score) --- */
.game-hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 20px;
    padding: 12px 20px;
    margin-bottom: 25px;
    flex-wrap: wrap;
    gap: 12px;
}

.hud-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 18px;
    background: white;
    padding: 8px 16px;
    border-radius: 50px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    border: 1px solid #e9ecef;
}

.hud-item.lives-container {
    color: var(--heart-red);
}

.heart-icon {
    display: inline-block;
    transition: transform 0.2s ease;
    font-size: 22px;
}

.heart-icon.lost {
    opacity: 0.25;
    transform: scale(0.8);
    filter: grayscale(1);
}

.heart-pop {
    animation: heartBeat 0.4s ease-in-out;
}

@keyframes heartBeat {
    0% { transform: scale(1); }
    50% { transform: scale(1.4); }
    100% { transform: scale(1); }
}

.hud-item.stars-container {
    color: #d39e00;
}

.hud-item.streak-container {
    color: var(--fire-orange);
    position: relative;
}

.streak-active {
    animation: flamePulse 1s infinite alternate;
}

@keyframes flamePulse {
    from { transform: scale(1); filter: drop-shadow(0 0 2px rgba(253, 126, 20, 0.4)); }
    to { transform: scale(1.1); filter: drop-shadow(0 0 8px rgba(253, 126, 20, 0.8)); }
}

.hud-item.score-container {
    color: var(--accent);
}

/* --- OPTIONS DE CONFIGURATION (Opérations, Difficulté, Chrono, Sons) --- */
.game-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 25px;
    background: #f8f9fa;
    padding: 18px;
    border-radius: 20px;
    border: 1px dashed #ced4da;
}

.control-group {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.control-label {
    font-weight: 700;
    font-size: 14px;
    color: #495057;
    margin-right: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pill-btn {
    background: white;
    border: 2px solid #dee2e6;
    color: #495057;
    padding: 8px 16px;
    border-radius: 50px;
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.pill-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-2px);
}

.pill-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    box-shadow: 0 4px 12px rgba(25, 135, 84, 0.25);
}

/* Couleurs par niveau de difficulté */
.pill-btn.diff-1.active { background: var(--level-easy); border-color: var(--level-easy); }
.pill-btn.diff-2.active { background: var(--level-medium); border-color: var(--level-medium); color: #212529; }
.pill-btn.diff-3.active { background: var(--level-hard); border-color: var(--level-hard); }
.pill-btn.diff-4.active { background: var(--level-genius); border-color: var(--level-genius); }

.toggle-btn {
    background: #e9ecef;
    border: 2px solid #ced4da;
    padding: 8px 18px;
    border-radius: 50px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.toggle-btn.active {
    background: #0d6efd;
    color: white;
    border-color: #0d6efd;
}

/* --- BARRE DE PROGRESSION DU TEMPS --- */
.timer-bar-container {
    width: 100%;
    height: 14px;
    background: #e9ecef;
    border-radius: 20px;
    overflow: hidden;
    margin-bottom: 25px;
    position: relative;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

.timer-bar-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #20c997, #ffc107, #dc3545);
    background-size: 200% 100%;
    border-radius: 20px;
    transition: width 0.1s linear;
}

.timer-bar-fill.warning {
    animation: timerBlink 0.5s infinite alternate;
}

@keyframes timerBlink {
    from { opacity: 1; }
    to { opacity: 0.5; }
}

/* --- ZONE DE CALCUL (QUESTION) --- */
.question-card {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border: 3px solid #dee2e6;
    border-radius: 25px;
    padding: 30px 20px;
    margin-bottom: 25px;
    position: relative;
    box-shadow: 0 8px 20px rgba(0,0,0,0.04);
}

.mascot-avatar {
    font-size: 45px;
    margin-bottom: 10px;
    display: inline-block;
    animation: floatMascot 3s ease-in-out infinite alternate;
}

@keyframes floatMascot {
    from { transform: translateY(0); }
    to { transform: translateY(-8px); }
}

.equation-text {
    font-size: clamp(32px, 8vw, 54px);
    font-weight: 800;
    color: #1a252f;
    letter-spacing: 2px;
    margin: 10px 0;
    font-family: 'Poppins', sans-serif;
}

.equation-operator {
    color: var(--accent);
    padding: 0 6px;
}

/* --- GRILLE DE REPONSES (4 BOUTONS) --- */
.answers-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 25px;
}

.answer-btn {
    background: white;
    border: 3px solid #ced4da;
    border-radius: 20px;
    padding: 22px 15px;
    font-size: clamp(24px, 5vw, 36px);
    font-weight: 800;
    color: #212529;
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 6px 0 #ced4da, 0 10px 15px rgba(0,0,0,0.05);
    outline: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.answer-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-3px);
    box-shadow: 0 9px 0 var(--accent), 0 12px 20px rgba(0,0,0,0.1);
}

.answer-btn:active {
    transform: translateY(3px);
    box-shadow: 0 3px 0 var(--accent);
}

/* Effets visuels de réponse */
.answer-btn.correct {
    background-color: #d1e7dd !important;
    border-color: #198754 !important;
    color: #0f5132 !important;
    box-shadow: 0 6px 0 #198754 !important;
    animation: correctBounce 0.4s ease;
}

.answer-btn.wrong {
    background-color: #f8d7da !important;
    border-color: #dc3545 !important;
    color: #842029 !important;
    box-shadow: 0 6px 0 #dc3545 !important;
    animation: shakeError 0.4s ease;
}

@keyframes correctBounce {
    0% { transform: scale(1); }
    40% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

@keyframes shakeError {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-10px); }
    40%, 80% { transform: translateX(10px); }
}

/* --- BANNIERE DE FEEDBACK --- */
.feedback-banner {
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    border-radius: 15px;
    margin-bottom: 20px;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    transform: translateY(10px);
}

.feedback-banner.show {
    opacity: 1;
    transform: translateY(0);
}

.feedback-banner.success {
    background: #d1e7dd;
    color: #0f5132;
    border: 1px solid #badbcc;
}

.feedback-banner.error {
    background: #f8d7da;
    color: #842029;
    border: 1px solid #f5c2c7;
}

/* --- SECTION TROPHÉES ET BADGES --- */
.trophies-section {
    margin-top: 35px;
    background: #f8f9fa;
    border-radius: 20px;
    padding: 25px 20px;
    border: 1px solid #e9ecef;
}

.trophies-title {
    font-size: 20px;
    font-weight: 700;
    color: #212529;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.trophies-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 12px;
}

.trophy-card {
    background: white;
    border: 2px solid #e9ecef;
    border-radius: 16px;
    padding: 12px 8px;
    text-align: center;
    transition: all 0.2s ease;
    opacity: 0.4;
    filter: grayscale(0.8);
}

.trophy-card.unlocked {
    opacity: 1;
    filter: grayscale(0);
    border-color: #ffc107;
    box-shadow: 0 4px 12px rgba(255, 193, 7, 0.2);
    background: #fffdf5;
}

.trophy-icon {
    font-size: 32px;
    margin-bottom: 5px;
}

.trophy-name {
    font-size: 13px;
    font-weight: 700;
    color: #333;
    line-height: 1.2;
}

.trophy-desc {
    font-size: 11px;
    color: #6c757d;
    margin-top: 3px;
}

/* --- MODAL FIN DE PARTIE / GAME OVER --- */
.game-over-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    padding: 20px;
}

.game-over-modal.show {
    opacity: 1;
    visibility: visible;
}

.game-over-card {
    background: white;
    border-radius: 25px;
    padding: 35px 25px;
    width: 100%;
    max-width: 480px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.2);
    border-top: 8px solid var(--accent);
    transform: scale(0.8);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.game-over-modal.show .game-over-card {
    transform: scale(1);
}

.game-over-icon {
    font-size: 65px;
    margin-bottom: 10px;
}

.game-over-title {
    font-size: 26px;
    font-weight: 800;
    color: #212529;
    margin-bottom: 15px;
}

.stats-summary-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin: 20px 0;
}

.stat-box {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 15px;
    padding: 12px;
}

.stat-val {
    font-size: 22px;
    font-weight: 800;
    color: var(--accent);
}

.stat-lbl {
    font-size: 12px;
    color: #6c757d;
    font-weight: 600;
}

.btn-restart {
    background-color: var(--accent) !important;
    color: white !important;
    border: none;
    padding: 14px 30px;
    border-radius: 50px;
    cursor: pointer;
    font-weight: 800;
    font-size: 18px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px rgba(25, 135, 84, 0.3);
    width: 100%;
    margin-top: 10px;
}

.btn-restart:hover {
    background-color: var(--accent-hover) !important;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(25, 135, 84, 0.4);
}

/* --- CANVAS CONFETTI OVERLAY --- */
#confettiCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10001;
}

/* --- NAVBAR & GLOBAL UI (Rétention stricte du design fourni) --- */
.top-navbar {
    width: 100%;
    background-color: #ffffff;
    position: fixed;
    top: 0;
    left: 0;
    height: 60px;
    display: flex;
    align-items: center;
    z-index: 9999;
    border-bottom-left-radius: 17px;  
    border-bottom-right-radius: 17px;
    border-bottom: 2px solid var(--accent) !important; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.nav-container {
    width: 100%;
    padding: 0 15px;
    display: flex;
    justify-content: center !important;
    align-items: center;
    position: relative;
    height: 100%;
}

.nav-center {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

.nav-links {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 35px;
}

.nav-links a {
    text-decoration: none;
    color: #4a5568;
    font-weight: 600;
    transition: 0.3s;
    white-space: nowrap;
    font-size: 14px;
}

.nav-links a:hover, .nav-links a.active-link {
    color: var(--accent);
}

.menu-icon {
    display: none; 
    flex-direction: column;
    gap: 5px;
    cursor: pointer;
}

.menu-icon span {
    width: 30px;
    height: 4px;
    background-color: var(--accent);
    border-radius: 2px;
}

/* Dropdowns */
.dropdown-item {
  position: relative;
  display: inline-block;
}

.dropdown-btn {
  background: transparent;
  border: none;
  color: #4a5568;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.dropdown-btn:hover,
.dropdown-item:hover .dropdown-btn,
.dropdown-btn[aria-expanded="true"] {
  color: #198754;
  background-color: rgba(25, 135, 84, 0.08);
}

.dropdown-arrow {
  transition: transform 0.25s ease;
}

.dropdown-item:hover .dropdown-arrow,
.dropdown-btn[aria-expanded="true"] .dropdown-arrow {
  transform: rotate(180deg);
  stroke: #198754;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 8px;
  min-width: 210px;
  background-color: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
  padding: 8px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 10000;
}

@media (min-width: 769px) {
  .dropdown-item:hover .dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }
}

.dropdown-menu.show {
  opacity: 1 !important;
  visibility: visible !important;
  transform: translateY(0) !important;
}

.dropdown-link {
  display: flex !important;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  color: #334155 !important;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  border-radius: 8px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.dropdown-link:hover {
  background-color: rgba(25, 135, 84, 0.1);
  color: #198754 !important;
}

/* Footer & Modals */
footer { 
    text-align: center; 
    padding: 30px 20px; 
    font-size: 14px; 
    color: #212529 !important; 
    margin-top: 30px;
    display: flex;
    flex-direction: column; 
    gap: 10px;
    direction: ltr !important; 
    width: 100%;
    box-sizing: border-box;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 25px; 
    flex-wrap: wrap;
}

footer a { 
    color: #155724 !important; 
    text-decoration: underline !important; 
    cursor: pointer; 
    font-weight: 600; 
    transition: 0.3s;
}

footer a:hover { color: #28a745; text-decoration: underline; }

.modal { display: none; position: fixed; z-index: 10000; left: 0; top: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); overflow-y: auto; }
.modal-content { background: white; margin: 5% auto; padding: 30px; width: 90%; max-width: 700px; border-radius: 20px; text-align: left; line-height: 1.6; direction: ltr; }
.modal-content h2 { border-bottom: 2px solid var(--accent); padding-bottom: 10px; color: var(--accent); }
.close-btn { float: right; font-size: 28px; font-weight: bold; cursor: pointer; color: #6c757d; }
.close-btn:hover { color: #000; }

#toast {
    visibility: hidden;
    min-width: 250px;
    background-color: #28a745; 
    color: #fff;
    text-align: center;
    border-radius: 12px;
    padding: 16px;
    position: fixed;
    z-index: 10002;
    left: 50%;
    top: -100px; 
    transform: translateX(-50%);
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
    transition: top 0.4s, visibility 0.4s, opacity 0.4s;
    opacity: 0;
}

#toast.show {
    visibility: visible;
    top: 30px; 
    opacity: 1;
}

/* Media Queries Responsives */
@media (max-width: 768px) {
    .menu-icon {
        display: flex; 
    }

    .nav-links {
        display: none; 
        flex-direction: column;
        position: absolute;
        top: 65px; 
        left: 50%;
        transform: translateX(-50%);
        background: white;
        width: 280px;
        padding: 20px;
        border-radius: 20px;
        box-shadow: 0 10px 30px rgba(0,0,0,0.1);
        border: 1px solid #eee;
        z-index: 10000;
        gap: 15px;
    }

    .nav-links.active {
        display: flex !important;
    }

    .nav-links a {
        font-size: 15px !important;
        width: 100%;
        text-align: center;
        border-bottom: 1px solid #f1f1f1;
        padding-bottom: 6px;
        color: #2d3748 !important;
    }

    .dropdown-item { width: 100%; }
    .dropdown-btn { width: 100%; justify-content: center; }
    .dropdown-menu {
        position: static;
        opacity: 1;
        visibility: visible;
        transform: none;
        box-shadow: none;
        border: none;
        border-left: 2px solid #198754;
        border-radius: 0;
        margin-top: 4px;
        padding: 4px 0 4px 12px;
        background: transparent !important;
        display: none;
    }
    .dropdown-menu.show { display: block !important; }

    .game-hud {
        justify-content: center;
        padding: 10px;
    }

    .hud-item {
        font-size: 15px;
        padding: 6px 12px;
    }

    .answers-grid {
        grid-template-columns: 1fr;
    }

    .answer-btn {
        padding: 18px 10px;
        font-size: 28px;
    }

    .card {
        padding: 20px 15px;
    }
}
