@import url('https://fonts.googleapis.com/css2?family=Luckiest+Guy&display=swap');
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    user-select: none;
    -webkit-tap-highlight-color: transparent; /* Removes blue overlay on tap */
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #222;
    color: white;
}

.hidden {
    display: none !important;
}

#btn-minimize-upgrades {
    display: none !important; /* Hidden on desktop */
}

@keyframes spinBackground {
    from { transform: translate(-50%, -50%) rotate(0deg); }
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

@keyframes rgbGlow {
    0% { box-shadow: 0 0 15px rgba(255, 0, 0, 0.8), inset 0 0 10px rgba(255, 0, 0, 0.5); border-color: #ff0000; }
    33% { box-shadow: 0 0 15px rgba(0, 255, 0, 0.8), inset 0 0 10px rgba(0, 255, 0, 0.5); border-color: #00ff00; }
    66% { box-shadow: 0 0 15px rgba(0, 0, 255, 0.8), inset 0 0 10px rgba(0, 0, 255, 0.5); border-color: #0000ff; }
    100% { box-shadow: 0 0 15px rgba(255, 0, 0, 0.8), inset 0 0 10px rgba(255, 0, 0, 0.5); border-color: #ff0000; }
}

#splash-screen, #main-menu, #settings-menu, #animals-menu, #hero-selection {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    background: transparent; /* Ensure transparent so global BG shows */
}

#global-background {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 200vmax; /* Much larger than screen to cover corners when spinning */
    height: 200vmax;
    background: url('menu_background.png') no-repeat center center;
    background-size: cover;
    z-index: 1; /* Behind everything */
    animation: spinBackground 120s linear infinite; /* Slow spin */
    pointer-events: none;
}

.menu-panel {
    background: black;
    padding: 15px; /* Reduced from 40px */
    border-radius: 15px;
    border: 3px solid white;
    text-align: center;
    max-width: 95%; /* Increased width slightly */
    max-height: 100vh; /* Increased height allowance */
    overflow-y: hidden; /* Disable scroll */
    animation: rgbGlow 4s linear infinite;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center; /* Center vertically */
    gap: 5px; /* Reduced gap from 15px */
}
#splash-screen {
    cursor: pointer;
}

h1 { 
    font-family: 'Luckiest Guy', cursive; 
    font-size: 4.5rem; 
    margin-bottom: 20px; 
    color: #FFEB3B;
    text-shadow: 4px 4px 0px #2E7D32, 6px 6px 0px #1B5E20; 
    letter-spacing: 3px;
    -webkit-text-stroke: 2px #1B5E20;
}
h2 { font-size: 2.5rem; margin-bottom: 20px; }

button, .button-link {
    display: block;
    width: 280px;
    padding: 15px 10px;
    margin: 12px auto;
    
    /* Jungle Green Style */
    background: linear-gradient(to bottom, #66BB6A 0%, #2E7D32 100%);
    border: 3px solid #A5D6A7;
    border-radius: 15px;
    
    /* Typography */
    font-family: 'Luckiest Guy', cursive;
    color: white;
    font-size: 1.5rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    text-shadow: 2px 2px 0px #1B5E20;
    text-decoration: none;
    text-align: center;
    cursor: pointer;
    
    /* 3D Pop Effect */
    box-shadow: 0 6px 0 #1B5E20, 0 10px 10px rgba(0,0,0,0.3);
    transition: all 0.1s ease;
    position: relative;
    top: 0;
}

button:active { 
    top: 6px; 
    box-shadow: 0 0 0 #1B5E20, inset 0 3px 5px rgba(0,0,0,0.4);
    background: linear-gradient(to bottom, #2E7D32 0%, #1B5E20 100%);
}
button:hover { background: #000000; border-color: #fff; }
/* Hero Selection */
.hero-options {
    flex: 1.5; /* Right column takes slightly more space */
    display: flex;
    flex-wrap: wrap; /* Allow cards to wrap to next line */
    justify-content: center; /* Center cards horizontally */
    gap: 10px;
    align-content: flex-start; /* Start cards at the top */
    height: 100%; /* Fill the height of the layout wrapper */
    overflow-y: auto; /* Scroll ONLY the cards if they don't fit */
    padding-left: 10px; /* Spacing from left column */
    border-left: 1px solid #555; /* Optional separator line */
}
.hero-card {
    background: rgba(255,255,255,0.1);
    padding: 10px;
    border-radius: 10px;
    cursor: pointer;
    border: 2px solid transparent;
    position: relative;
    width: 140px; /* Force fixed width so they grid nicely */
    flex-shrink: 0;
}

/* Hero Card Specific Colors (Lighter versions of My Animals) */
.hero-card[data-type="deer"] { background: rgba(160, 82, 45, 0.6); } /* Sienna */
.hero-card[data-type="chimp"] { background: rgba(70, 100, 100, 0.6); } /* Lighter Slate */
.hero-card[data-type="dog"] { background: rgba(107, 142, 35, 0.6); } /* Olive Drab */
.hero-card[data-type="snake"] { background: rgba(106, 90, 205, 0.6); } /* Slate Blue */
.hero-card[data-type="pig"] { background: rgba(218, 165, 32, 0.6); } /* GoldenRod */
.hero-card[data-type="anteater"] { background: rgba(165, 42, 42, 0.6); } /* Brown */
.hero-card[data-type="cat"] { background: rgba(32, 178, 170, 0.6); } /* Light Sea Green */

/* Ensure hover effect creates a "glow" on top of the color */
.hero-card:hover { 
    filter: brightness(1.3); 
    border-color: #ff9800; 
}
/* Add this logic for locked cards */
.hero-card[data-locked="true"] {
    opacity: 0.8;
    border-color: #555;
}
.hero-card[data-locked="false"] img {
    filter: none !important; /* Remove grayscale when unlocked */
}
.hero-card:hover { border-color: #ff9800; background: rgba(255,255,255,0.2); }

#game-ui {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Let clicks pass through to canvas */
    z-index: 20; /* Higher than Canvas (5) and Menu Background */
}

#roster-panel {
    position: absolute;
    top: 120px;
    left: 20px;
    display: flex;
    flex-direction: column;
    gap: 0;
    pointer-events: auto; /* Changed to auto so button is clickable */
    transition: all 0.3s ease;
}

#roster-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 50vh;
    overflow-y: auto;
    pointer-events: auto; /* ENABLE clicks so scrollbar works */
}

/* Mobile Layout Overrides */
@media (max-width: 768px) {
   /* Move XP/Upgrade Bar to Bottom */
    #top-bar {
        position: absolute; 
        top: auto;
        bottom: 0;
        left: 0;
        width: 100%;
        padding-right: 0 !important; /* Reset desktop padding */
        /* UPDATED: Large padding pushes buttons up away from screen edge */
        padding-bottom: 25px !important; 
        z-index: 100; 
    }

   /* 4. Position Birdshot Bar ABOVE XP Bar on Mobile */
    #birdshot-bar {
        transform: none !important;
        
        /* Move to bottom */
        top: auto !important;   
        bottom: 200px !important; /* Sits just above the XP/Upgrade bar */
        
        left: 50% !important;
        transform: translateX(-50%) !important; /* Center it */
        
        /* Adjust Size */
        width: 175px !important; 
        height: 30px !important;
        z-index: 100; 
    }
    
    /* Shrink text inside bar for mobile */
    #birdshot-bar #birdshot-text {
        font-size: 0.8rem;
    }
}

