/* --- CSS Variables & Theming --- */
:root {
    --primary: #FF4D4D;
    --primary-light: #FFEDED;
    --primary-gradient: linear-gradient(135deg, #FF6B6B 0%, #FF4D4D 100%);

    --bg-main: #F8F9FA;
    --surface: #FFFFFF;

    --text-dark: #1E293B;
    --text-muted: #64748B;
    --text-light: #94A3B8;

    --success: #10B981;
    --error: #EF4444;
    --info: #3B82F6;
    --warning: #F59E0B;
    --review: #8B5CF6; 
    
    --border: #E2E8F0;

    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-xl: 32px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 8px 20px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 30px rgba(0, 0, 0, 0.12);
    --shadow-primary: 0 8px 20px rgba(255, 77, 77, 0.25);
}

/* --- Dark Theme Overrides --- */
body.dark-theme {
    --bg-main: #0F172A;
    --surface: #1E293B;
    --text-dark: #F8FAFC;
    --text-muted: #94A3B8;
    --text-light: #64748B;
    --border: #334155;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 20px rgba(0, 0, 0, 0.3);
    --primary-light: #3F1D1D;
}

/* Dark Theme Specific Elements */
body.dark-theme .stat-pill.pill-green { background-color: #064E3B; color: #34D399; }
body.dark-theme .stat-pill.pill-red { background-color: #7F1D1D; color: #F87171; }
body.dark-theme .btn-google { background: #1E293B; color: #F8FAFC; border-color: #334155; }
body.dark-theme .exam-header,
body.dark-theme .exam-footer,
body.dark-theme .exam-sections { background: var(--surface); }
body.dark-theme .header-search-bar input { background: var(--bg-main); color: var(--text-dark); border-color: var(--border); }
body.dark-theme .pdf-page { background: var(--surface); color: var(--text-dark); }
body.dark-theme .toast { background: var(--surface); color: var(--text-dark); border: 1px solid var(--border); }
body.dark-theme .toast.error { border-left: 4px solid var(--error); }
body.dark-theme .toast.success { border-left: 4px solid var(--success); }
body.dark-theme .toast.info { border-left: 4px solid var(--info); }
body.dark-theme .palette-btn.not-visited { background: #334155; color: #94A3B8; border-color: #475569; }
body.dark-theme .legend-box.not-visited { background: #334155; border-color: #475569; }
body.dark-theme .sol-opt.correct { background: rgba(16,185,129,0.1); color: var(--success); border-color: var(--success); }
body.dark-theme .sol-opt.wrong { background: rgba(239,68,68,0.1); color: var(--error); border-color: var(--error); }
body.dark-theme .sol-explanation { background: rgba(255,77,77,0.1); color: var(--text-dark); }

/* --- Global Reset & Mobile Optimizations --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
    -webkit-tap-highlight-color: transparent; /* Removes blue tap highlight */
    user-select: none; /* Prevents text selection globally */
    -webkit-user-select: none;
}

/* Re-enable text selection only where necessary */
.pdf-text, .q-text, .sol-q-text, .sol-explanation, input {
    user-select: text;
    -webkit-user-select: text;
}

body {
    background-color: var(--bg-main); /* FIX: Seamless integration with OS browser bounds */
    color: var(--text-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    overscroll-behavior-y: none; /* Prevents rubber-banding on iOS */
    transition: background-color 0.3s;
}

/* App Container */
#app-container {
    width: 100%;
    max-width: 414px;
    height: 100%; /* FIX: Works with min-height 100dvh for proper mobile scaling */
    min-height: 100dvh;
    background-color: var(--bg-main);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.1);
    transition: background-color 0.3s;
}

/* Common Utility Classes */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-center { text-align: center; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--primary); }

/* Dynamic State Utilities */
.hidden { display: none !important; }

/* Premium Empty State */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 500;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    animation: fadeIn 0.4s ease;
}

/* --- Premium Skeleton Loaders --- */
@keyframes shimmer {
    0% { background-position: -1000px 0; }
    100% { background-position: 1000px 0; }
}

.skeleton-box, .skeleton-text, .skeleton-button {
    background: #E2E8F0;
    background-image: linear-gradient(90deg, #E2E8F0 0px, #F1F5F9 40px, #E2E8F0 80px);
    background-size: 1000px 100%;
    animation: shimmer 2.5s infinite linear;
    border-radius: var(--radius-sm);
}

body.dark-theme .skeleton-box, 
body.dark-theme .skeleton-text, 
body.dark-theme .skeleton-button {
    background: #334155;
    background-image: linear-gradient(90deg, #334155 0px, #475569 40px, #334155 80px);
}

.skeleton-text.title-skel { height: 16px; width: 60%; margin-bottom: 8px; border-radius: 4px; }
.skeleton-text.sub-skel { height: 12px; width: 40%; border-radius: 4px; }
.skeleton-text.inline-skel { height: 14px; width: 40px; display: inline-block; vertical-align: middle; border-radius: 4px; }
.skeleton-button { width: 70px; height: 32px; border-radius: 20px; }

/* Spinner */
.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Icon Button */
.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    color: var(--text-dark);
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-btn:active {
    background: var(--bg-main);
    transform: scale(0.95);
}

.icon-btn.no-border {
    border: none;
    box-shadow: var(--shadow-sm);
}

/* Badge */
.badge-red {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--primary-light);
    color: var(--primary);
}

/* --- View System --- */
.base-view {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    /* Extra padding for safe area (iPhone notches & Android nav bar) */
    padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px));
    display: none;
    animation: fadeIn 0.3s ease;
    -ms-overflow-style: none;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch; /* Momentum scrolling */
}

.base-view::-webkit-scrollbar { display: none; }
.base-view.active { display: block; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Sub Views (Deep Linking overlays) */
.sub-view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-main);
    z-index: 50;
    padding: 20px;
    padding-bottom: calc(30px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    -ms-overflow-style: none;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.sub-view::-webkit-scrollbar { display: none; }
.sub-view.active { transform: translateX(0); }

/* --- Headers --- */
.top-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: max(10px, env(safe-area-inset-top, 0px)) 0 20px 0;
    background: var(--bg-main);
    position: sticky;
    top: 0;
    z-index: 10;
    transition: 0.3s;
}

.top-header h2 {
    font-size: 1.25rem;
    flex: 1;
    margin-left: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.back-btn {
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px;
    color: var(--text-dark);
    transition: 0.2s;
}

.back-btn:active { transform: scale(0.9); }

/* --- TOAST NOTIFICATIONS --- */
.toast-container {
    position: absolute;
    top: max(20px, env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 90%;
    max-width: 380px;
    pointer-events: none;
}

.toast {
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    color: white;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    animation: toastSlideDown 0.3s ease forwards;
    pointer-events: auto;
}

.toast.error { background: var(--error); }
.toast.success { background: var(--success); }
.toast.info { background: var(--info); }

.toast i { font-size: 1.2rem; }

@keyframes toastSlideDown {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.toast-fade-out {
    animation: toastFadeOut 0.3s ease forwards;
}

@keyframes toastFadeOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-20px); }
}

/* --- SEARCH BARS --- */
.header-search-bar {
    position: relative;
    width: 100%;
}

.header-search-bar i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.header-search-bar input {
    width: 100%;
    padding: 12px 14px 12px 40px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-dark);
    font-size: 0.9rem;
    outline: none;
    transition: 0.2s;
    box-shadow: var(--shadow-sm);
}

