:root {
    --brand-primary: #002147;
    --brand-secondary: #005bb5;
    --accent: #D4AF37;
    --bg-body: #f4f6f9;
    --bg-card: #ffffff;
    --text-main: #2c3e50;
    --text-sub: #6c757d;
    --border-subtle: #e9ecef;
    --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.06);
    --success-bg: #d1e7dd;
    --success-text: #0f5132;
    --error-bg: #f8d7da;
    --error-text: #842029;
    --flag-bg: #fff3cd;
    --flag-text: #856404;
}

[data-theme="dark"] {
    --brand-primary: #3b82f6;
    --brand-secondary: #60a5fa;
    --bg-body: #121212;
    --bg-card: #1e1e1e;
    --text-main: #e2e8f0;
    --text-sub: #94a3b8;
    --border-subtle: #333;
    --success-bg: #064e3b;
    --success-text: #6ee7b7;
    --error-bg: #7f1d1d;
    --error-text: #fca5a5;
    --flag-bg: #451a03;
    --flag-text: #fcd34d;
}

[data-theme="dark"] body {
    background-image:
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.1) 0, transparent 50%),
        radial-gradient(at 100% 100%, rgba(147, 197, 253, 0.05) 0, transparent 50%);
}

body {
    font-family: 'Outfit', 'Segoe UI', system-ui, sans-serif;
    background-color: var(--bg-body);
    background-image:
        radial-gradient(at 0% 0%, rgba(0, 33, 71, 0.05) 0, transparent 50%),
        radial-gradient(at 100% 100%, rgba(0, 91, 181, 0.05) 0, transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    margin: 0;
    padding: 0;
    transition: background-color 0.4s ease, color 0.4s ease;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* --- CUSTOM SCROLLBARS --- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(150, 150, 150, 0.3);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(150, 150, 150, 0.5);
}

/* --- ANIMATIONS --- */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes pulseGlowLight {
    0% {
        box-shadow: 0 0 0 0 rgba(0, 33, 71, 0.2);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(0, 33, 71, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(0, 33, 71, 0);
    }
}

@keyframes pulseGlowDark {
    0% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.2);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(59, 130, 246, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
    }
}

/* --- GLASSMORPHISM UTILITIES --- */
.glass-panel {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

[data-theme="dark"] .glass-panel {
    background: rgba(30, 30, 30, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.glass-card {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.05);
}

[data-theme="dark"] .glass-card {
    background: rgba(40, 40, 40, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    box-sizing: border-box;
}

/* --- LAYOUT GRID --- */
.app-container {
    display: flex;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

/* --- SIDEBAR --- */
.sidebar {
    width: 250px;
    background: var(--bg-card);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: margin-left 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s ease;
    z-index: 1000;
    /* Increased Z to sit above content when toggling */
    overflow-x: hidden;
    margin-left: 0;
}

body.sidebar-collapsed .sidebar {
    margin-left: -250px;
}

.sidebar-brand {
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border-subtle);
}

.logo-icon {
    font-size: 1.8rem;
    background: rgba(0, 33, 71, 0.05);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    overflow: hidden;
    /* Ensure image stays inside */
}

.logo-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 5px;
    /* Add some breathing room */
}

.brand-text {
    font-weight: 800;
    color: var(--brand-primary);
    line-height: 1.1;
}

.tier-pill {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    margin-top: 5px;
    color: white;
    background: #ccc;
}

.tier-free {
    background: #6c757d;
}

.tier-plus {
    background: var(--brand-secondary);
}

.tier-tester {
    background: var(--accent);
    color: #000;
}

.tier-admin {
    background: #dc3545;
}

.sidebar-nav {
    flex: 1;
    padding: 8px 6px;
    display: flex;
    flex-direction: column;
    gap: 0px;
    overflow-y: hidden;
    overflow-x: hidden;
}

.options-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    /* Reduced from 8px */
    margin-top: 10px;
    /* Reduced from 15px */
}

.opt-label {
    display: flex;
    align-items: center;
    /* better alignment */
    gap: 8px;
    /* Reduced from 10px */
    padding: 8px 12px;
    /* Super compressed from 10px 15px */
    border: 2px solid var(--border-subtle);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-body);
    font-size: 0.95rem;
    /* Slightly smaller for density */
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: none;
    background: transparent;
    color: var(--text-sub);
    font-weight: 600;
    cursor: pointer;
    border-radius: 8px;
    transition: 0.2s;
    text-align: left;
    width: 100%;
    font-size: 0.9rem;
    font-family: inherit;
}

.nav-item:hover {
    background: rgba(0, 0, 0, 0.03);
    color: var(--brand-primary);
    transform: translateX(2px);
}

.nav-item.active {
    background: rgba(0, 33, 71, 0.08);
    color: var(--brand-primary);
    font-weight: 700;
}

[data-theme="dark"] .nav-item.active {
    background: rgba(255, 255, 255, 0.1);
}

.nav-item .icon {
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
}

.sidebar-footer {
    padding: 8px 12px;
    border-top: 1px solid var(--border-subtle);
}

.nav-header {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-sub);
    font-weight: 700;
    margin: 8px 0 2px 10px;
    letter-spacing: 0.5px;
    opacity: 0.8;
}

