/*=================================
   ALGOVISION MASTER STYLESHEET 
===================================
*/

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;600;700;800&family=JetBrains+Mono:wght@500&family=Outfit:wght@400;600;800&display=swap');

/* ==========================================================
   DESIGN SYSTEM TOKENS — "Warm Soft-Tech & Modern Bento" v1.0
   Spec ref: AlgoVision Design Language & Architecture Spec, §1 & §3
   Phase 1 of the UI/UX overhaul roadmap.

   IMPORTANT: these tokens are declared but NOT YET CONSUMED by any
   rule below this block. Every existing component rule in this file
   still uses its original hard-coded hex values on purpose — token
   migration happens screen-by-screen in later phases (see roadmap).
   This phase must produce ZERO visual change to the live site.
   ========================================================== */

:root {

    /* --- §1.1 Base Canvas ---
       Replaced the prototype-phase off-white + navy/blue combo with a
       warm blush-cream canvas and a deep plum-ink chrome — chosen to
       harmonize with the palette already locked in below (plum echoes
       the Graph category's lavender without reusing it outright;
       terracotta, introduced further down, stays clear of both
       --state-amber and --state-emerald so it can't be confused with
       either transient visualizer state). */
    --canvas-base: #F7EFE9;
    /* Primary page background — warm blush-cream */
    --canvas-alt: #EFE2D8;
    /* Secondary section background — deeper warm sand */
    --chrome-ink: #241A2E;
    /* Floating dark sidebar/nav/dock shell — deep plum-espresso.
       Renamed from --sidebar-navy now that it's no longer navy. */
    --chrome-ink-elevated: #2F2338;
    /* Sidebar hover/active row. Renamed from --sidebar-navy-elevated. */
    --panel-dark: #2A1F33;
    /* Content-panel dark surface (theory drawer, code panel, telemetry
       HUD, visualizer arena) — deliberately a slightly different shade
       from --chrome-ink so chrome and content surfaces stay visually
       distinct. Also doubles as the shared dark "ink" text color. */
    --surface-dark-alt: #3D2E48;
    /* Secondary dark shade — dark-context dividers/borders (sidebar
       border, array-block default fill, tree/graph node fill) and,
       coincidentally the same value, a dark neutral text/hover color
       on light surfaces (algo-card-title, filter-pill:hover). */
    --muted-slate: #cbd5e1;
    /* Muted neutral — light text on dark panels, and light icon/border
       accents on light surfaces. Left cool/neutral on purpose — a
       warm-toned muted color would fight with the terracotta accent
       wherever both appear near each other (e.g. code text color). */

    /* --- Chrome accent (Phase: color-identity pass) ---
       Replaces the old raw #3b82f6 used throughout for buttons, links,
       hover states, and focus rings. Deliberately NOT reused from
       --state-blue/--cat-array — blue was previously overloaded across
       chrome AND category AND visualizer-state simultaneously; giving
       chrome its own distinct hue fixes that overload as a side effect
       of the aesthetic change, not just a coat of paint. */
    --accent-primary: #E2724A;
    --accent-primary-rgb: 226, 114, 74;
    --accent-primary-dark: #C85F3A;
    /* hover/pressed variant, for the few spots that darken on interaction */

    /* --- §1.2 Category Palette — CHROME & BADGES ONLY ---
       Never apply these to a visualizer node/element state. */
    --cat-array: #DCEBFA;
    /* Soft Sky Blue */
    --cat-stack: #FBE3D5;
    /* Warm Peach */
    --cat-queue: #FBF1CC;
    /* Butter Yellow */
    --cat-tree: #DDEFE3;
    /* Mint Green */
    --cat-graph: #E7E1F5;
    /* Lavender */
    --cat-border: rgba(0, 0, 0, 0.05);
    /* Standard 1px card border, paired with every category fill */

    /* --- §1.3 State Palette — TRANSIENT VISUALIZER ANIMATIONS ONLY ---
       Never apply these to static UI chrome. Each state also has a
       non-color differentiator (motion/shape/icon) defined in the
       component phase that consumes it — see spec §1.3. */
    --state-amber: #F59E0B;
    /* Active / Comparing (primary) — pulsing */
    --state-blue: #3B82F6;
    /* Comparing (secondary) — static glow */
    --state-blue-rgb: 59, 130, 246;
    /* rgba() companion for the glow/tooltip-style effects on this state */
    --state-emerald: #10B981;
    /* Sorted / Found — elevation pop */
    --state-dim-opacity: 0.25;
    /* Dimmed / Discarded — opacity */
    --state-dim-grayscale: 40%;
    /* Dimmed / Discarded — desaturation, for non-color legibility */

    /* --- §1.4 Typography ---
       Font families are declared here as tokens; the @import above
       still supplies the actual font files. */
    --font-display: 'Outfit', sans-serif;
    /* Hero headlines only (Screen 1) */
    --font-ui: 'Plus Jakarta Sans', sans-serif;
    /* UI body, cards, panels */
    --font-mono: 'JetBrains Mono', monospace;
    /* Code Inspector line rendering */

    /* --- §1.5 Radius Scale --- */
    --radius-sm: 8px;
    /* Badges / pills */
    --radius-md: 14px;
    /* Bento cards */
    --radius-lg: 20px;
    /* Docks / drawers */
    --radius-full: 999px;
    /* Pill nav, filter tabs */

    /* --- §3 Elevation Scale (4-Tier) ---
       Rule: a component may only use its own tier's shadow/border/
       z-index — never borrow from an adjacent tier. */

    /* L1 — Canvas: page background, visualizer arena */
    --elevation-l1-shadow: none;
    --elevation-l1-border: none;
    --elevation-l1-z: 0;

    /* L2 — Sidebar / Panels: sidebar, bento cards, docked Code Inspector */
    --elevation-l2-shadow: 0 2px 8px rgba(11, 17, 32, 0.06);
    --elevation-l2-border: 1px solid rgba(0, 0, 0, 0.05);
    --elevation-l2-z: 10;

    /* L3 — Floating Docks: bottom Control Dock, floating/inset sidebar */
    --elevation-l3-shadow: 0 8px 24px rgba(11, 17, 32, 0.12);
    --elevation-l3-border: 1px solid rgba(255, 255, 255, 0.08);
    --elevation-l3-z: 20;

    /* L4 — Drawers / Overlays: Theory Drawer, confirm states, modals */
    --elevation-l4-shadow: 0 16px 48px rgba(11, 17, 32, 0.20);
    --elevation-l4-border: none;
    --elevation-l4-scrim: rgba(11, 17, 32, 0.35);
    --elevation-l4-z: 30;

    /* --- Motion durations (referenced by reduced-motion overrides below) --- */
    --motion-fast: 200ms;
    --motion-base: 400ms;
    --motion-slow: 600ms;
}

