:root {
    --map-safe-top: env(safe-area-inset-top, 0px);
    --map-safe-right: env(safe-area-inset-right, 0px);
    --map-safe-bottom: env(safe-area-inset-bottom, 0px);
    --map-safe-left: env(safe-area-inset-left, 0px);
}

body:has(#map-container) {
    min-height: 100vh;
    min-height: 100dvh;
    background: #e8f2f8;
    overscroll-behavior: none;
}

#map-container {
    height: 100vh !important;
    height: 100dvh !important;
    background:
        radial-gradient(circle at 20% 20%, rgba(91, 141, 191, 0.16), transparent 36%),
        linear-gradient(180deg, #edf6fb 0%, #dcecf4 100%);
}

#map {
    background: transparent;
}

.map-header {
    top: calc(0.625rem + var(--map-safe-top)) !important;
    right: auto !important;
    left: 50% !important;
    transform: translateX(-50%);
    width: min(44rem, calc(100% - 1.25rem - var(--map-safe-left) - var(--map-safe-right)));
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 7.75rem 0.5rem 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.82);
    border-radius: 1.125rem;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 0.75rem 2rem rgba(15, 45, 67, 0.15);
    backdrop-filter: blur(1rem);
    -webkit-backdrop-filter: blur(1rem);
    pointer-events: auto !important;
}

.btn-back-map {
    width: 2.75rem;
    min-width: 2.75rem;
    height: 2.75rem;
    padding: 0 !important;
    justify-content: center;
    border: 1px solid #dbe8f0;
    border-radius: 0.875rem !important;
    background: #f4f8fb !important;
    box-shadow: none !important;
    color: #183b56 !important;
    font-size: 0 !important;
    gap: 0 !important;
}

.btn-back-map i {
    font-size: 0.9rem;
}

.btn-back-map:focus-visible,
.map-dock-button:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.28);
    outline-offset: 2px;
}

.btn-back-label {
    display: none;
}

.map-heading {
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.map-heading strong {
    overflow: hidden;
    color: #102a43;
    font-size: 0.92rem;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.map-location-status {
    display: flex;
    align-items: center;
    gap: 0.32rem;
    min-width: 0;
    margin-top: 0.24rem;
    color: #627d98;
    font-size: 0.68rem;
    font-weight: 500;
}

.map-location-status span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.map-location-status[data-state="ready"] {
    color: #15803d;
}

.map-location-status[data-state="weak"] {
    color: #b45309;
}

.map-location-status[data-state="outside"] {
    color: #6d28d9;
}

.map-location-status[data-state="offline"] {
    color: #b91c1c;
}

.map-location-status[data-state="error"] {
    color: #b45309;
}

.map-location-status[data-state="locating"] i,
.map-location-status[data-state="weak"] i {
    animation: map-status-pulse 1.2s ease-in-out infinite;
}

.progress-tracker {
    position: absolute !important;
    z-index: 1001;
    top: calc(0.95rem + var(--map-safe-top)) !important;
    right: max(calc((100% - 44rem) / 2 + 1rem), calc(1rem + var(--map-safe-right))) !important;
    width: 6.5rem;
    min-width: 6.5rem !important;
    max-width: 6.5rem !important;
    padding: 0.15rem 0.25rem !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
}

.progress-info {
    justify-content: center;
    gap: 0.3rem !important;
    margin-bottom: 0.28rem !important;
    color: #334e68 !important;
    font-size: 0.7rem !important;
}

.progress-icon {
    display: none;
}

#discovered-count {
    color: #d97706 !important;
    font-size: 0.9rem !important;
}

.progress-bar-container {
    height: 0.55rem !important;
    border: 0 !important;
    border-radius: 999px !important;
    background: #dce7ee !important;
}

.progress-bar-fill {
    border-radius: inherit !important;
    background: linear-gradient(90deg, #f59e0b, #facc15) !important;
}

.progress-percentage {
    display: none;
}

.map-bottom-dock {
    position: absolute;
    z-index: 1002;
    right: auto;
    bottom: calc(0.625rem + var(--map-safe-bottom));
    left: 50%;
    width: min(31rem, calc(100% - 1.25rem - var(--map-safe-left) - var(--map-safe-right)));
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.5rem;
    padding: 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.84);
    border-radius: 1.125rem;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 0.75rem 2rem rgba(15, 45, 67, 0.18);
    backdrop-filter: blur(1rem);
    -webkit-backdrop-filter: blur(1rem);
    transform: translateX(-50%);
}

.map-dock-button {
    min-height: 3rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 0.85rem;
    border: 0;
    border-radius: 0.85rem;
    background: #eef5f9;
    color: #183b56;
    font-family: 'Prompt', sans-serif;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
}

.map-dock-button--primary {
    min-width: 3rem;
    background: linear-gradient(135deg, #2563eb, #0ea5e9);
    color: #fff;
    box-shadow: 0 0.45rem 1rem rgba(37, 99, 235, 0.24);
}

.map-dock-button--primary.is-loading i {
    animation: map-locate-spin 0.9s linear infinite;
}

.map-guide-chevron {
    margin-left: auto;
    transition: transform 180ms ease;
}

.map-bottom-dock.is-expanded .map-guide-chevron {
    transform: rotate(180deg);
}

.map-guide-panel {
    grid-column: 1 / -1;
    padding: 0.7rem 0.65rem 0.35rem;
    border-top: 1px solid #e1eaf0;
}

.map-guide-panel[hidden] {
    display: none;
}

.map-guide-copy {
    margin: 0 0 0.65rem;
    color: #486581;
    font-size: 0.76rem;
    line-height: 1.55;
}

.map-legend {
    position: static !important;
    width: auto !important;
    max-width: none !important;
    display: flex !important;
    justify-content: flex-start;
    gap: 0.7rem 1rem !important;
    flex-wrap: wrap;
    padding: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    transform: none !important;
}

.map-legend--legacy[hidden] {
    display: none !important;
}

.legend-item {
    font-size: 0.75rem !important;
}

.legend-dot {
    flex: 0 0 auto;
}

.leaflet-bottom.leaflet-right {
    right: calc(0.625rem + var(--map-safe-right));
    bottom: calc(5rem + var(--map-safe-bottom));
}

.leaflet-control-zoom {
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.88) !important;
    border-radius: 0.9rem !important;
    box-shadow: 0 0.45rem 1.25rem rgba(15, 45, 67, 0.18) !important;
}

.leaflet-control-zoom a {
    width: 2.75rem !important;
    height: 2.75rem !important;
    line-height: 2.75rem !important;
    color: #183b56 !important;
}

.leaflet-control-attribution {
    margin-bottom: calc(4.75rem + var(--map-safe-bottom)) !important;
    background: rgba(255, 255, 255, 0.72) !important;
    font-size: 0.55rem !important;
}

.leaflet-popup-content-wrapper {
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 1.125rem !important;
    box-shadow: 0 1rem 2.5rem rgba(15, 45, 67, 0.25) !important;
}

.leaflet-popup-content {
    width: min(84vw, 22rem) !important;
    max-height: min(62vh, 32rem);
    max-height: min(62dvh, 32rem);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.leaflet-popup-close-button {
    top: 0.45rem !important;
    right: 0.45rem !important;
    width: 2.5rem !important;
    height: 2.5rem !important;
    display: grid !important;
    place-items: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.92) !important;
    color: #102a43 !important;
    font-size: 1.4rem !important;
    box-shadow: 0 0.2rem 0.75rem rgba(15, 45, 67, 0.16);
}

.popup-info {
    padding: 1rem !important;
    text-align: left !important;
}

.popup-title {
    padding-right: 2.25rem;
    font-size: 1.08rem !important;
}

.btn-navigate {
    min-height: 3rem;
    display: flex !important;
    align-items: center;
    justify-content: center;
    margin-top: 0.85rem;
    border-radius: 0.85rem !important;
}

.achievement-content {
    width: calc(100% - 1.5rem) !important;
    max-height: calc(100dvh - 1.5rem);
    overflow-y: auto;
    padding: 2rem 1.25rem !important;
    border-width: 2px !important;
}

#location-error-overlay > div {
    width: min(100%, 24rem);
    padding: 2rem 1.25rem !important;
}

