/* ==========================================================================
   GEN-Z / NOTION-STYLE MINIMALIST DESIGN SYSTEM
   ========================================================================== */
:root {
    /* Clean Light Theme (Default) */
    --color-bg-primary: #ffffff;
    --color-bg-secondary: #f9f9fb;
    --color-bg-tertiary: #f2f2f5;
    --color-text-primary: #111111;
    --color-text-secondary: #555555;
    --color-border: #eaeaee;
    
    /* Soft Pastel Accents */
    --color-accent-1: #0066ff; /* Searching - Sharp Blue */
    --color-accent-2: #7c3aed; /* Sorting - Soft Purple (tuned for WCAG AA with white text) */
    --color-accent-3: #10b981; /* Success - Mint Green */
    --color-accent-4: #f59e0b; /* Warning - Warm Amber */
    --color-accent-5: #ef4444; /* Error - Soft Red */

    /* Fixed (theme-independent) text colors for legibility on top of the accent colors above */
    --color-on-warm: #14131a; /* dark text for amber/green/red solid badges & bars */
    --color-success-text: #047857; /* accessible green for text-on-tint (quiz/checkpoint "correct") */
    --color-danger-text: #b91c1c; /* accessible red for text-on-tint (quiz/checkpoint "wrong") */

    --color-bar-default: #e2e8f0;
    --color-nav-bg: rgba(255, 255, 255, 0.85);
    
    /* Extremely subtle shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.03);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.04);
    
    --border-radius: 16px;
    --border-radius-sm: 8px;
    
    /* Light Theme Syntax Highlighting */
    --syn-bg: #f8f9fa;
    --syn-kw: #d73a49;
    --syn-str: #032f62;
    --syn-num: #005cc5;
    --syn-comment: #6a737d;
    --syn-func: #6f42c1;
}

[data-theme="dark"] {
    --color-bg-primary: #0d0d12;
    --color-bg-secondary: #14141a;
    --color-bg-tertiary: #1c1c24;
    --color-text-primary: #f3f4f6;
    --color-text-secondary: #c0c4cc;
    --color-border: #272732;
    
    --color-bar-default: #374151;
    --color-nav-bg: rgba(13, 13, 18, 0.85);
    
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.5);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.4);
    
    /* Dark Theme Syntax Highlighting */
    --syn-bg: #14141a;
    --syn-kw: #ff7b72;
    --syn-str: #a5d6ff;
    --syn-num: #79c0ff;
    --syn-comment: #8b949e;
    --syn-func: #d2a8ff;
}

/* ==========================================================================
   GLOBAL STYLES & TYPOGRAPHY
   ========================================================================== */
* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--color-bg-primary);
    color: var(--color-text-primary);
    line-height: 1.7;
    transition: background-color 0.3s, color 0.3s;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

h1 { font-size: clamp(2.5rem, 6vw, 4.5rem); font-weight: 800; line-height: 1.08; margin-bottom: 1.5rem; letter-spacing: -0.03em; }
h2 { font-size: clamp(1.75rem, 4vw, 2.5rem); font-weight: 700; margin-bottom: 1.5rem; color: var(--color-text-primary); letter-spacing: -0.02em; }
h3 { font-size: 1.25rem; font-weight: 700; margin-bottom: 0.75rem; letter-spacing: -0.01em; }
p { margin-bottom: 1.5rem; color: var(--color-text-secondary); font-size: 1.05rem; line-height: 1.7; }

a { color: var(--color-accent-1); text-decoration: none; font-weight: 500; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--color-accent-1); outline-offset: 2px; border-radius: 4px; }

.skip-link {
    position: absolute; top: -100%; left: 50%; transform: translateX(-50%); z-index: 1001;
    background: var(--color-text-primary); color: var(--color-bg-primary);
    padding: 0.75rem 1.5rem; border-radius: 0 0 8px 8px; font-weight: 600;
}
.skip-link:focus { top: 0; }

section { padding: 8rem 2rem; max-width: 1200px; margin: 0 auto; }
.section-divider { height: 1px; background: var(--color-border); margin: 0 auto; max-width: 1000px; }

/* ==========================================================================
   NAVIGATION
   ========================================================================== */
nav {
    position: fixed; top: 0; left: 0; right: 0; height: 70px;
    background-color: var(--color-nav-bg); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    display: flex; justify-content: space-between; align-items: center; gap: 1.5rem;
    padding: 0 2rem; z-index: 1000; border-bottom: 1px solid var(--color-border);
}

