:root {
    /* Light Mode Colors */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    
    --accent-primary: #4f46e5;
    --accent-hover: #4338ca;
    --accent-light: #e0e7ff;
    --accent-dark: #312e81;
    
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    --card-bg: rgba(255, 255, 255, 0.9);
    --glass-border: rgba(255, 255, 255, 0.5);
    --code-bg: #f1f5f9;
    
    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    --gradient-bg: linear-gradient(135deg, #f8fafc 0%, #e0e7ff 100%);
}

.dark-mode {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #0f172a;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    
    --accent-primary: #6366f1;
    --accent-hover: #818cf8;
    --accent-light: #312e81;
    --accent-dark: #c7d2fe;
    
    --border-color: #334155;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    
    --card-bg: rgba(30, 41, 59, 0.8);
    --glass-border: rgba(255, 255, 255, 0.05);
    --code-bg: #0f172a;
    
    --gradient-bg: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--gradient-bg);
    background-attachment: fixed;
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Outfit', sans-serif;
    color: var(--text-primary);
    font-weight: 800;
}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Mobile Header */
.mobile-header {
    display: none;
    position: sticky;
    top: 0;
    z-index: 60;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.logo {
    font-size: 1.5rem;
    font-weight: 800;
    font-style: italic;
    color: var(--text-primary);
}

.logo span {
    color: var(--accent-primary);
}

.mobile-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.1s ease, box-shadow 0.2s ease;
}

.btn-primary:active {
    transform: scale(0.95);
}

.theme-btn {
    background-color: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.theme-btn:hover {
    background-color: var(--border-color);
}

.theme-btn svg {
    width: 1.25rem;
    height: 1.25rem;
}

.dark-mode .theme-btn {
    color: #facc15; /* yellow-400 */
}

/* Sidebar */
.sidebar {
    width: 320px;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
    z-index: 50;
    transition: background-color 0.3s ease, border-color 0.3s ease, transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}
.sidebar::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--bg-tertiary);
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-top: 0.25rem;
}