.roster-card {
    background: rgba(0,0,0,0.5);
    padding: 5px; /* Reduced padding */
    border-radius: 5px;
    display: flex;
    align-items: center;
    gap: 5px;
    color: white;
    font-weight: bold;
    border: 1px solid #555;
    min-width: 120px;
    transform: scale(0.8); /* 20% smaller overall */
    transform-origin: top left;
    margin-bottom: -10px; /* Compensate for scale gap */
}

/* Gray background for icons */
.roster-card img {
    background-color: #555; 
    border-radius: 50%;
}

#monolith-timer-ui, #map-timer-ui {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 2rem;
    font-weight: bold;
    text-shadow: 2px 2px 0px black;
    pointer-events: none;
}
#monolith-timer-ui { top: 80px; color: #ff00ff; }
#map-timer-ui { top: 120px; color: #00ff00; }

#top-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    padding-right: 240px; /* Shift content left to avoid top-right icons */
    background: rgba(0,0,0,0.6);
    pointer-events: auto;
    gap: 20px;
    flex-wrap: wrap; /* Added */
}

.stat-box {
    font-size: 1.5rem;
    font-weight: bold;
    color: #ffd700;
}

.upgrades {
    display: flex;
    gap: 10px;
}

.upgrade-btn {
    display: flex; /* Added */
    align-items: center; /* Added */
    background: #4CAF50;
    padding: 5px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    border: 2px solid #fff;
    transition: background 0.2s;
}

