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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    background: #2b2b2b;
    color: #e0e0e0;
    overflow: hidden;
    height: 100vh;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    width: 200px;
    background: #3a3a3a;
    border-right: 1px solid #4a4a4a;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid #4a4a4a;
}

.sidebar-header h3 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #999;
    font-weight: 600;
}

.algorithm-nav {
    display: flex;
    flex-direction: column;
}

.algo-option {
    background: transparent;
    border: none;
    color: #e0e0e0;
    padding: 14px 20px;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    transition: background 0.15s ease;
    position: relative;
}

.algo-option:hover {
    background: #424242;
}

.algo-option.active {
    background: #484848;
}

.algo-option.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: #5ba3ff;
}

.radio {
    width: 14px;
    height: 14px;
    border: 2px solid #888;
    border-radius: 50%;
    position: relative;
    flex-shrink: 0;
}

.algo-option.active .radio {
    border-color: #5ba3ff;
}

.algo-option.active .radio::after {
    content: '';
    position: absolute;
    width: 6px;
    height: 6px;
    background: #5ba3ff;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* ============================================
   MAIN CONTAINER
   ============================================ */
.main-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Top Bar */
.top-bar {
    background: #363636;
    padding: 16px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #4a4a4a;
}

.top-bar h1 {
    font-size: 18px;
    font-weight: 600;
    color: #fff;
}

.legend-indicators {
    display: flex;
    gap: 24px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.color-box {
    width: 20px;
    height: 20px;
    border-radius: 3px;
}

.visited-color {
    background: #5ba3ff;
}

.path-color {
    background: #d4d4d4;
}

/* Control Bar */
.control-bar {
    background: #363636;
    padding: 12px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #4a4a4a;
    gap: 20px;
}

.controls-left,
.controls-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

/* Buttons */
.btn-primary {
    background: #5ba3ff;
    color: white;
    border: none;
    padding: 9px 22px;
    border-radius: 5px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-primary:hover:not(:disabled) {
    background: #4a92ee;
}

.btn-primary:disabled {
    background: #555;
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-secondary {
    background: #2d2d2d;
    border: 1px solid #4a4a4a;
    color: #e0e0e0;
    padding: 8px 18px;
    border-radius: 5px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-secondary:hover {
    background: #3a3a3a;
    border-color: #5a5a5a;
}

.view-toggle {
    display: flex;
    gap: 4px;
    background: #2d2d2d;
    padding: 3px;
    border-radius: 5px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: #999;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.icon-btn:hover {
    background: #3a3a3a;
    color: #e0e0e0;
}

.icon-btn.active {
    background: #4a4a4a;
    color: #fff;
}

.clear-btn {
    background: #2d2d2d;
    border: 1px solid #4a4a4a;
    font-size: 24px;
    font-weight: 300;
}

.tool-buttons {
    display: flex;
    gap: 8px;
}

.tool-btn {
    background: #2d2d2d;
    border: 1px solid #4a4a4a;
    color: #e0e0e0;
    padding: 7px 14px;
    border-radius: 5px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
}

.tool-btn:hover {
    background: #3a3a3a;
    border-color: #5a5a5a;
}

.tool-btn.active {
    background: #4a4a4a;
    border-color: #5ba3ff;
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 10px;
}

.speed-control label {
    font-size: 13px;
    color: #999;
    font-weight: 500;
}

.speed-slider-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.speed-label {
    font-size: 11px;
    color: #777;
}

#speedSlider {
    width: 100px;
    height: 4px;
    background: #4a4a4a;
    border-radius: 2px;
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;
}

#speedSlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: #5ba3ff;
    border-radius: 50%;
    cursor: pointer;
}

#speedSlider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    background: #5ba3ff;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.stats-box {
    display: flex;
    gap: 18px;
    padding: 6px 14px;
    background: #2d2d2d;
    border-radius: 5px;
}

.stat {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 11px;
    color: #888;
    white-space: nowrap;
}

.stat-label strong {
    color: #fff;
    font-size: 13px;
}

.toggle-buttons {
    display: flex;
    gap: 8px;
}

.toggle-btn {
    background: #2d2d2d;
    border: 1px solid #4a4a4a;
    color: #999;
    padding: 6px 12px;
    border-radius: 5px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
}

.toggle-btn:hover {
    background: #3a3a3a;
}

.toggle-btn.active {
    color: #fff;
}

.toggle-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

.wall-color {
    background: #1a1a1a;
}

.weight-color {
    background: #ff9800;
}

/* ============================================
   GRID AREA
   ============================================ */
.grid-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow: auto;
    background: #2b2b2b;
}

.grid {
    display: inline-block;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.grid-row {
    display: flex;
}

.node {
    width: 28px;
    height: 28px;
    border: 1px solid #3a3a3a;
    background: #e4e4e4;
    cursor: pointer;
    transition: transform 0.1s ease;
    position: relative;
}

.node:hover {
    transform: scale(1.08);
    z-index: 10;
}

/* Node States */
.node-start {
    background: #22c55e;
    border-color: #16a34a;
}

.node-start::after {
    content: 'S';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-weight: bold;
    font-size: 14px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.node-finish {
    background: #ef4444;
    border-color: #dc2626;
}

.node-finish::after {
    content: 'E';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-weight: bold;
    font-size: 14px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.node-wall {
    background: #1a1a1a;
    border-color: #0a0a0a;
    animation: wallPop 0.2s ease-out;
}

.node-weight {
    background: #ff9800;
    border-color: #f57c00;
    animation: weightPop 0.2s ease-out;
}

.node-visited {
    background: #5ba3ff;
    border-color: #4a92ee;
    animation: visitedPulse 0.4s ease-out;
}

.node-path {
    background: #fbbf24;
    border-color: #f59e0b;
    animation: pathGlow 0.3s ease-out;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes wallPop {
    0% {
        transform: scale(0.6);
        background: #2a2a2a;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        background: #1a1a1a;
    }
}

@keyframes weightPop {
    0% {
        transform: scale(0.6);
        background: #ffb74d;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        background: #ff9800;
    }
}

@keyframes visitedPulse {
    0% {
        transform: scale(0.5);
        background: #93c5fd;
        border-radius: 50%;
    }
    50% {
        transform: scale(1.12);
        background: #60a5fa;
    }
    100% {
        transform: scale(1);
        background: #5ba3ff;
        border-radius: 0;
    }
}

@keyframes pathGlow {
    0% {
        transform: scale(0.7);
        background: #fde047;
    }
    50% {
        transform: scale(1.15);
        background: #facc15;
    }
    100% {
        transform: scale(1);
        background: #fbbf24;
    }
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1400px) {
    .stats-box {
        display: none;
    }
}

@media (max-width: 1024px) {
    .control-bar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .controls-left,
    .controls-right {
        justify-content: center;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 60px;
    }
    
    .sidebar-header h3 {
        font-size: 10px;
    }
    
    .algo-option span:not(.radio) {
        display: none;
    }
    
    .node {
        width: 20px;
        height: 20px;
    }
}