/* ============================================================
   Maze Solver — Neo-Brutalist UI
   Zero radius · Syne + Plus Jakarta Sans · Warm Paper & Ink
   ============================================================ */

/* ---- Theme Tokens ---- */
:root {
    /* Brutalist token */
    --r: 0px;

    /* Light Theme (default) */
    --bg:        #F2EFE8;
    --surface-1: #E8E4DB;
    --surface-2: #DDD9CF;
    --surface-3: #D2CEC4;

    --text-1: #0F0E0D;
    --text-2: #5A5650;
    --text-3: #9A958E;

    --border-1: #C8C3B8;
    --border-2: #B0ABA0;

    /* Accent */
    --accent-primary: #E8380D;

    /* Maze rendering */
    --maze-wall:    #0F0E0D;
    --maze-path:    #F2EFE8;
    --maze-visited: #D97706;
    --maze-optimal: #1A7A4A;
    --maze-start:   #1A7A4A;
    --maze-end:     #C0321A;

    /* Status */
    --clr-go:   #1A7A4A;
    --clr-stop: #C0321A;
    --clr-path: #D97706;

    /* Shadows */
    --shadow-btn: 4px 4px 0 rgba(15,14,13,0.25);
    --shadow-card: 3px 3px 0 rgba(15,14,13,0.12);

    /* Nav BG */
    --nav-bg: #0F0E0D;
    --nav-text: #F2EFE8;
    --nav-text-muted: #9A958E;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg:        #131210;
    --surface-1: #1C1A17;
    --surface-2: #252320;
    --surface-3: #2E2C28;

    --text-1: #F0ECE4;
    --text-2: #8A8680;
    --text-3: #504D49;

    --border-1: #3D3A35;
    --border-2: #504D49;

    --accent-primary: #FF5533;

    --maze-wall:    #3D3A35;
    --maze-path:    #131210;
    --maze-visited: #FBBF24;
    --maze-optimal: #22C55E;
    --maze-start:   #22C55E;
    --maze-end:     #EF4444;

    --clr-go:   #22C55E;
    --clr-stop: #EF4444;
    --clr-path: #FBBF24;

    --shadow-btn: 4px 4px 0 rgba(0,0,0,0.5);
    --shadow-card: 3px 3px 0 rgba(0,0,0,0.35);

    --nav-bg: #0F0E0D;
    --nav-text: #F0ECE4;
    --nav-text-muted: #504D49;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text-1);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    transition: background 0.3s, color 0.3s;
}

/* ---- Navigation Bar ---- */
.main-nav {
    display: flex;
    align-items: center;
    height: 52px;
    padding: 0 20px;
    background: var(--nav-bg);
    border-bottom: 2px solid var(--border-2);
    flex-shrink: 0;
    gap: 24px;
    position: relative;
    overflow: hidden;
    color: var(--nav-text);
}

/* SVG Noise texture overlay on the navbar */
.nav-noise {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.06;
    z-index: 0;
}

.main-nav > * {
    position: relative;
    z-index: 1;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}
.nav-brand .brand-icon {
    width: 30px; height: 30px;
    display: grid; place-items: center;
    background: var(--accent-primary);
    border-radius: var(--r);
    color: #fff;
    flex-shrink: 0;
    font-weight: 800;
}
.nav-title {
    font-family: 'Syne', sans-serif;
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: -0.3px;
    color: var(--nav-text);
}

/* Pulse Dot */
.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-primary);
    display: inline-block;
    margin-left: 2px;
    animation: pulse-dot 3s ease-in-out infinite;
}
@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.7); }
}

