/* ─────────────────────────────────────────────────────────────
   Life in the UK — Modern Edtech design system
   Indigo→Violet primary, Plus Jakarta Sans, WCAG AA
   ───────────────────────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
    /* Brand */
    --indigo-50:  #EEF2FF;
    --indigo-100: #E0E7FF;
    --indigo-500: #6366F1;
    --indigo-600: #4F46E5;
    --indigo-700: #4338CA;
    --violet-500: #8B5CF6;
    --violet-600: #7C3AED;
    --violet-700: #6D28D9;

    /* Neutral (light) */
    --bg:          #F8FAFC;
    --bg-subtle:   #F1F5F9;
    --surface:     #FFFFFF;
    --surface-2:   #F8FAFC;
    --text:        #0F172A;
    --text-muted:  #475569;
    --text-faint:  #94A3B8;
    --border:      #E2E8F0;
    --border-strong:#CBD5E1;

    /* Semantic */
    --primary:        var(--indigo-600);
    --primary-hover:  var(--indigo-700);
    --primary-soft:   var(--indigo-50);
    --secondary:      var(--violet-600);
    --success:        #059669;
    --success-soft:   #D1FAE5;
    --success-strong: #047857;
    --danger:         #DC2626;
    --danger-soft:    #FEE2E2;
    --danger-strong:  #B91C1C;
    --warning:        #D97706;
    --warning-soft:   #FEF3C7;
    --warning-strong: #B45309;
    --streak:         #F97316;

    /* Effects */
    --gradient:        linear-gradient(135deg, var(--indigo-600) 0%, var(--violet-600) 100%);
    --gradient-soft:   linear-gradient(135deg, var(--indigo-50) 0%, #F5F3FF 100%);
    --shadow-xs:       0 1px 2px rgba(15,23,42,0.05);
    --shadow-sm:       0 2px 4px rgba(15,23,42,0.06), 0 1px 2px rgba(15,23,42,0.04);
    --shadow:          0 4px 12px rgba(79,70,229,0.08), 0 1px 3px rgba(15,23,42,0.05);
    --shadow-lg:       0 12px 32px rgba(79,70,229,0.12), 0 4px 8px rgba(15,23,42,0.06);
    --shadow-xl:       0 24px 48px rgba(79,70,229,0.16), 0 8px 16px rgba(15,23,42,0.08);
    --ring:            0 0 0 3px rgba(99,102,241,0.35);

    /* Geometry */
    --radius-sm: 8px;
    --radius:    12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-pill: 999px;

    /* Type */
    --font: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;

    /* Motion */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --dur-fast: 150ms;
    --dur: 220ms;
    --dur-slow: 360ms;

    /* Layout */
    --container: 1100px;
    --nav-h: 64px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg:           #0B1020;
        --bg-subtle:    #0F1530;
        --surface:      #131A33;
        --surface-2:    #1A2240;
        --text:         #F1F5F9;
        --text-muted:   #94A3B8;
        --text-faint:   #64748B;
        --border:       #1F2A4A;
        --border-strong:#2C3A5E;
        --primary-soft: #1E1B4B;
        --success-soft: #064E3B;
        --danger-soft:  #450A0A;
        --warning-soft: #451A03;
        --gradient-soft: linear-gradient(135deg, #1E1B4B 0%, #2E1065 100%);
        --shadow-xs: 0 1px 2px rgba(0,0,0,0.4);
        --shadow-sm: 0 2px 4px rgba(0,0,0,0.4);
        --shadow:    0 4px 14px rgba(0,0,0,0.45), 0 1px 3px rgba(0,0,0,0.3);
        --shadow-lg: 0 16px 40px rgba(0,0,0,0.55);
        --shadow-xl: 0 24px 56px rgba(0,0,0,0.65);
        --ring:      0 0 0 3px rgba(139,92,246,0.45);
    }
}

/* Reset */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.6;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "cv11", "ss01";
}
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-sm); }

/* Icons */
.icon { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }
.icon-xl { width: 32px; height: 32px; }
.icon-hero { width: 28px; height: 28px; }

