:root {
    /* Color Palette */
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --secondary: #3b82f6;
    --accent: #8b5cf6;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #0ea5e9;

    /* Light Theme (default variables will be overridden by dark mode) */
    --bg-base: #f8fafc;
    --bg-glass: rgba(255, 255, 255, 0.7);
    --bg-glass-hover: rgba(255, 255, 255, 0.9);
    --glass-border: rgba(255, 255, 255, 0.5);
    --text-main: #0f172a;
    --text-muted: #64748b;
    --card-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);
    
    /* Code blocks */
    --code-bg: #1e1e1e;
    --code-text: #d4d4d4;

    /* Fonts */
    --font-sans: 'Inter', sans-serif;
    --font-heading: 'Outfit', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

[data-theme="dark"] {
    --bg-base: #0f172a;
    --bg-glass: rgba(30, 41, 59, 0.7);
    --bg-glass-hover: rgba(30, 41, 59, 0.9);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --card-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
    
    --code-bg: #000000;
    --code-text: #e2e8f0;
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-base);
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    font-weight: 700;
    line-height: 1.2;
}

/* Background Animations */
.bg-animated {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}
.blob {
    position: absolute;
    filter: blur(80px);
    opacity: 0.5;
    border-radius: 50%;
    animation: float 20s infinite alternate ease-in-out;
}
.blob-1 {
    width: 400px; height: 400px;
    background: var(--primary);
    top: -10%; left: -10%;
}
.blob-2 {
    width: 500px; height: 500px;
    background: var(--accent);
    bottom: -20%; right: -10%;
    animation-delay: -5s;
}
.blob-3 {
    width: 300px; height: 300px;
    background: var(--secondary);
    top: 40%; left: 40%;
    animation-duration: 25s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(100px, 100px) scale(1.2); }
}

/* Glassmorphism Utilities */
.glass-panel {
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    box-shadow: var(--card-shadow);
    transition: all 0.3s ease;
}

.gradient-text {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: inline-block;
}

/* Navbar */
.navbar {
    position: sticky;
    top: 1rem;
    margin: 0 1rem;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
}
.nav-brand {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary);
}
.nav-links {
    list-style: none;
    display: flex;
    gap: 2rem;
}
.nav-links li {
    cursor: pointer;
    font-weight: 500;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.nav-links li:hover {
    color: var(--primary);
}
.theme-toggle {
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.2rem;
    cursor: pointer;
    transition: transform 0.3s;
}
.theme-toggle:hover {
    transform: rotate(30deg);
}

/* Layout */
.container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1rem;
    position: relative;
}

.view {
    display: none;
    animation: fadeIn 0.4s ease forwards;
}
.view.active {
    display: block;
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    text-align: center;
}
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}
.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}
.btn-secondary {
    background: var(--bg-glass-hover);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
}
.btn-secondary:hover:not(:disabled) {
    background: var(--primary);
    color: white;
}
.btn-outline {
    background: transparent;
    border: 1px solid var(--text-muted);
    color: var(--text-main);
}
.btn-warning {
    background: var(--warning);
    color: white;
}
.btn-lg { padding: 1rem 2rem; font-size: 1.1rem; }
.btn-sm { padding: 0.5rem 1rem; font-size: 0.875rem; }

/* Loader */
.loader-view {
    text-align: center;
    padding: 5rem 0;
}
.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid var(--bg-glass-hover);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

/* Home View */
.hero {
    text-align: center;
    margin-bottom: 4rem;
    padding: 3rem 0;
}
.hero h1 {
    font-size: 4rem;
    margin-bottom: 1rem;
}
.hero p {
    font-size: 1.25rem;
    color: var(--text-muted);
    max-width: 600px;
    margin: 0 auto;
}
.modes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
}
.mode-card {
    padding: 2.5rem;
    text-align: center;
    cursor: pointer;
    border: 2px solid transparent;
}
.mode-card:hover {
    transform: translateY(-10px);
    border-color: var(--primary);
}
.mode-card.exam-mode:hover {
    border-color: var(--danger);
}
.mode-icon {
    font-size: 3rem;
    color: var(--primary);
    margin-bottom: 1.5rem;
}
.exam-mode .mode-icon { color: var(--danger); }
.mode-card h3 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

/* Practice Setup View */
#setup-view { padding: 2rem; }
.setup-content { margin-top: 1.5rem; }
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin: 1.5rem 0;
}
.checkbox-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-glass-hover);
    padding: 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
}
.setup-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

/* Quiz View */
.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    margin-bottom: 2rem;
}
.quiz-progress { flex: 1; margin-right: 2rem; }
.progress-bar {
    height: 8px;
    background: var(--bg-glass-hover);
    border-radius: 4px;
    margin-top: 0.5rem;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.3s ease;
}
.quiz-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.timer {
    font-family: var(--font-mono);
    font-size: 1.25rem;
    font-weight: 600;
}
.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    background: var(--bg-glass-hover);
}
.topic-badge { color: var(--info); border: 1px solid var(--info); }
.diff-badge.easy { color: var(--success); border: 1px solid var(--success); }
.diff-badge.medium { color: var(--warning); border: 1px solid var(--warning); }
.diff-badge.hard { color: var(--danger); border: 1px solid var(--danger); }

