* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    /* Fondo gradiente: de un violeta espacial en el centro hacia negro puro en los bordes */
    background: radial-gradient(circle at center, #2a0845 0%, #000000 80%);
    overflow: hidden;
    font-family: monospace;
    touch-action: none; /* Previene scroll y zoom táctil en mobile */
    user-select: none;
}
canvas { display: block; }

#canvas-container {
    cursor: none;
    position: relative;
    /* Aseguramos que el contenedor del juego sea de cristal */
    background: transparent;
}

/* --- PANTALLA DE INTRODUCCIÓN Y CARGA --- */
#loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: url('intro1.webp') no-repeat center center;
    background-size: contain;
    background-color: #050505;
    z-index: 99999; /* Tapa absolutamente todo */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease;
}

.intro-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    margin-top: 150px;
    margin-bottom: -80px;
}

#intro-play-btn {
    width: 350px;
    cursor: pointer;
    transition: transform 0.2s, filter 0.2s;
}

#intro-play-btn:hover { transform: scale(1.05); filter: drop-shadow(0 0 15px #00ffff); }

.intro-lower-buttons { display: flex; gap: 20px; align-items: center; }

.intro-btn {
    width: 250px;
    cursor: pointer;
    transition: transform 0.2s;
}
.intro-btn:hover { transform: scale(1.05); }

.btn1-wrapper { position: relative; }
#intro-btn-0 {
    position: absolute;
    bottom: -20px;
    left: -20px;
    width: 80px;
    cursor: pointer;
    z-index: 10;
    transition: transform 0.2s;
}
#intro-btn-0:hover { transform: scale(1.1) rotate(-10deg); }

.loading-ui { position: absolute; bottom: 30px; display: flex; flex-direction: column; align-items: center; }
#loading-bar-wrap { width: 280px; height: 3px; background: rgba(100,170,255,0.15); border-radius: 2px; overflow: hidden; }
#loading-bar { height: 100%; width: 0%; background: linear-gradient(90deg, #4af, #aff); transition: width 0.2s ease; box-shadow: 0 0 12px #4af; }
#loading-status { margin-top: 12px; font-size: 11px; color: rgba(100,200,255,0.5); letter-spacing: 2px; text-shadow: 0 0 5px #000; }

/* --- HUD y Textos --- */
#aim-reticle { display: none; position: fixed; width: 48px; height: 48px; transform: translate(-50%, -50%); pointer-events: none; z-index: 10000; }
#aim-reticle .center-dot { position: absolute; width: 4px; height: 4px; background: #00ffff; border-radius: 50%; top: 50%; left: 50%; transform: translate(-50%, -50%); box-shadow: 0 0 10px #00ffff; }
#aim-reticle .outer-ring { position: absolute; width: 100%; height: 100%; border: 2px solid rgba(0,255,255,0.4); border-radius: 50%; }
#aim-reticle .crosshair { position: absolute; background: rgba(0,255,255,0.6); box-shadow: 0 0 8px #00ffff; }
#aim-reticle .crosshair.v { width: 2px; height: 12px; left: 50%; transform: translateX(-50%); }
#aim-reticle .crosshair.v.top { top: 0; }
#aim-reticle .crosshair.v.bottom { bottom: 0; }
#aim-reticle .crosshair.h { height: 2px; width: 12px; top: 50%; transform: translateY(-50%); }
#aim-reticle .crosshair.h.left { left: 0; }
#aim-reticle .crosshair.h.right { right: 0; }

#shop-container, #shop-header, .shop-btn, .arrow { cursor: none !important; }

#aim-reticle.aim-neon .center-dot, #aim-reticle.aim-neon .outer-ring, #aim-reticle.aim-neon .crosshair { display: none !important; }
#aim-reticle.aim-neon { width: 0; height: 0; border-left: 10px solid transparent; border-right: 10px solid transparent; border-bottom: 20px solid #00ffcc; background: transparent; border-top: none; filter: drop-shadow(0 0 10px #00ffcc); transform: translate(-50%, -50%) rotate(180deg); }

#hud { position: fixed; top: 0; left: 0; right: 0; padding: 16px 24px; pointer-events: none; z-index: 10; }
#money-display { position: fixed; left: 2%; top: 2%; letter-spacing: 3px; font-size: 15px; color: #c9c9c9; text-shadow: 0 0 10px #c9c9c9; }
#game-clock { position: fixed; left: 2%; top: 5%; letter-spacing: 2px; font-size: 14px; color: #c9c9c9; text-shadow: 0 0 5px #c9c9c9; }

