body {
    display: flex;
    /* Cambiar align-items para que el contenido pueda crecer */
    align-items: flex-start; /* Alinear arriba por defecto */
    justify-content: center;
    min-height: 100vh; /* Asegura altura mínima */
    background-color: #f0f0f0;
    font-family: sans-serif;
    margin: 0;
    /* Prevenir scroll en la página principal */
    overflow: hidden;
}

/* Ajusta el contenedor padre */
#game-container {
   width: 95vw; /* O un % */
   max-width: 800px; /* Límite */
   /* Centrar el contenedor en la página */
   margin: 10px auto;
   position: relative; /* Necesario para overlays */
   /* overflow: hidden; Podría ser útil */
    border: 1px solid #ccc;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);   
}

/* --- Nuevo Contenedor Principal --- */
#app-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%; /* Ocupar todo el ancho disponible */
    height: 100vh; /* Ocupar toda la altura de la ventana */
    padding: 0; /* Sin padding vertical/horizontal extra en el contenedor principal */
    box-sizing: border-box;
}

/* --- Área del Juego (Canvas y Overlays) --- */
#game-area {
    position: relative;
    width: 100%; /* Ocupar el ancho de app-container */
    /* Altura calculada: Por defecto flexible */
    flex-grow: 1; /* Permitir que crezca para ocupar espacio */
    display: flex; /* Usar flex para centrar el canvas si no ocupa todo */
    justify-content: center;
    align-items: center;
    overflow: hidden; /* Esconde cualquier desbordamiento del canvas o overlays */
    /* Eliminar margen inferior si usamos flex-grow */
    /* margin-bottom: 10px; */
}

#gameCanvas {
    display: block;
    background-color: #77aa77;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);

    /* --- Adaptación Tamaño Canvas --- */
    /* Por defecto (escritorio), limita el tamaño */
    max-width: 100%;
    max-height: 100%; /* Ocupar como máximo el área disponible en #game-area */
    aspect-ratio: 800 / 600; /* Mantiene la proporción */
    /* Centrado automático si es más pequeño que #game-area */
    object-fit: contain; /* Escala manteniendo aspecto, sin recortar */
}

#dashboard {
    position: absolute;
    top: 10px;
    left: 10px;
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    border-radius: 5px;
    font-size: 12px; /* Más pequeño por defecto */
    padding: 5px;
    /* Quizás posicionarlo diferente */
    /* top: unset; bottom: 10px; width: calc(100% - 20px); */}
#dashboard div {
    margin-bottom: 5px;
}

#controls-info {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 5px;
    border-radius: 3px;
    font-size: 12px;
    display: none; /* Ocultar texto de teclado en móvil */
}

#start-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    z-index: 10;
}
#end-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%; /* Ocupa toda el área del padre (#game-area) */
    background-color: rgba(0, 0, 0, 0.85); /* Un poco más opaco si quieres */
    color: white;
    display: flex; /* Mantenemos flex */
    flex-direction: column;
    justify-content: center; /* Centrar verticalmente EL CONTENIDO DENTRO DEL AREA VISIBLE */
    align-items: center;
    text-align: center;
    z-index: 10;
    padding: 20px; /* Añadir padding interno */
    box-sizing: border-box; /* Incluir padding en el tamaño */

    /* --- CLAVE PARA EL SCROLL --- */
    overflow-y: auto; /* Añade barra de scroll vertical SI es necesario */
    /* Opcional: limitar la altura máxima si causa problemas con 100% */
    /* max-height: 100%; */

    /* Asegurar que el contenido no fuerce el tamaño */
    /* Puede que no necesites esto si el scroll funciona bien */
    /* justify-content: flex-start; */ /* Alinear arriba y dejar que scroll haga el resto */
}

#start-screen button, #end-screen button {
    /*padding: 10px 20px;*/
    /*font-size: 1.2em;*/
    margin-top: 20px;
    cursor: pointer;
}
#start-screen select {
    padding: 5px;
    margin-top: 10px;
}

