/* ============================================
   FE Electrical & Computer Practice Exam
   CBT-Style Interface
   ============================================ */

:root {
    --primary: #1a56db;
    --primary-dark: #1041a3;
    --primary-light: #e8f0fe;
    --success: #16a34a;
    --success-light: #dcfce7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Consolas', monospace;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
    --radius: 8px;
    --radius-sm: 4px;
    --radius-lg: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background: var(--gray-100);
    color: var(--gray-800);
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
    height: 100dvh; /* dynamic viewport height — accounts for mobile browser chrome */
    /* iOS safe areas for notch/home indicator */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.screen {
    display: none;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
}
.screen.active {
    display: flex;
    flex-direction: column;
}

/* ============ BUTTONS ============ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
    background: white;
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}
.btn-secondary:hover { background: var(--gray-50); border-color: var(--gray-400); }

.btn-nav {
    background: var(--gray-200);
    color: var(--gray-700);
    padding: 8px 16px;
}
.btn-nav:hover { background: var(--gray-300); }

.btn-next {
    background: var(--primary);
    color: white;
}
.btn-next:hover { background: var(--primary-dark); }

.btn-flag {
    background: transparent;
    color: var(--gray-600);
    border: 1px solid var(--gray-300);
    min-width: 140px;
    text-align: center;
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    touch-action: manipulation;
}
.btn-flag:hover { background: var(--warning-light); border-color: var(--warning); color: var(--gray-800); }
.btn-flag.flagged {
    background: var(--warning-light);
    border-color: var(--warning);
    color: var(--gray-800);
}

.btn-check {
    background: var(--success);
    color: white;
}
.btn-check:hover { background: #15803d; }

.btn-sm { padding: 6px 12px; font-size: 13px; }

.btn-icon {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: var(--radius-sm);
    color: white;
    font-size: 13px;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all 0.15s;
}
.btn-icon:hover { background: rgba(255,255,255,0.15); }

.btn-end { border-color: rgba(220,38,38,0.5); color: #fca5a5; }
.btn-end:hover { background: rgba(220,38,38,0.2); }

.btn-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--gray-500);
    padding: 4px 8px;
    line-height: 1;
}
.btn-close:hover { color: var(--gray-800); }

.hidden { display: none !important; }

/* ============ PAYWALL / SALES ============ */
.paywall-content {
    text-align: center;
    max-width: 540px;
    margin: 0 auto;
}
.paywall-features {
    text-align: left;
    display: inline-block;
    margin-bottom: 32px;
}
.paywall-feature {
    padding: 6px 0;
    font-size: 15px;
    color: var(--gray-700);
}
.paywall-check {
    color: #16a34a;
    font-weight: 700;
    margin-right: 8px;
}
.paywall-pricing {
    margin-bottom: 24px;
}
.paywall-price {
    font-size: 48px;
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
}
.paywall-price-label {
    font-size: 14px;
    color: var(--gray-500);
    margin-top: 4px;
    margin-bottom: 16px;
}
.btn-buy {
    font-size: 18px;
    padding: 14px 48px;
    border-radius: 10px;
}
.paywall-key-section {
    margin-top: 24px;
}
.paywall-blog-link {
    display: inline-block;
    margin-bottom: 12px;
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
}
.paywall-key-link {
    font-size: 13px;
    color: var(--gray-500);
}
.key-entry-form {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.key-input {
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    text-align: center;
    padding: 10px 16px;
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    width: 280px;
    max-width: 100%;
    letter-spacing: 1px;
    text-transform: uppercase;
}
.key-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,86,219,0.15);
}
.key-error {
    color: #dc2626;
    font-size: 13px;
}

/* License success screen */
.license-success {
    text-align: center;
    max-width: 480px;
    margin: 0 auto;
    padding: 40px 20px;
}
.success-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: #16a34a;
    color: white;
    font-size: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}
.license-key-display {
    font-family: 'JetBrains Mono', monospace;
    font-size: 20px;
    font-weight: 600;
    background: var(--gray-100);
    border: 2px solid var(--gray-200);
    border-radius: 8px;
    padding: 12px 20px;
    margin: 12px auto;
    display: inline-block;
    letter-spacing: 1px;
    user-select: all;
}
.key-save-note {
    font-size: 13px;
    color: var(--gray-500);
    margin-bottom: 24px;
}

.btn-demo {
    display: block;
    margin: 12px auto 0;
    font-size: 14px;
    padding: 10px 32px;
    border-radius: 8px;
}

/* Demo upsell on results page */
.demo-upsell {
    text-align: center;
    background: linear-gradient(135deg, #eef2ff, #e8f0fe);
    border: 2px solid var(--primary);
    border-radius: 12px;
    padding: 28px 24px;
    margin: 24px 0;
}
.demo-upsell h3 {
    font-size: 20px;
    color: var(--gray-900);
    margin-bottom: 8px;
}
.demo-upsell p {
    color: var(--gray-600);
    margin-bottom: 16px;
    font-size: 14px;
}
body.dark-mode .demo-upsell {
    background: linear-gradient(135deg, #1a1d3a, #1e2a4a);
    border-color: #6d9efc;
}
body.dark-mode .demo-upsell h3 { color: #e8eaf4; }
body.dark-mode .demo-upsell p { color: #a0a4b8; }

/* Dark mode paywall overrides */
body.dark-mode .paywall-feature { color: #c8cad8; }
body.dark-mode .paywall-check { color: #4ade80; }
body.dark-mode .key-input {
    background: #1a1d2e;
    border-color: #2e3148;
    color: #e8eaf4;
}
body.dark-mode .license-key-display {
    background: #1a1d2e;
    border-color: #2e3148;
    color: #e8eaf4;
}

/* ============ LANDING SCREEN ============ */
.landing-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 60px 24px;
}

.landing-header {
    text-align: center;
    margin-bottom: 48px;
    position: relative;
}

.logo-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    background: var(--primary);
    color: white;
    font-size: 28px;
    font-weight: 700;
    border-radius: 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-lg);
}

.landing-header h1 {
    font-size: 32px;
    color: var(--gray-900);
    margin-bottom: 4px;
}

.landing-header h2 {
    font-size: 20px;
    color: var(--primary);
    font-weight: 600;
    margin-bottom: 8px;
}

.landing-subtitle {
    color: var(--gray-500);
    font-size: 14px;
}

.mode-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 32px;
}

.mode-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 32px 24px;
    text-align: center;
    box-shadow: var(--shadow);
    border: 2px solid transparent;
    transition: all 0.2s;
}
.mode-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-lg);
}

.mode-icon {
    font-size: 36px;
    margin-bottom: 12px;
}

.mode-card h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--gray-800);
}

.mode-card p {
    font-size: 13px;
    color: var(--gray-500);
    margin-bottom: 20px;
    line-height: 1.5;
}

/* Topic Selection */
.topic-select-panel {
    background: white;
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}

.topic-select-panel h3 {
    margin-bottom: 16px;
    font-size: 18px;
}

.topic-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.topic-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
    font-size: 13px;
}
.topic-item:hover { background: var(--gray-50); }
.topic-item input { accent-color: var(--primary); }
.topic-item .topic-count { color: var(--gray-400); font-size: 12px; margin-left: auto; }