#event-announcer { position: fixed; top: 15%; left: 50%; transform: translateX(-50%); color: #ff00ff; font-size: 24px; letter-spacing: 5px; text-transform: uppercase; text-shadow: 0 0 15px #ff00ff; opacity: 0; transition: opacity 1s ease-in-out; pointer-events: none; z-index: 100; }
#restricted-warning { display: none; position: fixed; top: 30%; left: 50%; transform: translateX(-50%); color: #ff0000; font-size: 20px; letter-spacing: 3px; font-weight: bold; background: rgba(20, 0, 0, 0.85); padding: 15px 30px; border: 2px solid #ff0000; border-radius: 5px; text-transform: uppercase; text-shadow: 0 0 10px #ff0000; box-shadow: 0 0 20px rgba(255, 0, 0, 0.4); pointer-events: none; z-index: 1000; text-align: center; }
#controls-hint { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); color: rgba(180,220,255,0.6); font-size: 12px; letter-spacing: 3px; text-transform: uppercase; pointer-events: none; z-index: 10; }

/* --- NUEVA TIENDA RETRO SCI-FI --- */
#shop-container {
    position: fixed;
    right: 20px;
    top: 20px;
    width: 320px;
    z-index: 20;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    background-image: url('hud1.webp');
    background-repeat: no-repeat;
    background-position: top right;
    background-size: contain;
}

#shop-header {
    color: #eabd63;
    position: relative;
    z-index: 2;
    font-family: monospace;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    text-shadow: 0 0 5px #eabd63, 0 0 10px #a65329;
    user-select: none;
    padding: 15px 35px 10px 10px;
    text-align: left;
}

#shop-content {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 0px;
    margin-left: -5px;
    z-index: 1;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-in-out, padding 0.4s ease-in-out;
}

#shop-container.abierto #shop-content {
    max-height: 800px;
    padding: 20px 10px 100px -35px;
}

#shop-content::before {
    content: '';
    position: absolute;
    top: -100px;
    left: 0px;
    width: 100%;
    height: 150%;
    background-image: url('hud2.webp');
    background-repeat: no-repeat;
    background-size: 85% auto;
    background-position: left top;
    opacity: 0.10;
    z-index: -1;
}

.shop-item-container {
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(234, 189, 99, 0.3);
    margin-bottom: 2px;
    width: 280px;
}