@keyframes map-status-pulse {
    50% { opacity: 0.4; }
}

@keyframes map-locate-spin {
    to { transform: rotate(360deg); }
}

@media (min-width: 48rem) {
    .map-header {
        grid-template-columns: auto minmax(14rem, 1fr);
        padding: 0.625rem 10rem 0.625rem 0.625rem;
    }

    .btn-back-map {
        width: auto;
        padding: 0 1rem !important;
        font-size: 0.82rem !important;
        gap: 0.5rem !important;
    }

    .btn-back-label {
        display: inline;
    }

    .map-heading strong {
        font-size: 1rem;
    }

    .progress-icon {
        display: inline;
    }

    .progress-tracker {
        width: 8.5rem;
        min-width: 8.5rem !important;
        max-width: 8.5rem !important;
    }

    .map-bottom-dock {
        right: calc(1rem + var(--map-safe-right));
        left: auto;
        width: 22rem;
        transform: none;
    }

    .leaflet-popup-content {
        width: 31rem !important;
    }
}

@media (prefers-reduced-motion: reduce) {
@media (max-width: 22.5rem) {
    .map-locate-label {
        display: none;
    }
}

    .map-location-status[data-state="weak"] i,
    .map-location-status[data-state="locating"] i,
    .map-dock-button--primary.is-loading i {
        animation: none;
    }

    .map-guide-chevron {
        transition: none;
    }
}


/* Treasure hunt marker states */
.treasure-marker-icon {
    border: 0 !important;
    background: transparent !important;
}

.treasure-pin {
    display: grid;
    width: 2.75rem;
    height: 2.75rem;
    place-items: center;
    border: 0.2rem solid #fff;
    border-radius: 50% 50% 0 50%;
    color: #fff;
    font-family: system-ui, sans-serif;
    font-size: 1.05rem;
    font-weight: 900;
    line-height: 1;
    transform: rotate(45deg);
}

.treasure-pin span {
    transform: rotate(-45deg);
}

.treasure-pin--mystery {
    background: linear-gradient(135deg, #7c3aed, #4c1d95);
    box-shadow: 0 0.25rem 0.9rem rgba(91, 33, 182, 0.52);
    animation: treasure-beacon 2.2s ease-in-out infinite;
}

.treasure-pin--nearby {
    background: linear-gradient(135deg, #0ea5e9, #2563eb);
    box-shadow: 0 0 0 0.35rem rgba(14, 165, 233, 0.2), 0 0.35rem 1rem rgba(37, 99, 235, 0.5);
}

.treasure-pin--unlocked {
    background: linear-gradient(135deg, #facc15, #f59e0b);
    box-shadow: 0 0 0 0.35rem rgba(250, 204, 21, 0.2), 0 0.35rem 1rem rgba(245, 158, 11, 0.48);
}

@keyframes treasure-beacon {
    0%, 100% { box-shadow: 0 0.25rem 0.9rem rgba(91, 33, 182, 0.48); }
    50% { box-shadow: 0 0 0 0.45rem rgba(124, 58, 237, 0.14), 0 0.4rem 1.2rem rgba(91, 33, 182, 0.7); }
}

@media (prefers-reduced-motion: reduce) {
    .treasure-pin--mystery {
        animation: none;
    }
}