html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #1a1a1a;
    color: #1a1a1a;
}

#map {
    position: absolute;
    inset: 0;
}

/* Floating search bar — pill-shaped, near the top */
#search-bar {
    position: absolute;
    top: max(env(safe-area-inset-top, 0px) + 12px, 12px);
    left: 24px;
    right: 24px;
    height: 48px;
    background: #ffffff;
    border-radius: 9999px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    display: flex;
    align-items: center;
    padding: 0 16px 0 0;
    z-index: 10;
    cursor: text;
    overflow: hidden;
}

#search-bar .icon {
    width: 24px;
    height: 24px;
    flex: 0 0 24px;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    color: #1976d2; /* primary blue */
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

#search-bar .icon-left {
    color: #5f6368; /* on-surface-variant grey */
}

#search-bar .icon-share {
    color: #5f6368;
    margin-right: 12px;
    opacity: 1;
    transition: opacity 400ms ease;
}



#search-bar.searching .icon-share,
#search-bar.no-selection .icon-share {
    opacity: 0;
    pointer-events: none;
    margin-right: -24px; /* collapse the slot when hidden */
}

#search-bar .icon-menu {
    color: #5f6368;
    opacity: 1;
    transition: opacity 400ms ease;
}

#search-bar .icon-clear {
    color: #5f6368;
    margin-left: -24px; /* overlap menu slot so it stays in the same place */
    opacity: 0;
    pointer-events: none;
    transition: opacity 400ms ease;
}

#search-bar.searching .icon-menu {
    opacity: 0;
    pointer-events: none;
}

#search-bar.searching .icon-clear {
    opacity: 1;
    pointer-events: auto;
}

#search-bar .icon svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
    position: absolute;
    inset: 0;
}

/* Left brand slot: logo fills the full bar height so its circular boundary
 * aligns with the pill's left curve. The magnifier shown while searching
 * sits centred at standard icon size. */
#search-bar .icon-left {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    margin-right: 4px;
}

#search-bar .icon-left .brand-logo {
    position: absolute;
    inset: 0;
    width: 48px;
    height: 48px;
    transition: opacity 300ms ease;
}

#search-bar .icon-left .brand-search {
    position: absolute;
    inset: 12px;
    width: 24px;
    height: 24px;
    opacity: 0;
    fill: currentColor;
    transition: opacity 300ms ease;
}
#search-bar.searching .icon-left .brand-logo { opacity: 0; }
#search-bar.searching .icon-left .brand-search { opacity: 1; }
#search-bar.searching .icon-left { color: #5f6368; }

/* Right-side magnifier shortcut, hidden while editing. */
#search-bar .icon-search-trigger {
    color: #5f6368;
    margin-right: 8px;
    opacity: 1;
    transition: opacity 200ms ease;
}

#search-bar.searching .icon-search-trigger,
#search-bar:not(.no-selection) .icon-search-trigger {
    opacity: 0;
    pointer-events: none;
    margin-right: -24px;
}

#search-bar .icon-share svg {
    width: 20px;
    height: 20px;
    inset: 2px;
    fill: none;
}

.search-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    min-width: 0;
    position: relative;
}

/* Compact block code shown at the right edge of the search bar when a
 * block is selected (e.g. [1008ka1m]). Subtle: smaller, lighter weight,
 * muted colour. Hidden while the user is actively typing in the input. */
.search-code {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #ffffff;
    background: #1976d2;
    padding: 2px 10px;
    border-radius: 9999px;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    border: none;
    font-family: inherit;
}
.search-code:active { background: #1565c0; }
.search-code:empty { display: none; }
#search-bar.searching .search-code { display: none; }

#search-input {
    width: 100%;
    height: 24px;
    border: none;
    outline: none;
    background: transparent;
    font-size: 16px;
    font-weight: 500;
    color: #1a1a1a;
    text-align: left;
    -webkit-appearance: none;
    appearance: none;
    transition: padding-right 150ms ease;
}
#search-bar.idle #search-input.has-code { padding-right: 80px; }

/* Suppress native clear buttons on type="search" — we have our own. */
#search-input::-webkit-search-cancel-button,
#search-input::-webkit-search-decoration { -webkit-appearance: none; display: none; }

#search-bar.idle.no-selection #search-input { text-align: center; }

#search-results {
    position: absolute;
    top: calc(max(env(safe-area-inset-top, 0px) + 12px, 12px) + 56px);
    left: 24px;
    right: 24px;
    max-height: 320px;
    overflow-y: auto;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    z-index: 9;
}