.shop-item-row { display: flex; align-items: center; gap: 5px; padding: 5px; }
.shop-btn { background: rgba(234, 189, 99, 0.05); border: 1px solid rgba(234, 189, 99, 0.3); color: #c9c9c9; padding: 10px; cursor: pointer; font-family: monospace; text-align: left; flex-grow: 1; }
.shop-btn:hover { background: rgba(234, 189, 99, 0.2); }
.price { float: right; color: #eabd63; }
.arrow { cursor: pointer; color: #a65329; font-size: 18px; padding: 5px 10px; user-select: none; transition: transform 0.3s ease, color 0.2s; }
.arrow:hover { color: #eabd63; text-shadow: 0 0 8px #eabd63; }
.arrow.rotated { transform: rotate(90deg); }
.shop-description { max-height: 0; overflow: hidden; transition: max-height 0.5s ease-in-out, padding-bottom 0.5s ease-in-out; font-size: 11px; color: #eabd63; padding: 0 10px; line-height: 1.4; }
.shop-description.open { max-height: 80px; padding-bottom: 10px; }

.turret-loader-container { position: fixed; width: 60px; height: 6px; background: rgba(0, 0, 0, 0.5); border: 1px solid #00ffff; pointer-events: none; display: flex; align-items: center; }
.turret-loader-bar { width: 0%; height: 100%; background: #ff00ff; box-shadow: 0 0 5px #ff00ff; }
.turret-spinner { position: absolute; right: -15px; width: 10px; height: 10px; border: 2px solid rgba(255, 0, 255, 0.3); border-top: 2px solid #ff00ff; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.spinning { display: block !important; }
.repair-hint { color: #ff0000; font-family: 'Orbitron', sans-serif; font-size: 10px; font-weight: bold; text-shadow: 0 0 5px #ff0000; margin-bottom: 5px; text-align: center; display: none; animation: blink 0.8s infinite; }
@keyframes blink { 0% { opacity: 1; } 50% { opacity: 0.3; } 100% { opacity: 1; } }

.special-btn { color: #ffd700; border: 1px solid rgba(255, 215, 0, 0.5); }
.special-btn:hover { background: rgba(255, 215, 0, 0.2); box-shadow: 0 0 10px rgba(255, 215, 0, 0.5); }
.win-btn { color: #00ff00; border: 1px solid rgba(0, 255, 0, 0.5); animation: pulse-green 2s infinite; }
.win-btn:hover { background: rgba(0, 255, 0, 0.2); }
@keyframes pulse-green { 0% { box-shadow: 0 0 0px rgba(0, 255, 0, 0); } 50% { box-shadow: 0 0 15px rgba(0, 255, 0, 0.8); } 100% { box-shadow: 0 0 0px rgba(0, 255, 0, 0); } }

#master-container { position: fixed; left: 20px; bottom: 20px; width: 220px; z-index: 999999; pointer-events: auto; }
#master-header { cursor: pointer; color: #592911; border: 1px solid #592911; padding: 10px; background: rgba(0,0,0,0.8); text-align: center; text-transform: uppercase; letter-spacing: 2px; font-size: 12px; }
#master-items { display: none; flex-direction: column; gap: 15px; margin-bottom: 5px; background: rgba(0, 0, 0, 0.9); border: 1px solid #a65329; padding: 15px; }
.control-group { display: flex; flex-direction: column; gap: 5px; }
.control-group label { color: #a65329; font-size: 10px; letter-spacing: 1px; font-weight: bold; }
input[type=range] { -webkit-appearance: none; background: #a65329; height: 4px; border-radius: 2px; outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; background: #592911; border-radius: 50%; cursor: pointer; box-shadow: 0 0 5px #592911; }

#country-select::-webkit-scrollbar { width: 8px; }
#country-select::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.8); border-left: 1px solid #c9c9c9; }
#country-select::-webkit-scrollbar-thumb { background: #c9c9c9; border-radius: 4px; }
#country-select::-webkit-scrollbar-thumb:hover { background: #c9c9c9; }

#username-input, #intro-country-select {
    background: rgba(0, 255, 255, 0.05);
    border: 1px solid rgba(0, 255, 255, 0.5);
    color: #00ffff;
    font-family: monospace;
    outline: none;
    cursor: pointer;
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.2), inset 0 0 10px rgba(0, 255, 255, 0.1);
    transition: all 0.3s ease;
}

#username-input {
    font-size: 16px;
    padding: 12px 20px;
    text-align: center;
    text-transform: uppercase;
    width: 320px;
    border-left: 6px solid #00ffff;
    border-right: 6px solid #00ffff;
}

#username-input:focus, #intro-country-select:focus, #hud-country-select:focus {
    background: rgba(0, 255, 255, 0.15);
    border-color: #00ffff;
    box-shadow: 0 0 25px rgba(0, 255, 255, 0.6), inset 0 0 15px rgba(0, 255, 255, 0.3);
}

#username-input::placeholder { color: rgba(0, 255, 255, 0.4); letter-spacing: 2px; }

#intro-country-select option, #hud-country-select option {
    background: #050505; color: #00ffff; font-family: monospace;
}

#intro-country-container {
    display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 10px;
}

#intro-country-container label {
    color: #eabd63; font-family: monospace; font-size: 12px; letter-spacing: 3px; text-shadow: 0 0 5px #00ffff;
}

#hud-country-container {
    position: fixed;
    left: 2%;
    top: 13%;
    display: flex;
    align-items: center;
    gap: 15px;
    z-index: 10;
    pointer-events: auto;
}

#hud-country-container label {
    color: #eabd63;
    font-family: monospace;
    font-size: 14px;
    letter-spacing: 2px;
    text-shadow: 0 0 5px #eabd63;
}

#hud-country-select {
    width: 200px;
    color: #eabd63;
    padding: 5px 10px;
    font-size: 14px;
    border-left: 3px solid #eabd63;
    border-right: 3px solid #eabd63;
    background: rgba(0, 0, 0, 0.8);
}

#hud-country-select:focus {
    border-color: #eabd63;
    color: #eabd63;
    box-shadow: 0 0 15px rgba(234, 189, 99, 0.4);
}

#hud-country-select option {
    background: #050505;
    color: #eabd63;
    font-family: monospace;
}

#player-name-display {
    position: fixed;
    left: 2%;
    top: 8%;
    letter-spacing: 2px;
    font-size: 14px;
    color: #c9c9c9;
    text-shadow: 0 0 5px #c9c9c9;
}

#subtitles {
    position: fixed;
    bottom: 20%;
    left: 50%;
    transform: translateX(-50%);
    color: #ffea00;
    font-size: 18px;
    font-family: monospace;
    text-align: center;
    letter-spacing: 2px;
    width: 80%;
    max-width: 800px;
    text-shadow: 2px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 0 0 15px rgba(0,0,0,0.8);
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#mobile-controls {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 9999;
}

