/* --- FONT IMPORTS --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700&display=swap');

/* --- DESIGN SYSTEM TOKENS --- */
:root {
    /* Color Palette - Light Mode (Apple/Google Inspired) */
    --primary: #4F46E5;
    --primary-hover: #4338CA;
    --primary-soft: rgba(79, 70, 229, 0.1);

    --bg-main: #F8FAFC;
    --bg-surface: rgba(255, 255, 255, 0.8);
    --bg-card: #FFFFFF;

    --text-main: #1E293B;
    --text-muted: #64748B;
    --text-on-primary: #FFFFFF;

    --border: #E2E8F0;
    --border-hover: #CBD5E1;

    --success: #10B981;
    --success-soft: rgba(16, 185, 129, 0.1);
    --error: #EF4444;
    --error-soft: rgba(239, 68, 68, 0.1);

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.3);
    --glass-blur: blur(12px);

    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Mode Tokens */
body.dark-mode {
    --primary: #6366F1;
    --primary-hover: #818CF8;
    --primary-soft: rgba(99, 102, 241, 0.2);

    --bg-main: #0F172A;
    --bg-surface: rgba(30, 41, 59, 0.7);
    --bg-card: #1E293B;

    --text-main: #F1F5F9;
    --text-muted: #94A3B8;

    --border: #334155;
    --border-hover: #475569;

    --glass-bg: rgba(15, 23, 42, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6);
}

/* --- RESET & BASE --- */
/* Focus States */
:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 4px;
    border-radius: var(--radius-sm);
}

.theme-toggle:focus-visible {
    outline-color: var(--text-main);
}

/* Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.6;
    overflow-x: hidden;
    transition: background-color 0.5s ease, color 0.5s ease;
}

h1,
h2,
h3,
h4,
.start-btn,
.topic-card h3 {
    font-family: 'Outfit', sans-serif;
}

/* --- SCROLLBAR --- */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-main);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* --- GLASSMORPHISM UTILITY --- */
.glass {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
}

/* --- THEME TOGGLE --- */
.theme-toggle {
    position: fixed;
    top: 24px;
    right: 24px;
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1000;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.theme-toggle:hover {
    transform: scale(1.1) rotate(12deg);
    box-shadow: var(--shadow-lg);
}

.theme-icon {
    width: 24px;
    height: 24px;
    color: var(--text-main);
}

/* --- SPLASH SCREEN --- */
.splash-screen {
    position: fixed;
    inset: 0;
    background: var(--bg-card);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    transition: opacity 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.splash-screen.hide {
    opacity: 0;
    pointer-events: none;
    display: none;
}

.splash-screen img {
    width: 120px;
    height: auto;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    animation: pulse 2s infinite ease-in-out;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

/* --- HOME SCREEN --- */
.home {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    text-align: center;
}

.main-header {
    text-align: center;
    margin-bottom: 60px;
}

.main-header h1 {
    font-size: 3.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), #818CF8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.main-header h4 {
    font-size: 1.1rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* --- BUTTONS --- */
.btn-primary,
.btn-secondary {
    padding: 14px 32px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    font-family: 'Outfit', sans-serif;
}

.btn-primary {
    background: var(--primary);
    color: var(--text-on-primary);
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

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

.btn-secondary:hover {
    background: var(--primary-soft);
    transform: translateY(-2px);
}

.btn-primary:active,
.btn-secondary:active {
    transform: translateY(0);
}

/* --- TOPIC CARDS --- */
.topic-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 32px;
    width: 100%;
    max-width: 1200px;
}

.topic-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 40px 32px;
    text-decoration: none;
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    transition: var(--transition);
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.topic-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-xl);
    border-color: var(--primary);
}

.topic-icon {
    font-size: 3rem;
    margin-bottom: 24px;
    transition: var(--transition);
}

.topic-card:hover .topic-icon {
    transform: scale(1.1);
}

.topic-card h3 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text-main);
}

