body {
    background-image: url('/main_menu_background.png');
    background-size: cover;
    background-position: center;
    background-color: #000; /* Black background for contrast */
    color: #fff;
    font-family: 'Press Start 2P', sans-serif; /* A typical retro game font */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    text-align: center;
    height: 100vh;
    width: 100vw;
    box-sizing: border-box;
    transition: background-image 0.5s ease-in-out;
    overflow: hidden; /* Prevent scrolling on mobile */
}

body.in-game {
    background-image: none;
    background-color: #000;
}

#main-menu {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 25px;
    padding: 10px;
    background-color: rgba(0, 0, 0, 0.4);
    border-radius: 20px;
    padding: 30px;
}

#main-menu h1.game-title {
    font-size: 3.5em; 
    line-height: 1.1;
    margin-bottom: 20px;
    color: #f0f0f0;
    text-shadow:
        /* White inner glow */
        0 0 5px #fff,
        /* Green vibrant glow */
        0 0 10px #0f0,
        0 0 20px #0f0,
        0 0 30px #0f0,
        /* Black outline */
        -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000,
        -3px 0 0 #000, 3px 0 0 #000, 0 -3px 0 #000, 0 3px 0 #000;
    animation: electric-glow 4s linear infinite;
}

@keyframes electric-glow {
    0%, 100% {
        text-shadow:
            0 0 5px #fff,
            0 0 10px #0f0, 0 0 20px #0f0, 0 0 30px #0f0,
            -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000,
            -3px 0 0 #000, 3px 0 0 #000, 0 -3px 0 #000, 0 3px 0 #000;
    }
    50% {
        text-shadow:
            0 0 8px #fff,
            0 0 15px #3f3, 0 0 25px #3f3, 0 0 40px #3f3,
            -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000,
            -3px 0 0 #000, 3px 0 0 #000, 0 -3px 0 #000, 0 3px 0 #000;
    }
}

/* Media Query for smaller screens (mobile) */
@media (max-width: 480px) {
    #main-menu h1.game-title {
        font-size: 2.2em; /* Smaller font size for mobile */
    }
    .menu-button {
        width: 220px;
        font-size: 1.1em;
        padding: 15px 20px;
    }
}

.menu-button {
    padding: 18px 35px;
    font-family: 'Press Start 2P', sans-serif;
    font-size: 1.3em;
    cursor: pointer;
    color: white;
    border: none;
    border-radius: 10px;
    text-shadow: 3px 3px #000;
    width: 320px;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
    animation: pulse-button 2s infinite;
}

.menu-button:nth-of-type(1) { background-color: #28a745; } /* Iniciar - Green */
.menu-button:nth-of-type(2) { background-color: #3498db; animation-delay: 0.2s; } /* Ajuda - Blue */
.menu-button:nth-of-type(3) { background-color: #f39c12; animation-delay: 0.4s; } /* Controles - Orange */

.menu-button:hover, .menu-button:active {
    transform: scale(1.05) translateY(-3px);
    animation-play-state: paused;
}

.menu-button:nth-of-type(1):hover { background-color: #2ecc71; }
.menu-button:nth-of-type(2):hover { background-color: #5dade2; }
.menu-button:nth-of-type(3):hover { background-color: #f1c40f; }

@keyframes pulse-button {
    0% {
        transform: scale(1);
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
    }
    50% {
        transform: scale(1.02);
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.6);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4);
    }
}

#game-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column; /* Stack game and controls vertically */
}

#game-container {
    position: relative;
    width: 100%;
    max-width: 100vw;
    flex-grow: 1; /* Allow container to take available space */
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden; /* Prevent canvas from overflowing */
}

@media (pointer: coarse) and (orientation: portrait) {
    #game-container {
        max-height: 70vh;
    }
}

canvas {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain; /* Make canvas fit inside container while keeping aspect ratio */
}

#back-to-menu-button {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 15;
    padding: 8px 12px;
    font-family: 'Press Start 2P', sans-serif;
    font-size: 0.8em;
    cursor: pointer;
    background-color: rgba(231, 76, 60, 0.7);
    color: white;
    border: 2px solid white;
    border-radius: 5px;
    text-shadow: 1px 1px #000;
    display: none; /* Hidden by default, shown when game starts */
}

body.in-game #back-to-menu-button {
    display: block;
}

#back-to-menu-button:hover {
    background-color: rgba(192, 57, 43, 1.0);
}

