/* == Base (merged from style.common.css and style.index.css) == */
:root {
    --bg: #f7f7f9;
    --panel: #ffffff;
    --text: #111111;
    --muted: #555;
    --border: #e0e0e0;
    --accent: #3D6CC8;
    --accent-hover: #355fb0;
    /* slightly darker than --accent */
    --accent-ring: rgba(61, 108, 200, 0.35);
    --accent-soft-bg: rgba(61, 108, 200, 0.12);
    --accent-soft-hover: rgba(61, 108, 200, 0.18);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.06);
    --map-bg: #ffffff;
    --map-frame: #a80000;
    --label-bg: rgba(255, 255, 255, 0.85);
    --label-text: #111;
    --control-bg: #ffffff;
    --control-text: #111;
    /* glass variables */
    --glass-bg: rgba(255, 255, 255, 0.72);
    --glass-stroke: rgba(0, 0, 0, 0.06);
    --glass-blur: 12px;
    --topbar-offset: 32px;
}

.promo-slot a {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    text-decoration: none;
}

html {
    box-sizing: border-box;
}

*, *::before, *::after {
    box-sizing: inherit;
}

html[data-theme="dark"] {
    --bg: #0f1115;
    --panel: #171a21;
    --text: #e7eaf0;
    --muted: #a6adbb;
    --border: #262a33;
    --accent: #6FA0F0;
    --accent-hover: #5E95E0;
    --accent-ring: rgba(111, 160, 240, 0.35);
    --accent-soft-bg: rgba(111, 160, 240, 0.16);
    --accent-soft-hover: rgba(111, 160, 240, 0.22);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 6px 18px rgba(0, 0, 0, 0.5);
    --map-bg: #0b0d11;
    --map-frame: #222831;
    --label-bg: rgba(23, 26, 33, 0.8);
    --label-text: #e7eaf0;
    --control-bg: #1e232b;
    --control-text: #e7eaf0;
    /* glass variables (dark) */
    --glass-bg: rgba(23, 26, 33, 0.55);
    --glass-stroke: rgba(255, 255, 255, 0.08);
}

html, body {
    width: 100%;
    overflow-x: hidden;
    margin: 0;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    /* space for fixed topbar */
    padding-top: calc(var(--topbar-offset) + env(safe-area-inset-top, 0px));
}

.container {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 12px;
}

.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1200; /* above map controls (~1000-1100), below modals (1300+) */
    /* glass effect */
    background: var(--glass-bg);
    -webkit-backdrop-filter: saturate(1.2) blur(var(--glass-blur));
    backdrop-filter: saturate(1.2) blur(var(--glass-blur));
    border-bottom: 1px solid var(--glass-stroke);
    box-shadow: var(--shadow);
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
}

.topbar-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.brand {
    display: inline-flex;
}

.brand .title {
    letter-spacing: 0.2px;
}

.title .beta {
    font-size: 0.6em;
    line-height: 1;
    display: inline-block;
    vertical-align: text-top;
}

.logo {
    height: 22px;
    width: auto;
    display: inline-block;
}

html[data-theme="dark"] .logo {
    filter: brightness(0) invert(1);
}

.theme-toggle {
    border: 1px solid var(--border);
    background: var(--control-bg);
    color: var(--control-text);
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.theme-toggle .theme-icon[data-dark] {
    display: none;
}

html[data-theme="dark"] .theme-toggle .theme-icon[data-light] {
    display: none;
}

html[data-theme="dark"] .theme-toggle .theme-icon[data-dark] {
    display: inline;
}

/* Map viewport */
#map-viewport {
    position: relative;
    width: 100%;
    aspect-ratio: 1/1;
    overflow: hidden;
    background: var(--panel);
    border: none;
    border-radius: 0;
    box-shadow: none;
    min-width: 0;
    scroll-margin-top: 72px;
}

