/* General Body and Font Styles */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

:root {
    --primary-color: #4CAF50; /* A nice green for the theme */
    --secondary-color: #FFC107; /* A vibrant yellow */
    --background-color: #333; /* Dark background for contrast */
    --font-color: #FFFFFF;
    --heart-color: #E91E63;
    --button-bg-color: #616161;
    --button-border-color: #757575;
    --button-text-color: #FFFFFF;
    --button-hover-bg: #757575;
    --orange-gem-color: #FF9800; /* Bright orange for gems */
    --game-title-shadow-color: #4CAF50; /* Green shadow for game title */
    --toast-blue-frame: #2196F3; /* --- NEW --- Blue for toast frame */
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden; /* Prevents scrolling on mobile */
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--font-color);
}

/* Main Game Layout - Taller for phones, fixed max-width */
#game-container {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100vh; /* Occupy full viewport height */
    max-width: 400px; /* Make it less wide to fit phones more accurately */
    margin: 0 auto;
    background-color: #212121;
    box-shadow: 0 0 20px rgba(0,0,0,0.7);
    position: relative; /* --- MODIFIED --- Needed for toast positioning */
}

/* Header Section */
#game-header {
    display: flex;
    flex-wrap: wrap; /* Allow items to wrap on very small screens */
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background-color: #424242;
    border-bottom: 2px solid var(--primary-color);
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    position: relative; /* --- MODIFIED --- For z-index to work correctly */
    z-index: 10;
}

.header-title {
    font-family: 'Press Start 2P', cursive; /* --- MODIFIED --- Playful font */
    font-size: 1.3em; /* --- MODIFIED --- Adjusted size for new font */
    color: var(--secondary-color);
    margin: 0;
    text-shadow: 2px 2px 4px var(--game-title-shadow-color);
    line-height: 1.2; /* --- NEW --- Adjust line height for better spacing */
}

.header-info {
    font-size: 1em;
    font-weight: bold;
}

#lives-counter {
    display: flex;
    align-items: center;
    gap: 8px;
}

#hearts-container {
    display: flex;
}

.heart {
    color: var(--heart-color);
    font-size: 1.2em;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

/* Progress Bar */
#progress-container {
    width: 100%;
    order: 3; /* Puts it on the next line if wrapping */
    margin-top: 8px;
    background-color: #616161;
    border-radius: 10px;
    border: 1px solid #757575;
    position: relative;
    height: 20px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.4);
}

#progress-bar-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(45deg, var(--primary-color), #8BC34A);
    border-radius: 10px;
    transition: width 0.3s ease-in-out;
}

#progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: bold;
    color: #fff;
    text-shadow: 1px 1px 1px #000;
}

/* Game Area (Perfect Square) - Larger now */
#game-area-container {
    flex-grow: 1; /* Allow it to take available space */
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative; /* Needed for absolute positioning of children */
    padding: 10px; /* Padding around the canvas */
    touch-action: none; /* Disables browser gestures like pull-to-refresh */
    min-height: 300px; /* Increased minimum height for the game area */
    max-height: 60vh; /* Increased max height to make it larger */
}


#game-canvas, #intro-video {
    width: 95%; /* Make it larger within its container */
    max-width: 380px; /* Increased max width to make it larger */
    aspect-ratio: 1 / 1; /* Keep it square */
    background-color: #000;
    border: 3px solid #616161;
    box-shadow: 0 0 15px rgba(0,0,0,0.5);
    border-radius: 8px;
}

#intro-video {
    position: absolute;
    z-index: 10;
}

/* New Game Controls Section */
#game-controls {
    padding: 8px; /* Slightly reduced padding */
    background-color: #333;
    border-top: 2px solid #555;
    display: flex;
    flex-direction: column;
    gap: 6px; /* Reduced space between rows */
}

.control-row {
    display: flex;
    justify-content: space-around;
    gap: 6px; /* Reduced space between buttons in a row */
}

.game-button {
    flex: 1; /* Distribute space evenly */
    padding: 8px 5px; /* Reduced padding for smaller buttons */
    font-size: 0.75em; /* Smaller font size for text to fit */
    font-weight: bold;
    color: var(--button-text-color);
    background: linear-gradient(145deg, #424242, #212121);
    border: 2px solid var(--button-border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.1);
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
    white-space: nowrap; /* Prevent text wrapping */
    overflow: hidden;
    text-overflow: ellipsis;
}

.game-button:hover {
    background: linear-gradient(145deg, #555555, #333333);
    transform: translateY(-2px);
    box-shadow: 0 6px 8px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.15);
}

.game-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.05);
}

.icon-button {
    flex: none; /* Do not grow */
    width: 40px; /* Fixed width for square buttons */
    height: 40px; /* Fixed height for square buttons */
    padding: 0; /* Remove padding for icon buttons */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.3em; /* Icon size */
}

/* Gem Counter Styling */
.gem-row {
    display: flex;
    align-items: center;
    justify-content: flex-start; /* --- MODIFIED --- Align items left */
    gap: 4px; /* --- MODIFIED --- Reduced gap for closer buttons */
    background-color: #2a2a2a;
    border-radius: 10px;
    padding: 6px 10px;
    border: 1px solid #444;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.5);
}

.gem-row .game-button {
    flex: 0 0 auto; /* --- MODIFIED --- Prevent growing or shrinking */
    font-size: 0.7em; /* --- MODIFIED --- Smaller font for button text */
}

.gem-display {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 1.1em;
    font-weight: bold;
    color: var(--orange-gem-color);
    text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
    background-color: #3a3a3a;
    padding: 4px 10px;
    border-radius: 8px;
    border: 1px solid #555;
    margin-left: auto; /* --- MODIFIED --- Pushes the counter to the far right */
    flex-shrink: 0;
}

