* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #00ffff;
    --secondary-color: #ff6b6b;
    --accent-color: #ffa500;
    --background-dark: #0a0a0a;
    --background-secondary: #1a1a2e;
    --background-tertiary: #16213e;
    --panel-bg: rgba(0, 20, 40, 0.95);
    --text-primary: #ffffff;
    --text-secondary: #aaaaaa;
    --success-color: #00ff88;
    --danger-color: #ff3366;
    --warning-color: #ffff00;
    --border-color: rgba(0, 255, 255, 0.2);
    --shadow-glow: 0 0 20px rgba(0, 255, 255, 0.3);
}

body {
    background: linear-gradient(135deg, var(--background-dark) 0%, var(--background-secondary) 50%, var(--background-tertiary) 100%);
    font-family: 'Courier New', monospace;
    color: var(--text-primary);
    min-height: 100vh;
    display: grid;
    grid-template-areas: 
        "header header"
        "controls visualization"
        "stats visualization"
        "info visualization";
    grid-template-columns: 300px 1fr;
    grid-template-rows: auto auto auto 1fr;
    gap: 10px;
    padding: 10px;
    overflow-x: hidden;
}

/* Header */
.header {
    grid-area: header;
    text-align: center;
    padding: 20px;
    background: var(--panel-bg);
    border-radius: 15px;
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-glow);
}

.header h1 {
    font-size: 2.5em;
    color: var(--primary-color);
    text-shadow: 0 0 20px rgba(0, 255, 255, 0.5);
    margin-bottom: 10px;
}

.header p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 1001;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    cursor: pointer;
    flex-direction: column;
    gap: 3px;
}

.mobile-menu-toggle span {
    width: 20px;
    height: 2px;
    background: var(--primary-color);
    border-radius: 1px;
    transition: all 0.3s ease;
}

.mobile-menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -6px);
}

/* Controls Panel */
.controls-panel {
    grid-area: controls;
    background: var(--panel-bg);
    padding: 20px;
    border-radius: 15px;
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-glow);
    display: flex;
    flex-direction: column;
    gap: 20px;
    height: fit-content;
}

.controls-section {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-group label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: bold;
}

.select-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
}

select, input[type="range"] {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-family: inherit;
    transition: all 0.3s ease;
}

select {
    flex: 1;
    cursor: pointer;
}

select:hover, select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.3);
}

input[type="range"] {
    accent-color: var(--primary-color);
    height: 6px;
    flex: 1;
}

.value-display {
    color: var(--primary-color);
    font-weight: bold;
    min-width: 30px;
    text-align: center;
    font-size: 12px;
}