#map {
    position: relative;
    display: block;
    height: 100%;
    width: 100%;
    border: none;
    background-color: var(--map-bg);
    transform-origin: 0 0;
    will-change: transform;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: pixelated;
    backface-visibility: hidden;
}

#map.satellite-active {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-color: transparent;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: pixelated;
}

#map.satellite-active {
    background-image: url('map_light.webp');
}

html[data-theme="dark"] #map.satellite-active {
    background-image: url('map_dark.webp');
}

/* Political overlay: implemented as #map::after (base stays standard/satellite) */
#map {
    position: relative;
}

#map::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0;
    /* controlled via CSS variable; default is off */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: 0;
    /* below map content */
}

#map.political-active::after {
    opacity: var(--political-overlay-opacity, 0);
}

#map.political-active::after {
    background-image: url('map_political_light.webp');
}

html[data-theme="dark"] #map.political-active::after {
    background-image: url('map_political_dark.webp');
}

#map>canvas {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: pixelated;
    backface-visibility: hidden;
    will-change: transform;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    /* above political overlay */
}

.stations-layer {
    position: absolute;
    inset: 0;
    z-index: 2; /* above localities (1), below labels order remains per element */
}

/* Localities layer (simple POIs) */
.localities-layer {
    position: absolute;
    inset: 0;
    z-index: 1; /* above canvas but below station markers (same z, later DOM wins) */
}

.locality-marker {
    position: absolute;
    transform: translate(-50%, -50%) scale(calc(1 / var(--map-scale, 1)));
    transform-origin: center center;
}

.locality-marker::before {
    content: '';
    display: block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #1976d2; /* blue */
    border: 1px solid #ffffff;
    box-shadow: 0 0 4px rgba(0,0,0,0.25);
}

html[data-theme="dark"] .locality-marker::before {
    border-color: rgba(255,255,255,0.9);
}

.locality-label {
    position: absolute;
    top: -10px;
    left: 8px;
    background: var(--label-bg);
    color: var(--label-text);
    /* Slightly larger base size and stronger weight for readability; scale with zoom */
    font-size: calc(
        var(--station-label-font-size, 11px)
        * clamp(1, calc(var(--map-scale, 1) * 0.6), 1.5)
    );
    font-weight: 600;
    padding: 2px 5px;
    border-radius: 3px;
    border: 1px solid var(--glass-stroke);
    white-space: nowrap;
    box-shadow: 0 0 4px rgba(0,0,0,0.2);
    transform: translate(0, -100%);
    pointer-events: none;
    /* Improve contrast without being too intrusive */
    opacity: 0.85;
    text-shadow: 0 0 1px rgba(0,0,0,0.35);
}

/* Stronger contrast for dark theme: invert subtle text glow */
html[data-theme="dark"] .locality-label {
    text-shadow: 0 0 1px rgba(255,255,255,0.25);
}

/* At higher zoom (>=2x), increase opacity further */
#map[data-zoom-level="gte2"] .locality-label { opacity: 0.95; }

/* Highlighting for selected search target */
.station-marker.highlighted-station::after {
    content: '';
    position: absolute;
    inset: -8px;
    border: 2px solid #ffcc00;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(255,204,0,0.8);
    pointer-events: none;
}
.locality-marker.highlighted-locality::after {
    content: '';
    position: absolute;
    inset: -10px;
    border: 2px solid #ffcc00;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(255,204,0,0.75);
    pointer-events: none;
}

/* Locality size variants */
.locality-marker.type-large::before,
.locality-marker.type-capital::before {
    width: 8px;
    height: 8px;
    background: #1565c0; /* darker blue */
}
.locality-marker.type-capital::before {
    width: 10px;
    height: 10px;
    background: #0d47a1; /* darkest blue */
}

/* Zoom-based visibility: show small localities only when zoomed in (>= 2x) */
#map[data-zoom-level="lt2"] .locality-marker.type-small .locality-label,
#map[data-zoom-level="lt2"] .locality-marker.type-small::before {
    opacity: 0;
}
#map[data-zoom-level="lt2"] .locality-marker.type-small {
    pointer-events: none;
}