/* --- MAIN CONTENT --- */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
    background: var(--bg-body);
}

.top-bar {
    padding: 15px 30px;
    background: var(--bg-body);
    position: sticky;
    top: 0;
    z-index: 50;
}

.hamburger-btn {
    display: none;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text-main);
    cursor: pointer;
    padding: 5px;
}

body.sidebar-collapsed .global-hamburger {
    display: block;
    /* Reveal top-bar hamburger when main sidebar leaves */
}

/* Phase 25: Bind Top Bar Logo strictly to layout state */
#top-bar-brand {
    display: none !important;
}

body.sidebar-collapsed #top-bar-brand {
    display: flex !important;
}

.top-bar-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    max-width: 1000px;
    margin: 0 auto;
    width: 100%;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--brand-primary);
}

.module-switcher-compact {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 20px;
    padding: 3px;
    display: flex;
}

.mod-pill {
    padding: 5px 15px;
    border-radius: 15px;
    border: none;
    background: transparent;
    font-weight: 600;
    color: var(--text-sub);
    cursor: pointer;
    font-size: 0.85rem;
    transition: 0.2s;
}

.mod-pill.active {
    background: var(--brand-primary);
    color: white;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

/* --- VIEWS --- */
.view-section {
    padding: 30px 30px 40px 30px;
    animation: fadeInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    max-width: 1000px;
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
}

.view-section.hidden {
    display: none;
    animation: none;
}

.dashboard-hero {
    background: radial-gradient(circle at top right, var(--brand-secondary), var(--brand-primary));
    color: white;
    padding: 40px;
    border-radius: 20px;
    margin-bottom: 30px;
    box-shadow: 0 15px 35px rgba(0, 33, 71, 0.2);
    position: relative;
    overflow: hidden;
}

/* Subtle texture/glow overlay */
.dashboard-hero::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml;utf8,<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"><filter id="noiseFilter"><feTurbulence type="fractalNoise" baseFrequency="0.65" numOctaves="3" stitchTiles="stitch"/></filter><rect width="100%" height="100%" filter="url(%23noiseFilter)" opacity="0.05"/></svg>');
    opacity: 0.3;
    pointer-events: none;
}

[data-theme="dark"] .dashboard-hero {
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.4);
}

.dashboard-hero h1 {
    color: white;
    margin-bottom: 10px;
    font-size: 2rem;
}

.dashboard-hero p {
    margin-top: 0;
    opacity: 0.9;
    font-size: 1.1rem;
}

.dashboard-hero button {
    background: white;
    color: var(--brand-primary);
    border: none;
    font-weight: 700;
    margin-top: 20px;
    width: auto;
    padding: 12px 25px;
}

.dashboard-hero button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

/* --- EXAM MODE OVERRIDES (Desktop) --- */
/* (Phase 24: Removed old fixed sidebar logic. Sidebar is now controlled globally via .sidebar-collapsed) */

body.exam-mode .mobile-overlay.active {
    display: block;
    /* Maintain capability to darken if needed */
}

/* Ensure main content stretches when sidebar is gone */
body.sidebar-collapsed .main-content {
    margin-left: 0 !important;
}