.nav-tabs {
    display: flex; gap: 0;
}
.nav-tab {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 18px; font-size: 0.82rem; font-weight: 600;
    font-family: 'Plus Jakarta Sans', sans-serif;
    border: none; border-radius: var(--r);
    cursor: pointer; transition: all 0.15s ease;
    background: transparent; color: var(--nav-text-muted);
    text-transform: uppercase; letter-spacing: 0.5px;
    position: relative;
    overflow: hidden;
}
.nav-tab::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 3px;
    background: var(--accent-primary);
    transform: scaleX(0);
    transition: transform 0.25s ease;
    transform-origin: left;
}
.nav-tab:hover { color: var(--nav-text); }
.nav-tab:hover::after { transform: scaleX(1); }
.nav-tab.active {
    color: var(--nav-text);
    background: rgba(255,255,255,0.06);
}
.nav-tab.active::after { transform: scaleX(1); }
.nav-tab svg { flex-shrink: 0; }
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* Theme Toggle Button */
.theme-toggle {
    width: 36px; height: 36px;
    display: grid; place-items: center;
    background: transparent;
    border: 2px solid rgba(255,255,255,0.15);
    border-radius: var(--r);
    color: var(--nav-text);
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 1rem;
}
.theme-toggle:hover {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.3);
}

/* ---- Tab Panels ---- */
.tab-panel {
    display: none;
    height: calc(100vh - 52px);
    overflow: hidden;
}
.tab-panel.active { display: flex; flex-direction: column; }

/* ---- App Shell ---- */
.app-shell {
    display: flex;
    height: 100%;
    flex: 1;
    gap: 0;
}

.workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px 18px;
    min-width: 0;
}

/* ---- Top Bar ---- */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand h1 {
    font-family: 'Syne', sans-serif;
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: -0.3px;
    line-height: 1.2;
}

.subtitle {
    font-size: 0.8rem;
    color: var(--text-2);
    font-weight: 400;
}

.top-actions {
    display: flex;
    gap: 8px;
}

/* ---- Buttons (Brutalist) ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 0.82rem;
    font-weight: 700;
    font-family: 'Plus Jakarta Sans', sans-serif;
    border: 2px solid var(--text-1);
    border-radius: var(--r);
    cursor: pointer;
    transition: all 0.12s ease;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    position: relative;
}
.btn:active { transform: translate(2px, 2px); box-shadow: none !important; }

.btn-outline {
    background: var(--surface-1);
    color: var(--text-1);
    border: 2px solid var(--border-2);
    box-shadow: var(--shadow-btn);
}
.btn-outline:hover {
    background: var(--surface-2);
    transform: translate(-1px, -1px);
    box-shadow: 5px 5px 0 rgba(15,14,13,0.2);
}

.btn-play {
    background: var(--clr-go);
    color: #fff;
    border: 2px solid var(--text-1);
    box-shadow: var(--shadow-btn);
}
.btn-play:hover {
    transform: translate(-1px, -1px);
    box-shadow: 5px 5px 0 rgba(15,14,13,0.3);
    filter: brightness(1.1);
}

.btn-pause {
    background: var(--surface-2);
    color: var(--text-1);
    border: 2px solid var(--border-2);
    box-shadow: var(--shadow-btn);
}
.btn-pause:hover {
    background: var(--surface-3);
    transform: translate(-1px, -1px);
    box-shadow: 5px 5px 0 rgba(15,14,13,0.2);
}

/* Solve / CTA button */
.btn-solve {
    background: var(--accent-primary);
    color: #fff;
    border: 2px solid var(--text-1);
    box-shadow: var(--shadow-btn);
    font-family: 'Syne', sans-serif;
    font-weight: 700;
    font-size: 0.9rem;
}
.btn-solve:hover {
    transform: translate(-1px, -1px);
    box-shadow: 5px 5px 0 rgba(15,14,13,0.35);
    filter: brightness(1.1);
}

/* ---- Grid ---- */
.grid-container {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
    min-height: 0;
}

/* ---- Algorithm Cards (Brutalist) ---- */
.algo-card {
    background: var(--surface-1);
    border: 2px solid var(--border-1);
    border-radius: var(--r);
    padding: 12px 14px 14px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    cursor: pointer;
    transition: transform 0.12s, box-shadow 0.12s, border-color 0.15s;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-card);
}
.algo-card:hover {
    border-color: var(--accent-primary);
    transform: translate(-2px, -2px);
    box-shadow: 5px 5px 0 rgba(15,14,13,0.2);
}

