/* --- Global & Strict Mobile Viewport Fix --- */
html, body {
    margin: 0; padding: 0;
    width: 100%; height: 100%;
    position: fixed; inset: 0;
    background-color: #1a1511;
    overflow: hidden;
    overscroll-behavior: none;
    font-family: "Georgia", serif;
    -webkit-tap-highlight-color: transparent;
}

#loadingScreen {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: #2b1d12; z-index: 9999;
    display: flex; justify-content: center; align-items: center;
    color: #dfc494; font-size: 1.5rem; font-style: italic;
    transition: opacity 0.5s ease-out;
}

#dustCanvas {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    z-index: 4; pointer-events: none;
}

/* Local Magic Birds Page Overlay (Positioned to match inner book content context container) */
#magicBirdsLayer {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 150;
    overflow: hidden;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.magic-floating-bird {
    position: absolute;
    pointer-events: none;
    will-change: transform;
    filter: drop-shadow(0 2px 2px rgba(0,0,0,0.35));
}

.book-container {
    position: relative; width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center; z-index: 5;
    opacity: 0; transition: opacity 1s;
}
.book-container.ready { opacity: 1; }

/* Audio Layout Controller Styling */
.audio-widget {
    position: absolute;
    top: 2%;
    left: 2%;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: rgba(43, 29, 18, 0.85);
    padding: 8px 12px;
    border-radius: 8px;
    border: 2px solid #dfc494;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    transition: transform 0.2s ease;
}
.audio-widget:hover {
    transform: scale(1.03);
}

.audio-btn {
    background: none;
    border: none;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
}
.audio-btn svg {
    width: 28px;
    height: 28px;
    fill: #dfc494;
    transition: fill 0.2s, transform 0.1s;
}
.audio-btn:active svg {
    transform: scale(0.9);
}
.audio-btn.muted svg {
    fill: #8b7355;
}

.volume-slider-container {
    width: 70px;
    display: flex;
    align-items: center;
}
.volume-slider-container input[type="range"] {
    width: 100%;
    margin: 0;
    cursor: pointer;
    accent-color: #dfc494;
}

.audio-label {
    color: #dfc494;
    font-size: 0.65rem;
    font-style: italic;
    letter-spacing: 0.5px;
    text-transform: lowercase;
    text-align: center;
    pointer-events: none;
    white-space: nowrap;
}

.page {
    background-color: #fdf5e6;
    box-shadow: inset 0 0 20px rgba(101, 67, 33, 0.4);
    overflow: hidden; position: relative;
}

