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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0b0f1a;
    min-height: 100vh;
    color: #e2e8f0;
    overflow-x: hidden;
}

.bg-animated {
    position: fixed;
    inset: 0;
    background: radial-gradient(1200px 600px at 10% 10%, rgba(102,126,234,0.25), transparent 60%),
                radial-gradient(900px 500px at 90% 20%, rgba(118,75,162,0.25), transparent 60%),
                radial-gradient(700px 800px at 50% 110%, rgba(16,185,129,0.18), transparent 60%);
    filter: blur(40px) saturate(120%);
    z-index: 0;
    animation: floatBg 18s ease-in-out infinite alternate;
}

@keyframes floatBg {
    0% { transform: translateY(0) scale(1); }
    100% { transform: translateY(-30px) scale(1.05); }
}

/* Light theme overrides */
body.light {
    background: #f5f7fb;
    color: #0f172a;
}

body.light .bg-animated {
    background: radial-gradient(1200px 600px at 10% 10%, rgba(250,204,21,0.18), transparent 60%),
                radial-gradient(900px 500px at 90% 20%, rgba(248,113,113,0.18), transparent 60%),
                radial-gradient(700px 800px at 50% 110%, rgba(59,130,246,0.15), transparent 60%);
    filter: blur(36px) saturate(120%);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    position: relative;
    z-index: 1;
}

.header {
    text-align: center;
    margin-bottom: 30px;
    color: #e2e8f0;
}
body.light .header { color: #0f172a; }

.title {
    font-size: 3.2rem;
    font-weight: 700;
    margin-bottom: 10px;
    text-shadow: 0 10px 30px rgba(80, 200, 255, 0.25), 0 2px 8px rgba(0,0,0,0.5);
}

.subtitle {
    font-size: 1rem;
    font-weight: 400;
    opacity: 0.8;
}

.brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}
.logo-mark { filter: drop-shadow(0 8px 20px rgba(99,102,241,0.45)); }

.logo-glow {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #67e8f9, #4f46e5 70%);
    box-shadow: 0 0 20px #60a5fa, 0 0 40px #a78bfa, 0 0 60px #34d399;
}

.header-actions {
    margin: 14px 0 6px;
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.top-progress {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, rgba(99,102,241,0.15), rgba(16,185,129,0.15));
    z-index: 1000;
}
.top-progress #progress-bar {
    display: block;
    height: 100%; width: 0%;
    background: linear-gradient(90deg, #6366f1, #22c55e);
    box-shadow: 0 4px 16px rgba(99,102,241,0.5);
    transition: width .2s ease;
}

.controls {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(148, 163, 184, 0.15);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 18px 20px;
    margin-bottom: 25px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.05), 0 10px 30px rgba(0,0,0,0.35);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}
