body {
    margin: 0;
    padding: 0;
    background: #000;
    overflow: hidden;
}

#map {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
}

.title {
    position: absolute;
    top: 30px;
    left: 30px;
    z-index: 10;
    color: white;
    font-family: 'Helvetica Neue', sans-serif;
    letter-spacing: 5px;
    text-transform: uppercase;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}

.title h2 {
    font-size: 40px;
}

.total-stats {
    margin-top: 8px;
    font-size: 16px;
    letter-spacing: 1.5px;
    opacity: 0.75;
}

.map-status {
    margin-top: 8px;
    font-size: 11px;
    letter-spacing: 1px;
    color: #ffd6d6;
    max-width: min(80vw, 380px);
    line-height: 1.35;
    text-transform: none;
}

.basemap-toggle {
    position: absolute;
    top: 30px;
    right: 30px;
    z-index: 25;
    padding: 9px 18px;
    background: rgba(0, 0, 0, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    color: #fff;
    font-family: 'Helvetica Neue', sans-serif;
    font-size: 11px;
    letter-spacing: 2px;
    text-transform: uppercase;
    cursor: pointer;
    backdrop-filter: blur(4px);
    transition: background 0.2s, border-color 0.2s, opacity 0.2s, right 0.3s ease-in-out;
}

.basemap-toggle:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.9);
    border-color: rgba(255, 255, 255, 0.6);
}

.basemap-toggle:disabled {
    opacity: 0.4;
    cursor: default;
}

/* Slide the button along with the side panel */
body:not(.panel-closed) .basemap-toggle {
    right: 430px;
}

.track-panel {
    position: absolute;
    left: 20px;
    right: 440px;
    /* Leave space for the side panel */
    bottom: 20px;
    z-index: 35;
    color: #fff;
    background: rgba(0, 0, 0, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    font-family: 'Helvetica Neue', sans-serif;
    padding: 14px;
    backdrop-filter: blur(4px);
    transition: right 0.3s ease;
}

.track-panel.empty {
    left: 20px;
    right: auto;
    bottom: 20px;
    padding: 10px 14px;
    border-radius: 999px;
}

.track-cta {
    display: none;
    margin: 0;
    font-size: 11px;
    opacity: 0.95;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.track-details {
    display: block;
}

.track-panel.empty .track-cta {
    display: block;
}

.track-panel.empty .track-details {
    display: none;
}

.track-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 10px;
}

.track-panel-title {
    margin: 0;
    font-size: 14px;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    font-weight: 500;
}

.track-panel-hint {
    margin: 0;
    font-size: 11px;
    opacity: 0.7;
}

.track-stats {
    display: grid;
    grid-template-columns: repeat(5, minmax(90px, 1fr));
    gap: 8px;
    margin-bottom: 10px;
}

.stat-card {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 6px;
    padding: 8px;
}

.stat-label {
    display: block;
    font-size: 10px;
    opacity: 0.75;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 14px;
    font-weight: 500;
}

#elevation-profile {
    width: 100%;
    height: 130px;
    display: block;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 6px;
}

/* =========================================
   NEW: SIDE PANEL & MARKDOWN STYLES 
   ========================================= */

.side-panel {
    position: absolute;
    top: 0;
    right: -450px;
    /* Hidden off-screen by default */
    width: 400px;
    box-sizing: border-box;
    bottom: 0;
    background: rgba(10, 10, 10, 0.90);
    backdrop-filter: blur(10px);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 30;
    transition: right 0.3s ease-in-out;
    padding: 40px 30px;
    overflow-y: auto;
    color: white;
    font-family: 'Helvetica Neue', sans-serif;
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.8);
}

.side-panel.active {
    right: 0;
    /* Slide in */
}

/* When panel is closed, allow the bottom track-panel to expand */
body.panel-closed .track-panel {
    right: 20px;
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 20px;
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.close-btn:hover {
    opacity: 1;
}

/* Markdown typography */
.markdown-body {
    font-size: 14px;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.85);
}

.markdown-body h1 {
    font-size: 22px;
    font-weight: 500;
    margin-bottom: 20px;
    letter-spacing: 1px;
}

.markdown-body h2,
.markdown-body h3 {
    color: white;
    font-weight: 500;
    margin-top: 25px;
    margin-bottom: 10px;
}

.markdown-body p {
    margin-bottom: 15px;
}

.markdown-body img {
    max-width: 100%;
    border-radius: 6px;
    margin: 15px 0;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.markdown-body ul {
    margin-bottom: 20px;
    padding-left: 20px;
}

.markdown-body a {
    color: #00d4ff;
    text-decoration: none;
}

.markdown-body a:hover {
    text-decoration: underline;
}


/* =========================================
   POI (Points of Interest) POPUPS 
   ========================================= */

.maplibregl-popup-content {
    background: rgba(10, 10, 10, 0.95) !important;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px !important;
    font-family: 'Helvetica Neue', sans-serif;
    padding: 12px 16px !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.8) !important;
    backdrop-filter: blur(4px);
}

/* Fix the little triangle pointing down */
.maplibregl-popup-tip {
    border-top-color: rgba(10, 10, 10, 0.95) !important;
    border-bottom-color: rgba(10, 10, 10, 0.95) !important;
}

/* Close button (we hide it because we use hover) */
.maplibregl-popup-close-button {
    display: none;
}