.theme-switcher-container {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--bg-tertiary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.theme-label {
    font-size: 0.625rem;
    font-weight: 800;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.nav-menu {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-bottom: 2rem;
}

.nav-group-title {
    font-size: 0.625rem;
    font-weight: 900;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 1rem 1rem 0.25rem 1rem;
    margin-top: 0.5rem;
}

.nav-item {
    display: flex;
    flex-direction: column;
    width: 100%;
    text-decoration: none;
    padding: 1rem;
    border-radius: 0.75rem;
    border: 2px solid transparent;
    transition: all 0.2s ease;
    cursor: pointer;
}

.nav-item:hover {
    background-color: var(--bg-tertiary);
}

.nav-item.active {
    border-color: var(--accent-primary);
    background-color: var(--accent-light);
    box-shadow: var(--shadow-sm);
}

.nav-item.active .nav-num {
    color: var(--accent-primary);
}

.nav-item.active .nav-title {
    color: var(--accent-primary);
}

.nav-num {
    font-size: 0.625rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: -0.05em;
    color: var(--text-muted);
    transition: color 0.2s ease;
}

.nav-title {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text-secondary);
    transition: color 0.2s ease;
    margin-top: 0.125rem;
}

/* Main Content */
.main-content {
    flex-grow: 1;
    padding: 2rem 3rem;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.content-wrapper {
    max-w-4xl;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    flex-grow: 1;
}

.content-section {
    display: none;
    animation: fadeIn 0.4s ease-out;
}

.content-section.active {
    display: block;
}

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

/* Typography in Content */
.section-header {
    margin-bottom: 2.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.section-title {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    line-height: 1.2;
}

.section-subtitle {
    color: var(--accent-primary);
    font-style: italic;
    font-size: 0.875rem;
    font-weight: 600;
}

.article-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--accent-hover);
    margin-top: 2.5rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
}

.article-title span {
    color: var(--text-muted);
    margin-right: 0.5rem;
}

p {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

ul {
    list-style-type: disc;
    padding-left: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

li {
    margin-bottom: 0.5rem;
}

strong, b {
    color: var(--text-primary);
    font-weight: 700;
}

/* Premium Components */
.math-display {
    background-color: var(--bg-secondary);
    border-left: 4px solid var(--accent-primary);
    padding: 1.5rem;
    margin: 1.5rem 0;
    border-radius: 0 0.75rem 0.75rem 0;
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
    transition: background-color 0.3s ease;
}

.math-display .def-title {
    font-weight: 800;
    margin-bottom: 0.5rem;
    color: var(--accent-dark);
    text-decoration: underline;
    text-decoration-color: var(--accent-primary);
    text-underline-offset: 4px;
}

.proof-block {
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    margin: 1.5rem 0;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    line-height: 1.7;
}

.proof-title {
    font-weight: 800;
    color: #e11d48; /* rose-600 */
    margin-bottom: 1rem;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.1em;
}
.dark-mode .proof-title {
    color: #fb7185; /* rose-400 */
}

.highlight-box {
    background-color: var(--accent-light);
    padding: 1.5rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.highlight-title {
    font-weight: 800;
    color: var(--accent-dark);
    margin-bottom: 0.75rem;
}

.code-block {
    background-color: var(--code-bg);
    padding: 1rem;
    border-radius: 0.5rem;
    font-family: monospace;
    font-size: 0.875rem;
    overflow-x: auto;
    border: 1px solid var(--border-color);
    margin-bottom: 1rem;
}

/* Interactive Components */
.interactive-widget {
    background: var(--gradient-primary);
    color: white;
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: var(--shadow-lg);
    margin: 2rem 0;
    border-bottom: 6px solid var(--accent-dark);
}

.interactive-widget h4 {
    color: #e0e7ff;
    font-size: 1.25rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
}

.interactive-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.interactive-input {
    flex: 1;
    min-width: 150px;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    border: none;
    background-color: rgba(0,0,0,0.2);
    color: white;
    font-weight: 700;
    font-size: 1rem;
    outline: none;
}
.interactive-input::placeholder { color: rgba(255,255,255,0.5); }

.interactive-btn {
    background-color: rgba(255,255,255,0.2);
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
    padding: 0.75rem 1.5rem;
    border-radius: 0.75rem;
    font-weight: 800;
    cursor: pointer;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    transition: all 0.2s ease;
    backdrop-filter: blur(4px);
}

.interactive-btn:hover {
    background-color: rgba(255,255,255,0.3);
    transform: translateY(-2px);
}
.interactive-btn:active {
    transform: translateY(0);
}

.interactive-output {
    background-color: rgba(0,0,0,0.4);
    padding: 1.25rem;
    border-radius: 0.75rem;
    font-family: monospace;
    font-size: 1.125rem;
    color: #c7d2fe;
    text-align: center;
    border: 1px solid rgba(255,255,255,0.1);
    min-height: 3.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Visualization Array */
.array-container {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin: 1rem 0;
    flex-wrap: wrap;
}

.array-item {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-secondary);
    border: 2px solid var(--accent-primary);
    border-radius: 8px;
    font-weight: 800;
    color: var(--text-primary);
    transition: all 0.3s ease;
}

.array-item.active {
    background-color: #f59e0b;
    border-color: #d97706;
    color: white;
    transform: scale(1.1);
}
.array-item.sorted {
    background-color: #10b981;
    border-color: #059669;
    color: white;
}

/* Footer */
.footer {
    margin-top: 4rem;
    padding: 1.5rem;
    text-align: center;
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border-color);
    border-radius: 1rem;
    margin-bottom: 1rem;
}

.footer p {
    font-size: 0.625rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.2em;
    font-weight: 700;
    margin: 0;
}

.footer span {
    color: #f59e0b; /* amber-500 */
}

/* Mobile Responsive */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background-color: rgba(0,0,0,0.5);
    z-index: 40;
    backdrop-filter: blur(2px);
}

.overlay.active {
    display: block;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem auto;
}

.loading-state {
    text-align: center;
    padding: 4rem;
    color: var(--text-muted);
}

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

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    
    .mobile-header {
        display: flex;
    }
    
    .sidebar {
        position: fixed;
        left: -100%;
        width: 85%;
        max-width: 320px;
        box-shadow: var(--shadow-lg);
    }
    
    .sidebar.open {
        left: 0;
    }
    
    .sidebar-header {
        display: none;
    }
    
    .main-content {
        padding: 1rem;
    }
    
    .section-title {
        font-size: 2rem;
    }
}