/* --- RESPONSIVE MOBILE --- */
@media (max-width: 800px) {
    .app-container {
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
    }

    .hamburger-btn {
        display: block;
    }

    .top-bar {
        padding: 15px 20px;
    }

    /* Standard Vertical Slide-out Menu */
    .sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        /* Hidden by default */
        width: 250px;
        height: 100vh;
        z-index: 1000;
        transition: left 0.3s cubic-bezier(0.16, 1, 0.3, 1);
        border-right: 1px solid var(--border-subtle);
        box-shadow: 5px 0 25px rgba(0, 0, 0, 0.1);
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-brand {
        justify-content: space-between;
        padding: 12px 15px;
    }

    .sidebar-nav {
        flex-direction: column;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 10px 8px;
        flex: 1;
        gap: 0;
    }

    .nav-header {
        margin: 10px 0 3px 12px;
        font-size: 0.65rem;
    }

    .nav-item {
        flex-direction: row;
        justify-content: flex-start;
        padding: 8px 10px;
        font-size: 0.9rem;
    }

    .nav-item .icon {
        font-size: 1.1rem;
    }

    .sidebar-footer {
        position: relative;
        bottom: auto;
        left: auto;
        width: 100%;
        border-top: 1px solid var(--border-subtle);
        display: flex;
        flex-direction: column;
        padding: 8px 12px;
        box-shadow: none;
    }

    .view-section {
        padding: 20px 20px 40px 20px;
    }

    .main-content {
        height: 100%;
        overflow-y: auto;
    }


    /* Overlay for clicking out */
    .mobile-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 900;
        /* Just below sidebar */
        backdrop-filter: blur(2px);
    }

    .mobile-overlay.active {
        display: block;
    }
}

.panel {
    padding: 25px;
    border-radius: 16px;
    margin-bottom: 25px;
    animation: fadeInUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* New/Modified styles for shrinking elements */
.q-card {
    padding: 15px;
    /* Shrink padding */
}

.q-text {
    margin-bottom: 10px;
    /* Shrink margin */
}

.option-item {
    margin-bottom: 8px;
    /* Shrink margin */
    padding: 8px 0;
    /* Shrink padding */
}

.option-label {
    font-weight: 700;
    margin-right: 10px;
    /* Reduced from 15px */
    color: var(--brand-secondary);
}

.option-text {
    flex: 1;
    font-size: 0.95rem;
    /* Slight compacting */
}

.action-buttons {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    /* Phase 26: Reduced from explicit empty state */
    padding-top: 10px;
    border-top: 1px solid var(--border-subtle);
}

.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--brand-primary);
}

input,
select,
textarea {
    width: 100%;
    padding: 12px 15px;
    border-radius: 8px;
    border: 2px solid var(--border-subtle);
    background: var(--bg-card);
    color: var(--text-main);
    font-size: 1rem;
    box-sizing: border-box;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--brand-primary);
    outline: none;
}

/* --- CUSTOM RANGE SLIDER --- */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--border-subtle);
    border-radius: 5px;
    outline: none;
    opacity: 0.8;
    transition: opacity .2s;
    border: none;
    padding: 0;
}

input[type="range"]:hover {
    opacity: 1;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--brand-primary);
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

textarea {
    resize: none;
    overflow-y: hidden;
}

.source-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    border-bottom: 2px solid var(--border-subtle);
    padding-bottom: 10px;
}

.source-tab {
    cursor: pointer;
    padding: 5px 10px;
    font-weight: 600;
    color: var(--text-sub);
    opacity: 0.6;
    transition: 0.2s;
    border-radius: 6px;
}

.source-tab:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.03);
}

.source-tab.active {
    color: var(--brand-primary);
    opacity: 1;
    background: rgba(0, 33, 71, 0.05);
}

.drop-zone {
    border: 2px dashed var(--border-subtle);
    border-radius: 12px;
    padding: 30px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: rgba(0, 0, 0, 0.01);
}

.drop-zone:hover {
    border-color: var(--brand-primary);
    background: rgba(0, 33, 71, 0.03);
}

.file-chip {
    display: inline-block;
    background: var(--border-subtle);
    padding: 4px 10px;
    border-radius: 15px;
    margin: 4px;
    font-size: 0.8rem;
}

