:root {
    /* Color Palette */
    --bg-dark: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.7);
    --sidebar-bg: rgba(15, 23, 42, 0.95);
    --accent-primary: #8b5cf6;
    --accent-secondary: #06b6d4;
    --accent-grad: linear-gradient(135deg, #8b5cf6 0%, #06b6d4 100%);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: rgba(255, 255, 255, 0.1);
    
    /* Visualization States */
    --state-idle: #6366f1;
    --state-active: #f59e0b;
    --state-swap: #ef4444;
    --state-sorted: #10b981;
    
    /* Shadows */
    --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);
    --glass-blur: blur(12px);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
}

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

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2.5rem;
    text-decoration: none;
    color: inherit;
}

.app-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.app-title span {
    background: var(--accent-grad);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-menu {
    flex: 1;
    overflow-y: auto;
    margin-right: -0.5rem;
    padding-right: 0.5rem;
}

.nav-menu::-webkit-scrollbar {
    width: 4px;
}

.nav-section {
    margin-bottom: 2rem;
}

.section-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.1em;
    margin-bottom: 1rem;
    display: block;
}

.nav-list {
    list-style: none;
}

.nav-link {
    display: block;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    margin-bottom: 0.25rem;
}

.nav-link:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.nav-link.active {
    background: var(--accent-grad);
    color: white;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
}

.nav-link.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: radial-gradient(circle at top right, rgba(139, 92, 246, 0.05), transparent 40%),
                radial-gradient(circle at bottom left, rgba(6, 182, 212, 0.05), transparent 40%);
    padding: 2rem 3rem;
    overflow-y: auto;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
}



.algo-selection-group {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 0.25rem;
    border-radius: 0.75rem;
    display: inline-flex;
    gap: 0.25rem;
    margin-bottom: 1.5rem;
}

.algo-btn {
    background: transparent;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.algo-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.algo-btn.active {
    background: var(--accent-grad);
    color: white;
    box-shadow: var(--shadow-md);
}

.title-row {
    margin-bottom: 0.5rem;
}

#algo-title {
    font-family: 'Outfit', sans-serif;
    font-size: 2.25rem;
    font-weight: 700;
}

#algo-desc {
    color: var(--text-secondary);
    max-width: 600px;
    font-size: 1rem;
    line-height: 1.6;
}

.header-actions {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.input-group input {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.6rem 1rem;
    color: white;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    width: 200px;
}

/* Buttons */
.primary-btn {
    background: var(--accent-grad);
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 0.75rem;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s;
}

.primary-btn:hover {
    transform: scale(1.05);
}

.secondary-btn {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1.25rem;
    border-radius: 0.75rem;
    color: white;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.icon-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Visualization Layout */
.visualization-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 2rem;
    flex: 1;
}

.visualizer-container {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1.5rem;
    backdrop-filter: var(--glass-blur);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.canvas-area {
    flex: 1;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 8px;
    padding: 3rem;
    min-height: 400px;
}

/* Visualization Bars */
.bar {
    background: var(--state-idle);
    border-radius: 4px 4px 0 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    display: flex;
    justify-content: center;
}

.bar-value {
    position: absolute;
    top: -25px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.bar.active { background: var(--state-active); box-shadow: 0 0 15px var(--state-active); }
.bar.swap { background: var(--state-swap); box-shadow: 0 0 15px var(--state-swap); }
.bar.sorted { background: var(--state-sorted); box-shadow: 0 0 15px var(--state-sorted); }

/* Controls Area */
.controls-container {
    padding: 1.5rem 3rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
}

.playback-controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.speed-control label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Code Panel */
.explanation-side {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.code-panel {
    background: #020617;
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    overflow: hidden;
}

.panel-header {
    background: rgba(255, 255, 255, 0.05);
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

.lang-select {
    background: #1e293b;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 0.7rem;
    padding: 2px 8px;
    cursor: pointer;
    outline: none;
    font-weight: 600;
}

.lang-select:hover {
    border-color: var(--accent-primary);
}

.code-block {
    padding: 1rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    line-height: 1.7;
    color: #cbd5e1;
    white-space: pre;
    overflow-x: auto;
}

.code-line {
    display: block;
    padding: 0 0.5rem;
    border-radius: 4px;
}

.code-line.highlight {
    background: rgba(139, 92, 246, 0.2);
    color: #e9d5ff;
    border-left: 2px solid var(--accent-primary);
}

/* Complexity */
.complexity-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.complexity-item {
    display: flex;
    justify-content: space-between;
}

.complexity-item .label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.complexity-item .value {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    color: var(--accent-secondary);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Mobile Responsiveness */
@media (max-width: 1024px) {
    .visualization-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        min-height: 100vh;
        height: auto;
    }
    
    .sidebar {
        width: 100%;
        padding: 1rem;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    
    .nav-menu {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .nav-section {
        margin-bottom: 1rem;
        width: 100%;
    }
    
    .nav-list {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .nav-link {
        margin-bottom: 0;
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }
    
    .main-content {
        padding: 1rem;
        overflow-y: visible;
    }
    
    .content-header {
        flex-direction: column;
        gap: 1rem;
    }
    
    .canvas-area {
        padding: 1rem;
        min-height: 250px;
    }
    
    .controls-container {
        flex-direction: column;
        gap: 1.5rem;
        padding: 1rem;
    }
}
