/* --- ESTILOS PADRÃO (DESKTOP FIRST) --- */
html, body {
    height: 100%; /* Garante uma referência de altura estável para o mobile */
    margin: 0;
    padding: 0;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #333;
    font-family: 'Press Start 2P', cursive;
    color: #fff;
    overflow: hidden;
}

#game-container {
    position: relative;
    border: 4px solid #111;
    border-radius: 5px;
    box-shadow: 0 0 0 5px #555, inset 0 0 0 5px #222;
}

canvas {
    display: block;
    background-color: #fff;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    font-size: 1em;
    padding: 20px;
    box-sizing: border-box;

    /* --- ANIMATION STYLES --- */
    opacity: 0;
    pointer-events: none; /* Can't click when invisible */
    transition: opacity 0.4s ease-in-out;
}

.overlay.visible {
    opacity: 1;
    pointer-events: auto; /* Can click when visible */
}

.overlay h2 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1.8em;
    color: #ffcc00;
    text-shadow: 3px 3px #c0392b;
}

/* Other overlay styles remain the same... */
.overlay p { 
    line-height: 1.6; 
}

.overlay .score-display { 
    margin: 10px 0; 
    color: #f1c40f; 
    font-size: 0.9em; 
}

.overlay .button-group { 
    display: flex; 
    flex-direction: column; 
    gap: 15px;
    margin-top: 10px;
}

.overlay button { 
    padding: 15px 30px;
    font-size: 0.8em; 
    font-family: 'Press Start 2P', cursive; 
    color: #fff; 
    background-color: #3498db; 
    border: 3px solid #2980b9; 
    border-radius: 0; 
    cursor: pointer; 
    margin-top: 10px;
    box-shadow: 0 4px #2980b9; 
}

.overlay button:active { 
    box-shadow: 0 2px #2980b9; 
    transform: translateY(2px); 
}

#stage-win-overlay .button-group {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#stop-playing-button, #back-to-menu-button { 
    background-color: #e74c3c; 
    border-color: #c0392b; 
    box-shadow: 0 4px #c0392b; 
}

#stop-playing-button:active, #back-to-menu-button:active {
    box-shadow: 0 2px #c0392b; 
}

.stop-button {
    background-color: #e74c3c !important;
    border-color: #c0392b !important;
    box-shadow: 0 4px #c0392b !important;
}

.stop-button:active {
    box-shadow: 0 2px #c0392b !important;
}

#hud {
    position: absolute;
    top: 15px;
    left: 15px;
    font-size: 1em;
    color: #fff;
    text-shadow: 2px 2px #000;
    line-height: 1.5;
    opacity: 0; /* Starts faded out */
    transition: opacity 0.4s ease-in-out;
}

#hud.visible { 
    opacity: 1; 
}

/* --- CHARACTER & NAME STYLES --- */
#character-selector { 
    display: flex; 
    justify-content: center; 
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap; 
}

.character-option { 
    border: 3px solid #555; 
    padding: 5px;
    text-align: center; 
    cursor: pointer; 
    transition: background-color 0.2s, border-color 0.2s; 
}

.character-option:hover { 
    background-color: #444; 
}

.character-option.active { 
    border-color: #ffcc00; 
    background-color: #5a4a00; 
}

.character-option canvas { 
    width: 64px;
    height: 64px;
    background-color: #2c3e50; 
    image-rendering: pixelated; /* Ensures preview is sharp */

}

.character-option p { 
    margin: 5px 0 0; 
    font-size: 0.7em; 
}

.player-name-input-container { 
    margin: 10px 0; 
}

.player-name-input-container input { 
    font-family: 'Press Start 2P', cursive; 
    background: #555; 
    color: #fff; 
    border: 2px solid #888; 
    padding: 8px;
    text-align: center; 
    width: 180px;
    font-size: 0.8em; 
}

/* --- LEADERBOARD STYLES --- */
#scores-list { 
    list-style-type: none; 
    padding: 0; 
    margin: 0 0 20px 0; 
    width: 80%; 
    max-height: 200px; 
    overflow-y: auto; 
    font-size: 0.9em; 
}

#scores-list li { 
    display: flex; 
    justify-content: space-between; 
    padding: 5px 10px;
    background-color: rgba(0,0,0,0.2); 
    margin-bottom: 5px;
}
#scores-list li:nth-child(1) { 
    color: #ffd700; 
} 

#scores-list li:nth-child(2) { 
    color: #c0c0c0; 
} 

#scores-list li:nth-child(3) { 
    color: #cd7f32; 
}

/* --- MOBILE SUPPORT STYLES --- */
#rotate-overlay { 
    display: none; 
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100vw; 
    height: 100vh; 
    background-color: #111; 
    z-index: 100; 
    flex-direction: column; 
    justify-content: center; 
    align-items: center; 
    text-align: center; 
    padding: 20px; 
}

#rotate-overlay p { 
    margin-bottom: 20px; 
    font-size: 1.2em; 
}

/* --- MOBILE ON-SCREEN CONTROLS & OVERLAYS --- */
#touch-control { display: none; }
#rotate-overlay { display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background-color: #111; z-index: 100; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 20px; }
#rotate-overlay p { margin-bottom: 20px; font-size: 1.2em; }

@media screen and (max-width: 768px) {
    #game-container {
        position: fixed;
        top: 0; left: 0;
        width: 100%; height: 100%;
        border: none; border-radius: 0; box-shadow: none;
        display: flex; justify-content: center; align-items: center;
    }
    canvas {
        max-width: 100%;
        max-height: 100%;
    }
    @media (orientation: portrait) {
        #game-container { display: none; }
        #rotate-overlay { display: flex; }
    }
}

@media (pointer: coarse) {
    #touch-control {
        display: block;
        position: absolute;
        bottom: 5%;
        right: 5%;
        width: 100px;
        height: 100px;
        background-color: rgba(255, 255, 255, 0.2);
        border: 2px solid rgba(255, 255, 255, 0.4);
        border-radius: 50%;
        z-index: 10;
    }
}