#menu-dropdown {
    position: absolute;
    top: calc(max(env(safe-area-inset-top, 0px) + 12px, 12px) + 56px);
    right: 24px;
    min-width: 160px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
    padding: 6px 0;
    z-index: 12;
}

.menu-item {
    display: block;
    width: 100%;
    text-align: left;
    border: none;
    background: none;
    padding: 12px 18px;
    font-size: 14px;
    color: #1a1a1a;
    cursor: pointer;
    font-family: inherit;
}

.menu-item:hover { background: #f5f5f5; }

.result-row {
    padding: 14px 20px;
    font-size: 16px;
    color: #1a1a1a;
    cursor: pointer;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.08);
}

.result-row:last-child { border-bottom: none; }
.result-row:hover, .result-row.selected { background: #f5f5f5; }

#geolocate-btn {
    position: absolute;
    /* search bar top + bar height + gap */
    top: calc(max(env(safe-area-inset-top, 0px) + 12px, 12px) + 56px);
    right: 24px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: transparent;
    border: 2px solid #ffffff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
    cursor: pointer;
    /* Sit behind #search-results (z-index 9) so an open results list
     * occludes the button rather than vice versa. */
    z-index: 8;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background-color 200ms ease, border-color 200ms ease;
}

#geolocate-btn:hover { background: rgba(255, 255, 255, 0.15); }
#geolocate-btn.locating,
#geolocate-btn.tracking {
    background: #1976d2;
    border-color: #1976d2;
    color: #ffffff;
}
#geolocate-btn.tracking:hover { background: #1565c0; }

#geolocate-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

#dialog {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
}

#dialog[hidden] { display: none; }

.dialog-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
}

