/* Global / Design Tokens */
:root{
    --ui-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --popup-font-size: 14px;
    --popup-line-height: 1.45;
    --popup-color: #222;
    --popup-bg: #ffffff;
    --popup-padding: 12px;
    --popup-radius: 6px;
    --popup-accent: #000000;
    --popup-max-width: clamp(220px, 28vw, 520px);
}

html, body { overflow-x: hidden; overscroll-behavior-x: contain; }
body { font-family: var(--ui-font); background: #fbfbfb; color: #222; margin: 0; }

/* Landing page — card grid */
#landing {
    max-width: 1100px;
    margin: 0 auto;
    padding: 40px 20px;
}

.landing-heading {
    font-size: 2rem;
    font-weight: 700;
    text-align: center;
    margin: 0 0 32px;
    letter-spacing: 0.3px;
}

.landing-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
}

.landing-card {
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 14px rgba(0,0,0,0.08);
    transition: transform 200ms ease, box-shadow 200ms ease;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
}
.landing-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 28px rgba(0,0,0,0.13);
}

.landing-card-thumb {
    width: 100%;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    display: block;
    background: #e8e8e8;
}
.landing-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.landing-card-body {
    padding: 16px;
}
.landing-card-body h2 {
    margin: 0 0 6px;
    font-size: 1.15rem;
    font-weight: 600;
}
.landing-card-body p {
    margin: 0;
    font-size: 0.88rem;
    color: #555;
    line-height: 1.45;
}