.header-search-bar input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* ========================================= */
/* AUTHENTICATION VIEWS                      */
/* ========================================= */
.auth-view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--surface);
    z-index: 200;
    display: none;
    flex-direction: column;
    padding: max(30px, env(safe-area-inset-top, 0px)) 30px calc(30px + env(safe-area-inset-bottom, 0px)) 30px;
    animation: fadeIn 0.4s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.auth-view.active { display: flex; }

.auth-header {
    text-align: center;
    margin-bottom: 40px;
    margin-top: 20px;
}

.auth-logo {
    width: 70px;
    height: 70px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin: 0 auto 20px auto;
    box-shadow: var(--shadow-sm);
}

.auth-header h1 {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text-dark);
    margin-bottom: 8px;
}

.auth-header p {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 24px;
}

.input-group { position: relative; }

.input-group i {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    font-size: 1.1rem;
}

.auth-input {
    width: 100%;
    padding: 16px 16px 16px 45px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--bg-main);
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-dark);
    outline: none;
    transition: 0.2s;
}

.auth-input:focus {
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.auth-forgot {
    text-align: right;
    margin-top: -8px;
}

.auth-forgot a {
    font-size: 0.8rem;
    color: var(--primary);
    font-weight: 700;
    text-decoration: none;
}

.btn-auth-main {
    width: 100%;
    padding: 16px;
    border-radius: 14px;
    background: var(--primary);
    color: white;
    border: none;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s;
    box-shadow: var(--shadow-primary);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.btn-auth-main:active {
    transform: scale(0.96);
    box-shadow: var(--shadow-sm);
}

.auth-divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 24px 0;
    color: var(--text-light);
    font-size: 0.85rem;
    font-weight: 600;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border);
}