.nav-brand { font-weight: 700; font-size: clamp(0.85rem, 1.6vw, 1.15rem); white-space: nowrap; flex-shrink: 0; display: flex; align-items: center; gap: 0.5rem; letter-spacing: -0.02em; font-family: 'Inter', -apple-system, sans-serif; }
.nav-brand span { color: var(--color-accent-1); }
.logo-cds { font-family: 'JetBrains Mono', monospace; font-weight: 700; font-size: 1.15rem; background: linear-gradient(135deg, var(--color-accent-1), #8b5cf6); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; padding: 0.15rem 0.3rem; }

.nav-links { display: flex; gap: 1rem; list-style: none; margin-left: auto; margin-right: 2rem; }
.nav-links a { color: var(--color-text-secondary); font-weight: 500; font-size: 0.78rem; white-space: nowrap; transition: color 0.2s, transform 0.2s; font-family: 'Inter', -apple-system, sans-serif; letter-spacing: 0.02em; position: relative; }
.nav-links a::after { content: ''; position: absolute; bottom: -2px; left: 0; width: 0; height: 2px; background: var(--color-accent-1); transition: width 0.25s ease; border-radius: 2px; }
.nav-links a:hover { color: var(--color-text-primary); transform: translateY(-1px); text-decoration: none; }
.nav-links a:hover::after { width: 100%; }
.nav-links a.active { color: var(--color-text-primary); }
.nav-links a.active::after { width: 100%; }
.nav-links a:hover, .nav-links a.active { color: var(--color-text-primary); text-decoration: none; }

.nav-controls { display: flex; align-items: center; gap: 1rem; }
.theme-toggle { background: none; border: none; font-size: 1.25rem; cursor: pointer; color: var(--color-text-primary); padding: 0.5rem; border-radius: 50%; transition: background 0.2s; }
.theme-toggle:hover { background: var(--color-bg-tertiary); }

.hamburger { display: none; background: none; border: none; color: var(--color-text-primary); font-size: 1.5rem; cursor: pointer; }

/* ==========================================================================
   HERO SECTION
   ========================================================================== */
#home {
    min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center;
    text-align: center; position: relative; padding-top: 70px; overflow: hidden;
}

.hero-content { z-index: 2; width: 100%; max-width: 800px; padding: 2rem; position: relative; box-sizing: border-box; }
.hero-subtitle { 
    display: inline-block; padding: 0.5rem 1rem; background: var(--color-bg-tertiary); 
    border-radius: 100px; color: var(--color-accent-1); font-weight: 700; 
    font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 1.5rem; font-family: 'Inter', -apple-system, sans-serif;
}

/* Hero animated SVG illustration */
.hero-visual {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    opacity: 0.12; pointer-events: none; z-index: 0;
}
.hero-svg { width: 90%; max-width: 500px; height: auto; }

/* Bar entrance animation */
.hero-svg .bar { animation: barRise 0.6s ease-out both; transform-origin: bottom; }
.hero-svg .bar-1 { animation-delay: 0.1s; }
.hero-svg .bar-2 { animation-delay: 0.2s; }
.hero-svg .bar-3 { animation-delay: 0.3s; }
.hero-svg .bar-4 { animation-delay: 0.15s; }
.hero-svg .bar-5 { animation-delay: 0.35s; }
.hero-svg .bar-6 { animation-delay: 0.25s; }
.hero-svg .bar-7 { animation-delay: 0.4s; }

@keyframes barRise {
    from { transform: scaleY(0); }
    to { transform: scaleY(1); }
}

/* Scanning line animation */
.hero-svg .scan-line {
    animation: scanMove 3s ease-in-out infinite;
}
@keyframes scanMove {
    0% { transform: translateX(-10px); opacity: 0; }
    10% { opacity: 0.8; }
    90% { opacity: 0.8; }
    100% { transform: translateX(390px); opacity: 0; }
}

/* Bar pulse — suggests an active comparison */
.hero-svg .bar-4 { animation: barRise 0.6s ease-out both, barPulse 2s ease-in-out 1s infinite; }
@keyframes barPulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

@media (max-width: 768px) {
    .hero-visual { opacity: 0.08; }
}

.btn-group { display: flex; gap: 1rem; justify-content: center; margin-top: 3rem; }
.btn {
    padding: 0.875rem 1.75rem; border-radius: 100px; font-weight: 600; cursor: pointer; display: inline-flex; justify-content: center; align-items: center;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); border: none; font-family: 'Inter', -apple-system, sans-serif; font-size: 1rem; text-decoration: none;
}
.btn-primary { background-color: var(--color-text-primary); color: var(--color-bg-primary); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); opacity: 0.9; text-decoration: none; }
.btn-secondary { background-color: transparent; border: 1px solid var(--color-border); color: var(--color-text-primary); }
.btn-secondary:hover { background-color: var(--color-bg-secondary); text-decoration: none; }

