:root {
    --bg-dark: #0f1115;
    --bg-panel: rgba(25, 28, 35, 0.6);
    --border-light: rgba(255, 255, 255, 0.08);
    --text-main: #f0f2f5;
    --text-muted: #a0a5b1;
    --accent-primary: #6366f1;
    --accent-hover: #4f46e5;
    --accent-glow: rgba(99, 102, 241, 0.4);
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --correct-bg: rgba(16, 185, 129, 0.15);
    --correct-border: rgba(16, 185, 129, 0.4);
    --wrong-bg: rgba(239, 68, 68, 0.15);
    --wrong-border: rgba(239, 68, 68, 0.4);
    --panel-radius: 16px;
    --transition: cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.6;
    /* Create a premium dark gradient background */
    background: radial-gradient(circle at 15% 50%, rgba(99, 102, 241, 0.15), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(139, 92, 246, 0.15), transparent 25%);
    background-color: var(--bg-dark);
}

/* Desktop: lock body scroll, content scrolls inside panels */
@media (min-width: 901px) {
    body {
        overflow: hidden;
    }
}

.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-light);
    border-radius: var(--panel-radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.app-container {
    display: flex;
    height: 100vh;
    padding: 20px;
    gap: 20px;
    max-width: 1600px;
    margin: 0 auto;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Sidebar */
.sidebar {
    width: 320px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.sidebar-header h2 {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, #a5b4fc, #818cf8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 10px;
}

.modules-accordion {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.module-group {
    margin-bottom: 12px;
}

.module-title {
    padding: 12px 16px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    border-radius: 8px;
    transition: all 0.3s var(--transition);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.module-title:hover {
    background: rgba(255, 255, 255, 0.05);
}

.module-title i {
    font-size: 0.8rem;
    transition: transform 0.3s ease;
}

.module-title.active i {
    transform: rotate(180deg);
}

.section-list {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s var(--transition);
    padding-left: 10px;
}

.section-list.open {
    max-height: 2000px;
}

.section-item {
    padding: 10px 16px;
    margin: 4px 0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-muted);
    transition: all 0.2s ease;
    border-left: 2px solid transparent;
}

.section-item:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.03);
    border-left-color: var(--accent-primary);
}

.section-item.active {
    color: #fff;
    background: var(--accent-glow);
    border-left-color: #fff;
    font-weight: 600;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 32px;
}

.header-info {
    flex: 1;
}

.header-info h1 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.progress-container {
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
    max-width: 400px;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary), #8b5cf6);
    box-shadow: 0 0 10px var(--accent-glow);
    transition: width 0.5s var(--transition);
}

.score-card {
    text-align: right;
    padding-left: 24px;
    border-left: 1px solid var(--border-light);
}

.score-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.score-value {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--success);
}

.quiz-container {
    flex: 1;
    padding: 32px;
    overflow-y: auto;
    position: relative;
    scroll-behavior: smooth;
}

.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-muted);
}

.welcome-icon {
    font-size: 4rem;
    margin-bottom: 24px;
    background: linear-gradient(135deg, var(--accent-primary), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

/* Question Cards */
.question-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    transform: translateY(10px);
    opacity: 0;
    animation: slideUp 0.4s var(--transition) forwards;
    transition: all 0.3s ease;
}

.question-card:hover {
    border-color: rgba(255, 255, 255, 0.1);
}

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

.q-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.q-badge {
    background: rgba(99, 102, 241, 0.1);
    color: #a5b4fc;
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.q-text {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 24px;
    line-height: 1.5;
}

/* Options */
.options-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.option-box {
    display: flex;
    align-items: center;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--border-light);
    background: rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.option-box:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
}

.option-box.selected {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--accent-primary);
}

.option-box.correct-reveal {
    background: var(--correct-bg);
    border-color: var(--correct-border);
}

.option-box.wrong-reveal {
    background: var(--wrong-bg);
    border-color: var(--wrong-border);
}

.opt-letter {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
    margin-right: 16px;
    flex-shrink: 0;
    transition: all 0.2s;
}

.option-box.selected .opt-letter {
    background: var(--accent-primary);
    color: #fff;
}

.option-box.correct-reveal .opt-letter {
    background: var(--success);
    color: #fff;
}

.option-box.wrong-reveal .opt-letter {
    background: var(--danger);
    color: #fff;
}

.opt-text {
    flex: 1;
    font-size: 0.95rem;
}

.opt-icon {
    position: absolute;
    right: 16px;
    font-size: 1.2rem;
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.option-box.correct-reveal .opt-icon {
    opacity: 1;
    transform: scale(1);
    color: var(--success);
}

.option-box.wrong-reveal .opt-icon {
    opacity: 1;
    transform: scale(1);
    color: var(--danger);
}

/* Explanation */
.explanation {
    margin-top: 20px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.03);
    border-left: 3px solid var(--accent-primary);
    border-radius: 0 8px 8px 0;
    font-size: 0.9rem;
    color: #cbd5e1;
    display: none;
    animation: fadeIn 0.5s ease;
}