.station-marker {
    position: absolute;
    background-color: #808080;
    border: 1px solid #ffffff;
    border-radius: 50%;
    width: 8px;
    height: 8px;
    cursor: pointer;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
    transform: translate(-50%, -50%) scale(calc(1 / var(--map-scale, 1)));
    transform-origin: center center;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    z-index: 1;
    /* above political overlay */
}

/* Keep default round marker globally – no special shapes here */

html[data-theme="dark"] .station-marker {
    border-color: rgba(255, 255, 255, 0.9);
}

/* No global diamond shape for terminals – keep basic dots */

.station-label {
    position: absolute;
    background-color: var(--label-bg);
    padding: 2px 5px;
    border-radius: 3px;
    font-size: var(--station-label-font-size, 11px);
    white-space: nowrap;
    /* default position above the marker; can be overridden by label-pos-* */
    transform: translate(-50%, calc(-1 * var(--station-label-offset, 120%)));
    pointer-events: none;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
    opacity: 0.6;
    transition: opacity 120ms ease;
    color: var(--label-text);
    z-index: 1;
    /* above political overlay */
}

/* Individual station type styles */
.station-marker.type-metro {
    background-color: #d32f2f;
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

/* hub: square and larger size */
.station-marker.hub {
    background-color: #444444;
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

/* terminal: diamond via pseudo-element – base is transparent */
.station-marker.type-end {
    background-color: transparent;
    border-color: transparent;
}

.station-marker.type-end::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8px;
    height: 8px;
    background-color: #7b1fa2;
    border: 1px solid #ffffff;
    border-radius: 2px;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
    transform: translate(-50%, -50%) rotate(45deg);
}

/* Forced label positions to avoid collisions */
.station-label.label-pos-top {
    transform: translate(-50%, calc(-1 * var(--station-label-offset, 120%)));
}

.station-label.label-pos-bottom {
    transform: translate(-50%, var(--station-label-bottom-offset, 20%));
}

.station-label.label-pos-left {
    transform: translate(calc(-100% - var(--station-label-gap-x, 6px)), -50%);
}

.station-label.label-pos-right {
    transform: translate(var(--station-label-gap-x, 6px), -50%);
}

.station-label.label-hidden {
    display: none;
}

#map[data-zoom-level="lt2"] .station-marker.type-passenger:not(.hub):not(.important) .station-label {
    opacity: 0;
}

#map[data-zoom-level="lt2"] .station-marker.type-passenger:not(.hub):hover .station-label {
    opacity: 0.95;
}

.station-marker:hover .station-label {
    opacity: 0.95;
}

.station-marker.highlight-stop .station-label {
    opacity: 1;
    font-weight: 700;
}

.station-marker.important .station-label {
    opacity: 0.95;
    font-weight: 600;
}

.station-marker.highlighted-station {
    box-shadow: 0 0 0 2px var(--accent), 0 0 10px rgba(0, 0, 0, 0.4);
    z-index: 1002;
}

.station-marker.highlighted-station .station-label {
    opacity: 1;
    font-weight: 700;
}

/* Zoom & tools */
#map-controls, #map-tools-top {
    position: absolute;
    right: 12px;
    display: flex;
    gap: 6px;
    z-index: 1001;
}

#map-controls {
    bottom: 12px;
    flex-direction: column;
    /* styled like mini-menu */
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    -webkit-backdrop-filter: saturate(180%) blur(10px);
    backdrop-filter: saturate(180%) blur(10px);
    padding: 4px;
    gap: 6px;
    -webkit-user-select: none;
    user-select: none;
}

html[data-theme="dark"] #map-controls {
    background: rgba(23, 26, 33, 0.70);
}

#map-tools-top {
    top: 12px;
}

.toggle-btn, .zoom-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--control-bg);
    color: var(--control-text);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease, color 140ms ease;
}

