:root {
    --bg-color: #0f172a;
    --panel-bg: rgba(30, 41, 59, 0.7);
    --panel-border: rgba(255, 255, 255, 0.1);
    --panel-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --secondary: #475569;
    --secondary-hover: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-on-primary: #ffffff;
    --accent: #f43f5e;
    --canvas-bg: rgba(15, 23, 42, 0.4);
    --app-bg: radial-gradient(circle at top right, #1e1b4b, #0f172a);
    --header-gradient: linear-gradient(to right, #60a5fa, #a78bfa);
    --subtle-hover: rgba(255, 255, 255, 0.05);
    --active-shadow: 0 4px 14px rgba(59, 130, 246, 0.39);
    --overlay-bg: rgba(15, 23, 42, 0.7);
    --surface-strong: rgba(15, 23, 42, 0.85);
    --surface-soft: rgba(15, 23, 42, 0.5);
    --surface-muted: rgba(0, 0, 0, 0.3);
    --success: #34d399;
    --link-accent: #60a5fa;
    --chip-bg: rgba(52, 211, 153, 0.12);
    color-scheme: dark;
}

:root[data-theme="light"] {
    --bg-color: #eef5ff;
    --panel-bg: rgba(255, 255, 255, 0.78);
    --panel-border: rgba(37, 99, 235, 0.15);
    --panel-shadow: 0 14px 34px -18px rgba(37, 99, 235, 0.32);
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #dbeafe;
    --secondary-hover: #bfdbfe;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-on-primary: #ffffff;
    --accent: #e11d48;
    --canvas-bg: rgba(255, 255, 255, 0.52);
    --app-bg:
        radial-gradient(circle at top right, rgba(147, 197, 253, 0.6), transparent 34rem),
        linear-gradient(135deg, #f8fbff 0%, #eaf4ff 48%, #f7fbff 100%);
    --header-gradient: linear-gradient(to right, #1d4ed8, #0f766e);
    --subtle-hover: rgba(37, 99, 235, 0.08);
    --active-shadow: 0 6px 16px rgba(37, 99, 235, 0.2);
    --overlay-bg: rgba(248, 250, 252, 0.76);
    --surface-strong: rgba(255, 255, 255, 0.88);
    --surface-soft: rgba(255, 255, 255, 0.62);
    --surface-muted: rgba(219, 234, 254, 0.62);
    --success: #059669;
    --link-accent: #2563eb;
    --chip-bg: rgba(5, 150, 105, 0.12);
    color-scheme: light;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--app-bg);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow-x: hidden;
    transition: background 0.25s ease, color 0.25s ease;
}

.app-container {
    width: 100%;
    max-width: 1000px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    height: 95vh;
}

.page {
    display: none;
    flex-direction: column;
    flex: 1;
    gap: 20px;
    min-height: 0;
    /* Important for flex children to scroll/shrink properly */
}

.page.active {
    display: flex;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    padding: 10px 20px;
}

.tab-btn {
    order: 1;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    color: var(--text-main);
    background: var(--subtle-hover);
}

.tab-btn.active {
    color: var(--text-on-primary);
    background: var(--primary);
    box-shadow: var(--active-shadow);
}

.theme-toggle {
    order: 2;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    padding: 6px 10px 6px 6px;
    border: 1px solid var(--panel-border);
    border-radius: 999px;
    background: var(--surface-soft);
    color: var(--text-main);
    font: inherit;
    font-size: 0.86rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.theme-toggle:hover {
    background: var(--subtle-hover);
    border-color: rgba(59, 130, 246, 0.42);
    transform: translateY(-1px);
}

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

.theme-toggle-track {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: center;
    width: 54px;
    height: 28px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.78);
    color: #f8fafc;
    padding: 3px;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.theme-icon {
    width: 15px;
    height: 15px;
    justify-self: center;
    z-index: 1;
    opacity: 0.72;
}

.theme-toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #f8fafc;
    box-shadow: 0 3px 9px rgba(15, 23, 42, 0.32);
    transform: translateX(26px);
    transition: transform 0.22s ease, background 0.22s ease;
}

.theme-toggle-text {
    min-width: 2.2em;
    text-align: left;
}

:root[data-theme="light"] .theme-toggle-track {
    background: rgba(37, 99, 235, 0.16);
    color: #1e3a8a;
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.18);
}

:root[data-theme="light"] .theme-toggle-thumb {
    background: #ffffff;
    transform: translateX(0);
}

:root[data-theme="light"] #btnLocation {
    background: var(--surface-strong) !important;
    border-color: var(--panel-border) !important;
    color: var(--text-main) !important;
}

:root[data-theme="light"] [style*="color: #f8fafc"],
:root[data-theme="light"] [style*="color:#f8fafc"] {
    color: var(--text-main) !important;
}

:root[data-theme="light"] [style*="color: #94a3b8"],
:root[data-theme="light"] [style*="color:#94a3b8"] {
    color: var(--text-muted) !important;
}

:root[data-theme="light"] [style*="background-color: #f8fafc"],
:root[data-theme="light"] [style*="background-color:#f8fafc"] {
    background-color: var(--text-main) !important;
}

:root[data-theme="light"] [style*="border-top: 2px dashed #f8fafc"],
:root[data-theme="light"] [style*="border-top:2px dashed #f8fafc"],
:root[data-theme="light"] [style*="border-top: 2px dotted #f8fafc"],
:root[data-theme="light"] [style*="border-top:2px dotted #f8fafc"] {
    border-top-color: var(--text-main) !important;
}

:root[data-theme="light"] select.btn.secondary,
:root[data-theme="light"] input[type="number"] {
    background: var(--surface-strong) !important;
    border-color: var(--panel-border) !important;
    color: var(--text-main) !important;
}

:root[data-theme="light"] #dbDropArea {
    border-color: var(--panel-border) !important;
}

