.top-bar.sticky {
    position: sticky;
    top: 0;
}

:root {
    color-scheme: light;
    font-family: 'Inter', 'Segoe UI', Roboto, sans-serif;
    --bg: linear-gradient(180deg, #ecf2ff 0%, #f9fbff 100%);
    --panel: #ffffffeb;
    --primary: #111827;
    --muted: #6b7280;
    --accent: #1d4ed8;
    --border: rgba(17, 24, 39, 0.08);
    --shadow: 0 24px 60px rgba(15, 23, 42, 0.15);
    --swatch-border: rgba(255, 255, 255, 0.6);
    --bfs: #2563eb;
    --dijkstra: #16a34a;
    --astar: #f59e0b;
    --greedy: #f97316;
    --transition: cubic-bezier(0.22, 1, 0.36, 1);
    --header-height: 120px;
}

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

body {
    background: var(--bg);
    color: var(--primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.55;
    font-feature-settings: 'liga' 1, 'kern' 1;
}

.top-bar {
    display: grid;
    grid-template-columns: minmax(0, 2fr) auto;
    align-items: center;
    gap: 1.5rem;
    padding: 1.75rem 2.25rem;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(17, 24, 39, 0.06);
    position: relative;
    z-index: 15;
    min-height: var(--header-height);
}

.branding h1 {
    font-size: 1.9rem;
    font-weight: 700;
    letter-spacing: -0.015em;
}

.branding p {
    margin-top: 0.4rem;
    color: var(--muted);
    font-weight: 500;
    letter-spacing: 0.02em;
}

.controls {
    display: flex;
    gap: 0.9rem;
}

.controls button {
    padding: 0.65rem 1.45rem;
    border: none;
    border-radius: 14px;
    font-weight: 600;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    transition: transform 0.22s var(--transition), box-shadow 0.22s var(--transition);
    box-shadow: 0 18px 35px rgba(37, 99, 235, 0.25);
}

.controls button:nth-child(2) {
    background: rgba(17, 24, 39, 0.08);
    color: var(--primary);
    box-shadow: none;
}

.controls button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.controls button:hover:not(:disabled) {
    transform: translateY(-1.5px);
    box-shadow: 0 22px 40px rgba(37, 99, 235, 0.28);
}

main {
    flex: 1;
    display: grid;
    gap: 1.75rem;
    grid-template-columns: minmax(0, 2.2fr) minmax(320px, 1fr);
    padding: 2.25rem 2.5rem 2.5rem;
    height: calc(100vh - var(--header-height));
    max-height: calc(100vh - var(--header-height));
    box-sizing: border-box;
    min-height: 0;
    overflow: hidden;
}

.map-panel {
    position: relative;
    background: var(--panel);
    border-radius: 28px;
    overflow: hidden;
    box-shadow: var(--shadow);
    height: 100%;
    min-height: 0;
    border: 1px solid var(--border);
}

#map {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
}

.legend {
    background: var(--panel);
    border-radius: 28px;
    padding: 1.75rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 2rem;
    border: 1px solid var(--border);
    height: 100%;
    max-height: 100%;
    min-height: 0;
    overflow-y: auto;
    scrollbar-gutter: stable both-edges;
}

.legend-section {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.legend-section h2 {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--muted);
}

.legend-section ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.legend-section li {
    display: block;
}

.algo-chip {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.75rem;
    border-radius: 12px;
    border: 1px solid transparent;
    background: rgba(15, 23, 42, 0.05);
    font-weight: 600;
    color: var(--accent);
    cursor: pointer;
    transition: transform 0.22s var(--transition), border 0.22s var(--transition), background 0.22s var(--transition);
}

.algo-chip:hover {
    transform: translateY(-1px);
    border-color: rgba(37, 99, 235, 0.35);
}

.algo-chip.active {
    border-color: rgba(37, 99, 235, 0.65);
    background: rgba(37, 99, 235, 0.12);
}

.algo-chip.dimmed {
    opacity: 0.45;
}

.swatch {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: inline-block;
}

.swatch.bfs { background: var(--bfs); }
.swatch.dijkstra { background: var(--dijkstra); }
.swatch.astar { background: var(--astar); }
.swatch.greedy { background: var(--greedy); }

.info-panel {
    background: rgba(15, 23, 42, 0.04);
    border-radius: 16px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 220px;
    overflow-y: auto;
}

#statusLog {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: 0.95rem;
}

.status-entry {
    padding: 0.55rem 0.75rem;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.06);
    line-height: 1.4;
}

.status-entry strong {
    display: block;
    font-weight: 600;
}