.zoom-btn:hover {
    background: var(--accent-soft-hover);
    border-color: var(--accent);
}

.zoom-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-ring);
    border-color: var(--accent);
}

.toggle-btn[aria-pressed="true"] {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* Map layers mini-menu (glass, like PWA banner) */
.map-menu {
    background: rgba(255, 255, 255, 0.85);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    -webkit-backdrop-filter: saturate(180%) blur(10px);
    backdrop-filter: saturate(180%) blur(10px);
    padding: 8px 10px;
    display: grid;
    gap: 6px;
    min-width: 160px;
}

.map-menu-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-start;
}

.map-menu-option {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
}

.map-menu-option input[type="radio"],
.map-menu-option input[type="checkbox"] {
    accent-color: var(--accent);
}

html[data-theme="dark"] .map-menu {
    background: rgba(23, 26, 33, 0.70);
}

/* Layout */
main {
    padding: 16px 12px 28px;
}

.content {
    display: grid;
    grid-template-columns: minmax(320px, 380px) 1fr;
    gap: 16px;
    align-items: start;
    min-width: 0;
}

@media (max-width: 980px) {
    .content {
        grid-template-columns: 1fr;
    }
}

/* Forms */
#search-panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    box-shadow: var(--shadow);
}

.station-search-row, .search-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

@media (max-width: 480px) {
    .search-row {
        gap: 6px;
    }

    .btn-swap, .btn-search {
        flex: 0 0 auto;
    }
}

.btn-station-search, .btn-clear, .btn-search, .btn-swap {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--control-bg);
    color: var(--control-text);
    cursor: pointer;
}

.btn-clear {
    padding: 8px 10px;
    color: var(--muted);
}

.btn-clear:hover {
    color: var(--control-text);
}

.field {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1 1 200px;
}

.field label {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 4px;
}

.field input {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--panel);
    color: var(--text);
}

.btn-search {
    background: var(--accent-soft-bg);
    color: var(--control-text);
    border-color: var(--accent);
}

.btn-station-search {
    background: var(--accent-soft-bg);
    color: var(--control-text);
    border-color: var(--accent);
}

.btn-search, .btn-station-search, .itinerary .btn-choose {
    transition: background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease, color 140ms ease;
}

.btn-search:hover, .btn-station-search:hover, .itinerary .btn-choose:hover {
    background: var(--accent-soft-hover);
    border-color: var(--accent);
}

.btn-search:focus-visible, .btn-station-search:focus-visible, .itinerary .btn-choose:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-ring);
}

/* Divider */
.or-divider {
    position: relative;
    text-align: center;
    margin: 10px 0;
    color: var(--muted);
}

.or-divider::before, .or-divider::after {
    content: "";
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background: var(--border);
}

.or-divider::before {
    left: 0;
}

.or-divider::after {
    right: 0;
}

.or-divider>span {
    display: inline-block;
    padding: 0 8px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 12px;
    line-height: 1.8;
}

/* Results & legend */
#search-results {
    margin-top: 12px;
    font-size: 14px;
    display: grid;
    gap: 12px;
}

.results-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.itinerary {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
    cursor: pointer;
    transition: background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.itinerary::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 4px;
    background: var(--route-color, transparent);
}

.itinerary.selected {
    border-color: var(--border);
    box-shadow: 0 0 0 1px color-mix(in oklab, var(--route-color, var(--accent)) 16%, transparent), 0 0 0 4px color-mix(in oklab, var(--route-color, var(--accent)) 10%, transparent), 0 0 22px 0 color-mix(in oklab, var(--route-color, var(--accent)) 24%, transparent);
}

.itinerary[tabindex]:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-ring);
}

.itinerary-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    margin-bottom: 6px;
}

.itinerary-meta {
    font-weight: 400;
    color: var(--muted);
    font-size: 13px;
}

/* Timeline-style itinerary layout */
.itinerary .timeline {
    margin-top: 8px;
    display: grid;
    grid-template-columns: 28px 1fr;
    position: relative;
}