:root[data-theme="light"] #dbProgressWrap,
:root[data-theme="light"] #dbLogArea {
    background: var(--surface-soft) !important;
    border-color: var(--panel-border) !important;
}

/* Glassmorphism utility */
.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--panel-shadow);
    transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

/* Header */
header {
    text-align: center;
}

header h1 {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 8px;
    background: var(--header-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

header h1 span {
    font-size: 1rem;
    font-weight: 600;
    background: var(--primary);
    -webkit-text-fill-color: initial;
    color: var(--text-on-primary);
    padding: 4px 10px;
    border-radius: 8px;
}

header p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* Main Canvas Area */
.canvas-wrapper {
    position: relative;
    display: flex;
    flex: 1;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    padding: 0;
    min-height: 400px;
}

canvas {
    width: 100%;
    height: 100%;
    background: var(--canvas-bg);
    cursor: crosshair;
    border-radius: 15px;
    touch-action: none;
    /* Prevent scrolling when drawing on mobile */
}

/* Controls */
footer.controls {
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text-on-primary);
}

.btn svg {
    width: 20px;
    height: 20px;
}

.btn.primary {
    background: var(--primary);
    box-shadow: var(--active-shadow);
}

.btn.primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.23);
}

.btn.primary:disabled {
    background: var(--secondary);
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

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

.btn.secondary {
    background: var(--panel-bg);
    border: 1px solid var(--secondary);
    color: var(--text-main);
}

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

/* Stats Overlay */
.stats-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--surface-strong);
}

.stats-panel.hidden {
    display: none;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.stat-item .label {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-item .value {
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--success);
}

/* Loader */
#loading {
    position: absolute;
    inset: 0;
    background: var(--overlay-bg);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 16px;
    z-index: 10;
}

#loading.hidden {
    display: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--panel-border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Mobile Toast Notification */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--accent);
    color: var(--text-on-primary);
    padding: 10px 20px;
    border-radius: 30px;
    font-weight: 600;
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(244, 63, 94, 0.4);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 50;
    opacity: 0;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

#btnLocation {
    transition: all 0.2s ease;
}

#btnLocation:hover {
    background: var(--surface-strong) !important;
    transform: scale(1.05);
}

#btnLocation:active {
    transform: scale(0.95);
}

.map-layer-control {
    display: inline-flex;
    gap: 4px;
    padding: 4px !important;
    border-radius: 10px !important;
    overflow: hidden;
    pointer-events: auto;
}

.map-layer-control button {
    min-width: 42px;
    height: 30px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--text-main);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease;
}

.map-layer-control button:hover {
    background: var(--subtle-hover);
}