.topic-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--gray-200);
}

#topic-question-count {
    flex: 1;
    text-align: center;
    color: var(--gray-500);
    font-size: 13px;
}

/* History */
.history-section {
    background: white;
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow);
}

.history-section h3 { margin-bottom: 12px; }

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    background: var(--gray-50);
    border-radius: var(--radius);
    font-size: 13px;
}

.history-item .hist-score {
    font-weight: 700;
    font-size: 16px;
    min-width: 48px;
}

.history-item .hist-score.pass { color: var(--success); }
.history-item .hist-score.fail { color: var(--danger); }
.history-item .hist-details { flex: 1; color: var(--gray-600); }
.history-item .hist-date { color: var(--gray-400); font-size: 12px; }

.history-item:hover { background: var(--gray-100); }

.history-info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.history-date { font-size: 12px; color: var(--gray-500); }
.history-mode { font-size: 11px; color: var(--gray-400); text-transform: uppercase; letter-spacing: 0.5px; }
.history-score { display: flex; align-items: center; gap: 8px; }
.history-pct { font-weight: 700; font-size: 16px; }
.history-detail { font-size: 12px; color: var(--gray-500); }
.history-pass { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px; }
.history-pass.pass { background: var(--success-light); color: var(--success); }
.history-pass.fail { background: var(--danger-light); color: var(--danger); }

.history-review-btn {
    padding: 4px 12px;
    font-size: 11px;
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid var(--primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    transition: background 0.15s;
    margin-left: 8px;
}
.history-review-btn:hover { background: var(--primary); color: white; }

/* ============ EXAM SCREEN ============ */
#exam-screen {
    overflow: hidden;
}

/* Desktop: nav + exam-body sit side by side below the header */

.exam-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--gray-800);
    color: white;
    padding: 0 20px;
    height: 52px;
    flex-shrink: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.exam-title {
    font-weight: 600;
    font-size: 15px;
}

.exam-mode-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--primary);
    font-weight: 500;
}

.header-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.timer-display {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-mono);
    font-size: 18px;
    font-weight: 600;
}

.timer-display.warning { color: var(--warning); }
.timer-display.critical { color: #ef4444; animation: pulse 1s infinite; }

@keyframes pulse {
    50% { opacity: 0.6; }
}

.progress-info {
    font-size: 12px;
    color: var(--gray-400);
}

.pace-indicator {
    display: inline-block;
    margin-left: 8px;
    font-size: 11px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 4px;
    background: rgba(0,0,0,0.05);
}

.section-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--gray-500);
    background: var(--gray-100);
    padding: 2px 10px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Exam Body Layout */
.exam-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    margin-left: 220px;
    height: calc(100vh - 52px);
    height: calc(100dvh - 52px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}

/* Question Navigation Sidebar — fixed on left, outside overflow containers */
.question-nav {
    position: fixed;
    left: 0;
    top: 52px;
    bottom: 0;
    width: 220px;
    background: white;
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 90;
}

.question-nav.collapsed {
    width: 0;
    border: none;
    overflow: visible;
}
.btn-expand-nav {
    display: none;
    position: absolute;
    top: 10px;
    left: 4px;
    z-index: 10;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 14px;
    box-shadow: var(--shadow-md);
    align-items: center;
    justify-content: center;
}
.btn-expand-nav:hover { background: var(--primary-dark); }

.nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    font-weight: 600;
    font-size: 13px;
    border-bottom: 1px solid var(--gray-200);
}

.btn-collapse {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--gray-400);
    padding: 2px 6px;
}
.btn-close-mobile-nav {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    color: var(--gray-400);
    padding: 4px 8px;
    margin-left: auto;
}
@media (max-width: 768px) {
    .btn-close-mobile-nav { display: block; }
    .btn-collapse { display: none; }
}

.nav-legend {
    display: flex;
    gap: 12px;
    padding: 8px 16px;
    font-size: 11px;
    color: var(--gray-500);
    border-bottom: 1px solid var(--gray-100);
}

.legend-item { display: flex; align-items: center; gap: 4px; }

.dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}
.dot-answered { background: var(--primary); }
.dot-flagged { background: var(--warning); }
.dot-current { background: var(--gray-800); border: 2px solid var(--primary); }

.nav-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    padding: 12px;
    overflow-y: auto;
    flex: 1;
}

.nav-btn {
    width: 100%;
    max-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    background: white;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.1s;
    color: var(--gray-600);
    padding: 6px 2px;
}
/* Difficulty border indicators for review mode */
.nav-btn.diff-easy { border-left: 3px solid var(--success); }
.nav-btn.diff-medium { border-left: 3px solid var(--warning); }
.nav-btn.diff-hard { border-left: 3px solid var(--danger); }
.nav-btn:hover { background: var(--gray-100); }
.nav-btn.answered { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.nav-btn.flagged { background: var(--warning-light); border-color: var(--warning); color: #92400e; }
.nav-btn.current { border-color: var(--gray-800); border-width: 2px; font-weight: 700; }
.nav-btn.correct { background: var(--success-light); border-color: var(--success); color: var(--success); }
.nav-btn.incorrect { background: var(--danger-light); border-color: var(--danger); color: var(--danger); }

.nav-filters {
    display: flex;
    border-top: 1px solid var(--gray-200);
    padding: 8px 12px;
    gap: 6px;
}

.btn-filter {
    flex: 1;
    padding: 4px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    background: white;
    font-size: 11px;
    cursor: pointer;
    font-family: var(--font-sans);
}
.btn-filter.active { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }

/* Review Mode Topic Filter */
.nav-topic-filter {
    padding: 8px 12px;
    border-bottom: 1px solid var(--gray-200);
}
.nav-topic-filter select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    background: white;
    color: var(--gray-700);
    cursor: pointer;
}
.nav-topic-filter select:focus {
    outline: none;
    border-color: var(--primary);
}
.nav-topic-filter select + select {
    margin-top: 6px;
}
.review-diff-legend {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    font-size: 10px;
    color: var(--gray-500);
}
.diff-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
}
.diff-dot.diff-easy { background: var(--success); }
.diff-dot.diff-medium { background: var(--warning); }
.diff-dot.diff-hard { background: var(--danger); }

.nav-topic-divider {
    grid-column: 1 / -1;
    padding: 6px 4px 2px;
    font-size: 10px;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-top: 2px solid var(--primary-light);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.nav-topic-divider .topic-count {
    font-weight: 400;
    color: var(--gray-400);
    text-transform: none;
    letter-spacing: 0;
}

/* Main Question Area */
.question-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 20px 32px;
    background: var(--gray-50);
}

.question-topic-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.topic-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.difficulty-badge {
    font-size: 11px;
    padding: 2px 10px;
    border-radius: 10px;
    font-weight: 500;
}

