/* Shared algorithm visualization styles */
:root {
    --bg: #0a0a0b;
    --bg-secondary: #111113;
    --bg-card: #16161a;
    --border: #222228;
    --text: #ededef;
    --text-secondary: #8a8a8e;
    --accent: #6c63ff;
    --accent-glow: rgba(108, 99, 255, 0.15);
    --accent-hover: #7b73ff;
    --gradient-start: #6c63ff;
    --gradient-end: #a78bfa;
    --green: #34d399;
    --red: #f87171;
    --yellow: #fbbf24;
    --orange: #fb923c;
    --cyan: #22d3ee;
    --pink: #f472b6;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, sans-serif;
    background: var(--bg); color: var(--text); line-height: 1.6;
    -webkit-font-smoothing: antialiased; min-height: 100vh;
}
::selection { background: rgba(108, 99, 255, 0.3); color: var(--text); }

/* Nav */
nav {
    position: fixed; top: 0; left: 0; right: 0; z-index: 100;
    padding: 16px 0;
    background: rgba(10, 10, 11, 0.8); backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}
nav .container {
    max-width: 1100px; margin: 0 auto; padding: 0 24px;
    display: flex; justify-content: space-between; align-items: center;
}
.logo { font-size: 1.1rem; font-weight: 700; color: var(--text); text-decoration: none; letter-spacing: -0.02em; }
.logo span { color: var(--accent); }
.nav-links { display: flex; gap: 24px; align-items: center; }
.nav-links a { font-size: 0.875rem; color: var(--text-secondary); text-decoration: none; transition: color 0.2s; }
.nav-links a:hover { color: var(--text); }
.nav-links a.active { color: var(--accent); }

/* Layout */
.container { max-width: 1100px; margin: 0 auto; padding: 0 24px; }
.page { padding-top: 80px; }

/* Breadcrumb & Header */
.breadcrumb { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 16px; }
.breadcrumb a { color: var(--accent); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.page-header { padding: 60px 0 40px; border-bottom: 1px solid var(--border); }
.page-header h1 { font-size: clamp(1.8rem, 4vw, 2.5rem); font-weight: 800; letter-spacing: -0.03em; margin-bottom: 12px; }
.page-header p { color: var(--text-secondary); font-size: 1.05rem; max-width: 700px; line-height: 1.7; }

/* Tags */
.tag { display: inline-block; padding: 4px 12px; border-radius: 100px; font-size: 0.75rem; font-weight: 600; border: 1px solid var(--border); color: var(--text-secondary); margin-right: 8px; margin-top: 12px; }
.tag.algo { border-color: rgba(108, 99, 255, 0.3); color: var(--accent); }
.tag a { color: inherit; text-decoration: none; }

/* AI Disclaimer */
.ai-disclaimer {
    background: rgba(251, 191, 36, 0.08);
    border: 1px solid rgba(251, 191, 36, 0.25);
    border-radius: 10px; padding: 12px 18px;
    font-size: 0.85rem; color: var(--yellow);
    margin-bottom: 20px; line-height: 1.6;
}
.ai-disclaimer a { color: var(--yellow); text-decoration: underline; text-underline-offset: 2px; }
.ai-disclaimer a:hover { color: var(--text); }

/* Problem statement */
.problem { padding: 40px 0; border-bottom: 1px solid var(--border); }
.problem h2 { font-size: 1.3rem; font-weight: 700; margin-bottom: 16px; }
.problem-box {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 12px; padding: 24px;
    font-size: 0.95rem; line-height: 1.8; color: var(--text-secondary);
}
.problem-box code {
    background: rgba(108, 99, 255, 0.1); color: var(--accent);
    padding: 2px 6px; border-radius: 4px; font-size: 0.9em;
}

/* Visualization area */
.viz { padding: 40px 0 80px; }
.viz h2 { font-size: 1.3rem; font-weight: 700; margin-bottom: 24px; }

/* Controls */
.controls { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 32px; align-items: center; }
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 20px; border-radius: 10px; font-size: 0.9rem; font-weight: 600;
    border: none; cursor: pointer; transition: all 0.2s; font-family: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); transform: translateY(-1px); }
.btn-secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.speed-label { font-size: 0.85rem; color: var(--text-secondary); margin-left: 8px; }

/* Config inputs */
.config { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; align-items: flex-end; }
.config-field label {
    display: block; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-secondary); margin-bottom: 6px; font-weight: 600;
}
.config-field input, .config-field select {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); padding: 8px 12px; font-size: 0.9rem; font-family: inherit;
    width: 200px; transition: border-color 0.2s;
}
.config-field input:focus, .config-field select:focus { outline: none; border-color: var(--accent); }

/* Card containers */
.viz-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 16px; padding: 24px; margin-bottom: 24px;
}
.viz-card-title {
    font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-secondary); margin-bottom: 16px; font-weight: 600;
}