.library-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.02);
}

.lib-category {
    margin-bottom: 15px;
}

.lib-cat-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--brand-primary);
    text-transform: uppercase;
    margin-bottom: 5px;
    padding-left: 5px;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 2px;
}

.lib-item {
    display: flex;
    align-items: center;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: 0.2s;
}

.lib-item:hover {
    background: var(--bg-card);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.lib-item input {
    width: 18px;
    height: 18px;
    margin-right: 10px;
    cursor: pointer;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    width: auto;
    transition: transform 0.1s;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-primary {
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 33, 71, 0.3);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    font-size: 0.9rem;
    margin: 2px;
}

.btn-secondary:hover {
    border-color: var(--brand-secondary);
    color: var(--brand-primary);
}

.btn-secondary.active {
    background: var(--brand-primary);
    color: white;
    border-color: var(--brand-primary);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 0.85rem;
    border-radius: 6px;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.toggle-card {
    background: rgba(0, 0, 0, 0.03);
    padding: 10px 12px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border: 1px solid transparent;
    transition: 0.2s;
}

.toggle-card:hover {
    border-color: var(--border-subtle);
    background: rgba(0, 0, 0, 0.05);
}

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

.toggle-header strong {
    font-size: 0.95rem;
    color: var(--brand-primary);
}

.toggle-desc {
    font-size: 0.75rem;
    color: var(--text-sub);
    line-height: 1.2;
    margin-top: 0;
}

.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.slider {
    background-color: var(--brand-primary);
}

input:checked+.slider:before {
    transform: translateX(18px);
}

/* --- QUESTION CARDS --- */
.q-card-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* Much tighter than 15px */
}

.q-card {
    background: var(--bg-card);
    padding: 12px 15px;
    /* Phase 26: Super compressed from 15px 20px */
    border-radius: 16px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    /* Softer shadow */
    border: 1px solid var(--border-subtle);
    font-size: 1rem;
    /* Compact font size */
    line-height: 1.4;
    /* Tighter line height */
    position: relative;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.3s;
    margin-bottom: 20px;
    scroll-margin-top: 100px;
}

.q-card.flagged {
    border-left-color: var(--accent);
}

.q-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
}

.badge {
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    background: var(--border-subtle);
    color: var(--text-sub);
    margin-right: 5px;
    cursor: pointer;
    transition: 0.2s;
}

.badge:hover {
    opacity: 0.8;
    transform: scale(1.05);
}

.badge.hidden-tag {
    display: none;
}

.flag-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-sub);
    font-size: 1.2rem;
}

.flag-btn.active {
    color: var(--accent);
}

.nav-sidebar {
    position: fixed;
    right: 20px;

    /* Phase 29: Vertical safe-zone lock, stopping overlap. */
    top: 90px;
    max-height: calc(100vh - 120px);
    /* Stretch only as needed, never past bottom */

    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 90;
    background: var(--bg-card);
    padding: 10px;
    border-radius: 20px;
    box-shadow: var(--shadow-card);
    border: 1px solid var(--border-subtle);
    display: none;
    transition: all 0.3s ease;

    /* Phase 27/29: Scrollable Navigation Container */
    overflow-y: auto;
    -ms-overflow-style: none;
    /* IE and Edge */
    scrollbar-width: none;
    /* Firefox */
}

/* Phase 27: Hide scrollbar visually but keep functionality */
.nav-sidebar::-webkit-scrollbar {
    display: none;
}

.nav-dot {
    width: 30px;
    /* Upgraded from 12px */
    height: 30px;
    /* Upgraded from 12px */
    border-radius: 8px;
    /* Rounded Squares */
    background: var(--border-subtle);
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    flex-shrink: 0;

    /* Phase 27: Number styling */
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: var(--text-main);
    font-size: 0.9rem;
}

.nav-dot:hover {
    transform: scale(1.1);
    /* Reduced scale jump since it is larger */
}

.nav-dot.answered {
    background: var(--brand-primary);
    color: white;
    /* Contrast */
}

.nav-dot.flagged {
    box-shadow: 0 0 0 2px var(--accent);
}