.page img {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%; object-fit: cover; pointer-events: none;
    z-index: 1;
}
.page-cover { background-color: #3e2723; }

/* Page 2 Glow */
.glow-overlay {
    position: absolute; top: 45%; left: 50%; transform: translate(-50%, -50%);
    width: 40%; height: 20%;
    background: radial-gradient(circle, rgba(255,215,0,0.6) 0%, rgba(255,215,0,0) 70%);
    animation: pulse-glow 3s infinite alternate ease-in-out; pointer-events: none; mix-blend-mode: overlay;
    z-index: 2;
}
@keyframes pulse-glow {
    0% { opacity: 0.3; transform: translate(-50%, -50%) scale(0.9); }
    100% { opacity: 0.8; transform: translate(-50%, -50%) scale(1.1); }
}

/* Page 6 Environment Animations */
.map-page {
    position: relative;
    overflow: hidden;
}

.map-page img,
.map-paths {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

.env-bird {
    position: absolute; top: 22%; left: -10%;
    animation: flyBird 16s linear infinite; pointer-events: none;
    filter: drop-shadow(0 5px 3px rgba(0,0,0,0.3));
    z-index: 3;
}

.env-water-shimmer {
    position: absolute; top: 56%; left: 15%; width: 50%; height: 25%;
    background: radial-gradient(ellipse, rgba(135, 206, 235, 0.7) 0%, transparent 60%);
    animation: shimmer 2.5s infinite alternate ease-in-out; pointer-events: none;
    mix-blend-mode: overlay;
    z-index: 2;
}

@keyframes flyBird { 0% { transform: translate(0, 0) scale(0.8); } 100% { transform: translate(120vw, -20vh) scale(1.2); } }
@keyframes shimmer { 0% { opacity: 0.4; transform: scale(0.95); } 100% { opacity: 1; transform: scale(1.05); } }

/* Dropzones */
.dropzone { position: absolute; z-index: 100; pointer-events: auto; }
#zone-church { bottom: 10%; right: 5%; width: 30%; height: 30%; }
#zone-venue { top: 45%; left: 10%; width: 30%; height: 30%; }
/* FIXED: Store dropzone placed at lower-left over the store graphics */
#zone-store { bottom: 5%; left: 5%; width: 30%; height: 25%; }

.map-paths { position: absolute; top:0; left:0; width:100%; height:100%; pointer-events: none; z-index: 2; }

/* Character Layout styling */
.child-adventurer {
    position: absolute;
    width: 80px;
    height: 90px;
    top: 76%;          /* Exactly on the bridge vertically */
    left: 47%;         /* Exactly on the bridge horizontally */
    margin-top: -45px; /* Offsets half height so center locks to 76% without breaking GSAP */
    margin-left: -40px;/* Offsets half width so center locks to 47% without breaking GSAP */
    z-index: 1000;
    cursor: grab;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    touch-action: none !important;
    -webkit-user-select: none;
    user-select: none;
    pointer-events: auto;
}

/* Mobile responsive scaling */
@media (max-width: 768px) {
    .child-adventurer {
        width: 50px;
        height: 56px;
        margin-top: -28px;
        margin-left: -25px;
    }
}

.child-adventurer:active { cursor: grabbing; }

.character {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    transform-origin: center bottom;
    animation: breathe 2s infinite alternate ease-in-out;
}

.character-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

.shadow {
    width: 70px;
    height: 8px;
    background: rgba(0,0,0,0.4);
    border-radius: 50%;
    filter: blur(3px);
    margin-top: -4px;
    z-index: 1;
    animation: shadow-scale 2s infinite alternate ease-in-out;
}

/* Character Speech Dialogue Bubble Styling */
.bubble-speech-wrap {
    position: absolute;
    bottom: 100%;               /* Anchors the bubble right to the top edge of the head */
    margin-bottom: 6px;         /* Creates a clean 6px gap above Lior */
    left: 50%;
    transform: translateX(-50%) scale(0);
    transform-origin: bottom center;
    background: #ffffff;
    border: 2px solid #654321;
    border-radius: 12px;
    padding: 6px 12px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.25);
    white-space: nowrap;
    z-index: 1005;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.bubble-speech-wrap.speech-active {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}
.speech-inner-bubble {
    color: #3e2723;
    font-size: 0.75rem;
    font-weight: bold;
    font-family: "Georgia", serif;
}
.speech-pointer-tip {
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-top: 8px solid #654321;
}
.speech-pointer-tip::after {
    content: '';
    position: absolute;
    top: -10px;
    left: -6px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 7px solid #ffffff;
}

/* Walking Animations */
.is-walking .character {
    animation: walk-bounce 0.5s infinite linear;
}

@keyframes breathe { 0% { transform: scale(0.97); } 100% { transform: scale(1.03); } }
@keyframes walk-bounce {
    0%, 100% { transform: translateY(0) scale(1) rotate(0deg); }
    50% { transform: translateY(-8px) scaleY(0.95) rotate(3deg); }
}
@keyframes shadow-scale { 0% { transform: scaleX(0.8); opacity: 0.6; } 100% { transform: scaleX(1.1); opacity: 0.3; } }

/* --- RSVP Page Layout Details --- */
.rsvp-btn {
    position: absolute; width: 50%; height: 10%; left: 25%;
    cursor: pointer; z-index: 100; touch-action: none;
    -webkit-user-select: none; user-select: none;
}
.rsvp-yes { top: 55%; }
.rsvp-no { top: 72%; }

/* --- Popups --- */
.vintage-popup {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.8); z-index: 2000;
    display: flex; justify-content: center; align-items: center;
    opacity: 1; transition: opacity 0.4s ease;
}
.vintage-popup.hidden { opacity: 0; pointer-events: none; }

.popup-content {
    background: #e1cda5;
    border: 4px solid #654321; outline: 2px solid #8b5a2b; outline-offset: -6px;
    width: 85%; max-width: 450px; padding: 40px; border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8), inset 0 0 50px rgba(139, 90, 43, 0.3);
    position: relative; text-align: center; color: #3e2723;
}
.popup-content h2 { border-bottom: 2px dashed #8b5a2b; padding-bottom: 10px; margin-top: 0; }
.close-btn { position: absolute; top: 10px; right: 15px; background: none; border: none; font-size: 24px; cursor: pointer; color: #654321; }

.interactive-btn {
    display: inline-block; margin-top: 20px; padding: 12px 24px;
    background: #654321; color: #fdf5e6; text-decoration: none; border-radius: 5px;
    font-weight: bold; transition: background 0.3s;
}
.interactive-btn.hidden { display: none; }

/* --- Map Instruction Popup Specifics --- */
#mapGuidePopup .popup-content {
    max-width: 380px;
}
#mapGuidePopup p {
    font-size: 1rem;
    line-height: 1.5;
    margin: 15px 0;
}