.status-entry span {
    opacity: 0.75;
    font-size: 0.87rem;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.control-group label {
    font-weight: 600;
    font-size: 0.95rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.control-group select {
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
    border: 1px solid rgba(37, 99, 235, 0.15);
    background: rgba(255, 255, 255, 0.9);
    min-height: 120px;
    font-size: 0.95rem;
    transition: border 0.18s ease, box-shadow 0.18s ease;
}

.control-group input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

.hint {
    font-size: 0.8rem;
    color: rgba(17, 24, 39, 0.55);
}

.control-group.toggles {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
}

.control-group.toggles button {
    padding: 0.5rem;
    border-radius: 12px;
    border: 1px solid rgba(37, 99, 235, 0.1);
    background: rgba(37, 99, 235, 0.08);
    font-weight: 600;
    color: var(--accent);
    cursor: pointer;
    transition: transform 0.2s var(--transition), background 0.2s var(--transition), border 0.2s var(--transition);
}

.control-group.toggles button:hover:not(:disabled) {
    transform: translateY(-1px);
    background: rgba(37, 99, 235, 0.16);
    border-color: rgba(37, 99, 235, 0.25);
}

.control-group.toggles button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
    transform: none;
}

.benchmark-table {
    display: grid;
    gap: 0.4rem;
    background: rgba(15, 23, 42, 0.04);
    border-radius: 16px;
    padding: 0.75rem;
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid rgba(17, 24, 39, 0.06);
    backdrop-filter: blur(8px);
}

.benchmark-header,
.benchmark-row {
    display: grid;
    grid-template-columns: 1.15fr 0.9fr 1fr 0.9fr;
    gap: 0.75rem;
    font-size: 0.9rem;
    align-items: center;
}

.benchmark-header {
    font-weight: 700;
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.78rem;
}

.benchmark-row {
    padding: 0.45rem 0.5rem;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.06);
    line-height: 1.35;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease, border 0.2s ease;
    border: 1px solid transparent;
}

.benchmark-row:hover {
    transform: translateY(-1px);
    background: rgba(15, 23, 42, 0.1);
}

.benchmark-row.active {
    border-color: rgba(15, 23, 42, 0.35);
    background: rgba(15, 23, 42, 0.16);
}

.benchmark-row.completed {
    border-color: rgba(22, 163, 74, 0.45);
    background: rgba(22, 163, 74, 0.12);
}

.benchmark-row.disabled,
.benchmark-row.disabled:hover {
    opacity: 0.45;
    cursor: default;
    transform: none;
    background: rgba(15, 23, 42, 0.04);
    border-color: transparent;
}

.benchmark-row span {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.benchmark-row.dimmed {
    opacity: 0.45;
    filter: grayscale(10%);
}

.benchmark-color {
    display: inline-flex;
    width: 12px;
    height: 12px;
    border-radius: 999px;
    margin-right: 0.4rem;
}

.runner-icon {
    background: transparent !important;
    border: none !important;
}

.runner-avatar {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: 3px solid transparent;
    overflow: hidden;
    box-shadow: 0 16px 32px rgba(15, 23, 42, 0.35);
    transition: transform 0.2s var(--transition), box-shadow 0.2s var(--transition);
}

.runner-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.route-detail {
    background: rgba(15, 23, 42, 0.04);
    border-radius: 16px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 220px;
    overflow-y: auto;
    font-size: 0.9rem;
    border: 1px solid rgba(17, 24, 39, 0.06);
    backdrop-filter: blur(8px);
}

.route-detail h3 {
    font-size: 0.95rem;
    font-weight: 700;
}

.route-detail ul {
    list-style: decimal;
    margin-left: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.route-detail strong {
    font-weight: 700;
}

.route-detail .muted {
    color: rgba(15, 23, 42, 0.6);
    font-size: 0.85rem;
}

@media (max-width: 1024px) {
    main {
        grid-template-columns: 1fr;
        height: auto;
        max-height: none;
        overflow: visible;
    }

    .legend {
        flex-direction: column;
        height: auto;
        max-height: none;
    }
}

@media (max-width: 640px) {
    .top-bar {
        grid-template-columns: 1fr;
        gap: 0.9rem;
        padding: 1.25rem 1.5rem 1.5rem;
    }

    .branding h1 {
        font-size: 1.55rem;
    }

    .branding p {
        margin-top: 0.25rem;
        font-size: 0.9rem;
    }

    main {
        padding: 1rem;
        gap: 1.25rem;
        height: auto;
        max-height: none;
        overflow: visible;
    }

    .controls {
        width: 100%;
        gap: 0.75rem;
        flex-wrap: wrap;
    }

    .controls button {
        flex: 1;
        padding: 0.65rem 0.85rem;
        font-size: 0.98rem;
        min-width: 150px;
    }

    .map-panel {
        min-height: 360px;
    }
}
