* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --dark: #1e293b;
    --light: #f8fafc;
    --gray: #64748b;
    --gray-light: #e2e8f0;
    --border: #cbd5e1;
    --shadow: rgba(0, 0, 0, 0.1);
    --node-default: #6366f1;
    --node-visiting: #f59e0b;
    --node-visited: #10b981;
    --node-path: #ec4899;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 2rem 1rem;
    color: var(--dark);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px var(--shadow);
    overflow: hidden;
}

/* Header */
header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    padding: 3rem 2rem;
    text-align: center;
}

.header-content h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.subtitle {
    font-size: 1.2rem;
    opacity: 0.95;
    margin-bottom: 1rem;
}

.header-meta {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
}

.badge {
    background: rgba(255, 255, 255, 0.2);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    backdrop-filter: blur(10px);
}

/* Sections */
section {
    padding: 2rem;
    border-bottom: 1px solid var(--gray-light);
}

section:last-of-type {
    border-bottom: none;
}

h2 {
    color: var(--primary);
    margin-bottom: 1.5rem;
    font-size: 1.8rem;
}

/* Pattern Info */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.info-card {
    background: var(--light);
    padding: 1.5rem;
    border-radius: 12px;
    border-left: 4px solid var(--primary);
}

.info-card h3 {
    color: var(--primary);
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.info-card ul {
    list-style: none;
}

.info-card li {
    padding: 0.4rem 0;
    color: var(--dark);
}

.info-card li::before {
    content: "→ ";
    color: var(--primary);
    font-weight: bold;
}

/* Problem Tabs */
.problem-tabs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.tab-btn {
    background: white;
    border: 2px solid var(--border);
    padding: 1rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tab-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.problem-name {
    font-weight: 600;
    font-size: 1.05rem;
}

/* Visualizer */
.visualizer {
    background: var(--light);
}

.visualizer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.controls {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
    background: white;
    color: var(--primary);
    border: 2px solid var(--primary);
}

.btn-secondary:hover {
    background: var(--primary);
    color: white;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.hidden {
    display: none !important;
}

/* Traversal Controls */
.traversal-controls, .path-sum-controls, .builder-controls {
    background: white;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.traversal-select {
    flex: 1;
    min-width: 250px;
    padding: 0.75rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
}

.traversal-select:focus {
    outline: none;
    border-color: var(--primary);
}

.path-sum-controls input {
    width: 120px;
    padding: 0.75rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
}

.path-sum-controls input:focus {
    outline: none;
    border-color: var(--primary);
}

.builder-controls {
    flex-direction: column;
    align-items: flex-start;
}

.builder-instructions {
    background: #e0e7ff;
    padding: 1rem;
    border-radius: 8px;
    border-left: 4px solid var(--primary);
    width: 100%;
}

.builder-instructions p {
    margin: 0.25rem 0;
    color: var(--dark);
}

/* Speed Control */
.speed-control {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: white;
    border-radius: 8px;
}

.speed-control label {
    font-weight: 600;
    color: var(--primary);
}

#speedSlider {
    flex: 1;
    max-width: 200px;
}

#speedLabel {
    font-weight: 600;
    min-width: 80px;
    color: var(--dark);
}

/* Canvas */
.canvas-container {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 1.5rem;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 500px;
    overflow-x: auto;
}

#visualizerCanvas {
    display: block;
    cursor: pointer;
}

/* Traversal Result */
.traversal-result {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
}

.traversal-result h3 {
    color: var(--primary);
    margin-bottom: 1rem;
}

.result-array {
    background: var(--light);
    padding: 1rem;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 1.1rem;
    color: var(--dark);
    border: 2px solid var(--border);
    min-height: 60px;
    display: flex;
    align-items: center;
}

/* Step Description */
.step-description {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    border-left: 4px solid var(--primary);
}

.step-description h3 {
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.step-description p {
    color: var(--dark);
    line-height: 1.6;
    font-size: 1.05rem;
}

/* LeetCode Problems */
.problems-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.problem-card {
    background: var(--light);
    padding: 1.5rem;
    border-radius: 12px;
    border-top: 4px solid var(--primary);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.problem-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px var(--shadow);
}

.problem-card h3 {
    color: var(--dark);
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.difficulty {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.difficulty.easy {
    background: #d1fae5;
    color: #065f46;
}

.difficulty.medium {
    background: #fed7aa;
    color: #92400e;
}

.difficulty.hard {
    background: #fecaca;
    color: #991b1b;
}

.problem-card p {
    color: var(--gray);
    margin-bottom: 1rem;
    line-height: 1.6;
}

.problem-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.3s ease;
}

.problem-link:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}

/* Algorithm Explanation */
.explanation-content {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.explanation-section h3 {
    color: var(--primary);
    margin-bottom: 1rem;
}

.explanation-section p {
    color: var(--dark);
    line-height: 1.8;
    margin-bottom: 1rem;
}

.explanation-section ul {
    list-style: none;
    padding-left: 0;
}

.explanation-section li {
    padding: 0.5rem 0;
    color: var(--dark);
    line-height: 1.6;
}

.explanation-section li::before {
    content: "✓ ";
    color: var(--success);
    font-weight: bold;
    margin-right: 0.5rem;
}

.code-example {
    background: var(--dark);
    color: #e2e8f0;
    padding: 1.5rem;
    border-radius: 12px;
    overflow-x: auto;
    margin-top: 1rem;
}

.code-example pre {
    margin: 0;
}

.code-example code {
    font-family: 'Courier New', monospace;
    font-size: 0.95rem;
    line-height: 1.6;
}

/* Footer */
footer {
    background: var(--dark);
    color: white;
    padding: 2rem;
    text-align: center;
}

.footer-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.footer-links a {
    color: white;
    text-decoration: none;
    transition: color 0.3s ease;
}

.footer-links a:hover {
    color: var(--primary);
}

footer p {
    opacity: 0.8;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 1rem 0.5rem;
    }

    .container {
        border-radius: 12px;
    }

    header {
        padding: 2rem 1rem;
    }

    .header-content h1 {
        font-size: 1.8rem;
    }

    section {
        padding: 1.5rem 1rem;
    }

    .visualizer-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .controls {
        width: 100%;
    }

    .btn {
        flex: 1;
        min-width: 100px;
    }

    .info-grid,
    .problem-tabs,
    .problems-grid {
        grid-template-columns: 1fr;
    }

    .footer-links {
        flex-direction: column;
        gap: 1rem;
    }
}

/* Animations */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.problem-card,
.info-card {
    animation: fadeIn 0.5s ease;
}