/* ==========================================================================
   COMPONENTS (Cards, Brain Map, Tags, Flowcharts)
   ========================================================================== */
.card {
    background-color: var(--color-bg-secondary); border-radius: var(--border-radius);
    padding: 2rem; border: 1px solid var(--color-border);
    transition: transform 0.2s, box-shadow 0.2s;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }

.grid-2x2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 2rem; }

/* "The Brain Map" - How to think section */
.brain-card {
    background-color: rgba(139, 92, 246, 0.04); border: none;
    border-left: 4px solid var(--color-accent-2); border-radius: 0 var(--border-radius-sm) var(--border-radius-sm) 0;
    padding: 1.5rem; margin: 1.5rem 0; position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
}
.brain-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.brain-card h4 { color: var(--color-accent-2); font-size: 0.9rem; margin-bottom: 0.75rem; display: flex; align-items: center; gap: 0.5rem; text-transform: uppercase; letter-spacing: 0.03em; font-family: 'Inter', -apple-system, sans-serif; }

.brain-card p { margin-bottom: 0.75rem; font-size: 0.95rem; }
.brain-card ul { margin-left: 1.25rem; color: var(--color-text-secondary); font-size: 0.95rem; }
.brain-card li { margin-bottom: 0.5rem; }

.tag-list { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.5rem; }
.tag {
    font-size: 0.8rem; font-weight: 500; padding: 0.35rem 0.85rem; border-radius: 100px;
    background-color: var(--color-bg-secondary); border: 1px solid var(--color-border);
    display: inline-flex; align-items: center; gap: 0.4rem; font-family: 'Inter', -apple-system, sans-serif;
}
.tag.vibe { background-color: var(--color-text-primary); color: var(--color-bg-primary); border: none; font-weight: 600; }
.tag.blue { color: var(--color-accent-1); background-color: rgba(0, 102, 255, 0.05); border-color: rgba(0, 102, 255, 0.1); }
.tag.purple { color: var(--color-accent-2); background-color: rgba(139, 92, 246, 0.05); border-color: rgba(139, 92, 246, 0.1); }

/* Flowcharts (Mermaid) */
.flowchart-details {
    margin: 1.5rem 0; background: var(--color-bg-tertiary); border-radius: var(--border-radius-sm);
    border: 1px solid var(--color-border); overflow: hidden;
}
.flowchart-details summary {
    padding: 1rem; font-weight: 600; cursor: pointer; color: var(--color-text-primary);
    user-select: none; display: flex; align-items: center; gap: 0.5rem;
}
.flowchart-details summary:hover { background: var(--color-bg-secondary); }
.mermaid-container { padding: 1.5rem; background: var(--color-bg-primary); border-top: 1px solid var(--color-border); overflow-x: auto; display: flex; justify-content: center; }
.mermaid-container .mermaid { max-width: 100%; }

/* Algorithm Steps List */
.steps-container { padding: 1.5rem 2rem; background: var(--color-bg-primary); border-top: 1px solid var(--color-border); }
.steps-list { margin: 0; padding: 0 0 0 1.75rem; display: flex; flex-direction: column; gap: 0.75rem; }
.steps-list li { color: var(--color-text-secondary); font-size: 0.95rem; line-height: 1.7; padding-left: 0.25rem; }
.steps-list li strong { color: var(--color-text-primary); }

/* Code Blocks */
.code-container { position: relative; margin-top: 1rem; }
pre {
    background-color: var(--syn-bg);
    color: var(--color-text-primary); padding: 0; border-radius: var(--border-radius-sm);
    overflow-x: auto; font-family: 'JetBrains Mono', 'Consolas', monospace; font-size: 0.85rem;
    border: 1px solid var(--color-border); line-height: 1.6;
}
pre code { display: block; }
.copy-btn {
    position: absolute; top: 12px; right: 12px; background: var(--color-bg-primary); border: 1px solid var(--color-border);
    color: var(--color-text-secondary); padding: 0.4rem 0.75rem; border-radius: 6px; cursor: pointer; font-size: 0.75rem; transition: all 0.2s; font-weight: 500;
    font-family: 'Inter', -apple-system, sans-serif;
}
.copy-btn:hover { background: var(--color-bg-tertiary); color: var(--color-text-primary); }