/* ==========================================================
   REDUCED-MOTION SCAFFOLD — spec §5.3
   Centralized here so every future animated component (ghost
   trail, amber pulse, elevation pop, drawer slide-in, etc.) has
   ONE place to register its fallback instead of scattering
   `prefers-reduced-motion` checks per-component. Populated
   progressively as each feature is built in later phases; empty
   / inert overrides for now since no component consumes the
   motion tokens above yet.
   ========================================================== */
@media (prefers-reduced-motion: reduce) {
    :root {
        --motion-fast: 0ms;
        --motion-base: 0ms;
        --motion-slow: 0ms;
    }

    /* Phase 3: complexity tooltip appears instantly, no fade delay */
    .complexity-tooltip {
        transition: none;
        transition-delay: 0s;
    }

    /* Phase 4: amber pulse becomes a static highlight (still colored,
       still ringed — just no scale animation) */
    .array-block.comparing {
        animation: none;
    }

    /* Phase 4: ghost trail shows/hides instantly instead of fading */
    .array-block.ghost-trail {
        transition: none;
    }

    /* Phase 4: found/sorted/current skip the translateY elevation-pop
       motion but keep every other visual cue (color, outline, checkmark) */
    .array-block.found,
    .array-block.sorted,
    .array-block.current,
    .array-block.comparing {
        transform: none !important;
    }

    /* Phase 6: hero illustration motifs stay still instead of floating */
    .hero-float-1,
    .hero-float-2,
    .hero-float-3 {
        animation: none;
    }

    /* Phase 7: drawer opens/closes instantly instead of sliding, scrim
       appears/disappears instantly instead of fading */
    .theory-drawer,
    .theory-drawer.open,
    .theory-scrim,
    .theory-scrim.open {
        transition: none;
    }
}

/* --- SECTION 1: GLOBAL BASE & RESETS --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--canvas-base);
    color: var(--panel-dark);
    font-family: var(--font-ui);
    /* Clean, modern body text */
    overflow-x: hidden;
    min-height: 100vh;
}

/* Headings use Outfit for a premium "Product" feel */
h1,
h2,
h3,
.nav-brand {
    font-family: var(--font-display);
    letter-spacing: -0.02em;
}

button {
    font-family: var(--font-ui);
    cursor: pointer;
    transition: 0.2s ease-in-out;
}

/* --- SECTION 2: SCREEN NAVIGATION --- */
.screen {
    display: none;
    min-height: 100vh;
    width: 100%;
}

.screen.active {
    display: block;
    animation: fadeIn 0.4s ease;
}

.hidden {
    display: none !important;
}

#welcome-screen.active {
    display: flex;
    flex-direction: column;
    background: radial-gradient(ellipse 80% 55% at 50% 15%, var(--canvas-alt) 0%, var(--canvas-base) 70%);
    min-height: 100vh;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- SECTION 3: WELCOME HERO (Phase 6 / spec Screen 1) --- */

/* Minimalist nav: logo + quick-jump category badges straight into the
   dashboard, pre-filtered — reuses the same buildDashboard() + sidebar
   active-state wiring the sidebar nav already uses. */
.hero-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    max-width: 1300px;
    width: 100%;
    margin: 0 auto;
    padding: 28px 48px;
}

.hero-nav-brand {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 1.3rem;
    color: var(--panel-dark);
    letter-spacing: -0.02em;
}

.hero-nav-brand .hero-brand-accent {
    color: var(--accent-primary);
}

.hero-quick-jump {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.quick-jump-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: white;
    border: var(--elevation-l2-border);
    box-shadow: var(--elevation-l2-shadow);
    padding: 8px 16px;
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 0.82rem;
    color: #334155;
    transition: all 0.2s ease;
}

.quick-jump-badge:hover {
    transform: translateY(-2px);
    box-shadow: var(--elevation-l3-shadow);
    border-color: var(--accent-primary);
}

.quick-jump-badge:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Two-column hero: copy + CTA on one side, tactile SVG illustration on
   the other. Wraps to a stacked single column on narrower viewports
   (see the 900px breakpoint). */
.hero-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 60px;
    flex-wrap: wrap;
    max-width: 1300px;
    width: 100%;
    margin: 0 auto;
    padding: 40px 48px 100px;
}

.hero-copy {
    flex: 1 1 420px;
    max-width: 560px;
}