/* Array visualization */
.array-container { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; justify-content: center; }
.array-cell {
    width: 48px; height: 48px; display: flex; align-items: center; justify-content: center;
    border-radius: 8px; font-weight: 600; font-size: 0.9rem;
    border: 2px solid var(--border); background: var(--bg-secondary);
    transition: all 0.3s ease; font-variant-numeric: tabular-nums;
    position: relative;
}
.array-cell.active { border-color: var(--accent); background: rgba(108, 99, 255, 0.1); }
.array-cell.left-ptr { border-color: var(--green); background: rgba(52, 211, 153, 0.1); }
.array-cell.right-ptr { border-color: var(--red); background: rgba(248, 113, 113, 0.1); }
.array-cell.mid-ptr { border-color: var(--accent); background: rgba(108, 99, 255, 0.15); }
.array-cell.found { border-color: var(--green); background: rgba(52, 211, 153, 0.2); }
.array-cell.discarded { opacity: 0.3; }
.array-cell.window { border-color: var(--cyan); background: rgba(34, 211, 238, 0.1); }
.array-cell.highlight { border-color: var(--yellow); background: rgba(251, 191, 36, 0.1); }
.array-cell.done { border-color: var(--green); background: rgba(52, 211, 153, 0.15); }

/* Pointer labels */
.ptr-label {
    position: absolute; bottom: -22px; font-size: 0.65rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap;
}
.ptr-label.lo { color: var(--green); }
.ptr-label.hi { color: var(--red); }
.ptr-label.mid { color: var(--accent); }
.ptr-label.left { color: var(--green); }
.ptr-label.right { color: var(--red); }
.ptr-label.slow { color: var(--cyan); }
.ptr-label.fast { color: var(--orange); }

/* Two-column layout */
.viz-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

/* Status / log */
.status-current { font-size: 1.1rem; font-weight: 600; margin-bottom: 16px; min-height: 1.8em; }
.status-current .highlight { color: var(--accent); }
.status-current .yes { color: var(--green); }
.status-current .no { color: var(--red); }

.log {
    max-height: 240px; overflow-y: auto;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.8rem; line-height: 1.8;
}
.log-entry { color: var(--text-secondary); }
.log-entry.success { color: var(--green); }
.log-entry.fail { color: var(--red); }
.log-entry.result { color: var(--accent); font-weight: 700; }

/* Code panel */
pre {
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.82rem; line-height: 1.9; overflow-x: auto;
}
.code-line { padding: 0 8px; border-radius: 4px; transition: background 0.3s; display: block; }
.code-line.active { background: rgba(108, 99, 255, 0.12); }
.kw { color: #c792ea; }
.fn { color: #82aaff; }
.num { color: var(--yellow); }
.cm { color: #546e7a; }
.op { color: #89ddff; }
.str { color: var(--green); }

/* Explanation */
.explanation { padding: 40px 0 60px; border-top: 1px solid var(--border); }
.explanation h2 { font-size: 1.3rem; font-weight: 700; margin-bottom: 16px; }
.explanation h3 { font-size: 1.05rem; font-weight: 700; margin: 24px 0 8px; }
.explanation p { color: var(--text-secondary); font-size: 0.95rem; line-height: 1.8; margin-bottom: 12px; }
.explanation ul { color: var(--text-secondary); font-size: 0.95rem; line-height: 1.8; margin-left: 20px; margin-bottom: 12px; }
.explanation code { background: rgba(108, 99, 255, 0.1); color: var(--accent); padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }
.complexity-table { margin: 16px 0; }
.complexity-row { display: flex; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.complexity-row:last-child { border-bottom: none; }
.complexity-label { color: var(--text-secondary); width: 120px; flex-shrink: 0; }
.complexity-value { color: var(--accent); font-family: 'SF Mono', monospace; font-weight: 600; }

/* Footer */
footer {
    background: var(--bg-secondary); border-top: 1px solid var(--border);
    padding: 32px 0; text-align: center;
}
footer p { color: var(--text-secondary); font-size: 0.85rem; }
footer a { color: var(--accent); text-decoration: none; }

/* Responsive */
@media (max-width: 768px) {
    .viz-grid { grid-template-columns: 1fr; }
    .config { flex-direction: column; }
    .config-field input, .config-field select { width: 100%; }
    .array-cell { width: 40px; height: 40px; font-size: 0.8rem; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* Graph / tree visualizations */
.graph-canvas {
    width: 100%; min-height: 300px;
    background: var(--bg-secondary); border-radius: 12px;
    border: 1px solid var(--border);
}

/* DP table */
.dp-table { border-collapse: collapse; margin: 0 auto; }
.dp-table td, .dp-table th {
    width: 42px; height: 42px; text-align: center;
    border: 1px solid var(--border); font-size: 0.85rem;
    font-variant-numeric: tabular-nums; transition: all 0.3s;
}
.dp-table th { background: var(--bg-secondary); color: var(--text-secondary); font-weight: 600; font-size: 0.75rem; }
.dp-table td.active { background: rgba(108, 99, 255, 0.15); border-color: var(--accent); }
.dp-table td.filled { background: rgba(52, 211, 153, 0.1); }
.dp-table td.current { background: rgba(251, 191, 36, 0.15); border-color: var(--yellow); }