.auth-divider span { padding: 0 10px; }

.btn-google {
    width: 100%;
    padding: 14px;
    border-radius: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dark);
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    cursor: pointer;
    transition: 0.2s;
    box-shadow: var(--shadow-sm);
}

.btn-google:active { transform: scale(0.98); }

.btn-google img {
    width: 22px;
    height: 22px;
}

.auth-footer {
    text-align: center;
    margin-top: auto;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.auth-footer span {
    color: var(--primary);
    font-weight: 700;
    cursor: pointer;
}

/* ========================================= */
/* 1. HOME VIEW STYLES                       */
/* ========================================= */
.home-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.user-greeting {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar-placeholder {
    width: 48px;
    height: 48px;
    background: #E8CFBB;
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    background-size: cover;
    background-position: center;
}

.greeting-text p {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.greeting-text h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.streak-badge {
    background: var(--surface);
    padding: 6px 14px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-dark);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border);
}

.streak-badge i { color: #F59E0B; font-size: 1.1rem; }

.daily-quiz-card {
    background: var(--primary-gradient);
    border-radius: var(--radius-lg);
    padding: 24px;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-primary);
    margin-bottom: 30px;
    cursor: pointer;
    transition: all 0.2s;
}

.daily-quiz-card:active {
    transform: scale(0.96);
    box-shadow: 0 4px 10px rgba(255, 77, 77, 0.2);
}

.daily-quiz-card h3 { font-size: 1.25rem; margin-bottom: 6px; }
.daily-quiz-card p { font-size: 0.85rem; opacity: 0.9; }

.play-btn {
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: 0.3s;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.section-header h3 { font-size: 1.1rem; color: var(--text-dark); }

.exam-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 30px;
}

.exam-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}

.exam-card:active {
    transform: scale(0.96);
    border-color: var(--primary-light);
}

.exam-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 12px;
    transition: 0.2s;
}