.hero-copy h1 {
    font-family: var(--font-display);
    font-size: clamp(2.4rem, 5vw, 4.2rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.05;
    color: var(--panel-dark);
    margin-bottom: 24px;
}

.hero-highlight {
    background: linear-gradient(to right, var(--accent-primary), #8b5cf6);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hero-copy p {
    color: #475569;
    font-size: 1.15rem;
    line-height: 1.6;
    max-width: 480px;
    margin-bottom: 36px;
}

.primary-btn {
    background: var(--chrome-ink);
    color: white;
    border: none;
    padding: 16px 40px;
    border-radius: var(--radius-full);
    font-weight: 700;
    box-shadow: var(--elevation-l3-shadow);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.primary-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 16px 32px rgba(11, 17, 32, 0.25);
}

.primary-btn:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 3px;
}

/* --- Tactile 3D illustration (spec: stacked layers / tree / graph, each
   using its own category token so it visually previews the dashboard's
   color language) --- */
.hero-illustration {
    flex: 1 1 380px;
    max-width: 640px;
    display: flex;
    justify-content: center;
}

.hero-svg {
    width: 100%;
    height: auto;
    max-width: 560px;
    overflow: visible;
}

.hero-stack-layer {
    fill: var(--cat-stack);
    stroke: rgba(0, 0, 0, 0.06);
    stroke-width: 1;
}

.hero-tree-node {
    fill: var(--cat-tree);
    stroke: rgba(0, 0, 0, 0.06);
    stroke-width: 1;
}

.hero-tree-edge {
    stroke: #94a3b8;
    stroke-width: 2;
    opacity: 0.6;
}

.hero-graph-node {
    fill: var(--cat-graph);
    stroke: rgba(0, 0, 0, 0.06);
    stroke-width: 1;
}

.hero-graph-edge {
    stroke: #94a3b8;
    stroke-width: 2;
    opacity: 0.6;
}

/* Gentle independent float per motif — organic rather than synchronized */
@keyframes hero-float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.hero-float-1 {
    animation: hero-float 5s ease-in-out infinite;
}

.hero-float-2 {
    animation: hero-float 6s ease-in-out infinite;
    animation-delay: 0.4s;
}

.hero-float-3 {
    animation: hero-float 5.5s ease-in-out infinite;
    animation-delay: 0.8s;
}

/* --- SECTION 4: DASHBOARD LAYOUT (The Glow-Up) --- */
.main-dashboard-wrapper {
    display: grid;
    grid-template-columns: 280px 1fr;
    min-height: 100vh;
    background-color: var(--canvas-alt);
    /* Subtle warm depth layer for the whole app */
}

/* SIDEBAR: Deep plum-ink chrome for contrast
   Phase 2: migrated to the --chrome-ink token (renamed from
   --sidebar-navy during the color-identity pass) and given explicit L2
   elevation (§3) — the border-right divider color is intentionally left
   as-is since it's a directional divider, not a card border/shadow, and
   isn't covered by the elevation token set. */
.dashboard-sidebar {
    background-color: var(--chrome-ink);
    padding: 40px 25px;
    border-right: 1px solid var(--surface-dark-alt);
    color: white;
    font-family: var(--font-ui);
    box-shadow: var(--elevation-l2-shadow);
    position: relative;
    z-index: var(--elevation-l2-z);
}

.dashboard-sidebar h2 {
    color: #64748b;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 30px;
    padding-left: 10px;
}

.sidebar-nav li {
    padding: 14px 18px;
    border-radius: 12px;
    margin-bottom: 8px;
    font-weight: 600;
    color: #94a3b8;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.sidebar-nav li.active {
    background: var(--surface-dark-alt);
    color: var(--accent-primary);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.sidebar-nav li:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* --- Sidebar category dot badges (Phase 2 / spec §1.2) ---
   Color-coded per data-structure category, using the chrome-only
   pastel tokens. Purely decorative identifiers alongside the existing
   text label — no WCAG text-contrast implication. */
.sidebar-dot {
    width: 9px;
    height: 9px;
    border-radius: var(--radius-full);
    display: inline-block;
    flex-shrink: 0;
}

.sidebar-dot-array {
    background: var(--cat-array);
}

.sidebar-dot-stack {
    background: var(--cat-stack);
}

.sidebar-dot-queue {
    background: var(--cat-queue);
}

.sidebar-dot-tree {
    background: var(--cat-tree);
}

.sidebar-dot-graph {
    background: var(--cat-graph);
}

/* STAGE: This is the main white area */
.dashboard-stage {
    padding: 60px 80px;
    /* More breathing room on sides */
    background: var(--canvas-base);
    /* Slightly different from the wrapper for depth */
}

.dashboard-header h2 {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--panel-dark);
    margin-bottom: 40px;
    letter-spacing: -1px;
}

/* Sub-categories with the Blue Line */
.ds-category h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #334155;
    margin-bottom: 25px;
    padding-left: 15px;
    border-left: 4px solid var(--accent-primary);
    /* That specific blue line */
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-i-icon {
    color: var(--muted-slate);
    font-size: 0.9rem;
}

/* The Cards: Make them pop! */
.card-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    margin-bottom: 50px;
}

/* --- Bento card (Phase 3 / spec §1.2, §3, §5.2) ---
   Category-pastel background comes from a modifier class the card also
   carries (.algo-card-array etc, applied by JS to match the active
   sidebar category) — the base rule below supplies a neutral fallback
   in case that modifier is ever missing. Card is now a column layout
   (title row, then a tags row) rather than a single space-between row,
   to make room for the mode badge + complexity tag. */
.algo-card {
    background: var(--canvas-alt);
    border: var(--elevation-l2-border);
    padding: 24px 30px;
    border-radius: var(--radius-md);
    width: 320px;
    /* Slightly wider cards */
    display: flex;
    flex-direction: column;
    gap: 14px;
    cursor: pointer;
    box-shadow: var(--elevation-l2-shadow);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.algo-card.algo-card-array {
    background: var(--cat-array);
}

.algo-card.algo-card-stack {
    background: var(--cat-stack);
}

.algo-card.algo-card-queue {
    background: var(--cat-queue);
}

.algo-card.algo-card-tree {
    background: var(--cat-tree);
}

.algo-card.algo-card-graph {
    background: var(--cat-graph);
}

.algo-card:hover {
    transform: translateY(-5px);
    border-color: var(--accent-primary);
    box-shadow: var(--elevation-l3-shadow);
}

/* Card is a div[role="button"] now (see app.js comment for why), so the
   native button focus ring is gone — restore an explicit one. */
.algo-card:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 3px;
}

.algo-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.algo-card-title {
    font-weight: 700;
    color: var(--surface-dark-alt);
    font-size: 1.05rem;
}

.arrow {
    color: var(--muted-slate);
    font-size: 1.2rem;
    transition: 0.2s;
}

.algo-card:hover .arrow {
    color: var(--accent-primary);
    transform: translateX(3px);
}