/* Skip link */
.skip-link { position: absolute; left: -9999px; top: 8px; background: var(--primary); color: white; padding: 0.5rem 1rem; border-radius: var(--radius-sm); z-index: 1000; }
.skip-link:focus { left: 8px; }

/* ── Layout shell ── */
#app { min-height: 100vh; display: flex; flex-direction: column; }

#nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    height: var(--nav-h);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: saturate(180%) blur(8px);
    -webkit-backdrop-filter: saturate(180%) blur(8px);
}
.nav-inner {
    max-width: var(--container);
    width: 100%;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 2rem;
}
.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    font-weight: 800;
    font-size: 1.0625rem;
    color: var(--text);
    letter-spacing: -0.01em;
    cursor: pointer;
    border-radius: var(--radius-sm);
    padding: 0.25rem 0.375rem;
    margin-left: -0.375rem;
}
.nav-brand-mark {
    width: 32px; height: 32px;
    background: var(--gradient);
    border-radius: 10px;
    display: grid; place-items: center;
    color: white;
    box-shadow: 0 4px 12px rgba(79,70,229,0.3);
}
.nav-brand-mark .icon { width: 18px; height: 18px; stroke-width: 2.5; }
.nav-links { display: flex; gap: 0.125rem; flex: 1; }
.nav-links button {
    color: var(--text-muted);
    padding: 0.5rem 0.875rem;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
    display: flex; align-items: center; gap: 0.5rem;
}
.nav-links button .icon { width: 16px; height: 16px; opacity: 0.85; }
.nav-links button:hover { color: var(--text); background: var(--bg-subtle); }
.nav-links button.active { color: var(--primary); background: var(--primary-soft); }
.nav-streak {
    display: flex; align-items: center; gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    background: linear-gradient(135deg, #FFF7ED 0%, #FFEDD5 100%);
    color: var(--streak);
    border: 1px solid #FED7AA;
    border-radius: var(--radius-pill);
    font-weight: 700;
    font-size: 0.85rem;
}
.nav-streak .icon { width: 15px; height: 15px; stroke-width: 2.5; fill: currentColor; }
.nav-streak.zero { background: var(--bg-subtle); color: var(--text-faint); border-color: var(--border); }
.nav-streak.zero .icon { fill: none; }
.nav-toggle { display: none; padding: 0.5rem; border-radius: var(--radius-sm); color: var(--text); }
.nav-toggle:hover { background: var(--bg-subtle); }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .nav-streak { background: linear-gradient(135deg, #431407 0%, #7C2D12 100%); border-color: #9A3412; color: #FED7AA; }
    :root:not([data-theme="light"]) .nav-streak.zero { background: var(--bg-subtle); color: var(--text-faint); border-color: var(--border); }
}

main {
    flex: 1;
    max-width: var(--container);
    width: 100%;
    margin: 0 auto;
    padding: 2.5rem 1.5rem 5rem;
}
.screen { display: none; animation: fadeIn var(--dur-slow) var(--ease-out); }
.screen.active { display: block; }
.hidden { display: none !important; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    min-height: 44px;
    font-weight: 600;
    font-size: 0.95rem;
    border-radius: var(--radius);
    transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease), color var(--dur) var(--ease);
    text-decoration: none;
    white-space: nowrap;
    letter-spacing: -0.005em;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:disabled:active { transform: none; }

.btn-primary {
    background: var(--gradient);
    color: white;
    box-shadow: 0 4px 14px rgba(79,70,229,0.32), inset 0 1px 0 rgba(255,255,255,0.18);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 8px 22px rgba(79,70,229,0.42), inset 0 1px 0 rgba(255,255,255,0.22); }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-subtle); color: var(--text); }

.btn-danger { color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }

.btn-large { padding: 1rem 1.75rem; font-size: 1rem; min-height: 52px; border-radius: var(--radius-lg); }

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.9rem;
    padding: 0.5rem 0.75rem;
    margin-left: -0.5rem;
    border-radius: var(--radius-sm);
}
.btn-back:hover { color: var(--text); background: var(--bg-subtle); }

.btn-icon {
    width: 40px; height: 40px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    border: 1px solid var(--border);
    background: var(--surface);
    transition: all var(--dur) var(--ease);
}
.btn-icon:hover { color: var(--primary); border-color: var(--primary); }
.btn-icon.filter-active { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }

/* ── Home: hero + continue ── */
.home-hero {
    background: var(--gradient);
    border-radius: var(--radius-xl);
    padding: 2.5rem;
    color: white;
    margin-bottom: 1.5rem;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}
.home-hero::before {
    content: '';
    position: absolute;
    top: -50%; right: -10%;
    width: 400px; height: 400px;
    background: radial-gradient(circle, rgba(255,255,255,0.18) 0%, transparent 60%);
    pointer-events: none;
}
.home-hero::after {
    content: '';
    position: absolute;
    bottom: -60%; left: -10%;
    width: 360px; height: 360px;
    background: radial-gradient(circle, rgba(255,255,255,0.10) 0%, transparent 60%);
    pointer-events: none;
}
.home-hero-content { position: relative; z-index: 1; max-width: 560px; }
.home-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    background: rgba(255,255,255,0.18);
    border: 1px solid rgba(255,255,255,0.22);
    backdrop-filter: blur(8px);
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-pill);
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 1.125rem;
    letter-spacing: -0.005em;
}
.home-eyebrow .icon { width: 14px; height: 14px; }
.home-hero h1 {
    font-size: clamp(1.875rem, 4vw, 2.5rem);
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -0.025em;
    margin-bottom: 0.75rem;
}
.home-hero p {
    font-size: 1rem;
    line-height: 1.55;
    opacity: 0.9;
    margin-bottom: 1.5rem;
    max-width: 480px;
}
.home-hero-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
.home-hero .btn-primary {
    background: white;
    color: var(--primary);
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}
.home-hero .btn-primary:hover { background: #FAFBFF; box-shadow: 0 12px 32px rgba(0,0,0,0.24); }
.home-hero .btn-secondary {
    background: rgba(255,255,255,0.14);
    color: white;
    border-color: rgba(255,255,255,0.28);
    backdrop-filter: blur(8px);
}
.home-hero .btn-secondary:hover { background: rgba(255,255,255,0.22); color: white; border-color: rgba(255,255,255,0.4); }

.hero-stats {
    display: flex;
    gap: 1.5rem;
    margin-top: 1.75rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(255,255,255,0.18);
    position: relative;
    z-index: 1;
}
.hero-stat {
    display: flex;
    flex-direction: column;
}
.hero-stat-num { font-size: 1.5rem; font-weight: 800; line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.hero-stat-label { font-size: 0.8rem; opacity: 0.82; margin-top: 0.25rem; font-weight: 500; }

/* Section heading */
.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 1rem;
    margin-top: 2rem;
}
.section-head h2 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.015em;
}
.section-head .section-link {
    color: var(--primary);
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
}
.section-head .section-link:hover { text-decoration: underline; }

.home-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}
.home-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    cursor: pointer;
    transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    text-align: left;
    position: relative;
    overflow: hidden;
}
.home-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: transparent; }
.home-card:active { transform: translateY(-1px) scale(0.99); }
.home-card-icon {
    width: 44px; height: 44px;
    border-radius: 12px;
    display: grid; place-items: center;
    background: var(--primary-soft);
    color: var(--primary);
    margin-bottom: 0.25rem;
}
.home-card-icon .icon { width: 22px; height: 22px; stroke-width: 2; }
.home-card.accent-violet .home-card-icon { background: #F5F3FF; color: var(--violet-600); }
.home-card.accent-emerald .home-card-icon { background: var(--success-soft); color: var(--success-strong); }
.home-card.accent-amber .home-card-icon { background: var(--warning-soft); color: var(--warning-strong); }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .home-card.accent-violet .home-card-icon { background: #2E1065; color: #C4B5FD; }
}
.home-card h3 { font-size: 1.0625rem; font-weight: 700; letter-spacing: -0.01em; color: var(--text); }
.home-card p { font-size: 0.875rem; color: var(--text-muted); line-height: 1.55; }
.home-card-meta {
    display: flex; align-items: center; justify-content: space-between;
    margin-top: auto;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}
.home-card-arrow { color: var(--text-faint); transition: transform var(--dur) var(--ease), color var(--dur) var(--ease); }
.home-card:hover .home-card-arrow { color: var(--primary); transform: translateX(3px); }

/* ── Test intro ── */
.test-intro {
    max-width: 560px;
    margin: 2rem auto;
    text-align: center;
}
.test-intro-icon {
    width: 64px; height: 64px;
    margin: 0 auto 1.25rem;
    background: var(--gradient);
    border-radius: 18px;
    display: grid; place-items: center;
    color: white;
    box-shadow: 0 12px 32px rgba(79,70,229,0.32);
}
.test-intro-icon .icon { width: 32px; height: 32px; stroke-width: 2; }
.test-intro h2 {
    font-size: 1.875rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    margin-bottom: 0.5rem;
}
.test-intro .test-subhead { color: var(--text-muted); margin-bottom: 2rem; font-size: 1rem; }
.test-info-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.75rem;
    text-align: left;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}