.map-layer-control button.active {
    background: var(--primary);
    color: var(--text-on-primary);
    box-shadow: var(--active-shadow);
}

.about-me {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-top: 4px;
    padding-top: 18px;
    border-top: 1px solid var(--panel-border);
}

.about-me-copy {
    min-width: 0;
}

.about-me-label {
    margin-bottom: 4px;
    color: var(--success);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.about-me h3 {
    margin-bottom: 8px;
    color: var(--text-main);
    font-size: 1.25rem;
    line-height: 1.2;
}

.about-me-quote {
    color: var(--text-main);
    font-size: 0.95rem;
    line-height: 1.55;
}

.about-me-quote.zh {
    color: var(--text-main);
    font-weight: 650;
}

.about-me-credit {
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 0.85rem;
    line-height: 1.45;
}

.about-me-links {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.about-me-links a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    background: var(--surface-soft);
    text-decoration: none;
    transition: all 0.2s ease;
}

.about-me-links img {
    width: 24px;
    height: 24px;
    object-fit: contain;
    flex-shrink: 0;
}

.about-me-links a:hover,
.about-me-links a:focus-visible {
    border-color: rgba(52, 211, 153, 0.8);
    background: rgba(52, 211, 153, 0.14);
    outline: none;
    transform: translateY(-2px);
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(59, 130, 246, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0);
    }
}

.custom-tooltip {
    background-color: var(--surface-strong);
    border: 1px solid var(--panel-border);
    color: var(--text-main);
    font-weight: bold;
    border-radius: 4px;
    padding: 2px 6px;
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.hidden {
    display: none !important;
}

/* ===== TUTORIAL SUB-TABS ===== */
.tutorial-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--panel-border);
}
.tutorial-tab {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 8px 8px 0 0;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 600;
    padding: 8px 22px;
    margin-bottom: -1px;
    cursor: pointer;
    transition: all 0.2s;
}
.tutorial-tab:hover { color: var(--text-main); background: var(--subtle-hover); }
.tutorial-tab.active { color: var(--text-on-primary); border-bottom-color: var(--primary); background: var(--primary); }

.tutorial-panel {
    display: none;
    height: 100%;
    overflow-y: auto;
    padding: 16px 20px 20px;
    flex-direction: column;
    gap: 20px;
}
.tutorial-panel.active { display: flex; }

/* Desktop: tutorial columns side by side, tabs hidden */
@media (min-width: 769px) {
    .tutorial-tabs { display: none; }
    #tutorialPanels {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 30px;
        overflow-y: auto !important;
    }
    .tutorial-panel,
    .tutorial-panel.active {
        display: flex !important;
        height: auto !important;
        overflow-y: visible !important;
    }
}

/* ===== RESPONSIVE ===== */

