/* =========================================
   1. VARIABLES & RESET
   ========================================= */
:root {
    --primary: gold;
    --text: #333;
    --bg: #eaf3fa;
    --anim: 0.3s ease;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Poppins", sans-serif;
    background: var(--bg);
    overflow: hidden; /* Default: Locked for Desktop app-like feel */
}

/* =========================================
   2. LOADER
   ========================================= */
#loading-screen {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.4s ease;
}
#loading-screen.hidden { opacity: 0; pointer-events: none; }

.spinner {
    width: 60px; height: 60px;
    border: 6px solid #ddd;
    border-top: 6px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
    margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================
   3. MAP ENGINE (The Core Fix)
   ========================================= */

/* The Viewport Frame */
.map-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    background: #aaddff; /* Fallback blue */
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: filter var(--anim);
}

/* The Content Wrapper
   (Holds Image + Pins together so they never drift) */
.map-wrapper {
    position: relative;
    /* Aspect Ratio is CRITICAL. It locks the coord system. */
    aspect-ratio: 3840/2156;
    height: 100%;
    width: auto;
    max-width: 100%;
}

/* The Map Image */
.map-bg {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Never crop the image */
    display: block;
}

/* State: Dim map when popup is open */
.map-container.map-active { filter: brightness(0.8); }

/* --- MOBILE SPECIFIC (Pan Mode) --- */
@media (orientation: portrait) {
    body {
        /* Enable swiping on phone */
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .map-container {
        display: block; /* Unlock flexbox centering */
        width: auto;
        height: 100vh;
        overflow-x: auto; /* Allow horizontal scroll */
        overflow-y: hidden;
    }

    .map-wrapper {
        height: 100vh; /* Force full height */
        width: auto;   /* Width expands naturally */
        max-width: none; /* Remove desktop limit */

        /* Ensure wrapper is at least screen width */
        min-width: 100vw;
    }
}

/* =========================================
   4. ICONS & PINS
   ========================================= */
/* Position relative to .map-wrapper now! */
.icon, .pin { position: absolute; }

.icon {
    transform: translate(-50%, -50%);
    z-index: 20;
    transition: transform var(--anim), opacity var(--anim);
    pointer-events: none;
}
.icon.active {
    transform: translate(-50%, -50%) scale(2.2);
    z-index: 100;
    filter: drop-shadow(0 10px 20px rgba(0,0,0,0.4));
}
.icon img { width: 100%; height: auto; display: block; }

/* Optimization: Fade out inactive icons */
.map-container.map-active .icon:not(.active) { opacity: 0.3; }

/* Responsive Icon Sizes */
[data-target="blackgazebo"] { width: 9%; }
[data-target="whitegazebo"] { width: 7%; }
[data-target="ballroom"]    { width: 18%; }
[data-target="canopy"]      { width: 8%; }
[data-target="field"]       { width: 15%; }
[data-target="food_court"]  { width: 8%; }
[data-target="office"]      { width: 10%; }

/* Pins */
.pin {
    transform: translate(-50%, -100%);
    cursor: pointer;
    z-index: 50;
    transition: transform 0.25s ease, filter 0.25s ease, opacity 0.2s ease;
    transform-origin: bottom center;
}
.pin:hover {
    transform: translate(-50%, -100%) scale(1.18);
    filter: drop-shadow(0 0 6px var(--primary));
}
.pin img { width: clamp(30px, 4vw, 55px); height: auto; }

/* Hide pins when popup opens */
.map-container.map-active .pin { opacity: 0; pointer-events: none; }


/* =========================================
   5. POPUP DRAWER
   ========================================= */
.popup {
    position: fixed;
    top: 0; right: 0;
    width: 40%; max-width: 550px; height: 100%;
    background: white;
    box-shadow: -5px 0 25px rgba(0,0,0,0.3);
    transition: transform 0.45s cubic-bezier(0.25, 1, 0.5, 1);
    z-index: 200;
    padding: 20px;
    display: flex; flex-direction: column;
    overflow-y: auto;
    transform: translateX(100%);
}

.popup.right { right: 0; left: auto; transform: translateX(100%); }
.popup.left  { left: 0; right: auto; transform: translateX(-100%); }
.popup.show.right, .popup.show.left { transform: translateX(0); }

.close-btn {
    position: absolute;
    top: 15px; right: 15px;
    background: #ff5555; color: white;
    border-radius: 50%; border: none;
    width: 36px; height: 36px; cursor: pointer;
    z-index: 10;
}

/* =========================================
   6. GALLERY & UI COMPONENTS
   ========================================= */
.gallery { position: relative; margin-top: 60px; }
.gallery img {
    width: 100%; max-height: 400px;
    object-fit: contain; border-radius: 10px;
    transition: opacity var(--anim);
}

.nav-btn {
    position: absolute; top: 50%;
    transform: translateY(-50%);
    background: var(--primary);
    border: none; width: 36px; height: 36px;
    border-radius: 50%; cursor: pointer;
}
#prevImg { left: -20px; }
#nextImg { right: -20px; }

#popupText {
    font-family: 'Open Sans', sans-serif;
    margin-top: 15px; font-size: 16px;
    color: var(--text); line-height: 1.6;
}
#popupText .poem {
    font-family: 'Playfair Display', serif;
    font-style: italic; font-weight: 500;
    font-size: 18px; display: block;
    margin-bottom: 12px; color: #444;
}

.home-btn {
    position: fixed; top: 15px; left: 15px;
    z-index: 9000;
    background: var(--primary); color: black;
    text-decoration: none; font-weight: 600;
    padding: 10px 18px; border-radius: 50px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.home-btn:hover { transform: scale(1.06); }

/* --- Mobile Tweaks --- */
@media (max-width: 768px) {
    .popup { width: 90%; max-width: none; }

    /* Slightly smaller pins on phone */
    .pin img { width: 45px; }

    /* Adjust text size */
    #popupText { font-size: 14px; }
}