.info-row { display: flex; flex-direction: column; gap: 0.25rem; align-items: center; text-align: center; }
.info-row-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); margin-bottom: 0.375rem; }
.info-row-icon .icon { width: 18px; height: 18px; }
.info-row-val { font-size: 1.125rem; font-weight: 700; letter-spacing: -0.01em; }
.info-row-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }

/* ── Test active ── */
.test-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.625rem;
}
.test-progress {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}
.test-progress strong { color: var(--text); font-weight: 800; }
.test-timer {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    font-weight: 700;
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    transition: all var(--dur) var(--ease);
}
.test-timer .icon { width: 14px; height: 14px; stroke-width: 2.5; }
.test-timer.warning { background: var(--warning-soft); border-color: #FCD34D; color: var(--warning-strong); }
.test-timer.danger { background: var(--danger-soft); border-color: #FCA5A5; color: var(--danger-strong); animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.78; } }
@media (prefers-reduced-motion: reduce) {
    .test-timer.danger { animation: none; }
    .screen { animation: none; }
}

.test-progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-subtle);
    border-radius: var(--radius-pill);
    overflow: hidden;
    margin-bottom: 0.75rem;
}
.test-progress-fill {
    height: 100%;
    background: var(--gradient);
    border-radius: var(--radius-pill);
    transition: width var(--dur-slow) var(--ease-out);
    width: 0;
}

.test-score-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    font-size: 0.85rem;
}
.test-score-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius-pill);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.test-score-pill.correct { background: var(--success-soft); color: var(--success-strong); }
.test-score-pill.wrong { background: var(--danger-soft); color: var(--danger-strong); }
.test-score-pill .icon { width: 13px; height: 13px; stroke-width: 3; }

.question-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 1.75rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.25rem;
}
.question-chapter-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    background: var(--primary-soft);
    color: var(--primary);
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    font-weight: 700;
    margin-bottom: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.question-chapter-tag .icon { width: 12px; height: 12px; stroke-width: 2.5; }
.question-card h3 {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.4;
    margin-bottom: 1.25rem;
    color: var(--text);
    letter-spacing: -0.015em;
}

.options-list { display: flex; flex-direction: column; gap: 0.5rem; }
.option-btn {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    width: 100%;
    text-align: left;
    padding: 0.875rem 1rem;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    transition: transform var(--dur-fast) var(--ease), border-color var(--dur) var(--ease), background var(--dur) var(--ease);
    min-height: 56px;
    font-size: 0.95rem;
    line-height: 1.45;
    color: var(--text);
}
.option-btn:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-soft); }
.option-btn:active { transform: scale(0.99); }
.option-btn.selected { border-color: var(--primary); background: var(--primary-soft); }
.option-btn.correct { border-color: var(--success); background: var(--success-soft); color: var(--success-strong); }
.option-btn.incorrect { border-color: var(--danger); background: var(--danger-soft); color: var(--danger-strong); }
.option-letter {
    width: 28px; height: 28px;
    flex-shrink: 0;
    border-radius: 8px;
    display: grid; place-items: center;
    background: var(--bg-subtle);
    color: var(--text-muted);
    font-weight: 700;
    font-size: 0.8125rem;
    transition: all var(--dur) var(--ease);
}
.option-btn:hover:not(:disabled) .option-letter, .option-btn.selected .option-letter { background: var(--primary); color: white; }
.option-btn.correct .option-letter { background: var(--success); color: white; }
.option-btn.incorrect .option-letter { background: var(--danger); color: white; }
.option-text { flex: 1; }
.option-icon { color: currentColor; opacity: 0.9; }
.option-icon .icon { width: 18px; height: 18px; stroke-width: 2.5; }

