:root {
    --panel-text: #e8e8ea;
    --accent-blue: #2b5cff;
    --accent-blue-hover: #244de0;
    --icon-btn-bg: #9aa0a6;
    --side-btn-bg: #ffffff;
    --side-btn-color: #111827;
}

body {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.6;
    overflow-x: visible;
    background: none;
}

/* ── Maps ── */
#circles,
#basemap {
    width: 100%;
    height: 100vh;
}
#basemap canvas {
    opacity: 0.6;
}

/* ── Loading overlay ── */
#loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(24, 24, 28, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}
#loading-overlay[hidden] { display: none; }

#loading-spinner {
    width: 44px;
    height: 44px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
#loading-text {
    color: #fff;
    font: 500 1rem/1.4 inherit;
    letter-spacing: 0.01em;
}

/* ── Map title header ── */
.title-wrapper {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 11;
    text-align: center;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.city-selector-link {
    text-decoration: none;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.2s ease;
    cursor: pointer;
}
.city-selector-link:hover { transform: scale(1.02); }

.map-title {
    background: var(--panel-bg);
    color: white;
    border-radius: 8px 8px 0 0;
    backdrop-filter: saturate(1.2) blur(6px);
    padding: 8px 14px 8px 18px;
    font: 600 clamp(20px, 2.8vw, 28px)/1.2 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    max-width: 90vw;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.map-title svg {
    opacity: 0.7;
    transition: opacity 0.2s;
    padding-top: 5px;
}
.city-selector-link:hover .map-title svg { opacity: 1; }

.subheader {
    display: inline-block;
    background: var(--panel-bg);
    padding: 6px 12px;
    border-radius: 8px;
    color: white;
    font: 500 clamp(12px, 1.6vw, 16px)/1.2 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    backdrop-filter: saturate(1.2) blur(6px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    max-width: 35vw;
}

/* ── Logo ── */
.logo-fixed {
    position: fixed;
    top: max(0px, env(safe-area-inset-top));
    z-index: 1000;
    display: inline-block;
    height: 130px;
    width: 110px;
    margin: 10px;
}

/* ── Side buttons ── */
.side-button {
    position: fixed;
    z-index: 1000;
    width: 35px;
    height: 35px;
    padding: 0;
    display: grid;
    place-items: center;
    background: var(--side-btn-bg);
    color: var(--side-btn-color);
    border: none;
    border-radius: 8px;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
    cursor: pointer;
}
.general-info {
    top: max(170px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
}
.general-info svg { width: 22px; height: 22px; }

/* ── Panels (nav-panel + legend share base styles) ── */
.nav-panel,
.legend {
    background: var(--panel-bg);
    color: var(--panel-text);
    position: absolute;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    backdrop-filter: saturate(1.2) blur(6px);
    max-width: min(86vw, 360px);
    overflow: hidden;
    bottom: 10px;
}
.nav-panel { z-index: 11; min-width: 360px; right: 10px; }
.legend    { z-index: 10; min-width: 260px; left: 10px; }

/* ── Panel + popover headers ── */
aside header,
.pop-inner > header {
    background: var(--panel-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    font-weight: 600;
    border-bottom: 1px solid white;
}
.pop-inner > header {
    margin: -10px -12px 0;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
}

/* ── Time form ── */
#timeForm {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 8px 10px 10px;
}
#timeForm label { display: grid; gap: 4px; }
#timeForm select {
    background: var(--panel-bg);
    color: var(--panel-text);
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255);
    font: inherit;
}

.btn-primary {
    background: var(--accent-blue);
    color: #fff;
    border: 0;
    border-radius: 6px;
    padding: 3px;
    font: inherit;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.02s ease;
}
.btn-primary:hover { background: var(--accent-blue-hover); }
#timeForm .btn-primary { grid-column: 1 / -1; }
#timeForm .btn-primary:not(:disabled):active { transform: translateY(1px); }
#timeForm .btn-primary:disabled {
    background: #3a3f4b;
    color: #a9afbb;
    cursor: not-allowed;
    opacity: 0.8;
    pointer-events: none;
}

/* ── Collapsible panel bodies ── */
#navigation-body,
#legend-body {
    overflow: hidden;
    height: auto;
    transition: height 0.5s ease;
}
#navigation-body[hidden],
#legend-body[hidden] { display: none; }

#legend-body { padding: 4px 0; }

.nav-panel:has(.legend__toggle[aria-expanded="false"]) #navigation-body { height: 0; padding: 0; }
.nav-panel:has(.legend__toggle[aria-expanded="false"]) .navigation__header { border: 0; }
.legend:has(.legend__toggle[aria-expanded="false"]) #legend-body { height: 0; padding: 0; }
.legend:has(.legend__toggle[aria-expanded="false"]) .legend__header { border: 0; }

/* ── Legend table ── */
.legend table { border-collapse: collapse; width: 100%; }
.legend th,
.legend td { padding: 7px 10px; border-bottom: 1px solid rgba(0, 0, 0, 0.05); }
.legend tbody tr:last-child td { border-bottom: 0; }

.swatch {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.13);
    display: inline-block;
    margin-right: 8px;
    vertical-align: -2px;
}

/* ── Icon buttons ── */
.icon-btn {
    width: 20px;
    height: 20px;
    display: inline-grid;
    place-items: center;
    padding: 0;
    border: 0;
    cursor: pointer;
    border-radius: 50%;
    background: var(--icon-btn-bg);
    color: #111827;
    position: relative;
    transition: background 0.15s ease;
}
.icon-btn:hover { background: white; }
.icon-btn:focus-visible { outline: none; }
.icon-btn::before {
    content: "";
    position: absolute;
    inset: -5px;
}