/* Back link (map → landing) */
.back-link {
    display: inline-block;
    font-size: 0.9rem;
    color: #444;
    text-decoration: none;
    padding: 4px 0;
    transition: color 120ms ease;
    grid-column: 1 / -1;
}
.back-link:hover { color: #000; }

/* SVG map */
svg {
    width: 100%;
    height: auto;
    max-width: 100%;
    display: block;
    margin: 0 auto;
    border: none;
    box-sizing: border-box;
    border-radius: 8px;
    /* Prevent browser zoom/pinch on the SVG */
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Map states / provinces */
#map-controls { position: fixed; left: 10px; top: 10px; background: rgba(255,255,255,0.95); border:1px solid #ccc; padding:8px; z-index:9999; font-size:13px; }
.state:not(.state--active) { fill: #B9E8E4; stroke: #fff; stroke-width: 0.5; }
.state:hover { stroke: #000 !important; stroke-width: 1.2px !important; vector-effect: non-scaling-stroke;}

/* Hotspots */
.hotspot {
    cursor: pointer;
    pointer-events: auto;
    touch-action: manipulation;
    fill: rgba(215, 38, 61, 0.65);
    stroke: rgb(200,0,0);
    transform-box: fill-box;
    transform-origin: center;
    transition: transform 180ms cubic-bezier(.34, 1.56, .64, 1), fill 160ms ease, stroke 160ms ease;
}

/* Pop the circle slightly on hover so it reads as clickable, in addition to the colour shift */
.hotspot-group:hover .hotspot {
    transform: scale(1.35);
}

/* Cluster badge text (rendered inside the cluster circle) */
.hotspot-cluster-label {
    fill: #fff;
    font-weight: 700;
    pointer-events: none;
    text-anchor: middle;
    dominant-baseline: central;
}

/* Carousel wrapper */
.popup-carousel {
    position: relative;
    display: block;
    margin-bottom: 8px;
    overflow: hidden;
}
.popup-carousel img {
    margin-bottom: 0;
}
.popup-carousel-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.18);
    backdrop-filter: blur(12px) saturate(1.6);
    -webkit-backdrop-filter: blur(12px) saturate(1.6);
    border: 1px solid rgba(255, 255, 255, 0.30);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 180ms ease, border-color 180ms ease, transform 180ms ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}
.popup-carousel-btn:hover {
    background: rgba(255, 255, 255, 0.32);
    border-color: rgba(255, 255, 255, 0.55);
    transform: translateY(-50%) scale(1.08);
}
.popup-carousel-btn:active {
    transform: translateY(-50%) scale(0.95);
    background: rgba(255, 255, 255, 0.42);
}
.popup-prev { left: 8px; }
.popup-next { right: 8px; }
.popup-carousel-counter {
    text-align: center;
    font-size: 11px;
    color: #888;
    margin: 4px 0 8px;
}

/* Cluster list popup */
.popup--cluster > strong {
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: #999;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(0,0,0,0.07);
    margin-bottom: 4px;
}

.popup-cluster-list {
    list-style: none;
    margin: 4px -2px 0;
    padding: 0;
}
.popup-cluster-list li {
    padding: 7px 10px;
    cursor: pointer;
    border-radius: 6px;
    font-size: 13.5px;
    color: #222;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background 120ms ease, color 120ms ease;
    -webkit-font-smoothing: antialiased;
}
.popup-cluster-list li::after {
    content: '\203A';
    font-size: 17px;
    line-height: 1;
    color: #c0c0c0;
    flex-shrink: 0;
    margin-left: 8px;
    transition: color 120ms ease;
}
.popup-cluster-list li:hover {
    background: rgba(0, 100, 220, 0.09);
    color: #005ee0;
}
.popup-cluster-list li:hover::after {
    color: #005ee0;
}

/* Province tooltip (follows cursor) */
.tooltip {
    position: absolute;
    left: 0;
    top: 0;
    transform: translate3d(0,0,0);
    will-change: transform, opacity;
    pointer-events: none;
    opacity: 0;
    background: rgba(17,17,17,0.92);
    color: #fff;
    padding: 6px 8px;
    font-size: 13px;
    line-height: 1;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.06);
    box-shadow: 0 8px 24px rgba(0,0,0,0.28);
    transition: opacity 160ms ease, transform 160ms ease;
    z-index: 9999;
    white-space: nowrap;
    font-family: var(--ui-font);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Hotspot popup */
.popup {
    position: absolute;
    left: 0;
    top: 0;
    background: var(--popup-bg);
    border: 1px solid rgba(0,0,0,0.08);
    padding: var(--popup-padding);
    box-sizing: border-box;
    pointer-events: auto;
    opacity: 0;
    visibility: hidden;
    transition: opacity 220ms cubic-bezier(.2,.9,.2,1), box-shadow 220ms ease;
    --popup-left: 0px;
    --popup-top: 0px;
    transform: translate3d(var(--popup-left), var(--popup-top), 0) scale(1);
    max-width: var(--popup-max-width);
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    line-height: var(--popup-line-height);
    border-radius: var(--popup-radius);
    box-shadow: 0 6px 20px rgba(0,0,0,0.08);
    z-index: 10000;
    font-family: var(--ui-font);
    font-size: var(--popup-font-size);
    color: var(--popup-color);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    will-change: transform, opacity;
    transform-origin: 50% 0;
    backface-visibility: hidden;
}
.popup--large { max-width: clamp(360px, 40vw, 760px); }
.popup strong { font-weight: 600; font-size: 1.05em; color: #111; }
.popup p { margin: 0.35em 0 0; }
.popup img {
    width: 100%;
    height: auto;
    object-fit: cover;
    border-radius: 6px;
    display: block;
    margin: 0 0 8px;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 260ms ease, transform 260ms ease;
}
.popup::before, .popup::after { display: none !important; }
.popup.open {
    opacity: 1;
    visibility: visible;
    box-shadow: 0 12px 36px rgba(0,0,0,0.12);
}

.map-interaction-active .popup,
.map-interaction-active #map-controls {
    pointer-events: none !important;
}

/* Map card layout */
.map-card h1 {
    font-family: inherit;
    text-align: left;
    font-size: 1.75rem;
    margin: 8px 0 12px;
    text-transform: none;
    letter-spacing: 0.5px;
    line-height: 1.2;
    font-weight: bold;
    color: rgb(51, 51, 51);
    margin: 0px;
    padding-top: 0rem;
}
.map-area {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    box-sizing: border-box;
    min-height: 0;
    gap: 20px;
    visibility: hidden;
}

.map-card {
    background: #ffffff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.08);
    overflow: hidden;
    max-width: 50%;
    width: calc(100% - 32px);
    box-sizing: border-box;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    gap: 20px;
    min-height: 0;
}

.map-meta {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: center;
}
.map-meta img {
    max-width: 100%;
    height: auto;
}

/* Search UI */
.map-search {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
}
#map-search {
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.08);
    box-shadow: 0 4px 10px rgba(0,0,0,0.04);
    font-size: 13px;
    width: 320px;
    max-width: 40vw;
}
.map-search-suggestions {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    width: 320px;
    box-sizing: border-box;
    margin: 0;
    background: #fff;
    list-style: none;
    padding: 6px 0;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    border: 1px solid rgba(0,0,0,0.06);
    z-index: 10001;
    min-width: 320px;
    max-width: 320px;
    max-height: 280px;
    display: none;
    overflow: auto;
}
.map-search-suggestions[aria-hidden="false"] { display: block; }
.map-search-suggestions li { padding: 8px 12px; cursor: pointer; font-size: 13px; }
.map-search-suggestions li.selected, .map-search-suggestions li:hover { background: rgba(0, 0, 0, 0.08); }