/* --- Tags row: Mode Indicator + Complexity tag (spec §2.3, §5.2) --- */
.algo-card-tags {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Neutral/chrome styling on purpose — differentiated by icon + text
   ("▶ Algorithm" vs "⚡ Structure"), not by hue, so it never collides
   with the category or state color systems. */
.mode-badge {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    background: rgba(15, 23, 42, 0.06);
    color: #334155;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.complexity-tag {
    position: relative;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    background: rgba(15, 23, 42, 0.08);
    color: var(--panel-dark);
    cursor: help;
}

.complexity-tag:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

.complexity-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--chrome-ink);
    color: white;
    font-family: var(--font-ui);
    font-weight: 500;
    font-size: 0.75rem;
    line-height: 1.4;
    padding: 8px 12px;
    border-radius: 8px;
    box-shadow: var(--elevation-l3-shadow);
    width: max-content;
    max-width: 220px;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--motion-fast) ease, visibility 0s linear var(--motion-fast);
    transition-delay: 200ms;
    /* spec §5.2 — delayed fade-in avoids flicker on fast mouse passes */
    z-index: var(--elevation-l4-z);
    pointer-events: none;
}

.complexity-tag:hover .complexity-tooltip,
.complexity-tag:focus .complexity-tooltip,
.complexity-tag:focus-visible .complexity-tooltip {
    opacity: 1;
    visibility: visible;
}

/* --- Category filter pill tabs (spec: top category filter tabs) ---
   Only rendered by JS when a category has more than one sub-type to
   switch between (e.g. Array: Searching/Sorting). */
.filter-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 30px;
}

.filter-pill {
    background: white;
    border: var(--elevation-l2-border);
    color: #64748b;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 8px 20px;
    border-radius: var(--radius-full);
    box-shadow: var(--elevation-l2-shadow);
    transition: all 0.2s ease;
}

.filter-pill:hover {
    color: var(--surface-dark-alt);
    border-color: var(--accent-primary);
}

.filter-pill:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

.filter-pill.active {
    background: var(--chrome-ink);
    color: white;
    border-color: var(--chrome-ink);
}

/* --- SECTION 5: WORKSPACE FLOATING NAVBAR ---
   Phase 2: this is a genuinely "floating" surface (sits on top of the
   canvas, not flush like the sidebar), so it takes L3 elevation per §3
   — including the translucent glass-edge border, which replaces the
   previous opaque var(--surface-dark-alt) border now that it's treated as a floating
   dock rather than a flush panel. */
.modern-nav {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 16px;
    background: var(--chrome-ink);
    padding: 12px 30px;
    max-width: 1100px;
    margin: 20px auto;
    border-radius: var(--radius-full);
    position: relative;
    border: var(--elevation-l3-border);
    box-shadow: var(--elevation-l3-shadow);
    z-index: var(--elevation-l3-z);
}

.nav-brand {
    font-weight: 800;
    font-size: 1.3rem;
    flex: 1;
}

.text-white {
    color: white;
}

/* Same naming note as .btn-blue above — class name kept, color updated */
.text-blue {
    color: var(--accent-primary);
}

.nav-center {
    min-width: 0;
    /* lets the grid track shrink below the pill's content width, so
       text-overflow: ellipsis on the pill actually has room to kick in
       on narrow viewports instead of forcing the grid wider */
    display: flex;
    justify-content: center;
}

.current-algo-pill {
    color: var(--accent-primary);
    background: rgba(var(--accent-primary-rgb), 0.1);
    padding: 8px 24px;
    border-radius: var(--radius-full);
    font-weight: 700;
    font-size: 0.85rem;
    border: 1px solid rgba(var(--accent-primary-rgb), 0.2);
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.nav-spacer {
    flex: 1;
}

/* --- SECTION 6: WORKSPACE SPLIT-PANE SHELL (Phase 4 / spec §4.1) ---
   Zero-scroll only applies at desktop widths (≥1024px) — see the media
   query near the bottom of this section. Below that, the screen keeps
   normal document flow/scroll (full mobile stacking + tab-switcher
   refinement is a later pass; for now this is a safe non-broken fallback
   that already satisfies "not zero-scroll on mobile"). */
.workspace-split-pane {
    display: flex;
    flex-direction: row;
    gap: 20px;
    max-width: 1300px;
    width: calc(100% - 40px);
    margin: 0 auto;
    min-height: 0;
}

.workspace-left-stage {
    flex: 1 1 60%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.workspace-right-stage {
    flex: 1 1 40%;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

@media (min-width: 1024px) {
    #workspace-screen.active {
        display: flex;
        flex-direction: column;
        min-height: 100vh;
        overflow-y: auto;
        /* Not a rigid height:100vh + overflow:hidden anymore — that
           combination broke down on real-world short viewports (a ~640px
           laptop window, browser chrome eating space, etc): the floating
           dock was position:fixed, entirely independent of the flex
           layout, so no amount of padding-bottom reservation could stop
           it overlapping once the arena's minimum size + the dock's real
           size exceeded whatever vertical space was actually left. Now
           everything lives in normal flow (see .controls-wrapper below),
           so overlap is structurally impossible — a short viewport just
           scrolls the page instead, which is a far better fallback. */
    }

    .workspace-split-pane {
        flex: 1 1 420px;
        min-height: 420px;
        /* real floor so the arena/code panel never get crushed to
           nothing — if the viewport is too short to fit this plus the
           dock, the page scrolls rather than anything overlapping */
    }

    .workspace-left-stage {
        min-height: 0;
    }

    .workspace-right-stage {
        min-height: 0;
        overflow: hidden;
        /* the code panel inside scrolls internally — see .code-panel pre */
    }
}

/* --- Theory Drawer (spec §4.1) — true slide-in on desktop, full-screen
   bottom sheet on mobile. Triggered by the persistent edge peek-tab
   rather than a nav-embedded button, so its existence is discoverable
   without a click-to-discover step. --- */
.theory-peek-tab {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    background: var(--panel-dark);
    color: white;
    border: none;
    padding: 14px 10px;
    border-radius: var(--radius-md) 0 0 var(--radius-md);
    box-shadow: var(--elevation-l2-shadow);
    font-weight: 600;
    font-size: 0.78rem;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: var(--elevation-l2-z);
    transition: transform 0.2s ease;
}

.theory-peek-tab:hover {
    transform: translateY(-50%) translateX(-4px);
}

.theory-peek-tab:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

.theory-scrim {
    position: fixed;
    inset: 0;
    background: var(--elevation-l4-scrim);
    z-index: var(--elevation-l4-z);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--motion-base) ease, visibility 0s linear var(--motion-base);
}

.theory-scrim.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity var(--motion-base) ease, visibility 0s linear 0s;
}