/* Tablet Portrait & Phone Landscape (≤768px) */
@media (max-width: 768px) {
    body { padding: 8px; overflow-y: auto; align-items: flex-start; }
    .app-container { gap: 8px; min-height: 100dvh; height: auto; }
    .page { flex: none !important; min-height: 0; gap: 8px !important; }

    header h1 { font-size: 1.4rem; flex-direction: row; flex-wrap: wrap; gap: 6px; }
    .glass-panel { padding: 14px; }

    .tabs { gap: 6px; padding: 8px 10px; }
    .tab-btn { font-size: 0.85rem; padding: 7px 11px; }
    .theme-toggle { margin-left: 0; padding-right: 8px; font-size: 0.78rem; }
    .theme-toggle-track { width: 48px; height: 26px; }
    .theme-toggle-thumb { width: 20px; height: 20px; transform: translateX(22px); }
    :root[data-theme="light"] .theme-toggle-thumb { transform: translateX(0); }

    /* Page 1: flatten canvas-wrapper so children become direct flex items of .page */
    main.canvas-wrapper {
        display: contents !important;
    }
    /* Map needs its own glass-panel-like styling since wrapper is display:contents */
    #map {
        position: relative !important;
        inset: auto !important;
        height: 55vh !important;
        min-height: 200px;
        flex: none !important;
        background: var(--panel-bg);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border: 1px solid var(--panel-border);
        border-radius: 16px;
        box-shadow: var(--panel-shadow);
        order: 0;
    }
    /* Strategy panel: above map, collapsible on mobile */
    #strategyPanel {
        position: static !important;
        order: -1;
        min-width: 0 !important;
        max-height: none !important;
        overflow: visible !important;
        border-radius: 12px;
        z-index: auto !important;
        flex: none !important;
    }
    /* 2-column checkboxes so collapsed → expanded doesn't take too much height */
    .strategy-list > div { display: grid; grid-template-columns: 1fr 1fr; align-items: start; gap: 0; }
    .strategy-list > div > span { grid-column: 1 / -1; }

    /* Stats panel: below map, collapsible on mobile */
    #statsPanel {
        position: static !important;
        top: auto !important;
        right: auto !important;
        order: 1;
        flex: none !important;
        flex-direction: column !important;
        gap: 6px !important;
        padding: 10px 14px !important;
        border-radius: 12px;
        z-index: auto !important;
        width: 100% !important;
        display: flex !important;
    }
    #statsContent { display: flex; flex-direction: column; gap: 8px; }
    /* Stats panel: mobile re-layout for route items */
    #extraStatsDetails > div {
        flex-wrap: wrap !important;
    }
    #extraStatsDetails .replay-btn {
        font-size: 0.7rem !important;
        padding: 2px 5px !important;
    }

    #btnStrategyToggle { display: none !important; }

    /* DB page: stack vertically */
    .db-row { flex-direction: column !important; }
    #dbDropArea { min-height: 130px !important; }
    .about-me {
        align-items: flex-start;
        flex-direction: column;
        gap: 14px;
    }

    /* Buttons */
    .btn { padding: 12px 18px; font-size: 0.9rem; }
    footer.controls { gap: 8px; flex: none; order: 2; }
    footer.controls .btn { width: 100%; }
    footer.controls .dropdown { width: 100%; }

    /* Export dropdown: open upward on mobile so it doesn't block content below */
    .dropdown { position: relative; }
    .dropdown .dropdown-content {
        bottom: 100% !important;
        top: auto !important;
        padding-bottom: 6px;
        padding-top: 0;
        left: 0;
        right: 0;
        min-width: 100%;
    }
    .dropdown .dropdown-content .dropdown-item {
        padding: 10px 14px;
        font-size: 0.85rem;
        text-align: center;
    }
}

/* Phone Portrait (≤480px) */
@media (max-width: 480px) {
    body { padding: 5px; }
    .app-container { gap: 5px; }

    header { padding: 10px 12px; }
    header h1 { font-size: 1.1rem; }
    header h1 span { font-size: 0.72rem; padding: 3px 7px; }
    header p { font-size: 0.78rem; }

    .tabs { gap: 3px; padding: 6px; }
    .tab-btn { font-size: 0.72rem; padding: 6px 7px; }
    .theme-toggle { gap: 6px; padding: 5px 8px 5px 5px; }
    .theme-toggle-text { display: none; }
    .glass-panel { padding: 10px; border-radius: 10px; }

    /* Footer: 2-column grid */
    footer.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
    footer.controls .btn { width: auto; padding: 10px 6px; font-size: 0.8rem; }
    footer.controls .dropdown { width: 100%; }
    footer.controls .dropdown .btn { width: 100%; }

    #dbLogArea { max-height: 180px !important; }

    .stats-panel { padding: 6px 9px; }
    .stat-item .value { font-size: 0.9rem; }
    .stat-item .label { font-size: 0.75rem; }
    #btnReplayAll { font-size: 0.72rem !important; padding: 3px 7px !important; }
}

/* Phone Landscape (short viewport height) */
@media (max-height: 500px) and (orientation: landscape) {
    .app-container { gap: 3px; height: 100dvh; }
    header { padding: 5px 12px; }
    header h1 { font-size: 1rem; margin-bottom: 2px; }
    header p { display: none; }
    .tabs { padding: 4px 8px; }
    .tab-btn { padding: 5px 10px; font-size: 0.8rem; }
}

/* Export Dropdown */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    bottom: 100%;
    padding-bottom: 10px;
    /* Extends invisible hitbox downwards over the gap */
    left: 0;
    min-width: 160px;
    background-color: var(--bg-color);
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    box-shadow: var(--panel-shadow);
    z-index: 1000;
    overflow: hidden;
}

