/*------------- Fae Blossom Wildwood Labyrinth ------------*/
.game-viewport {
    width: 480px;  
    height: 480px; 
    max-width: 95vw; /* Safety for mobile */
    max-height: 95vw; /* Keep it square on mobile */
    overflow: hidden; 
    position: relative;
    margin: 20px auto; 
    border: 4px solid #3e2731;
    background: #1a231a;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

#grid-map {
    display: grid;
    position: absolute; 
    top: 0; left: 0;
    transition: transform 0.2s ease-out; 
    border: 8px solid #3e2731;
    image-rendering: pixelated;
    background: #1a231a;
    box-sizing: border-box;
    width: max-content;
}

.cell {
    width: 64px;
    height: 64px;
    overflow: hidden;
    box-sizing: border-box;
    image-rendering: pixelated;
    background-repeat: no-repeat;
    background-position: center;
}

#maze-info {
    font-family: '04b03', sans-serif;
    font-size: 16px;
    line-height: 1.5;
    text-align: center;
    max-width: 500px;
    margin: 15px auto;
    padding: 10px;
    border-radius: 10px;
}

.ui-dashboard {
    width: 480px;
    background: #e8dff0;
    margin: -21px auto 20px auto;
    border: 6px solid #3e2731;
    border-radius: 0 0 12px 12px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 12px 0;
    font-family: '04b03', sans-serif;
    box-shadow: 0 10px 20px rgba(0,0,0,0.3);
    position: relative;
    z-index: 5;
}

.ui-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.ui-label {
    font-size: 14px;
    color: #3a2f3f;
    letter-spacing: 1px;
}



/* Items Found */

.item-slots {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #b8a5eb;
    padding: 4px 12px;
    border-radius: 4px;
    border: 2px solid white;
    min-width: 60px;
}

.item-slots .bar-text {
    position: static;
    transform: none;
    font-size: 14px;
}

.item-slots .ui-icon {
   margin-top: -10px;
    image-rendering: pixelated;
}


/* Crystals Found */

.crystal-slots .bar-text {
    position: static; 
    transform: none;
    font-size: 14px;
}

.crystal-slots {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 10px;
}


.crystal-slots {
    display: flex;
    flex-direction: row; 
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #b8a5eb;
    padding: 4px 12px;
    border-radius: 4px;
    border: 2px solid white;
    min-width: 60px;
}


.crystal-slots .ui-icon {
    width: 32px;
    height: 32px;
    image-rendering: pixelated;
}


/* Energy Bar Styling */
.energy-bar-container {
    width: 120px;
    height: 20px;
    background: #e8dff0;
    border: 2px solid white;
    position: relative;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}

.energy-bar-fill {
    width: 100%; 
    height: 100%;
    background: linear-gradient(to right, #4e9464, #7fce8e);
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1); 
}

#energy-count {
    position: absolute;
    width: 100%;
    text-align: center;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 14px;
    pointer-events: none; 
    z-index: 2;
}

.music-slots .ui-icon {
    width: 40px;
    height: 40px;
    image-rendering: pixelated;
}




/*------------- Tiles & Base Layer -------------*/
.wall { 
    background-image: url('../assets/tiles/hedge_1.png'); 
    background-size: cover; 
}

/* BASE FLOOR:
   Every non-wall cell uses the --floor-url variable injected by JS.
*/
.cell[class*="floor-"] {
    background-image: var(--floor-url);
    background-size: 64px 64px;
    background-repeat: no-repeat;
    background-position: center;
    position: relative;
}

/* ENTITY STACKING:
   We force the background to be: [Entity Image], [Grass_1 Image].
   This fixes the "wrong grass" under items and the "upscaling" issues.
*/
.cell.crystal, 
.cell.crow-tile, 
.cell.mushroom-ring, 
.cell[class*="item-id-"] {
    background-repeat: no-repeat, no-repeat !important;
    background-position: center, center !important;
    /* First value is Item size, Second value is Grass size */
    background-size: 32px 32px, 64px 64px !important; 
}

/* Specific Image Assignments with grass_1.png forced underneath */
.cell.crystal { 
    background-image: url('https://faeblossom.com/assets/crystal_icon.png'), url('../assets/tiles/grass_1.png') !important; 
}

.cell.mushroom-ring { 
    background-image: url('../assets/tiles/mushroomring.gif'), url('../assets/tiles/grass_1.png') !important; 
    background-size: 64px 64px, 64px 64px !important; /* Upscale to 64 */
}

/* Forageable Item IDs */
.cell.item-id-4 { background-image: url('../assets/tiles/items/acorn.png'), url('../assets/tiles/grass_1.png') !important; }
.cell.item-id-5 { background-image: url('../assets/tiles/items/goldenacorn.png'), url('../assets/tiles/grass_1.png') !important; }
.cell.item-id-6 { background-image: url('../assets/tiles/items/forestleaf.png'), url('../assets/tiles/grass_1.png') !important; }
.cell.item-id-7 { background-image: url('../assets/tiles/items/mushroom.png'), url('../assets/tiles/grass_1.png') !important; }