.algo-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    gap: 8px;
}

.algo-title {
    font-family: 'Syne', sans-serif;
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: -0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.algo-badge {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 0.68rem;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: var(--r);
    white-space: nowrap;
    flex-shrink: 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px solid;
}
.algo-badge.waiting {
    background: transparent;
    color: var(--text-3);
    border-color: var(--border-1);
}
.algo-badge.running {
    background: var(--clr-path);
    color: var(--text-1);
    border-color: var(--text-1);
    animation: pulse-badge 1.5s ease-in-out infinite;
}
.algo-badge.finished {
    background: var(--clr-go);
    color: #fff;
    border-color: var(--text-1);
}
.algo-badge.paused {
    background: var(--clr-stop);
    color: #fff;
    border-color: var(--text-1);
}

@keyframes pulse-badge {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.algo-time {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-3);
    margin-bottom: 8px;
}

/* Canvas */
.canvas-wrapper {
    flex: 1;
    border-radius: var(--r);
    overflow: hidden;
    background: var(--maze-path);
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border: 2px solid var(--border-1);
}

canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* ---- Bottom Bar ---- */
.bottom-bar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface-1);
    border: 2px solid var(--border-1);
    border-radius: var(--r);
    padding: 10px 18px;
    box-shadow: var(--shadow-card);
}

.speed-group {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-2);
    font-size: 0.82rem;
    font-weight: 500;
}
.speed-group svg { color: var(--text-3); flex-shrink: 0; }

.speed-group input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 160px;
    height: 4px;
    border-radius: 0;
    background: var(--border-1);
    outline: none;
    cursor: pointer;
}
.speed-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 0;
    background: var(--accent-primary);
    border: 2px solid var(--text-1);
    cursor: pointer;
    transition: transform 0.1s;
}
.speed-group input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}
.speed-group input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 0;
    background: var(--accent-primary);
    border: 2px solid var(--text-1);
    cursor: pointer;
}

.speed-val {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-3);
    min-width: 24px;
    text-align: right;
}

.action-group {
    display: flex;
    gap: 8px;
}

/* ---- Sidebar ---- */
.sidebar {
    width: 300px;
    flex-shrink: 0;
    background: var(--surface-1);
    border-left: 2px solid var(--border-1);
    display: flex;
    flex-direction: column;
    padding: 20px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 2px;
}

.sidebar-header h2 {
    font-family: 'Syne', sans-serif;
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: -0.3px;
}

.sidebar-badge {
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 3px 8px;
    border-radius: var(--r);
    background: var(--clr-go);
    color: #fff;
    border: 1px solid var(--text-1);
}

.sidebar-sub {
    font-size: 0.78rem;
    color: var(--text-3);
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 2px solid var(--border-1);
}

.leaderboard-scroll {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-2) transparent;
}

.leaderboard-empty {
    text-align: center;
    color: var(--text-3);
    font-size: 0.85rem;
    padding: 30px 10px;
    line-height: 1.6;
}

/* Leaderboard Items */
.lb-item {
    padding: 12px 14px;
    border-radius: var(--r);
    background: var(--surface-2);
    margin-bottom: 8px;
    border: 2px solid var(--border-1);
    transition: border-color 0.2s, transform 0.12s;
}
.lb-item:last-child { margin-bottom: 0; }
.lb-item:hover {
    transform: translate(-1px, -1px);
    box-shadow: 3px 3px 0 rgba(15,14,13,0.15);
}

.lb-item.gold {
    border-color: var(--clr-path);
    background: var(--surface-2);
    border-left: 4px solid var(--clr-path);
}

.lb-item.optimal {
    border-left: 4px solid var(--clr-go);
}

.lb-rank {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px;
}

.lb-pos {
    font-family: 'Syne', sans-serif;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-3);
    width: 18px;
}

