html,
body {
    height: 100%;
    margin: 0;
    background-color: #ede8e0;
    font-family: Inter, sans-serif;
    text-rendering: optimizeLegibility;
    text-align: center;
    overflow-x: hidden;        /* fallback for old browsers */
    overflow-x: clip;          /* modern: clips WITHOUT turning body into a scroll container */
    max-width: 100%;
}


/* ---- Popup overlay backdrop ---- */
/* Hidden by default; becomes a full-screen dark overlay whenever a
   .popup-content.visible lives inside it (CSS :has() selector).        */
.popup-info {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.50);
    align-items: center;
    justify-content: center;
}

.popup-info:has(.popup-content.visible) {
    display: flex;
}


/* ---- Modal box ---- */
.popup-content {
    width: 75vw;
    max-width: 1100px;
    height: 82vh;
    display: none;
    flex-direction: column;
    position: relative;
    background-color: #ffffff;
    border-radius: 4px;
    box-shadow: 0px 20px 60px rgba(0, 0, 0, 0.55);
    overflow: hidden;
}

.popup-content.visible {
    display: flex;
}


/* ---- Title / header bar ---- */
.popup-content .popup-title {
    background-color: #1e0e1a;
    color: #ffffff;
    text-align: left;
    padding: 16px 52px 16px 24px;
    font-weight: 600;
    font-size: 20px;
    line-height: 1.3;
    flex-shrink: 0;
    /* remove old fixed height */
    height: auto;
}


/* ---- Close (×) button — sits in the top-right corner of the title bar ---- */
/* close.svg already has fill="#e3e3e3" (light grey) — no invert needed.   */
.popup-content .exit-button {
    width: 28px;
    height: 28px;
    top: 13px;
    right: 16px;
    z-index: 100000 !important;
    background-color: transparent;
    position: absolute;
    background-image: url('../icons/close.svg');
    background-position: 50% 50%;
    background-repeat: no-repeat;
    background-size: 80%;
    cursor: pointer;
    opacity: 0.80;
    transition: opacity 0.15s;
}

.popup-content .exit-button:hover {
    opacity: 1;
}


/* ---- Scrollable body ---- */
.popup-content .popup-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px 30px 30px 30px;
    font-size: 14px;
    text-align: left;
    line-height: 1.65;
    color: #222222;
    background-color: #ede8e0;  /* matches main page background */
    white-space: normal;        /* was pre-wrap */
    height: auto;               /* remove old fixed height */
}


/* ---- Section headings inside the help body (## in markdown → <h2>) ---- */
.popup-content .popup-body h2 {
    font-size: 15px;
    font-weight: 700;
    color: #1e0e1a;
    margin: 1.4em 0 0.45em 0;
    padding-bottom: 6px;
    border-bottom: 1.5px solid #cfc8bf;
}

.popup-content .popup-body h2:first-child {
    margin-top: 0;
}

.popup-content .popup-body p {
    margin: 0.5em 0;
}

.popup-content .popup-body strong {
    color: #111111;
}

.popup-content .popup-body a {
    color: #1e0e1a;
    text-decoration: underline;
}

.popup-content .popup-body a:hover {
    opacity: 0.75;
}


/* ---- Citation popup (narrow variant) ---- */
#citation-content {
    width: 500px;
    height: auto;
    min-height: 80px;
}


/* ---- Main layout ---- */
.grid-container {
    display: flex;
    flex-direction: row;
    height: 100%;
}

.grid-container.blurred {
    filter: blur(2px);
}

/* .left-panel {
    width: 15%;
    padding: 10px;
    overflow-y: visible;
    display: flex;
    flex-direction: column;
    min-height: 300px;
    min-width: 250px;
    max-width: 800px;
    height: 100%;
}

.right-panel {
    flex-grow: 1;
    flex-direction: column;
    padding: 10px;
    height: 84%;
    padding-bottom: 20px;
} */
.left-panel {
    width: 15%;
    padding: 10px;
    overflow-y: visible;
    display: flex;
    flex-direction: column;
    min-height: 300px;
    min-width: 250px;
    max-width: 800px;
    height: 100%;
    position: relative;   
    z-index: 2;          
}

.right-panel {
    flex-grow: 1;
    flex-direction: column;
    padding: 10px;
    height: 84%;
    padding-bottom: 20px;
    position: relative;   
    z-index: 1;           
}



.top-icon-row {
    display: flex;
    width: 100%;
    height: 72px;
    padding: 10px;
    flex-direction: row;
    align-items: center;
}

/* Restore original icon spacing */
.top-icon-row-icon {
    margin-right: 20px;
}

/* Push the icon buttons to the far right */
#helpbox-button {
    margin-left: auto;
}

.leaflet-map {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
}

#map {
    width: 100%;
    height: 100%;
    min-width: 400px;
    min-height: 400px;
}


/* ---- Mobile ---- */
@media (max-width: 800px) {
    :root {
        --mobile-gutter: 8px;     /* THE number to tune: space either side of the controls and map on phones */
    }

    html,
    body {
        height: auto;              /* was 100% globally — lets the page grow to content */
    }

    .grid-container {
        display: grid;             /* triggers the stack — DO NOT remove */
        flex-direction: column;    /* DO NOT remove */
        height: auto;              /* was 100% */
    }

    .left-panel {
        width: 100%;               /* full-width stack — DO NOT remove */
        display: grid;             /* DO NOT remove */
        min-width: 200px;
        overflow: visible;
        padding: 10px calc(var(--mobile-gutter) - 8px);   /* each .dropdown adds its own 8px side margin (dropdowns.css) */
        margin: 0;
        height: auto;              /* was 800px fixed */
    }

    .right-panel {
        flex-direction: column;
        padding: 10px var(--mobile-gutter);   /* map lines up with the controls above it */
        box-sizing: border-box;
        height: auto;
    }

    #map {
        width: 100%;
        min-width: 0;              /* was 400px (desktop) */
        height: 480px;             /* fixed px, NOT 55vh — this is the loop-breaker */
        box-sizing: border-box;
    }

    .popup-content {
        width: 95vw;
        height: 90vh;
    }
}


/* ---- Embedded in an iframe (desktop layout only) ----
   index.ts adds class "embedded" to <html> when the page is inside an iframe.
   Standalone, the page fills the viewport using the percentage heights above.
   Embedded, those percentages would be relative to the iframe, whose height we are
   trying to set from the content, so they create a feedback loop (grow-only height,
   inner scrollbar). So here the height comes from content, with a fixed map height.
   The `not all and (max-width: 800px)` query is the exact complement of the mobile
   block above, so the mobile layout is left alone. */
@media not all and (max-width: 800px) {
    html.embedded {
        --embedded-map-height: 900px;   /* THE number to tune: map height when embedded on desktop */
    }

    html.embedded,
    html.embedded body {
        height: auto;
    }

    html.embedded .grid-container {
        height: auto;
    }

    html.embedded .left-panel {
        height: auto;
    }

    html.embedded .right-panel {
        height: auto;
        padding: 10px 10px 20px;
        min-width: 0;          /* lets the map column shrink as the window narrows */
    }

    html.embedded #map {
        height: var(--embedded-map-height);
        max-height: none;      /* .leaflet-map sets max-height:100% */
    }
}