/* --- Scratch Canvas --- */
.scratch-container { position: relative; width: 100%; height: 250px; margin-top: 15px; border: 3px solid #8b5a2b; border-radius: 5px; overflow: hidden; }
.scratch-container img, #scratchCanvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
#realVenue { object-fit: cover; z-index: 1; }
#scratchCanvas { cursor: crosshair; z-index: 2; touch-action: none; -webkit-user-select: none; user-select: none; }

#closingMessage { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); color: white; font-size: 2em; z-index: 3000; text-shadow: 0 0 10px rgba(255,255,255,0.5); transition: opacity 1s; text-align: center; width: 90%;}
#closingMessage.hidden { opacity: 0; pointer-events: none; }

/* --- Custom Mobile Hard-Close Overlay --- */
.mobile-cover-overlay {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 100%; height: 100%;
    z-index: 9999;
    pointer-events: none;
    overflow: visible;
    perspective: 2000px;
}

.mobile-cover-overlay img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform-origin: right center;
    transform: rotateY(-90deg);
    box-shadow: -10px 0 20px rgba(0,0,0,0.5);
}

.mobile-cover-overlay.hidden {
    display: none;
}

#mapPage {
    position: relative;
    z-index: 5;
}

/* Custom Church Verification Styling */
#churchAuthSection input {
    background: #fdfbf7;
    border: 1px solid #c8b288;
    color: #4a3b32;
    font-size: 0.95rem;
    outline: none;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.08);
    transition: border-color 0.3s ease;
}

#churchAuthSection input:focus {
    border-color: #8b5a2b;
}

.auth-message {
    font-size: 0.9rem;
    line-height: 1.4;
    padding: 8px;
    border-radius: 6px;
    background-color: rgba(217, 83, 79, 0.08);
}

/* --- General Store Popup Feature Styling --- */
.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.82);
    z-index: 2500;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s ease-in-out;
}

.popup-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Main Modal Card */
.shelf-modal-card {
    position: relative;
    width: 90%;
    max-width: 440px;           /* Sized so web shows full image without spilling */
    max-height: 88vh;           
    display: flex;
    flex-direction: column;
    background: #2b1d0c;
    border: 6px solid #5a3c18;
    border-radius: 12px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.8);
    overflow-y: auto;           /* Allows smooth scroll if screen height is tiny */
    color: #4a2e12;
    font-family: Georgia, serif;
    margin: auto;
    box-sizing: border-box;
}

.shelf-close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    z-index: 100;
    background: #3e2610;
    color: #f3e5ab;
    border: 2px solid #8b5a2b;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.5);
    transition: transform 0.2s ease, background-color 0.2s ease;
}

.shelf-close-btn:hover {
    transform: scale(1.1);
    background-color: #5a3c18;
}

.shelf-header {
    text-align: center;
    background: #3e2610;
    color: #f3e5ab;
    padding: 10px;
    font-size: 1.1rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    border-bottom: 2px solid #8b5a2b;
}

/* Shelf Viewport — Locks 1:1 aspect ratio so hotspots never misalign */
.shelf-viewport {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1 !important;  /* Forces exact square */
    flex-shrink: 0 !important;       /* PREVENTS flexbox from squashing height */
    background: url('assets/shelf.png') center/cover no-repeat;
    box-sizing: border-box;
}

.shelf-hotspot {
    position: absolute;
    cursor: pointer;
    border-radius: 8px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.shelf-hotspot:hover {
    transform: scale(1.03);
    box-shadow: 0 0 15px rgba(240, 185, 58, 0.6);
}

.hotspot-robes { top: 12%; left: 8%; width: 32%; height: 70%; }
.hotspot-backpack { top: 30%; left: 38%; width: 33%; height: 50%; }
.hotspot-camera { top: 60%; left: 68%; width: 28%; height: 28%; }

/* --- Crisp Text Fixes for General Store Card --- */
.shelf-card-detail {
    position: relative;
    background: #fdfbf7;
    padding: 18px;
    min-height: 120px;
    flex: 1;                     /* FILLS remaining card space dynamically */
    overflow-y: auto;            /* ENABLES scrolling inside for long text/photos */
    border-top: 4px solid #8b5a2b;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
    color: #2c1d11 !important;
}

.shelf-card-detail h4 {
    font-family: "Georgia", serif;
    font-size: 1.15rem;
    color: #3e2723;
    margin: 0 0 4px 0;
}

.shelf-card-detail p {
    font-size: 0.9rem;
    line-height: 1.4;
    color: #5c4033;
}

.unpack-item-row {
    opacity: 1;
    transform: none;
    background: #ffffff;
    border: 1px solid #dcd0c0;
    border-left: 4px solid #8b5a2b;
    margin: 8px 0;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.88rem;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
    color: #1a1a1a !important;
    letter-spacing: normal !important;
    line-height: 1.4;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.polaroid-frame {
    background: #ffffff;
    padding: 12px 12px 18px 12px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.15);
    transform: rotate(-1deg);
    text-align: left;
    border: 1px solid #e2d8c3;
    margin-top: 10px;
    border-radius: 4px;
}

/* --- Map Target & Path Calibration --- */

/* Position the dropzone directly over the General Store building in lower-left */
#zone-store { 
    bottom: 8%; 
    left: 18%; 
    width: 32%; 
    height: 30%; 
    z-index: 100;
}

