:root {
    color-scheme: dark;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body,
#challenge-map {
    height: 100%;
    margin: 0;
    width: 100%;
}

body {
    background: #111827;
    overflow: hidden;
}

.challenge-mobile-compass {
    display: none;
}

.challenge-title,
.challenge-controls,
.challenge-popups,
.challenge-logo {
    position: absolute;
    z-index: 5;
}

.challenge-title {
    align-items: center;
    background: rgba(15, 23, 42, .88);
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 12px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, .24);
    color: #fff;
    display: flex;
    gap: 10px;
    left: 18px;
    padding: 10px 14px;
    top: 18px;
}

.challenge-title img {
    height: 34px;
    width: 26px;
}

.challenge-title h1,
.challenge-title p {
    margin: 0;
}

.challenge-title h1 {
    font-size: 18px;
    line-height: 1.25;
}

.challenge-title p {
    color: #cbd5e1;
    font-size: 12px;
    margin-top: 2px;
}

.challenge-logo {
    background: rgba(255, 255, 255, .92);
    border-radius: 10px;
    box-shadow: 0 8px 22px rgba(0, 0, 0, .2);
    max-height: 92px;
    max-width: min(280px, 28vw);
    object-fit: contain;
    padding: 6px;
    right: 18px;
    top: 18px;
}

.challenge-controls {
    background: rgba(15, 23, 42, .92);
    border: 1px solid rgba(255, 255, 255, .14);
    border-radius: 12px;
    bottom: 24px;
    box-shadow: 0 12px 34px rgba(0, 0, 0, .28);
    color: #fff;
    left: 18px;
    max-height: calc(100vh - 130px);
    overflow: auto;
    padding: 12px;
    width: min(330px, calc(100vw - 36px));
}

.challenge-controls__heading,
.challenge-event,
.challenge-event label {
    align-items: center;
    display: flex;
}

.challenge-controls__heading {
    justify-content: space-between;
}

.challenge-controls__collapse {
    background: transparent;
    border: 0;
    color: #fff;
    cursor: pointer;
    font-size: 22px;
}

.challenge-controls.is-collapsed {
    bottom: 18px;
    width: 150px;
}

.challenge-controls.is-collapsed .challenge-controls__content {
    display: none;
}

.challenge-event {
    border-top: 1px solid rgba(255, 255, 255, .09);
    gap: 8px;
    justify-content: space-between;
    margin-top: 9px;
    padding-top: 9px;
}

.challenge-event label {
    cursor: pointer;
    gap: 8px;
    min-width: 0;
}

.challenge-event label span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.challenge-event a {
    color: #fff;
    font-size: 18px;
    text-decoration: none;
}

.challenge-event__colour {
    background: var(--event-colour);
    border: 2px solid rgba(255, 255, 255, .75);
    border-radius: 50%;
    display: inline-block;
    flex: 0 0 auto;
    height: 13px;
    width: 13px;
}

.challenge-map-items,
.challenge-basemaps {
    border-top: 1px solid rgba(255, 255, 255, .14);
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    margin-top: 12px;
    padding-top: 12px;
}

.challenge-map-items strong,
.challenge-basemaps strong {
    flex-basis: 100%;
    font-size: 13px;
}

.challenge-map-items label {
    font-size: 13px;
}

.challenge-basemaps button,
.challenge-fit {
    background: #273449;
    border: 1px solid rgba(255, 255, 255, .16);
    border-radius: 7px;
    color: #fff;
    cursor: pointer;
    padding: 6px 9px;
}

.challenge-basemaps button.is-active,
.challenge-fit {
    background: #e77d11;
}

.challenge-fit {
    margin-top: 12px;
    width: 100%;
}

.challenge-popups {
    bottom: 24px;
    display: flex;
    gap: 12px;
    max-height: min(560px, calc(100vh - 48px));
    max-width: calc(100vw - 400px);
    overflow-x: auto;
    overflow-y: hidden;
    right: 24px;
}

.challenge-popups--participants {
    bottom: 24px;
    left: 50%;
    max-width: calc(100vw - 48px);
    right: auto;
    top: auto;
    transform: translateX(-50%);
    width: max-content;
}

.challenge-popup {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 15px 42px rgba(0, 0, 0, .32);
    color: #172033;
    flex: 0 0 min(390px, calc(100vw - 48px));
    max-height: min(560px, calc(100vh - 48px));
    overflow: auto;
    padding: 14px;
}

.challenge-popup--participant {
    background: transparent;
    color: #fff;
    flex-basis: min(430px, calc(100vw - 48px));
    overflow: auto;
    padding: 0;
    width: min(430px, calc(100vw - 48px));
}

.challenge-popup--participant > [data-popup-content],
.challenge-popup--participant > [data-popup-content] > [id^="participant-"] {
    max-width: none;
    padding: 0;
    width: 100%;
}

.challenge-popup--participant .participantInfoHolder {
    color: #fff;
    max-width: 100%;
    min-height: 200px;
    position: relative;
    width: 100%;
}

.challenge-popup--participant.challenge-popup--minified {
    align-self: flex-end;
    height: auto;
    max-height: none;
    overflow: visible;
}