/* Desktop: fixed to the right edge, full viewport height, slides in from
   off-screen. visibility (not display) is used so the transform
   transition can play, while still pulling the closed drawer out of the
   tab order for accessibility. */
.theory-drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: 440px;
    max-width: 100%;
    background: var(--panel-dark);
    padding: 30px;
    overflow-y: auto;
    box-shadow: var(--elevation-l4-shadow);
    z-index: var(--elevation-l4-z);
    transform: translateX(100%);
    visibility: hidden;
    transition: transform var(--motion-base) ease, visibility 0s linear var(--motion-base);
}

.theory-drawer.open {
    transform: translateX(0);
    visibility: visible;
    transition: transform var(--motion-base) ease, visibility 0s linear 0s;
}

.theory-close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(255, 255, 255, 0.08);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    font-size: 0.9rem;
    line-height: 1;
}

.theory-close-btn:hover {
    background: rgba(255, 255, 255, 0.16);
}

.theory-close-btn:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}

.theory-drawer h3 {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--accent-primary);
    letter-spacing: -0.5px;
}

/* Mobile (<768px): full-screen bottom sheet instead of a right-side rail —
   a 440px-wide rail would eat the entire phone viewport anyway. */
@media (max-width: 767px) {
    .theory-drawer {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 85vh;
        max-height: 85vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        transform: translateY(100%);
    }

    .theory-drawer.open {
        transform: translateY(0);
    }
}

#algo-description {
    font-size: 1.05rem;
    line-height: 1.8;
    /* Increased line-height for better readability */
    color: var(--muted-slate);
    /* Making it slightly lighter for dark panels */
}

.time-color,
.space-color {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.95rem;
}

.complexity-badges {
    display: flex;
    gap: 12px;
    margin-top: 15px;
}

.badge {
    background: rgba(247, 239, 233, 0.1);
    padding: 8px 20px;
    border-radius: 30px;
    font-weight: 600;
    font-size: 0.9rem;
}

/* --- Bottom Control Dock (spec §2, §3 L3) ---
   Deliberately NOT position:fixed at any width anymore (see the
   #workspace-screen.active comment above for why) — stays in normal
   flow so flexbox can never let it overlap a sibling. Styling alone
   (elevation shadow, glass blur, rounded-lg radius, dark surface)
   still reads as a floating dock even though it isn't literally
   floating over content. */
.controls-wrapper {
    display: flex;
    justify-content: center;
    margin: 20px auto;
}

.controls-panel {
    background: rgba(11, 17, 32, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 16px 24px;
    border-radius: var(--radius-lg);
    border: var(--elevation-l3-border);
    box-shadow: var(--elevation-l3-shadow);
    max-width: 1100px;
    width: calc(100% - 40px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.control-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
}

.dashboard-input {
    background: var(--canvas-base);
    border: 1px solid var(--muted-slate);
    padding: 10px 18px;
    border-radius: 8px;
    outline: none;
}

.dashboard-input:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
    border-color: var(--accent-primary);
}

.dashboard-btn {
    padding: 10px 24px;
    border-radius: 8px;
    border: none;
    font-weight: 700;
    color: white;
}

.dashboard-btn:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}

/* Class name kept as .btn-blue for compatibility with the many places
   app.js generates this class dynamically — renaming it would mean
   touching every one of those call sites for a cosmetic label change.
   The rendered color is the new terracotta accent, not blue. */
.btn-blue {
    background: var(--accent-primary);
}

.btn-red {
    background: #ef4444;
}

.btn-secondary {
    background: #64748b;
}

/* Clear inline-confirm (spec §2.2) — first click swaps the button into
   this state instead of clearing immediately; same button, no modal, so
   the zero-scroll layout never has to accommodate a popup. */
.dashboard-btn.confirm-pending {
    background: #b91c1c;
}

/* Timeline scrubber (spec §2.1) */
.scrubber-row {
    width: 100%;
    max-width: 480px;
    align-items: center;
    gap: 10px;
}

.scrubber-row .dashboard-btn {
    padding: 8px 14px;
    flex: 0 0 auto;
}

.scrubber-row #step-scrubber {
    flex: 1;
    width: auto;
    min-width: 100px;
}

.scrubber-row #step-scrubber:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* --- Session history strip (spec §2.2, optional) ---
   Structure-mode only; hidden/empty for Algorithm-mode workspaces. Sits
   just above the control dock in source order. */
.session-history {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 1100px;
    width: calc(100% - 40px);
    margin: 0 auto 12px auto;
    padding: 2px 4px;
}

.session-chip {
    flex: 0 0 auto;
    background: rgba(15, 23, 42, 0.06);
    color: #334155;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: var(--radius-full);
    white-space: nowrap;
}

.session-chip-latest {
    background: var(--chrome-ink);
    color: white;
}

.session-arrow {
    flex: 0 0 auto;
    color: #94a3b8;
    font-size: 0.8rem;
}

/* --- SECTION 7: VISUALIZER STAGE --- */
.visualizer-arena {
    background: var(--panel-dark);
    width: 100%;
    flex: 1 1 auto;
    min-height: 360px;
    border-radius: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* Center the array blocks vertically */
    position: relative;
    /* CRITICAL for the absolute pill */
    border: 1px solid var(--surface-dark-alt);
    overflow: hidden;
}

/* --- Live Telemetry HUD (spec: Comparisons / Swaps / Current Index) ---
   Algorithm-mode only — hidden by app.js for Structure-mode workspaces. */