/* --- Store Dropzone position --- */
#zone-store {
    bottom: 5%;
    left: 10%;
    width: 35%;
    height: 30%;
    z-index: 100;
}

/* --- Crisp Carousel Card Styles for Shelf Items --- */
.carousel-card-wrap {
    background: #ffffff;
    border: 1px solid #dcd0c0;
    border-radius: 8px;
    padding: 12px;
    margin-top: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.carousel-nav-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.carousel-content-slot {
    flex: 1;
    min-height: 80px;
    display: flex;
    align-items: center;
}

.unpack-item-row {
    display: none;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
    font-size: 0.88rem;
    line-height: 1.45;
    color: #2c1d11 !important;
    letter-spacing: normal !important;
    text-align: left;
    width: 100%;
}

.unpack-item-row.active {
    display: block;
    animation: carouselFadeIn 0.25s ease-in-out;
}

.unpack-item-row strong {
    color: #8b5a2b;
}

/* Pagination Arrow Buttons */
.carousel-nav-btn {
    background: #8b5a2b;
    color: #ffffff;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, opacity 0.2s;
    user-select: none;
    flex-shrink: 0;
}

.carousel-nav-btn:hover:not(:disabled) {
    background: #5c3a1a;
}

.carousel-nav-btn:disabled {
    background: #e0d5c5;
    color: #a09585;
    cursor: not-allowed;
    opacity: 0.5;
}

/* Step Dots */
.carousel-step-dots {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 10px;
}

.carousel-step-dots .step-dot {
    width: 7px;
    height: 7px;
    background-color: #dcd0c0;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.carousel-step-dots .step-dot.active {
    background-color: #8b5a2b;
}

@keyframes carouselFadeIn {
    from { opacity: 0; transform: translateY(2px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Update around line 513 in main style.css (Desktop) */
.hotspot-camera {
    top: 60%;
    left: 68%;
    width: 25%;    /* Reduced from 28% to fit camera width */
    height: 22%;   /* Reduced from 28% so it doesn't spill onto the bottom wooden ledge */
}

/* --- Mobile Layout & Text Protection Fix --- */
@media (max-width: 768px) {
    /* 1. Modal Container locked to screen height */
    .shelf-modal-card {
        width: 92% !important;
        max-width: 400px !important;
        max-height: 84dvh !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;   /* Keeps outer corners rounded */
    }

    /* 2. Compact header bar */
    .shelf-header {
        padding: 6px 8px !important;
        flex-shrink: 0 !important;
    }

    /* 3. Compact shelf image height to give text maximum vertical space */
    .shelf-viewport {
        height: 160px !important;
        min-height: 160px !important;
        flex-shrink: 0 !important;
        aspect-ratio: auto !important;
        background-position: center center !important;
        background-size: cover !important;
    }

    /* 4. White Details Box — Scrollable so NO text is ever sliced off */
    .shelf-card-detail {
        flex: 1 1 auto !important;
        overflow-y: auto !important;  /* Enables internal scrolling if text runs long */
        padding: 12px 14px 24px 14px !important; /* Bottom padding keeps last sentence away from border */
        min-height: 0 !important;
    }

    .shelf-card-detail p {
        font-size: 0.82rem !important;
        line-height: 1.35 !important;
    }

    /* 5. Mobile Hotspot Alignments for 160px shelf */
    .hotspot-robes {
        top: 2% !important;
        left: 7% !important;
        width: 32% !important;
        height: 92% !important;
    }

    .hotspot-backpack {
        top: 15% !important;
        left: 36% !important;
        width: 34% !important;
        height: 72% !important;
    }

    /* Mobile Camera Hotspot Fix */
    .hotspot-camera {
       top: 75% !important;     /* Pushes the box down directly onto the camera */
       left: 68% !important;    /* Keeps horizontal alignment centered over the camera */
       width: 27% !important;   /* Snug width around the camera body */
       height: 28% !important;  /* Stops at the top edge of the wooden shelf */
    }

}