:root {
    --main-bg-color: #2c3e50;
    --container-bg-color: #34495e;
    --board-bg-color: #0d1218;
    --main-font-color: #ecf0f1;
    --border-color: #95a5a6;
    --block-size: min(30px, 8vw); 
}

html {
    height: 100%;
    overscroll-behavior: none;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--main-bg-color);
    color: var(--main-font-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    
    /* ----- CORRECCIÓN SCROLL PC ----- */
    /* Cambiamos height por min-height y quitamos overflow */
    min-height: 100vh;
    /* overflow: hidden; -- ELIMINADO */
    
    margin: 0;
    padding: 0; 
    box-sizing: border-box;
    
    overscroll-behavior: none;
    touch-action: none; 
}

/* El h1 ya no existe, por lo que quitamos sus estilos */

h2, h3 {
    text-align: center;
    margin-top: 0;
    margin-bottom: 20px;
}

#game-container {
    display: flex;
    align-items: flex-start;
    gap: 30px;
    background-color: var(--container-bg-color);
    padding: 20px;
    border-radius: 10px;
    border: 3px solid var(--border-color);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

#game-board {
    width: calc(var(--block-size) * 10);
    height: calc(var(--block-size) * 20);
    background-color: var(--board-bg-color);
    border: 2px solid var(--border-color);
    position: relative;
    touch-action: none;
}

#block-container {
    display: grid;
    grid-template-columns: repeat(10, var(--block-size));
    grid-template-rows: repeat(20, var(--block-size));
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

#game-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: calc(var(--block-size) * 5); 
}

#score {
    font-size: 2em;
    font-weight: bold;
    margin: 0 0 20px 0;
}

#next-piece-board {
    display: grid;
    align-items: center;
    justify-content: center;
    background-color: var(--board-bg-color);
    border: 1px solid var(--border-color);
    width: calc(var(--block-size) * 5);
    height: calc(var(--block-size) * 5);
    padding: calc(var(--block-size) * 0.5);
    box-sizing: border-box;
}

.block {
    width: 100%;
    height: 100%;
    box-shadow: inset 0px 0px 5px rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

.I { background-color: #3498db; }
.O { background-color: #f1c40f; }
.T { background-color: #9b59b6; }
.L { background-color: #e67e22; }
.J { background-color: #165a8c; }
.S { background-color: #2ecc71; }
.Z { background-color: #c0392b; }

.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(13, 18, 24, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--main-font-color);
    text-align: center;
    padding: 20px;
    box-sizing: border-box;
    z-index: 100; 
}

.game-overlay h2 {
    font-size: 2.5em;
    margin-bottom: 10px;
    text-shadow: 2px 2px 5px rgba(0,0,0,0.5);
}
.game-overlay p {
    font-size: 1.2em;
    margin-bottom: 25px;
}
.game-overlay button {
    font-size: 1.2em;
    font-weight: bold;
    padding: 15px 30px;
    border: 2px solid var(--main-font-color);
    background-color: transparent;
    color: var(--main-font-color);
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}
.game-overlay button:hover {
    background-color: var(--main-font-color);
    color: var(--main-bg-color);
    transform: scale(1.05);
}

.hidden {
    display: none;
}

@media (max-width: 650px) {
    body {
        padding: 5px;
        /* Hacemos que el juego empiece desde arriba en móvil */
        justify-content: flex-start; 
        min-height: -webkit-fill-available; /* Arreglo para vh en iOS */
        height: 100%;
    }
    
    #game-container {
        flex-direction: column;
        align-items: center;
        padding: 10px;
        gap: 15px; /* Reducimos el espacio */
    }
    
    /* ----- CORRECCIÓN LAYOUT MÓVIL ----- */
    #game-board {
        order: 2; /* El tablero va segundo */
    }

    #game-info {
        order: 1; /* La info va primero */
        flex-direction: row;
        justify-content: space-around;
        width: 100%;
        min-width: unset;
        align-items: center;
    }
    
    #game-info h2, #game-info h3 {
        margin-bottom: 10px;
    }
    #score {
        margin: 0;
        margin-bottom: 10px;
    }
    .game-overlay h2 {
        font-size: 2em;
    }
    .game-overlay p {
        font-size: 1em;
    }
    .game-overlay button {
        font-size: 1em;
        padding: 12px 24px;
    }
}