.difficulty-badge.easy { background: var(--success-light); color: var(--success); }
.difficulty-badge.medium { background: var(--warning-light); color: #92400e; }
.difficulty-badge.hard { background: var(--danger-light); color: var(--danger); }

.question-content {
    flex: 1 0 auto;
}

.question-text {
    font-size: 16px;
    line-height: 1.7;
    margin-bottom: 24px;
    color: var(--gray-800);
}

.question-text code {
    font-family: var(--font-mono);
    background: var(--gray-200);
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 14px;
}

.question-text .formula {
    display: block;
    text-align: center;
    margin: 12px 0;
    font-family: var(--font-mono);
    font-size: 15px;
    padding: 12px;
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
}

/* Code blocks and pseudocode */
.question-text pre, .feedback-explanation pre, .feedback-steps pre {
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    background: var(--gray-800);
    color: #e5e7eb;
    padding: 14px 16px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 12px 0;
    white-space: pre;
    tab-size: 4;
}
.option-text pre, .option-text code {
    font-family: var(--font-mono);
    font-size: 12px;
    background: var(--gray-100);
    padding: 1px 5px;
    border-radius: 3px;
}
.option-text pre {
    display: block;
    padding: 6px 10px;
    margin: 4px 0 0;
    white-space: pre;
    overflow-x: auto;
}

/* Answer Options */
.answer-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 680px;
}

.option {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    background: white;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    font-size: 14px;
    line-height: 1.5;
    text-align: left;
}
.option:hover { border-color: var(--primary); background: var(--primary-light); }
.option.selected { border-color: var(--primary); background: var(--primary-light); }
.option.correct { border-color: var(--success); background: var(--success-light); }
.option.incorrect { border-color: var(--danger); background: var(--danger-light); }
.option.disabled { pointer-events: none; opacity: 0.7; }
.option.disabled.correct { opacity: 1; }
.option.disabled.incorrect { opacity: 1; }

.option-letter {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--gray-300);
    font-weight: 600;
    font-size: 12px;
    flex-shrink: 0;
    color: var(--gray-600);
    transition: all 0.15s;
}

.option.selected .option-letter { border-color: var(--primary); background: var(--primary); color: white; }
.option.correct .option-letter { border-color: var(--success); background: var(--success); color: white; }
.option.incorrect .option-letter { border-color: var(--danger); background: var(--danger); color: white; }

.option-text { flex: 1; padding-top: 2px; }

/* Multi-select indicator */
.multi-select-hint {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    margin-bottom: 8px;
    background: var(--warning-light);
    border: 1px solid #f59e0b;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: #92400e;
}
.multi-select-hint .hint-icon { font-size: 16px; }

/* Multi-select: square letter badges instead of circles */
.option.multi-select .option-letter {
    border-radius: 4px;
}
.option.multi-select.selected .option-letter::after {
    content: '\2713';
    position: absolute;
    font-size: 18px;
    font-weight: 700;
}
.option.multi-select .option-letter {
    position: relative;
}
.option.multi-select.selected .option-letter {
    font-size: 0;
}
.option.multi-select.selected .option-letter::after {
    font-size: 14px;
}
/* Partial credit indicator */
.partial-credit {
    color: #d97706;
    font-weight: 600;
}

/* Feedback Panel */
.feedback-panel {
    margin-top: 20px;
    border-radius: var(--radius);
    overflow: visible;
    border: 1px solid var(--gray-200);
}

.feedback-header {
    padding: 12px 18px;
    font-weight: 600;
    font-size: 14px;
}
.feedback-header.correct { background: var(--success-light); color: var(--success); }
.feedback-header.incorrect { background: var(--danger-light); color: var(--danger); }

.feedback-explanation {
    padding: 12px 14px;
    background: white;
    font-size: 14px;
    line-height: 1.7;
    color: var(--gray-700);
    border-top: 1px solid var(--gray-200);
}

.feedback-explanation .formula {
    display: block;
    text-align: center;
    margin: 8px 0;
    font-family: var(--font-mono);
    font-size: 14px;
    padding: 8px;
    background: var(--gray-50);
    border-radius: var(--radius-sm);
}

.feedback-reference {
    padding: 10px 18px;
    background: var(--gray-50);
    font-size: 12px;
    color: var(--gray-500);
    border-top: 1px solid var(--gray-200);
}

/* Question Controls */
.question-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    margin-top: auto;
    border-top: 1px solid var(--gray-200);
    flex-shrink: 0;
}

.controls-center {
    display: flex;
    gap: 12px;
}

/* ============ REFERENCE PANEL ============ */
.reference-panel {
    width: 400px;
    background: white;
    border-left: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}

.ref-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.ref-header h3 {
    font-size: 14px;
    flex: 1;
}

.ref-search {
    width: 100%;
    margin-top: 8px;
    padding: 6px 12px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: var(--font-sans);
}

.ref-nav {
    display: flex;
    overflow-x: auto;
    border-bottom: 1px solid var(--gray-200);
    padding: 0 8px;
}

.ref-tab {
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--gray-500);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: var(--font-sans);
}
.ref-tab:hover { color: var(--gray-700); }
.ref-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.ref-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    font-size: 13px;
    line-height: 1.7;
}

.ref-section h4 {
    font-size: 14px;
    color: var(--primary);
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--gray-200);
}

.ref-section {
    margin-bottom: 20px;
}

.ref-formula {
    font-family: var(--font-mono);
    background: var(--gray-50);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    margin: 4px 0;
    font-size: 13px;
    border-left: 3px solid var(--primary);
    transition: background 0.3s, box-shadow 0.3s;
}
.ref-formula.ref-highlight {
    background: #e8f0fe;
    box-shadow: 0 0 0 2px var(--primary), 0 2px 8px rgba(26,86,219,0.2);
    border-left-color: var(--primary);
}
body.dark-mode .ref-formula.ref-highlight {
    background: #1e2a4a;
    box-shadow: 0 0 0 2px #6d9efc, 0 2px 8px rgba(109,158,252,0.25);
}

.ref-formula-label {
    font-size: 12px;
    color: var(--gray-500);
    margin-top: 8px;
}

/* ============ CALCULATOR ============ */
.calculator-modal {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    border: 1px solid var(--gray-200);
}

.calc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--gray-800);
    color: white;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    font-size: 13px;
    font-weight: 600;
    cursor: move;
}

.calc-body { padding: 12px; }
.calc-note {
    font-size: 10px;
    color: var(--gray-500);
    text-align: center;
    padding: 0 4px 6px;
    line-height: 1.3;
}

.calc-display {
    width: 100%;
    padding: 10px 12px;
    background: var(--gray-50);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 18px;
    text-align: right;
    margin-bottom: 8px;
    color: var(--gray-800);
}

.calc-buttons {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
}

.calc-buttons.calc-buttons-6col {
    grid-template-columns: repeat(6, 1fr);
}