/* Line numbers */
.code-line { display: flex; }
.line-num {
    flex-shrink: 0; width: 3.5ch; text-align: right; padding: 0 1ch 0 1rem;
    color: var(--color-text-secondary); opacity: 0.5; user-select: none;
    border-right: 1px solid var(--color-border);
}
.line-content { padding: 0 1rem; white-space: pre; }

/* Syntax colors */
.kw { color: var(--syn-kw); font-weight: 600; } .str { color: var(--syn-str); } 
.num { color: var(--syn-num); } .comment { color: var(--syn-comment); font-style: italic; opacity: 0.9; }
.func { color: var(--syn-func); }

/* ==========================================================================
   ALGORITHM LAYOUT (Split View)
   ========================================================================== */
.algorithm-section { display: flex; gap: 4rem; margin-bottom: 6rem; align-items: flex-start; }
.algo-story { flex: 1.1; min-width: 0; }
.algo-visualizer { flex: 0.9; position: sticky; top: 100px; }

/* ==========================================================================
   VISUALIZER ENGINE
   ========================================================================== */
.viz-container {
    background-color: var(--color-bg-primary); border: 1px solid var(--color-border);
    border-radius: var(--border-radius); padding: 2rem; box-shadow: var(--shadow-sm);
}

.viz-canvas {
    height: 280px; display: flex; align-items: flex-end; justify-content: center;
    gap: 6px; margin-bottom: 2rem; position: relative; padding-bottom: 20px;
}

.viz-bar {
    background-color: var(--color-bar-default); width: 100%; border-radius: 6px 6px 0 0;
    transition: height 0.3s ease, background-color 0.3s ease, transform 0.3s ease;
    position: relative; display: flex; justify-content: center; align-items: flex-end; padding-bottom: 8px;
}

.viz-bar span { font-size: 0.75rem; color: var(--color-text-primary); font-family: 'JetBrains Mono', monospace; font-weight: 600; }
.viz-bar.comparing span { color: #fff; }
.viz-bar.active span, .viz-bar.sorted span, .viz-bar.pivot span { color: var(--color-on-warm); }

.viz-controls { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.viz-input { 
    background: var(--color-bg-secondary); border: 1px solid var(--color-border); 
    color: var(--color-text-primary); padding: 0.6rem 1rem; border-radius: 100px; width: 90px; font-family: inherit; font-weight: 500;
}
.viz-status { flex-grow: 1; text-align: right; font-size: 0.95rem; font-weight: 500; color: var(--color-text-secondary); }

.viz-bar.active { background-color: var(--color-accent-4); } /* Checking/Comparing */
.viz-bar.comparing { background-color: var(--color-accent-2); } /* Sorting active */
.viz-bar.sorted { background-color: var(--color-accent-3); } /* Done */
.viz-bar.pivot { background-color: var(--color-accent-5); } /* Pivot */
.viz-bar.inactive { opacity: 0.2; }

/* Visualizer Color Legend */
.viz-legend {
    display: flex; gap: 1rem; flex-wrap: wrap; justify-content: center;
    margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--color-border);
}
.viz-legend-item {
    display: flex; align-items: center; gap: 0.35rem;
    font-size: 0.7rem; font-family: 'Inter', -apple-system, sans-serif;
    color: var(--color-text-secondary); font-weight: 500;
}
.viz-legend-swatch {
    width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0;
    border: 1px solid var(--color-border);
}

/* Visualizer utility classes (replacing inline styles) */
.viz-btn { padding: 0.6rem 1.2rem; }
.algo-first { margin-top: 4rem; }
.hero-text { font-size: 1.2rem; width: 100%; max-width: 600px; margin: 0 auto; box-sizing: border-box; }
.author-img { width: 90px; height: 80px; border-radius: 50%; object-fit: cover; margin: 0 auto 1.5rem; display: block; border: 1px solid var(--color-border); }
.portfolio-btn { display: inline-flex; align-items: center; gap: 0.5rem; }
.footer-main { padding: 3rem 2rem; text-align: center; background: var(--color-bg-secondary); border-top: 1px solid var(--color-border); color: var(--color-text-secondary); font-size: 0.9rem; }
.quiz-nav-btn { width: 100%; }

/* ==========================================================================
   SCROLL PROGRESS BAR
   ========================================================================== */
.progress-bar {
    position: fixed; top: 0; left: 0; height: 3px; width: 0%;
    background: linear-gradient(90deg, var(--color-accent-1), var(--color-accent-2));
    z-index: 1001; transition: width 0.1s linear;
}

/* ==========================================================================
   EMBEDDED CHECKPOINTS
   ========================================================================== */
.checkpoint {
    margin-top: 2rem; padding: 1.25rem 1.5rem;
    background: var(--color-bg-secondary); border-radius: var(--border-radius-sm);
    border: 1px solid var(--color-border);
}
.checkpoint-heading {
    font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--color-accent-1); font-weight: 700; margin-bottom: 0.75rem;
    font-family: 'Inter', -apple-system, sans-serif; display: flex; align-items: center; gap: 0.4rem;
}
.check-q { margin-bottom: 1rem; }
.check-q:last-child { margin-bottom: 0; }
.check-q-text { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.6rem; color: var(--color-text-primary); }
.check-opts { display: flex; flex-direction: column; gap: 0.4rem; }
.check-opt {
    padding: 0.5rem 0.9rem; border: 1px solid var(--color-border); border-radius: 6px;
    background: var(--color-bg-primary); cursor: pointer; transition: all 0.15s;
    font-size: 0.85rem; font-weight: 500; text-align: left; font-family: inherit;
}
.check-opt:hover { border-color: var(--color-accent-1); }
.check-opt.selected { background: rgba(0, 102, 255, 0.08); border-color: var(--color-accent-1); }
.check-opt.correct { background: rgba(16, 185, 129, 0.1); border-color: var(--color-accent-3); color: var(--color-success-text); }
.check-opt.wrong { background: rgba(239, 68, 68, 0.1); border-color: var(--color-accent-5); color: var(--color-danger-text); }
.check-feedback {
    font-size: 0.82rem; margin-top: 0.5rem; padding: 0.5rem 0.75rem;
    background: var(--color-bg-tertiary); border-radius: 6px; line-height: 1.5; display: none;
    border-left: 3px solid var(--color-accent-3);
}
.check-feedback.show { display: block; }