.poi-popup-title {
    margin: 0 0 4px 0;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #ffb703;
    /* Amber color to contrast with the white tracks */
}

.poi-popup-alt {
    margin: 0;
    font-size: 11px;
    opacity: 0.7;
}


/* =========================================
   POI SIDE PANEL CONTENT
   ========================================= */

.poi-panel {
    padding-top: 10px;
}

.poi-panel-type {
    font-size: 11px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: #ffb703;
    margin-bottom: 10px;
    opacity: 0.9;
}

.poi-panel-name {
    font-size: 22px;
    font-weight: 500;
    margin: 0 0 24px 0;
    letter-spacing: 0.5px;
    line-height: 1.3;
    color: #fff;
}

.poi-panel-stats {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 28px;
}

.poi-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
}

.poi-stat-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    opacity: 0.6;
}

.poi-stat-value {
    font-size: 14px;
    font-weight: 500;
    color: #fff;
}

.poi-status--open {
    color: #4ade80;
}

.poi-status--closed {
    color: #f87171;
}

.poi-panel-description {
    font-size: 14px;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.8);
    white-space: pre-line;
    margin: 0 0 24px 0;
}

.poi-link {
    display: inline-block;
    margin-top: 4px;
    padding: 10px 18px;
    border: 1px solid rgba(255, 183, 3, 0.4);
    border-radius: 6px;
    color: #ffb703;
    font-size: 13px;
    text-decoration: none;
    letter-spacing: 0.5px;
    transition: background 0.2s, border-color 0.2s;
}

.poi-link:hover {
    background: rgba(255, 183, 3, 0.1);
    border-color: #ffb703;
}


/* =========================================
   MOBILE / TABLETTE
   ========================================= */

/* Téléphones : écran étroit, ou écran bas en paysage (844x390 & compagnie) */
@media (max-width: 768px), (max-width: 900px) and (max-height: 500px) {

    /* Le titre laisse la place au bouton de fond de carte */
    .title {
        top: calc(10px + env(safe-area-inset-top));
        left: calc(12px + env(safe-area-inset-left));
        right: calc(96px + env(safe-area-inset-right));
        letter-spacing: 2px;
    }

    .title h2 {
        font-size: 24px;
    }

    .total-stats {
        margin-top: 6px;
        font-size: 15px;
        letter-spacing: 1px;
    }

    .map-status {
        max-width: 100%;
        font-size: 10px;
    }

    .basemap-toggle {
        top: calc(10px + env(safe-area-inset-top));
        right: calc(12px + env(safe-area-inset-right));
        padding: 8px 12px;
        font-size: 10px;
        letter-spacing: 1px;
    }

    /* Pas de décalage : sur mobile le panneau latéral couvre l'écran */
    body:not(.panel-closed) .basemap-toggle {
        right: calc(12px + env(safe-area-inset-right));
    }

    /* Le bandeau du bas prend toute la largeur, quel que soit l'état du panneau.
       max-height le borne si le texte est agrandi (réglage système) : il défile
       plutôt que de manger tout l'écran. */
    .track-panel,
    body.panel-closed .track-panel {
        left: calc(8px + env(safe-area-inset-left));
        right: calc(8px + env(safe-area-inset-right));
        bottom: calc(8px + env(safe-area-inset-bottom));
        padding: 10px;
        max-height: 45vh;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .track-panel.empty {
        right: auto;
        padding: 9px 14px;
    }

    /* Description ouverte : le bandeau reste visible, en version compacte */
    body:not(.panel-closed) .track-panel-hint {
        display: none;
    }

    body:not(.panel-closed) #elevation-profile {
        height: 64px;
    }

    .track-panel-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
        margin-bottom: 8px;
    }

    .track-panel-title {
        font-size: 12px;
        letter-spacing: 0.8px;
    }

    .track-panel-hint {
        font-size: 10px;
    }

    .track-stats {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
        margin-bottom: 8px;
    }

    .stat-card {
        padding: 6px;
    }

    .stat-label {
        font-size: 9px;
        letter-spacing: 0.4px;
        margin-bottom: 2px;
    }

    .stat-value {
        font-size: 12px;
    }

    #elevation-profile {
        height: 90px;
    }

    /* Panneau latéral : pleine largeur, arrêté au-dessus du bandeau de stats
       (--track-panel-offset est mis à jour par app.js) */
    .side-panel {
        width: 100%;
        right: -100%;
        bottom: var(--track-panel-offset, 0px);
        z-index: 60;
        padding: 52px calc(18px + env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) calc(18px + env(safe-area-inset-left));
        padding-top: calc(52px + env(safe-area-inset-top));
        border-left: none;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    /* Zone de tap confortable pour fermer */
    .close-btn {
        top: calc(6px + env(safe-area-inset-top));
        right: calc(8px + env(safe-area-inset-right));
        width: 44px;
        height: 44px;
        line-height: 1;
        font-size: 30px;
        opacity: 0.8;
    }

    .markdown-body h1,
    .poi-panel-name {
        font-size: 19px;
    }

    .poi-panel-name {
        margin-bottom: 18px;
    }
}

/* Écrans très étroits : 3 colonnes ne tiennent plus */
@media (max-width: 340px) {
    .track-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    #elevation-profile {
        height: 70px;
    }
}

/* Mobile en paysage : la hauteur est la ressource rare */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
    .track-stats {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }

    #elevation-profile {
        height: 60px;
    }

    .title h2 {
        font-size: 13px;
    }
}