.telemetry-hud {
    display: flex;
    gap: 12px;
    background: var(--panel-dark);
    border-radius: var(--radius-md);
    border: var(--elevation-l2-border);
    box-shadow: var(--elevation-l2-shadow);
    padding: 14px 20px;
    flex: 0 0 auto;
}

.telemetry-stat {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.telemetry-label {
    color: #64748b;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.telemetry-value {
    font-family: var(--font-mono);
    color: var(--accent-primary);
    font-size: 1.15rem;
    font-weight: 700;
}

.status-message {
    position: absolute !important;
    top: 30px !important;
    /* Fixed distance from the top edge */
    left: 50% !important;
    transform: translateX(-50%) !important;
    padding: 10px 24px;
    border-radius: 50px;
    font-size: 0.95rem;
    font-weight: 700;
    z-index: 15 !important;
    /* Above the visualizer content, but deliberately below the floating
       dock (L3/20) and Theory Drawer (L4/30) — a status pill shouldn't
       visually punch through a modal overlay if the drawer opens while
       a run is in progress. Was hardcoded to 1000 pre-dating the
       elevation token system; that value made it outrank every L1-L4
       surface, which is exactly the bug the elevation rule (§3) exists
       to prevent. */
    border: 1px solid transparent;
    white-space: nowrap;
    transition: all 0.3s ease;
    display: none;
    /* Default hidden */
}

.status-message.success {
    display: block !important;
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
    border-color: rgba(16, 185, 129, 0.4);
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.2);
}

.status-message.searching {
    display: block !important;
    background: rgba(var(--state-blue-rgb), 0.2);
    color: var(--state-blue);
    border-color: rgba(var(--state-blue-rgb), 0.4);
}

.status-message.error {
    display: block !important;
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.4);
}

#visualizer-container {
    display: flex !important;
    flex-direction: row !important;
    justify-content: center;
    align-items: flex-end;
    /* Keeps blocks sitting on the same horizontal line */
    gap: 18px;
    width: 100%;
    padding-bottom: 40px;
    /* Extra room for the index labels */
}

.block-wrapper {
    display: flex !important;
    flex-direction: column !important;
    /* Forces Index UNDER Number */
    align-items: center;
    gap: 12px;
    /* Breathing room between square and label */
}

.array-block {
    background: var(--surface-dark-alt);
    color: white;
    width: 65px;
    height: 65px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.3rem;
    border-radius: 12px;
    border: 2px solid #334155;
    position: relative;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* THE FIX: Style the index label so it pops */
.block-index {
    color: #64748b;
    /* Slate gray */
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 500;
    opacity: 1 !important;
    display: block !important;
}

/* --- STATES (Phase 4 / spec §1.3) ---
   Colors now come from the state tokens, and each state carries a
   non-color differentiator so it doesn't rely on hue alone: found/sorted
   gets a checkmark badge, comparing pulses + a dashed ring, current gets
   a static solid ring, dimmed desaturates as well as fading. */
.array-block.found {
    background: var(--state-emerald) !important;
    color: white !important;
    border-color: var(--state-emerald) !important;
    transform: translateY(-15px) scale(1.05);
    box-shadow: 0 0 30px rgba(16, 185, 129, 0.5);
}

.array-block.found::after,
.array-block.sorted::after {
    content: '✓';
    position: absolute;
    top: -8px;
    right: -8px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--state-emerald);
    color: white;
    font-size: 0.65rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 2px var(--panel-dark);
}

.array-block.current {
    background: var(--state-blue) !important;
    border-color: var(--state-blue) !important;
    transform: translateY(-10px);
    outline: 2px solid var(--state-blue);
    outline-offset: 3px;
    box-shadow: 0 0 16px rgba(var(--state-blue-rgb), 0.35);
}

/* Sorting-specific states */
.array-block.comparing {
    background: var(--state-amber) !important;
    border-color: var(--state-amber) !important;
    transform: translateY(-10px);
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.4);
    outline: 2px dashed var(--state-amber);
    outline-offset: 3px;
    animation: pulse-amber var(--motion-slow) ease-in-out infinite;
}

@keyframes pulse-amber {

    0%,
    100% {
        transform: translateY(-10px) scale(1);
    }

    50% {
        transform: translateY(-10px) scale(1.08);
    }
}

.array-block.sorted {
    background: var(--state-emerald) !important;
    border-color: var(--state-emerald) !important;
}

.array-block.dimmed {
    opacity: var(--state-dim-opacity);
    filter: grayscale(var(--state-dim-grayscale));
}

/* --- Step-scrub ghost trail (spec §5.1) ---
   Implemented as a fading ring (rather than a literal cloned overlay) on
   the block that just lost its comparing/current highlight — cheap, no
   extra DOM, same "doesn't feel like an instant cut" effect. */
.array-block.ghost-trail {
    transition: box-shadow var(--motion-base) ease-out;
}

.array-block.ghost-trail-amber {
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.3);
}

.array-block.ghost-trail-blue {
    box-shadow: 0 0 0 3px rgba(var(--state-blue-rgb), 0.3);
}

.array-block.ghost-trail.ghost-trail-fade {
    box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
}

/* Speed slider */
.speed-row {
    align-items: center;
    gap: 12px;
}

.speed-label {
    color: #94a3b8;
    font-weight: 600;
    font-size: 0.9rem;
}

input[type="range"] {
    accent-color: var(--accent-primary);
    width: 200px;
    cursor: pointer;
}

/* --- SECTION 8: CODE EDITOR --- */
.code-panel {
    background: var(--panel-dark);
    padding: 30px;
    border-radius: var(--radius-lg);
    border: var(--elevation-l2-border);
    box-shadow: var(--elevation-l2-shadow);
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex: 0 0 auto;
}

.tab-btn {
    background: rgba(247, 239, 233, 0.1);
    border: var(--elevation-l2-border);
    padding: 6px 16px;
    border-radius: 8px;
    font-weight: 600;
    color: var(--muted-slate);
}

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