body.light .controls {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(148,163,184,0.25);
    box-shadow: 0 10px 25px rgba(2,6,23,0.08);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.control-group label {
    font-weight: 600;
    color: #cbd5e1;
    font-size: 0.9rem;
}
body.light .control-group label { color: #475569; }

.slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(90deg, rgba(59,130,246,0.35), rgba(167,139,250,0.35));
    outline: none;
    -webkit-appearance: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #93c5fd, #4f46e5 70%);
    cursor: pointer;
    box-shadow: 0 0 0 4px rgba(79,70,229,0.2), 0 10px 30px rgba(79,70,229,0.4);
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #93c5fd, #4f46e5 70%);
    cursor: pointer;
    border: none;
    box-shadow: 0 0 0 4px rgba(79,70,229,0.2), 0 10px 30px rgba(79,70,229,0.4);
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.btn-primary {
    background: linear-gradient(135deg, #4f46e5 0%, #8b5cf6 100%);
    color: white;
}
body.light .btn-primary { box-shadow: 0 8px 22px rgba(79,70,229,0.25); }

.btn-primary:hover {
    transform: translateY(-2px) scale(1.01);
    box-shadow: 0 12px 35px rgba(79, 70, 229, 0.45);
}

.btn-secondary {
    background: rgba(148, 163, 184, 0.12);
    color: #cbd5e1;
    border: 1px solid rgba(148, 163, 184, 0.2);
}
body.light .btn-secondary { background: rgba(148,163,184,0.15); color: #334155; border-color: rgba(148,163,184,0.35); }

.btn-secondary:hover {
    background: rgba(148, 163, 184, 0.2);
    transform: translateY(-2px);
}

.btn-neon {
    position: relative;
    overflow: hidden;
}

.btn-neon::after {
    content: '';
    position: absolute;
    inset: -2px;
    background: conic-gradient(from 90deg, #60a5fa, #a78bfa, #34d399, #60a5fa);
    filter: blur(12px);
    opacity: 0.4;
    transition: opacity .3s ease;
    z-index: -1;
}

.btn-neon:hover::after { opacity: 0.7; }

.algorithm-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 25px;
}

.algo-btn {
    padding: 15px 20px;
    border: none;
    border-radius: 12px;
    background: rgba(2, 6, 23, 0.5);
    border: 1px solid rgba(148, 163, 184, 0.2);
    color: #cbd5e1;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.05), 0 8px 30px rgba(0,0,0,0.35);
}
.
.algo-btn:hover { transform: translateY(-3px) rotate(-0.2deg); }
.algo-btn:active { transform: translateY(-1px) scale(0.98); }
body.light .algo-btn { background: rgba(255,255,255,0.9); color: #1f2937; border-color: rgba(148,163,184,0.35); box-shadow: 0 8px 24px rgba(2,6,23,0.08); }
body.light .algo-btn:hover { background: #ffffff; }
body.light .algo-btn.active { box-shadow: 0 12px 30px rgba(99,102,241,0.25); color: #fff; }

.algo-btn:hover {
    background: rgba(2, 6, 23, 0.7);
    transform: translateY(-3px);
    box-shadow: 0 12px 35px rgba(0,0,0,0.45);
}

.algo-btn.active {
    background: linear-gradient(135deg, rgba(79,70,229,0.8) 0%, rgba(139,92,246,0.8) 100%);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 12px 35px rgba(99,102,241,0.45);
}

.algo-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.visualization-container {
    background: rgba(2, 6, 23, 0.55);
    backdrop-filter: blur(14px);
    border-radius: 18px;
    padding: 30px;
    margin-bottom: 25px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), 0 15px 45px rgba(0,0,0,0.5);
    border: 1px solid rgba(148, 163, 184, 0.15);
}
body.light .visualization-container {
    background: rgba(255,255,255,0.9);
    border: 1px solid rgba(148,163,184,0.25);
    box-shadow: 0 15px 35px rgba(2,6,23,0.08);
}

.array-container {
    height: 400px;
    display: flex;
    align-items: end;
    justify-content: center;
    gap: 3px;
    margin-bottom: 30px;
    padding: 20px;
    background: linear-gradient(180deg, rgba(15,23,42,0.8), rgba(2,6,23,0.6));
    border-radius: 12px;
    min-height: 300px;
    border: 1px solid rgba(148,163,184,0.12);
}

/* Cursor glow follower */
.cursor-glow {
    position: fixed;
    width: 180px; height: 180px;
    border-radius: 50%;
    pointer-events: none;
    background: radial-gradient(circle, rgba(99,102,241,0.25), transparent 60%);
    mix-blend-mode: screen;
    transform: translate(-50%, -50%);
    z-index: 2;
}
body.light .cursor-glow {
    background: radial-gradient(circle, rgba(59,130,246,0.18), transparent 60%);
    mix-blend-mode: multiply;
}
body.light .array-container {
    background: linear-gradient(180deg, rgba(255,255,255,0.9), rgba(241,245,249,0.9));
    border-color: rgba(148,163,184,0.25);
}

.array-bar {
    background: linear-gradient(180deg, #60a5fa 0%, #7c3aed 100%);
    border-radius: 4px 4px 0 0;
    transition: transform 0.18s ease, height 0.18s ease, background 0.18s ease;
    position: relative;
    min-width: 8px;
    box-shadow: 0 6px 20px rgba(124,58,237,0.35), 0 2px 8px rgba(0,0,0,0.45);
}
body.light .array-bar { box-shadow: 0 6px 20px rgba(124,58,237,0.18), 0 2px 8px rgba(2,6,23,0.1); }
body.light .array-bar.comparing { box-shadow: 0 10px 28px rgba(251,113,133,0.25); }
body.light .array-bar.swapping { box-shadow: 0 14px 35px rgba(239,68,68,0.3); }
body.light .array-bar.sorted { box-shadow: 0 12px 30px rgba(16,185,129,0.28); }

.array-bar.comparing {
    background: linear-gradient(180deg, #fbbf24 0%, #fb7185 100%);
    transform: translateY(-6px) scale(1.04);
    box-shadow: 0 10px 30px rgba(251,113,133,0.4);
}

.array-bar.swapping {
    background: linear-gradient(180deg, #fb7185 0%, #ef4444 100%);
    transform: translateY(-10px) scale(1.08);
    box-shadow: 0 14px 40px rgba(239,68,68,0.45);
}

.array-bar.sorted {
    background: linear-gradient(180deg, #10b981 0%, #22c55e 100%);
    box-shadow: 0 12px 35px rgba(16,185,129,0.45);
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
    text-align: center;
}

.stat {
    padding: 15px;
    background: rgba(2, 6, 23, 0.55);
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.2);
}
body.light .stat { background: rgba(255,255,255,0.9); border-color: rgba(148,163,184,0.3); }

.stat-label {
    display: block;
    font-weight: 600;
    color: #94a3b8;
    margin-bottom: 5px;
    font-size: 0.9rem;
}
body.light .stat-label { color: #64748b; }

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #e2e8f0;
}
body.light .stat-value { color: #0f172a; }

.info-panel {
    background: rgba(2, 6, 23, 0.55);
    backdrop-filter: blur(12px);
    border-radius: 16px;
    padding: 25px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), 0 15px 45px rgba(0,0,0,0.5);
    border: 1px solid rgba(148, 163, 184, 0.15);
}
body.light .info-panel {
    background: rgba(255,255,255,0.92);
    border: 1px solid rgba(148,163,184,0.25);
    box-shadow: 0 15px 35px rgba(2,6,23,0.08);
}

.info-panel h3 {
    margin-bottom: 15px;
    color: #e2e8f0;
    font-size: 1.3rem;
}
body.light .info-panel h3 { color: #0f172a; }

#algorithm-info {
    line-height: 1.6;
    color: #cbd5e1;
}
body.light #algorithm-info { color: #334155; }

#algorithm-info p {
    margin-bottom: 10px;
}

.footer {
    margin: 16px 0 0;
    text-align: center;
    color: #94a3b8;
    font-size: 0.9rem;
}
body.light .footer { color: #64748b; }

.algorithm-details {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin-top: 15px;
}

.algorithm-details h4 {
    color: #93c5fd;
    margin-bottom: 10px;
}

.algorithm-details ul {
    margin-left: 20px;
}

.algorithm-details li {
    margin-bottom: 5px;
}

@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    .title {
        font-size: 2rem;
    }
    
    .controls {
        grid-template-columns: 1fr;
    }
    
    .algorithm-buttons {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .array-container {
        height: 300px;
        min-height: 250px;
    }
    
    .stats {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .algorithm-buttons {
        grid-template-columns: 1fr;
    }
    
    .array-container {
        height: 250px;
        min-height: 200px;
    }
}