.dialog-card {
    position: relative;
    max-width: 320px;
    margin: 0 24px;
    background: #ffffff;
    border-radius: 16px;
    padding: 20px 20px 12px 20px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

.dialog-title {
    margin: 0 0 8px 0;
    font-size: 18px;
    font-weight: 600;
    color: #1a1a1a;
}

.dialog-body {
    margin: 0 0 16px 0;
    font-size: 14px;
    color: #5f6368;
    line-height: 1.4;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.dialog-btn {
    border: none;
    background: none;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 500;
    color: #1976d2;
    cursor: pointer;
    border-radius: 8px;
}

.dialog-btn:hover { background: rgba(25, 118, 210, 0.08); }
.dialog-cancel { color: #5f6368; }

/* Help / About / Settings overlay.
 *
 * Mobile (default): full-width panel, no scrim.
 * Desktop (>= 768px): right-anchored 480 px drawer with a scrim covering
 *   the rest of the map.
 *
 * The whole overlay is always in the DOM; .open toggles visibility so the
 * slide / fade transitions can run. */
#screen-overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
    pointer-events: none;
    color: #1a1a1a;
}

#screen-overlay.open { pointer-events: auto; }

.screen-scrim {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    transition: background 200ms ease;
}

.screen-panel {
    position: absolute;
    inset: 0;
    background: #f7f9fc;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateX(100%);
    transition: transform 280ms cubic-bezier(0.2, 0, 0, 1);
    will-change: transform;
}

#screen-overlay.open .screen-panel { transform: translateX(0); }

@media (min-width: 768px) {
    .screen-panel {
        left: auto;
        width: min(480px, 92vw);
        box-shadow: -4px 0 32px rgba(0, 0, 0, 0.18);
    }
    #screen-overlay.open .screen-scrim { background: rgba(0, 0, 0, 0.32); }
}

.screen-header {
    display: flex;
    align-items: center;
    padding: max(env(safe-area-inset-top, 0px), 0px) 8px 0 8px;
    height: calc(56px + max(env(safe-area-inset-top, 0px), 0px));
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    flex: 0 0 auto;
}

.screen-close {
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    cursor: pointer;
    color: #1a1a1a;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    margin-left: auto;
}

.screen-close:hover { background: rgba(0, 0, 0, 0.06); }

.screen-close svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.screen-title {
    margin: 0 0 0 16px;
    font-size: 20px;
    font-weight: 600;
    color: #1a1a1a;
}

.screen-content {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 24px 28px 40px 28px;
    line-height: 1.6;
    font-size: 15px;
    color: #2a2a2a;
}

.screen-content > * { max-width: 60ch; }

.screen-content .lead {
    font-size: 16px;
    color: #1a1a1a;
}

.screen-content h3 {
    display: block;
    margin: 28px 0 10px 0;
    font-size: 18px;
    font-weight: 700;
    color: #1a1a1a;
    border-bottom: 3px solid #1976d2;
    padding-bottom: 6px;
    line-height: 1.3;
}

.screen-content h3:first-child { margin-top: 4px; }

/* Status heading rendered as a red pill — matches the top-bar status
 * badge so the link is visually obvious. Always red regardless of the
 * heading-style picker below. */
.screen-content h3.status-heading {
    display: inline-block;
    background: #d32f2f;
    color: #ffffff;
    padding: 6px 16px;
    border: none;
    border-radius: 9999px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1.3;
}

.screen-content h4 {
    margin: 20px 0 6px 0;
    font-size: 15px;
    font-weight: 600;
    color: #1976d2;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.screen-content p { margin: 0 0 14px 0; }
.screen-content ul { padding-left: 22px; margin: 10px 0 16px 0; }
.screen-content li { margin-bottom: 8px; }
.screen-content em { font-style: normal; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.92em; background: rgba(25, 118, 210, 0.08); padding: 1px 6px; border-radius: 4px; color: #1456a0; }
.screen-content a { color: #1976d2; text-decoration: none; }
.screen-content a:hover { text-decoration: underline; }

.about-logo {
    display: flex;
    justify-content: center;
    margin: 8px 0 8px 0;
}

.about-version {
    text-align: center;
    margin: 0 0 24px 0 !important;
    color: #6b7280;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    max-width: none !important;
}

#toast {
    position: fixed;
    left: 50%;
    bottom: max(env(safe-area-inset-bottom, 0px) + 24px, 24px);
    transform: translateX(-50%);
    background: rgba(26, 26, 26, 0.92);
    color: #ffffff;
    padding: 10px 18px;
    border-radius: 9999px;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    z-index: 20;
    opacity: 0;
    transition: opacity 250ms ease;
    pointer-events: none;
}

/* Phase-status badge anchored under the search bar — same pill styling
 * as the code badge but red, centred, and wider. Hidden while the user
 * is searching so it doesn't fight the results dropdown. */
#status-badge {
    position: absolute;
    top: calc(max(env(safe-area-inset-top, 0px) + 12px, 12px) + 56px + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #d32f2f;
    color: #ffffff;
    border: none;
    padding: 4px 14px;
    border-radius: 9999px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    z-index: 9;
    letter-spacing: 0.02em;
}
#status-badge:active { background: #b71c1c; }
#search-bar.searching ~ #status-badge { display: none; }

/* Tap-the-pill explainer popup, anchored under the search bar. */
#code-info {
    position: absolute;
    top: calc(max(env(safe-area-inset-top, 0px) + 12px, 12px) + 56px + 8px);
    left: 24px;
    right: 24px;
    background: rgba(26, 26, 26, 0.92);
    color: #ffffff;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    z-index: 11;
    opacity: 0;
    transition: opacity 250ms ease;
    pointer-events: none;
    max-width: 560px;
}
#code-info.visible { opacity: 1; }
#code-info .hl { font-weight: 600; color: #80b9f3; font-variant-numeric: tabular-nums; }
#code-info .info-link {
    pointer-events: auto;
    background: none;
    border: none;
    color: #80b9f3;
    text-decoration: underline;
    cursor: pointer;
    font: inherit;
    padding: 0;
}
#code-info .info-link:hover { color: #a8cdf6; }

#toast.visible {
    opacity: 1;
}

#update-banner {
    position: fixed;
    left: 50%;
    bottom: max(env(safe-area-inset-bottom, 0px) + 24px, 24px);
    transform: translateX(-50%);
    background: rgba(26, 26, 26, 0.92);
    color: #ffffff;
    padding: 8px 8px 8px 18px;
    border-radius: 9999px;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    z-index: 25;
    display: flex;
    align-items: center;
    gap: 12px;
    opacity: 0;
    transition: opacity 250ms ease;
    pointer-events: none;
}

#update-banner.visible {
    opacity: 1;
    pointer-events: auto;
}

#update-reload {
    background: rgba(255, 255, 255, 0.18);
    color: #ffffff;
    border: none;
    border-radius: 9999px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
}

#update-reload:hover {
    background: rgba(255, 255, 255, 0.28);
}
