/* --- 1. VARIABILI E BASE --- */
:root {
    --bg-color: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --text-main: #f8fafc;
    --gold: #fbbf24;
    --green: #10b981;
    --red: #ef4444;
    --blue: #38bdf8;
    --glass-border: rgba(255, 255, 255, 0.08);
    --nav-width: 260px;
    --nav-collapsed-width: 80px;
    --mobile-nav-height: 75px;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Cairo', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    direction: rtl;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}


/* --- 2. LAYOUT & WRAPPER --- */
.main-wrapper {
    width: 100%;
    max-width: 920px;
    margin: 0 auto;
    padding: 20px;
    padding-bottom: calc(var(--mobile-nav-height) + 28px);
    transition: margin-right 0.28s cubic-bezier(.2, .9, .3, 1), max-width 0.28s cubic-bezier(.2, .9, .3, 1);
}

@media (min-width: 1024px) {
    .main-wrapper {
        margin-right: var(--nav-width);
        max-width: calc(100% - var(--nav-width) - 40px);
        padding-bottom: 40px;
    }

    .app-navbar.collapsed~.main-wrapper {
        margin-right: var(--nav-collapsed-width);
        max-width: calc(100% - var(--nav-collapsed-width) - 40px);
    }
}

/* --- 3. CARDS (Glass) --- */
.card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 20px;
    border-radius: 18px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

/* --- 4. TOP-BAR (Quiz) --- */
.top-bar {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
    width: 100%;
}

.top-bar>* {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 1 auto;
}

.exit-btn {
    background: rgba(239, 68, 68, 0.08);
    color: var(--red);
    border: 1px solid rgba(239, 68, 68, 0.22);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
}

.lives-box,
#lives-display {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    font-weight: bold;
}

.timer-box,
.stat-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    font-weight: bold;
    gap: 5px;
    width: 30%;
}

.timer-box.timer-warning {
    color: var(--gold);
    border-color: rgba(251, 191, 36, 0.18);
    box-shadow: 0 6px 18px rgba(251, 191, 36, 0.06);
}

/* --- 5. PULSANTI E SELETTORI --- */
.challenge-btn {
    width: 100%;
    padding: 16px 18px;
    background: linear-gradient(135deg, #06b6d4 6%, #10b981 50%, #0ea5e9 100%);
    border: none;
    border-radius: 14px;
    color: white;
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(2, 6, 23, 0.5);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.challenge-btn:active {
    transform: translateY(1px) scale(.997);
}

.level-btn,
.num-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 10px 14px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    border: none;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.level-btn {
    color: #fff;
}

.num-btn {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
}

.level-btn:active,
.num-btn:active {
    transform: translateY(1px);
}

.level-btn.easy { background: var(--green); }
.level-btn.medium { background: var(--gold); }
.level-btn.hard { background: var(--red); }

.level-btn.easy, .level-btn.medium, .level-btn.hard{
    min-width: 20%;
    color: white;
}

/* --- STILE TASTO ELIMINA DATI --- */
.danger-btn {
    width: 50%;
    padding: 16px 18px;
    /* Gradiente sui toni del rosso e bordeaux per indicare pericolo */
    background: linear-gradient(135deg, #ef4444 0%, #991b1b 100%);
    border: none;
    border-radius: 14px;
    color: white;
    font-size: 17px;
    font-weight: 400;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(239, 68, 68, 0.2);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    margin-top: 20px; /* Spazio dal resto degli elementi */
}

.danger-btn:active {
    transform: translateY(1px) scale(.997);
    box-shadow: 0 5px 15px rgba(239, 68, 68, 0.3);
}

/* Opzionale: un leggero effetto al passaggio (se non sei su mobile) */
@media (hover: hover) {
    .danger-btn:hover {
        filter: brightness(1.1);
    }
}

/* --- 6. NUM-SELECTOR --- */
.num-selector {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 20px 0;
}

.num-btn {
    flex: 1;
    max-width: 130px;
    padding: 12px;
    border-radius: 12px;
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    cursor: pointer;
}

.num-btn.active {
    background: var(--gold);
    color: white;
    border-color: var(--gold);
}

/* --- 7. OPZIONI (risposte) --- */
.options-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 18px;
}

.option-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 12px 14px;
    border-radius: 12px;
    text-align: right;
    font-size: 15px;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s;
    width: 100%;
}

.option-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 22px rgba(2, 6, 23, 0.45);
}

@media (min-width: 1024px) {
    .options-grid {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 12px;
    }

    .option-btn {
        flex: 1 1 calc(50% - 12px);
        max-width: calc(50% - 12px);
        width: auto;
    }
}

/* --- 8. NAVBAR E SIDEBAR --- */
.app-navbar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--mobile-nav-height);
    background: linear-gradient(180deg, rgba(30, 41, 59, 0.9), rgba(17, 24, 39, 0.85));
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 6px 8px;
    z-index: 1100;
    border-top: 1px solid rgba(255, 255, 255, 0.02);
    backdrop-filter: blur(8px);
}