#start-screen h2, #end-screen h2 {
    font-size: 1.5em;
}
#end-screen h2 {
    margin-top: 0; /* Evitar margen extra arriba con scroll */
    margin-bottom: 15px;
}
#end-screen p {
     margin: 8px 0; /* Espaciado entre párrafos */
}
#end-screen #restartButton {
     margin-top: 20px;
     margin-bottom: 10px; /* Espacio inferior si hay scroll */
}

#start-screen button, #end-screen button, #user-info-form button {
    padding: 12px 20px; /* Botones más grandes para tocar */
    font-size: 1.1em;
}
.deviation-feedback {
    border: 3px solid red;
    animation: screenShake 0.3s ease-in-out;
}

@keyframes screenShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-5px); }
}

#user-info-form label {
    /* Stile per le etichette se necessario */
    color: #eee;
}

#user-info-form input {
    padding: 5px;
    /* Stili per gli input */
}

#user-info-form button {
     padding: 8px 15px;
     font-size: 1em; /* Riduci leggermente rispetto al bottone start/restart */
     margin-top: 10px;
     cursor: pointer;
}

 #user-info-form {
     /* Asegurar que no sea más ancho que la pantalla */
     width: 100%;
     max-width: 400px; /* Limitar ancho del form */
     margin-top: 20px;
     /* ...otros estilos... */
 }
 
/* Estilos para pantallas más grandes (ej. tablets y escritorio) */
@media (min-width: 600px) {
    #dashboard {
        font-size: 14px;
        padding: 10px;
        /* Posición original si quieres */
        /* bottom: unset; top: 10px; width: auto; */
    }
    #start-screen h2, #end-screen h2 {
        font-size: 2em; /* Tamaño original */
    }
     /* Puedes restaurar #controls-info si quieres */
     /* #controls-info { display: block; } */
}

/* --- Estilos Botones Táctiles (Mejorados) --- */
/* --- Contenedor de Controles Táctiles (Modificado) --- */
.touch-controls-container {
    /* Ya no es position: absolute */
    flex-shrink: 0; /* Evita que se encoja si no hay espacio */
    display: none; /* Controlado por @media */
    width: 100%;   /* Ocupa el ancho de app-container */
    max-width: 500px; /* Limitar el ancho máximo de los controles */
    padding: 10px 15px; /* Espacio interno */
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center; /* Alinear botones verticalmente */
    /* background-color: #eee; */ /* Fondo opcional para ver el área */
    margin-top: 5px; /* Pequeño espacio arriba */
}

.touch-button-group {
    display: flex;
    gap: 25px; /* Aumentar espacio entre botones */
    pointer-events: auto;
}

.touch-button {
    /* --- Tamaño y Forma --- */
    width: 75px;   /* Más grande */
    height: 75px;  /* Más grande */
    border-radius: 50%; /* Círculo perfecto */

    /* --- Colores y Fondo --- */
    background-color: rgba(50, 50, 50, 0.75); /* Un gris oscuro semitransparente */
    border: 3px solid rgba(200, 200, 200, 0.6); /* Borde gris claro, más grueso */
    color: rgba(255, 255, 255, 0.9); /* Texto blanco casi opaco */
    box-shadow: 0 3px 5px rgba(0, 0, 0, 0.4); /* Sombra sutil para dar profundidad */

    /* --- Texto Interno --- */
    font-size: 2.2em;   /* Texto MUCHO más grande */
    font-weight: bold;
    font-family: 'Arial', sans-serif; /* Fuente clara */
    line-height: 1; /* Asegurar centrado vertical del texto */

    /* --- Alineación y Comportamiento --- */
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    pointer-events: auto;
    transition: background-color 0.08s ease-out, transform 0.08s ease-out, border-color 0.08s ease-out; /* Transición más rápida */

    /* Para evitar el highlight azul en Chrome mobile al tocar */
    -webkit-tap-highlight-color: transparent;
}