.challenge-popup--participant.challenge-popup--minified .participantInfoHolder.participantInfoHolder--minified {
    min-height: 0 !important;
    top: 0 !important;
    transform: none !important;
}

.challenge-popup--participant > .challenge-popup__close {
    display: none;
}

.challenge-participant-mobile-header {
    display: none;
}

.challenge-popup__close {
    background: #172033;
    border: 0;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    font-size: 20px;
    height: 30px;
    position: sticky;
    float: right;
    right: 0;
    top: 0;
    width: 30px;
    z-index: 2;
}

.challenge-popup h3 {
    font-size: 20px;
    margin: 4px 38px 2px 0;
}

.challenge-popup__event {
    color: #64748b;
    font-weight: 600;
}

.challenge-popup dl {
    display: grid;
    gap: 5px 12px;
    grid-template-columns: max-content 1fr;
}

.challenge-popup dt,
.challenge-popup dd {
    margin: 0;
}

.challenge-popup dd {
    color: #e77d11;
}

.challenge-loading {
    align-items: center;
    background: rgba(15, 23, 42, .88);
    border-radius: 12px;
    color: #fff;
    display: flex;
    gap: 10px;
    left: 50%;
    padding: 12px 16px;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 8;
}

.challenge-loading span {
    animation: challenge-spin .8s linear infinite;
    border: 3px solid rgba(255, 255, 255, .3);
    border-radius: 50%;
    border-top-color: #ef870c;
    height: 24px;
    width: 24px;
}

.challenge-map-marker {
    align-items: center;
    background: #fff;
    border: 2px solid #172033;
    border-radius: 50%;
    box-shadow: 0 3px 8px rgba(0, 0, 0, .3);
    cursor: pointer;
    display: flex;
    height: 32px;
    justify-content: center;
    overflow: visible;
    width: 32px;
}

.challenge-map-marker img {
    border-radius: 50%;
    height: 100%;
    object-fit: contain;
    width: 100%;
}

.challenge-map-marker--staff,
.challenge-map-marker--start,
.challenge-map-marker--finish,
.challenge-map-marker--start-finish,
.challenge-map-marker--pois,
.challenge-map-marker--checkpoints {
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
}

.challenge-map-marker--pois {
    cursor: default;
    height: 26px;
    pointer-events: none;
    width: 26px;
}

.challenge-map-marker--staff img,
.challenge-map-marker--start img,
.challenge-map-marker--finish img,
.challenge-map-marker--start-finish img,
.challenge-map-marker--pois img,
.challenge-map-marker--checkpoints img {
    border-radius: 0;
}

.challenge-map-marker__label.challenge-map-marker__label--staff {
    background: rgba(0, 0, 0, .6);
    bottom: calc(100% + 2px);
    font-size: 12px;
    padding: 1px 3px;
}

.challenge-map-marker__label {
    background: rgba(15, 23, 42, .9);
    border-radius: 4px;
    bottom: calc(100% + 5px);
    color: #fff;
    font-size: 11px;
    left: 50%;
    padding: 3px 6px;
    pointer-events: none;
    position: absolute;
    transform: translateX(-50%);
    white-space: nowrap;
}

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