.topic-card p {
    font-size: 1rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.topic-card.disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

/* --- QUIZ INTERFACE --- */
.quiz-section {
    position: fixed;
    inset: 0;
    background: var(--bg-main);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 24px;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.quiz-section.active {
    opacity: 1;
    pointer-events: auto;
}

.quiz-box {
    width: 100%;
    max-width: 800px;
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    padding: 40px;
    display: none;
    flex-direction: column;
    max-height: 90vh;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

@media (max-width: 640px) {
    .quiz-box {
        padding: 24px;
        border-radius: var(--radius-lg);
        max-height: 95vh;
    }
}

.quiz-box.active {
    display: flex;
    animation: fadeInScale 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.popup-info {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    z-index: 1001;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.popup-info.active {
    opacity: 1;
    pointer-events: auto;
    animation: fadeInScaleCenter 0.4s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes fadeInScaleCenter {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.quiz-box h1 {
    font-size: 2rem;
    margin-bottom: 24px;
    color: var(--primary);
    text-align: center;
}

.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 32px;
}

.header-score {
    background: var(--primary-soft);
    color: var(--primary);
    padding: 6px 16px;
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 0.9rem;
}

.question-text {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 32px;
    color: var(--text-main);
}

.highlight {
    color: var(--primary);
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 4px;
}

/* --- OPTIONS --- */
.option-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.option {
    width: 100%;
    padding: 16px 20px;
    background: var(--bg-main);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    font-size: 1.05rem;
    font-weight: 500;
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.option:hover {
    border-color: var(--primary);
    background: var(--bg-card);
    transform: translateX(8px);
}

.option:focus-visible {
    border-color: var(--primary);
    background: var(--primary-soft);
    outline: none;
}

.option.selected {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary);
}

.option.correct {
    border-color: var(--success);
    background: var(--success-soft);
    color: var(--success);
}

.option.incorrect {
    border-color: var(--error);
    background: var(--error-soft);
    color: var(--error);
}

/* --- QUIZ FOOTER --- */
.quiz-footer {
    margin-top: 40px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.question-total {
    color: var(--text-muted);
    font-weight: 500;
}

.next-btn {
    padding: 12px 32px;
    background: var(--border);
    color: var(--text-muted);
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: not-allowed;
    transition: var(--transition);
}

.next-btn.active {
    background: var(--primary);
    color: var(--text-on-primary);
    cursor: pointer;
    box-shadow: var(--shadow-md);
}

.next-btn.active:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* --- RESULT BOX --- */
.result-box {
    text-align: center;
    padding: 60px 40px;
}

.circular-progress {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: conic-gradient(var(--primary) 0deg, var(--border) 0deg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 32px;
    position: relative;
    transition: background 1s ease-out;
}

.circular-progress::before {
    content: '';
    position: absolute;
    inset: 12px;
    background: var(--bg-card);
    border-radius: 50%;
}

.progress-value {
    position: relative;
    font-size: 3rem;
    font-weight: 700;
    color: var(--text-main);
}

.score-text {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 40px;
    display: block;
}

.result-box .buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
}

.result-box button {
    padding: 14px 28px;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.tryAgain-btn {
    background: var(--primary);
    color: var(--text-on-primary);
    border: none;
}

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

.tryAgain-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

.goHome-btn:hover {
    background: var(--primary-soft);
    transform: translateY(-2px);
}

/* --- RESPONSIVE --- */
@media (max-width: 768px) {
    .home {
        padding: 40px 20px;
    }

    .main-header h1 {
        font-size: 3rem;
    }

    .topic-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .quiz-box h1 {
        font-size: 1.75rem;
    }

    .option {
        padding: 14px 18px;
        font-size: 1rem;
    }

    .btn-primary,
    .btn-secondary {
        width: 100%;
        justify-content: center;
    }

    .quiz-box {
        padding: 24px;
    }

    .question-text {
        font-size: 1.25rem;
    }

    .topic-grid {
        grid-template-columns: 1fr;
        gap: 24px;
    }
}

@media (max-width: 480px) {
    .main-header h1 {
        font-size: 2.5rem;
    }

    .main-header h4 {
        font-size: 0.875rem;
    }

    .quiz-footer {
        flex-direction: column;
        gap: 20px;
        align-items: stretch;
    }

    .next-btn {
        width: 100%;
    }
}