/*------------- Guardian Crow (Static Method) -------------*/
.cell.crow-tile {
    /* Use the stacking method to force grass_1.png as a backup */
    background-image: var(--floor-url), url('../assets/tiles/grass_1.png') !important;
    background-repeat: no-repeat, no-repeat !important;
    background-position: center, center !important;
    background-size: 64px 64px, 64px 64px !important;
    position: relative;
    overflow: hidden;
}

/* 2. THE BIRD: A separate layer so it never "breaks" the tile background */
.crow-entity {
    position: absolute;
    top: 0; left: 0;
    width: 64px; height: 64px;
    background-image: url('../assets/tiles/crow.gif');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    image-rendering: pixelated;
    z-index: 2;
    pointer-events: none;
    transition: opacity 0.5s ease-out;
}

/* 3. FLIPPING: Just the bird turns, not the whole tile */
.crow-flipped { 
    transform: scaleX(-1); 
}
/* ------- Player Sprites ------- */
.player-sprite {
    width: 64px; height: 64px;
    position: absolute; z-index: 10;
    background-size: contain; background-repeat: no-repeat;
    image-rendering: pixelated;
    transition: left 0.15s ease-out, top 0.15s ease-out;
}
.dir-up    { background-image: url('../assets/sprites/player_up.gif'); }
.dir-down  { background-image: url('../assets/sprites/player_down.gif'); }
.dir-left  { background-image: url('../assets/sprites/player_left.gif'); }
.dir-right { background-image: url('../assets/sprites/player_right.gif'); }

#shake-layer {
    width: 100%;
    height: 100%;
    position: relative;
}

@keyframes bump-subtle {
  0%   { transform: translateX(0); }
  25%  { transform: translateX(-1.5px); }
  50%  { transform: translateX(1.5px); }
  75%  { transform: translateX(-0.5px); }
  100% { transform: translateX(0); }
}

