body {
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: #333;
    font-family: Arial, sans-serif;
    overflow-x: hidden;
}

.contenedor-principal {
    width: 100%;
    max-width: 1024px;
    margin: 0 auto;
    position: relative;
}

.pantalla {
    position: fixed;
    width: 1024px;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    left: 50%;
    transform: translateX(-50%);
}

.seleccion {
    text-align: center;
    padding: 20px;
}

#personajes, #escenarios {
    display: flex;
    gap: 20px;
    margin: 20px 0;
    justify-content: center;
}

.personaje, .escenario {
    width: 150px;
    height: 150px;
    border: 3px solid #ccc;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    background-size: cover;
    background-position: center;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.personaje::after, .escenario::after {
    content: attr(data-nombre);
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 5px;
    text-align: center;
    font-size: 1.1em;
}

.personaje.seleccionado, .escenario.seleccionado {
    border-color: #4CAF50;
    transform: scale(1.05);
    box-shadow: 0 0 10px rgba(0,0,0,0.2);
}

.oculto {
    display: none !important;
}

#comenzarJuego {
    padding: 15px 30px;
    font-size: 1.2em;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.3s ease;
}

#comenzarJuego:hover {
    background: #45a049;
}

#comenzarJuego:disabled {
    background: #cccccc;
    cursor: not-allowed;
}

.btn {
    padding: 10px 20px;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    margin: 10px;
}

#gameOver {
    text-align: center;
    background: rgba(0, 0, 0, 0.9);
    color: white;
}

#mensajeFinal {
    font-size: 2em;
    margin-bottom: 10px;
    color: #FF6B6B;
}

.mensaje-secundario {
    font-size: 1.5em;
    margin-bottom: 30px;
    color: #4ECDC4;
}

.botones-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

.btn {
    padding: 15px 30px;
    font-size: 1.2em;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.3s ease;
    width: 250px;
    text-align: center;
}

.btn-primary {
    background: #4CAF50;
    color: white;
}

.btn-secondary {
    background: #45B7D1;
    color: white;
}

.btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 10px rgba(255,255,255,0.2);
}

.boton-sonido {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    color: white;
    cursor: pointer;
    z-index: 1000;
    display: none; /* Inicialmente oculto */
    transition: all 0.3s ease;
}

.boton-sonido:hover {
    background: rgba(0, 0, 0, 0.7);
    transform: scale(1.1);
}

.boton-sonido.activo {
    display: block;
}

.boton-sonido.silenciado i::before {
    content: "\f6a9"; /* Ícono de volumen silenciado */
}

/* Estilos para el botón de salto en móviles */
.boton-salto {
    position: fixed;
    bottom: 20px;
    right: 80px; /* A la derecha del botón de sonido */
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    color: white;
    cursor: pointer;
    z-index: 1000;
    display: none;
    transition: all 0.3s ease;
    font-size: 24px;
}

.boton-salto.activo {
    display: block;
}

.boton-salto:active {
    background: rgba(0, 0, 0, 0.7);
    transform: scale(0.95);
}

/* Estilos para forzar orientación horizontal en móviles */
.orientacion-alerta {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    color: white;
    justify-content: center;
    align-items: center;
    text-align: center;
    z-index: 2000;
}

@media screen and (orientation: portrait) {
    .orientacion-alerta {
        display: flex;
    }
}

@media screen and (max-width: 800px) {
    body {
        min-height: 100vh;
        min-height: -webkit-fill-available; /* Para iOS */
    }

    html {
        height: -webkit-fill-available; /* Para iOS */
    }

    #gameCanvas {
        width: 100vw;
        height: 100vh;
        height: -webkit-fill-available; /* Para iOS */
    }
    
    .pantalla {
        height: auto;
        min-height: 100vh;
        padding: 20px 0;
    }
    
    .personaje, .escenario {
        width: 100px;
        height: 100px;
    }
    
    .btn {
        width: 200px;
        font-size: 1em;
    }

    /* Ajustar el menú inicial para móviles */
    #menuInicial {
        position: absolute;
        overflow-y: auto;
    }

    /* Mantener el game over como fixed */
    #gameOver {
        position: fixed;
    }

    /* Ajustes para el menú inicial en móviles */
    #menuInicial h1 {
        font-size: 1.5em;
        margin: 10px 0;
    }

    #menuInicial h2 {
        font-size: 1.2em;
        margin: 8px 0;
    }

    .seleccion {
        padding: 10px;
    }

    #personajes, #escenarios {
        gap: 10px;
        margin: 10px 0;
    }

    .personaje, .escenario {
        width: 80px;
        height: 80px;
        border-width: 2px;
    }

    #comenzarJuego {
        padding: 10px 20px;
        font-size: 1em;
        margin-top: 10px;
    }

    /* Ajustes para el juego */
    #gameCanvas {
        width: 100vw;
        height: 100vh;
        height: -webkit-fill-available;
    }
    
    .pantalla {
        height: 100vh;
        padding: 10px 0;
        justify-content: flex-start;
    }
    
    .btn {
        width: 180px;
        font-size: 0.9em;
        padding: 12px 20px;
    }

    /* Game Over ajustes */
    #gameOver {
        position: fixed;
    }

    #mensajeFinal {
        font-size: 1.5em;
        margin-bottom: 8px;
    }

    .mensaje-secundario {
        font-size: 1.2em;
        margin-bottom: 20px;
    }

    .botones-container {
        gap: 10px;
    }
}

