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

:root {
    --primary: #667eea;
    --secondary: #764ba2;
    --accent: #4ecdc4;
    --warning: #ff6b6b;
    --success: #6bcf7f;
    --info: #ffd93d;
    --dark: #1a1a2e;
    --darker: #16213e;
    --light: #e94057;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: linear-gradient(135deg, var(--dark) 0%, var(--darker) 50%, #0f3460 100%);
    color: white;
    min-height: 100vh;
    overflow-x: hidden;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

h1 {
    text-align: center;
    margin-bottom: 30px;
    font-size: clamp(2rem, 4vw, 3.5rem);
    background: linear-gradient(45deg, var(--light), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.tabs {
    display: flex;
    justify-content: center;
    margin-bottom: 30px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 8px;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    flex-wrap: wrap;
}

.tab {
    padding: 12px 16px;
    margin: 4px;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    border-radius: 12px;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 600;
    font-size: 0.9rem;
    position: relative;
    overflow: hidden;
    flex: 1;
    min-width: 120px;
    text-align: center;
}

.tab::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, var(--primary), var(--secondary));
    opacity: 0;
    transition: opacity 0.4s ease;
    border-radius: 12px;
    z-index: -1;
}

.tab.active {
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
}

.tab.active::before {
    opacity: 1;
}

.tab:hover:not(.active) {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    transform: translateY(-1px);
}

.tab-content {
    display: none;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    padding: 30px;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

button {
    padding: 12px 20px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: linear-gradient(45deg, var(--primary), var(--secondary));
    color: white;
    font-size: 0.9rem;
    position: relative;
    overflow: hidden;
    min-width: 120px;
}

button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s;
}

button:hover::before {
    left: 100%;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

button.danger {
    background: linear-gradient(45deg, var(--warning), #e55353);
}

button.success {
    background: linear-gradient(45deg, var(--success), #5cb85c);
}

select, input[type="number"] {
    padding: 12px 16px;
    border: none;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
    min-width: 150px;
}

select:focus, input[type="number"]:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--accent);
}

select option {
    background: var(--darker);
    color: white;
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.08);
    padding: 8px 16px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    flex: 1;
    min-width: 200px;
}

input[type="range"] {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.2);
    outline: none;
    -webkit-appearance: none;
    min-width: 80px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}

.canvas-container {
    width: 100%;
    overflow: auto;
    margin: 20px 0;
}

#canvas, #graphCanvas, #treeCanvas {
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    background: rgba(0, 0, 0, 0.3);
    display: block;
    margin: 0 auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    max-width: 100%;
}

.info-panel {
    margin-top: 25px;
    background: rgba(255, 255, 255, 0.08);
    padding: 25px;
    border-radius: 16px;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

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

.stat {
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.05);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-label {
    font-size: 0.85rem;
    opacity: 0.8;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent);
}

.grid-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 25px;
    overflow: auto;
}

.grid {
    display: grid;
    gap: 1px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    padding: 12px;
    margin: 0 auto;
}

.cell {
    width: 20px;
    height: 20px;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 2px;
}

.cell:hover {
    transform: scale(1.1);
}

.cell.wall {
    background: #2a2a2a;
    box-shadow: inset 0 0 8px rgba(0,0,0,0.5);
}

.cell.start {
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent);
}

.cell.end {
    background: var(--warning);
    box-shadow: 0 0 12px var(--warning);
}

.cell.visited {
    background: var(--info);
    box-shadow: 0 0 8px var(--info);
}

.cell.path {
    background: var(--success);
    box-shadow: 0 0 10px var(--success);
    animation: pulse 1s ease-in-out;
}
.cell.weighted {
    background: #ffa500;
    opacity: 0.7;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

.algorithm-info {
    background: rgba(255, 255, 255, 0.08);
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    border-left: 4px solid var(--accent);
}

.algorithm-info h3 {
    color: var(--accent);
    margin-bottom: 8px;
    font-size: 1.1rem;
}

.algorithm-info p {
    opacity: 0.9;
    line-height: 1.5;
    font-size: 0.9rem;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
    margin: 15px 0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(45deg, var(--accent), var(--primary));
    width: 0%;
    transition: width 0.3s ease;
}

.legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 15px 0;
    flex-wrap: wrap;
}

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

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 3px;
}

.sound-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    padding: 10px;
    border-radius: 50%;
    cursor: pointer;
    backdrop-filter: blur(20px);
    transition: all 0.3s ease;
    z-index: 1000;
}

.sound-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.grid-instructions {
    opacity: 0.8;
    text-align: center;
    font-size: 0.9rem;
    margin-top: 10px;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }

    h1 {
        font-size: 2rem;
        margin-bottom: 20px;
    }

    .tabs {
        flex-direction: column;
        gap: 4px;
    }

    .tab {
        margin: 0;
        width: 100%;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    button, select, input[type="number"], .slider-container {
        width: 100%;
    }

    .stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }

    .sound-toggle {
        position: static;
        align-self: flex-end;
        margin-bottom: 10px;
        margin-left: auto;
        display: block;
    }

    .grid {
        transform: scale(0.9);
        transform-origin: top center;
    }

    .cell {
        width: 16px;
        height: 16px;
    }

    .algorithm-info {
        padding: 15px;
    }

    .tab-content {
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 10px;
    }

    h1 {
        font-size: 1.8rem;
    }

    .stat-value {
        font-size: 1.4rem;
    }

    .grid {
        transform: scale(0.8);
    }

    .cell {
        width: 14px;
        height: 14px;
    }

    .legend {
        gap: 10px;
    }

    .legend-item {
        font-size: 0.75rem;
    }
}