.dropdown:hover .dropdown-content {
    display: block;
}
.dropdown:has(button:disabled):hover .dropdown-content {
    display: none;
}

.dropdown-item {
    color: var(--text-main);
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s ease;
}


.dropdown-item:hover {
    background-color: var(--primary);
    color: var(--text-on-primary);
}

/* Tutorial Card Detail Panels */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    margin-bottom: 0;
}
.card-header:hover { color: var(--link-accent); }
.toggle-icon {
    font-size: 0.75rem;
    color: var(--link-accent);
    transition: transform 0.3s ease;
    flex-shrink: 0;
}
.card-header.open .toggle-icon { transform: rotate(90deg); }
.detail-panel {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.45s ease;
}
.detail-panel.open { max-height: 1600px; }
.detail-inner {
    border-top: 1px solid var(--panel-border);
    padding-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.detail-section { display: flex; flex-direction: column; gap: 7px; }
.detail-heading {
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--link-accent);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding-bottom: 4px;
    border-bottom: 1px solid color-mix(in srgb, var(--link-accent), transparent 70%);
}
.detail-steps {
    color: var(--text-main);
    font-size: 0.87rem;
    line-height: 1.65;
    padding-left: 18px;
    margin: 0;
}
.detail-steps li { margin-bottom: 3px; }
.detail-steps ul { padding-left: 16px; margin-top: 3px; }
.formula-box {
    background: var(--surface-muted);
    border-left: 3px solid #3b82f6;
    border-radius: 0 6px 6px 0;
    padding: 7px 11px;
}
.formula-title {
    font-size: 0.74rem;
    color: var(--link-accent);
    margin-bottom: 4px;
    font-weight: 600;
}
.formula-box code {
    display: block;
    font-family: 'Courier New', monospace;
    font-size: 0.81rem;
    color: var(--text-main);
    line-height: 1.75;
    background: none;
    padding: 0;
}
.param-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.84rem;
}
.param-table td {
    padding: 4px 8px;
    vertical-align: top;
    border-bottom: 1px solid var(--panel-border);
    color: var(--text-main);
}
.param-table td:first-child {
    font-family: 'Courier New', monospace;
    color: #fbbf24;
    white-space: nowrap;
    width: 1%;
    padding-right: 14px;
}
.complexity-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.complexity-label { font-size: 0.8rem; color: var(--text-muted); }
.complexity-value {
    font-family: 'Courier New', monospace;
    font-size: 0.82rem;
    color: var(--success);
    background: var(--chip-bg);
    padding: 2px 8px;
    border-radius: 4px;
}
.detail-note {
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin: 2px 0 0;
}

/* Tutorial Animations */
.tutorial-card {
    background: var(--surface-soft);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.tutorial-card h3 {
    color: var(--text-main);
    border-bottom: 1px solid var(--panel-border);
    padding-bottom: 8px;
    font-size: 1.1rem;
}

.tutorial-card p {
    color: var(--text-main);
    font-size: 0.95rem;
    line-height: 1.6;
}

/* Collapsible panels */
#strategyPanel.collapsed #strategyPanelHeader {
    margin-bottom: 0 !important;
}

@media (min-width: 769px) {
    #strategyPanel {
        left: 64px !important;
        max-width: min(320px, calc(100% - 96px));
    }

    #strategyPanel.collapsed {
        min-width: 0 !important;
        overflow: visible !important;
        padding: 12px 14px !important;
    }
}

.strategy-mobile-arrow {
    margin-left: auto;
    font-size: 0.8rem;
    color: var(--link-accent);
    transition: transform 0.2s;
    flex-shrink: 0;
}
#strategyPanel.collapsed .strategy-list { display: none; }
#strategyPanel.collapsed .strategy-mobile-arrow { transform: rotate(-90deg); }

.stats-toggle-arrow { font-size: 0.8rem; color: var(--link-accent); transition: transform 0.2s; flex-shrink: 0; }
#statsPanel.collapsed #statsContent { display: none; }
#statsPanel.collapsed #extraStatsDetails { display: none; }
#statsPanel.collapsed .stats-toggle-arrow { transform: rotate(-90deg); }
#statsPanelHeader { display: flex; align-items: center; justify-content: space-between; cursor: pointer; user-select: none; width: 100%; padding-bottom: 6px; border-bottom: 1px solid var(--panel-border); margin-bottom: 4px; }
#statsPanelHeader:hover { opacity: 0.8; }