.controls-info {
    margin-top: 20px;
    padding: 15px;
    background: #444;
    border: 2px solid #fff;
    border-radius: 10px;
    width: 300px;
}

.info-popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 20px;
    border-radius: 10px;
    border: 3px solid white;
    text-align: center;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 0 15px #000;
    z-index: 100;
    max-height: 85vh; /* Prevent popup from being taller than the screen */
    overflow-y: auto; /* Add vertical scrollbar when needed */
    box-sizing: border-box;
}
.info-popup h2 {
    margin-top: 0;
    font-size: 1.5em;
}
.info-popup p {
    font-size: 0.9em;
    line-height: 1.6;
    margin-bottom: 15px;
}

.close-popup-button {
    margin-top: 20px;
    padding: 10px 20px;
    font-family: 'Press Start 2P', sans-serif;
    font-size: 1em;
    cursor: pointer;
    background-color: #e74c3c;
    color: white;
    border: 2px solid white;
    border-radius: 5px;
    text-shadow: 2px 2px #000;
}
.close-popup-button:hover {
    background-color: #c0392b;
}

#popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 20px;
    border-radius: 10px;
    border: 3px solid white;
    text-align: center;
    width: 90%;
    max-width: 700px;
    box-shadow: 0 0 15px #000;
    z-index: 10;
}

#popup-content-container {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
}

#player-victory-image {
    width: 120px;
    height: 120px;
    background-image: url('/player_walk.png');
    background-size: 400%; /* Show one frame of 4 */
    background-position: 0% 0%;
    align-self: flex-end; /* Align to bottom */
    flex-shrink: 0;
}

#popup-message-container {
    flex: 1;
    text-align: left;
}

#villain-quotes .villain-quote {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 10px;
}

#villain-quotes .villain-image {
    width: 50px;
    height: 50px;
    object-fit: contain;
}

#popup-buttons {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

#popup h2 {
    margin-top: 0;
    font-size: 1.5em;
}

#popup p {
    font-size: 0.9em;
    line-height: 1.5;
    text-align: left;
}

#restart-button, #play-again-button {
    margin-top: 10px;
    padding: 10px 20px;
    font-family: 'Press Start 2P', sans-serif;
    font-size: 0.9em;
    cursor: pointer;
    color: white;
    border: 2px solid white;
    border-radius: 5px;
    display: none;
}

#restart-button {
    background-color: #e74c3c; /* Red for menu */
}
#restart-button:hover {
    background-color: #c0392b;
}

#play-again-button {
     background-color: #4CAF50; /* Green for play */
}
#play-again-button:hover {
    background-color: #45a049;
}

.hidden {
    display: none !important;
}

/* --- Mobile Controls Area --- */
#mobile-controls-area {
    display: none; /* Hidden by default */
    width: 100%;
    background-color: #111;
    padding: 10px 20px;
    box-sizing: border-box;
    flex-shrink: 0; /* Prevent this area from shrinking */
    position: relative;
    height: 100px;
}

/* Show on touch devices only */
@media (pointer: coarse) {
  body.in-game #mobile-controls-area {
    display: block;
  }
}

.mobile-btn {
    position: absolute;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.7);
    color: white;
    font-size: 20px;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
}

.mobile-btn:active {
    background-color: rgba(255, 255, 255, 0.7);
    transform: scale(0.95);
}

#d-pad {
    position: absolute;
    bottom: 25px;
    left: 20px;
    width: 120px;
    height: 50px;
}

#left-btn {
    position: absolute;
    bottom: 0;
    left: 0;
}

#right-btn {
    position: absolute;
    bottom: 0;
    left: 70px;
}

#action-buttons {
    position: absolute;
    bottom: 25px;
    right: 20px;
    width: 140px;
    height: 70px;
}

#shoot-btn {
    position: absolute;
    bottom: 0;
    right: 70px;
}

#fly-btn {
    position: absolute;
    bottom: 40px;
    right: 120px;
}

#jump-btn {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 60px;
    height: 60px;
    font-size: 24px;
}

/* Media query adjustments for very small screens */
@media (max-width: 380px) {
    .mobile-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    #d-pad {
        gap: 10px;
    }
    
    #action-buttons {
        gap: 8px;
    }
    
    #fly-btn,
    #shoot-btn {
        width: 45px;
        height: 45px;
        font-size: 18px;
    }
    
    #jump-btn {
        width: 55px;
        height: 55px;
        font-size: 22px;
    }
}