.ic-gd { background: #FFF0F0; color: #EF4444; }
.ic-mts { background: #EFF6FF; color: #3B82F6; }
.ic-chsl { background: #F0FDF4; color: #10B981; }
.ic-cgl { background: #FAF5FF; color: #A855F7; }

.exam-title {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text-dark);
    margin-bottom: 4px;
}

.exam-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

.test-list-card {
    background: var(--surface);
    padding: 16px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: 0.2s;
    border: 1px solid transparent;
}

.test-list-card:active {
    transform: scale(0.98);
    border-color: var(--border);
}

/* ========================================= */
/* 2. LEADERBOARD VIEW STYLES                */
/* ========================================= */
.podium-section {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 16px;
    margin-bottom: 40px;
    padding-top: 20px;
}

.podium-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    transition: 0.3s;
    cursor: pointer;
}

.podium-avatar {
    border-radius: 50%;
    background: #ddd;
    background-size: cover;
    background-position: center;
    border: 3px solid transparent;
    box-shadow: var(--shadow-md);
    position: relative;
}

.premium-badge {
    position: absolute;
    bottom: -12px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.9rem;
    color: white;
    border: 2px solid var(--bg-main);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.rank-2 .podium-avatar { width: 68px; height: 68px; border-color: #E2E8F0; box-shadow: 0 0 15px rgba(226, 232, 240, 0.6); }
.rank-2 .premium-badge { background: linear-gradient(135deg, #F1F5F9, #94A3B8); color: #334155; }

.rank-1 { z-index: 10; margin-bottom: 15px; }
.rank-1 .podium-avatar { width: 88px; height: 88px; border-color: #FBBF24; padding: 2px; box-shadow: 0 0 20px rgba(251, 191, 36, 0.6); }
.rank-1 .premium-badge {
    background: linear-gradient(135deg, #FDE047, #D97706);
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
    bottom: -14px;
    border-color: var(--bg-main);
}

.crown-icon {
    position: absolute;
    top: -22px;
    color: #F59E0B;
    font-size: 1.8rem;
    filter: drop-shadow(0 2px 4px rgba(245, 158, 11, 0.4));
}

.rank-3 .podium-avatar { width: 68px; height: 68px; border-color: #FED7AA; box-shadow: 0 0 15px rgba(254, 215, 170, 0.6); }
.rank-3 .premium-badge { background: linear-gradient(135deg, #FDBA74, #C2410C); }

.podium-name {
    font-size: 0.85rem;
    font-weight: 700;
    margin-top: 20px;
    margin-bottom: 2px;
    text-align: center;
    color: var(--text-dark);
    max-width: 90px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.podium-score { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; }

.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.list-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    transition: 0.2s;
    cursor: pointer;
}

.list-item:active { transform: scale(0.98); }

.list-rank {
    width: 30px;
    font-weight: 700;
    color: var(--text-light);
    font-size: 1.1rem;
}

.list-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #eee;
    margin-right: 12px;
    background-size: cover;
    background-position: center;
}

.list-info { flex: 1; overflow: hidden; }

.list-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-badge { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }
.list-score { text-align: right; padding-left: 10px; }

.score-val {
    font-weight: 800;
    font-size: 1.05rem;
    display: block;
    color: var(--text-dark);
}

.score-lbl { font-size: 0.65rem; color: var(--text-muted); font-weight: 600; }

.list-item.highlight {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-primary);
    transform: scale(1.02);
}

.list-item.highlight .list-rank,
.list-item.highlight .list-badge,
.list-item.highlight .score-lbl { color: rgba(255, 255, 255, 0.9); }
.list-item.highlight .list-name,
.list-item.highlight .score-val { color: white; }

.list-item.highlight .you-badge {
    background: white;
    color: var(--primary);
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 0.6rem;
    font-weight: bold;
    position: absolute;
    bottom: -5px;
    right: -5px;
    border: 1px solid var(--primary);
}

/* ========================================= */
/* 3. MOCK TEST VIEW STYLES                  */
/* ========================================= */
.scrollable-tabs {
    display: flex;
    gap: 20px;
    overflow-x: auto;
    white-space: nowrap;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
    -webkit-overflow-scrolling: touch;
}

.scrollable-tabs::-webkit-scrollbar { display: none; }

.scroll-tab {
    font-size: 0.95rem;
    color: var(--text-muted);
    padding-bottom: 8px;
    cursor: pointer;
    position: relative;
    font-weight: 500;
    transition: 0.2s;
}

.scroll-tab.active { color: var(--primary); font-weight: 700; }

.scroll-tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--primary);
}

.btn-action {
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.btn-start { background: var(--primary); color: white; }
.btn-start:active { transform: scale(0.95); }
.btn-locked { background: var(--bg-main); color: var(--text-muted); cursor: not-allowed; border: 1px solid var(--border); }

/* ========================================= */
/* 4. PROFILE VIEW STYLES                    */
/* ========================================= */
.profile-sticky-header {
    position: relative !important;
    padding-bottom: 15px;
    z-index: 1;
    border-bottom: 1px solid transparent;
}

.profile-header-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 0 20px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
    text-align: center;
}

.profile-avatar-wrap {
    position: relative;
    margin-bottom: 16px;
    cursor: pointer;
    transition: transform 0.1s ease-out;
}

.profile-avatar {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    border: 4px solid var(--primary-light);
    background-size: cover;
    background-position: center;
}

.edit-badge {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 28px;
    height: 28px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    font-size: 0.7rem;
}

body.dark-theme .edit-badge { border-color: var(--surface); }

.perf-stats-container {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 30px;
}

.perf-card {
    flex: 1;
    background: var(--surface);
    padding: 16px 10px;
    border-radius: var(--radius-md);
    text-align: center;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    cursor: default;
}

.perf-icon { font-size: 1.2rem; margin-bottom: 8px; color: var(--primary); }

.settings-list {
    background: var(--surface);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.setting-item {
    display: flex;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: 0.2s;
    color: var(--text-dark);
}

.setting-item:last-child { border-bottom: none; }

.setting-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-main);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dark);
    margin-right: 16px;
    transition: 0.2s;
}

.setting-item:active { background: var(--bg-main); }

/* Toggle Switch UI */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #CBD5E1;
    transition: .4s;
}
.slider:before {
    position: absolute;
    content: "";
    height: 18px; width: 18px;
    left: 3px; bottom: 3px;
    background-color: white;
    transition: .4s;
}
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(20px); }
.slider.round { border-radius: 24px; }
.slider.round:before { border-radius: 50%; }

.btn-logout {
    width: 100%;
    padding: 14px;
    margin-top: 30px;
    background: var(--primary-light);
    color: var(--primary);
    border: none;
    border-radius: var(--radius-lg);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.btn-logout:active { transform: scale(0.98); }

/* ========================================= */
/* DEEP LINKING VIEWS (Level 2, 3, 4, 5, 6)  */
/* ========================================= */

/* Tier Chips */
.chip-container {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    overflow-x: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.chip-container::-webkit-scrollbar { display: none; }

.tier-chip {
    padding: 6px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: 0.2s;
    white-space: nowrap;
}

.tier-chip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Options Grid */
.options-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 10px; }

.option-card {
    display: flex;
    align-items: center;
    background: var(--surface);
    padding: 16px 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    border: 1px solid var(--border);
    transition: all 0.2s ease;
}

.option-card:active { transform: scale(0.98); background: var(--bg-main); }

.opt-icon {
    width: 50px;
    height: 50px;
    border-radius: 14px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.3rem;
    margin-right: 16px;
    transition: 0.3s;
}

.bg-orange { background: #FFF7ED; color: #F97316; }
.bg-blue { background: #EFF6FF; color: #3B82F6; }
.bg-purple { background: #FAF5FF; color: #A855F7; }
.bg-teal { background: #F0FDFA; color: #14B8A6; }

/* Material List */
.material-list-container { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }

.material-item {
    display: flex;
    align-items: center;
    padding: 16px;
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all 0.2s;
    border-left: 4px solid var(--primary);
    border-top: 1px solid var(--border);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.material-item:active { transform: scale(0.98); background: var(--bg-main); }

.mat-icon { font-size: 1.5rem; color: var(--primary); margin-right: 16px; transition: 0.2s; }
.mat-details { flex: 1; }
.mat-title { font-size: 0.95rem; font-weight: 700; margin-bottom: 4px; color: var(--text-dark); }
.mat-meta { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; display: flex; gap: 10px; align-items: center; }

/* --- PREMIUM PDF VIEWER --- */
#view-pdf-viewer {
    padding: 0;
    display: flex;
    flex-direction: column;
    background: #E2E8F0;
    overflow: hidden;
}

body.dark-theme #view-pdf-viewer { background: #0F172A; }

.pdf-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(14px + env(safe-area-inset-top, 0px)) 20px 14px 20px;
    background: #323639;
    color: #E8EAED;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    z-index: 10;
    font-size: 0.95rem;
}

.pdf-title-box {
    flex: 1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 0 15px;
}

.pdf-top-icons { display: flex; gap: 15px; align-items: center; }
.pdf-top-icons i { cursor: pointer; padding: 5px; transition: color 0.2s; }
.pdf-top-icons i:hover { color: #FFFFFF; }

.pdf-content-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
    -ms-overflow-style: none;
    scrollbar-width: none;
    position: relative;
    -webkit-overflow-scrolling: touch;
}

.pdf-content-area::-webkit-scrollbar { display: none; }

.pdf-page {
    width: 100%;
    max-width: 800px;
    min-height: 700px;
    background: #FFFFFF;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    padding: 40px 30px;
    position: relative;
    margin-bottom: 20px;
    color: #1E293B;
    overflow: hidden;
    transition: opacity 0.3s ease;
}

.pdf-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-45deg);
    font-size: 4.5rem;
    color: var(--border);
    opacity: 0.4;
    font-weight: 900;
    user-select: none;
    pointer-events: none;
    z-index: 0;
    letter-spacing: 5px;
}

#pdf-dynamic-content {
    font-size: 0.95rem;
    line-height: 1.7;
    color: inherit;
    word-wrap: break-word;
    position: relative;
    z-index: 1; 
}

#pdf-dynamic-content h1, 
#pdf-dynamic-content h2, 
#pdf-dynamic-content h3 {
    color: inherit;
    margin-top: 24px;
    margin-bottom: 12px;
    font-weight: 700;
}

#pdf-dynamic-content h1 { font-size: 1.5rem; text-align: center; border-bottom: 2px solid var(--border); padding-bottom: 10px; margin-top: 0; }
#pdf-dynamic-content h2 { font-size: 1.25rem; }
#pdf-dynamic-content h3 { font-size: 1.1rem; }
#pdf-dynamic-content p { margin-bottom: 16px; text-align: justify; }
#pdf-dynamic-content ul, #pdf-dynamic-content ol { margin-bottom: 16px; padding-left: 24px; }
#pdf-dynamic-content li { margin-bottom: 8px; }

#pdf-dynamic-content img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    margin: 15px auto;
    display: block;
    box-shadow: var(--shadow-sm);
}

#pdf-dynamic-content strong { font-weight: 700; }
#pdf-dynamic-content em { font-style: italic; }
#pdf-dynamic-content blockquote {
    border-left: 4px solid var(--primary);
    padding-left: 16px;
    color: var(--text-muted);
    font-style: italic;
    margin: 16px 0;
    background: var(--bg-main);
    padding: 10px 16px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* --- PREMIUM EXAM TEST INTERFACE (CBT Style) --- */
#view-exam-test {
    padding: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-main);
}