.code-panel pre {
    background: #020617;
    padding: 25px;
    border-radius: 12px;
    overflow-x: auto;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    margin: 0;
}

code {
    font-family: var(--font-mono);
    color: var(--muted-slate);
    line-height: 1.6;
}

/* Step playback controls (Prev / Play-Pause / Next), now merged into
   .scrubber-row alongside the timeline slider */
.scrubber-row .dashboard-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}


/* Code panel: per-line rendering + active-line sync with the visualizer */
.code-line {
    display: block;
    padding: 1px 8px;
    border-radius: 4px;
    white-space: pre;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    border-left: 3px solid transparent;
}

.code-line.active-line {
    background: rgba(var(--accent-primary-rgb), 0.18);
    border-left: 3px solid var(--accent-primary);
}


/* ==========================================
   SECTION 9: RESPONSIVE / MOBILE
   ========================================== */

/* --- Tablet & below (~900px): collapse sidebar, tighten panel margins --- */
@media (max-width: 900px) {

    /* Hero: tighter padding; illustration naturally wraps below the copy
       via the existing flex-wrap on .hero-content, no extra rule needed
       for the stacking itself. */
    .hero-nav {
        padding: 20px 24px;
    }

    .hero-content {
        padding: 20px 24px 60px;
        gap: 36px;
        justify-content: center;
        text-align: center;
    }

    .hero-copy {
        max-width: 100%;
    }

    .hero-copy p {
        margin-left: auto;
        margin-right: auto;
    }

    .hero-illustration {
        max-width: 420px;
    }

    /* Dashboard: sidebar becomes a horizontal scrollable strip above content */
    .main-dashboard-wrapper {
        grid-template-columns: 1fr;
    }

    .dashboard-sidebar {
        padding: 20px;
        border-right: none;
        border-bottom: 1px solid var(--surface-dark-alt);
    }

    .dashboard-sidebar h2 {
        margin-bottom: 12px;
        padding-left: 4px;
    }

    .sidebar-nav {
        display: flex;
        gap: 10px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }

    .sidebar-nav li {
        white-space: nowrap;
        margin-bottom: 0;
    }

    .dashboard-stage {
        padding: 30px 20px;
    }

    .dashboard-header h2 {
        font-size: 1.7rem;
        margin-bottom: 24px;
    }

    /* Cards: stack full-width instead of a fixed 320px */
    .algo-card {
        width: 100%;
    }

    .card-grid {
        gap: 16px;
    }

    /* Filter pill tabs: same horizontal-scroll-strip pattern as the sidebar
       nav above, since a wrapped multi-row pill list eats vertical space
       that's already tight on mobile. */
    .filter-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
        margin-bottom: 20px;
    }

    .filter-pill {
        white-space: nowrap;
    }

    /* Workspace navbar: title pill drops to its own row instead of
       competing for horizontal space with the logo on narrow screens */
    .modern-nav {
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "brand spacer"
            "center center";
        row-gap: 10px;
        margin: 16px;
        padding: 12px 20px;
        border-radius: 24px;
    }

    .nav-brand {
        grid-area: brand;
    }

    .nav-spacer {
        grid-area: spacer;
    }

    .nav-center {
        grid-area: center;
        justify-content: center;
    }

    .current-algo-pill {
        max-width: 100%;
    }

    /* Split-pane: stack left/right stages instead of squeezing them
       side-by-side — the true 60/40 split is a desktop-only promise. */
    .workspace-split-pane {
        flex-direction: column;
    }

    .workspace-right-stage {
        max-height: 420px;
    }

    /* Panels: fixed 1100px max-width overflows a phone viewport — go fluid with side margins */
    .theory-drawer {
        padding: 20px;
    }

    .controls-panel,
    .code-panel,
    .visualizer-arena {
        padding: 20px;
    }

    .complexity-badges {
        flex-wrap: wrap;
    }

    .control-row {
        flex-wrap: wrap;
    }

    .dashboard-input {
        flex: 1 1 140px;
    }

    /* Visualizer: allow horizontal scroll instead of squeezing/overflowing blocks */
    #visualizer-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
        padding: 0 16px 40px;
    }

    .array-block {
        width: 52px;
        height: 52px;
        font-size: 1.05rem;
    }

    .status-message {
        top: 16px !important;
        font-size: 0.85rem;
        padding: 8px 18px;
    }
}

/* --- Phones (~480px): typography and control sizing --- */
@media (max-width: 480px) {
    .hero-nav-brand {
        font-size: 1.05rem;
    }

    .quick-jump-badge {
        font-size: 0.72rem;
        padding: 6px 12px;
    }

    .hero-copy p {
        font-size: 0.95rem;
    }

    .primary-btn {
        padding: 14px 32px;
    }

    .dashboard-header h2 {
        font-size: 1.4rem;
    }

    .ds-category h3 {
        font-size: 1rem;
    }

    /* Bento card tags: same shrink treatment as the rest of phone typography */
    .mode-badge,
    .complexity-tag {
        font-size: 0.65rem;
        padding: 3px 8px;
    }

    .complexity-tooltip {
        max-width: 160px;
        font-size: 0.7rem;
    }

    .filter-pill {
        font-size: 0.78rem;
        padding: 6px 14px;
    }

    .theory-drawer h3 {
        font-size: 1.3rem;
    }

    #algo-description {
        font-size: 0.95rem;
    }

    .current-algo-pill {
        font-size: 0.7rem;
        padding: 6px 14px;
        letter-spacing: 0.5px;
    }

    .nav-brand {
        font-size: 1.1rem;
    }

    .speed-label {
        font-size: 0.8rem;
    }

    input[type="range"] {
        width: 140px;
    }

    .theory-peek-tab {
        font-size: 0.68rem;
        padding: 10px 7px;
    }

    .telemetry-hud {
        padding: 10px 14px;
        gap: 6px;
    }

    .telemetry-value {
        font-size: 0.95rem;
    }

    .telemetry-label {
        font-size: 0.62rem;
    }

    .dashboard-btn {
        padding: 10px 16px;
        font-size: 0.85rem;
    }

    .tab-btn {
        padding: 6px 12px;
        font-size: 0.85rem;
    }

    .array-block {
        width: 46px;
        height: 46px;
        font-size: 0.95rem;
        border-radius: 10px;
    }

    .block-index {
        font-size: 0.75rem;
    }

    .code-panel pre {
        padding: 16px;
    }

    code {
        font-size: 0.8rem;
    }
}