.calc-buttons button {
    padding: 8px 4px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    background: white;
    font-family: var(--font-sans);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.1s;
    min-height: 36px;
}
.calc-buttons button:hover { background: var(--gray-100); }
.calc-buttons button.calc-op { background: var(--gray-100); font-weight: 600; font-size: 14px; }
.calc-buttons button.calc-fn { background: #f0f4ff; color: var(--primary); font-size: 11px; }
.calc-buttons button.calc-fn:hover { background: #dbe4ff; }
.calc-buttons button.calc-clear { background: var(--danger-light); color: var(--danger); font-weight: 600; }
.calc-buttons button.calc-clear:hover { background: #fca5a5; }
.calc-buttons button.calc-eq { background: var(--primary); color: white; font-weight: 600; font-size: 16px; }
.calc-buttons button.calc-eq:hover { background: var(--primary-dark); }

.calc-angle-mode {
    background: #f59e0b;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

/* ============ RESULTS SCREEN ============ */
.results-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 40px 24px;
}

.results-header {
    text-align: center;
    margin-bottom: 40px;
}

.results-header h1 {
    font-size: 28px;
    margin-bottom: 24px;
}

.score-circle {
    position: relative;
    width: 160px;
    height: 160px;
    margin: 0 auto 24px;
}

.score-circle svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.score-bg {
    fill: none;
    stroke: var(--gray-200);
    stroke-width: 8;
}

.score-fill {
    fill: none;
    stroke: var(--primary);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 326.73;
    stroke-dashoffset: 326.73;
    transition: stroke-dashoffset 1.5s ease;
}

.score-fill.pass { stroke: var(--success); }
.score-fill.fail { stroke: var(--danger); }

.score-text {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.score-pct {
    font-size: 36px;
    font-weight: 700;
    color: var(--gray-800);
}

.score-label {
    font-size: 13px;
    color: var(--gray-500);
}

.score-summary {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-bottom: 16px;
}

.summary-stat { text-align: center; }

.stat-value {
    display: block;
    font-size: 24px;
    font-weight: 700;
    color: var(--gray-800);
}

.stat-label {
    font-size: 12px;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pass-indicator {
    font-size: 16px;
    font-weight: 600;
    padding: 8px 24px;
    border-radius: 20px;
    display: inline-block;
}
.pass-indicator.pass { background: var(--success-light); color: var(--success); }
.pass-indicator.fail { background: var(--danger-light); color: var(--danger); }

/* Results Breakdown */
.results-breakdown {
    background: white;
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.results-breakdown h2 {
    font-size: 18px;
    margin-bottom: 16px;
}

.breakdown-row {
    display: flex;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--gray-100);
    font-size: 13px;
}
.breakdown-row:last-child { border-bottom: none; }

.breakdown-topic {
    width: 200px;
    font-weight: 500;
    color: var(--gray-700);
}

.breakdown-bar-wrap {
    flex: 1;
    margin: 0 16px;
    height: 8px;
    background: var(--gray-200);
    border-radius: 4px;
    overflow: hidden;
}

.breakdown-bar {
    height: 100%;
    border-radius: 4px;
    transition: width 1s ease;
}
.breakdown-bar.good { background: var(--success); }
.breakdown-bar.ok { background: var(--warning); }
.breakdown-bar.bad { background: var(--danger); }

.breakdown-score {
    width: 80px;
    text-align: right;
    font-weight: 600;
    font-family: var(--font-mono);
    font-size: 13px;
}

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

/* ============ MODAL ============ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.modal {
    background: white;
    border-radius: var(--radius-lg);
    padding: 32px;
    max-width: 420px;
    width: 90%;
    box-shadow: var(--shadow-lg);
}

.modal h3 {
    font-size: 18px;
    margin-bottom: 8px;
}

.modal p {
    color: var(--gray-600);
    font-size: 14px;
    margin-bottom: 24px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}


/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* ============ KATEX FORMULA STYLING ============ */
.formula-expr .katex { font-size: 1.1em; }
.ref-content .katex-display { margin: 8px 0; }

/* ============ USER PROFILE / DASHBOARD ============ */
.profile-section {
    background: white;
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

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

.profile-header h3 {
    font-size: 18px;
    color: var(--gray-800);
    margin: 0;
}

.profile-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-danger {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid var(--danger);
}
.btn-danger:hover {
    background: var(--danger);
    color: white;
}

.profile-stats {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    flex: 1;
    background: var(--gray-50);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    border: 1px solid var(--gray-200);
}

.stat-card .stat-value {
    display: block;
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}

.stat-card .stat-label {
    display: block;
    font-size: 11px;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Topic Strength Grid */
.topic-strength-grid {
    margin-bottom: 20px;
}

.strength-legend {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
    font-size: 11px;
    color: var(--gray-500);
}

.strength-legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.strength-dot {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

.strength-dot.strength-strong { background: var(--success); }
.strength-dot.strength-moderate { background: var(--warning); }
.strength-dot.strength-weak { background: var(--danger); }
.strength-dot.strength-unseen { background: var(--gray-300); }

.strength-items {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.strength-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    border-left: 4px solid transparent;
    transition: background 0.15s;
}

.strength-item:hover {
    background: var(--gray-50);
}

.strength-item.strength-strong {
    background: rgba(22, 163, 74, 0.08);
    border-left-color: var(--success);
}

.strength-item.strength-moderate {
    background: rgba(245, 158, 11, 0.08);
    border-left-color: var(--warning);
}

.strength-item.strength-weak {
    background: rgba(220, 38, 38, 0.08);
    border-left-color: var(--danger);
}

.strength-item.strength-unseen {
    background: var(--gray-50);
    border-left-color: var(--gray-300);
    color: var(--gray-400);
}

.strength-topic-name {
    font-weight: 500;
    color: var(--gray-700);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.strength-item.strength-unseen .strength-topic-name {
    color: var(--gray-400);
}

.strength-pct {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--gray-500);
    margin-left: 8px;
    flex-shrink: 0;
}

/* Recommendations */
.recommendations {
    margin-top: 4px;
}

.recommendations h4 {
    font-size: 14px;
    color: var(--gray-700);
    margin-bottom: 12px;
}

.rec-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 8px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    font-size: 13px;
}

.rec-card.rec-weak {
    background: rgba(220, 38, 38, 0.04);
    border-color: rgba(220, 38, 38, 0.2);
}

.rec-card.rec-unseen {
    background: rgba(37, 99, 235, 0.04);
    border-color: rgba(37, 99, 235, 0.2);
}

.rec-card.rec-flagged {
    background: rgba(245, 158, 11, 0.04);
    border-color: rgba(245, 158, 11, 0.2);
}

.rec-card.rec-review {
    background: rgba(147, 51, 234, 0.04);
    border-color: rgba(147, 51, 234, 0.2);
}

.rec-card.rec-good {
    background: rgba(22, 163, 74, 0.04);
    border-color: rgba(22, 163, 74, 0.2);
}

.rec-icon {
    font-size: 18px;
    flex-shrink: 0;
    line-height: 1;
    margin-top: 2px;
}

.rec-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.rec-text strong {
    font-size: 13px;
    color: var(--gray-800);
}

.rec-detail {
    font-size: 12px;
    color: var(--gray-600);
}

.rec-action {
    font-size: 11px;
    color: var(--gray-400);
}

.rec-empty {
    color: var(--gray-400);
    font-size: 13px;
    text-align: center;
    padding: 16px 0;
}

/* ============ WEAK AREAS MODE CARD ============ */
.mode-card[data-mode="weakareas"] {
    border: 2px solid transparent;
}
.mode-card[data-mode="weakareas"]:hover {
    border-color: var(--danger);
}

/* ============ FLAG FOR PRACTICE BUTTON ============ */
.btn-flag-practice {
    background: transparent;
    color: var(--gray-600);
    border: 1px solid var(--gray-300);
    cursor: pointer;
    transition: all 0.15s;
}
.btn-flag-practice:hover {
    background: var(--warning-light);
    border-color: var(--warning);
    color: var(--gray-800);
}
.btn-flag-practice.flagged-for-practice {
    background: var(--warning-light);
    border-color: var(--warning);
    color: #92400e;
    font-weight: 600;
}

/* ============ RESULTS WEAK AREAS ============ */
.results-weak-areas {
    background: white;
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    border-left: 4px solid var(--danger);
}

.results-weak-areas h2 {
    font-size: 18px;
    margin-bottom: 16px;
    color: var(--gray-800);
}

.weak-topics-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.weak-topic-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--gray-50);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.weak-topic-name {
    font-weight: 500;
    color: var(--gray-700);
}

.weak-topic-pct {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--danger);
    font-weight: 600;
}

/* ============ RESPONSIVE UPDATES ============ */
@media (max-width: 1024px) {
    .mode-cards { grid-template-columns: repeat(2, 1fr); }
    .strength-items { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .mode-cards { grid-template-columns: 1fr; }
    .topic-grid { grid-template-columns: repeat(2, 1fr); }
    .question-nav { display: none; }
    .reference-panel { width: 100%; position: absolute; right: 0; top: 52px; bottom: 0; z-index: 50; }
    .question-area { padding: 16px 20px; }
    .score-summary { gap: 20px; }
    .profile-stats { flex-wrap: wrap; }
    .stat-card { min-width: calc(50% - 8px); }
    .strength-items { grid-template-columns: 1fr; }
    .profile-header { flex-direction: column; gap: 12px; align-items: flex-start; }
    .profile-actions { flex-wrap: wrap; }
}

/* ============ ENHANCED FEEDBACK WALKTHROUGH ============ */
.feedback-pattern {
    background: #f0f4ff;
    border-left: 4px solid #4f46e5;
    padding: 10px 14px;
    margin: 0;
    border-radius: 0;
}
.feedback-pattern .pattern-name {
    font-weight: 700;
    color: #4f46e5;
    font-size: 15px;
}
.feedback-pattern .pattern-keywords {
    margin-top: 6px;
    color: #6b7280;
    font-size: 13px;
}
.feedback-pattern .pattern-keywords span {
    background: #e5e7eb;
    padding: 2px 8px;
    border-radius: 12px;
    margin-right: 6px;
    font-family: var(--font-mono);
    display: inline-block;
    margin-top: 4px;
}

.feedback-steps {
    margin: 0;
    padding: 12px 14px;
    background: #f9fafb;
    border-top: 1px solid var(--gray-200);
}
.feedback-steps h4 {
    margin-bottom: 8px;
    font-size: 14px;
    color: #374151;
}
.feedback-steps ol {
    margin: 0;
    padding-left: 20px;
}
.feedback-steps ol li {
    margin-bottom: 6px;
    line-height: 1.5;
    font-size: 14px;
    color: var(--gray-700);
}

.feedback-handbook {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 8px 14px;
    background: #fff7ed;
    border-top: 1px solid var(--gray-200);
    font-size: 13px;
}
.feedback-handbook .handbook-icon { font-size: 18px; }
.feedback-handbook .handbook-section { font-weight: 600; color: #9a3412; }

.feedback-calculator {
    margin: 0;
    padding: 8px 14px;
    background: #f0fdf4;
    border-top: 1px solid var(--gray-200);
    font-size: 13px;
    color: var(--gray-700);
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.feedback-calculator .calc-icon { font-size: 16px; margin-right: 6px; }

.feedback-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding: 12px 18px;
    border-top: 1px solid #e5e7eb;
}

.feedback-actions .btn-flag-practice.flagged-for-practice {
    background: var(--success-light);
    color: var(--success);
    border-color: var(--success);
}

/* Toast notification */
.feedback-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--gray-800);
    color: white;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font-sans);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 3000;
    pointer-events: none;
}
.feedback-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============ SVG DIAGRAMS ============ */
.diagram-placeholder {
    margin: 16px 0;
    text-align: center;
}
.fe-diagram {
    --diagram-bg: #ffffff;
    --diagram-voltage: #1a56db;
    --diagram-current: #dc2626;
    --diagram-value: #16a34a;
    --diagram-accent: #1a56db;
    --diagram-grid: #d1d5db;
    max-width: 500px;
    width: 100%;
    height: auto;
    margin: 0 auto;
    display: block;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    background: var(--diagram-bg);
    padding: 12px;
    color: #1f2937;
}
.feedback-panel .fe-diagram {
    max-width: 420px;
    margin: 12px auto;
}

/* ============ MOBILE RESPONSIVE ============ */

/* Prevent iOS zoom on input focus */
input, select, textarea { font-size: 16px; }

/* --- Phones (max-width: 479px) --- */
@media (max-width: 479px) {
    .landing-container { padding: 24px 12px; }
    .landing-header { padding: 24px 16px 20px; }
    .landing-header h1 { font-size: 22px; }
    .landing-header h2 { font-size: 15px; }
    .landing-subtitle { font-size: 12px; }
    .logo-mark { width: 52px; height: 52px; font-size: 20px; margin-bottom: 10px; }
    .mode-cards { grid-template-columns: 1fr; gap: 12px; }
    .mode-card { padding: 16px 14px; }
    .mode-icon { font-size: 24px; margin-bottom: 6px; }
    .mode-card h3 { font-size: 15px; }
    .mode-card p { font-size: 12px; }
    .question-area { padding: 12px 14px; }
    .question-text { font-size: 15px; }
    .answer-options { max-width: 100%; }
    .option { padding: 10px 12px; font-size: 14px; }
    .option-letter { width: 22px; height: 22px; font-size: 11px; }
    .profile-stats .stat-card { min-width: 100%; }
    .score-circle { width: 100px; height: 100px; }
    .topic-grid { grid-template-columns: 1fr; }
}

/* --- Small tablets / large phones (max-width: 639px) --- */
@media (max-width: 639px) {
    .landing-container { padding: 32px 14px; }
    .mode-cards { grid-template-columns: 1fr; gap: 14px; }
    .topic-grid { grid-template-columns: 1fr; }
    .profile-stats { flex-wrap: wrap; }
    .profile-stats .stat-card { min-width: calc(50% - 8px); }
}

/* --- Tablets and below (max-width: 768px) --- */
@media (max-width: 768px) {
    /* Exam header — wrap for mobile */
    .exam-header {
        flex-wrap: wrap;
        height: auto;
        padding: 8px 12px;
        gap: 4px;
    }
    .header-left { flex: 1; min-width: 0; overflow: hidden; }
    .header-left .exam-mode-badge { font-size: 10px; padding: 1px 6px; white-space: nowrap; }
    .header-center { order: 3; width: 100%; justify-content: center; padding: 4px 0; }
    .header-right { gap: 2px; flex-shrink: 0; }
    .exam-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .btn-icon { padding: 6px 8px; font-size: 12px; min-height: 40px; }
    .btn-end { font-size: 11px; }

    /* Question navigator — slide-out drawer on mobile */
    .question-nav {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 260px;
        max-width: 80vw;
        z-index: 200;
        background: var(--gray-50);
        border-right: 1px solid var(--gray-200);
        box-shadow: var(--shadow-lg);
        overflow-y: auto;
        display: none;
    }
    .question-nav.mobile-open {
        display: flex;
    }
    .btn-expand-nav:not(.hidden) {
        display: flex !important;
        position: fixed;
        left: 8px;
        top: 70px;
        bottom: auto;
        z-index: 199;
        width: auto;
        height: 40px;
        padding: 0 12px 0 10px;
        border-radius: 20px;
        font-size: 13px;
        gap: 4px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    }

    /* Question area takes full width on mobile — no sidebar margin */
    .exam-body { flex-direction: column; flex: 1; overflow: hidden; margin-left: 0; }
    .question-area { flex: 1; width: 100%; min-width: 0; }
    .answer-options { max-width: 100%; }

    /* Reference panel — full-screen overlay on mobile */
    .reference-panel {
        position: fixed;
        width: 100%;
        max-width: 100%;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        z-index: 250;
        border: none;
    }

    /* Calculator — bottom sheet on mobile */
    .calculator-modal {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        max-height: 65vh;
        border-radius: 16px 16px 0 0;
        z-index: 300;
    }
    .calc-btn { min-height: 44px; font-size: 13px; }

    /* Nav grid */
    .nav-grid { grid-template-columns: repeat(8, 1fr); gap: 3px; padding: 8px; }
    .nav-btn { min-height: 36px; font-size: 11px; }

    /* Question controls — sticky bottom bar on mobile */
    .question-controls {
        position: sticky;
        bottom: 0;
        background: var(--gray-50);
        padding: 10px 8px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
        margin: 0 -14px;
        border-top: 1px solid var(--gray-200);
        z-index: 50;
    }
    .controls-center { gap: 6px; flex-wrap: wrap; justify-content: center; }
    .btn-nav { padding: 8px 10px; font-size: 13px; }
    .btn-flag { padding: 8px 10px; font-size: 12px; min-width: 120px; }
    .question-controls { flex-wrap: wrap; gap: 6px; justify-content: center; }

    /* Exam body fills remaining space */
    .exam-body {
        flex: 1;
        min-height: 0;
    }
}

/* --- Mobile nav overlay backdrop --- */
.nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 199;
}
.nav-backdrop.active {
    display: block;
}

/* --- Touch target minimums --- */
@media (pointer: coarse) {
    .btn { min-height: 44px; }
    .btn-sm { min-height: 40px; padding: 8px 14px; }
    .option { min-height: 48px; }
    .nav-btn { min-height: 40px; }
    .calc-btn { min-height: 48px; }
    .btn-dark-toggle { width: 44px; height: 44px; }
    .ref-nav-btn { min-height: 40px; padding: 8px 10px; }
}

/* --- Diagram responsiveness --- */
.fe-diagram { max-width: 100%; }
@media (max-width: 479px) {
    .fe-diagram { max-width: 100%; border: none; padding: 4px; }
}

/* --- Legal footer --- */
.legal-footer {
    margin-top: 32px;
    padding: 20px 24px;
    text-align: center;
    font-size: 11px;
    color: var(--gray-400);
    border-top: 1px solid var(--gray-200);
    line-height: 1.6;
}
.legal-footer p { margin-bottom: 4px; }
.legal-footer a { color: var(--primary); text-decoration: none; }
.legal-footer a:hover { text-decoration: underline; }

/* --- Report Issue Modal --- */
.btn-report { color: var(--warning); border-color: var(--warning); }
.btn-report:hover { background: var(--warning-light); }
.report-modal { max-width: 440px; }
.report-question-id { font-size: 13px; color: var(--gray-500); margin-bottom: 12px; }
.report-types { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.report-type-option {
    display: flex; align-items: center; gap: 8px;
    font-size: 14px; cursor: pointer; padding: 6px 8px;
    border-radius: var(--radius-sm); transition: background 0.15s;
}
.report-type-option:hover { background: var(--gray-50); }
.report-type-option input[type="radio"] { accent-color: var(--primary); }
.report-textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--gray-300);
    border-radius: var(--radius); font-family: var(--font-sans); font-size: 14px;
    resize: vertical; background: var(--gray-50); color: var(--gray-800);
}
.report-textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,0.1); }
.report-success { text-align: center; padding: 24px 16px; }
.report-success .check-icon { font-size: 48px; color: var(--success); margin-bottom: 8px; }
.report-success p { color: var(--gray-600); margin-top: 8px; }

