/* ===== RESET & BASE ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #0f172a;
    --bg2: #1e293b;
    --bg3: #334155;
    --surface: rgba(30, 41, 59, 0.85);
    --primary: #6366f1;
    --primary-light: #818cf8;
    --accent: #f59e0b;
    --accent2: #10b981;
    --danger: #ef4444;
    --text: #e2e8f0;
    --text2: #94a3b8;
    --text3: #64748b;
    --border: rgba(99, 102, 241, 0.2);
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 20px 50px rgba(0,0,0,0.4);
}

body {
    font-family: 'Nunito', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
}

a { color: var(--primary-light); text-decoration: none; transition: color 0.2s; }
a:hover { color: #fff; }

img { max-width: 100%; height: auto; }

/* ===== POPUP ===== */
.popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.2s;
}

.popup-overlay.hidden { display: none; }

.popup-box {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: var(--shadow);
    animation: popIn 0.3s ease-out;
}

.popup-icon { font-size: 2.5rem; margin-bottom: 12px; }
.popup-title { font-size: 1.2rem; font-weight: 800; margin-bottom: 8px; color: var(--text); }
.popup-message { font-size: 0.95rem; color: var(--text2); margin-bottom: 20px; line-height: 1.5; }

.popup-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.popup-btn {
    padding: 10px 28px;
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.popup-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(99, 102, 241, 0.3); }
.popup-btn:focus-visible { outline: 2px solid var(--primary-light); outline-offset: 2px; }

.popup-btn-danger {
    background: linear-gradient(135deg, #dc2626, var(--danger));
}

.popup-btn-cancel {
    background: var(--bg3);
}

.popup-btn-cancel:hover { background: #475569; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ===== NAVBAR ===== */
.navbar {
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-logo img { height: 44px; width: auto; }

.nav-links {
    display: flex;
    align-items: center;
    gap: 20px;
}

.nav-links a {
    color: var(--text2);
    font-weight: 600;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.nav-links a:hover { color: #fff; }

.nav-btn {
    padding: 8px 20px !important;
    border-radius: var(--radius-sm) !important;
    font-weight: 700 !important;
    font-size: 0.85rem !important;
    transition: all 0.2s !important;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #8b5cf6) !important;
    color: #fff !important;
}

.btn-outline {
    border: 2px solid var(--border) !important;
    color: var(--text2) !important;
}

.btn-outline:hover {
    border-color: var(--primary-light) !important;
    color: #fff !important;
}

.nav-user {
    color: var(--accent);
    font-weight: 700;
    font-size: 0.85rem;
}

.hamburger {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}

.hamburger span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: 0.3s;
}

/* ===== MAIN ===== */
.main-content {
    flex: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px;
    width: 100%;
}

/* ===== HERO ===== */
.hero {
    text-align: center;
    padding: 60px 20px;
}

.hero h1 {
    font-size: 2.8rem;
    font-weight: 900;
    margin-bottom: 16px;
    background: linear-gradient(135deg, var(--primary-light), var(--accent), var(--accent2));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.2;
}

.hero p {
    font-size: 1.15rem;
    color: var(--text2);
    max-width: 600px;
    margin: 0 auto 32px;
}

.hero-actions {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 14px 32px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-family: 'Nunito', sans-serif;
    font-size: 1rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    text-decoration: none;
    color: inherit;
}

.btn-lg { padding: 16px 40px; font-size: 1.05rem; }
.btn-sm { padding: 8px 16px; font-size: 0.85rem; }

.btn-primary-solid {
    background: linear-gradient(135deg, var(--primary), #8b5cf6);
    color: #fff;
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.3);
}

.btn-primary-solid:hover { transform: translateY(-2px); box-shadow: 0 12px 30px rgba(99, 102, 241, 0.4); color: #fff; }

.btn-ghost {
    background: transparent;
    color: var(--text2);
    border: 2px solid var(--border);
}

.btn-ghost:hover { border-color: var(--primary-light); color: #fff; }

.btn-success {
    background: linear-gradient(135deg, #059669, var(--accent2));
    color: #fff;
}

.btn-danger {
    background: linear-gradient(135deg, #dc2626, var(--danger));
    color: #fff;
}

/* ===== LEVEL CARDS ===== */
.levels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    margin-top: 48px;
}

.level-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    text-align: center;
    transition: transform 0.3s, box-shadow 0.3s;
}

.level-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow);
}

.level-icon { font-size: 2.5rem; margin-bottom: 12px; }
.level-card h3 { font-size: 1.2rem; font-weight: 800; margin-bottom: 8px; }
.level-card p { color: var(--text2); font-size: 0.9rem; }

/* ===== CARDS ===== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    margin-bottom: 24px;
    backdrop-filter: blur(12px);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.card-header h2 {
    font-size: 1.3rem;
    font-weight: 800;
}

/* ===== FORMS ===== */
.form-group { margin-bottom: 18px; }

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 0.9rem;
    color: var(--text2);
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(15, 23, 42, 0.6);
    color: var(--text);
    font-size: 0.95rem;
    font-family: 'Nunito', sans-serif;
    transition: border-color 0.3s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
}

textarea.form-control { resize: vertical; min-height: 100px; }

.form-auth {
    max-width: 440px;
    margin: 40px auto;
}

.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    text-align: left;
    padding: 12px 16px;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

tbody td {
    padding: 14px 16px;
    border-bottom: 1px solid rgba(99, 102, 241, 0.08);
    font-size: 0.95rem;
}

tbody tr:hover { background: rgba(99, 102, 241, 0.05); }

/* ===== RANKING ===== */
.rank-medal { font-size: 1.3rem; }

.rank-bar {
    height: 8px;
    background: var(--bg3);
    border-radius: 4px;
    overflow: hidden;
    min-width: 120px;
}

.rank-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 4px;
    transition: width 0.6s ease;
}

/* ===== QUIZ ===== */
.quiz-container { max-width: 700px; margin: 0 auto; }

.quiz-header {
    text-align: center;
    margin-bottom: 32px;
}

.quiz-progress {
    height: 6px;
    background: var(--bg3);
    border-radius: 3px;
    margin-bottom: 24px;
    overflow: hidden;
}

.quiz-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent2));
    border-radius: 3px;
    transition: width 0.4s;
}