.timeline-node {
    display: contents; /* let children align to grid columns */
}

.timeline-node .node-icon {
    grid-column: 1 / 2;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--control-bg);
    border: 3px solid var(--border);
    margin: 6px 0;
    z-index: 1;
    margin-left: 5px;
}

.timeline-node .node-label {
    grid-column: 2 / 3;
    align-self: center;
    font-size: 16px;
    font-weight: 700;
    padding: 2px 0;
    margin-left: 4px;
}

.timeline-node.transfer .node-icon {
    background: transparent;
    border-color: var(--node-color, var(--accent));
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--node-color, var(--accent)) 20%, transparent) inset;
}

.timeline-node.start .node-icon {
    background: #00000000;
    border-color: var(--node-color, var(--accent));
}

.timeline-node.end .node-icon {
    background: var(--node-color, var(--accent));
    border-color: var(--node-color, var(--accent));
    position: relative;
}

.timeline-node.end .node-icon::after {
    content: '';
    position: absolute;
    inset: 0;
    margin: auto;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #fff;
}

.timeline-leg {
    grid-column: 1 / -1;
    position: relative;
    padding: 4px 0 8px 0;
}

.timeline-leg::before {
    content: '';
    position: absolute;
    left: 11px;
    width: 6px;
    top: 0;
    bottom: 0;
    border-radius: 4px;
    background: color-mix(in oklab, var(--leg-color, var(--accent)) 38%, transparent);
    pointer-events: none; /* don't block clicks on details */
}

/* When a leg has an icon, create a gap in the middle for the glyph */
.timeline-leg.has-icon::before {
    background: linear-gradient(
        to bottom,
        color-mix(in oklab, var(--leg-color, var(--accent)) 38%, transparent) 0,
        color-mix(in oklab, var(--leg-color, var(--accent)) 38%, transparent) calc(50% - 12px),
        transparent calc(50% - 12px),
        transparent calc(50% + 12px),
        color-mix(in oklab, var(--leg-color, var(--accent)) 38%, transparent) calc(50% + 12px),
        color-mix(in oklab, var(--leg-color, var(--accent)) 38%, transparent) 100%
    );
}

/* Centered glyph (square colored by line with the transport icon as mask) */
.timeline-leg .leg-glyph {
    position: absolute;
    left: 14px; /* center of the 6px rail at 11px */
    top: 50%;
    transform: translate(-50%, -50%);
    display: block;
    width: 22px;
    height: 22px;
    /* No square background; draw only the icon shape via mask */
    background: var(--leg-color, var(--accent));
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
    -webkit-mask-size: 90% 90%;
    mask-size: 90% 90%;
    z-index: 1;
}

.timeline-leg .leg-header {
    grid-column: 2 / 3;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-left: 8px;
    margin-left: 24px;
}

.count-chip {
    display: block;
    background: var(--control-bg);
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px 10px;
    font-size: 13px;
}

details.leg-details { display: inline-block; }

details.leg-details summary {
    list-style: none;
    cursor: pointer;
    position: relative;
    display: block;
}

details.leg-details summary::after {
    content: '▾';
    color: var(--muted);
    margin-left: 8px;
    float: right;
}

details.leg-details summary::-webkit-details-marker {
    display: none;
}

details.leg-details[open] summary::after {
    content: '▴';
}

.leg-stations-box {
    margin-top: 0;
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--muted);
    border-radius: 0 0 10px 10px;
    padding: 8px 10px;
}

/* Seamless connection between summary and details content */
details.leg-details[open] .count-chip {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}
details.leg-details:not([open]) .leg-stations-box { display: none; }

.leg-stations-box .sep {
    opacity: 0.6;
    padding: 0 4px;
}

.leg {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 10px;
    align-items: baseline;
    padding: 6px 0;
    border-top: 1px dashed var(--border);
}

.leg:first-of-type {
    border-top: 0;
    padding-top: 0;
}