/* Dark mode report modal */
body.dark-mode .report-type-option:hover { background: #252840; }
body.dark-mode .report-textarea { background: #0f1117; border-color: #2e3148; color: #e8eaf4; }
body.dark-mode .report-textarea:focus { border-color: #6d9efc; box-shadow: 0 0 0 3px rgba(109,158,252,0.15); }

/* Dark mode footer */
body.dark-mode .legal-footer { border-top-color: #2e3148; }

/* ============ DARK MODE TOGGLE ============ */
.btn-dark-toggle {
    position: absolute;
    top: 16px;
    right: 20px;
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
    color: var(--gray-600);
    font-size: 20px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 10;
}
.btn-dark-toggle:hover {
    background: var(--gray-200);
    color: var(--gray-800);
}
/* In exam header the toggle is inline, not absolute */
.header-right .btn-dark-toggle {
    position: static;
    width: 36px;
    height: 36px;
    font-size: 18px;
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.2);
    color: #e2e8f0;
}
.header-right .btn-dark-toggle:hover {
    background: rgba(255,255,255,0.2);
}

/* ============ DARK MODE ============ */
body.dark-mode {
    --primary: #6d9efc;
    --primary-dark: #5b8dee;
    --primary-light: #1e2a4a;
    --success: #4ade80;
    --success-light: #14332a;
    --danger: #f87171;
    --danger-light: #3b1c1c;
    --warning: #fbbf24;
    --warning-light: #3b2f0f;
    --gray-50: #0f1117;
    --gray-100: #161822;
    --gray-200: #1e2030;
    --gray-300: #2e3148;
    --gray-400: #5c5f77;
    --gray-500: #8b8fa8;
    --gray-600: #b0b4cc;
    --gray-700: #d0d4e8;
    --gray-800: #e8eaf4;
    --gray-900: #f4f5fb;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.35);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.4);
    color-scheme: dark;
}
body.dark-mode {
    background: #0f1117;
    color: #e8eaf4;
}

/* Landing screen */
body.dark-mode .landing-container {
    background: #161822;
}
body.dark-mode .landing-header {
    background: linear-gradient(135deg, #1a1d2e 0%, #0f1117 100%);
}
body.dark-mode .mode-card {
    background: #1e2030;
    border-color: #2e3148;
}
body.dark-mode .mode-card:hover {
    border-color: #6d9efc;
    box-shadow: 0 4px 12px rgba(109,158,252,0.15);
}

/* Exam header */
body.dark-mode .exam-header {
    background: #0f1117;
    border-bottom: 1px solid #2e3148;
}

/* Question area */
body.dark-mode .question-area {
    background: #161822;
}
body.dark-mode .question-content {
    color: #e8eaf4;
}

/* Options */
body.dark-mode .option {
    background: #1e2030;
    border-color: #2e3148;
    color: #d0d4e8;
}
body.dark-mode .option:hover:not(.disabled) {
    background: #252840;
    border-color: #6d9efc;
}
body.dark-mode .option.selected {
    background: #1e2a4a;
    border-color: #6d9efc;
}
body.dark-mode .option.correct {
    background: #14332a;
    border-color: #4ade80;
}
body.dark-mode .option.incorrect {
    background: #3b1c1c;
    border-color: #f87171;
}
body.dark-mode .option-letter {
    background: #2e3148;
    color: #b0b4cc;
}

/* Feedback panel */
body.dark-mode .feedback-panel {
    background: #1a1d2e;
    border-color: #2e3148;
    color: #d0d4e8;
}
body.dark-mode .feedback-pattern,
body.dark-mode .feedback-steps,
body.dark-mode .feedback-handbook,
body.dark-mode .feedback-calculator,
body.dark-mode .feedback-explanation {
    border-top-color: #2e3148;
}

/* Navigator */
body.dark-mode .question-nav {
    background: #0f1117;
    border-color: #2e3148;
}
body.dark-mode .nav-btn {
    background: #1e2030;
    border-color: #2e3148;
    color: #b0b4cc;
}
body.dark-mode .nav-btn.current {
    border-color: #6d9efc;
    background: #1e2a4a;
}
body.dark-mode .nav-btn.answered {
    background: #14332a;
    border-color: #4ade80;
    color: #4ade80;
}
body.dark-mode .nav-btn.flagged {
    background: #3b2f0f;
    border-color: #fbbf24;
}

/* Reference panel */
body.dark-mode .reference-panel {
    background: #161822;
    border-color: #2e3148;
    color: #d0d4e8;
}
body.dark-mode .ref-nav-btn {
    background: #1e2030;
    border-color: #2e3148;
    color: #b0b4cc;
}
body.dark-mode .ref-nav-btn.active,
body.dark-mode .ref-nav-btn:hover {
    background: #1e2a4a;
    border-color: #6d9efc;
    color: #6d9efc;
}
body.dark-mode .ref-formula {
    background: #1e2030;
    border-color: #2e3148;
}

/* Calculator */
body.dark-mode .calculator-modal {
    background: #1a1d2e;
    border-color: #2e3148;
    color: #d0d4e8;
}
body.dark-mode .calc-display {
    background: #0f1117;
    color: #e8eaf4;
    border-color: #2e3148;
}
body.dark-mode .calc-btn {
    background: #1e2030;
    border-color: #2e3148;
    color: #d0d4e8;
}
body.dark-mode .calc-btn:hover {
    background: #252840;
}

/* Code blocks */
body.dark-mode pre,
body.dark-mode code {
    background: #0f1117;
    color: #e8eaf4;
}

/* Scrollbars */
body.dark-mode ::-webkit-scrollbar-track {
    background: #161822;
}
body.dark-mode ::-webkit-scrollbar-thumb {
    background: #2e3148;
}

/* SVG diagrams */
body.dark-mode .fe-diagram {
    --diagram-bg: #1e2030;
    --diagram-voltage: #6d9efc;
    --diagram-current: #f87171;
    --diagram-value: #4ade80;
    --diagram-accent: #6d9efc;
    --diagram-grid: #3e4160;
    background: var(--diagram-bg);
    border-color: #2e3148;
    color: #e8eaf4;
}

/* Buttons */
body.dark-mode .btn {
    border-color: #2e3148;
}
body.dark-mode .btn-secondary {
    background: #1e2030;
    color: #d0d4e8;
    border-color: #2e3148;
}
body.dark-mode .btn-secondary:hover {
    background: #252840;
}
body.dark-mode .btn-icon {
    color: #b0b4cc;
}
body.dark-mode .btn-icon:hover {
    background: rgba(255,255,255,0.1);
}

/* Topic filter */
body.dark-mode .nav-topic-filter select {
    background: #1e2030;
    color: #d0d4e8;
    border-color: #2e3148;
}

/* Results screen */
body.dark-mode .results-container {
    background: #161822;
    color: #d0d4e8;
}
body.dark-mode .stat-card {
    background: #1e2030;
    border-color: #2e3148;
}

/* KaTeX in dark mode */
body.dark-mode .katex { color: #e8eaf4; }

/* Toggle button in dark mode */
body.dark-mode .btn-dark-toggle {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.2);
    color: #fbbf24;
}

/* --- Step-by-step solution & calculator tips --- */
body.dark-mode .feedback-panel,
body.dark-mode .feedback-panel * {
    color: #d0d4e8;
}
body.dark-mode .feedback-panel h4,
body.dark-mode .feedback-panel strong {
    color: #e8eaf4;
}
body.dark-mode .feedback-correct { background: #14332a; color: #4ade80; border-color: #22543d; }
body.dark-mode .feedback-incorrect { background: #3b1c1c; color: #f87171; border-color: #7f1d1d; }

/* Feedback sub-section backgrounds (all hardcode light colors) */
body.dark-mode .feedback-explanation {
    background: #1a1d2e;
    color: #d0d4e8;
    border-top-color: #2e3148;
}
body.dark-mode .feedback-explanation .formula {
    background: #0f1117;
    color: #d0d4e8;
}
body.dark-mode .feedback-pattern {
    background: #1a1d3a;
    border-left-color: #818cf8;
}
body.dark-mode .feedback-pattern .pattern-name {
    color: #a5b4fc;
}
body.dark-mode .feedback-pattern .pattern-keywords {
    color: #8b8fa8;
}
body.dark-mode .feedback-pattern .pattern-keywords span {
    background: #2e3148;
    color: #d0d4e8;
}
body.dark-mode .feedback-steps {
    background: #161822;
    border-top-color: #2e3148;
}
body.dark-mode .feedback-steps h4 {
    color: #e8eaf4;
}
body.dark-mode .feedback-steps ol li {
    color: #d0d4e8;
}
body.dark-mode .feedback-handbook {
    background: #2a1f0f;
    border-top-color: #2e3148;
    color: #d0d4e8;
}
body.dark-mode .feedback-handbook .handbook-section {
    color: #fb923c;
}
body.dark-mode .feedback-calculator {
    background: #0f2018;
    border-top-color: #2e3148;
    color: #d0d4e8;
}
body.dark-mode .feedback-reference {
    background: #161822;
    color: #8b8fa8;
}
body.dark-mode .feedback-actions {
    border-top-color: #2e3148;
}
body.dark-mode .feedback-header.correct {
    background: #14332a;
    color: #4ade80;
}
body.dark-mode .feedback-header.incorrect {
    background: #3b1c1c;
    color: #f87171;
}

/* --- Difficulty badges --- */
body.dark-mode .difficulty-badge.easy { background: #14332a; color: #4ade80; }
body.dark-mode .difficulty-badge.medium { background: #3b2f0f; color: #fbbf24; }
body.dark-mode .difficulty-badge.hard { background: #3b1c1c; color: #f87171; }

/* --- Nav button states (answered, flagged, difficulty colors) --- */
body.dark-mode .nav-btn.diff-easy { border-left-color: #4ade80; }
body.dark-mode .nav-btn.diff-medium { border-left-color: #fbbf24; }
body.dark-mode .nav-btn.diff-hard { border-left-color: #f87171; }
body.dark-mode .dot-answered { background: #6d9efc; }
body.dark-mode .dot-flagged { background: #fbbf24; }
body.dark-mode .nav-btn.flagged { color: #fbbf24; }

/* --- Flag button --- */
body.dark-mode .btn-flag { background: #1e2030; border-color: #2e3148; color: #b0b4cc; }
body.dark-mode .btn-flag:hover { background: #3b2f0f; border-color: #fbbf24; color: #fbbf24; }
body.dark-mode .btn-flag.flagged { background: #3b2f0f; border-color: #fbbf24; color: #fbbf24; }

/* --- Question controls --- */
body.dark-mode .question-controls { background: #161822; border-color: #2e3148; }

/* --- Profile / Your Progress section --- */
body.dark-mode .profile-section,
body.dark-mode .profile-card {
    background: #1e2030;
    border-color: #2e3148;
    color: #d0d4e8;
}
body.dark-mode .profile-section h3,
body.dark-mode .profile-card h3 { color: #e8eaf4; }
body.dark-mode .stat-card {
    background: #252840;
    border-color: #2e3148;
    color: #d0d4e8;
}
body.dark-mode .stat-value { color: #e8eaf4; }
body.dark-mode .stat-label { color: #8b8fa8; }
body.dark-mode .progress-bar { background: #2e3148; }
body.dark-mode .progress-fill { background: #6d9efc; }

/* --- Previous Results / History --- */
body.dark-mode .history-section {
    background: #1e2030;
    border-color: #2e3148;
    color: #d0d4e8;
}
body.dark-mode .history-section h3 { color: #e8eaf4; }
body.dark-mode .history-item {
    background: #252840;
    border-color: #2e3148;
    color: #d0d4e8;
}
body.dark-mode .history-item:hover { background: #2e3148; }
body.dark-mode .history-date,
body.dark-mode .history-mode,
body.dark-mode .history-detail,
body.dark-mode .hist-details,
body.dark-mode .hist-date { color: #8b8fa8; }
body.dark-mode .history-pass.pass { background: #14332a; color: #4ade80; }
body.dark-mode .history-pass.fail { background: #3b1c1c; color: #f87171; }
body.dark-mode .history-review-btn {
    background: transparent;
    border-color: #6d9efc;
    color: #6d9efc;
}
body.dark-mode .history-review-btn:hover { background: #6d9efc; color: #0f1117; }

/* --- Topic selection grid --- */
body.dark-mode .topic-item {
    background: #1e2030;
    border-color: #2e3148;
    color: #d0d4e8;
}
body.dark-mode .topic-item:hover { background: #252840; }
body.dark-mode .topic-count { color: #8b8fa8; }

/* --- Topic select / topic filter dropdown --- */
body.dark-mode .topic-select-container,
body.dark-mode .topic-select-grid {
    background: #161822;
    color: #d0d4e8;
}

/* --- Score/results screen --- */
body.dark-mode .score-circle { background: #1e2030; border-color: #2e3148; }
body.dark-mode .score-label { color: #8b8fa8; }
body.dark-mode .results-topic-bar { background: #2e3148; }
body.dark-mode .results-topic-fill { background: #6d9efc; }

/* --- All white backgrounds to dark --- */
body.dark-mode .question-area,
body.dark-mode .question-content,
body.dark-mode .answer-options-container {
    background: #161822;
}
body.dark-mode .question-controls {
    background: #161822;
    border-top-color: #2e3148;
}

/* --- Review filter legend dots --- */
body.dark-mode .diff-dot.easy { background: #4ade80; }
body.dark-mode .diff-dot.medium { background: #fbbf24; }
body.dark-mode .diff-dot.hard { background: #f87171; }
body.dark-mode .review-diff-legend { color: #8b8fa8; }

/* --- Nav topic dividers --- */
body.dark-mode .nav-topic-divider { background: #2e3148; color: #8b8fa8; }

/* --- Modals and overlays --- */
body.dark-mode .modal-overlay { background: rgba(0,0,0,0.7); }
body.dark-mode .modal-content {
    background: #1e2030;
    border-color: #2e3148;
    color: #d0d4e8;
}

/* --- General white bg catch-all --- */
body.dark-mode .landing-container { background: #0f1117; }
body.dark-mode .mode-card p { color: #8b8fa8; }
body.dark-mode .landing-subtitle { color: #8b8fa8; }
body.dark-mode .landing-header h1 { color: #e8eaf4; }
body.dark-mode .landing-header h2 { color: #6d9efc; }

/* --- Remaining white backgrounds --- */
body.dark-mode .topic-select-panel {
    background: #1e2030;
    color: #d0d4e8;
}
body.dark-mode .topic-select-panel h3 { color: #e8eaf4; }
body.dark-mode .question-text .formula {
    background: #0f1117;
    color: #d0d4e8;
}
body.dark-mode .calc-buttons button {
    background: #1e2030;
    border-color: #2e3148;
    color: #d0d4e8;
}
body.dark-mode .calc-buttons button:hover { background: #252840; }
body.dark-mode .calc-buttons button.calc-op { background: #252840; color: #e8eaf4; }
body.dark-mode .calc-buttons button.calc-fn { background: #1a1d3a; color: #a5b4fc; }
body.dark-mode .calc-buttons button.calc-fn:hover { background: #252850; }
body.dark-mode .calc-buttons button.calc-clear { background: #3b1c1c; color: #f87171; }
body.dark-mode .calc-buttons button.calc-clear:hover { background: #5a2020; }
body.dark-mode .calc-buttons button.calc-eq { background: #6d9efc; color: #0f1117; }
body.dark-mode .calc-buttons button.calc-eq:hover { background: #5b8dee; }
body.dark-mode .results-breakdown {
    background: #1e2030;
    border-color: #2e3148;
    color: #d0d4e8;
}
body.dark-mode .results-breakdown h2 { color: #e8eaf4; }
body.dark-mode .results-weak-areas {
    background: #1e2030;
    border-color: #2e3148;
    color: #d0d4e8;
}
body.dark-mode .results-weak-areas h2 { color: #e8eaf4; }
body.dark-mode .btn-filter {
    background: #1e2030;
    border-color: #2e3148;
    color: #b0b4cc;
}
body.dark-mode .btn-filter.active {
    background: #1e2a4a;
    border-color: #6d9efc;
    color: #6d9efc;
}
body.dark-mode .modal {
    background: #1e2030;
    border-color: #2e3148;
    color: #d0d4e8;
}

/* --- Scrollbar dark mode --- */
body.dark-mode ::-webkit-scrollbar { width: 8px; }
body.dark-mode ::-webkit-scrollbar-track { background: #0f1117; }
body.dark-mode ::-webkit-scrollbar-thumb { background: #2e3148; border-radius: 4px; }
body.dark-mode ::-webkit-scrollbar-thumb:hover { background: #5c5f77; }

/* ============ PRINT STYLES ============ */
@media print {
    .exam-header, .question-nav, .question-controls, .reference-panel, .calculator-modal { display: none; }
    .question-area { padding: 0; }
}