.quiz-question {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 20px;
    padding: 20px;
    background: rgba(99, 102, 241, 0.08);
    border-radius: var(--radius-sm);
    border-left: 4px solid var(--primary);
}

.quiz-options { display: flex; flex-direction: column; gap: 12px; }

.quiz-option {
    padding: 16px 20px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 12px;
}

.quiz-option:hover {
    border-color: var(--primary-light);
    background: rgba(99, 102, 241, 0.1);
}

.quiz-option.selected {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.15);
}

.quiz-option.correct {
    border-color: var(--accent2) !important;
    background: rgba(16, 185, 129, 0.15) !important;
}

.quiz-option.wrong {
    border-color: var(--danger) !important;
    background: rgba(239, 68, 68, 0.1) !important;
}

.quiz-option-letter {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.quiz-nav {
    display: flex;
    justify-content: space-between;
    margin-top: 24px;
}

/* ===== STATS GRID ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
}

.stat-number {
    font-size: 2rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--primary-light), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.stat-label {
    color: var(--text3);
    font-size: 0.85rem;
    font-weight: 600;
    margin-top: 4px;
}

/* ===== ADMIN NAV ===== */
.admin-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.admin-nav a {
    padding: 10px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text2);
    font-weight: 700;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.admin-nav a:hover, .admin-nav a.active {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--primary);
    color: #fff;
}

/* ===== BADGES ===== */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
}

.badge-primaire { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.badge-college  { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.badge-lycee    { background: rgba(16, 185, 129, 0.15); color: #34d399; }

/* ===== ACTIONS ROW ===== */
.actions-row {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

/* ===== QUESTION ITEM ===== */
.question-item {
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.question-item:last-child { border-bottom: none; }

.question-item-inner {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

.question-options-grid {
    margin-top: 8px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    font-size: 0.9rem;
}

/* ===== FILTER BAR ===== */
.filter-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

/* ===== FOOTER ===== */
.site-footer {
    background: rgba(15, 23, 42, 0.95);
    border-top: 1px solid var(--border);
    padding: 24px;
    margin-top: auto;
}

.footer-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.footer-logo img { height: 36px; width: auto; }
.site-footer p { color: var(--text3); font-size: 0.85rem; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .hamburger { display: flex; }

    .nav-links {
        display: none;
        position: absolute;
        top: 64px;
        left: 0;
        right: 0;
        background: rgba(15, 23, 42, 0.98);
        backdrop-filter: blur(16px);
        flex-direction: column;
        padding: 20px;
        gap: 12px;
        border-bottom: 1px solid var(--border);
    }

    .nav-links.open { display: flex; }

    .hero h1 { font-size: 1.8rem; }
    .hero p { font-size: 1rem; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid-2 { grid-template-columns: 1fr; }
    .footer-inner { flex-direction: column; gap: 12px; text-align: center; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .main-content { padding: 16px; }
}

/* ===== UTILS ===== */
.text-center { text-align: center; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.hidden { display: none !important; }