/* ==========================================================================
   PYTHON STARTER PACK
   ========================================================================== */
.starter-grid { display: flex; flex-direction: column; gap: 0.75rem; }
.starter-card {
    background: var(--color-bg-secondary); border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm); overflow: hidden;
    transition: border-color 0.2s;
}
.starter-card:hover { border-color: var(--color-accent-1); }
.starter-header {
    display: flex; align-items: flex-start; gap: 1rem; padding: 1.25rem 1.5rem; cursor: pointer;
}
.starter-icon { font-size: 1.5rem; flex-shrink: 0; margin-top: 0.15rem; }
.starter-header h3 { font-size: 1rem; margin-bottom: 0.25rem; }
.starter-header p { font-size: 0.9rem; margin-bottom: 0; color: var(--color-text-secondary); line-height: 1.6; }
.starter-code summary {
    padding: 0.5rem 1.5rem 0.5rem 3.5rem; font-size: 0.8rem; cursor: pointer; color: var(--color-accent-1);
    font-weight: 600; font-family: 'Inter', -apple-system, sans-serif; user-select: none;
    border-top: 1px solid var(--color-border);
}
.starter-code summary:hover { background: var(--color-bg-tertiary); }
.starter-code .code-container { margin: 0; }

/* Big O complexity badge */
.tag.complexity { background: var(--color-accent-1); color: #fff; border: none; font-family: 'JetBrains Mono', monospace; }

/* ==========================================================================
   QUIZ SECTION
   ========================================================================== */
.quiz-container { max-width: 800px; margin: 0 auto; }
.quiz-card { background: var(--color-bg-secondary); border: 1px solid var(--color-border); border-radius: var(--border-radius); padding: 2rem; margin-bottom: 1.5rem; display: none; }
.quiz-card.active { display: block; animation: fadeIn 0.3s ease; }
.quiz-options { display: flex; flex-direction: column; gap: 0.75rem; margin-top: 1.5rem; }
.quiz-opt { 
    padding: 1rem 1.5rem; border: 1px solid var(--color-border); border-radius: var(--border-radius-sm); 
    background: var(--color-bg-primary); cursor: pointer; transition: all 0.2s; font-weight: 500;
}
.quiz-opt:hover { border-color: var(--color-accent-1); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.quiz-opt.selected { background: rgba(0, 102, 255, 0.1); border-color: var(--color-accent-1); color: var(--color-accent-1); }
.quiz-opt.correct { background: rgba(16, 185, 129, 0.1); border-color: var(--color-accent-3); color: var(--color-success-text); }
.quiz-opt.wrong { background: rgba(239, 68, 68, 0.1); border-color: var(--color-accent-5); color: var(--color-danger-text); }
.quiz-progress { display: flex; justify-content: space-between; margin-bottom: 1rem; color: var(--color-text-secondary); font-size: 0.9rem; font-weight: 600; }
.quiz-nav { display: flex; justify-content: space-between; margin-top: 2rem; }

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

/* ==========================================================================
   HERO STATS STRIP
   ========================================================================== */
.hero-stats {
    display: flex; justify-content: center; gap: 2.5rem; flex-wrap: wrap;
    margin-top: 3.5rem; padding-top: 2rem; border-top: 1px solid var(--color-border);
}
.hero-stat { display: flex; flex-direction: column; align-items: center; gap: 0.15rem; }
.hero-stat-num { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.02em; color: var(--color-text-primary); }
.hero-stat-label {
    font-size: 0.75rem; font-weight: 500; color: var(--color-text-secondary);
    text-transform: uppercase; letter-spacing: 0.04em;
}

/* ==========================================================================
   HOW THIS PAGE WORKS
   ========================================================================== */
.how-it-works { padding: 3rem 2rem 5rem; max-width: 1200px; margin: 0 auto; }
.how-it-works-inner {
    display: flex; align-items: stretch; justify-content: center; gap: 1.25rem;
    flex-wrap: wrap;
}
.how-step {
    flex: 1 1 200px; max-width: 240px; text-align: center;
    background: var(--color-bg-secondary); border: 1px solid var(--color-border);
    border-radius: var(--border-radius); padding: 1.5rem 1.25rem;
}
.how-step-icon { font-size: 1.75rem; display: block; margin-bottom: 0.75rem; }
.how-step h4 { font-size: 0.95rem; margin-bottom: 0.4rem; }
.how-step p { font-size: 0.85rem; margin-bottom: 0; line-height: 1.55; }
.how-arrow {
    display: flex; align-items: center; color: var(--color-text-secondary);
    font-size: 1.25rem; opacity: 0.5; flex-shrink: 0;
}

/* ==========================================================================
   SECTION HEADING ROW + TIME TAGS
   ========================================================================== */
.section-heading-row { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.section-heading-row h2 { margin-bottom: 0; }
.tag.time-tag {
    background: var(--color-bg-tertiary); color: var(--color-text-secondary);
    font-family: 'JetBrains Mono', monospace; font-weight: 500;
}

/* ==========================================================================
   IN-PAGE SUB-NAVIGATION (pills)
   ========================================================================== */
.subnav {
    display: flex; gap: 0.6rem; flex-wrap: wrap; margin: 1.5rem 0 2.5rem;
    position: sticky; top: 86px; z-index: 10;
    background: var(--color-nav-bg); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    padding: 0.6rem; border-radius: 100px; border: 1px solid var(--color-border);
    width: fit-content;
}
.subnav-pill {
    padding: 0.45rem 1rem; border-radius: 100px; font-size: 0.85rem; font-weight: 600;
    color: var(--color-text-secondary); background: transparent; transition: all 0.2s;
    white-space: nowrap;
}
.subnav-pill:hover { background: var(--color-bg-tertiary); color: var(--color-text-primary); text-decoration: none; }

/* ==========================================================================
   CHEAT SHEET / COMPARISON TABLES
   ========================================================================== */
.table-wrap {
    overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--border-radius-sm);
    -webkit-overflow-scrolling: touch;
}
.cheat-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; min-width: 640px; }
.cheat-table th, .cheat-table td { padding: 0.85rem 1.1rem; text-align: left; border-bottom: 1px solid var(--color-border); }
.cheat-table th {
    background: var(--color-bg-tertiary); font-family: 'Inter', sans-serif; font-weight: 600;
    font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--color-text-secondary);
    white-space: nowrap;
}
.cheat-table tbody tr:last-child td { border-bottom: none; }
.cheat-table tbody tr:hover { background: var(--color-bg-secondary); }
.cheat-table td code { font-size: 0.85rem; }