.nav-dot.correct {
    background: #28a745 !important;
    color: white;
}

.nav-dot.wrong {
    background: #dc3545 !important;
    color: white;
}

.nav-dot.partial {
    background: #fd7e14 !important;
    color: white;
}

.nav-dot.active-dot {
    transform: scale(1.1);
    z-index: 2;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    border: 2px solid white;
    /* Hard emphasis */
}

/* Phase 27: Sub-screens shift nav to bottom */
@media (max-width: 1250px) {
    .nav-sidebar {
        position: fixed;
        bottom: 20px;
        top: auto;
        right: 50%;
        transform: translateX(50%);
        flex-direction: row;
        flex-wrap: wrap;
        width: max-content;
        max-width: 90vw;
        justify-content: center;
    }
}

.saq-intro {
    background: rgba(0, 0, 0, 0.03);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-style: italic;
}

.saq-part {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px dashed var(--border-subtle);
}

.saq-part:last-child {
    border-bottom: none;
}

.marking-scheme {
    display: none;
    background: rgba(0, 128, 0, 0.05);
    padding: 15px;
    border-radius: 8px;
    margin-top: 10px;
    border: 1px solid var(--success-text);
}

.mark-point {
    display: flex;
    align-items: flex-start;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: var(--success-text);
    cursor: pointer;
}

.mark-point input {
    width: 18px;
    height: 18px;
    margin-right: 10px;
    margin-top: 3px;
    cursor: pointer;
    flex-shrink: 0;
}

.option-item {
    border: 2px solid var(--border-subtle);
    border-radius: 8px;
    margin-bottom: 6px;
    /* Phase 26: Reduced from 10px */
    padding: 8px 12px;
    /* Phase 26: Added explicit dense padding */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: 0.2s;
}

.option-item:hover {
    border-color: var(--brand-secondary);
    background: rgba(0, 33, 71, 0.02);
}

.option-item.excluded {
    opacity: 0.5;
    text-decoration: line-through;
    background: rgba(0, 0, 0, 0.05);
    border-color: transparent;
}

.option-item label {
    padding: 15px;
    cursor: pointer;
    width: 100%;
    display: flex;
    align-items: center;
}

.option-item input {
    width: 20px;
    height: 20px;
    margin-right: 15px;
}

.exclude-btn {
    background: none;
    border: none;
    color: var(--text-sub);
    font-size: 1.2rem;
    padding: 0 15px;
    cursor: pointer;
    opacity: 0.5;
    transition: 0.2s;
}

.exclude-btn:hover {
    opacity: 1;
    color: var(--error-text);
    transform: scale(1.2);
}

.feedback-box {
    margin-top: 20px;
    padding: 15px;
    border-radius: 8px;
    display: none;
    animation: slideDown 0.3s;
}

.feedback-box.correct {
    background: var(--success-bg);
    color: var(--success-text);
    border: 1px solid currentColor;
}

.feedback-box.wrong {
    background: var(--error-bg);
    color: var(--error-text);
    border: 1px solid currentColor;
}

.word-count {
    font-size: 0.8rem;
    color: var(--text-sub);
    display: block;
    text-align: right;
    margin-top: 5px;
}

.word-count.error {
    color: var(--error-text);
    font-weight: bold;
}

#sticky-score {
    position: sticky;
    top: 10px;
    z-index: 100;
    background: var(--brand-primary);
    color: white;
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    display: none;
}

.filter-matrix {
    background: var(--bg-card);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid var(--border-subtle);
    margin-bottom: 20px;
}

.filter-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 10px;
    align-items: center;
}

.filter-label {
    font-size: 0.8rem;
    font-weight: bold;
    width: 80px;
    color: var(--text-sub);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-card);
    padding: 30px;
    border-radius: 16px;
    text-align: center;
    max-width: 600px;
    width: 90%;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    animation: popIn 0.3s;
    max-height: 90vh;
    overflow-y: auto;
}

.score-circle {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 8px solid var(--brand-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--brand-primary);
    margin: 0 auto 20px;
}

.instruction-section {
    text-align: left;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 15px;
}

.instruction-section h3 {
    margin: 0 0 10px 0;
    color: var(--brand-primary);
    font-size: 1.1rem;
}