.gem-icon {
    font-size: 1.4em;
    line-height: 1;
    color: var(--orange-gem-color);
    text-shadow: 0 0 8px var(--orange-gem-color), 0 0 12px rgba(255, 152, 0, 0.7);
}


/* Footer Section */
#game-footer {
    padding: 8px 15px;
    background-color: #424242;
    border-top: 2px solid var(--primary-color);
    display: flex;
    justify-content: space-between; /* Distribute items */
    align-items: center;
    font-size: 0.75em;
    color: #BDBDBD;
}

.footer-left {
    display: flex;
    align-items: center;
    gap: 5px;
}

.age-restriction {
    font-size: 1.5em; /* Larger emoji */
    color: red;
    line-height: 1;
}

.age-text {
    font-size: 0.8em; /* Slightly smaller font */
    color: #BDBDBD;
    white-space: nowrap; /* Prevent text from wrapping */
}

.copyright {
    margin: 0;
    text-align: right; /* Move copyright to the right */
}


/* Modal for Game Over / Congratulations / Confirmations */
#modal-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: #424242;
    padding: 20px;
    border-radius: 15px;
    text-align: center;
    border: 2px solid var(--secondary-color);
    box-shadow: 0 5px 25px rgba(0,0,0,0.5);
    max-width: 90%;
    width: 360px; /* Fixed width for consistency */
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* --- NEW --- Make modal message area scrollable */
#modal-message {
    max-height: 40vh; /* Set a max height */
    overflow-y: auto; /* Add a scrollbar if content overflows */
    text-align: left; /* Better for reading long text */
    padding: 5px 10px;
    background: rgba(0,0,0,0.2);
    border-radius: 5px;
}

/* --- NEW: Style for the modal input field --- */
#modal-input {
    width: 85%;
    padding: 12px;
    margin: 5px auto;
    border-radius: 8px;
    border: 2px solid var(--button-border-color);
    background-color: #fff;
    color: #333;
    font-size: 1.1em;
    text-align: center;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

#modal-input:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2), 0 0 10px var(--secondary-color);
}


#modal-image {
    max-width: 100%;
    height: auto;
    border-radius: 10px;
    margin: 0 auto; /* Center image */
    border: 2px solid #616161;
}

#modal-buttons {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.modal-btn {
    padding: 12px 25px;
    font-size: 1.1em;
    font-weight: bold;
    color: #212121;
    background-color: var(--secondary-color);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: background-color 0.2s;
    box-shadow: 0 3px 5px rgba(0,0,0,0.3);
}

.modal-btn:hover {
    background-color: #FFD54F;
}

/* Fading Toast Notification --- MODIFIED --- */
#toast-notification {
    position: absolute; /* Changed from fixed to be relative to game-container */
    top: -100px; /* Start off-screen above */
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(30, 30, 30, 0.95);
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    border: 3px solid var(--toast-blue-frame); /* Blue frame */
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    z-index: 5; /* Below header, above canvas area */
    opacity: 0;
    transition: opacity 0.5s, top 0.5s;
    visibility: hidden;
    width: 80%; /* Fit inside the container */
    max-width: 360px;
    text-align: center;
    box-sizing: border-box;
}

#toast-notification.show {
    visibility: visible;
    opacity: 1;
    /* Position it right above the game area, accounting for header height */
    top: calc(100px); /* Adjust this value based on header height */
    animation: fadeinout-top 3s ease-in-out forwards;
}

@keyframes fadeinout-top {
    0% { opacity: 0; top: 70px; }
    20% { opacity: 1; top: 100px; } /* Fade in and move down */
    80% { opacity: 1; top: 100px; } /* Hold */
    100% { opacity: 0; top: 70px; } /* Fade out and move up */
}


/* In-Game Level Passed Animation */
#level-passed-message {
    position: absolute;
    top: 25%;
    left: 50%;
    transform: translateX(-50%);
    color: var(--secondary-color);
    font-size: 3em;
    font-weight: bold;
    text-shadow: 3px 3px 6px rgba(0,0,0,0.7);
    z-index: 50;
    opacity: 0; /* Start hidden */
    animation: message-appear 0.5s ease-out forwards;
    pointer-events: none;
}

#framed-level-image {
    position: absolute;
    top: 50%;
    left: 50%;
    max-width: 70%;
    max-height: 70%;
    border: 8px solid #fff;
    border-image: linear-gradient(45deg, var(--secondary-color), #FFD54F) 1;
    box-shadow: 0 0 30px rgba(255, 193, 7, 0.6);
    z-index: 49;
    opacity: 0; /* Start hidden for animation */
    animation: image-appear 0.8s ease-out 0.3s forwards; /* Delayed start */
    pointer-events: none;
}

@keyframes message-appear {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes image-appear {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.7);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}


/* Utility Class */
.hidden {
    display: none !important;
}

/* Responsive adjustments for smaller screens if needed */
@media (max-width: 360px) {
    .header-title {
        font-size: 1.1em; /* Adjust title font on very small screens */
    }
    
    .game-button {
        font-size: 0.7em; /* Even smaller font for very small screens */
        padding: 8px 3px;
    }
    
    .gem-row .game-button {
        flex-basis: 100px;
    }

    .icon-button {
        width: 36px;
        height: 36px;
        font-size: 1.1em;
    }

    .gem-display {
        font-size: 0.9em;
        padding: 2px 6px;
    }

    .gem-icon {
        font-size: 1.1em;
    }

    .age-text {
        font-size: 0.7em;
    }
}