.upgrade-btn:hover { background: #45a049; }
.upgrade-btn.disabled { background: #555; cursor: not-allowed; opacity: 0.7; }

.cost {
    font-size: 0.8rem;
    margin-left: 5px;
    color: #eee;
}

canvas {
    display: block;
    /* Removed background-color so clearRect reveals the div behind it */
    position: relative;
    z-index: 5; 
}

/* Modal Styles */
#game-over-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal-content {
    background: #333;
    padding: 40px;
    border-radius: 15px;
    text-align: center;
    border: 4px solid #ff9800;
    box-shadow: 0 0 20px rgba(0,0,0,0.8);
}

/* Fix for animal cards in menu */
.animal-grid {
    display: flex;
    gap: 20px;
}
.animal-card {
    text-align: center;
}
.animal-card img {
    border-radius: 5px;
    background: rgba(255,255,255,0.1);
    margin-bottom: 5px;
}

#birdshot-bar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 300px;
    height: 30px;
    background: #333;
    border: 2px solid white;
    border-radius: 15px;
    overflow: hidden;
    pointer-events: none;
}
#birdshot-fill {
    height: 100%;
    background: #00ffff;
    width: 0%;
    transition: width 0.1s linear;
}
#birdshot-text {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    text-shadow: 1px 1px 2px black;
    color: white;
}

#flag-canvas {
    cursor: default !important;
}

#hero-selection .menu-panel {
    max-width: 95%;
    width: 1100px; /* Wide enough for side-by-side */
    height: auto;
    max-height: 90vh; /* Cap height so it stays on screen */
    overflow-y: auto; /* Enable vertical scrolling */
    padding: 20px;
}

/* --- RESPONSIVE / MOBILE UPDATES --- */


/* --- HERO SELECTION LAYOUT (Desktop Default) --- */
#setup-container {
    display: flex;
    flex-direction: row;
    height: 100%;
}

/* --- MOBILE RESPONSIVE UPDATES --- */
@media (max-width: 768px) {
    /* 1. Main Menu: Stack Merch Images */
    .merch-container {
        flex-direction: column !important;
        gap: 10px !important;
    }
    .merch-container a img {
        height: auto !important;
        max-height: 18vh !important;
        width: auto !important;
    }

    /* 2. Hero Selection Screen Override */
    
    /* Unlock the parent panel to allow the whole page to scroll on mobile */
    #hero-selection .menu-panel {
        display: block !important; 
        overflow-y: auto !important; /* ENABLE PAGE SCROLLING */
        height: auto !important;
        max-height: 90vh !important;
        padding-top: 40px; 
    }

    /* FORCE Vertical Stack (Overrides HTML inline style) */
    #setup-container {
        display: flex !important;
        flex-direction: column !important; /* Forces 1 column */
        height: auto !important; /* Let it grow tall */
        gap: 20px !important;
    }

    /* Left Column (Settings/Flag) */
    #setup-container > div:first-child {
        width: 100%;
        flex: none; 
    }
    
    #flag-canvas {
        max-width: 100%;
        height: auto;
    }

    /* Right Column (Animals) */
    .hero-options {
        width: 100%;
        flex: none; 
        height: auto !important;
        max-height: none !important; /* Remove internal scroll limit */
        overflow: visible !important; /* Don't scroll internally, let page scroll */
        padding-left: 0;
        border-left: none;
        border-top: 2px solid #555; 
        padding-top: 20px;
        margin-bottom: 40px; 
    }

    /* Mobile Card Sizing */
    .hero-card {
        width: 45% !important; 
        max-width: 140px;
        font-size: 0.9rem;
    }
}