.exam-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.exam-title-box {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text-dark);
}

.exam-title-box i { font-size: 1.2rem; cursor: pointer; padding: 4px; color: var(--text-muted); }
.exam-header-actions { display: flex; align-items: center; gap: 16px; }

.exam-sub-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: var(--bg-main);
    border-bottom: 1px solid var(--border);
}

.exam-timer {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 800;
    font-size: 1rem;
    color: #DC2626;
    background: #FEF2F2;
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid #FCA5A5;
}

.exam-progress { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }

.exam-sections {
    display: flex;
    overflow-x: auto;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    -ms-overflow-style: none;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.exam-sections::-webkit-scrollbar { display: none; }

.exam-sec-tab {
    padding: 14px 16px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    white-space: nowrap;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    transition: 0.2s;
}

.exam-sec-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.exam-question-area { flex: 1; overflow-y: auto; padding: 24px 20px; position: relative; -webkit-overflow-scrolling: touch;}

.q-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    font-size: 0.85rem;
}

.q-num {
    font-weight: 800;
    font-size: 1.15rem;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: 8px;
}

.q-num::before {
    content: '';
    display: block;
    width: 4px;
    height: 18px;
    background: var(--primary);
    border-radius: 4px;
}

.q-marks {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.8rem;
    box-shadow: var(--shadow-sm);
}

