:root {
    --bg: #f8f9fb;
    --ink: #0f172a;
    --muted: #64748b;
    --panel: rgba(255, 255, 255, 0.92);
    --panel-solid: #ffffff;
    --accent: #f59e0b;
    --accent-deep: #d97706;
    --accent-light: rgba(245, 158, 11, 0.12);
    --train: #3b82f6;
    --border: rgba(15, 23, 42, 0.08);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow: 0 8px 32px rgba(15, 23, 42, 0.1), 0 2px 8px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 20px 60px rgba(15, 23, 42, 0.12), 0 4px 16px rgba(15, 23, 42, 0.08);
    --radius: 16px;
    --radius-sm: 10px;
    --topbar-height: 72px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --icon-scale: 1;
    --vehicle-scale: 1;
    --stop-scale: 1;
    --route-dot-scale: 1;
    --line-scale: 1;
}

body {
    margin: 0;
    font-family: "Inter", "Space Grotesk", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.dark {
    --bg: #0a0f1a;
    --ink: #f1f5f9;
    --muted: #94a3b8;
    --panel: rgba(15, 23, 42, 0.92);
    --panel-solid: #111827;
    --border: rgba(241, 245, 249, 0.08);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.4);
}

#app {
    position: relative;
    min-height: 100vh;
    overflow: hidden;
}

#map {
    height: 100vh;
    width: 100%;
    filter: saturate(1.05) contrast(1.02);
}

/* Topbar */
.topbar {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 8px 14px;
    background: var(--panel);
    border-radius: 14px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(20px) saturate(1.8);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
    animation: float-in 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 500;
    border: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-logo {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    object-fit: contain;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.brand-title {
    font-family: "Fraunces", serif;
    font-size: 1.15rem;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: -0.01em;
}

/* Search */
.search-wrap {
    position: relative;
    display: flex;
    gap: 6px;
    align-items: center;
    max-width: 440px;
    width: 100%;
    justify-self: center;
}

.search-icon-left {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 0.8rem;
    pointer-events: none;
    z-index: 1;
}

.search-wrap input {
    height: 38px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    padding: 0 32px 0 34px;
    font-size: 0.88rem;
    font-family: inherit;
    background: rgba(255, 255, 255, 0.7);
    flex: 1;
    min-width: 0;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
    color: var(--ink);
}

body.dark .search-wrap input {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
}

.search-wrap input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
    background: rgba(255, 255, 255, 0.95);
}

body.dark .search-wrap input:focus {
    background: rgba(255, 255, 255, 0.1);
}

.search-wrap input::placeholder {
    color: var(--muted);
    opacity: 0.7;
}

.search-wrap button {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--muted);
    padding: 0;
    font-size: 0.8rem;
    cursor: pointer;
    display: none;
    place-items: center;
    transition: color var(--transition), background var(--transition);
}

.search-wrap button.visible {
    display: grid;
}

.search-wrap button:hover {
    color: var(--ink);
    background: rgba(15, 23, 42, 0.06);
}

.search-results {
    position: absolute;
    top: 46px;
    left: 0;
    right: 0;
    background: var(--panel-solid);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 6px;
    display: grid;
    gap: 2px;
    z-index: 600;
    border: 1px solid var(--border);
    animation: float-in 0.2s ease-out;
}

.search-results[hidden] {
    display: none;
}

.search-results:empty {
    display: none;
}

.search-result {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background var(--transition);
    font-size: 0.88rem;
}

.search-result:hover {
    background: var(--accent-light);
}

/* Settings */
.topbar-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.settings-btn {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    font-size: 0.95rem;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.settings-btn:hover,
.settings-btn.active {
    background: rgba(15, 23, 42, 0.06);
    color: var(--ink);
    border-color: var(--accent);
}

body.dark .settings-btn:hover,
body.dark .settings-btn.active {
    background: rgba(255, 255, 255, 0.06);
}

.settings-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 260px;
    background: var(--panel-solid);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 16px;
    display: grid;
    gap: 12px;
    z-index: 550;
    animation: float-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid var(--border);
}

.settings-dropdown[hidden] {
    display: none;
}

.settings-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

.toggle {
    display: flex;
    gap: 10px;
    align-items: center;
    font-size: 0.85rem;
    color: var(--muted);
    cursor: pointer;
    padding: 4px 0;
    transition: color var(--transition);
}

.toggle:hover {
    color: var(--ink);
}