.joystick-zone {
    position: absolute;
    bottom: 20px;
    width: 150px;
    height: 150px;
    pointer-events: auto;
}

#joystick-left { left: 20px; }

.joystick-base {
    position: absolute;
    bottom: 25px;
    left: 25px;
    width: 100px;
    height: 100px;
    background: rgba(0, 255, 255, 0.1);
    border: 2px solid rgba(0, 255, 255, 0.5);
    border-radius: 50%;
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.2);
    display: flex;
    justify-content: center;
    align-items: center;
}

.joystick-stick {
    width: 40px;
    height: 40px;
    background: rgba(0, 255, 255, 0.6);
    border-radius: 50%;
    box-shadow: 0 0 10px #00ffff;
    position: absolute;
    transform: translate(0px, 0px);
}

#mobile-actions-diamond {
    position: absolute;
    bottom: 30px;
    right: 30px;
    display: grid;
    grid-template-columns: 60px 60px 60px;
    grid-template-rows: 60px 60px 60px;
    pointer-events: auto;
}

#btn-c { grid-column: 2; grid-row: 1; }
#btn-d { grid-column: 1; grid-row: 2; }
#btn-b { grid-column: 3; grid-row: 2; }
#btn-a { grid-column: 2; grid-row: 3; }

.mobile-btn-round {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid #00ffff;
    color: #00ffff;
    font-family: monospace;
    font-size: 18px;
    font-weight: bold;
    text-shadow: 0 0 5px #00ffff;
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.2);
    outline: none;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: auto;
    transition: all 0.1s ease;
}

.mobile-btn-round:active {
    background: rgba(0, 255, 255, 0.3);
    transform: scale(0.9);
}

/* --- RESPONSIVE / MOBILE VIEW (VERTICAL / PORTRAIT) --- */
@media (max-width: 768px) and (orientation: portrait) {
    #mobile-controls { display: block; }
    #controls-hint { display: none !important; }
    #aim-reticle { display: none !important; }

    #loading {
        background-image: url('LunarShots-vertical.webp');
        background-size: cover;
        background-position: center;
    }

    .intro-content {
        margin-top: 50px;
        transform: none;
    }

    #intro-play-btn { width: 175px; }
    .intro-btn { width: 125px; }
    #intro-btn-0 { width: 40px; bottom: -10px; left: -10px; }

    #money-display { font-size: 12px; top: 3%; }
    #game-clock { font-size: 11px; top: 7%; }
    #player-name-display { font-size: 11px; top: 11%; }

    #hud-country-container {
        top: 15%;
        transform: scale(0.8);
        transform-origin: left top;
    }

    #shop-container {
        transform: scale(0.7);
        transform-origin: top right;
        right: 10px;
        top: 10px;
    }

    #master-container {
        transform: scale(0.7);
        transform-origin: top left;
        left: 10px;
        top: 25%;
        bottom: auto;
    }

    #subtitles {
        font-size: 14px;
        bottom: 25%;
    }
}

/* --- RESPONSIVE / MOBILE VIEW (HORIZONTAL / LANDSCAPE) --- */
@media (max-width: 950px) and (orientation: landscape) {
    #mobile-controls { display: block; }
    #controls-hint { display: none !important; }
    #aim-reticle { display: none !important; }

    #loading {
        background-image: url('intro1.webp');
        background-size: cover;
        background-position: center;
    }

    .intro-content {
        margin-top: 10px;
        transform: scale(0.65);
    }

    /* Achicar botones a la mitad también en landscape */
    #intro-play-btn { width: 175px; }
    .intro-btn { width: 125px; }
    #intro-btn-0 { width: 40px; bottom: -10px; left: -10px; }

    /* Controles más a los bordes */
    .joystick-zone { bottom: 5px; }
    #joystick-left { left: 10px; }

    #mobile-actions-diamond {
        bottom: 10px;
        right: 10px;
        transform: scale(0.85);
        transform-origin: bottom right;
    }

    /* HUD más compacto */
    #money-display { font-size: 11px; top: 3%; }
    #game-clock { font-size: 10px; top: 9%; }
    #player-name-display { font-size: 10px; top: 15%; }

    #hud-country-container {
        top: 22%;
        transform: scale(0.7);
        transform-origin: left top;
    }

    /* Tienda y Settings adaptados a la poca altura */
    #shop-container {
        transform: scale(0.55);
        transform-origin: top right;
        right: 5px;
        top: 5px;
    }

    #master-container {
        transform: scale(0.55);
        transform-origin: top left;
        left: 5px;
        top: 35%;
        bottom: auto;
    }

    #subtitles {
        font-size: 13px;
        bottom: 15%;
    }
}
