:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius: 1rem;
    --transition: all 0.3s ease;
}

[data-theme="dark"] {
    --primary: #3b82f6;
    --primary-dark: #60a5fa;
    --background: #0f172a;
    --surface: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--background);
    color: var(--text-main);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-container {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    padding: 1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    margin-bottom: 2rem;
}

.logo-area {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: 700;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-main);
}

.logo-icon {
    color: var(--primary);
}

.highlight {
    color: var(--primary);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.icon-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-main);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.icon-btn:hover {
    background: var(--border);
}

/* Main Content */
#main-content {
    flex: 1;
    position: relative;
}

.screen {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s ease, transform 0.4s ease;
    display: none;
}

.screen.active {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

/* Premium Nav Button */
.premium-nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.1);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    font-weight: 600;
    font-size: 0.9rem;
    transition: var(--transition);
    border: 1px solid rgba(245, 158, 11, 0.2);
    margin-right: 0.75rem;
}

.premium-nav-btn:hover {
    background: rgba(245, 158, 11, 0.2);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(245, 158, 11, 0.1);
}

/* Hero Section */
.hero-content {
    text-align: center;
    padding: 2rem 0;
}

.badge {
    display: inline-block;
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
    padding: 0.25rem 0.75rem;
    border-radius: 2rem;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

h1 {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--text-main) 0%, var(--primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
    margin-bottom: 3rem;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.feature-card {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.feature-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.icon-box {
    width: 50px;
    height: 50px;
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    margin: 0 auto 1rem;
}

.feature-card h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.feature-card p {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.exam-config {
    margin-bottom: 2rem;
}

.exam-config label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-muted);
}

.exam-config select {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-main);
    font-size: 1rem;
    cursor: pointer;
    outline: none;
    width: 100%;
    max-width: 300px;
}

.cta-btn {
    background: var(--primary);
    color: white;
    padding: 1rem 2rem;
    border: none;
    border-radius: 3rem;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: 0 4px 14px 0 rgba(37, 99, 235, 0.39);
}

.cta-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.02);
}

.cta-btn.secondary {
    background: var(--surface);
    color: var(--text-main);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.cta-btn.secondary:hover {
    background: var(--border);
}

/* Exam Screen */
.exam-header {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
}

.timer-badge {
    align-self: flex-end;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--primary);
    box-shadow: var(--shadow);
}

.progress-container {
    width: 100%;
}

#question-counter {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

.progress-bar-bg {
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.question-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    margin-bottom: 2rem;
}

.question-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.category-tag {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    color: var(--primary);
    background: rgba(37, 99, 235, 0.1);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.question-text {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 2rem;
    line-height: 1.5;
}

.options-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.option-item {
    padding: 1rem;
    border: 2px solid var(--border);
    border-radius: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 1rem;
    font-weight: 500;
}

.option-item:hover {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.02);
}

.option-item.selected {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
}

.option-marker {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: transparent;
    transition: var(--transition);
}

.option-item.selected .option-marker {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.exam-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-btn {
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border: none;
}

.nav-btn.secondary {
    background: transparent;
    color: var(--text-muted);
}

.nav-btn.secondary:hover:not(:disabled) {
    background: var(--border);
    color: var(--text-main);
}

.nav-btn.secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.nav-btn.primary {
    background: var(--primary);
    color: white;
}

.nav-btn.primary:hover {
    background: var(--primary-dark);
}

.nav-btn.danger {
    background: var(--danger);
    color: white;
}

.nav-btn.danger:hover {
    background: #dc2626;
}

.hidden {
    display: none !important;
}

/* Results Screen */
.result-header {
    text-align: center;
    margin-bottom: 2rem;
}

.score-overview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    margin-bottom: 3rem;
}

.score-circle {
    position: relative;
    width: 150px;
    height: 150px;
}

.circular-chart {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    max-height: 250px;
}

.circle-bg {
    fill: none;
    stroke: var(--border);
    stroke-width: 2.5;
}

.circle {
    fill: none;
    stroke: var(--success);
    stroke-width: 2.8;
    stroke-linecap: round;
    transition: stroke-dasharray 1s ease-out;
}

.percentage {
    fill: var(--text-main);
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: bold;
    font-size: 0.5rem;
    text-anchor: middle;
}

.score-label {
    margin-top: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    text-align: center;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    width: 100%;
}

.stat-item {
    background: var(--surface);
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

#stat-correct {
    color: var(--success);
}

#stat-wrong {
    color: var(--danger);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* === Chart & Review Fixes === */

.charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.chart-card {
    background: var(--surface);
    padding: 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    height: 320px;
    /* Constrain height */
    position: relative;
}

.chart-card h3 {
    text-align: center;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    position: absolute;
    width: 100%;
    top: 1rem;
    left: 0;
}

.chart-wrapper {
    margin-top: 2rem;
    height: calc(100% - 2rem);
    position: relative;
}

.detailed-review {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    max-height: 500px;
    /* Fix vertical scroll here */
}

.detailed-review h3 {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    margin: 0 !important;
    background: var(--background);
    border-radius: var(--radius) var(--radius) 0 0;
}

.review-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    overflow-y: auto;
    /* Enable scroll */
}

.review-item {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 1rem;
    border-radius: 0.5rem;
    flex-shrink: 0;
}

.review-item.correct {
    border-left: 5px solid var(--success);
}

.review-item.wrong {
    border-left: 5px solid var(--danger);
}