.lb-name {
    font-size: 0.88rem;
    font-weight: 700;
    letter-spacing: -0.1px;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lb-tags {
    display: flex;
    gap: 4px;
}

.lb-tag {
    font-size: 0.6rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding: 2px 6px;
    border-radius: var(--r);
    border: 1px solid;
}
.lb-tag.fastest {
    background: var(--clr-path);
    color: var(--text-1);
    border-color: var(--text-1);
}
.lb-tag.shortest {
    background: var(--clr-go);
    color: #fff;
    border-color: var(--text-1);
}

.lb-stats {
    display: flex;
    gap: 14px;
    font-size: 0.75rem;
    color: var(--text-3);
    margin-left: 26px;
}
.lb-stats strong {
    color: var(--text-2);
    font-weight: 700;
}

/* Sidebar footer */
.sidebar-footer {
    flex-shrink: 0;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 2px solid var(--border-1);
}

.legend {
    display: flex;
    gap: 16px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    color: var(--text-3);
    font-weight: 500;
}

.swatch {
    width: 10px;
    height: 10px;
    border-radius: 0;
    flex-shrink: 0;
    border: 1px solid var(--text-1);
}

/* ---- Focus Mode ---- */
.hidden { display: none !important; }

.focus-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin-bottom: 12px;
    animation: focus-in 0.2s ease-out;
}

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

.focus-top {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.focus-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.focus-info h2 {
    font-family: 'Syne', sans-serif;
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.3px;
}

.focus-stats {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.focus-stat {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-2);
    padding: 5px 12px;
    background: var(--surface-2);
    border-radius: var(--r);
    border: 2px solid var(--border-1);
}

.focus-canvas-wrap {
    flex: 1;
    min-height: 0;
    border-radius: var(--r);
    overflow: hidden;
    background: var(--maze-path);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--border-1);
}

.focus-canvas-wrap canvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.focus-controls {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface-1);
    border: 2px solid var(--border-1);
    border-radius: var(--r);
    padding: 10px 18px;
    margin-top: 12px;
    box-shadow: var(--shadow-card);
}

/* ============================================================
   Map / Real-World Navigation Tab
   ============================================================ */
.map-shell {
    display: flex;
    height: 100%;
    flex: 1;
}

.map-container {
    flex: 1;
    min-width: 0;
}

/* Override Leaflet's default font */
.leaflet-container { font-family: 'Plus Jakarta Sans', sans-serif !important; }

.map-sidebar {
    width: 340px;
    flex-shrink: 0;
    background: var(--surface-1);
    border-left: 2px solid var(--border-1);
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
}

.map-sidebar h2 {
    font-family: 'Syne', sans-serif;
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: -0.3px;
}

.map-sidebar-sub {
    font-size: 0.82rem;
    color: var(--text-3);
    line-height: 1.5;
    padding-bottom: 14px;
    border-bottom: 2px solid var(--border-1);
}

.map-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-label {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ui-select {
    padding: 8px 12px;
    border-radius: var(--r);
    border: 2px solid var(--border-2);
    background: var(--surface-2);
    color: var(--text-1);
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 0.85rem;
    font-weight: 500;
    outline: none;
    cursor: pointer;
    transition: border-color 0.15s;
}
.ui-select:focus { border-color: var(--accent-primary); }

.coord-display {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-3);
    padding: 8px 12px;
    background: var(--surface-2);
    border-radius: var(--r);
    border: 2px solid var(--border-1);
}
.coord-display.set { color: var(--text-1); }

.map-btn-route {
    width: 100%;
    justify-content: center;
    padding: 12px;
    font-size: 0.9rem;
    margin-top: 4px;
}
.map-btn-route:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

.map-btn-clear {
    width: 100%;
    justify-content: center;
    padding: 10px;
    font-size: 0.85rem;
}

/* Route Results */
.route-results {
    background: var(--surface-2);
    border: 2px solid var(--border-1);
    border-radius: var(--r);
    padding: 16px;
}
.route-results h3 {
    font-family: 'Syne', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--clr-go);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.result-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.result-label {
    font-size: 0.8rem;
    color: var(--text-3);
    font-weight: 500;
}

.result-value {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-1);
}

