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

:root {
    --primary-color: #6366f1;
    --secondary-color: #8b5cf6;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --dark-bg: #1e293b;
    --darker-bg: #0f172a;
    --light-bg: #f8fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --highlight-color: #fbbf24;
    --sorted-color: #10b981;
    --comparing-color: #ef4444;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--text-primary);
    min-height: 100vh;
}

header {
    background: var(--darker-bg);
    color: white;
    padding: 2rem;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

header p {
    color: #94a3b8;
    font-size: 1.1rem;
}

.category-nav {
    background: var(--dark-bg);
    padding: 1rem;
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.category-btn {
    padding: 0.75rem 1.5rem;
    border: 2px solid transparent;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s ease;
}

.category-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.category-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    box-shadow: 0 4px 8px rgba(99, 102, 241, 0.3);
}

.container {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 2rem;
    max-width: 1600px;
    margin: 2rem auto;
    padding: 0 2rem;
}

.sidebar {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    height: fit-content;
    position: sticky;
    top: 2rem;
}

.sidebar h3 {
    margin-bottom: 1rem;
    color: var(--primary-color);
    font-size: 1.3rem;
}

.algorithm-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.algorithm-item {
    padding: 0.75rem 1rem;
    background: var(--light-bg);
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.algorithm-item:hover {
    background: var(--primary-color);
    color: white;
    transform: translateX(5px);
}

.algorithm-item.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--secondary-color);
}

.content {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.algorithm-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.algorithm-header h2 {
    color: var(--primary-color);
    font-size: 2rem;
}

.complexity-badges {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.badge {
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge.time {
    background: #dbeafe;
    color: #1e40af;
}

.badge.space {
    background: #dcfce7;
    color: #166534;
}

.description {
    background: var(--light-bg);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 2rem;
    line-height: 1.6;
    font-size: 1.05rem;
}

.visualization-container {
    margin-bottom: 2rem;
}

.controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
    background: var(--light-bg);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--border-color);
    transform: translateY(-2px);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.slider {
    width: 150px;
    height: 6px;
    border-radius: 5px;
    background: var(--border-color);
    outline: none;
    -webkit-appearance: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
}

.slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
}

.visualization {
    background: var(--light-bg);
    border-radius: 8px;
    padding: 2rem;
    min-height: 400px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

#canvas {
    max-width: 100%;
    height: auto;
}

.step-info {
    background: #fffbeb;
    border-left: 4px solid var(--warning-color);
    padding: 1rem;
    margin-top: 1rem;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.95rem;
    min-height: 50px;
}

.code-section {
    background: var(--darker-bg);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 2rem;
}

.code-tabs {
    display: flex;
    background: var(--dark-bg);
    border-bottom: 2px solid var(--primary-color);
}

.code-tab {
    padding: 1rem 2rem;
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
}

.code-tab:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.code-tab.active {
    color: white;
    border-bottom-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

pre {
    margin: 0;
    padding: 2rem;
    overflow-x: auto;
    background: transparent !important;
}

code {
    font-family: 'Courier New', Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
    font-size: 0.95rem;
    line-height: 1.6;
}

/* Override Prism theme to match our dark background */
pre[class*="language-"] {
    background: transparent;
    margin: 0;
}

code[class*="language-"] {
    background: transparent;
}

/* Ensure good contrast for syntax highlighting */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
    color: #999;
}

.token.punctuation {
    color: #ccc;
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
    color: #f08d49;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
    color: #7ec699;
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
    color: #67cdcc;
}

.token.atrule,
.token.attr-value,
.token.keyword {
    color: #cc99cd;
}

.token.function,
.token.class-name {
    color: #6196cc;
}

.token.regex,
.token.important,
.token.variable {
    color: #e2777a;
}

/* Plain text for explanation tab */
code.language-none {
    color: #e2e8f0;
}

.notes-section,
.use-cases-section,
.real-life-section {
    background: var(--light-bg);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.notes-section h3,
.use-cases-section h3,
.real-life-section h3 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    font-size: 1.3rem;
}

.notes-section ul,
.use-cases-section ul,
.real-life-section ul {
    list-style: none;
    padding-left: 0;
}

.notes-section li,
.use-cases-section li,
.real-life-section li {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
    line-height: 1.6;
}

.notes-section li:last-child,
.use-cases-section li:last-child,
.real-life-section li:last-child {
    border-bottom: none;
}

.notes-section li::before {
    content: "✓ ";
    color: var(--success-color);
    font-weight: bold;
    margin-right: 0.5rem;
}

.use-cases-section li::before {
    content: "→ ";
    color: var(--primary-color);
    font-weight: bold;
    margin-right: 0.5rem;
}

.real-life-section li::before {
    content: "🔹 ";
    margin-right: 0.5rem;
}

footer {
    background: var(--darker-bg);
    color: #94a3b8;
    text-align: center;
    padding: 2rem;
    margin-top: 2rem;
}

footer a {
    color: #a78bfa;
    text-decoration: none;
    transition: color 0.3s ease;
}

footer a:hover {
    color: #c4b5fd;
    text-decoration: underline;
}

footer p {
    margin: 0.5rem 0;
}

/* Visualization animations */
.bar {
    transition: all 0.3s ease;
}

.bar.comparing {
    fill: var(--comparing-color);
}

.bar.sorted {
    fill: var(--sorted-color);
}

.bar.pivot {
    fill: var(--warning-color);
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.highlight {
    animation: pulse 1s infinite;
}

/* Responsive design */
@media (max-width: 1024px) {
    .container {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
    }

    .algorithm-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
}

@media (max-width: 768px) {
    header h1 {
        font-size: 1.8rem;
    }

    .container {
        padding: 0 1rem;
    }

    .controls {
        justify-content: center;
    }

    .code-tabs {
        flex-wrap: wrap;
    }

    .code-tab {
        flex: 1;
        min-width: 100px;
    }
}