/* ==========================================
   SECTION 10: STACK & QUEUE (live data structures)
   ========================================== */

/* --- Stack: vertical layout, newest element visually on top --- */
#visualizer-container.stack-mode {
    flex-direction: column-reverse !important;
    align-items: center;
    justify-content: flex-start;
    gap: 14px;
    padding: 24px 0;
    overflow-y: auto;
    max-height: 420px;
}

.stack-block-wrapper {
    display: flex;
    align-items: center;
    gap: 14px;
}

.stack-side-label {
    color: var(--state-blue);
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.85rem;
    white-space: nowrap;
}

/* --- Queue: horizontal layout, front on the left --- */
#visualizer-container.queue-mode {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 18px;
    padding-bottom: 0;
}

.queue-block-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.queue-label-front,
.queue-label-rear,
.queue-label-spacer {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.78rem;
    white-space: nowrap;
    height: 1em;
}

.queue-label-front {
    color: var(--state-emerald);
}

.queue-label-rear {
    color: var(--state-amber);
}

.queue-label-front.queue-label-rear {
    color: var(--state-blue);
}

.queue-label-spacer {
    color: transparent;
}

/* --- Shared: empty-state message + pop/dequeue exit animation --- */
.empty-structure-msg {
    color: #64748b;
    font-family: var(--font-mono);
    font-size: 1rem;
    text-align: center;
    padding: 20px;
}

.array-block.popping,
.array-block.dequeuing {
    opacity: 0;
    transform: scale(0.7) translateY(-10px);
}

/* --- Mobile: cap stack scroll height a bit tighter, tighten queue gaps --- */
@media (max-width: 900px) {
    #visualizer-container.stack-mode {
        max-height: 320px;
        gap: 10px;
    }

    #visualizer-container.queue-mode {
        gap: 10px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start;
        padding-left: 16px;
        padding-right: 16px;
    }

    .stack-side-label {
        font-size: 0.75rem;
    }

    .queue-label-front,
    .queue-label-rear,
    .queue-label-spacer {
        font-size: 0.68rem;
    }
}

@media (max-width: 480px) {
    .empty-structure-msg {
        font-size: 0.85rem;
        padding: 14px;
    }
}


/* ==========================================
   SECTION 11: TREE (SVG-based node/edge structure)
   ========================================== */

#visualizer-container.tree-mode {
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 20px 10px;
    overflow-x: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-height: 480px;
}

.tree-svg {
    width: 100%;
    max-width: 640px;
    height: auto;
    /* SVG scales via viewBox, so it stays proportional at every screen size
       without needing separate mobile breakpoints for node/text sizing. */
}

.tree-edge {
    stroke: #334155;
    stroke-width: 2;
}

.tree-node circle {
    fill: var(--surface-dark-alt);
    stroke: var(--accent-primary);
    stroke-width: 2;
    transition: fill 0.3s ease, stroke 0.3s ease;
}

.tree-node text {
    fill: white;
    font-family: var(--font-ui);
    font-weight: 700;
    font-size: 15px;
    pointer-events: none;
}

.tree-node.comparing circle {
    fill: var(--state-amber);
    stroke: var(--state-amber);
}

.tree-node.found circle {
    fill: var(--state-emerald);
    stroke: var(--state-emerald);
}

@media (max-width: 900px) {
    #visualizer-container.tree-mode {
        max-height: 360px;
        padding: 14px 6px;
    }
}


/* ==========================================
   SECTION 12: GRAPH (SVG-based node/edge structure, circular layout)
   ========================================== */

#visualizer-container.graph-mode {
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 20px 10px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    max-height: 480px;
}

.graph-svg {
    width: 100%;
    max-width: 560px;
    height: auto;
    /* Scales via viewBox, same as tree-svg — no separate mobile sizing needed. */
}

.graph-edge {
    stroke: #334155;
    stroke-width: 2;
}

.graph-node circle {
    fill: var(--surface-dark-alt);
    stroke: #8b5cf6;
    stroke-width: 2;
    transition: fill 0.3s ease, stroke 0.3s ease;
}

.graph-node text {
    fill: white;
    font-family: var(--font-ui);
    font-weight: 700;
    font-size: 15px;
    pointer-events: none;
}

.graph-node.comparing circle {
    fill: var(--state-amber);
    stroke: var(--state-amber);
}

.graph-node.found circle {
    fill: var(--state-emerald);
    stroke: var(--state-emerald);
}

@media (max-width: 900px) {
    #visualizer-container.graph-mode {
        max-height: 360px;
        padding: 14px 6px;
    }
}


/* ==========================================
   SECTION 13: VISUALIZER LEGEND
   ========================================== */
/* Explains the color language used across every workspace (search, sort,
   stack/queue, tree, graph) so a first-time visitor doesn't have to guess
   what amber vs. green vs. dimmed means. */

.visualizer-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px 20px;
    max-width: 1100px;
    margin: 0 auto 16px auto;
    padding: 0 16px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #64748b;
    white-space: nowrap;
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.legend-dot-current {
    background: var(--state-blue);
    box-shadow: 0 0 6px rgba(var(--state-blue-rgb), 0.6);
}

.legend-dot-comparing {
    background: #f59e0b;
    box-shadow: 0 0 6px rgba(245, 158, 11, 0.6);
}

.legend-dot-found {
    background: #10b981;
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
}

.legend-dot-dimmed {
    background: #475569;
    opacity: 0.6;
}

@media (max-width: 480px) {
    .visualizer-legend {
        gap: 6px 14px;
        padding: 0 12px;
    }

    .legend-item {
        font-size: 0.7rem;
        gap: 5px;
    }

    .legend-dot {
        width: 10px;
        height: 10px;
    }
}