:root {
    --bg-color: #0f172a;
    --text-color: #f8fafc;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --bar-default: #38bdf8;
    --bar-compare: #ef4444;
    --bar-swap: #eab308;
    --bar-sorted: #22c55e;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Inter', sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    padding: 1.5rem;
    text-align: center;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
    z-index: 10;
}

header h1 {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 1.5rem;
    background: linear-gradient(90deg, #38bdf8, #818cf8);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.controls-wrapper {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 900px;
    margin: 0 auto;
}

@media (min-width: 768px) {
    .controls-wrapper {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

.settings {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
}

.setting-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
}

.setting-group label {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #94a3b8;
}

input[type=range] {
    accent-color: var(--primary);
    cursor: pointer;
}

/* Color Legend */
.color-legend {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: #94a3b8;
    font-weight: 600;
}

.color-box {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.box-default { background-color: var(--bar-default); }
.box-compare { background-color: var(--bar-compare); }
.box-swap { background-color: var(--bar-swap); }
.box-sorted { background-color: var(--bar-sorted); }

.grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    width: 100%;
    max-width: 1400px;
}

.visualizer-box {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.visualizer-box h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: #cbd5e1;
    letter-spacing: 0.5px;
    transition: color 0.2s ease;
}

.visualizer-box a {
    text-decoration: none;
}

.visualizer-box a:hover h2, 
.visualizer-box a:focus h2 {
    color: #38bdf8;
    text-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
    cursor: pointer;
}

.array-container {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    width: 100%;
    height: 30vh;
    min-height: 200px;
    gap: 1px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.bar {
    background-color: var(--bar-default);
    width: 100%; /* Dynamic based on flex */
    border-radius: 2px 2px 0 0;
    transition: height 0.05s linear, background-color 0.05s ease;
}

/* Article Page Layouts */
.article-container {
    max-width: 800px;
    margin: 2rem auto;
    padding: 2rem;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    line-height: 1.7;
}

.article-container h2 {
    color: #38bdf8;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    font-weight: 600;
}

.algo-diagram {
    display: block;
    width: 100%;
    max-width: 600px;
    margin: 2rem auto;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.article-container p {
    margin-bottom: 1rem;
    color: #e2e8f0;
}

.article-container ul, .article-container ol {
    margin-bottom: 1.5rem;
    padding-left: 2rem;
    color: #e2e8f0;
}

.article-container li {
    margin-bottom: 0.5rem;
}

.nav-header {
    display: flex;
    justify-content: flex-start;
    padding: 1rem 2rem;
    background: transparent;
    border: none;
    box-shadow: none;
}

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    border: 1px solid var(--glass-border);
    font-weight: 600;
    transition: all 0.2s ease;
}

.back-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
    transform: translateX(-4px);
}

.complexity-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    font-size: 0.95rem;
}

.complexity-table th, .complexity-table td {
    border: 1px solid var(--glass-border);
    padding: 0.75rem;
    text-align: left;
}

.complexity-table th {
    background-color: rgba(255, 255, 255, 0.05);
    color: #94a3b8;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 1px;
}

.complexity-table td {
    color: #f8fafc;
    font-family: monospace;
    font-size: 1.1rem;
}