/* Active state highlight (search) */
.state.state--active {
    stroke: var(--popup-accent, #000000) !important;
    stroke-width: 1px !important;
    vector-effect: non-scaling-stroke;
    pointer-events: none;
    opacity: 1 !important;
    filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.12));
}
.state.state--active:hover {
    stroke: var(--popup-accent, #000000) !important;
    stroke-width: 1px !important;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .popup, .popup img, .tooltip, .landing-card, .hotspot {
        transition: none !important;
        animation: none !important;
    }
}

/* Responsive breakpoints */
@media (max-width: 1190px) {
    .map-card { padding: 10px; width: calc(100% - 20px); max-width: 80%;}
    .map-card h1 { text-align: left; font-size: 25px; margin: 6px 0 10px; }
    #map { -webkit-overflow-scrolling: touch; }
    #map svg { touch-action: none; }
}

@media (max-width: 790px) {
    .map-card { padding: 10px; width: calc(100% - 20px); max-width: 90%; }
    .map-meta { grid-template-columns: 1fr; grid-template-rows: auto auto; gap: 8px; }
    .landing-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
    #map { -webkit-overflow-scrolling: touch; }
    #map svg { touch-action: none; }
}

@media (max-width: 520px) {
    .map-card { padding: 10px; width: calc(100% - 20px); max-width: 100%; }
    .map-meta img { width: 150px; margin: 0; }
    .map-card h1 { font-size: 20px;}
    #map { -webkit-overflow-scrolling: touch; }
    #map svg { touch-action: none; }

    .popup {
        position: fixed;
        left: 12px !important;
        right: 12px !important;
        top: auto !important;
        bottom: 5% !important;
        transform: translateY(0) scale(1);
        max-width: calc(100% - 24px);
        border-radius: 10px;
        box-shadow: 0 12px 36px rgba(0,0,0,0.14);
    }
    .popup::after { display: none; }

    .popup img {
        width: auto;
        max-width: 100%;
        max-height: 65vh;
        display: block;
        margin: 0 auto 8px;
    }

    .popup-cluster-list li {
        padding: 10px 10px;
        font-size: 15px;
    }

    .landing-heading { font-size: 1.5rem; }
    .landing-grid { grid-template-columns: 1fr; }
}

/* map wrapper */
/* Allow the page to continue scrolling when the map cannot scroll itself.
    Avoid trapping wheel gestures inside the map element (prevents scroll chaining).
*/
#map { grid-column: 1; grid-row: 2; min-height: 320px; display: flex; align-items: center; justify-content: center; height: auto; overflow-x: hidden; overflow-y: auto; overscroll-behavior: auto;}

#map svg { display: block; max-width: 100%; height: auto; pointer-events: auto;}

.map-card > #map svg, .map-area svg { width: 100%; height: 100%; max-height: 100%; object-fit: contain; display: block; }