:root {
    --bg: #0A0E17;
    /* Deep Navy */
    --surface: #112240;
    /* Light Navy */
    --surface-2: #1d2d50;
    /* Lighter Navy */
    --border: rgba(100, 255, 218, 0.1);
    /* Neon Green tinted border */
    --text: #CCD6F6;
    /* Light Slate/White */
    --text-muted: #8892B0;
    /* Slate */
    --accent: #5EEAD4;
    /* Vibrant Teal/Cyan */
    --neon-green: #5EEAD4;
    --accent-glow: rgba(94, 234, 212, 0.2);
    --easy: #64FFDA;
    --medium: #FF9D00;
    /* Orange Accent */
    --hard: #F44336;
    /* Red Accent */
    --logic-token: #BD93F9;
    /* Purple Accent */
    --blue-accent: #8BE9FD;
    --review-bg: #4c3322;
    --review-text: #FF9D00;
    --card-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, sans-serif;
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ─── LOADING & ERROR ───────────────────────────── */
#loadingScreen,
#errorScreen,
#app,
#successView,
#summaryView,
#interstitialView {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 24px;
    text-align: center;
    z-index: 2000;
    background: var(--bg);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

#loadingScreen.show,
#errorScreen.show,
#app.show,
#successView.show,
#summaryView.show,
#interstitialView.show {
    opacity: 1;
    pointer-events: auto;
}

#app {
    background: radial-gradient(circle at 50% -20%, #1e1b4b 0%, var(--bg) 80%);
    justify-content: flex-start;
    padding-top: 170px;
    /* Adjusted to 170px */
    overflow-y: auto;
}