/* Ajuste específico para orientación horizontal en móviles */
@media screen and (orientation: landscape) and (max-width: 800px) {
    #gameCanvas {
        height: 100vh;
        width: auto;
        max-width: 100vw;
    }
}

/* Ajustes específicos para pantallas muy pequeñas */
@media screen and (max-height: 500px) {
    #menuInicial h1 {
        font-size: 1.2em;
        margin: 5px 0;
    }

    #menuInicial h2 {
        font-size: 1em;
        margin: 5px 0;
    }

    .personaje, .escenario {
        width: 60px;
        height: 60px;
    }

    .seleccion {
        padding: 5px;
    }

    #personajes, #escenarios {
        gap: 8px;
        margin: 8px 0;
    }

    #comenzarJuego {
        padding: 8px 16px;
        font-size: 0.9em;
        margin-top: 8px;
    }
}

/* Ajustes específicos para móviles */
@media screen and (max-width: 800px) {
    body {
        min-height: 100vh;
        min-height: -webkit-fill-available;
        margin: 0;
        padding: 0;
        overflow: hidden;
    }

    html {
        height: -webkit-fill-available;
    }

    #gameCanvas {
        width: 100%;
        height: 100%;
        object-fit: contain; /* Mantener proporciones */
        position: fixed;
        top: 0;
        left: 0;
    }

    /* Ajustes para el menú inicial */
    #menuInicial {
        position: absolute;
        height: 100%;
        overflow-y: auto;
        padding: 10px;
        box-sizing: border-box;
    }

    #menuInicial h1 {
        font-size: 1.2em;
        margin: 5px 0;
    }

    #menuInicial h2 {
        font-size: 1em;
        margin: 5px 0;
    }

    .seleccion {
        padding: 5px;
    }

    #personajes, #escenarios {
        gap: 8px;
        margin: 8px 0;
    }

    .personaje, .escenario {
        width: 60px;
        height: 60px;
    }

    /* Ajustes para el juego en modo landscape */
    @media (orientation: landscape) {
        #gameCanvas {
            width: 100vw;
            height: 100vh;
            max-height: 100vh;
            object-fit: cover;
        }

        .boton-salto {
            bottom: 10px;
            right: 70px;
            width: 50px;
            height: 50px;
        }

        .boton-sonido {
            bottom: 10px;
            right: 10px;
            width: 50px;
            height: 50px;
        }
    }

    /* Ajustes para el juego en modo portrait */
    @media (orientation: portrait) {
        .orientacion-alerta {
            display: flex;
            background-color: rgba(0, 0, 0, 0.9);
            z-index: 9999;
        }
    }

    /* Game Over ajustes */
    #gameOver {
        position: fixed;
        padding: 20px;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        text-align: center;
    }

    #mensajeFinal {
        font-size: 1.2em;
        margin-bottom: 10px;
    }

    .mensaje-secundario {
        font-size: 1em;
        margin-bottom: 15px;
    }

    .btn {
        width: 160px;
        font-size: 0.9em;
        padding: 10px 15px;
    }
}

/* Ajustes específicos para pantallas muy pequeñas en landscape */
@media screen and (max-height: 450px) and (orientation: landscape) {
    .boton-salto, .boton-sonido {
        transform: scale(0.8);
    }

    #gameCanvas {
        object-fit: contain;
        max-width: 100vw;
        max-height: 100vh;
    }
}

/* Ajustes para móviles */
@media screen and (max-width: 1024px) {
    body {
        --scale-ratio: calc(100vw / 1024);
        min-height: 100vh;
        min-height: -webkit-fill-available;
        display: flex;
        justify-content: flex-start;
        align-items: flex-start;
        overflow: hidden;
        margin: 0;
        padding: 0;
    }

    .pantalla {
        width: 100%;
        max-width: 1024px;
        height: 100vh;
        position: absolute;
        left: 0;
        top: 0;
        transform: scale(var(--scale-ratio));
        transform-origin: top left;
    }

    #gameCanvas {
        width: 1024px;
        height: 500px;
        position: absolute;
        left: 0;
        top: 0;
        transform: scale(var(--scale-ratio));
        transform-origin: top left;
    }

    /* Ajustar posición de botones en móviles */
    .boton-salto,
    .boton-sonido {
        position: fixed;
        transform: scale(var(--scale-ratio));
        transform-origin: bottom right;
    }

    .boton-sonido {
        right: 10px;
        bottom: 10px;
    }

    .boton-salto {
        right: 80px;
        bottom: 10px;
    }
}

/* Ajuste específico para orientación landscape en móviles */
@media screen and (orientation: landscape) and (max-width: 1024px) {
    .pantalla,
    #gameCanvas {
        height: 100vh;
        transform: scale(min(var(--scale-ratio), calc(100vh / 500)));
        transform-origin: top left;
    }
}

.escenario {
    width: 150px;
    height: 150px;
    border: 3px solid #ccc;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    background-size: cover;
    background-position: center;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.escenario::after {
    content: attr(data-nombre);
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 5px;
    text-align: center;
    font-size: 1.1em;
}

.escenario.seleccionado {
    border-color: #4CAF50;
    transform: scale(1.05);
    box-shadow: 0 0 10px rgba(0,0,0,0.2);
}

/* Ajuste para móviles */
@media screen and (max-width: 1024px) {
    .escenario {
        width: 80px;
        height: 80px;
    }

    .escenario::after {
        font-size: 0.9em;
        padding: 3px;
    }
}