/* --- Mobile Optimization & Roster Toggle --- */

/* Default: Hide roster toggle on Desktop */
#btn-toggle-roster {
    display: none;
}

/* Mobile Only Rules */
@media (max-width: 768px) {
    
    /* 1. Pad Upgrades down below Mute/Settings and Stack them */
    #top-bar {
        padding-top: 20px; /* Moves everything down below icons */
        flex-direction: column; /* Stacks XP and Upgrades */
        align-items: center;
        gap: 5px;
    }

    /* 2. Make Upgrade buttons 15% smaller and split into 2 rows */
    .upgrades {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        width: 100%;
        gap: 5px;
    }

    .upgrade-btn {
        width: 48%; 
        font-size: 0.85rem; 
        justify-content: center;
        margin: 0;
        padding-top: 12px; /* Increased vertical padding */
        padding-bottom: 12px; 
    }
    /* 3. Move Roster down and setup Toggle functionality */
 #btn-roster-toggle {
        display: block; /* Show button only on mobile */
        position: absolute;
        top: 5px; 
        left: 5px;
        z-index: 2005;
        background: rgba(0,0,0,0.7);
        border: 2px solid white;
        color: white;
        padding: 5px 10px;
        font-size: 1rem;
        /* FIX: Prevent width collapse and text wrap */
        width: 140px; 
        min-width: 140px !important; /* Forces width to stay even if toggled */
        white-space: nowrap;
        text-align: center;
    }

    #roster-panel {
        top: 0; /* Reset panel top, rely on list margin */
        left: 5px;
        display: flex;
        flex-direction: column;
    }

    /* Push the list down so it doesn't overlap flag or toggle button */
    #roster-list {
        margin-top: 50px; 
    }

    /* Class to hide roster when toggled */
    #roster-panel.minimized {
        opacity: 0;
        pointer-events: none;
    }

    /* 4. Ensure Birdshot Bar appears above bottom edge on mobile */
    #birdshot-bar {
        bottom: 250px !important; /* Default High position (clears upgrade buttons) */
        width: 90%;
        z-index: 100;
        top: auto !important;
        transition: bottom 0.3s ease; /* Smooth sliding animation */
    }

    /* New state for when upgrades are minimized */
    #birdshot-bar.lowered {
        bottom: 80px !important; /* Low position (just above XP bar) */
    }
      /* 5. Mobile Minimize Button Styling */
    #btn-minimize-upgrades {
        display: block !important; /* Force show on mobile */
        position: absolute;
        top: -45px; /* Sits on top of the bar */
        right: 10px;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: #333;
        border: 2px solid white;
        color: gold;
        font-size: 1.2rem;
        z-index: 200;
        padding: 0;
        line-height: 36px; 
    }

    /* Minimized State: Hide upgrades, shrink bar */
    #top-bar.minimized-bar {
        padding-bottom: 5px !important;
        height: auto;
    }
    #top-bar.minimized-bar .upgrades {
        display: none;
    }


        /* Fix for overlapping, wrapping, and large text on mobile */
    #monolith-timer-ui, #map-timer-ui, #birdshot-timer-ui {
        font-size: 1.2rem !important; /* Reduced size (approx 40% smaller) */
        white-space: nowrap; /* Forces text to stay on one line */
        width: 100%; /* Ensures centering works without wrapping */
        text-align: center;
        /* Reset positioning to use full width stacking */
        left: 0 !important; 
        transform: none !important; 
    }

    /* Stack them vertically with tight spacing */
    #monolith-timer-ui { top: 90px !important; }
    #map-timer-ui { top: 115px !important; }
    #birdshot-timer-ui { top: 140px !important; }

        /* Scale down top right icons on mobile */
    #top-right-icons {
        transform: scale(0.85);
        transform-origin: top right;
        right: 10px !important;
        top: 25px !important;
    }
}

