/* ====================================
   REPARA FELIX JR. - Estilo Pixel Art
   ==================================== */

/* Fuente pixel art */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

body {
    background: #1a1a2e;
    background-image:
        radial-gradient(circle at 20% 30%, #2d2d5a 0%, transparent 50%),
        radial-gradient(circle at 80% 70%, #2d2d5a 0%, transparent 50%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Press Start 2P', 'Courier New', monospace;
    color: white;
    overflow: hidden;
    padding: 20px;
}

/* ===== Marco Arcade ===== */
.game-container {
    display: flex;
    justify-content: center;
    align-items: center;
}

.arcade-frame {
    /* Ancho fijo = game-screen (560) + padding (30*2) + border (8*2) */
    width: 636px;
    background: linear-gradient(180deg, #c91414 0%, #8a0a0a 100%);
    border: 8px solid #2a0505;
    border-radius: 20px;
    padding: 30px;
    box-shadow:
        0 0 40px rgba(255, 50, 50, 0.4),
        inset 0 0 20px rgba(0, 0, 0, 0.5);
    position: relative;
}

.arcade-frame::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    bottom: 10px;
    border: 3px solid #ffcc00;
    border-radius: 12px;
    pointer-events: none;
}

.arcade-title {
    text-align: center;
    color: #ffcc00;
    font-size: 24px;
    margin-bottom: 20px;
    text-shadow:
        3px 3px 0 #000,
        -1px -1px 0 #ff6600;
    letter-spacing: 2px;
}

/* ===== HUD: Puntaje, Nivel, Vidas ===== */
.hud {
    background: #0d0d0d;
    border: 3px solid #2a2a2a;
    border-radius: 6px;
    padding: 10px 24px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow:
        inset 0 0 8px rgba(0, 0, 0, 0.8),
        0 0 6px rgba(255, 204, 0, 0.2);
}

.hud-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 90px;
}

.hud-label {
    color: #ffcc00;
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    letter-spacing: 2px;
    text-shadow: 1px 1px 0 #5a3010;
}

.hud-value {
    color: #ff6030;
    font-family: 'Press Start 2P', monospace;
    font-size: 16px;
    text-shadow:
        0 0 4px #ff3000,
        2px 2px 0 #000;
    letter-spacing: 2px;
}

.hud-lives {
    display: flex;
    gap: 4px;
}

.life-heart {
    color: #ff3030;
    font-size: 20px;
    line-height: 1;
    text-shadow:
        2px 2px 0 #000,
        0 0 4px #ff0000;
    transition: all 0.3s ease;
}

.life-heart.lost {
    color: #3a3a3a;
    text-shadow: 2px 2px 0 #000;
    transform: scale(0.8);
    opacity: 0.5;
}

.life-heart.losing {
    animation: heartBreak 0.6s ease-out;
}

@keyframes heartBreak {
    0%   { transform: scale(1); color: #ff3030; }
    30%  { transform: scale(1.5); color: #ffffff; }
    60%  { transform: scale(0.5) rotate(20deg); color: #ff8080; }
    100% { transform: scale(0.8); color: #3a3a3a; opacity: 0.5; }
}

/* Pulso en el puntaje al sumar */
.hud-value.pulse {
    animation: scorePulse 0.4s ease-out;
}

@keyframes scorePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); color: #ffcc00; }
}

/* ===== Pantalla del Juego ===== */
.game-screen {
    width: 560px;
    height: 640px;
    background: #0a0a2a;
    border: 4px solid #000;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.8);
}

/* ===== Cielo Nocturno ===== */
.sky {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 100%;
    background: linear-gradient(180deg, #0a0a3a 0%, #1a1a5a 50%, #2d1a4a 100%);
}

.star {
    position: absolute;
    width: 4px;
    height: 4px;
    background: #ffffff;
    box-shadow:
        0 0 4px #ffffff,
        0 0 8px rgba(255, 255, 255, 0.5);
    animation: twinkle 2s ease-in-out infinite;
}

.star:nth-child(2) { animation-delay: 0.3s; }
.star:nth-child(3) { animation-delay: 0.6s; }
.star:nth-child(4) { animation-delay: 0.9s; }
.star:nth-child(5) { animation-delay: 1.2s; }
.star:nth-child(6) { animation-delay: 1.5s; }

@keyframes twinkle {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.moon {
    position: absolute;
    top: 30px;
    right: 50px;
    width: 40px;
    height: 40px;
    background: #fff8d6;
    border-radius: 50%;
    box-shadow:
        0 0 20px rgba(255, 248, 214, 0.6),
        -8px 0 0 -2px #0a0a3a;
}

/* ===== Edificio Niceland ===== */
.building {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 400px;
    height: 560px;
}

/* Techo del edificio (donde estará Ralph) */
.roof {
    position: absolute;
    top: 0;
    left: -20px;
    right: -20px;
    height: 50px;
    background: #8a4a2a;
    border-bottom: 4px solid #5a2a1a;
    box-shadow: inset 0 -4px 0 #6a3a1a;
}

.roof::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 0;
    right: 0;
    height: 8px;
    background: repeating-linear-gradient(
        90deg,
        #5a2a1a 0px,
        #5a2a1a 12px,
        #8a4a2a 12px,
        #8a4a2a 24px
    );
}

/* Contenedor de pisos */
.floors {
    position: absolute;
    top: 50px;
    left: 0;
    right: 0;
    bottom: 30px;
    background: #b87333;
    background-image: repeating-linear-gradient(
        90deg,
        #a06628 0px,
        #a06628 2px,
        #b87333 2px,
        #b87333 8px
    );
    border-left: 4px solid #6a4020;
    border-right: 4px solid #6a4020;
}

/* Cada piso tiene 4 ventanas */
.floor {
    height: 120px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0 8px;
    position: relative;
    border-bottom: 4px solid #5a3010;
    box-shadow: inset 0 -8px 0 #8a5523;
}

/* Ventanas */
.window {
    width: 70px;
    height: 80px;
    background: #4a90d9;
    border: 4px solid #2a4a6a;
    position: relative;
    box-shadow:
        inset 4px 4px 0 #6ab0ff,
        inset -4px -4px 0 #2a6090;
}

/* Cruz de la ventana */
.window::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 4px;
    background: #2a4a6a;
    transform: translateY(-50%);
}

.window::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 4px;
    background: #2a4a6a;
    transform: translateX(-50%);
}

/* Ventana iluminada (vecino con la luz prendida) */
.window.lit {
    background: #ffb830;
    box-shadow:
        inset 4px 4px 0 #ffd870,
        inset -4px -4px 0 #c08020,
        0 0 10px rgba(255, 200, 80, 0.6);
    animation: windowLitOn 0.5s ease-out;
}

.window.lit::before,
.window.lit::after {
    background: #6a3a10;
}

@keyframes windowLitOn {
    0%   { background: #4a90d9; }
    50%  { background: #ffffff; box-shadow: inset 4px 4px 0 #ffffff, inset -4px -4px 0 #c08020, 0 0 20px rgba(255, 255, 200, 0.9); }
    100% { background: #ffb830; }
}

/* Ventana rota */
.window.broken {
    background: #2a2a3a;
    box-shadow:
        inset 4px 4px 0 #4a4a5a,
        inset -4px -4px 0 #1a1a2a;
}

/* Si está iluminada y rota, prevalece "rota" */
.window.broken.lit {
    background: #2a2a3a;
    box-shadow:
        inset 4px 4px 0 #4a4a5a,
        inset -4px -4px 0 #1a1a2a;
    animation: none;
}

.window.broken::before,
.window.broken::after {
    background: #1a1a1a;
}

/* Cristales rotos (zigzag) */
.window.broken .glass-crack {
    position: absolute;
    inset: 0;
    background:
        linear-gradient(45deg, transparent 48%, #888 48%, #888 52%, transparent 52%),
        linear-gradient(-45deg, transparent 48%, #888 48%, #888 52%, transparent 52%);
    background-size: 20px 20px;
    opacity: 0.5;
}

/* Acera */
.sidewalk {
    position: absolute;
    bottom: 0;
    left: -30px;
    right: -30px;
    height: 30px;
    background: #6a6a6a;
    background-image: repeating-linear-gradient(
        90deg,
        #5a5a5a 0px,
        #5a5a5a 2px,
        #6a6a6a 2px,
        #6a6a6a 60px,
        #4a4a4a 60px,
        #4a4a4a 62px
    );
    border-top: 3px solid #4a4a4a;
}

/* ===== Ralph (Personaje Villano) ===== */
.ralph {
    position: absolute;
    width: 90px;
    height: 80px;
    top: -72px;        /* sobre el techo */
    left: 30px;
    z-index: 5;
}

/* Pelo desordenado marrón oscuro */
.ralph-hair {
    position: absolute;
    top: 0;
    left: 14px;
    width: 62px;
    height: 22px;
    background: #3a2010;
    box-shadow:
        -6px 4px 0 #3a2010,
        -10px 10px 0 #3a2010,
        6px 4px 0 #3a2010,
        10px 10px 0 #3a2010,
        0 -4px 0 #3a2010,
        -16px 2px 0 #3a2010,
        16px 2px 0 #3a2010;
}

/* Cara grande color piel */
.ralph-face {
    position: absolute;
    top: 18px;
    left: 18px;
    width: 54px;
    height: 26px;
    background: #f0b890;
    box-shadow:
        inset -4px -4px 0 #d09060,
        inset 4px 4px 0 #ffd0a8;
}

/* Ojos enojados */
.ralph-face::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 10px;
    width: 4px;
    height: 6px;
    background: #000;
    box-shadow: 26px 0 0 #000;
}

/* Boca ceñuda */
.ralph-face::after {
    content: '';
    position: absolute;
    bottom: 4px;
    left: 18px;
    width: 18px;
    height: 4px;
    background: #2a0a0a;
    border-radius: 0 0 4px 4px;
}

/* Cejas enojadas */
.ralph-eyebrows {
    position: absolute;
    top: 4px;
    left: 8px;
    width: 10px;
    height: 4px;
    background: #1a0a05;
    transform: rotate(15deg);
}

.ralph-eyebrows::after {
    content: '';
    position: absolute;
    top: 0;
    left: 28px;
    width: 10px;
    height: 4px;
    background: #1a0a05;
    transform: rotate(-15deg);
}

/* Cuerpo (camisa rojiza con tirantes) */
.ralph-body {
    position: absolute;
    top: 42px;
    left: 4px;
    width: 82px;
    height: 38px;
    background: #a04030;
    box-shadow:
        inset -4px -4px 0 #6a2818,
        inset 4px 4px 0 #c05848;
}

/* Tirantes amarillos visibles */
.ralph-body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 16px;
    width: 6px;
    height: 28px;
    background: #d49050;
    box-shadow: 44px 0 0 #d49050;
}

/* Brazo de atrás */
.ralph-arm-back {
    position: absolute;
    top: 42px;
    left: -10px;
    width: 22px;
    height: 30px;
    background: #f0b890;
    box-shadow: inset -3px -3px 0 #d09060;
    z-index: -1;
}

/* Brazo frontal (sostiene los ladrillos) */
.ralph-arm-front {
    position: absolute;
    top: 46px;
    right: -16px;
    width: 26px;
    height: 28px;
    background: #f0b890;
    box-shadow: inset -3px -3px 0 #d09060;
    transform-origin: 8px 6px;
    transition: transform 0.15s ease-out;
    z-index: 6;
}

/* Pila de ladrillos en la mano */
.ralph-bricks {
    position: absolute;
    top: 22px;
    right: -8px;
    width: 32px;
    height: 22px;
    background: #8a4a2a;
    border: 2px solid #3a1a0a;
    background-image:
        linear-gradient(transparent 47%, #4a2010 47%, #4a2010 53%, transparent 53%),
        linear-gradient(90deg, transparent 47%, #4a2010 47%, #4a2010 53%, transparent 53%);
    box-shadow:
        inset 2px 2px 0 #aa6040,
        inset -2px -2px 0 #5a2810;
}

/* Animación de Ralph lanzando ladrillo */
.ralph.throwing .ralph-arm-front {
    animation: ralphThrow 0.5s ease-in-out;
}

@keyframes ralphThrow {
    0%   { transform: rotate(0deg); }
    30%  { transform: rotate(-50deg); }
    55%  { transform: rotate(40deg); }
    100% { transform: rotate(0deg); }
}

/* Animación idle de Ralph (respiración furiosa) */
.ralph {
    animation: ralphIdle 1.8s ease-in-out infinite;
}

@keyframes ralphIdle {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-2px); }
}

/* ===== Ladrillos cayendo ===== */
.brick {
    position: absolute;
    width: 26px;
    height: 18px;
    background: #8a4a2a;
    border: 2px solid #3a1a0a;
    background-image:
        linear-gradient(transparent 46%, #4a2010 46%, #4a2010 54%, transparent 54%),
        linear-gradient(90deg, transparent 46%, #4a2010 46%, #4a2010 54%, transparent 54%);
    box-shadow:
        inset 2px 2px 0 #aa6040,
        inset -2px -2px 0 #5a2810,
        0 0 4px rgba(0, 0, 0, 0.5);
    z-index: 12;
    pointer-events: none;
}

/* Ladrillo rotando al caer */
.brick {
    animation: brickRotate 1.2s linear infinite;
}

@keyframes brickRotate {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Impacto del ladrillo al chocar */
.brick.smash {
    animation: brickSmash 0.3s ease-out forwards;
}

@keyframes brickSmash {
    0%   { transform: scale(1); opacity: 1; }
    100% { transform: scale(1.5); opacity: 0; }
}

/* ===== Pasteles bonus ===== */
.pie {
    position: absolute;
    width: 26px;
    height: 22px;
    z-index: 11;
    pointer-events: none;
    animation: pieFloat 0.6s ease-in-out infinite alternate;
}

@keyframes pieFloat {
    0%   { transform: rotate(-6deg); }
    100% { transform: rotate(6deg); }
}

/* Plato del pastel */
.pie::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 0;
    width: 26px;
    height: 14px;
    background: #f4d4a0;
    border: 2px solid #6a3a1a;
    border-radius: 0 0 12px 12px;
    box-shadow: inset -2px -3px 0 #c0a070;
}

/* Crema/relleno encima */
.pie::after {
    content: '';
    position: absolute;
    top: 0;
    left: 2px;
    width: 22px;
    height: 12px;
    background: #ff90c0;
    border: 2px solid #6a3a1a;
    border-radius: 12px 12px 0 0;
    box-shadow:
        inset 3px 3px 0 #ffc0d0,
        inset -2px -2px 0 #d06090;
}

/* Cereza encima (usamos un div hijo) */
.pie-cherry {
    position: absolute;
    top: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: 8px;
    height: 8px;
    background: #ff3030;
    border-radius: 50%;
    box-shadow:
        inset -2px -2px 0 #8a0000,
        inset 2px 2px 0 #ff8080;
    z-index: 2;
}

/* Tallito de la cereza */
.pie-cherry::before {
    content: '';
    position: absolute;
    top: -4px;
    left: 50%;
    width: 2px;
    height: 4px;
    background: #2a5a2a;
}

/* Pastel atrapado - animación de "yum" */
.pie.caught {
    animation: pieCaught 0.4s ease-out forwards;
}

@keyframes pieCaught {
    0%   { transform: scale(1); opacity: 1; }
    50%  { transform: scale(1.4); opacity: 1; }
    100% { transform: scale(0); opacity: 0; }
}

/* Destello de la ventana cuando el vecino lanza el pastel */
.window.neighbor-throws {
    animation: neighborFlash 0.4s ease-out;
}

@keyframes neighborFlash {
    0%, 100% { background: #4a90d9; }
    50%      { background: #ffffaa; box-shadow: inset 4px 4px 0 #ffffff, inset -4px -4px 0 #2a6090, 0 0 20px #ffff80; }
}

/* ===== Daño a Felix ===== */
.felix.hurt .felix-face,
.felix.hurt .felix-body,
.felix.hurt .felix-hat,
.felix.hurt .felix-legs {
    animation: hurtFlash 0.6s ease-out;
}

@keyframes hurtFlash {
    0%, 100% { filter: none; }
    20%, 60% { filter: brightness(2) sepia(1) hue-rotate(-50deg) saturate(5); }
    40%, 80% { filter: none; }
}

/* Sacudida de pantalla por impacto */
.game-screen.shake {
    animation: screenShake 0.4s ease-in-out;
}

@keyframes screenShake {
    0%, 100% { transform: translate(0, 0); }
    20% { transform: translate(-4px, 2px); }
    40% { transform: translate(4px, -3px); }
    60% { transform: translate(-3px, 3px); }
    80% { transform: translate(3px, -2px); }
}

/* ===== Felix (Personaje Pixel Art) ===== */
.felix {
    position: absolute;
    width: 32px;
    height: 48px;
    bottom: 30px;
    left: 280px;
    z-index: 10;
    transform: translateX(-50%);
    transition: left 0.1s ease-out, bottom 0.15s ease-out;
}

/* Felix mirando a la izquierda (espejo horizontal) */
.felix.facing-left {
    transform: translateX(-50%) scaleX(-1);
}

/* Animación de caminar (mecimiento) */
.felix.moving {
    animation: walkBob 0.3s ease-in-out infinite;
}

@keyframes walkBob {
    0%, 100% { margin-top: 0; }
    50% { margin-top: -2px; }
}

/* Animación de salto al subir */
.felix.jumping {
    animation: jumpUp 0.25s ease-out;
}

@keyframes jumpUp {
    0% { margin-top: 0; }
    50% { margin-top: -8px; }
    100% { margin-top: 0; }
}

/* Gorra azul */
.felix-hat {
    position: absolute;
    top: 0;
    left: 4px;
    width: 24px;
    height: 10px;
    background: #2060c0;
    border-radius: 12px 12px 0 0;
    box-shadow:
        inset -2px -2px 0 #103080,
        inset 2px 2px 0 #4090e0;
}

.felix-hat::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: -2px;
    right: -2px;
    height: 4px;
    background: #2060c0;
    border-radius: 0 0 4px 4px;
}

/* Cara */
.felix-face {
    position: absolute;
    top: 10px;
    left: 6px;
    width: 20px;
    height: 14px;
    background: #ffd4a3;
    border-radius: 4px;
    box-shadow:
        inset -2px -2px 0 #d4a373;
}

/* Ojos */
.felix-face::before {
    content: '';
    position: absolute;
    top: 5px;
    left: 4px;
    width: 3px;
    height: 3px;
    background: #000;
    box-shadow: 6px 0 0 #000;
}

/* Sonrisa */
.felix-face::after {
    content: '';
    position: absolute;
    bottom: 2px;
    left: 7px;
    width: 6px;
    height: 2px;
    background: #000;
    border-radius: 0 0 4px 4px;
}

/* Cuerpo (overol azul) */
.felix-body {
    position: absolute;
    top: 22px;
    left: 4px;
    width: 24px;
    height: 16px;
    background: #2060c0;
    box-shadow:
        inset -2px -2px 0 #103080,
        inset 2px 2px 0 #4090e0;
}

/* Botones del overol */
.felix-body::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 6px;
    width: 3px;
    height: 3px;
    background: #ffcc00;
    box-shadow: 9px 0 0 #ffcc00;
}

/* Piernas */
.felix-legs {
    position: absolute;
    bottom: 0;
    left: 4px;
    width: 24px;
    height: 10px;
    background: #1a1a3a;
}

.felix-legs::before {
    content: '';
    position: absolute;
    top: 0;
    left: 10px;
    width: 4px;
    height: 100%;
    background: #2060c0;
}

/* Botas */
.felix-legs::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: -2px;
    width: 12px;
    height: 4px;
    background: #5a3a1a;
    box-shadow: 16px 0 0 #5a3a1a;
}

/* Martillo dorado */
.felix-hammer {
    position: absolute;
    top: 18px;
    right: -8px;
    width: 6px;
    height: 18px;
    background: #8a5523;
    transform: rotate(-30deg);
    transform-origin: 50% 90%;
}

.felix-hammer::before {
    content: '';
    position: absolute;
    top: -4px;
    left: -6px;
    width: 18px;
    height: 8px;
    background: #ffcc00;
    box-shadow:
        inset -2px -2px 0 #c89000,
        inset 2px 2px 0 #ffe060;
}

/* Animación de golpe al reparar (ritmo rápido) */
.felix.hitting .felix-hammer {
    animation: hammerSwing 0.22s ease-in-out;
}

@keyframes hammerSwing {
    0%   { transform: rotate(-30deg); }
    30%  { transform: rotate(-80deg); }
    60%  { transform: rotate(45deg); }
    100% { transform: rotate(-30deg); }
}

/* Brillo dorado del martillo al impactar */
.felix.hitting .felix-hammer::before {
    box-shadow:
        inset -2px -2px 0 #c89000,
        inset 2px 2px 0 #ffe060,
        0 0 12px #fff4a0;
}

/* ===== Chispas de reparación ===== */
.sparkle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #ffcc00;
    box-shadow: 0 0 6px #ffe060;
    pointer-events: none;
    z-index: 15;
    clip-path: polygon(
        50% 0%, 60% 40%, 100% 50%,
        60% 60%, 50% 100%, 40% 60%,
        0% 50%, 40% 40%
    );
    animation: sparkleFly 0.7s ease-out forwards;
}

@keyframes sparkleFly {
    0% {
        transform: scale(0) rotate(0deg);
        opacity: 1;
    }
    40% {
        transform: scale(1.4) rotate(180deg);
        opacity: 1;
    }
    100% {
        transform: scale(0.2) rotate(360deg) translateY(-30px);
        opacity: 0;
    }
}

/* Texto flotante de puntos (+100) */
.float-text {
    position: absolute;
    color: #ffcc00;
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    text-shadow: 2px 2px 0 #000;
    pointer-events: none;
    z-index: 20;
    animation: floatUp 0.9s ease-out forwards;
}

@keyframes floatUp {
    0%   { transform: translateY(0); opacity: 0; }
    20%  { opacity: 1; }
    100% { transform: translateY(-40px); opacity: 0; }
}

/* Animación de "ventana arreglada" - pequeño flash */
.window.just-fixed {
    animation: windowFlash 0.4s ease-out;
}

@keyframes windowFlash {
    0%   { box-shadow: inset 4px 4px 0 #6ab0ff, inset -4px -4px 0 #2a6090, 0 0 0 rgba(255,204,0,0); }
    50%  { box-shadow: inset 4px 4px 0 #6ab0ff, inset -4px -4px 0 #2a6090, 0 0 20px rgba(255,204,0,0.9); }
    100% { box-shadow: inset 4px 4px 0 #6ab0ff, inset -4px -4px 0 #2a6090, 0 0 0 rgba(255,204,0,0); }
}

/* ===== Overlays (Game Over, Pantalla de inicio, etc.) ===== */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 200;
    gap: 24px;
}

.overlay.visible {
    display: flex;
    animation: overlayFadeIn 0.5s ease-out;
}

@keyframes overlayFadeIn {
    0%   { opacity: 0; }
    100% { opacity: 1; }
}

.overlay-title {
    font-family: 'Press Start 2P', monospace;
    font-size: 38px;
    letter-spacing: 4px;
    text-align: center;
}

.game-over-text {
    color: #ff2a2a;
    text-shadow:
        4px 4px 0 #000,
        -2px -2px 0 #5a0000,
        0 0 16px #ff0000;
    animation: gameOverPulse 1.4s ease-in-out infinite;
}

@keyframes gameOverPulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.06); }
}

.overlay-info {
    text-align: center;
    color: #ffcc00;
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    line-height: 2;
    text-shadow: 2px 2px 0 #000;
}

.final-score {
    color: #ff6030;
    font-size: 28px;
    margin-top: 8px;
    text-shadow:
        3px 3px 0 #000,
        0 0 8px #ff3000;
    letter-spacing: 3px;
}

.overlay-hint {
    color: white;
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    letter-spacing: 2px;
    margin-top: 20px;
    animation: hintBlink 1.2s ease-in-out infinite;
}

@keyframes hintBlink {
    0%, 49%  { opacity: 1; }
    50%, 100% { opacity: 0.25; }
}

/* ===== Nivel Completado / Nuevo Nivel ===== */
.level-overlay {
    background: rgba(0, 30, 10, 0.85);
}

.level-text {
    color: #30ff80;
    text-shadow:
        4px 4px 0 #000,
        -2px -2px 0 #005a2a,
        0 0 18px #30ff80;
    animation: levelPulse 0.9s ease-in-out infinite;
}

@keyframes levelPulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.08); }
}

.bonus-points {
    color: #ffcc00;
    font-size: 22px;
    margin-top: 12px;
    text-shadow:
        3px 3px 0 #000,
        0 0 12px #ffcc00;
    animation: bonusPop 0.6s ease-out;
}

@keyframes bonusPop {
    0%   { transform: scale(0) rotate(-15deg); }
    60%  { transform: scale(1.3) rotate(8deg); }
    100% { transform: scale(1) rotate(0deg); }
}

/* ===== Pantalla de Inicio ===== */
.start-overlay {
    background: rgba(10, 10, 40, 0.92);
}

.start-title {
    color: #ffcc00;
    font-size: 26px;
    letter-spacing: 3px;
    text-shadow:
        4px 4px 0 #000,
        -2px -2px 0 #c04000,
        0 0 18px rgba(255, 130, 0, 0.7);
    animation: titlePulse 1.4s ease-in-out infinite;
}

@keyframes titlePulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.05); }
}