.leg-index {
    font-weight: 700;
    color: var(--muted);
}

.leg .line {
    font-weight: 600;
}

/* (type badge removed from UI) */

.leg .stations {
    color: var(--muted);
    grid-column: 2 / 3;
}

.leg .stations .station.skipped {
    opacity: 0.6;
    text-decoration: line-through;
}

.leg .stations .sep {
    opacity: 0.5;
    padding: 0 2px;
}

.leg .board, .leg .alight {
    grid-column: 2 / 3;
}

.leg .alight {
    font-weight: 600;
}

.line-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: color-mix(in oklab, var(--route-color, #ccc) 18%, transparent);
}

.line-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--route-color, #999);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1) inset;
}

.itinerary-footer {
    margin-top: 6px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
}

.btn-choose {
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--accent);
    background: color-mix(in oklab, var(--accent) 10%, var(--control-bg));
    color: var(--control-text);
    cursor: pointer;
}

.itinerary.selected .btn-choose {
    background: color-mix(in oklab, var(--accent) 22%, var(--control-bg));
    color: #fff;
    border-color: var(--accent);
}

/* Filters */
#type-filters, #priority-options {
    margin-top: 10px;
    margin-bottom: 10px;
}

.filters-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filters-row label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--control-bg);
    color: var(--control-text);
    cursor: pointer;
}

.filters-row input[type="checkbox"] {
    accent-color: var(--accent);
}

/* Accent and focus for radio as well (priority options) */
.filters-row input[type="radio"] {
    accent-color: var(--accent);
}

.filters-row label:hover {
    background: var(--accent-soft-hover);
    border-color: var(--accent);
}

.filters-row label:focus-within {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-ring);
    border-color: var(--accent);
}

/* Dropdowns */
.dropdown summary {
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0;
    /* zapewnimy separację CSS-em na value, gap bywa różnie wspierany */
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--control-bg);
    color: var(--control-text);
    cursor: pointer;
    position: relative;
}

.dropdown summary::after {
    content: '▾';
    position: absolute;
    right: 10px;
    color: var(--muted);
}

.dropdown[open] summary {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.dropdown .filters-row {
    border: 1px solid var(--border);
    border-top: 0;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
    padding: 10px;
    margin-top: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(160px, 1fr));
    gap: 8px;
}

.dropdown-title {
    font-weight: 600;
}

.dropdown-value {
    color: var(--muted);
    font-size: 13px;
    margin-left: 10px;
}

.dropdown-value::before {
    content: '';
    color: var(--muted);
}

@media (max-width: 520px) {
    .dropdown .filters-row {
        grid-template-columns: 1fr;
    }
    /* Hide Export entry point on phones */
    .topbar .topbar-actions a[href="export.html"] { display: none !important; }
}

/* Export page: block on small screens */
@media (max-width: 720px) {
    body.export-blocked .export-layout { filter: blur(2px); pointer-events: none; -webkit-user-select: none; user-select: none; }
    body.export-blocked::after {
        content: 'Eksport jest dostępny tylko na większych ekranach. Otwórz tę stronę na komputerze.';
        position: fixed;
        inset: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 20px;
        text-align: center;
        background: color-mix(in oklab, var(--panel) 70%, rgba(0,0,0,0.6));
        color: var(--text);
        z-index: 9999;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    }
}

/* Alerts */
.alert {
    margin-top: 10px;
    padding: 10px 12px;
    border: 1px solid #f1b0b0;
    background: color-mix(in oklab, #f1b0b0 14%, var(--panel));
    color: #5a1b1b;
    border-radius: 10px;
}

.hidden {
    display: none !important;
}

/* Legend & sections */
#legend {
    margin-top: 12px;
    padding: 10px 0 0;
    border-top: 1px solid var(--border);
    color: var(--text);
    font-size: 13px;
}

.legend-group {
    margin-top: 10px;
}

.legend-title {
    font-weight: 700;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 6px;
}