/* ── Info popover layout ── */
.info-popover {
    position: relative;
    display: flex;
    gap: 10px;
    margin-left: auto;
    line-height: 0;
}

/* ── Toggle chevron ── */
.legend__toggle .chev {
    width: 20px;
    height: 20px;
    color: black;
    transition: transform 0.5s ease;
    transform-origin: 50% 50%;
    transform: rotate(180deg);
}
.legend__toggle[aria-expanded="true"] .chev { transform: rotate(0deg); }

/* ── Popover panel ── */
.pop {
    position: absolute;
    z-index: 1000;
    min-inline-size: 220px;
    max-inline-size: min(86vw, 360px);
    color: var(--panel-text);
    background: var(--panel-bg);
    border-radius: 8px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.3);
    backdrop-filter: saturate(1.2) blur(6px);
    padding: 10px 12px;
    transform: translateY(-8px);
}
.pop[hidden] { display: none !important; }
.pop[data-placement="bottom"] {
    inset: 100% auto auto 0;
    transform: translateY(8px);
}
.pop-inner { display: grid; gap: 6px; }
.pop-inner p { margin: 0; line-height: 1.5; color: var(--panel-text); }

.pop-close {
    padding: 2px;
    border: 0;
    background: transparent;
    cursor: pointer;
    color: var(--icon-btn-bg);
    font-size: 14px;
    border-radius: 4px;
}
.pop-close:hover { color: var(--panel-text); }
.pop-close:focus-visible { outline: none; }

/* ── Popover arrow ── */
.pop-arrow {
    position: absolute;
    inline-size: 10px;
    block-size: 10px;
    background: #1d1f24;
    transform: rotate(45deg);
}
.pop:not([data-placement="bottom"]) .pop-arrow { bottom: -6px; left: 12px; }
.pop[data-placement="bottom"] .pop-arrow { top: -5px; left: 12px; }
.pop[data-align="end"] .pop-arrow { left: auto; right: 12px; }

/* ── Map hints ── */
#map-hint,
#map-hint-action {
    position: fixed;
    left: 50%;
    top: 38%;
    transform: translateX(-50%);
    z-index: 12;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 20px;
    font-size: 0.9rem;
    pointer-events: none;
    backdrop-filter: blur(6px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
    white-space: nowrap;
    max-width: calc(100vw - 24px);
}
#map-hint svg,
#map-hint-action svg { flex-shrink: 0; }
#map-hint[hidden],
#map-hint-action[hidden] { display: none; }

#map-hint {
    background: var(--panel-bg);
    color: white;
    transition: opacity 0.3s ease;
}
#map-hint.map-hint--hidden { opacity: 0; }
#map-hint-action { background: var(--accent-blue); color: #fff; }

@keyframes btn-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(43, 92, 255, 0.7); }
    60%  { box-shadow: 0 0 0 8px rgba(43, 92, 255, 0); }
    100% { box-shadow: 0 0 0 0 rgba(43, 92, 255, 0); }
}
.btn--pulse { animation: btn-pulse 0.7s ease-out 2; }

/* ── MapLibre controls ── */
.maplibregl-ctrl-group { border-radius: 8px; }
.maplibregl-ctrl-group button { width: 35px; height: 35px; }
.maplibregl-ctrl-group .maplibregl-ctrl-icon { background-size: 80% 80%; }

/* ── Onboarding / tutorial ── */
.skip-btn {
    background: transparent;
    border: none;
    color: #d0d0d0;
    font-size: 14px;
    cursor: pointer;
    text-decoration: underline;
    transition: color 0.2s;
}
.skip-btn:hover { color: #ffffff; }

.tutorial-buttons {
    display: none;
    justify-content: space-between;
    align-items: center;
}
.tutorial-buttons button {
    padding: 6px 12px;
    border: none;
    border-radius: 8px;
    font: inherit;
    cursor: pointer;
    background: var(--accent-blue);
    color: white;
}
.tutorial-buttons .skip-btn {
    background: transparent;
    color: #d0d0d0;
    padding: 0;
}
.tutorial-progress { margin: 0 8px; }

.floating-clone {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    margin: 0;
    transform: translate3d(0, 0, 0);
}
#info-btn-onboarding { display: none; }

/* ── Responsive ── */
@media (prefers-reduced-motion: reduce) {
    .legend__toggle .chev,
    #legend-body,
    #navigation-body { transition: none; }
}

@media (max-width: 640px) {
    .map-title { font-size: 1.5rem; line-height: 1.0; }
    .subheader { font-size: 0.8rem; }

    .bottom-dock {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
        display: grid;
        gap: 12px;
        z-index: 11;
        pointer-events: none;
    }
    .bottom-dock > .legend,
    .bottom-dock > .nav-panel {
        pointer-events: auto;
        position: static !important;
        max-width: none !important;
    }

    .logo-fixed { height: 80px; width: 68px; }

    #map-hint,
    #map-hint-action {
        font-size: clamp(0.7rem, 3.5vw, 0.9rem);
        padding: 8px 12px;
        gap: 6px;
        overflow: hidden;
        max-width: calc(100vw - 32px);
    }
    #map-hint svg,
    #map-hint-action svg { width: 13px; height: 13px; }
}

@media (min-width: 641px) and (max-width: 1024px) {
    .bottom-dock { display: flex; }
    .logo-fixed { height: 80px; width: 68px; }
}