.map-instructions {
    margin-top: auto;
    background: var(--surface-2);
    border-radius: var(--r);
    padding: 16px;
    border: 2px solid var(--border-1);
}
.map-instructions h3 {
    font-family: 'Syne', sans-serif;
    font-size: 0.82rem;
    font-weight: 700;
    margin-bottom: 8px;
}
.map-instructions p {
    font-size: 0.78rem;
    color: var(--text-3);
    line-height: 1.55;
    margin-bottom: 6px;
}
.map-instructions p:last-child { margin-bottom: 0; }

/* Hide LRM's built-in itinerary panel */
.leaflet-routing-container { display: none !important; }

/* ---- Hamburger Button (hidden on desktop) ---- */
.nav-hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 36px;
    height: 36px;
    padding: 6px;
    background: transparent;
    border: 2px solid rgba(255,255,255,0.15);
    border-radius: var(--r);
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
}
.nav-hamburger span {
    display: block;
    width: 100%;
    height: 2px;
    background: var(--nav-text);
    transition: all 0.25s ease;
    transform-origin: center;
}
.nav-hamburger:hover {
    border-color: rgba(255,255,255,0.3);
    background: rgba(255,255,255,0.06);
}
.nav-hamburger.active span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
}
.nav-hamburger.active span:nth-child(2) {
    opacity: 0;
}
.nav-hamburger.active span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
}

/* ---- Responsive: Tablet ≤ 1100px ---- */
@media (max-width: 1100px) {
    .sidebar { width: 260px; padding: 16px; }
    .map-sidebar { width: 280px; padding: 16px; }
}

/* ---- Responsive: Small Tablet / Landscape Phone ≤ 768px ---- */
@media (max-width: 768px) {
    body {
        height: auto;
        min-height: 100vh;
        overflow: auto;
        overflow-x: hidden;
    }

    /* -- Nav -- */
    .main-nav {
        flex-wrap: wrap;
        height: auto;
        min-height: 52px;
        padding: 10px 14px;
        gap: 10px;
    }
    .nav-hamburger { display: flex; }
    .nav-right { margin-left: auto; order: 0; }
    .nav-tabs {
        display: none;
        flex-direction: column;
        width: 100%;
        order: 10;
        gap: 2px;
        padding-top: 8px;
        border-top: 1px solid rgba(255,255,255,0.1);
    }
    .nav-tabs.open { display: flex; }
    .nav-tab {
        padding: 12px 14px;
        width: 100%;
        justify-content: flex-start;
    }
    .nav-tab::after { display: none; }
    .nav-tab.active {
        background: rgba(255,255,255,0.1);
        border-left: 3px solid var(--accent-primary);
    }

    /* -- Tab Panels -- */
    .tab-panel {
        height: auto;
        min-height: calc(100vh - 52px);
        overflow: visible;
    }

    /* -- App Shell: Stack vertically -- */
    .app-shell {
        flex-direction: column;
        height: auto;
        min-height: 0;
    }

    .workspace {
        padding: 12px;
        min-height: 0;
        flex: none;
    }

    /* -- Top Bar -- */
    .top-bar {
        flex-wrap: wrap;
        gap: 10px;
    }
    .brand h1 { font-size: 1.15rem; }
    .subtitle { font-size: 0.72rem; }

    /* -- Grid: 2 columns -- */
    .grid-container {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-rows: repeat(3, minmax(180px, 1fr));
        gap: 8px;
        min-height: 560px;
        margin-bottom: 10px;
    }

    /* -- Bottom Bar -- */
    .bottom-bar {
        flex-wrap: wrap;
        gap: 10px;
        padding: 10px 14px;
    }
    .speed-group input[type="range"] { width: 100px; }

    /* -- Sidebar: Horizontal at bottom -- */
    .sidebar {
        width: 100%;
        flex-shrink: 0;
        border-left: none;
        border-top: 2px solid var(--border-1);
        padding: 16px 12px;
        max-height: 300px;
        overflow-y: auto;
    }
    .leaderboard-scroll { max-height: 180px; }
    .legend { flex-wrap: wrap; gap: 10px; }

    /* -- Focus Mode -- */
    .focus-top {
        flex-wrap: wrap;
        gap: 10px;
    }
    .focus-stats {
        margin-left: 0;
        flex-wrap: wrap;
        gap: 8px;
    }
    .focus-canvas-wrap {
        min-height: 250px;
    }
    .focus-controls {
        flex-wrap: wrap;
        gap: 10px;
        padding: 10px 12px;
    }
    .focus-controls .speed-group { flex: 1 1 100%; }
    .focus-controls .action-group { flex: 1 1 100%; justify-content: flex-end; }

    /* -- Map Shell: Stack vertically -- */
    .map-shell {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - 52px);
    }
    .map-container {
        min-height: 350px;
        height: 50vh;
        flex: none;
    }
    .map-sidebar {
        width: 100%;
        border-left: none;
        border-top: 2px solid var(--border-1);
        padding: 16px 12px;
        flex: none;
    }
}