@media (max-width: 700px) {
    .maplibregl-ctrl-top-right {
        display: none;
    }

    .challenge-mobile-compass {
        align-items: center;
        background: rgba(20, 20, 24, .78);
        border: 1px solid rgba(255, 255, 255, .16);
        border-radius: 50%;
        box-shadow: 0 4px 12px rgba(0, 0, 0, .24);
        display: inline-flex;
        height: 38px;
        justify-content: center;
        padding: 0;
        position: fixed;
        right: 14px;
        top: calc(14px + env(safe-area-inset-top, 0px));
        width: 38px;
        z-index: 8;
    }

    .challenge-mobile-compass:focus,
    .challenge-mobile-compass:hover {
        background: rgba(20, 20, 24, .92);
        outline: 0;
    }

    .challenge-mobile-compass__needle {
        display: block;
        filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .35));
        height: 21px;
        transform-origin: 50% 50%;
        transition: transform .08s linear;
        width: 21px;
    }

    .challenge-title {
        left: 10px;
        max-width: calc(100vw - 74px);
        padding: 8px 10px;
        top: 10px;
    }

    .challenge-title h1 {
        font-size: 15px;
    }

    .challenge-logo {
        display: none;
    }

    .challenge-controls {
        bottom: max(10px, env(safe-area-inset-bottom));
        left: 10px;
        max-height: 48vh;
        width: calc(100vw - 20px);
    }

    .challenge-controls.is-collapsed {
        width: 150px;
    }

    .challenge-popups {
        border-radius: 14px 14px 0 0;
        bottom: 0;
        display: block;
        left: 0;
        max-height: 55vh;
        max-width: none;
        overflow-x: hidden;
        overflow-y: auto;
        right: 0;
        top: auto;
        transform: none;
        width: 100%;
    }

    .challenge-popup {
        border-radius: 14px 14px 0 0;
        max-height: 55vh;
        width: 100%;
    }

    .challenge-popup--participant {
        display: flex;
        flex-direction: column;
        border-radius: 0;
        height: 100%;
        max-height: none;
        width: 100%;
    }

    .challenge-participant-mobile-header {
        align-items: center;
        background-color: rgba(20, 20, 24, .99);
        box-shadow: 0 4px 4px rgba(0, 0, 0, .3);
        color: #fff;
        display: flex;
        flex: 0 0 calc(50px + env(safe-area-inset-top));
        height: calc(50px + env(safe-area-inset-top));
        min-height: calc(50px + env(safe-area-inset-top));
        padding: env(safe-area-inset-top) 5px 0;
        position: relative;
        width: 100%;
        z-index: 2;
    }

    .challenge-participant-mobile-header .mobile-title-pin {
        height: 28px;
        left: 15px;
        margin: 0;
        position: absolute;
        top: calc(50% + (env(safe-area-inset-top) / 2));
        transform: translateY(-50%);
    }

    .challenge-participant-mobile-header__title {
        display: block;
        font-size: 18px;
        font-weight: 700;
        left: 52px;
        line-height: 1.15;
        margin: 0;
        overflow: hidden;
        position: absolute;
        right: 58px;
        text-overflow: ellipsis;
        top: calc(50% + (env(safe-area-inset-top) / 2));
        transform: translateY(-50%);
        white-space: nowrap;
    }

    .challenge-participant-mobile-header__close {
        align-items: center;
        background: rgba(32, 32, 38, .92);
        border: 1px solid rgba(255, 255, 255, .14);
        border-radius: 50%;
        box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .2), 0 2px 8px rgba(0, 0, 0, .28);
        display: inline-flex;
        height: 40px;
        justify-content: center;
        padding: 0;
        position: absolute;
        right: 7px;
        top: calc(50% + (env(safe-area-inset-top) / 2));
        transform: translateY(-50%);
        width: 40px;
    }

    .challenge-participant-mobile-header__close::before,
    .challenge-participant-mobile-header__close::after {
        background: #d8d8dc;
        border-radius: 4px;
        content: "";
        height: 2px;
        left: 50%;
        position: absolute;
        top: 50%;
        width: 20px;
    }

    .challenge-participant-mobile-header__close::before {
        transform: translate(-50%, -50%) rotate(45deg);
    }

    .challenge-participant-mobile-header__close::after {
        transform: translate(-50%, -50%) rotate(-45deg);
    }

    .challenge-popup--participant > [data-popup-content] {
        flex: 1 1 auto;
        min-height: 0;
        overflow-x: hidden;
        overflow-y: auto;
        width: 100%;
        -webkit-overflow-scrolling: touch;
    }

    .challenge-popups.challenge-popups--participants {
        background: #0b0c10;
        border-radius: 0;
        bottom: 0;
        height: 100%;
        height: 100dvh;
        left: 0;
        max-height: none;
        max-width: none;
        overflow: hidden;
        position: fixed;
        right: 0;
        top: 0;
        transform: none;
        width: 100%;
        z-index: 100;
    }

    .challenge-popups.challenge-popups--participants .challenge-popup--participant,
    .challenge-popups.challenge-popups--participants .challenge-popup--participant > [data-popup-content] {
        background: #0b0c10;
        height: 100%;
        max-height: none;
    }

    .challenge-popup--participant .participantInfoHolder,
    .challenge-popup--participant .participantInfoHolderMobile {
        background: #0b0c10 !important;
        border: 0 !important;
        border-radius: 0 !important;
        height: 100%;
        min-height: 100%;
        max-height: none;
        max-width: none;
        overflow-x: hidden;
        padding-bottom: env(safe-area-inset-bottom);
        width: 100%;
    }

    .challenge-popup--participant.challenge-popup--minified {
        bottom: max(10px, env(safe-area-inset-bottom));
        height: auto;
        left: 10px;
        max-height: none;
        position: fixed;
        width: calc(100% - 20px);
    }

    .challenge-popup--participant.challenge-popup--minified .challenge-participant-mobile-header {
        border-radius: 14px;
        flex-basis: 50px;
        min-height: 50px;
        padding-top: 0;
    }

    .challenge-popup--participant.challenge-popup--minified .challenge-participant-mobile-header__close {
        top: 50%;
    }

    .challenge-popup--participant.challenge-popup--minified > [data-popup-content] {
        display: none;
    }

    .challenge-popups.challenge-popups--participants:has(.challenge-popup--minified) {
        background: transparent;
        height: auto;
        left: 0;
        overflow: visible;
        pointer-events: none;
        right: 0;
        top: auto;
    }

    .challenge-popup--participant.challenge-popup--minified,
    .challenge-popup--participant.challenge-popup--minified * {
        pointer-events: auto;
    }

    .challenge-popup--participant.challenge-popup--minified .participantInfoHolder,
    .challenge-popup--participant.challenge-popup--minified .participantInfoHolderMobile {
        border: 1px solid rgba(255, 255, 255, .12) !important;
        border-radius: 14px !important;
        height: auto;
        overflow: hidden;
    }
}
