* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Arial, Helvetica, sans-serif;
    background: #0f172a;
    color: white;
    min-height: 100vh;
}

/* =========================
   HEADER
   ========================= */

header {
    text-align: center;
    padding: 25px;
    background: #1e293b;
}

header h1 {
    font-size: 32px;
    margin-bottom: 8px;
}

header p {
    color: #94a3b8;
}

/* =========================
   CONTROLS
   ========================= */

.controls {
    width: 95%;
    max-width: 1200px;
    margin: 20px auto;
    padding: 20px;
    background: #1e293b;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.control {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control label {
    font-size: 14px;
    color: #cbd5e1;
}

select {
    padding: 10px 15px;
    background: #334155;
    color: white;
    border: none;
    border-radius: 6px;
    outline: none;
    cursor: pointer;
}

input[type="range"] {
    width: 160px;
    cursor: pointer;
}

button {
    padding: 11px 18px;
    border: none;
    border-radius: 6px;
    background: #2563eb;
    color: white;
    font-size: 14px;
    cursor: pointer;
    transition: 0.2s;
}

button:hover {
    background: #1d4ed8;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* =========================
   STATISTICS
   ========================= */

.statistics {
    width: 95%;
    max-width: 900px;
    margin: 20px auto;
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

.stat {
    min-width: 160px;
    padding: 15px 25px;
    background: #1e293b;
    border-radius: 10px;
    text-align: center;
}

.stat span {
    display: block;
    color: #94a3b8;
    font-size: 13px;
    margin-bottom: 7px;
}

.stat strong {
    color: #38bdf8;
    font-size: 20px;
}

/* =========================
   VISUALIZER
   ========================= */

main {
    width: 95%;
    max-width: 1400px;
    height: 500px;
    margin: 20px auto;
    padding: 15px;
    background: #020617;
    border-radius: 12px;
    overflow: hidden;
}

#arrayContainer {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 3px;
}

/* =========================
   ARRAY BARS
   ========================= */

.bar {
    flex: 1;
    max-width: 25px;
    min-width: 2px;
    background: #38bdf8;
    border-radius: 3px 3px 0 0;
    transition: height 0.08s ease, background-color 0.08s ease;
}

.bar.comparing {
    background: #facc15;
}

.bar.swapping {
    background: #ef4444;
}

.bar.sorted {
    background: #22c55e;
}

/* =========================
   LEGEND
   ========================= */

.legend {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 25px;
    flex-wrap: wrap;
    margin: 20px;
}

.legend div {
    display: flex;
    align-items: center;
    gap: 7px;
    color: #cbd5e1;
    font-size: 14px;
}

.legendBar {
    width: 16px;
    height: 16px;
    border-radius: 3px;
}

.legendBar.normal {
    background: #38bdf8;
}

.legendBar.comparing {
    background: #facc15;
}

.legendBar.swapping {
    background: #ef4444;
}

.legendBar.sorted {
    background: #22c55e;
}

/* =========================
   FOOTER
   ========================= */

footer {
    text-align: center;
    padding: 20px;
    color: #64748b;
}

/* =========================
   MOBILE
   ========================= */

@media (max-width: 700px) {
    header h1 {
        font-size: 25px;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
    }

    .control {
        width: 100%;
    }

    input[type="range"] {
        width: 100%;
    }

    button {
        width: 100%;
    }

    main {
        height: 400px;
    }
}