/* --- Estilos al Presionar (:active) --- */
.touch-button:active {
    background-color: rgba(90, 90, 90, 0.85); /* Fondo más claro y opaco al presionar */
    border-color: rgba(255, 255, 255, 1); /* Borde blanco sólido */
    color: white;
    transform: scale(0.95); /* Ligero efecto de presión */
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); /* Sombra reducida */
}

/* --- Iconos (Alternativa al Texto - Opcional) --- */
/* Si prefieres iconos SVG o Font Awesome en lugar de texto A/D/←/→ */
/*
.touch-button i { // Ejemplo si usas Font Awesome <i class="fas fa-arrow-left"></i>
    font-size: 1.5em;
    color: inherit; // Hereda el color del botón
}
*/
/* Estilos específicos para cada botón si quieres iconos diferentes */
/* #touch-coarse-left::before { content: 'ᐊ'; font-size: 2em; } */
/* #touch-coarse-right::before { content: 'ᐅ'; font-size: 2em; } */
/* #touch-fine-left::before { content: '‹'; font-size: 2em; } */
/* #touch-fine-right::before { content: '›'; font-size: 2em; } */


/* --- Lógica para Mostrar/Ocultar (Sin Cambios) --- */
@media (pointer: coarse) {
    .touch-controls-container {
        display: flex;
    }
    #controls-info {
        display: none;
    }
    #game-area {
         /* Podrías reducir el margen inferior si los controles están visibles */
         /* margin-bottom: 5px; */
    }
}

@media (pointer: fine) {
     #app-container {
        /* Podrías limitar la altura máxima en escritorio si quieres */
         /* max-height: 90vh; */
         /* Añadir padding si se ve mejor en escritorio */
         padding: 10px 0;
     }    
     .touch-controls-container {
        display: none;
    }
     #controls-info {
         display: block;
     }
      #gameCanvas {
        /* Podrías limitar el tamaño máximo explícitamente aquí si lo deseas */
         max-width: 800px;
         /* max-height: 600px; (calculado por aspect-ratio) */
      }     
}

/* --- Ajustar Overlays para que se posicionen relativo a #game-area --- */
#dashboard,
#controls-info,
#start-screen {
    position: absolute; /* Siguen siendo absolutos */
    /* top, left, bottom, right se refieren ahora a los bordes de #game-area */
    box-sizing: border-box; /* Importante si usas padding/width 100% */
}

/* Revisa y ajusta las posiciones top/left/bottom/right si es necesario */
#dashboard { top: 10px; left: 10px; z-index: 6;/* ... otros estilos ... */ }
#controls-info { bottom: 10px; left: 10px; /* ... otros estilos ... */ }
#start-screen { top: 0; left: 0; width: 100%; height: 100%; z-index: 10;/* ... otros estilos ... */
}
/* --- Estilos Botón Salir --- */
.exit-button {
    display: none;
    position: absolute;
    top: 15px; /* Un poco más de espacio desde arriba */
    right: 15px; /* Un poco más de espacio desde la derecha */
    width: 50px;  /* Aumentar tamaño */
    height: 50px; /* Aumentar tamaño */
    border-radius: 50%;
    background-color: rgba(200, 50, 50, 0.7);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.7);
    font-size: 2em;   /* Aumentar tamaño del icono '✕' */
    font-weight: bold;
    line-height: 46px; /* Ajustar manualmente para centrar '✕' verticalmente */
                       /* (Puede requerir pruebas dependiendo de la fuente) */
                       /* O usar flexbox para centrar: */
                       /* display: flex; */
                       /* justify-content: center; */
                       /* align-items: center; */
                       /* line-height: 1; */ /* Si usas flexbox */
    text-align: center;
    padding: 0;
    cursor: pointer;
    z-index: 7;
    user-select: none;
    -webkit-user-select: none;
    transition: background-color 0.1s ease, transform 0.1s ease;
     -webkit-tap-highlight-color: transparent;
}

.exit-button:hover, /* Efecto hover para escritorio */
.exit-button:active { /* Efecto active para táctil */
    background-color: rgba(220, 40, 40, 0.9); /* Rojo más intenso */
    border-color: white;
    transform: scale(1.1);
}