.q-marks span.pos { color: var(--success); }
.q-marks span.neg { color: var(--error); }

.q-text {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-dark);
    margin-bottom: 28px;
    font-weight: 600;
}

/* Premium Radio Options */
.q-options-list { display: flex; flex-direction: column; gap: 14px; }

.q-option {
    display: flex;
    align-items: center;
    padding: 16px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 14px;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-dark);
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.q-option input[type="radio"] { display: none; }

/* Custom Radio Circle */
.q-radio-custom {
    width: 22px;
    height: 22px;
    border: 2px solid var(--text-light);
    border-radius: 50%;
    margin-right: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
    flex-shrink: 0;
}

.q-option:has(input[type="radio"]:checked) {
    border-color: var(--primary);
    background: var(--primary-light);
    box-shadow: 0 4px 12px rgba(255, 77, 77, 0.1);
}

.q-option:has(input[type="radio"]:checked) .q-radio-custom { border-color: var(--primary); }

.q-option:has(input[type="radio"]:checked) .q-radio-custom::after {
    content: '';
    width: 10px;
    height: 10px;
    background: var(--primary);
    border-radius: 50%;
}

.exam-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px)) 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 15px rgba(0, 0, 0, 0.05);
}

.exam-action-btn {
    padding: 14px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.9rem;
    border: none;
    cursor: pointer;
    transition: 0.2s;
}

.exam-action-btn:active { transform: scale(0.96); }

.btn-mark {
    background: var(--bg-main);
    color: var(--text-dark);
    border: 1px solid var(--border);
    flex: 1;
    margin-right: 12px;
}

.btn-next {
    background: var(--primary);
    color: white;
    flex: 1.5;
    box-shadow: var(--shadow-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* ========================================= */
/* CBT QUESTION PALETTE (Drawer UI)          */
/* ========================================= */
.cbt-palette-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    display: flex;
    justify-content: flex-end;
    animation: fadeIn 0.2s ease;
}

.cbt-palette-content {
    width: 80%;
    max-width: 320px;
    height: 100%;
    background: var(--surface);
    padding: calc(20px + env(safe-area-inset-top, 0px)) 20px calc(20px + env(safe-area-inset-bottom, 0px)) 20px;
    box-shadow: -4px 0 15px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
    transform: translateX(100%);
    animation: slideLeft 0.3s forwards ease;
    display: flex;
    flex-direction: column;
}

@keyframes slideLeft {
    to { transform: translateX(0); }
}

.palette-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin-bottom: 20px;
    flex: 1;
    align-content: flex-start;
}