.legend-row {
    column-count: 2;
    column-gap: 18px;
    column-fill: balance;
}

@media (max-width: 600px) {
    .legend-row {
        column-count: 1;
    }
}

.legend-item {
    break-inside: avoid;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1px solid #fff;
    box-shadow: 0 0 2px rgba(0, 0, 0, .2);
}

.legend-line {
    width: 36px;
    height: 0;
    border-top: 3px solid #999;
    opacity: .6;
}

.legend-empty {
    color: var(--muted);
}

/* Cards and wrappers */
.map-section {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    box-shadow: var(--shadow);
}

/* Ads */
.promo-slot {
    background: var(--panel);
    border: 1px dashed var(--border);
    border-radius: 10px;
    display: grid;
    place-items: center;
    color: var(--muted);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.promo-slot picture, .promo-slot img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    display: block;
    object-fit: contain;
}

.promo-below-search {
    margin-top: 12px;
}

/* Footer */
.site-footer {
    margin-top: 12px;
    background: var(--panel);
    border-top: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.footer-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px;
    font-size: 13px;
    color: var(--muted);
}

@media (max-width: 600px) {
    .footer-inner {
        flex-direction: column;
        align-items: flex-start;
    }
}

.btn {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--control-bg);
    color: var(--control-text);
    cursor: pointer;
}

.btn-success {
    border-color: #4aa564;
    background: color-mix(in oklab, #4aa564 10%, transparent);
}

.btn-info {
    border-color: #5aa3e8;
    background: color-mix(in oklab, #5aa3e8 10%, transparent);
}

.btn-danger {
    border-color: #f1b0b0;
    background: color-mix(in oklab, #f1b0b0 10%, transparent);
}

.btn-secondary {
    border-color: var(--border);
    background: color-mix(in oklab, var(--control-bg) 90%, transparent);
    color: var(--control-text);
}

/* Topbar-only: minimalist actions (no background/border, consistent spacing) */
.topbar .btn-secondary,
.topbar .link-plain {
    padding: 6px 8px;
    border-radius: 8px;
    background: transparent;
    border-color: transparent;
}

.topbar .theme-toggle {
    background: transparent;
    border: none;
    padding: 6px 8px;
}

.topbar .btn-secondary:hover,
.topbar .link-plain:hover,
.topbar .theme-toggle:hover {
    background: var(--accent-soft-bg);
}

.topbar .btn-secondary:focus-visible,
.topbar .link-plain:focus-visible,
.topbar .theme-toggle:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-ring);
    border-radius: 8px;
}

.btn-warning {
    border-color: #f6c453;
    background: color-mix(in oklab, #f6c453 14%, transparent);
    color: #5a3d00;
}

.link-plain {
    text-decoration: none;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Contributors modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease-in-out;
    z-index: 1300;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease-in-out;
    z-index: 1301;
    /* above overlay */
    padding: 16px;
}

.modal.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    width: min(720px, 100%);
    max-height: min(80vh, 100%);
    background: rgba(255, 255, 255, 0.85);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    -webkit-backdrop-filter: saturate(180%) blur(10px);
    backdrop-filter: saturate(180%) blur(10px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-content .modal-header {
    background: transparent;
}

html[data-theme="dark"] .modal-content {
    background: rgba(23, 26, 33, 0.70);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    margin: 0;
    font-size: 18px;
    line-height: 1.2;
}

.modal-close {
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    align-self: center;
    background: var(--control-bg);
    color: var(--control-text);
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    -webkit-tap-highlight-color: transparent;
    transition: background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease, color 140ms ease;
}

.modal-close:hover {
    background: var(--accent-soft-hover);
    border-color: var(--accent);
}

.modal-close:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-ring), 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* On mobile keep a larger touch target */
@media (max-width: 520px) {
    .modal-close {
        width: 32px;
        height: 32px;
        font-size: 18px;
    }
}

.modal-body {
    padding: 16px 20px 14px 20px;
    overflow: auto;
}

.modal-body #contributors-content {
    background: var(--panel);
    color: inherit;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 14px 16px;
}

.modal-body #contributors-content p {
    margin: 0 0 8px;
}