.toggle input {
    accent-color: var(--accent-deep);
    width: 16px;
    height: 16px;
}

.style-selector {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 0.85rem;
    color: var(--muted);
}

.style-selector select {
    background: var(--panel-solid);
    color: var(--ink);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 5px 8px;
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    flex: 1;
    transition: border-color var(--transition);
}

.style-selector select:focus {
    outline: none;
    border-color: var(--accent);
}

/* Route Panel */
.panel {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: min(380px, calc(100vw - 40px));
    background: var(--panel-solid);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 0;
    z-index: 450;
    animation: slide-up 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    display: none;
    border: 1px solid var(--border);
    overflow: hidden;
}

.panel.open {
    display: block;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(to bottom, var(--accent-light), transparent);
}

.panel-header h2 {
    margin: 0;
    font-family: "Fraunces", serif;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-header button {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    display: grid;
    place-items: center;
    font-size: 0.85rem;
    transition: background var(--transition), color var(--transition);
}

.panel-header button:hover {
    background: rgba(239, 68, 68, 0.08);
    color: #ef4444;
}

.panel-content {
    padding: 14px 16px;
    display: grid;
    gap: 10px;
    max-height: 45vh;
    overflow: auto;
    font-size: 0.9rem;
}

.panel-content strong {
    color: var(--muted);
    font-weight: 500;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.panel-placeholder {
    color: var(--muted);
    text-align: center;
    padding: 20px 0;
}

.panel-route {
    font-weight: 700;
    font-size: 1.05rem;
}

.panel-meta {
    font-size: 0.82rem;
    color: var(--muted);
    margin-top: 2px;
}

.panel-stops {
    margin: 4px 0 0;
    padding-left: 20px;
    line-height: 1.8;
}

.panel-stops li {
    padding: 2px 4px;
    border-radius: 4px;
    transition: background var(--transition);
    cursor: pointer;
}

.panel-stops li:hover {
    background: var(--accent-light);
}

.panel-stops li.current {
    font-weight: 600;
    color: var(--ink);
    background: var(--accent-light);
}

.panel-stops li.next {
    color: var(--accent-deep);
    font-weight: 500;
}

.panel-stops li.highlighted {
    background: var(--accent-light);
    border-radius: 6px;
    padding: 4px 8px;
    font-weight: 600;
    color: var(--accent-deep);
}

/* Route Browser */
.browse-country { margin-bottom: 2px; }
.browse-country > summary {
    font-weight: 700;
    font-size: 0.9rem;
    padding: 8px 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: 8px;
    transition: background var(--transition);
    list-style: none;
}
.browse-country > summary::-webkit-details-marker { display: none; }
.browse-country > summary::before {
    content: '\f078';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    font-size: 0.6rem;
    transition: transform 0.2s;
    color: var(--muted);
}
.browse-country[open] > summary::before { transform: rotate(180deg); }
.browse-country > summary:hover { background: var(--accent-light); }

.browse-city { margin-left: 12px; margin-bottom: 2px; }
.browse-city > summary {
    font-weight: 600;
    font-size: 0.82rem;
    padding: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    border-radius: 6px;
    color: var(--muted);
    transition: background var(--transition);
    list-style: none;
}
.browse-city > summary::-webkit-details-marker { display: none; }
.browse-city > summary::before {
    content: '\f078';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    font-size: 0.55rem;
    transition: transform 0.2s;
    color: var(--muted);
}
.browse-city[open] > summary::before { transform: rotate(180deg); }
.browse-city > summary:hover { background: var(--accent-light); }

.browse-count {
    margin-left: auto;
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--border);
    color: var(--muted);
    padding: 1px 7px;
    border-radius: 10px;
}

.browse-routes { margin-left: 8px; }
.browse-route {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background var(--transition);
}
.browse-route:hover { background: var(--accent-light); }
.browse-route-dot {
    width: calc(8px * var(--route-dot-scale));
    height: calc(8px * var(--route-dot-scale));
    border-radius: 50%;
    flex-shrink: 0;
}
.browse-route-num {
    font-weight: 700;
    white-space: nowrap;
}
.browse-route-name {
    color: var(--muted);
    font-size: 0.8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Legend */
.legend {
    position: absolute;
    right: 20px;
    bottom: 20px;
    background: var(--panel-solid);
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: var(--shadow);
    z-index: 450;
    border: 1px solid var(--border);
}

.legend-title {
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 8px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    padding: 2px 0;
}

.legend-dot {
    width: calc(10px * var(--route-dot-scale));
    height: calc(10px * var(--route-dot-scale));
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.8), 0 1px 3px rgba(0, 0, 0, 0.15);
}

.legend-bus {
    background: var(--accent);
}

.legend-train {
    background: var(--train);
}

/* Loading / Error */
.loading {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    color: white;
    z-index: 700;
}

.spinner {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

.loading-text {
    font-size: 0.9rem;
    font-weight: 500;
    letter-spacing: 0.01em;
}

.error {
    position: absolute;
    top: calc(var(--topbar-height) + 20px);
    left: 20px;
    right: 20px;
    padding: 12px 16px;
    background: #ef4444;
    color: white;
    border-radius: 12px;
    z-index: 700;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* Vehicle Markers */
.vehicle-icon {
    width: 100%;
    height: 100%;
    color: var(--vehicle-color, var(--accent));
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.25));
    position: relative;
    cursor: pointer;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.vehicle-icon:hover {
    transform: scale(1.15);
}

.vehicle-svg {
    width: 100%;
    height: 100%;
    display: block;
    transform-origin: 50% 50%;
}

.vehicle-shell {
    fill: currentColor;
}

.vehicle-core {
    fill: #ffffff;
}

.vehicle-icon.pulse::after {
    content: "";
    position: absolute;
    inset: calc(-7px * var(--vehicle-scale));
    border-radius: 14px;
    border: calc(2px * var(--vehicle-scale)) solid rgba(255, 255, 255, 0.55);
    animation: pulse 1.6s ease-out infinite;
}

/* Stop Markers */
.stop-marker {
    width: calc(10px * var(--stop-scale));
    height: calc(10px * var(--stop-scale));
    border: calc(2px * var(--stop-scale)) solid #1e293b;
    background: #f8fafc;
    border-radius: 3px;
    display: grid;
    place-items: center;
    transition: transform 0.15s ease;
}

.stop-marker:hover {
    transform: scale(1.2);
}

.stop-marker .stop-inner {
    width: calc(4px * var(--stop-scale));
    height: calc(4px * var(--stop-scale));
    background: #1e293b;
    border-radius: 1px;
    display: block;
}

.stop-marker-active {
    width: calc(16px * var(--stop-scale)) !important;
    height: calc(16px * var(--stop-scale)) !important;
    border: calc(2px * var(--stop-scale)) solid var(--accent-deep);
    background: var(--accent);
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.28), 0 2px 6px rgba(0, 0, 0, 0.12);
    z-index: 600 !important;
}

.stop-marker-active .stop-inner {
    width: calc(6px * var(--stop-scale));
    height: calc(6px * var(--stop-scale));
    background: var(--accent-deep);
}

/* Animations */
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes float-in {
    from { transform: translateY(-12px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes slide-up {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes pulse {
    0% { transform: scale(0.6); opacity: 0.7; }
    100% { transform: scale(1.6); opacity: 0; }
}

/* Leaflet zoom controls */
.leaflet-top.leaflet-left {
    top: var(--topbar-height);
    left: 12px;
}

.leaflet-control-zoom a {
    border-radius: 8px !important;
    border: 1px solid rgba(15, 23, 42, 0.08) !important;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06) !important;
}

/* Mobile */
@media (max-width: 600px) {
    .topbar {
        top: 8px;
        left: 8px;
        right: 8px;
        padding: 6px 10px;
        gap: 8px;
        border-radius: 12px;
    }

    .brand-title {
        font-size: 0.95rem;
    }

    .brand-logo {
        width: 28px;
        height: 28px;
    }

    .search-wrap input {
        height: 34px;
        font-size: 0.82rem;
        padding-left: 30px;
    }

    .search-icon-left {
        font-size: 0.72rem;
        left: 10px;
    }

    .search-wrap button,
    .settings-btn {
        width: 34px;
        height: 34px;
    }

    .settings-dropdown {
        width: calc(100vw - 16px);
        right: -8px;
    }

    .panel {
        left: 8px;
        bottom: 8px;
        width: min(380px, calc(100vw - 16px));
        max-height: calc(100vh - var(--topbar-height) - 24px);
        overflow-y: auto;
    }

    .panel-content {
        max-height: none;
    }

    .legend {
        right: 8px;
        bottom: 8px;
        padding: 8px 12px;
    }

    .leaflet-top.leaflet-left {
        left: 8px;
    }
}