/* ==========================================================================
   GLOSSARY
   ========================================================================== */
.glossary-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; margin-top: 2rem; }
.glossary-item {
    background: var(--color-bg-secondary); border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm); padding: 1.1rem 1.25rem;
}
.glossary-term-name {
    display: block; font-weight: 700; font-family: 'JetBrains Mono', monospace;
    color: var(--color-accent-1); margin-bottom: 0.4rem; font-size: 0.95rem;
}
.glossary-def { font-size: 0.88rem; color: var(--color-text-secondary); line-height: 1.55; }

/* ==========================================================================
   RESPONSIVE DESIGN
   ========================================================================== */
@media (min-width: 993px) {
    .viz-canvas { min-height: 320px; }
}

@media (max-width: 992px) {
    .algorithm-section { flex-direction: column; gap: 2rem; }
    .algo-story { width: 100%; }
    .algo-visualizer { position: relative; top: 0; width: 100%; }
}

/* Nav switches to the hamburger pattern a bit earlier than the general
   mobile breakpoint below — with 9 top-level links, the inline nav needs
   about 1120px to fit on one line without wrapping or overflowing. */
@media (max-width: 1140px) {
    .nav-links {
        position: fixed; top: 70px; left: -100%; width: 70%; height: calc(100vh - 70px);
        background: var(--color-nav-bg); flex-direction: column; align-items: center; justify-content: flex-start;
        padding-top: 2rem; transition: left 0.3s ease; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
        margin: 0; box-shadow: var(--shadow-lg);
    }
    .nav-links a { font-size: 0.95rem; }
    .nav-links.nav-open { left: 0; }
    .nav-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.3); z-index: 999; display: none; }
    .nav-overlay.active { display: block; }
    .hamburger { display: block; }
}