.test-feedback {
    margin-top: 1rem;
    padding: 0.875rem 1rem;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    line-height: 1.5;
}
.test-feedback .icon { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; stroke-width: 2.5; }
.test-feedback.correct-feedback { background: var(--success-soft); color: var(--success-strong); }
.test-feedback.incorrect-feedback { background: var(--danger-soft); color: var(--danger-strong); }

.test-explanation-details {
    margin-top: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-subtle);
    overflow: hidden;
}
.test-explanation-details summary {
    cursor: pointer;
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    list-style: none;
}
.test-explanation-details summary::-webkit-details-marker { display: none; }
.test-explanation-details summary::before {
    content: '';
    width: 0; height: 0;
    border-left: 5px solid currentColor;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    transition: transform var(--dur) var(--ease);
}
.test-explanation-details[open] summary::before { transform: rotate(90deg); }
.test-explanation-details p {
    padding: 0 1rem 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.6;
}

.test-nav { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 0.5rem; }

/* ── Results ── */
.results-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow-lg);
    text-align: center;
    max-width: 560px;
    margin: 0 auto;
    position: relative;
    overflow: hidden;
}
.results-icon {
    width: 72px; height: 72px;
    margin: 0 auto 1rem;
    border-radius: 20px;
    display: grid; place-items: center;
    box-shadow: var(--shadow-lg);
}
.results-icon.pass { background: linear-gradient(135deg, #10B981 0%, #059669 100%); color: white; }
.results-icon.fail { background: linear-gradient(135deg, #F87171 0%, #DC2626 100%); color: white; }
.results-icon .icon { width: 36px; height: 36px; stroke-width: 2.5; }
.results-card h2 {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    margin-bottom: 0.375rem;
}
.results-sub { color: var(--text-muted); margin-bottom: 1.75rem; font-size: 0.95rem; }
.results-score { margin-bottom: 1.75rem; }
.score-circle {
    width: 160px; height: 160px;
    border-radius: 50%;
    margin: 0 auto;
    display: grid; place-items: center;
    position: relative;
    background: conic-gradient(var(--ring-color, var(--primary)) var(--ring-pct, 0%), var(--bg-subtle) 0);
    transition: --ring-pct 1s var(--ease-out);
}
.score-circle::before {
    content: '';
    position: absolute;
    inset: 12px;
    background: var(--surface);
    border-radius: 50%;
}
.score-circle.pass { --ring-color: var(--success); }
.score-circle.fail { --ring-color: var(--danger); }
.score-circle span {
    position: relative;
    font-size: 3rem;
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.score-circle small {
    position: relative;
    font-size: 1rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-top: 0.25rem;
}
.results-breakdown {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin-bottom: 1.75rem;
    text-align: center;
}
.result-item {
    background: var(--bg-subtle);
    padding: 0.875rem 0.5rem;
    border-radius: var(--radius);
}
.result-item-val { font-size: 1.125rem; font-weight: 700; letter-spacing: -0.015em; font-variant-numeric: tabular-nums; }
.result-item-label { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.125rem; font-weight: 500; }
.results-actions { display: flex; gap: 0.625rem; justify-content: center; flex-wrap: wrap; }

/* ── Review ── */
.review-list { display: flex; flex-direction: column; gap: 0.75rem; }
.review-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.review-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
}
.review-item.correct-review { border-left-color: var(--success); }
.review-item.incorrect-review { border-left-color: var(--danger); }
.review-item-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.625rem; }
.review-item-num { font-weight: 700; color: var(--text-muted); font-size: 0.8rem; }
.review-item-status {
    display: inline-flex; align-items: center; gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-pill);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.review-item.correct-review .review-item-status { background: var(--success-soft); color: var(--success-strong); }
.review-item.incorrect-review .review-item-status { background: var(--danger-soft); color: var(--danger-strong); }
.review-item-status .icon { width: 12px; height: 12px; stroke-width: 3; }
.review-item h4 { font-size: 1rem; font-weight: 600; line-height: 1.45; margin-bottom: 0.625rem; }
.review-answer { font-size: 0.875rem; padding: 0.375rem 0; line-height: 1.5; }
.review-answer.your-wrong { color: var(--danger-strong); }
.review-answer.correct-ans { color: var(--success-strong); font-weight: 600; }
.review-item .explanation { font-size: 0.875rem; color: var(--text-muted); margin-top: 0.5rem; padding-top: 0.625rem; border-top: 1px dashed var(--border); line-height: 1.55; }

/* ── Chapters ── */
.chapters-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0.875rem; }
.chapter-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    cursor: pointer;
    transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    position: relative;
    text-align: left;
}
.chapter-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: transparent; }
.chapter-num {
    width: 44px; height: 44px;
    background: var(--gradient);
    color: white;
    border-radius: 12px;
    display: grid; place-items: center;
    font-weight: 800;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(79,70,229,0.28);
    font-variant-numeric: tabular-nums;
}
.chapter-info { flex: 1; min-width: 0; }
.chapter-info h3 { font-size: 1rem; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 0.25rem; }
.chapter-info p { font-size: 0.85rem; color: var(--text-muted); }
.chapter-progress-row { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.625rem; font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }
.chapter-progress-bar { flex: 1; height: 4px; background: var(--bg-subtle); border-radius: var(--radius-pill); overflow: hidden; }
.chapter-progress-fill { height: 100%; background: var(--gradient); border-radius: var(--radius-pill); transition: width var(--dur-slow) var(--ease-out); }
.chapter-arrow { color: var(--text-faint); transition: transform var(--dur) var(--ease), color var(--dur) var(--ease); align-self: center; }
.chapter-card:hover .chapter-arrow { color: var(--primary); transform: translateX(3px); }