.modal-body #contributors-content ul {
    margin: 8px 0 0 18px;
}

.modal-body #contributors-content li {
    margin: 4px 0;
}

.modal-body h2 {
    font-size: 16px;
    margin: 8px 0;
}

.modal-body h3 {
    font-size: 14px;
    margin: 6px 0;
    opacity: .9;
}

.no-scroll {
    overflow: hidden;
}

/* Footer contributors trigger — make it look like a subtle link */
.site-footer .btn-secondary,
.site-footer .link-plain {
    padding: 0;
    background: transparent;
    border: none;
    color: var(--muted);
    text-decoration: underline;
    border-radius: 0;
}

.site-footer .btn-secondary:hover,
.site-footer .link-plain:hover {
    color: var(--text);
    text-decoration-color: var(--text);
}

.site-footer .btn-secondary:focus-visible,
.site-footer .link-plain:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-ring);
    border-radius: 6px;
}

/* Server status widget */
.mc-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    font-size: 13px;
    color: var(--muted);
}

.mc-status .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #bbb;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15) inset;
}

.mc-status.online .dot {
    background: #2e7d32;
}

.mc-status.offline .dot {
    background: #c62828;
}

/* PWA install banner */
.pwa-banner {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 1100;
    /* above map-controls (1001) and topbar (100) */
    /* translucent background + backdrop blur */
    background: rgba(255, 255, 255, 0.85);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    transition: transform .2s ease, opacity .2s ease;
    -webkit-backdrop-filter: saturate(180%) blur(10px);
    backdrop-filter: saturate(180%) blur(10px);
}

.pwa-banner.hide {
    opacity: 0;
    transform: translateY(8px);
}

.pwa-banner-content {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 12px 16px;
}

.pwa-banner-text {
    flex: 1;
}

.pwa-banner-desc {
    opacity: .9;
    font-size: .95em;
    margin-top: 2px;
}

.pwa-banner-how {
    opacity: .9;
    font-size: .9em;
    margin-top: 6px;
}

.pwa-banner-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pwa-banner-never {
    font-size: .9em;
    opacity: .9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.pwa-banner-never input[type="checkbox"] {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
}

.pwa-banner-close {
    position: absolute;
    inset: 6px 8px auto auto;
    background: transparent;
    color: inherit;
    border: 0;
    font-size: 20px;
    cursor: pointer;
}

/* Mobile: layout and docking at the bottom */
@media (max-width: 520px) {
    .pwa-banner {
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 12px 12px 0 0;
        /* square bottom corners */
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }

    .pwa-banner-content {
        flex-direction: column;
        align-items: flex-start;
    }

    .pwa-banner-actions {
        width: 100%;
        justify-content: space-between;
    }
}

/* Desktop – compact window in the top-right corner */
@media (min-width: 981px) {
    .pwa-banner {
        top: 64px;
        right: 16px;
        left: auto;
        bottom: auto;
        width: auto;
        max-width: 360px;
    }

    .pwa-banner-content {
        flex-direction: column;
        align-items: stretch;
        padding: 12px 14px 10px;
        gap: 10px;
    }

    .pwa-banner-actions {
        justify-content: space-between;
    }
}

/* Desktop: hide text close button, show the cross icon */
@media (min-width: 521px) {
    .pwa-close-text {
        display: none;
    }
}

/* Mobile: show text close button, hide the cross icon */
@media (max-width: 520px) {
    .pwa-banner-close {
        display: none;
    }
}

/* Dark theme – more transparent, dark background */
html[data-theme="dark"] .pwa-banner {
    background: rgba(23, 26, 33, 0.70);
}

/* Primary button (used in PWA banner) */
.btn-primary {
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-primary:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-ring);
}