.anim-box {
    width: 100%;
    height: 150px;
    background: var(--surface-muted);
    border-radius: 8px;
    overflow: hidden;
    margin-top: 10px;
    display: flex;
    justify-content: center;
}
.anim-inner {
    position: relative;
    width: 280px;
    height: 150px;
    flex-shrink: 0;
    overflow: hidden;
}

.anim-node {
    width: 12px;
    height: 12px;
    background: #f43f5e;
    border: 2px solid white;
    border-radius: 50%;
    position: absolute;
    z-index: 2;
}

.anim-line {
    position: absolute;
    height: 3px;
    background: #3b82f6;
    transform-origin: 0 50%;
    z-index: 1;
    opacity: 0;
}

.anim-text {
    position: absolute;
    bottom: 10px;
    text-align: center;
    width: 100%;
    color: var(--text-main);
    font-weight: bold;
    z-index: 3;
    pointer-events: none;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

/* NN Animation */
.nn-line1 {
    top: 74.5px;
    left: 31.0px;
    width: 80.6px;
    transform: rotate(-29.74deg);
    animation: drawLine 4s infinite 0.5s;
}

.nn-line2 {
    top: 34.5px;
    left: 101.0px;
    width: 71.0px;
    transform: rotate(9.73deg);
    animation: drawLine 4s infinite 1.5s;
}

.nn-line3 {
    top: 46.5px;
    left: 171.0px;
    width: 90.5px;
    transform: rotate(44.10deg);
    animation: drawLine 4s infinite 2.5s;
}

/* 2-Opt Animation */
.opt-line-bad1 {
    top: 29.5px;
    left: 51.0px;
    width: 120.2px;
    transform: rotate(45.00deg);
    background: #ef4444;
    animation: fadeOutBad 4s infinite;
}

.opt-line-bad2 {
    top: 114.5px;
    left: 51.0px;
    width: 120.2px;
    transform: rotate(-45.00deg);
    background: #ef4444;
    animation: fadeOutBad 4s infinite;
}

.opt-line-good1 {
    top: 29.5px;
    left: 51.0px;
    width: 85.0px;
    transform: rotate(90.00deg);
    background: #34d399;
    opacity: 0;
    animation: fadeInGood 4s infinite;
}

.opt-line-good2 {
    top: 29.5px;
    left: 136.0px;
    width: 85.0px;
    transform: rotate(90.00deg);
    background: #34d399;
    opacity: 0;
    animation: fadeInGood 4s infinite;
}

/* Greedy Animation */
.greedy-line1 {
    top: 34.5px;
    left: 101.0px;
    width: 51.4px;
    transform: rotate(13.50deg);
    animation: drawLine 4s infinite 0.5s;
    background: #34d399;
}

.greedy-line2 {
    top: 109.5px;
    left: 51.0px;
    width: 53.9px;
    transform: rotate(-21.80deg);
    animation: drawLine 4s infinite 1.5s;
    background: #34d399;
}

.greedy-line3 {
    top: 64.5px;
    left: 166.0px;
    width: 49.2px;
    transform: rotate(-66.04deg);
    animation: drawLine 4s infinite 2.5s;
    background: #34d399;
}

/* Insertion Animation */
.ins-line-base {
    top: 74.5px;
    left: 31.0px;
    width: 140.0px;
    transform: rotate(0.00deg);
    border-top: 2px dashed #94a3b8;
    background: transparent;
    height: 0;
    animation: fadeOutBad 4s infinite;
}

.ins-node-new {
    top: 30px;
    left: 100px;
    background: #c084fc;
    animation: popIn 4s infinite;
}

.ins-line-new1 {
    top: 74.5px;
    left: 31.0px;
    width: 87.3px;
    transform: rotate(-23.63deg);
    background: #c084fc;
    opacity: 0;
    animation: fadeInGood 4s infinite 1s;
}

.ins-line-new2 {
    top: 39.5px;
    left: 111.0px;
    width: 69.5px;
    transform: rotate(30.26deg);
    background: #c084fc;
    opacity: 0;
    animation: fadeInGood 4s infinite 1s;
}

/* L-K Animation */
.lk-line-bad1 {
    top: 24.5px;
    left: 86.0px;
    width: 141.4px;
    transform: rotate(45.00deg);
    background: #ef4444;
    animation: fadeBoth 4s infinite;
}

.lk-line-bad2 {
    top: 124.5px;
    left: 86.0px;
    width: 141.4px;
    transform: rotate(-45.00deg);
    background: #ef4444;
    animation: fadeBoth 4s infinite;
}

.lk-line-bad3 {
    top: 74.5px;
    left: 46.0px;
    width: 180.0px;
    transform: rotate(0.00deg);
    background: #ef4444;
    animation: fadeBoth 4s infinite;
}

.lk-line-good1 {
    top: 24.5px;
    left: 86.0px;
    width: 100.0px;
    transform: rotate(0.00deg);
    background: #facc15;
    opacity: 0;
    animation: fadeInGood 4s infinite;
}

.lk-line-good2 {
    top: 124.5px;
    left: 186.0px;
    width: 64.0px;
    transform: rotate(-51.34deg);
    background: #facc15;
    opacity: 0;
    animation: fadeInGood 4s infinite;
}

.lk-line-good3 {
    top: 124.5px;
    left: 86.0px;
    width: 64.0px;
    transform: rotate(-128.66deg);
    background: #facc15;
    opacity: 0;
    animation: fadeInGood 4s infinite;
}

/* SA Animation */
.sa-node {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #fb923c;
    position: absolute;
    left: 100px;
    animation: bounceTemp 4s infinite;
}

.sa-bg {
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, rgba(239, 68, 68, 0.4), rgba(59, 130, 246, 0.1));
    animation: coolDown 4s infinite;
}