.info-btn {
    background: var(--primary-color);
    color: var(--background-dark);
    border: none;
    border-radius: 50%;
    width: 25px;
    height: 25px;
    cursor: pointer;
    font-weight: bold;
    font-size: 12px;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.info-btn:hover {
    background: var(--text-primary);
    transform: scale(1.1);
}

.action-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.btn {
    background: linear-gradient(45deg, var(--secondary-color), var(--accent-color));
    border: none;
    color: var(--text-primary);
    padding: 10px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.3s ease;
    flex: 1;
    min-width: 80px;
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(255, 107, 107, 0.4);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn.primary {
    background: linear-gradient(45deg, var(--primary-color), #0066cc);
}

.btn.primary:hover:not(:disabled) {
    box-shadow: 0 8px 20px rgba(0, 255, 255, 0.4);
}

.btn.danger {
    background: linear-gradient(45deg, var(--danger-color), #ff0044);
}

.btn.danger:hover:not(:disabled) {
    box-shadow: 0 8px 20px rgba(255, 51, 102, 0.4);
}

/* Stats Panel */
.stats-panel {
    grid-area: stats;
    background: var(--panel-bg);
    padding: 15px;
    border-radius: 15px;
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-glow);
    height: fit-content;
}

.stats-panel h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 12px;
}

.stat-item span:first-child {
    color: var(--text-secondary);
}

.stat-item span:last-child {
    color: var(--primary-color);
    font-weight: bold;
}

/* Algorithm Info Panel */
.algorithm-info-panel {
    grid-area: info;
    background: var(--panel-bg);
    padding: 15px;
    border-radius: 15px;
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-glow);
    height: fit-content;
}

.complexity-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.complexity-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.complexity-label {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.complexity-value {
    color: var(--primary-color);
    font-weight: bold;
    font-size: 12px;
}

/* Visualization Area */
.visualization-area {
    grid-area: visualization;
    background: var(--panel-bg);
    border-radius: 15px;
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-glow);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 20px;
    min-height: 400px;
    overflow: hidden;
}

.bars-container {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 1px;
    height: 100%;
    width: 100%;
}

.bar {
    background: linear-gradient(to top, var(--primary-color), var(--secondary-color));
    border-radius: 2px 2px 0 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    min-width: 2px;
    box-shadow: 0 0 5px rgba(0, 255, 255, 0.3);
}

.bar.comparing {
    background: linear-gradient(to top, var(--secondary-color), var(--accent-color));
    box-shadow: 0 0 15px rgba(255, 107, 107, 0.8);
    transform: scaleX(1.2);
}

.bar.swapping {
    background: linear-gradient(to top, var(--danger-color), #ff0066);
    box-shadow: 0 0 20px rgba(255, 51, 102, 1);
    transform: scale(1.1);
    animation: pulse 0.3s ease-in-out;
}

.bar.sorted {
    background: linear-gradient(to top, var(--success-color), var(--primary-color));
    box-shadow: 0 0 10px rgba(0, 255, 136, 0.6);
}

.bar.pivot {
    background: linear-gradient(to top, var(--warning-color), var(--accent-color));
    box-shadow: 0 0 20px rgba(255, 255, 0, 0.8);
    transform: scaleY(1.1);
}

@keyframes pulse {
    0%, 100% { transform: scale(1.1); }
    50% { transform: scale(1.3); }
}

/* Progress Bar */
.progress-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    transition: width 0.3s ease;
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
    z-index: 1000;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--panel-bg);
    border-radius: 20px;
    border: 1px solid var(--border-color);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    animation: modalIn 0.3s ease-out;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    color: var(--primary-color);
    font-size: 1.5em;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.modal-content {
    padding: 25px;
}

.modal-description {
    margin-bottom: 25px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.modal-description h3 {
    color: var(--primary-color);
    margin-bottom: 10px;
    font-size: 1.1em;
}

.modal-description p {
    margin-bottom: 15px;
}

.modal-description ul {
    margin-left: 20px;
    margin-bottom: 15px;
}

.modal-description li {
    margin-bottom: 5px;
}

.modal-complexity h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.1em;
}

.complexity-table {
    display: grid;
    gap: 10px;
}

.complexity-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.complexity-row span:first-child {
    color: var(--text-secondary);
}

.complexity-row span:last-child {
    color: var(--primary-color);
    font-weight: bold;
}

/* Responsive Design */
@media (max-width: 1024px) {
    body {
        grid-template-areas: 
            "header"
            "controls"
            "visualization"
            "stats"
            "info";
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr auto auto;
        padding: 5px;
    }

    .header h1 {
        font-size: 2em;
    }

    .controls-panel {
        position: sticky;
        top: 5px;
        z-index: 100;
    }

    .complexity-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: flex;
    }

    .header {
        padding: 15px;
    }

    .header h1 {
        font-size: 1.8em;
    }

    .header p {
        font-size: 12px;
    }

    .controls-panel {
        position: fixed;
        top: 0;
        left: -100%;
        width: 280px;
        height: 100vh;
        z-index: 1000;
        transition: left 0.3s ease;
        overflow-y: auto;
        border-radius: 0;
    }

    .controls-panel.active {
        left: 0;
    }

    body {
        grid-template-areas: 
            "header"
            "visualization"
            "stats"
            "info";
        padding-top: 60px;
    }

    .visualization-area {
        min-height: 300px;
    }

    .stats-panel, .algorithm-info-panel {
        margin: 0 5px;
    }

    .action-buttons {
        flex-direction: column;
    }

    .btn {
        min-width: auto;
    }

    .modal {
        margin: 10px;
        max-height: 90vh;
    }

    .modal-header {
        padding: 15px 20px;
    }

    .modal-content {
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.5em;
    }

    .visualization-area {
        min-height: 250px;
        padding: 10px;
    }

    .controls-panel {
        width: 100%;
        left: -100%;
    }

    .complexity-item {
        padding: 6px;
    }

    .modal {
        margin: 5px;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .bar {
        transition: none;
    }
    
    .btn {
        transition: none;
    }
    
    @keyframes pulse {
        0%, 100% { transform: none; }
        50% { transform: none; }
    }
}