@media (max-width: 768px) {
    section { padding: 5rem 1.5rem; }
    .btn-group { flex-direction: column; }
    .viz-bar { min-width: 12px; }
    button, .quiz-opt, .hamburger { min-height: 44px; }
    .viz-input { min-height: 44px; }
    .hero-stats { gap: 1.5rem; }
    .how-it-works-inner { flex-direction: column; align-items: center; }
    .how-step { width: 100%; }
    .how-arrow { transform: rotate(90deg); }
    .subnav { position: static; width: 100%; backdrop-filter: none; -webkit-backdrop-filter: none; }
}

/* ==========================================================================
   PRINT LAYOUT
   ========================================================================== */
@media print {
    nav, .nav-overlay, .hamburger, .theme-toggle, .viz-container, .btn, .viz-controls, .copy-btn, .quiz-nav, .quiz-opt, .subnav, .how-it-works { display: none !important; }
    body { font-size: 11pt; color: #000; background: #fff; }
    section { padding: 1rem 0; page-break-inside: avoid; }
    .algorithm-section { break-inside: avoid; }
    pre { border: 1px solid #ccc; background: #f9f9f9; padding: 0.75rem; font-size: 8pt; white-space: pre-wrap; word-break: break-word; }
    .mermaid-container { overflow: visible; }
    .mermaid-container svg { max-width: 100%; height: auto; }
    .flowchart-details { break-inside: avoid; page-break-inside: avoid; }
    .flowchart-details[open] { break-inside: avoid; }
    details.flowchart-details summary { list-style: none; }
    details.flowchart-details[open] summary { margin-bottom: 0.5rem; }
    details.flowchart-details:not([open]) { display: block !important; }
    details.flowchart-details:not([open]) summary { display: none; }
    details.flowchart-details:not([open]) .mermaid-container, details.flowchart-details:not([open]) .steps-container { display: block !important; }
    .brain-card { border-left-color: #8b5cf6; background: #faf5ff; }
    .code-line { break-inside: avoid; }
    a { color: #000; text-decoration: underline; }
    .footer-main { position: fixed; bottom: 0; width: 100%; font-size: 8pt; border: none; }
    @page { margin: 1.5cm; }
}

/* ==========================================================================
   GLOSSARY TOOLTIPS
   ========================================================================== */
.glossary-term {
    border-bottom: 1px dashed var(--color-text-secondary);
    cursor: help;
    position: relative;
}

.glossary-term:hover::after,
.glossary-term:focus::after {
    content: attr(data-definition);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-card-bg);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 400;
    font-family: 'Inter', sans-serif;
    white-space: normal;
    width: 260px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 100;
    line-height: 1.4;
    text-align: left;
    pointer-events: none;
}

.glossary-term:hover::before,
.glossary-term:focus::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--color-border);
    z-index: 101;
    pointer-events: none;
}

[data-theme="dark"] .glossary-term::after {
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

/* ==========================================================================
   DATA STRUCTURE VISUALIZERS (Stack, Queue, Linked List)
   ========================================================================== */

/* Shared */
.ds-empty {
    color: var(--color-text-secondary); font-size: 0.9rem; font-weight: 500;
    padding: 2rem; text-align: center; width: 100%;
    font-family: 'Inter', -apple-system, sans-serif;
}

/* Stack */
.ds-stack-wrapper {
    display: flex; flex-direction: column-reverse; align-items: center;
    justify-content: flex-end; height: 100%; min-height: 220px;
    gap: 6px; padding: 1rem 0;
}

.ds-stack-item {
    background: var(--color-accent-4); color: var(--color-on-warm); font-weight: 700;
    font-family: 'JetBrains Mono', monospace; font-size: 1rem;
    padding: 0.6rem 2.5rem; border-radius: 8px; width: 80%;
    max-width: 220px; text-align: center;
    animation: dsFadeIn 0.25s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.ds-stack-item:first-child {
    background: var(--color-accent-5);
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.2);
}

/* Queue */
.ds-queue-wrapper {
    display: flex; align-items: center; justify-content: center;
    gap: 4px; height: 100%; min-height: 220px; padding: 1rem 0.5rem;
    flex-wrap: nowrap; overflow-x: auto;
}

.ds-queue-item {
    background: var(--color-accent-1); color: #fff; font-weight: 700;
    font-family: 'JetBrains Mono', monospace; font-size: 1rem;
    padding: 0.6rem 1.2rem; border-radius: 8px; min-width: 50px;
    text-align: center; flex-shrink: 0;
    animation: dsFadeIn 0.25s ease;
}

.ds-queue-item.front {
    background: var(--color-accent-3);
    color: var(--color-on-warm);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.2);
}

.ds-queue-item.rear {
    background: var(--color-accent-4);
    color: var(--color-on-warm);
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.2);
}