.review-q {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.review-ans {
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
    color: var(--text-muted);
}

.ans-label {
    font-weight: 600;
}

.correct-text {
    color: var(--success);
}

.wrong-text {
    color: var(--danger);
}

.review-explanation {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px dashed var(--border);
    font-size: 0.85rem;
    color: var(--text-muted);
}

.results-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 2rem;
    padding-bottom: 2rem;
}

.app-footer {
    text-align: center;
    padding: 2rem 0;
    color: var(--text-muted);
    font-size: 0.875rem;
    border-top: 1px solid var(--border);
    margin-top: auto;
}

@media (max-width: 600px) {
    h1 {
        font-size: 2rem;
    }

    .features-grid {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .exam-footer {
        flex-direction: column-reverse;
        gap: 1rem;
    }

    .nav-btn {
        width: 100%;
        justify-content: center;
    }
}

/* === UPDATED STYLES FOR NEW FEATURES === */

/* Flag Button */
.meta-right {
    display: flex;
    align-items: center;
}

.flag-btn {
    background: var(--surface);
    border: 1px solid transparent;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    transition: var(--transition);
    font-weight: 500;
}

.flag-btn:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    color: var(--warning);
    transform: translateY(-1px);
}

.flag-btn.active {
    background: #fffbeb;
    border-color: #fcd34d;
    color: #b45309;
    box-shadow: none;
}

.flag-btn.active i {
    font-weight: 900;
}

/* Mode Toggles (Welcome Screen) */
.config-group {
    margin-bottom: 2rem;
}

.mode-toggles {
    display: flex;
    gap: 1rem;
    width: 100%;
}

.mode-btn {
    flex: 1;
    padding: 1.25rem 1rem;
    border: 2px solid transparent;
    background: var(--surface);
    color: var(--text-muted);
    border-radius: 1rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 1.05rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.mode-btn i {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
    opacity: 0.7;
}

.mode-btn:hover {
    background: var(--surface);
    border-color: var(--border);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    color: var(--primary);
}

.mode-btn:hover i {
    opacity: 1;
}

.mode-btn.active {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.04);
    color: var(--primary);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
}

.mode-btn.active i {
    opacity: 1;
}

/* Training Feedback Area */
.training-feedback {
    margin-top: 2rem;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.feedback-alert {
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.feedback-alert.correct {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.feedback-alert.wrong {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.feedback-explanation {
    background: var(--background);
    padding: 1.5rem;
    border-radius: var(--radius);
    border-left: 4px solid var(--primary);
}

.feedback-explanation h4 {
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-main);
}

.course-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
    padding: 0.5rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 2rem;
    text-decoration: none;
    color: var(--primary);
    font-weight: 600;
    font-size: 0.9rem;
    transition: var(--transition);
}

.course-link:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Check Button */
.nav-btn.accent {
    background: var(--primary-dark);
    color: white;
}

.nav-btn.accent:hover {
    filter: brightness(1.1);
}

/* Option States for Training Mode */
.option-item.correct-answer {
    border-color: var(--success);
    background: rgba(16, 185, 129, 0.05);
}

.option-item.correct-answer .option-marker {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

.option-item.wrong-answer {
    border-color: var(--danger);
    background: rgba(239, 68, 68, 0.05);
}

.option-item.wrong-answer .option-marker {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

.option-item.disabled {
    pointer-events: none;
    opacity: 0.8;
}

/* Results Review Link */
.review-link-btn {
    display: inline-block;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

/* Question Palette (Navigation) */
.palette-wrapper {
    margin: 1.5rem 0;
    width: 100%;
}

.palette-toggle-btn {
    width: 100%;
    background: transparent;
    border: 1px dashed var(--border);
    padding: 0.75rem;
    border-radius: var(--radius);
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 500;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.palette-toggle-btn:hover {
    background: var(--surface);
    border-color: var(--primary);
    color: var(--primary);
}

.question-palette {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 0.5rem;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 1rem;
    max-height: 200px;
    overflow-y: auto;
}

.question-dot {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--background);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.question-dot:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.question-dot.answered {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.question-dot.current {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.3);
}

.question-dot.flagged {
    border-color: var(--warning);
    color: var(--warning);
    background: #fffbeb;
    font-weight: 800;
}

.question-dot.flagged.answered {
    background: var(--warning);
    border-color: var(--warning);
    color: white;
}

/* === MONETIZATION & CONVERSION === */

/* Email Gate Overlay */
.detailed-review {
    position: relative;
    overflow: hidden;
    /* Ensure blur doesn't leak */
}

.email-gate {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.85);
    /* Light blurred overlay */
    backdrop-filter: blur(8px);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
}

[data-theme="dark"] .email-gate {
    background: rgba(15, 23, 42, 0.85);
}

.gate-content {
    background: var(--surface);
    padding: 2rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    max-width: 400px;
    width: 100%;
    animation: slideDown 0.4s ease-out;
}

.blurred-content {
    filter: blur(8px);
    user-select: none;
    pointer-events: none;
}

/* Premium Upsell in Menu */
.premium-lock {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--warning);
    background: rgba(245, 158, 11, 0.1);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    margin-left: 0.5rem;
}

/* Locked Review Item */
.review-item.locked {
    opacity: 0.7;
    background: repeating-linear-gradient(45deg,
            var(--surface),
            var(--surface) 10px,
            rgba(0, 0, 0, 0.02) 10px,
            rgba(0, 0, 0, 0.02) 20px);
    border-style: dashed;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}