.instruction-section p,
.instruction-section li {
    margin: 5px 0;
    font-size: 0.95rem;
    color: var(--text-main);
    line-height: 1.5;
}

.instruction-section ul {
    padding-left: 20px;
    margin: 0;
}

.highlight {
    color: var(--brand-secondary);
    font-weight: bold;
}

.changelog-table {
    width: 100%;
    text-align: left;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 10px;
    font-size: 0.85rem;
}

.changelog-table th {
    background: var(--brand-primary);
    color: white;
    padding: 8px;
}

.changelog-table th:first-child {
    border-top-left-radius: 8px;
}

.changelog-table th:last-child {
    border-top-right-radius: 8px;
}

.changelog-table td {
    border-bottom: 1px solid var(--border-subtle);
    padding: 8px;
    vertical-align: top;
}

.changelog-table tr:last-child td {
    border-bottom: none;
}

.version-badge {
    background: var(--accent);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 0.75rem;
}

.disclaimer-box {
    background: var(--flag-bg);
    color: var(--flag-text);
    padding: 15px;
    border-radius: 8px;
    font-size: 0.9rem;
    margin-top: 20px;
    text-align: left;
    border: 1px solid var(--accent);
}

.footer-credit {
    text-align: center;
    margin-top: 30px;
    color: var(--text-sub);
    font-size: 0.9rem;
    font-weight: 500;
    opacity: 0.7;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes popIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

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

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.6;
    }
}

.hidden {
    display: none !important;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s;
}

[data-theme="dark"] .loading-overlay {
    background: rgba(0, 0, 0, 0.7);
}

.spinner {
    width: 60px;
    height: 60px;
    border: 6px solid var(--border-subtle);
    border-top: 6px solid var(--brand-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

#loading-text {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--brand-primary);
    animation: pulse 1.5s infinite;
}

/* --- DASHBOARD STATS --- */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 40px;
}

.stat-card {
    background: var(--bg-card);
    padding: 40px 20px;
    border-radius: 12px;
    text-align: center;
    box-shadow: var(--shadow-card);
    border: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-5px);
    border-color: var(--brand-secondary);
}

.stat-value {
    display: block;
    font-size: 3rem;
    font-weight: 800;
    color: var(--brand-secondary);
    line-height: 1.2;
    margin-bottom: 10px;
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-sub);
}

@media (max-width: 768px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
}

.huge-input {
    font-size: 2rem !important;
    text-align: center;
    padding: 15px !important;
    font-weight: 700;
    color: var(--brand-primary) !important;
}

/* Library Collapsible Styles */
details.lib-category {
    margin-bottom: 15px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    overflow: hidden;
    color: var(--text-main);
}

summary.lib-cat-title {
    padding: 10px 15px;
    background: rgba(0, 0, 0, 0.03);
    font-weight: 600;
    cursor: pointer;
    list-style: none;
    /* Hide default triangle */
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--brand-primary);
}

/* Dark theme specific override */
[data-theme="dark"] summary.lib-cat-title {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

[data-theme="dark"] .lib-cat-content {
    background: var(--bg-card);
    color: var(--text-main);
}

summary.lib-cat-title::-webkit-details-marker {
    display: none;
}

summary.lib-cat-title::after {
    content: '▼';
    font-size: 0.8em;
    transition: transform 0.2s;
}

details[open] summary.lib-cat-title::after {
    transform: rotate(180deg);
}

.lib-cat-content {
    padding: 10px;
    border-top: 1px solid var(--border-subtle);
}

.select-all-row {
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 8px;
    margin-bottom: 8px;
    color: var(--brand-secondary);
}

/* Ensure generic modal (alerts) is above login modal */
#generic-modal {
    z-index: 2000;
}

#modal-login {
    z-index: 1000;
}

/* --- LANDING PAGES SHARED STYLES --- */
body.landing-page {
    display: block;
    height: auto;
    overflow-y: auto;
    background: var(--bg-body);
}

.landing-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 30px 0;
}

.logo {
    font-weight: 700;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-main);
    text-decoration: none;
}

@media (max-width: 768px) {
    .landing-nav {
        flex-direction: column;
        gap: 20px;
        padding: 20px 0;
    }
}