/* ---- Responsive: Portrait Phone ≤ 480px ---- */
@media (max-width: 480px) {
    .main-nav { padding: 8px 10px; }
    .nav-title { font-size: 0.95rem; }
    .nav-brand .brand-icon { width: 26px; height: 26px; }
    .nav-brand .brand-icon svg { width: 14px; height: 14px; }

    .workspace { padding: 8px; }

    /* -- Top Bar -- */
    .top-bar { margin-bottom: 10px; }
    .brand h1 { font-size: 1rem; }
    .subtitle { font-size: 0.68rem; }
    .btn { padding: 6px 10px; font-size: 0.75rem; }

    /* -- Grid: 1 column -- */
    .grid-container {
        grid-template-columns: 1fr;
        grid-template-rows: repeat(6, minmax(180px, 1fr));
        gap: 8px;
        min-height: 0;
    }

    .algo-card { padding: 8px 10px 10px; }
    .algo-title { font-size: 0.82rem; }
    .algo-badge { font-size: 0.6rem; padding: 2px 6px; }
    .algo-time { font-size: 0.68rem; }

    /* -- Bottom Bar -- */
    .bottom-bar { padding: 8px 10px; }
    .speed-group { font-size: 0.75rem; gap: 6px; }
    .speed-group input[type="range"] { width: 80px; }
    .action-group { gap: 6px; }

    /* -- Sidebar -- */
    .sidebar { padding: 12px 10px; max-height: 260px; }
    .sidebar-header h2 { font-size: 1rem; }
    .sidebar-sub { font-size: 0.72rem; }
    .lb-name { font-size: 0.8rem; }
    .lb-stats { font-size: 0.7rem; gap: 10px; margin-left: 20px; }

    /* -- Focus Mode -- */
    .focus-top { gap: 8px; }
    .focus-info h2 { font-size: 1rem; }
    .focus-stat { font-size: 0.7rem; padding: 4px 8px; }
    .focus-canvas-wrap { min-height: 200px; }
    .focus-controls { padding: 8px 10px; }

    /* -- Map -- */
    .map-container { height: 40vh; min-height: 280px; }
    .map-sidebar { padding: 14px 10px; gap: 12px; }
    .map-sidebar h2 { font-size: 1rem; }
    .map-sidebar-sub { font-size: 0.75rem; }
    .map-btn-route { padding: 10px; font-size: 0.82rem; }
    .map-btn-clear { padding: 8px; font-size: 0.78rem; }
    .result-label { font-size: 0.72rem; }
    .result-value { font-size: 0.78rem; }
    .map-instructions h3 { font-size: 0.75rem; }
    .map-instructions p { font-size: 0.72rem; }
}

/* ============================================================
   Micro-Animations — Grid Cell Pops
   ============================================================ */

/* Visited cell pop animation (used by JS when rendering) */
@keyframes vCell {
    0%   { transform: scale(0.5); opacity: 0.6; }
    70%  { transform: scale(1.08); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* Final path cell pop animation */
@keyframes pathCell {
    0%   { transform: scale(0.8); }
    50%  { transform: scale(1.3); filter: drop-shadow(0 0 6px var(--clr-go)); }
    100% { transform: scale(1); filter: none; }
}
