/* ========================================
   FLAPPY UNDERTALE - STYLES
   Reorganizado según convenciones modernas
   ======================================== */

/* === 1. FONTS Y RECURSOS === */
@font-face {
    font-family: 'PixelOperatorSC';
    src: url('assets/PixelOperatorSC.ttf') format('truetype');
    font-display: swap;
}

@font-face {
    font-family: 'PixelOperatorSC-Bold';
    src: url('assets/PixelOperatorSC-Bold.ttf') format('truetype');
    font-display: swap;
}

/* === 2. RESET Y CONFIGURACIÓN BASE === */
* {
    box-sizing: border-box;
}

/* Clase para elementos ocultos visualmente pero accesibles a lectores de pantalla */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'PixelOperatorSC', 'Arial', sans-serif;
    background: #000 url('assets/background.png') no-repeat center center;
    overflow: hidden;
    width: 100%;
    height: 100vh;
    
    /* Configuración de fondo universal */
    background-size: auto 100vh;
    background-position: center center;
    background-attachment: fixed;
    
    /* Optimizaciones de interacción */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    
    /* Prevenir orientación horizontal en dispositivos compatibles */
    -webkit-app-region: no-drag;
}

/* === 3. COMPONENTES PRINCIPALES === */

/* Canvas del juego */
canvas {
    display: block;
    background-color: rgba(0, 0, 0, 0.8);
}

/* Área de juego */
#gameArea {
    position: relative;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

/* === 4. ELEMENTOS DEL JUEGO === */

/* Jugador */
#player {
    position: absolute;
    width: 50px;
    height: 50px;
    background-image: url('assets/player.png');
    background-size: cover;
    bottom: 50%;
    left: 20%;
}

/* Tuberías */
.pipe {
    position: absolute;
    width: 60px;
    background-image: url('assets/pipe.png');
    background-size: cover;
}

/* === 5. INTERFAZ DE USUARIO === */

/* Puntaje */
#score {
    position: absolute;
    top: 20px;
    left: 20px;
    font-size: 24px;
    color: white;
    font-family: 'PixelOperatorSC-Bold', Arial, sans-serif;
}

/* Botón de jugar */
#playButton {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 10px 20px;
    font-size: 24px;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    cursor: pointer;
    font-family: 'PixelOperatorSC-Bold', Arial, sans-serif;
    border-radius: 5px;
    transition: background-color 0.3s ease;
}

#playButton:hover {
    background-color: rgba(0, 0, 0, 0.9);
}

/* Tabla de puntuaciones */
#leaderboard {
    position: absolute;
    top: 20px;
    right: 20px;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 10px;
    border-radius: 5px;
    max-height: 300px;
    overflow-y: auto;
    font-family: 'PixelOperatorSC', Arial, sans-serif;
}

.leaderboard-entry {
    margin: 5px 0;
    font-size: 18px;
}

/* === 6. RESPONSIVE DESIGN === */

/* Dispositivos móviles generales */
@media (hover: none) and (pointer: coarse) {
    body {
        background-attachment: scroll;
        height: 100dvh;
        background-size: auto 100dvh;
    }
}

/* Pantallas landscape anchas (aspect-ratio > 16:9) */
@media (min-aspect-ratio: 16/9) {
    body {
        background-size: auto 100vh;
    }
}

/* Pantallas portrait altas (aspect-ratio < 9:16) */
@media (max-aspect-ratio: 9/16) {
    body {
        background-size: auto 100vh;
    }
}

/* === 7. PARCHES ESPECÍFICOS PARA iOS === */

/* Optimizaciones generales para iOS */
@supports (-webkit-touch-callout: none) {
    body {
        /* Forzar aceleración por hardware */
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
        
        /* Configuración de fondo estable */
        background-size: auto 100vh !important;
        background-position: center center !important;
        background-repeat: no-repeat !important;
        
        /* Prevenir zoom automático */
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
        
        /* Usar viewport dinámico para iOS */
        height: 100dvh !important;
    }
    
    /* Centrar canvas perfectamente en iOS */
    canvas {
        position: absolute !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        -webkit-transform: translate(-50%, -50%) !important;
        z-index: 1 !important;
    }
    
    /* Contenedor de canvas ajustado para iOS */
    #game-canvas-container {
        position: relative !important;
        width: 100% !important;
        height: 100dvh !important;
        overflow: hidden !important;
    }
}

/* iPhone 11 y dispositivos similares (828x1792) */
@media only screen 
  and (device-width: 414px) 
  and (device-height: 896px) 
  and (-webkit-device-pixel-ratio: 2) {
    body {
        height: 100dvh !important;
        background-size: auto 100dvh !important;
        background-position: center center !important;
        will-change: transform;
        -webkit-perspective: 1000px;
        perspective: 1000px;
    }
    
    /* Asegurar que el canvas esté perfectamente centrado en iPhone 11 */
    canvas {
        position: absolute !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        -webkit-transform: translate(-50%, -50%) !important;
    }
}

/* Chrome iOS en modo landscape */
@media only screen 
  and (orientation: landscape) 
  and (-webkit-min-device-pixel-ratio: 2) {
    body {
        background-size: 100vw auto !important;
        background-position: center center !important;
    }
}

/* === 8. UTILIDADES Y HELPERS === */

/* Clase para elementos no seleccionables */
.no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Clase para aceleración por hardware */
.gpu-accelerated {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
}

/* === 9. UTILIDADES FINALES === */

/* Prevenir zoom y rotación accidental */
@media screen and (max-width: 768px) {
    html {
        -webkit-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
    }
    
    /* Configuración específica para móviles */
    body {
        /* Prevenir bounce scroll en iOS */
        overflow: hidden;
        -webkit-overflow-scrolling: touch;
        
        /* Asegurar altura completa en móviles */
        min-height: 100vh;
        min-height: 100dvh;
    }
}

/* === 10. FOOTER === */

/* Footer con disclaimer */
#game-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgba(0, 0, 0, 0.8);
    color: #ccc;
    text-align: center;
    padding: 8px 10px 6px 10px;
    font-family: 'PixelOperatorSC', Arial, sans-serif;
    font-size: 12px;
    line-height: 1.2;
    z-index: 1000;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

#game-footer p {
    margin: 0;
    opacity: 0.9;
}

/* Responsive footer */
@media screen and (max-width: 768px) {
    #game-footer {
        font-size: 9px;
        padding: 6px 8px 4px 8px;
    }
}

@media screen and (max-width: 480px) {
    #game-footer {
        font-size: 8px;
        padding: 4px 6px 3px 6px;
    }
}