.palette-btn {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-dark);
    transition: 0.2s;
}

.palette-btn:active { transform: scale(0.9); }

.palette-btn.answered { background: var(--success); color: white; border-color: var(--success); }
.palette-btn.unanswered { background: var(--error); color: white; border-color: var(--error); }
.palette-btn.marked { background: var(--review); color: white; border-color: var(--review); }
.palette-btn.not-visited { background: #E2E8F0; color: #64748B; }

.legend-box { width: 14px; height: 14px; border-radius: 4px; margin-right: 6px; }
.legend-box.answered { background: var(--success); }
.legend-box.unanswered { background: var(--error); }
.legend-box.marked { background: var(--review); }
.legend-box.not-visited { background: #E2E8F0; border: 1px solid var(--border); }

/* ========================================= */
/* RESULT SCORECARD & DASHBOARD UI           */
/* ========================================= */
.result-score-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30px 20px;
    background: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
    text-align: center;
    border: 1px solid var(--border);
}

.score-circle {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 8px solid var(--primary-light);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-top-color: var(--primary);
    margin-bottom: 15px;
    position: relative;
}

.score-circle h2 { font-size: 2rem; color: var(--primary); margin-bottom: -4px; }
.score-circle span { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; }

.result-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.stat-box {
    padding: 16px;
    border-radius: var(--radius-md);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.stat-box .lbl { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; }
.stat-box .val { font-size: 1.2rem; font-weight: 800; color: var(--text-dark); }
.stat-box.green .val { color: var(--success); }
.stat-box.red .val { color: var(--error); }
.stat-box.blue .val { color: var(--info); }
.stat-box.warning .val { color: var(--warning); }

/* Detailed Solutions UI */
.solution-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

.sol-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
}

.sol-q-text {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 16px;
    line-height: 1.5;
}

.sol-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.sol-opt {
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 0.9rem;
    background: var(--bg-main);
    color: var(--text-dark);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sol-opt.correct { background: #ECFDF5; border-color: var(--success); color: #065F46; font-weight: 600; }
.sol-opt.wrong { background: #FEF2F2; border-color: var(--error); color: #991B1B; }

.sol-explanation {
    background: var(--primary-light);
    padding: 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text-dark);
    border-left: 4px solid var(--primary);
    line-height: 1.6;
}

/* ========================================= */
/* BOOKMARKS & UTILITIES                     */
/* ========================================= */
.bookmark-active {
    color: var(--primary) !important;
    font-weight: 900 !important;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), color 0.2s;
}

/* Ensure KaTeX math formulas scale correctly and allow horizontal scroll if too long */
.katex-display {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 5px 0;
    margin: 10px 0;
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.katex-display::-webkit-scrollbar { display: none; }

/* ========================================= */
/* BOTTOM NAVIGATION                         */
/* ========================================= */
#bottom-nav {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    /* Extra padding for safe area */
    padding-bottom: env(safe-area-inset-bottom, 0px);
    height: calc(75px + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    display: flex;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.05);
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: var(--radius-lg);
    z-index: 100;
    transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    border-top: 1px solid var(--border);
}

body.hide-nav #bottom-nav { transform: translateY(100%); }

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    cursor: pointer;
    flex: 1;
    height: 100%;
    transition: all 0.3s ease;
    position: relative;
}

.nav-item i {
    font-size: 1.3rem;
    margin-bottom: 6px;
    transition: 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.nav-item span {
    font-size: 0.65rem;
    font-weight: 700;
    white-space: nowrap;
    transition: 0.3s;
}

.nav-item.active { color: var(--primary); }
.nav-item.active i { transform: translateY(-4px) scale(1.1); }

.nav-item::after {
    content: '';
    position: absolute;
    bottom: max(8px, env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%) scale(0);
    width: 4px;
    height: 4px;
    background: var(--primary);
    border-radius: 50%;
    transition: 0.3s;
}

.nav-item.active::after { transform: translateX(-50%) scale(1); }