.ds-queue-arrow {
    font-size: 1.2rem; color: var(--color-text-secondary);
    font-weight: 700; flex-shrink: 0;
}

.ds-queue-label {
    font-size: 0.7rem; font-weight: 600; color: var(--color-text-secondary);
    font-family: 'Inter', -apple-system, sans-serif; text-transform: uppercase;
    letter-spacing: 0.04em; flex-shrink: 0; white-space: nowrap;
}

/* Linked List */
.ds-ll-wrapper {
    display: flex; align-items: center; justify-content: center;
    gap: 4px; height: 100%; min-height: 220px; padding: 1rem 0.5rem;
    flex-wrap: nowrap; overflow-x: auto;
}

.ds-ll-node {
    background: var(--color-bg-secondary); border: 2px solid var(--color-accent-2);
    border-radius: 8px; display: flex; flex-direction: column;
    align-items: center; min-width: 60px; flex-shrink: 0;
    animation: dsFadeIn 0.25s ease;
    overflow: hidden;
}

.ds-ll-val {
    font-family: 'JetBrains Mono', monospace; font-weight: 700;
    font-size: 1.1rem; padding: 0.5rem 1rem; color: var(--color-text-primary);
}

.ds-ll-pointer {
    font-size: 0.55rem; font-family: 'Inter', -apple-system, sans-serif;
    background: var(--color-accent-2); color: #fff; width: 100%;
    text-align: center; padding: 0.2rem 0; text-transform: uppercase;
    letter-spacing: 0.05em; font-weight: 600;
}

.ds-ll-arrow {
    font-size: 1.4rem; color: var(--color-accent-2); font-weight: 700;
    flex-shrink: 0;
}

.ds-ll-end {
    font-family: 'JetBrains Mono', monospace; font-size: 0.8rem;
    color: var(--color-text-secondary); font-weight: 500;
    padding: 0.4rem 0.6rem; border: 1px dashed var(--color-border);
    border-radius: 6px; flex-shrink: 0;
}

.ds-ll-label {
    font-size: 0.7rem; font-weight: 700; color: var(--color-accent-2);
    font-family: 'Inter', -apple-system, sans-serif; text-transform: uppercase;
    letter-spacing: 0.05em; flex-shrink: 0; margin-right: 2px;
}

@keyframes dsFadeIn {
    from { opacity: 0; transform: scale(0.85); }
    to { opacity: 1; transform: scale(1); }
}

/* Ensure data structure canvases center content */
#canvas-stack, #canvas-queue, #canvas-linked-list {
    display: flex; align-items: center; justify-content: center;
}