.loader-ring {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(124, 58, 237, 0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ─── HEADER & PROGRESS ─────────────────────────── */
.app-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.header-top {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.back-btn {
    color: var(--accent);
    cursor: pointer;
}

.logo {
    font-weight: 700;
    font-size: 20px;
    color: var(--accent);
    font-family: 'Noto Serif', serif;
}

.header-progress-container {
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
}

#standardHeaderContent {
    width: 100%;
}

.progress-meta {
    width: 100%;
    display: flex;
    justify-content: flex-start;
    margin-bottom: 8px;
}

.progress-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

.progress-counter {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    margin-left: 8px;
    letter-spacing: 0.05em;
}

.progress-bar-track {
    width: 100%;
    height: 6px;
    background: var(--surface-2);
    border-radius: 3px;
    overflow: hidden;
    border: 1px solid rgba(100, 255, 218, 0.05);
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent-glow);
    width: 0%;
    transition: width 0.3s;
}

/* ─── SRS OVERLAY ───────────────────────────────── */
.footer-btns {
    position: relative;
    margin-top: 56px;
    width: 100%;
    max-width: 352px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    z-index: 50;

    /* Ensure stability: always occupy space but start hidden */
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s ease, visibility 0.3s;
    margin-left: auto;
    margin-right: auto;
}

.footer-btns.show {
    visibility: visible;
    opacity: 1;
}

.btn-forget {
    height: 56px;
    border: 1px solid var(--hard);
    background: rgba(244, 67, 54, 0.05);
    border-radius: 28px;
    color: var(--hard);
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-forget:hover {
    background: rgba(244, 67, 54, 0.15);
    box-shadow: 0 5px 20px rgba(244, 67, 54, 0.3), 0 0 25px rgba(244, 67, 54, 0.2);
    transform: translateY(-2px);
}

.btn-know {
    height: 56px;
    background: var(--accent);
    border: none;
    border-radius: 28px;
    color: #0A0E17;
    /* Deep Navy text */
    font-weight: 800;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 0 15px var(--accent-glow);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-know:hover {
    background: var(--accent);
    filter: brightness(1.1);
    transform: translateY(-3px);
    box-shadow: 0 8px 30px var(--accent-glow), 0 0 30px rgba(94, 234, 212, 0.4);
}

.next-session-btn {
    flex: 1;
    margin-top: 0;
    height: 52px;
    background: transparent;
    border: 1px solid var(--accent);
    border-radius: 12px;
    color: var(--accent);
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
}

.next-session-btn:hover {
    background: rgba(79, 209, 197, 0.1);
}

.exit-btn {
    flex: 1;
    height: 52px;
    background: transparent;
    border: 1px solid var(--text-muted);
    border-radius: 12px;
    color: var(--text-muted);
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
}

.exit-btn:hover {
    background: rgba(100, 116, 139, 0.1);
    border-color: var(--text);
    color: var(--text);
}

.success-actions {
    display: flex;
    gap: 12px;
    width: 100%;
    margin-top: 16px;
}

.next-session-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ─── THEME TOGGLE BUTTON ────────────────────── */
.theme-toggle-btn {
    background: none;
    border: none;
    padding: 0;
    color: var(--accent);
    cursor: pointer;
    opacity: 0.9;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s, transform 0.3s ease;
    line-height: 0;
}

.theme-toggle-btn:hover {
    opacity: 1;
    transform: rotate(20deg);
}

/* ─── LIGHT (SCHOLAR) THEME ──────────────────── */
[data-theme="light"] {
    --bg:          #F4F1EB;
    --surface:     #FFFFFF;
    --surface-2:   #EAE5DC;
    --border:      rgba(0, 0, 0, 0.09);
    --text:        #1C1712;
    --text-muted:  #6E675E;
    --accent:      #0F766E;
    --neon-green:  #0F766E;
    --accent-glow: rgba(15, 118, 110, 0.18);
    --easy:        #0F766E;
    --medium:      #C2540A;
    --hard:        #DC2626;
    --logic-token: #7C3AED;
    --blue-accent: #1D4ED8;
    --review-bg:   #FEF3C7;
    --review-text: #C2540A;
    --card-shadow: 0 4px 24px rgba(0, 0, 0, 0.07), 0 1px 4px rgba(0, 0, 0, 0.04);
}

/* Fix app radial gradient (was hardcoded dark purple) */
[data-theme="light"] #app {
    background: radial-gradient(circle at 50% -20%, #CBE9E5 0%, var(--bg) 70%);
}

/* Fix portal cards with hardcoded dark colors */
[data-theme="light"] .level-pill {
    background: var(--surface-2);
}

[data-theme="light"] .stat-card {
    background: var(--surface);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

/* Fix icon SVG fills that used the dark bg color */
[data-theme="light"] .header-icon svg rect[fill="#0A0E17"],
[data-theme="light"] .header-icon svg path[fill="#0A0E17"] {
    fill: #FFFFFF;
}

/* Fix task submit button text (hardcoded dark bg color in task.css) */
[data-theme="light"] .task-submit-btn {
    color: #FFFFFF;
}

/* Fix MCQ prompt (was rgba(255,255,255,0.54)) */
[data-theme="light"] #mcqPrompt {
    color: var(--text-muted) !important;
}

/* MCQ options */
[data-theme="light"] .mcq-option {
    background: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.1);
    color: var(--text);
}

/* Lens mode popup */
[data-theme="light"] .lens-content {
    background: var(--surface);
    border-color: var(--accent);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .lens-close-btn {
    background: rgba(0, 0, 0, 0.06);
    border-color: rgba(15, 118, 110, 0.4);
}

/* Badge overlay */
[data-theme="light"] .badge-base {
    background: rgba(255, 255, 255, 0.96);
}

/* Know button text (dark bg text stays readable) */
[data-theme="light"] .btn-know {
    color: #FFFFFF;
}

/* Neural loading labels */
[data-theme="light"] .neural-word-label {
    background: rgba(244, 241, 235, 0.92);
    border-color: rgba(15, 118, 110, 0.25);
}

/* History panel */
[data-theme="light"] .reader-history-panel {
    background: var(--surface);
}

[data-theme="light"] .history-item {
    border-bottom-color: rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .history-item:hover {
    background: rgba(15, 118, 110, 0.05);
}

/* Interstitial overlay */
[data-theme="light"] .interstitial-overlay {
    background: radial-gradient(circle at 50% 50%, rgba(203, 233, 229, 0.95) 0%, rgba(244, 241, 235, 0.98) 100%);
}

/* Syllable tag faded text */
[data-theme="light"] .syllable-tag {
    color: rgba(0, 0, 0, 0.35);
}

/* Transition for smooth switching */
body,
#app,
.card-face,
.stat-card,
.xp-card,
.lib-word-card,
.story-card,
.reader-history-panel {
    transition: background-color 0.25s ease, background 0.25s ease,
                border-color 0.25s ease, color 0.25s ease,
                box-shadow 0.25s ease;
}