/* GA Animation */
.ga-line1 {
    width: 200px;
    height: 4px;
    top: 40px;
    left: 20px;
    background: linear-gradient(90deg, #3b82f6 50%, #c084fc 50%);
    border-radius: 2px;
    position: absolute;
    animation: crossbar 4s infinite;
}

.ga-line2 {
    width: 200px;
    height: 4px;
    top: 100px;
    left: 20px;
    background: linear-gradient(90deg, #c084fc 50%, #3b82f6 50%);
    border-radius: 2px;
    position: absolute;
    animation: crossbar 4s infinite reverse;
}

@keyframes drawLine {

    0%,
    10% {
        opacity: 0;
        width: 0;
    }

    20%,
    90% {
        opacity: 1;
        width: var(--w);
    }

    100% {
        opacity: 0;
        width: 0;
    }
}

@keyframes fadeOutBad {

    0%,
    40% {
        opacity: 1;
    }

    50%,
    100% {
        opacity: 0;
    }
}

@keyframes fadeBoth {

    0%,
    30% {
        opacity: 1;
    }

    40%,
    100% {
        opacity: 0;
    }
}

@keyframes fadeInGood {

    0%,
    35% {
        opacity: 0;
    }

    45%,
    90% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}

@keyframes popIn {

    0%,
    20% {
        transform: scale(0);
        opacity: 0;
    }

    30%,
    90% {
        transform: scale(1);
        opacity: 1;
    }

    100% {
        transform: scale(0);
        opacity: 0;
    }
}

@keyframes bounceTemp {
    0% {
        top: 20px;
        transform: scale(1.5);
        background: #ef4444;
    }

    20% {
        top: 100px;
        transform: scale(1.2);
        background: #f97316;
    }

    40% {
        top: 40px;
        transform: scale(1.1);
        background: #fbbf24;
    }

    60% {
        top: 90px;
        transform: scale(1.0);
        background: #a3e635;
    }

    80%,
    100% {
        top: 75px;
        transform: scale(1.0);
        background: #3b82f6;
    }
}

@keyframes coolDown {
    0% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}

@keyframes crossbar {

    0%,
    20% {
        top: 40px;
        background: linear-gradient(90deg, #3b82f6 50%, #3b82f6 50%);
    }

    30%,
    70% {
        top: 70px;
        background: linear-gradient(90deg, #3b82f6 50%, #c084fc 50%);
    }

    80%,
    100% {
        top: 100px;
        background: linear-gradient(90deg, #c084fc 50%, #c084fc 50%);
    }
}