.nav-item {
    text-decoration: none;
    color: #94a3b8;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 20px;
    gap: 6px;
    padding: 6px 8px;
    min-width: 56px;
    min-height: 48px;
    border-radius: 10px;
    transition: transform 0.12s ease, background 0.12s ease;
}

.nav-item.active {
    color: var(--gold);
    position: relative;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 3px;
    background: linear-gradient(90deg, var(--gold), var(--blue));
    border-radius: 4px;
}

@media (min-width: 1024px) {
    .app-navbar {
        top: 0; right: 0; left: auto;
        width: var(--nav-width);
        height: 100vh;
        flex-direction: column;
        justify-content: flex-start;
        padding: 26px 12px;
        background: linear-gradient(180deg, rgba(4, 8, 20, 0.95), rgba(6, 10, 24, 0.85));
    }

    .nav-item {
        flex-direction: row-reverse;
        justify-content: flex-start;
        gap: 12px;
        padding: 12px;
        width: 100%;
    }

    .nav-item .nav-icon { font-size: 20px; width: 28px; text-align: center; }
    .nav-item .nav-label { font-size: 15px; font-weight: 600; color: #e6eef8; }

    .nav-item.active::before {
        left: 8px; top: 12px; bottom: 12px;
        width: 4px; height: auto;
        transform: none;
        background: linear-gradient(180deg, var(--gold), var(--blue));
    }

}

/* --- 9. TOGGLE SWITCHES (IMPOSTAZIONI) --- */
.switch {
    width: 48px; height: 28px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 999px;
    position: relative;
    display: inline-block;
    transition: background 0.18s ease;
}

.switch::after {
    content: "";
    position: absolute;
    width: 22px; height: 22px;
    background: white;
    border-radius: 50%;
    top: 3px; right: 3px;
    transition: 0.18s cubic-bezier(.2, .9, .3, 1);
}

input:checked+.switch { background: linear-gradient(90deg, var(--gold), var(--blue)); }
input:checked+.switch::after { right: auto; left: 3px; }

/* --- 10. PROFILE & PROGRESS --- */
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.profile-mini {
    background: rgba(255, 255, 255, 0.03);
    padding: 14px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    text-align: right;
}

.progress-track {
    width: 100%; height: 10px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 999px;
    margin-top: 10px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--gold), var(--blue));
    width: 0%;
    transition: width 0.36s ease;
}

/* --- 11. EXTRA TWEAKS --- */
.title { color: var(--gold); font-size: 22px; text-align: center; margin: 0 0 6px 0; }
.subtitle { color: #9fb0c6; font-size: 14px; margin: 6px 0; text-align: center; }

/* --- 12. AGGIUNTE PER FUNZIONALITÀ (STILE ORIGINALE) --- */

/* Selezione Topic */
#quiz-topic {
    width: 100%; 
    padding: 12px 15px; 
    font-size: 16px; 
    font-family: 'Cairo', sans-serif;
    color: var(--text-main); /* Testo bianco/chiaro */
    background-color: rgba(255, 255, 255, 0.05); /* Sfondo semi-trasparente */
    border: 1px solid var(--glass-border); 
    border-radius: 12px;
    cursor: pointer; 
    appearance: none; 
    -webkit-appearance: none;
    
    /* Freccia color Oro */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23fbbf24' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat; 
    background-position: left 15px center;
    
    text-align: right; 
    outline: none;
    transition: border-color 0.2s;
}

#quiz-topic:focus {
    border-color: var(--gold);
}

/* IMPORTANTE: Colore delle opzioni quando il menu si apre */
#quiz-topic option {
    background-color: #1e293b; /* Colore scuro coerente con --card-bg */
    color: white;
    padding: 10px;
}

/* Nuovo pulsante Inizia (Home) - Stile dorato coerente */
#main-start-btn {
    background: var(--gold) !important;
    color: #0f172a !important;
    font-weight: 900 !important;
    font-size: 22px !important;
    box-shadow: 0 6px 20px rgba(251, 191, 36, 0.2) !important;
}

/* Stato attivo per i pulsanti livello nelle impostazioni */
.level-btn.selected {
    border: 2px solid white !important;
    box-shadow: 0 0 15px rgba(255,255,255,0.2);
    transform: scale(1.02);
}

/* Fix SVG Livello */
#level-num { fill: #ffffff !important; }    
/*exit button*/
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.7); display: flex; align-items: center;
    justify-content: center; z-index: 9999; padding: 20px;
}
.modal-content {
    background: var(--card-bg); padding: 25px; border-radius: 15px;
    width: 100%; max-width: 400px; text-align: center; direction: rtl;
}
.modal-buttons { display: flex; gap: 10px; margin-top: 20px; }
.modal-btn {
    flex: 1; padding: 12px; border: none; border-radius: 8px;
    font-weight: bold; cursor: pointer;
}
.modal-btn.confirm { background: #22c55e; color: white; }
.modal-btn.cancel { background: #ef4444; color: white; }