.start-subtitle {
    color: #ff8030;
    font-family: 'Press Start 2P', monospace;
    font-size: 11px;
    letter-spacing: 2px;
    text-shadow: 2px 2px 0 #000;
    margin-top: -8px;
}

.start-controls {
    color: white;
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    line-height: 2.4;
    text-align: center;
    text-shadow: 1px 1px 0 #000;
    letter-spacing: 1px;
    margin: 8px 0;
}

.key-mini {
    display: inline-block;
    background: #2a2a2a;
    border: 2px solid #ffcc00;
    padding: 2px 6px;
    margin: 0 4px;
    color: #ffcc00;
    border-radius: 3px;
    font-size: 9px;
}

/* ===== Pantalla de Pausa ===== */
.pause-overlay {
    background: rgba(0, 0, 0, 0.75);
}

.pause-text {
    color: #00d0ff;
    font-size: 42px;
    letter-spacing: 6px;
    text-shadow:
        4px 4px 0 #000,
        -2px -2px 0 #003a5a,
        0 0 18px #00a0ff;
    animation: pausePulse 1s ease-in-out infinite;
}

@keyframes pausePulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.7; }
}

/* ===== Indicadores de audio (esquina inferior derecha) ===== */
.audio-indicators {
    position: absolute;
    bottom: 8px;
    right: 8px;
    display: flex;
    gap: 8px;
    z-index: 50;
    pointer-events: none;
}

