/* RESET DE ESTILOS GENERALES Y CONFIGURACIÓN RESPONSIVE */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #030308;
    font-family: 'Outfit', sans-serif;
    color: #ffffff;
}

/* CONTENEDOR PRINCIPAL DEL JUEGO */
#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* CANVAS DE JUEGO OPTIMIZADO */
#gameCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    display: block;
}

/* CAPA DE UI HTML (Súper nítida sobre el canvas) */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none; /* Deja pasar clicks al canvas cuando sea necesario */
}

/* COMPONENTES DE PANTALLA GENÉRICOS */
.ui-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 40px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s cubic-bezier(0.25, 1, 0.5, 1), visibility 0.4s;
    pointer-events: none;
}

.ui-screen.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* PANTALLA DE MENÚ INICIAL */
#menu-screen {
    justify-content: space-around;
    align-items: center;
    background: radial-gradient(circle at center, rgba(13, 11, 34, 0.3) 0%, rgba(3, 3, 8, 0) 70%);
}

.menu-header {
    text-align: center;
}

.game-title {
    font-size: 5rem;
    font-weight: 800;
    letter-spacing: 0.8rem;
    text-transform: uppercase;
    background: linear-gradient(135deg, #ffffff 0%, #a5b4fc 50%, #4f46e5 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 30px rgba(79, 70, 229, 0.4));
    animation: pulseGlow 4s infinite ease-in-out;
}

.game-subtitle {
    font-size: 1.1rem;
    font-weight: 300;
    letter-spacing: 0.2rem;
    color: #94a3b8;
    margin-top: 10px;
    text-transform: uppercase;
}

.menu-stats {
    display: flex;
    justify-content: center;
    margin: 20px 0;
}

.stat-box {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 15px 30px;
    text-align: center;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.4);
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #6366f1;
    letter-spacing: 0.15rem;
    margin-bottom: 5px;
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    color: #ffffff;
}

.menu-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    max-width: 320px;
}

/* BOTONES ESTILIZADOS */
.btn {
    font-family: 'Outfit', sans-serif;
    border: none;
    outline: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    overflow: hidden;
}

.btn-primary {
    width: 100%;
    padding: 18px 40px;
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: 0.15rem;
    color: #ffffff;
    background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
    border-radius: 50px;
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.btn-primary:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 0 30px rgba(99, 102, 241, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.btn-primary:active {
    transform: translateY(-1px) scale(0.99);
}

.btn-secondary {
    padding: 15px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #ffffff;
    width: 55px;
    height: 55px;
}

.btn-secondary svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
    transition: transform 0.2s;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.2);
    color: #a5b4fc;
}

.btn-secondary:hover svg {
    transform: scale(1.1);
}

.secondary-buttons {
    display: flex;
    gap: 20px;
    justify-content: center;
}

.instructions {
    text-align: center;
    font-size: 0.85rem;
    color: #64748b;
    letter-spacing: 0.05rem;
    text-transform: uppercase;
}

/* CONTROL DE RESPONSIVE PARA INSTRUCCIONES */
.device-instruction-pc { display: block; }
.device-instruction-mobile { display: none; }

@media (max-width: 768px) {
    .device-instruction-pc { display: none; }
    .device-instruction-mobile { display: block; }
    .game-title { font-size: 3.5rem; letter-spacing: 0.5rem; }
    .ui-screen { padding: 20px; }
}

/* INTERFAZ HUD DURANTE EL JUEGO */
#hud {
    pointer-events: none; /* Absolutamente transparente a eventos para no interferir con clicks del juego */
}

.hud-top {
    display: flex;
    justify-content: space-between;
    width: 100%;
}

.score-container, .energy-container {
    background: rgba(3, 3, 8, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 10px 20px;
    backdrop-filter: blur(5px);
}

.energy-container {
    text-align: right;
}

.hud-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    color: #94a3b8;
    letter-spacing: 0.1rem;
    margin-bottom: 2px;
}

.hud-value {
    font-size: 1.6rem;
    font-weight: 800;
    color: #ffffff;
    font-feature-settings: "tnum"; /* Números monoespaciados para evitar saltos de layout */
}

.hud-center {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    width: 100%;
}

.hud-alert-text {
    font-size: 2rem;
    font-weight: 800;
    color: #38bdf8;
    text-shadow: 0 0 15px rgba(56, 189, 248, 0.6);
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.hud-alert-text.show {
    opacity: 1;
    transform: scale(1);
}

/* PANTALLA GAME OVER */
#gameover-screen {
    justify-content: center;
    align-items: center;
    background: rgba(3, 3, 8, 0.85);
    backdrop-filter: blur(8px);
}

.gameover-box {
    width: 100%;
    max-width: 420px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 24px;
    padding: 40px;
    text-align: center;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.8);
    transform: scale(0.9);
    transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

#gameover-screen.active .gameover-box {
    transform: scale(1);
}

.gameover-title {
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: 0.1rem;
    color: #ef4444;
    text-shadow: 0 0 20px rgba(239, 68, 68, 0.3);
    margin-bottom: 20px;
}

.new-record-badge {
    display: inline-block;
    background: linear-gradient(135deg, #eab308 0%, #ca8a04 100%);
    color: #000000;
    font-weight: 800;
    font-size: 0.9rem;
    letter-spacing: 0.1rem;
    padding: 6px 16px;
    border-radius: 50px;
    margin-bottom: 25px;
    animation: bounce 1s infinite alternate;
}

.gameover-results {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 35px;
    background: rgba(0, 0, 0, 0.2);
    padding: 20px;
    border-radius: 16px;
}

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.result-row.divider {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 15px;
    margin-top: 5px;
}

.result-label {
    font-size: 0.9rem;
    color: #94a3b8;
    font-weight: 500;
}

.result-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: #ffffff;
}

.result-row.divider .result-value {
    color: #eab308;
    font-size: 1.4rem;
}

.btn-large {
    padding: 20px 40px;
    border-radius: 16px;
}

.btn-icon {
    width: 24px;
    height: 24px;
    fill: currentColor;
    margin-left: 10px;
}

/* MODAL DE ESTADÍSTICAS */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(3, 3, 8, 0.9);
    backdrop-filter: blur(10px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    pointer-events: none;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.modal-content {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    padding: 40px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: 0.1rem;
    color: #6366f1;
    margin-bottom: 30px;
}

.stats-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 35px;
}

.modal-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
    padding: 15px 20px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.modal-stat-label {
    font-size: 0.9rem;
    color: #94a3b8;
}

.modal-stat-value {
    font-size: 1.25rem;
    font-weight: 700;
}

.btn-close {
    width: 100%;
    border-radius: 12px;
}

/* CLASES AUXILIARES */
.hidden {
    display: none !important;
}

/* ANIMACIONES */
@keyframes pulseGlow {
    0%, 100% { filter: drop-shadow(0 0 20px rgba(79, 70, 229, 0.4)); }
    50% { filter: drop-shadow(0 0 35px rgba(99, 102, 241, 0.7)); }
}

@keyframes bounce {
    0% { transform: translateY(0); }
    100% { transform: translateY(-6px); }
}