.question-container {
    padding: 3rem;
    margin-bottom: 2rem;
}
.question-meta { margin-bottom: 1rem; display: flex; gap: 0.5rem; }
.question-text {
    font-size: 1.5rem;
    margin-bottom: 2rem;
    line-height: 1.4;
}
.code-container {
    background: var(--code-bg);
    color: var(--code-text);
    padding: 1rem;
    border-radius: 0.5rem;
    font-family: var(--font-mono);
    margin-bottom: 2rem;
    overflow-x: auto;
}
.options-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}
.option-btn {
    text-align: left;
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    background: var(--bg-glass-hover);
    border: 2px solid transparent;
    color: var(--text-main);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 1rem;
}
.option-btn:hover:not(:disabled) {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--primary);
}
.option-btn.selected {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.2);
}
.option-btn.correct {
    border-color: var(--success);
    background: rgba(16, 185, 129, 0.2);
}
.option-btn.wrong {
    border-color: var(--danger);
    background: rgba(239, 68, 68, 0.2);
}
.quiz-controls {
    display: flex;
    justify-content: space-between;
}

/* Results View */
.results-header { padding: 3rem; margin-bottom: 2rem; }
.score-circle { width: 150px; margin: 2rem auto; }
.circular-chart { display: block; margin: 0 auto; max-width: 80%; max-height: 250px; }
.circle-bg { fill: none; stroke: var(--bg-glass-hover); stroke-width: 3.8; }
.circle { fill: none; stroke-width: 2.8; stroke-linecap: round; transition: stroke-dasharray 1s ease-out; }
.percentage { fill: var(--text-main); font-family: var(--font-heading); font-size: 0.5em; text-anchor: middle; font-weight: bold; }
.results-stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }
.stat-card { padding: 1.5rem; text-align: center; }
.stat-value { display: block; font-size: 2.5rem; font-weight: bold; margin-top: 0.5rem; font-family: var(--font-mono); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.topic-breakdown { padding: 2rem; }
.topic-stat-row { display: flex; justify-content: space-between; padding: 0.75rem 0; border-bottom: 1px solid var(--glass-border); }

/* Review Item */
.review-item { padding: 1.5rem; margin-bottom: 1.5rem; }
.review-explanation { margin-top: 1.5rem; padding: 1rem; background: rgba(14, 165, 233, 0.1); border-left: 4px solid var(--info); border-radius: 0 0.5rem 0.5rem 0; }

/* Dashboard */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; }
.dashboard-grid > div { padding: 2rem; }
.progress-stats { display: flex; gap: 2rem; margin-top: 1.5rem; }
.p-stat { flex: 1; background: var(--bg-glass-hover); padding: 1rem; border-radius: 0.5rem; text-align: center; }
.p-label { display: block; font-size: 0.875rem; color: var(--text-muted); }
.p-val { font-size: 2rem; font-weight: bold; color: var(--primary); }

/* Notes View */
.notes-layout { display: flex; gap: 2rem; align-items: flex-start; }
.notes-sidebar { width: 250px; padding: 1.5rem; position: sticky; top: 80px; }
.toc-list { list-style: none; }
.toc-list li { padding: 0.5rem; cursor: pointer; border-radius: 0.25rem; transition: background 0.2s; }
.toc-list li:hover, .toc-list li.active { background: rgba(99, 102, 241, 0.2); color: var(--primary); }
.notes-content { flex: 1; padding: 3rem; min-height: 500px; }
.notes-content h2 { color: var(--primary); margin-bottom: 1rem; }
.notes-content h3 { margin: 1.5rem 0 0.5rem; }
.notes-content ul { margin-left: 1.5rem; margin-bottom: 1rem; }
.empty-state { text-align: center; color: var(--text-muted); padding: 5rem 0; }

/* Cheat Sheet Table */
.cheat-table { width: 100%; border-collapse: collapse; min-width: 800px; }
.cheat-table th, .cheat-table td { padding: 1rem; text-align: left; border-bottom: 1px solid var(--glass-border); }
.cheat-table th { background: rgba(0,0,0,0.1); font-weight: 600; color: var(--primary); }
.complexity-o1 { color: var(--success); font-weight: bold; }
.complexity-ologn { color: var(--info); font-weight: bold; }
.complexity-on { color: var(--warning); font-weight: bold; }
.complexity-onlogn { color: #f97316; font-weight: bold; }
.complexity-on2 { color: var(--danger); font-weight: bold; }

/* Utilities */
.text-center { text-align: center; }
.mt-4 { margin-top: 1.5rem; }
.mb-4 { margin-bottom: 1.5rem; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.col-span-2 { grid-column: span 2; }

/* Footer */
.app-footer {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1rem;
    text-align: center;
}
.footer-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem;
}
.social-links {
    display: flex;
    gap: 1.5rem;
}
.social-links a {
    color: var(--text-main);
    font-size: 1.5rem;
    transition: color 0.3s, transform 0.3s;
}
.social-links a:hover {
    color: var(--primary);
    transform: translateY(-3px);
}
.text-primary { color: var(--primary); }

/* Responsive */
@media (max-width: 768px) {
    .nav-links { display: none; }
    .hero h1 { font-size: 2.5rem; }
    .notes-layout { flex-direction: column; }
    .notes-sidebar { width: 100%; position: static; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .results-stats-grid { grid-template-columns: 1fr; }
    .progress-stats { flex-direction: column; }
}