.chapter-quiz-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}
.chapter-quiz-header h3 { font-size: 1.125rem; font-weight: 700; letter-spacing: -0.015em; }
.chapter-quiz-progress { color: var(--text-muted); font-weight: 600; font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.chapter-explanation, .explanation {
    margin-top: 1rem;
    padding: 0.875rem 1rem;
    background: var(--primary-soft);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    line-height: 1.55;
}

/* ── Flashcards ── */
.flashcard-categories { display: flex; flex-direction: column; gap: 0.625rem; max-width: 640px; margin: 0 auto; }
.subtitle { color: var(--text-muted); text-align: center; margin-bottom: 1.5rem; font-size: 0.95rem; }
.fc-category-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    cursor: pointer;
    transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
    display: flex;
    align-items: center;
    gap: 1rem;
    text-align: left;
}
.fc-category-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: transparent; }
.fc-cat-left { display: flex; align-items: center; gap: 0.875rem; flex: 1; min-width: 0; }
.fc-cat-icon {
    width: 44px; height: 44px;
    border-radius: 12px;
    display: grid; place-items: center;
    background: var(--primary-soft);
    color: var(--primary);
    flex-shrink: 0;
}
.fc-cat-icon .icon { width: 22px; height: 22px; }
.fc-category-card:nth-child(2n) .fc-cat-icon { background: #F5F3FF; color: var(--violet-600); }
.fc-category-card:nth-child(3n) .fc-cat-icon { background: var(--success-soft); color: var(--success-strong); }
.fc-category-card:nth-child(4n) .fc-cat-icon { background: var(--warning-soft); color: var(--warning-strong); }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .fc-category-card:nth-child(2n) .fc-cat-icon { background: #2E1065; color: #C4B5FD; }
}
.fc-cat-name { font-weight: 700; letter-spacing: -0.01em; margin-bottom: 0.125rem; }
.fc-cat-count { font-size: 0.8rem; color: var(--text-muted); }
.fc-cat-progress { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; flex-shrink: 0; text-align: right; font-variant-numeric: tabular-nums; }
.fc-cat-progress-meter { width: 60px; height: 4px; background: var(--bg-subtle); border-radius: var(--radius-pill); margin-top: 0.25rem; overflow: hidden; }
.fc-cat-progress-meter-fill { height: 100%; background: var(--gradient); border-radius: var(--radius-pill); }

.flashcard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.flashcard-counter {
    font-weight: 700;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    font-size: 0.95rem;
}
.flashcard-controls { display: flex; gap: 0.375rem; }

.flashcard-container {
    perspective: 1500px;
    margin: 1rem auto 1.5rem;
    max-width: 560px;
}
.flashcard {
    width: 100%;
    height: 320px;
    cursor: pointer;
    border-radius: var(--radius-xl);
    position: relative;
}
.flashcard:focus-visible { outline: none; box-shadow: var(--shadow-lg), var(--ring); }
.flashcard-inner {
    position: relative;
    width: 100%; height: 100%;
    transition: transform 0.6s var(--ease-out);
    transform-style: preserve-3d;
}
.flashcard-inner.flipped { transform: rotateY(180deg); }
.flashcard-front, .flashcard-back {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: var(--radius-xl);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    box-shadow: var(--shadow-lg);
}
.flashcard-front {
    background: var(--surface);
    border: 1px solid var(--border);
}
.flashcard-back {
    background: var(--gradient);
    color: white;
    transform: rotateY(180deg);
}
.flashcard-front p { font-size: 1.25rem; font-weight: 600; line-height: 1.5; color: var(--text); letter-spacing: -0.015em; }
.flashcard-back p { font-size: 1.125rem; font-weight: 500; line-height: 1.55; max-width: 90%; }
.flashcard-category-tag {
    position: absolute;
    top: 1rem; left: 1rem;
    display: inline-flex; align-items: center; gap: 0.375rem;
    background: var(--primary-soft);
    color: var(--primary);
    padding: 0.25rem 0.625rem;
    border-radius: var(--radius-pill);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.flashcard-flip-hint {
    position: absolute;
    bottom: 1rem;
    font-size: 0.78rem;
    color: var(--text-faint);
    display: flex; align-items: center; gap: 0.375rem;
}
.flashcard-back .flashcard-flip-hint { color: rgba(255,255,255,0.7); }
.flashcard-flip-hint .icon { width: 14px; height: 14px; }

.flashcard-nav { display: flex; gap: 0.625rem; max-width: 560px; margin: 0 auto 1rem; }
.btn-know, .btn-dont-know {
    flex: 1;
    padding: 0.875rem 1rem;
    min-height: 52px;
    border-radius: var(--radius-lg);
    font-weight: 700;
    font-size: 0.95rem;
    border: 2px solid transparent;
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    transition: transform var(--dur-fast) var(--ease), background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.btn-know { background: var(--success-soft); color: var(--success-strong); border-color: transparent; }
.btn-know:hover { background: var(--success); color: white; }
.btn-know:active { transform: scale(0.98); }
.btn-dont-know { background: var(--warning-soft); color: var(--warning-strong); }
.btn-dont-know:hover { background: var(--warning); color: white; }
.btn-dont-know:active { transform: scale(0.98); }
.btn-know .icon, .btn-dont-know .icon { width: 18px; height: 18px; stroke-width: 2.5; }

.flashcard-progress-bar {
    max-width: 560px;
    margin: 0 auto;
    height: 6px;
    background: var(--bg-subtle);
    border-radius: var(--radius-pill);
    overflow: hidden;
}
.flashcard-progress-fill { height: 100%; background: var(--gradient); border-radius: var(--radius-pill); transition: width var(--dur-slow) var(--ease-out); }

/* ── Stats ── */
.stats-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.875rem;
    margin-bottom: 2.25rem;
}
.stat-big-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
    overflow: hidden;
}
.stat-big-card-icon {
    width: 36px; height: 36px;
    border-radius: 10px;
    display: grid; place-items: center;
    background: var(--primary-soft);
    color: var(--primary);
    margin-bottom: 0.125rem;
}
.stat-big-card-icon .icon { width: 18px; height: 18px; }
.stat-big-card:nth-child(2) .stat-big-card-icon { background: #F5F3FF; color: var(--violet-600); }
.stat-big-card:nth-child(3) .stat-big-card-icon { background: var(--success-soft); color: var(--success-strong); }
.stat-big-card:nth-child(4) .stat-big-card-icon { background: var(--warning-soft); color: var(--warning-strong); }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .stat-big-card:nth-child(2) .stat-big-card-icon { background: #2E1065; color: #C4B5FD; }
}
.stat-big-number { font-size: 1.875rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-big-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }

.stats-section { margin-top: 2.25rem; }
.stats-section h3 { font-size: 1.0625rem; font-weight: 700; letter-spacing: -0.015em; margin-bottom: 0.875rem; }

.chapter-stats-list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.chapter-stat-row {
    display: grid;
    grid-template-columns: 1fr 2fr auto;
    align-items: center;
    gap: 1rem;
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.chapter-stat-row:last-child { border-bottom: none; }
.chapter-stat-name { font-size: 0.875rem; font-weight: 600; color: var(--text); }
.chapter-stat-bar { height: 8px; background: var(--bg-subtle); border-radius: var(--radius-pill); overflow: hidden; }
.chapter-stat-fill { height: 100%; border-radius: var(--radius-pill); transition: width var(--dur-slow) var(--ease-out); }
.chapter-stat-pct { font-weight: 700; font-size: 0.875rem; min-width: 48px; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }

.test-history-list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.test-history-item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 1rem;
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.test-history-item:last-child { border-bottom: none; }
.test-history-date { font-size: 0.875rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.test-history-score { font-weight: 700; font-size: 0.875rem; font-variant-numeric: tabular-nums; }
.test-history-score.pass { color: var(--success-strong); }
.test-history-score.fail { color: var(--danger-strong); }
.test-history-badge {
    display: inline-flex; align-items: center; gap: 0.25rem;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-pill);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.test-history-badge.pass { background: var(--success-soft); color: var(--success-strong); }
.test-history-badge.fail { background: var(--danger-soft); color: var(--danger-strong); }
.test-history-badge .icon { width: 11px; height: 11px; stroke-width: 3; }

.empty-state {
    padding: 2.25rem 1.5rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.625rem;
}
.empty-state .icon { width: 36px; height: 36px; color: var(--text-faint); stroke-width: 1.5; }

.stats-actions { margin-top: 2.25rem; display: flex; justify-content: center; }

/* ── Responsive ── */
@media (max-width: 880px) {
    .test-info-box { grid-template-columns: 1fr; gap: 1rem; }
    .info-row { flex-direction: row; align-items: center; text-align: left; gap: 0.875rem; }
    .info-row-icon { margin-bottom: 0; }
}

@media (max-width: 720px) {
    #nav { padding: 0 1rem; }
    .nav-links {
        position: fixed;
        top: var(--nav-h);
        left: 0; right: 0;
        background: var(--surface);
        flex-direction: column;
        padding: 0.75rem;
        gap: 0.25rem;
        box-shadow: var(--shadow-lg);
        border-bottom: 1px solid var(--border);
        transform: translateY(-110%);
        transition: transform var(--dur) var(--ease);
    }
    .nav-links.open { transform: translateY(0); }
    .nav-links button { justify-content: flex-start; padding: 0.75rem 1rem; }
    .nav-toggle { display: inline-flex; margin-left: auto; }
    .nav-streak { padding: 0.3125rem 0.625rem; font-size: 0.8rem; }
    main { padding: 1.25rem 1rem 4rem; }
    .home-hero { padding: 1.75rem; border-radius: var(--radius-lg); }
    .hero-stats { gap: 1.25rem; }
    .question-card { padding: 1.25rem; border-radius: var(--radius-lg); }
    .question-card h3 { font-size: 1.125rem; }
    .results-card { padding: 2rem 1.25rem; }
    .results-breakdown { grid-template-columns: repeat(2, 1fr); }
    .score-circle { width: 140px; height: 140px; }
    .score-circle span { font-size: 2.5rem; }
    .flashcard { height: 280px; }
    .flashcard-front p { font-size: 1.0625rem; }
    .chapter-stat-row { grid-template-columns: 1fr; gap: 0.5rem; }
    .chapter-stat-name { font-size: 0.85rem; }
}

@media (max-width: 420px) {
    .home-hero { padding: 1.5rem 1.25rem; }
    .home-hero h1 { font-size: 1.625rem; }
    .test-intro h2 { font-size: 1.5rem; }
}
