* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    overflow: hidden;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

#game-container {
    position: relative;
    width: 800px;
    height: 600px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
    border-radius: 10px;
    overflow: hidden;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    background: linear-gradient(180deg, #1a5f7a 0%, #002b5c 100%);
}

#score-container {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 10;
    background: rgba(0, 0, 0, 0.6);
    padding: 15px 20px;
    border-radius: 10px;
    color: white;
    font-size: 18px;
    font-weight: bold;
    text-align: right;
    min-width: 150px;
}

#level {
    margin-bottom: 5px;
}

#lives {
    margin-bottom: 5px;
    color: #ff69b4;
}

#record {
    color: #ffcc00;
    font-size: 16px;
}

#start-screen, #game-over-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    z-index: 100;
}

#start-screen h1, #game-over-screen h1 {
    font-size: 60px;
    margin-bottom: 30px;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.5);
}

#start-screen p, #game-over-screen p {
    font-size: 20px;
    margin: 10px 0;
    color: #aed9e0;
}

#start-button, #restart-button {
    margin-top: 30px;
    padding: 15px 40px;
    font-size: 24px;
    font-weight: bold;
    color: white;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

#start-button:hover, #restart-button:hover {
    transform: scale(1.05);
    box-shadow: 0 7px 20px rgba(0, 0, 0, 0.4);
}

#start-button:active, #restart-button:active {
    transform: scale(0.95);
}

#final-level {
    color: #00ff88;
    font-size: 24px;
    font-weight: bold;
}

#new-record {
    animation: pulse 1s infinite;
}

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

/* Controles móviles */
#mobile-controls {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    pointer-events: auto;
}

#controls-grid {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.control-row {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
}

.control-spacer {
    width: 70px;
}

.direction-btn {
    width: 70px;
    height: 70px;
    background: rgba(255, 255, 255, 0.9);
    border: 3px solid #333;
    border-radius: 15px;
    font-size: 32px;
    font-weight: bold;
    color: #333;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    transition: all 0.1s;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
}

.direction-btn:active {
    background: rgba(102, 126, 234, 0.9);
    color: white;
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.mobile-only {
    display: none;
}

.desktop-only {
    display: block;
}

/* Responsive */
@media (max-width: 850px) {
    #game-container {
        width: 100vw;
        height: 100vh;
        height: 100dvh; /* Usa altura dinámica del viewport para móviles */
        border-radius: 0;
        position: fixed;
        top: 0;
        left: 0;
    }
    
    #score-container {
        top: 10px;
        right: 10px;
        padding: 10px 15px;
        font-size: 14px;
        min-width: 120px;
    }
    
    #record {
        font-size: 13px;
    }
    
    #start-screen h1, #game-over-screen h1 {
        font-size: 48px;
    }
    
    #start-screen p, #game-over-screen p {
        font-size: 16px;
        padding: 0 20px;
        text-align: center;
    }
    
    #start-button, #restart-button {
        padding: 12px 35px;
        font-size: 20px;
        margin-top: 20px;
    }
    
    .mobile-only {
        display: block;
    }
    
    .desktop-only {
        display: none;
    }

    #mobile-controls {
        bottom: 60px;
    }

    .direction-btn {
        width: 65px;
        height: 65px;
        font-size: 28px;
    }

    .control-spacer {
        width: 65px;
    }
}

@media (max-width: 480px) {
    #score-container {
        font-size: 12px;
        padding: 8px 12px;
        min-width: 100px;
        top: max(10px, env(safe-area-inset-top));
        right: max(10px, env(safe-area-inset-right));
    }
    
    #start-screen h1, #game-over-screen h1 {
        font-size: 40px;
    }
    
    #start-screen p, #game-over-screen p {
        font-size: 14px;
    }

    #mobile-controls {
        bottom: max(50px, calc(env(safe-area-inset-bottom) + 20px));
    }

    .direction-btn {
        width: 55px;
        height: 55px;
        font-size: 24px;
    }

    .control-spacer {
        width: 55px;
    }

    #controls-grid {
        gap: 6px;
    }

    .control-row {
        gap: 6px;
    }
}