.audio-icon {
    width: 22px;
    height: 22px;
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid #ffcc00;
    border-radius: 3px;
    color: #ffcc00;
    font-size: 14px;
    line-height: 18px;
    text-align: center;
    text-shadow: 0 0 4px #ffcc00;
    transition: all 0.2s;
}

.audio-icon.off {
    color: #555;
    border-color: #444;
    text-shadow: none;
    opacity: 0.5;
    position: relative;
}

.audio-icon.off::after {
    content: '';
    position: absolute;
    top: 50%;
    left: -2px;
    right: -2px;
    height: 2px;
    background: #ff3030;
    transform: rotate(-25deg);
}

/* ===== Panel de instrucciones ===== */
.instructions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 6px 14px;
    color: #ffcc00;
    font-size: 9px;
    margin-top: 14px;
    letter-spacing: 1px;
    line-height: 1;
}

.key {
    display: inline-block;
    background: #2a2a2a;
    border: 2px solid #ffcc00;
    padding: 3px 6px;
    margin: 0 3px 0 0;
    color: white;
    border-radius: 3px;
    font-size: 9px;
}

/* Botón Volver a Jojo Games */
.back-home {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 100;
    padding: 10px 18px;
    background: linear-gradient(135deg, #ff6b9d, #5b8def);
    color: white;
    text-decoration: none;
    font-family: 'Comic Sans MS', 'Trebuchet MS', sans-serif;
    font-weight: bold;
    font-size: 14px;
    border-radius: 50px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s, box-shadow 0.2s;
    border: 2px solid white;
}
.back-home:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

/* ============================================
   MOBILE — controles táctiles + escalado
   ============================================ */

/* Controles ocultos por defecto (desktop) */
.mobile-controls { display: none; }
#rotate-hint { display: none; }

/* JS añade la clase body.is-narrow cuando hay que activar el modo mobile.
   Usamos clase en vez de @media para evitar problemas de cache/timing en file://
   y para tener control unificado desde JS. */
body.is-narrow {
    padding: 4px 0 0 !important;
    min-height: 100vh;
    height: 100vh;
    align-items: stretch !important;
    justify-content: flex-start !important;
    flex-direction: column !important;
    overflow: hidden;
}

body.is-narrow .game-container {
    display: block;
    margin: 0 auto;
    /* JS define width/height para reservar el espacio del transform: scale */
}

body.is-narrow .arcade-frame {
    transform-origin: top left;
    /* transform: scale(...) lo aplica JS */
    margin: 0;
}

body.is-narrow .instructions,
body.is-narrow .start-controls {
    display: none !important;
}

body.is-narrow .overlay-hint {
    font-size: 11px;
    background: rgba(255, 204, 0, 0.15);
    border: 2px solid #ffcc00;
    padding: 10px 18px;
    border-radius: 8px;
}

body.is-narrow .start-overlay,
body.is-narrow .game-over-overlay,
body.is-narrow .pause-overlay {
    cursor: pointer;
}

body.is-narrow .audio-indicators {
    pointer-events: auto;
}
body.is-narrow .audio-icon {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

body.is-narrow .back-home {
    top: 8px; left: 8px;
    padding: 6px 12px;
    font-size: 11px;
}

/* ===== Panel de controles táctiles ===== */
body.is-narrow .mobile-controls {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    gap: 12px;
    margin-top: auto;
    background: linear-gradient(to bottom, transparent, rgba(0,0,0,0.4));
    flex: 0 0 auto;
    touch-action: none;
    width: 100%;
}

body.is-narrow .mc-btn {
    background: linear-gradient(180deg, #4a3a1a, #2a1a08);
    border: 3px solid #ffcc00;
    color: #ffcc00;
    font-family: 'Press Start 2P', monospace;
    font-size: 22px;
    line-height: 1;
    border-radius: 10px;
    box-shadow:
        inset 0 -3px 0 rgba(0,0,0,0.4),
        0 2px 6px rgba(0,0,0,0.4);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: transform 0.06s, box-shadow 0.06s, background 0.06s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
body.is-narrow .mc-btn:active,
body.is-narrow .mc-btn.pressing {
    background: linear-gradient(180deg, #ffcc00, #c08020);
    color: #2a1a08;
    transform: translateY(2px);
    box-shadow:
        inset 0 2px 0 rgba(0,0,0,0.3),
        0 0 12px rgba(255, 204, 0, 0.5);
}

body.is-narrow .mc-dpad {
    display: grid;
    grid-template-columns: 56px 56px 56px;
    grid-template-rows: 56px 56px 56px;
    gap: 6px;
}
body.is-narrow .mc-up    { grid-column: 2; grid-row: 1; }
body.is-narrow .mc-left  { grid-column: 1; grid-row: 2; }
body.is-narrow .mc-right { grid-column: 3; grid-row: 2; }
body.is-narrow .mc-down  { grid-column: 2; grid-row: 3; }

body.is-narrow .mc-hammer {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    font-size: 44px;
    border-width: 4px;
    border-color: #ff6030;
    background: linear-gradient(180deg, #ff8040, #c04010);
    color: white;
    box-shadow:
        inset 0 -4px 0 rgba(0,0,0,0.4),
        0 0 14px rgba(255, 96, 48, 0.6),
        0 4px 10px rgba(0,0,0,0.5);
}
body.is-narrow .mc-hammer:active,
body.is-narrow .mc-hammer.pressing {
    background: linear-gradient(180deg, #ffcc00, #ff6030);
    color: #2a1a08;
    box-shadow:
        inset 0 3px 0 rgba(0,0,0,0.3),
        0 0 24px #ffcc00;
}

/* Pantallas muy chicas */
body.is-narrow.is-tiny .mc-dpad {
    grid-template-columns: 48px 48px 48px;
    grid-template-rows: 48px 48px 48px;
    gap: 4px;
}
body.is-narrow.is-tiny .mc-btn { font-size: 18px; border-width: 2px; }
body.is-narrow.is-tiny .mc-hammer { width: 84px; height: 84px; font-size: 36px; }
body.is-narrow.is-tiny .mobile-controls { padding: 8px 10px; gap: 8px; }

/* ===== HINT: rotar a vertical si el celular está en horizontal ===== */
@media (orientation: landscape) and (pointer: coarse) and (max-height: 500px) {
    #rotate-hint {
        display: flex;
        position: fixed; inset: 0;
        background: linear-gradient(135deg, #1a1a2e 0%, #2d2d5a 60%, #1a1a2e 100%);
        z-index: 9999;
        flex-direction: column;
        align-items: center; justify-content: center;
        padding: 28px;
        text-align: center;
    }
    .rh-phone {
        font-size: 92px;
        line-height: 1;
        margin-bottom: 22px;
        filter: drop-shadow(0 0 22px #ffcc00);
        animation: rhRotate 2.4s ease-in-out infinite;
        transform-origin: center;
    }
    .rh-text {
        font-family: 'Press Start 2P', monospace;
        color: #ffcc00;
        font-size: 22px;
        text-shadow: 3px 3px 0 #000;
        margin-bottom: 12px;
        letter-spacing: 2px;
    }
    .rh-sub {
        font-family: 'Comic Sans MS', 'Trebuchet MS', sans-serif;
        color: #fff;
        font-size: 16px;
        line-height: 1.4;
        opacity: 0.9;
    }
    /* tapar el juego de fondo */
    .arcade-frame, .mobile-controls, .back-home { visibility: hidden; }
}
@keyframes rhRotate {
    0%, 25%   { transform: rotate(-90deg); }
    55%, 100% { transform: rotate(0deg); }
}