.bump-shake {
    /* 0.1s is fast enough that the eye barely sees the movement, but the brain "feels" it */
    animation: bump-subtle 0.1s ease-in-out; 
}
/*---------- Crow Quiz Modal ---------- */
#crow-quiz-modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.8); display: none; 
    justify-content: center; align-items: center; z-index: 2000; 
}
.modal-content {
    background: white; padding: 30px; border-radius: 15px;
    border: 4px solid #b8a5eb; text-align: center;
    font-family: '04b03', sans-serif; max-width: 80%;
}
#crow-answer-select {
    margin: 15px 0; padding: 8px; background: #e8dff0; width: 100%;
    font-family: '04b03', sans-serif;
}
#crow-submit {
    background: #b8a5eb; 
    font-family: '04b03', sans-serif;
    color: white; border: 2px solid white;
    padding: 8px 16px; border-radius: 8px; cursor: pointer;
}
.shake-error { animation: shake 0.4s both; }
@keyframes shake {
    10%, 90% { transform: translate3d(-2px, 0, 0); }
    20%, 80% { transform: translate3d(4px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
    40%, 60% { transform: translate3d(6px, 0, 0); }
}

/*---------- Overlays & Effects ---------- */
#game-over-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7); display: flex; 
    justify-content: center; align-items: center; z-index: 1000;
}
.overlay-content {
    background: white; padding: 30px; border: 4px solid #5a4a3a;
    border-radius: 12px; text-align: center;
}
.teleporting {
    transition: transform 0.3s ease-in, opacity 0.3s ease-in;
    transform: scale(0) rotate(180deg); opacity: 0;
}
.sparkle-puff {
    position: absolute; width: 64px; height: 64px; z-index: 999;
    background: radial-gradient(circle, #fff 10%, #a5d8ff 40%, transparent 70%);
    animation: sparkle-burst 0.6s ease-out forwards;
}
@keyframes sparkle-burst {
    0% { transform: scale(0.5); opacity: 1; }
    100% { transform: scale(1.5); opacity: 0; }
}

/* --- Stats & Controls --- */
.crystal-daily-stat { font-family: '04b03', sans-serif; font-size: 14px; }
.controls-container { display: flex; justify-content: center;  }
.d-pad { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.d-middle { display: flex; gap: 40px; }
.d-btn {
    width: 45px; height: 45px; background: #b8a5eb;
    border: 3px solid #3e2731; border-radius: 8px; color: white;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 0 #3e2731;
    /* Disables browser-level zooming/gestures on these buttons */
    touch-action: manipulation; 
    
    /* Prevents the browser from showing a "tap highlight" box */
    -webkit-tap-highlight-color: transparent; 
    
    /* Prevents the user from accidentally selecting the button text */
    user-select: none;
}
.d-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #3e2731; }


/* Ivy Fairy Page */
.offering-container {
    margin: 20px auto 0 auto;
    text-align: center;
    max-width: 450px;
    padding: 10px 20px;
}

.fae-select {
    font-family: '04b03', sans-serif;
    background: #fdfbf5;
    border: none;
    border-bottom: 2px solid #b8a5eb;
    padding: 10px;
    width: 100
    color: #5a4a3a;
    outline: none;
    cursor: pointer;
    appearance: none;
}
/* Styling for the disabled (greyed out) options */
.fae-select option:disabled {
    color: #a1a1a1;
    font-style: italic;
    background-color: #f0f0f0;
}
.status-msg {
    font-style: italic;
    font-size: 0.9em;
    color: #7a6a8a;
    margin-top: 8px;
    min-height: 1.2em;
}

.fae-button:active { transform: translateY(2px); box-shadow: 0 2px 0 #8e7bc4; }
.status-msg { font-size: 0.8em; margin-top: 8px; color: #5a4a3a; }


.main-content img[src*="ivyfairy"] {
    width: 195px; 
    height: 180px;

    /* 2. Critical for crisp pixel art */
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    image-rendering: -moz-crisp-edges;

    /* 3. Visual effects */
    display: block;
    filter: drop-shadow(0 0 12px rgba(184, 165, 235, 0.4));
    
    /* 4. The floating animation */
    animation: fairy-float 5s ease-in-out infinite;
}
.main-content img[src*="ivyfairy"] + p {
    margin-top: -10px;           /* Remove the default top gap of the paragraph */
    margin-bottom: -10px;    /* Control the gap before the 'maze-info' box */
}
@keyframes fairy-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}
.glow-ready {
    box-shadow: 0 0 15px #b8a5eb;
    border-color: #ffffff !important;
    animation: button-pulse 2s infinite;
}

@keyframes button-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Container to center the button */
.launch-container {
    margin: 10px auto 40px auto;
    text-align: center;
}

.maze-enter-button {
    display: inline-block;
    text-decoration: none;
    font-family: '04b03', sans-serif;
    font-size: 16px;
    padding: 15px 40px;
    background-color: #4e9464; /* Forest Green */
    color: white;
    border: 4px solid #3e2731;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 6px 0 #2a4d35, 0 0 15px rgba(184, 165, 235, 0.3);
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.maze-enter-button:hover {
    background-color: #5faf78;
    transform: translateY(-2px);
    color: white;
    box-shadow: 0 8px 0 #2a4d35, 0 0 20px rgba(184, 165, 235, 0.6);
}

.maze-enter-button:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 #2a4d35;
}

/* The "Ready" state - triggers when an offering is made */
.maze-enter-button.glow-ready {
    background-color: #b8a5eb; /* Switches to Fairy Purple */
    box-shadow: 0 6px 0 #8e7bc4, 0 0 25px #b8a5eb;
    animation: portal-pulse 2s infinite;
}

@keyframes portal-pulse {
    0%, 100% { box-shadow: 0 6px 0 #8e7bc4, 0 0 15px #b8a5eb; }
    50% { box-shadow: 0 6px 0 #8e7bc4, 0 0 35px #d4c7f7; }
}

/*------------- Mobile Responsiveness -------------*/
@media (max-width: 600px) {
    /* 1. Fix Viewport and Dashboard Width */
    .game-viewport, .ui-dashboard {
        width: 95vw; /* Use almost full width of the phone screen */
        max-width: 480px;
    }

    /* 2. Fix UI Stacking - Keep them in a row */
    .ui-dashboard {
        display: flex;
        flex-direction: row; /* Force horizontal layout */
        flex-wrap: nowrap;
        justify-content: space-evenly;
        padding: 10px 5px;
        margin-top: -15px; /* Pull closer to the game window */
        background: #e8dff0 !important; /* Force background color */
    }

    /* 3. Scale the Icons */
    .ui-icon {
        width: 38px !important;
        height: 38px !important;
        image-rendering: pixelated;
    }

    /* 4. Increase Bar/Slot Sizes for readability */
    .item-slots, .crystal-slots {
        background: #b8a5eb !important; /* Force background color */
        padding: 6px 8px;
        min-width: 50px;
        gap: 4px;
    }

    .energy-bar-container {
        width: 80px; /* Slimmer for small screens */
    }

    /* 5. Fix Missing Backgrounds behind items */
    .cell.crystal, .cell.mushroom-ring, .cell[class*="item-id-"], .cell.crow-tile {
        /* Ensure the grass is forced as the bottom layer */
        background-image: var(--floor-url), url('../assets/tiles/grass_1.png') !important;
        background-size: 32px 32px, 64px 64px !important;
        background-color: #1a231a; /* Dark fallback to prevent white gaps */
    }

    /* 6. Adjust D-Pad for thumbs */
    .controls-container {
        margin-top: 20px;
    }
    .d-btn {
        width: 55px; /* Larger hit area for fingers */
        height: 55px;
    }
}