.explanation strong {
    color: #fff;
    display: block;
    margin-bottom: 8px;
}

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

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

/* Controls */
.controls {
    padding: 20px 32px;
    display: flex;
    justify-content: flex-end;
    gap: 16px;
}

.btn {
    padding: 12px 24px;
    border-radius: 8px;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    border: none;
    outline: none;
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
    box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
}

.btn-outline {
    background: transparent;
    color: var(--text-main);
    border: 1px solid var(--border-light);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.05);
}

.btn-glow {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    width: 100%;
    justify-content: center;
}

.btn-glow:hover {
    background: rgba(255, 255, 255, 0.15);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.1);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    border-radius: 30px;
    background: var(--accent-primary);
    color: white;
    font-weight: 500;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* Loading State */
/* Cheatsheet Right Panel */
.cheatsheet-panel {
    width: 280px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.cheatsheet-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-light);
}

.cheatsheet-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 8px;
}

.cheatsheet-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}

.cheatsheet-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    gap: 12px;
}

.cheatsheet-empty i {
    font-size: 2rem;
    opacity: 0.4;
}

.cheatsheet-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
}

.formula-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.formula-item {
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.2s ease;
}

.formula-item:hover {
    background: rgba(99, 102, 241, 0.08);
    border-color: rgba(99, 102, 241, 0.2);
}

.formula-name {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    font-weight: 600;
}

.formula-value {
    font-size: 0.88rem;
    font-family: 'Courier New', monospace;
    color: #a5b4fc;
    word-break: break-word;
}

.formula-latex {
    margin: 6px 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.formula-latex .katex {
    font-size: 0.9rem;
    color: #c4b5fd;
}

.formula-note {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
    margin-top: 4px;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    padding-top: 4px;
}

/* Cheatsheet Toggle Button (for tablet/mobile) */
.cheatsheet-toggle-btn {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1001;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 1px solid var(--border-light);
    background: var(--accent-primary);
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px var(--accent-glow);
    transition: all 0.2s ease;
}

.cheatsheet-toggle-btn:hover {
    transform: scale(1.1);
}

/* Loading State */
.loader {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: var(--accent-primary);
    animation: spin 1s ease-in-out infinite;
    margin: 40px auto;
}

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

/* Mobile Menu Button */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 1001;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid var(--border-light);
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    color: var(--text-main);
    font-size: 1.2rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
}

.mobile-menu-btn:hover {
    background: rgba(99, 102, 241, 0.2);
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    opacity: 1;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 900px) {
    .mobile-menu-btn {
        display: flex;
    }

    .sidebar-overlay {
        display: block;
        pointer-events: none;
    }

    .sidebar-overlay.active {
        pointer-events: auto;
    }

    .app-container {
        flex-direction: column;
        padding: 10px;
        gap: 10px;
        height: 100vh;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 300px;
        z-index: 1000;
        transform: translateX(-110%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        border-radius: 0 var(--panel-radius) var(--panel-radius) 0;
        overflow-y: auto;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        width: 100%;
    }

    header {
        padding: 14px 16px;
        padding-left: 60px;
    }

    .header-info h1 {
        font-size: 1rem;
    }

    .score-value {
        font-size: 1.3rem;
    }

    .quiz-container {
        padding: 16px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        flex: 1;
        min-height: 0;
    }

    .main-content {
        height: calc(100vh - 20px);
        overflow: hidden;
    }

    .question-card {
        padding: 16px;
        margin-bottom: 16px;
    }

    .q-text {
        font-size: 1rem;
    }

    .option-box {
        padding: 12px;
    }

    .controls {
        padding: 12px 16px;
    }

    .cheatsheet-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 300px;
        z-index: 1000;
        transform: translateX(110%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        border-radius: var(--panel-radius) 0 0 var(--panel-radius);
    }

    .cheatsheet-panel.open {
        transform: translateX(0);
    }

    .cheatsheet-toggle-btn {
        display: flex;
    }
}

@media (max-width: 480px) {
    .app-container {
        padding: 6px;
    }

    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 12px;
        padding-left: 56px;
    }

    .score-card {
        border-left: none;
        padding-left: 0;
        border-top: 1px solid var(--border-light);
        padding-top: 8px;
        text-align: left;
        width: 100%;
    }

    .progress-container {
        max-width: 100%;
    }

    .header-info h1 {
        font-size: 0.9rem;
    }

    .welcome-icon {
        font-size: 2.5rem;
    }

    .welcome-screen h2 {
        font-size: 1.1rem;
    }

    .welcome-screen p {
        font-size: 0.85rem;
    }

    .q-text {
        font-size: 0.95rem;
    }

    .opt-text {
        font-size: 0.85rem;
    }

    .explanation {
        font-size: 0.8rem;
    }

    .sidebar {
        width: 85vw;
        max-width: 320px;
    }

    .sidebar-header h2 {
        font-size: 1.2rem;
    }

    .btn-glow {
        font-size: 0.85rem;
        padding: 10px 16px;
    }
}