* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; }
body { background-color: #020617; color: #ffffff; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; overflow: hidden; }

#game-container { 
    position: relative; 
    width: 100%; 
    max-width: 420px; 
    height: 100dvh; 
    max-height: 640px; 
    aspect-ratio: 420 / 640;
    background: #0f172a; 
    box-shadow: 0 25px 35px -5px rgb(0 0 0 / 0.9); 
    overflow: hidden; 
    border-radius: 20px; 
    border: 3px solid #334155; 
}

canvas { display: block; width: 100%; height: 100%; background: #090d16; touch-action: none; transition: background 1s ease; }
.ui-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; flex-direction: column; pointer-events: none; }

.header-score { 
    position: relative;
    z-index: 100; /* Eleva la capa superior para que el botón de pausa nunca quede cubierto por botones arrastrables */
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    font-size: 0.8rem; 
    font-weight: 800; 
    text-shadow: 0 2px 4px rgba(0,0,0,0.8); 
    background: rgba(15, 23, 42, 0.85); 
    padding: 6px 10px; 
    border-radius: 12px; 
    margin: 12px; 
    border: 1px solid rgba(255,255,255,0.15); 
    pointer-events: auto; 
}
.header-left { display: flex; flex-direction: column; gap: 2px; }
.header-right { display: flex; align-items: center; gap: 8px; }
#trophiesVal { margin-left: 2px; letter-spacing: 1px; display: inline-flex; align-items: center; gap: 2px; }

/* Marcadores compactos que se leen bien encima del menú espacial y en partida. */
.header-score {
    margin: calc(env(safe-area-inset-top, 0px) + 8px) 10px 0;
    min-height: 58px;
    padding: 7px 10px;
    border-color: rgba(103, 232, 249, 0.52);
    background: linear-gradient(135deg, rgba(4, 18, 56, 0.88), rgba(11, 28, 78, 0.82));
    box-shadow: 0 0 13px rgba(34, 211, 238, 0.24), 0 5px 10px rgba(0, 0, 0, 0.35);
}
.header-left { gap: 4px; }
.header-left > div {
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    font-size: 0.96rem;
}
#livesVal, .header-right .icon-btn {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border: 1px solid rgba(186, 241, 255, 0.25);
    border-radius: 12px;
    background: rgba(2, 11, 39, 0.52);
}
.header-right .icon-btn { color: #dffcff; line-height: 1; font-size: 1.45rem; }

.draggable-btn { position: absolute; width: 45px; height: 45px; background: rgba(15, 23, 42, 0.65); backdrop-filter: blur(4px); border: 2px solid rgba(56, 189, 248, 0.5); border-radius: 50%; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: auto; touch-action: none; z-index: 20; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5); transition: transform 0.08s; cursor: pointer; }
.draggable-btn:active:not(.paused) { transform: scale(0.9); }
.draggable-btn.paused { border: 2px dashed #fbbf24; background: rgba(15, 23, 42, 0.85); box-shadow: 0 0 15px rgba(251, 191, 36, 0.5); animation: pulsePause 1.5s infinite; }
@keyframes pulsePause { 0% { transform: scale(1); } 50% { transform: scale(1.1); } 100% { transform: scale(1); } }

.hud-cost { position: absolute; top: -4px; right: -4px; background: #b91c1c; color: white; font-size: 0.55rem; font-weight: bold; padding: 1px 4px; border-radius: 8px; border: 1px solid #fee2e2; box-shadow: 0 2px 4px rgba(0,0,0,0.5); }
.hud-emoji { font-size: 1.1rem; line-height: 1; margin-top: 2px; }
.hud-lvl { font-size: 0.5rem; font-weight: 800; color: #e2e8f0; margin-top: 0; }

#fireBtn { background: linear-gradient(135deg, rgba(239, 68, 68, 0.75), rgba(185, 28, 28, 0.75)); border-color: rgba(254, 226, 226, 0.6); width: 65px; height: 65px; }
#fireBtn .hud-emoji { font-size: 1.6rem; margin-top: 0; }

#missileBtn { background: linear-gradient(135deg, rgba(245, 158, 11, 0.75), rgba(180, 83, 9, 0.75)); width: 55px; height: 55px; }
#missileBtn .hud-emoji { font-size: 1.4rem; margin-top: -8px; }
.missile-ready { animation: glowUpgrade 1.2s infinite !important; border-color: #fcd34d !important; }

#activeTutorialOverlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); z-index: 15; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px; pointer-events: auto; }
#activeTutorialText { background: rgba(15, 23, 42, 0.95); border: 2px solid #38bdf8; padding: 16px; border-radius: 12px; color: #fff; font-size: 1.05rem; font-weight: bold; box-shadow: 0 0 20px rgba(56, 189, 248, 0.6); max-width: 320px; margin-bottom: 20px; text-shadow: 0 2px 4px rgba(0,0,0,0.8); }
.tutorial-highlight { z-index: 100 !important; animation: superGlow 1s infinite alternate !important; pointer-events: auto !important; border-color: #38bdf8 !important; }
@keyframes superGlow { from { box-shadow: 0 0 10px #38bdf8, 0 0 20px #38bdf8; transform: scale(1.05); } to { box-shadow: 0 0 20px #38bdf8, 0 0 40px #38bdf8; transform: scale(1.15); } }

.screen-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(9, 13, 22, 0.96); display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; pointer-events: auto; z-index: 10; }
.screen-overlay h1 { font-size: 1.6rem; color: #38bdf8; margin-bottom: 8px; }
.screen-overlay p { color: #94a3b8; font-size: 0.85rem; margin-bottom: 14px; line-height: 1.3; }

/* Menú principal: utiliza el mismo fondo de la ronda 3 sin modificar el juego. */
.main-menu {
    justify-content: flex-start;
    padding: calc(env(safe-area-inset-top, 0px) + clamp(76px, 8.5vh, 90px)) max(14px, env(safe-area-inset-right, 14px)) calc(env(safe-area-inset-bottom, 0px) + 12px) max(14px, env(safe-area-inset-left, 14px));
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(2, 7, 30, 0.28) 0%, rgba(2, 8, 28, 0.1) 42%, rgba(2, 5, 21, 0.66) 100%),
        url('assets/fondo_ronda3.png') center / cover no-repeat;
}
.main-menu::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(ellipse at 50% 38%, rgba(34, 211, 238, 0.22), transparent 34%), linear-gradient(90deg, rgba(4, 8, 28, 0.25), transparent 20%, transparent 80%, rgba(4, 8, 28, 0.25));
}
.main-menu-content {
    position: relative;
    z-index: 1;
    width: min(100%, 400px);
    height: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    gap: clamp(4px, 0.8vh, 9px);
}
.menu-logo {
    position: relative;
    z-index: 2;
    display: block;
    width: min(76vw, 285px);
    max-width: 88%;
    max-height: clamp(104px, 16vh, 128px);
    height: auto;
    margin-bottom: 2px;
    object-fit: contain;
    transform: translateY(-4px);
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.55));
}
@media (min-width: 601px) {
    .menu-logo { width: 155px; max-height: 78px; }
}
.menu-ship {
    width: min(54vw, 235px);
    max-height: clamp(112px, 17vh, 150px);
    object-fit: contain;
    filter: drop-shadow(0 0 13px rgba(71, 225, 255, 0.96)) drop-shadow(0 0 26px rgba(39, 149, 255, 0.58)) drop-shadow(0 12px 9px rgba(0, 0, 0, 0.7));
    animation: menuShipFloat 3.2s ease-in-out infinite;
}
@keyframes menuShipFloat { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-8px) scale(1.025); } }
.menu-tagline { display: none; }
.menu-victory-message { display: none; margin: -3px 0 0 !important; color: #ffe766 !important; font-size: 0.77rem !important; font-weight: 900; text-shadow: 0 2px 4px #020617; }
.menu-victory-message.show { display: block; }
.menu-primary-actions, #superBossSlot, .menu-two-actions, .menu-mini-actions { width: 100%; }
.menu-primary-actions { display: grid; gap: clamp(5px, 0.8vh, 9px); }
.menu-two-actions { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(8px, 2.2vw, 12px); }
#startScreen .menu-btn, #startScreen .menu-mini-btn {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    width: 100%;
    max-width: none;
    margin: 0;
    color: #fff;
    border: 2px solid #75eaff;
    border-radius: 18px;
    background: linear-gradient(135deg, rgba(13, 66, 140, 0.96), rgba(11, 22, 86, 0.96));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.36), 0 0 13px rgba(34, 211, 238, 0.48), 0 6px 9px rgba(0, 0, 0, 0.45);
    text-shadow: 0 2px 3px rgba(0, 0, 0, 0.75);
}
.menu-btn::before, .menu-mini-btn::before { content: ''; position: absolute; inset: 2px; z-index: -1; border-radius: inherit; background: linear-gradient(120deg, rgba(255, 255, 255, 0.2), transparent 35%); }
#startScreen .menu-btn:active, #startScreen .menu-mini-btn:active { transform: scale(0.97); }
#startScreen .menu-btn { min-height: clamp(42px, 6.2vh, 52px); padding: 7px 13px; font-size: clamp(0.9rem, 3.8vw, 1.2rem); font-weight: 900; }
.menu-btn-icon { flex: 0 0 auto; font-size: 1.35em; line-height: 1; filter: drop-shadow(0 2px 2px rgba(0,0,0,0.55)); }
.menu-btn-arrow { margin-left: auto; font-size: 2em; font-weight: 400; line-height: 0.55; color: #dffbff; }
.menu-btn-label { display: flex; flex-direction: column; align-items: flex-start; line-height: 0.9; text-align: left; }
.menu-btn-label small { margin-top: 3px; color: #e6f8ff; font-size: 0.67em; font-weight: 800; }
#startScreen .menu-btn-launch { min-height: clamp(54px, 7.6vh, 64px); border-color: #ffe871; background: linear-gradient(135deg, #ffba12, #f36d12); box-shadow: inset 0 1px 0 rgba(255,255,255,0.65), 0 0 17px rgba(255, 162, 23, 0.75), 0 7px 10px rgba(0,0,0,0.5); font-size: clamp(1.22rem, 5.5vw, 1.65rem); }
.menu-btn-launch .menu-btn-icon { font-size: 1.25em; }
#superBossModeBtn { min-height: clamp(46px, 6.5vh, 52px); justify-content: flex-start; border-color: #d9aeff; background: linear-gradient(135deg, rgba(66, 42, 128, 0.98), rgba(23, 24, 76, 0.98)); box-shadow: inset 0 1px 0 rgba(255,255,255,0.32), 0 0 13px rgba(190, 129, 255, 0.65), 0 6px 9px rgba(0,0,0,0.46); }
#superBossModeBtn .menu-btn-label b { color: #ffe75f; font-size: 0.82em; }
#startScreen .menu-btn-hangar { border-color: #38e8ff; background: linear-gradient(135deg, #075db3, #0d2a73); }
#startScreen .menu-btn-shop { border-color: #48f0b8; background: linear-gradient(135deg, #098d73, #075148); }
#startScreen .menu-btn-tutorial { min-height: clamp(42px, 5.8vh, 48px); }
.menu-mini-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
#startScreen .menu-mini-btn { min-height: clamp(50px, 7vh, 55px); flex-direction: column; gap: 2px; padding: 6px 3px; border-radius: 15px; font-size: clamp(1.35rem, 5vw, 1.8rem); }
.menu-mini-btn small { color: #e9fbff; font-size: clamp(0.56rem, 2.25vw, 0.72rem); font-weight: 800; }

@media (max-height: 700px) {
    .main-menu { padding-top: calc(env(safe-area-inset-top, 0px) + 72px); }
    .menu-logo { max-height: 98px; width: min(64vw, 220px); }
    .menu-ship { max-height: 110px; width: min(46vw, 195px); }
    .menu-tagline { display: none; }
    .menu-victory-message { font-size: 0.66rem !important; }
    #startScreen .menu-btn { min-height: 39px; border-radius: 14px; }
    #startScreen .menu-btn-launch { min-height: 50px; }
    #superBossModeBtn { min-height: 43px; }
    #startScreen .menu-mini-btn { min-height: 48px; }
}

.btn { background-color: #38bdf8; color: #0f172a; border: none; padding: 10px 24px; font-size: 0.95rem; font-weight: 700; border-radius: 12px; cursor: pointer; box-shadow: 0 4px 12px rgba(56, 189, 248, 0.3); transition: transform 0.1s; width: 100%; max-width: 200px; margin-bottom: 8px; }
.btn.btn-secondary { background-color: #1e293b; color: #e2e8f0; border: 1px solid #38bdf8; box-shadow: none; }
.btn:active { transform: scale(0.95); }
.btn:disabled { background-color: #475569; color: #94a3b8; box-shadow: none; transform: none; cursor: not-allowed; }

.leaderboard-box { background: rgba(15, 23, 42, 0.8); border: 1px solid rgba(56, 189, 248, 0.2); border-radius: 10px; padding: 8px 16px; margin-bottom: 14px; width: 100%; max-width: 260px; text-align: left; }
.leaderboard-box h3 { font-size: 0.9rem; color: #fbbf24; margin-bottom: 4px; text-align: center; }
.lb-row { display: flex; justify-content: space-between; font-size: 0.8rem; color: #cbd5e1; padding: 2px 0; border-bottom: 1px dashed rgba(255,255,255,0.05); }

.initials-input-container { display: flex; gap: 8px; margin-bottom: 12px; justify-content: center; align-items: center; }
.initials-input-container input { background: #1e293b; border: 2px solid #38bdf8; color: #fff; font-size: 1.2rem; text-align: center; width: 60px; padding: 6px; border-radius: 8px; text-transform: uppercase; }
.icon-btn { background: none; border: none; font-size: 1.2rem; cursor: pointer; padding: 0 6px; pointer-events: auto; }

.trophy-rack { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-items: center; margin-bottom: 15px; width: 100%; }
.trophy-item { position: relative; width: 60px; height: 60px; background: rgba(15, 23, 42, 0.8); border: 2px solid #334155; border-radius: 12px; display: flex; justify-content: center; align-items: center; cursor: pointer; transition: transform 0.1s, border-color 0.2s; }
.trophy-item:active { transform: scale(0.9); }
.trophy-item.selected { border-color: #38bdf8; background: rgba(56, 189, 248, 0.2); }
.trophy-img { width: 40px; height: 40px; object-fit: contain; position: relative; z-index: 2; transition: filter 0.3s; }
.trophy-locked { filter: grayscale(100%) opacity(30%); }
.trophy-unlocked { filter: drop-shadow(0 0 6px rgba(251, 191, 36, 0.9)); }
.trophy-emoji-fallback { position: absolute; font-size: 1.6rem; z-index: 1; opacity: 0.5; transition: filter 0.3s; }

.achievements-list { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 300px; max-height: 250px; overflow-y: auto; padding-right: 4px; margin-bottom: 10px; }
.achievements-list::-webkit-scrollbar { width: 6px; }
.achievements-list::-webkit-scrollbar-track { background: #0f172a; border-radius: 4px; }
.achievements-list::-webkit-scrollbar-thumb { background: #38bdf8; border-radius: 4px; }

.achiev-item { padding: 10px; background: rgba(15, 23, 42, 0.8); border: 2px solid #334155; border-radius: 8px; font-size: 0.9rem; font-weight: bold; color: #94a3b8; cursor: pointer; text-align: left; transition: all 0.2s; display: flex; align-items: center; gap: 8px; }
.achiev-item:active { transform: scale(0.98); }
.achiev-item.unlocked { border-color: #fbbf24; color: #fbbf24; background: rgba(251, 191, 36, 0.1); box-shadow: 0 0 8px rgba(251, 191, 36, 0.3); }
.achiev-item.selected { background: rgba(56, 189, 248, 0.2); border-color: #38bdf8; color: #fff; }

#achievToast { position: absolute; top: -120px; left: 50%; transform: translateX(-50%); background: rgba(15, 23, 42, 0.95); border: 2px solid #fbbf24; padding: 10px 20px; border-radius: 12px; z-index: 130; text-align: center; box-shadow: 0 4px 15px rgba(251, 191, 36, 0.4); transition: top 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); pointer-events: none; }
#achievToast.show { top: calc(env(safe-area-inset-top, 0px) + 78px); }

.pause-shop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; max-width: 260px; margin-bottom: 16px; }
.pause-shop-btn { background: #1e293b; border: 1px solid #38bdf8; border-radius: 8px; padding: 6px; color: #fff; font-size: 0.75rem; font-weight: bold; cursor: pointer; display: flex; flex-direction: column; align-items: center; }
.pause-shop-btn:active { transform: scale(0.95); }

#flashOverlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: white; z-index: 50; opacity: 0; pointer-events: none; transition: opacity 0.5s; display: none; }
#flashOverlay.flash { display: block; opacity: 1; }

.shop-tabs { display: flex; gap: 10px; margin-bottom: 15px; }
.shop-tab { background: #1e293b; border: 1px solid #38bdf8; color: #fff; padding: 8px 16px; border-radius: 8px; cursor: pointer; font-weight: bold; transition: background 0.2s; }
.shop-tab.active { background: #38bdf8; color: #0f172a; }
.shop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 320px; max-height: 400px; overflow-y: auto; padding-right: 4px; margin-bottom: 10px; }
.shop-item { background: rgba(15, 23, 42, 0.8); border: 2px solid #334155; border-radius: 12px; padding: 12px 10px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.shop-item h4 { color: #38bdf8; font-size: 0.95rem; margin-bottom: 4px; }
.shop-item p { color: #94a3b8; font-size: 0.75rem; margin-bottom: 10px; line-height: 1.2; flex-grow: 1; }
.shop-btn { background: #10b981; color: white; border: none; padding: 8px 12px; border-radius: 6px; font-weight: bold; cursor: pointer; font-size: 0.85rem; width: 100%; transition: transform 0.1s, background 0.2s; }
.shop-btn:active { transform: scale(0.95); }
.shop-btn.equipped { background: #3b82f6; cursor: pointer; }
.shop-btn:disabled { background: #475569 !important; color: #94a3b8; cursor: not-allowed; transform: none; }
.shop-img { height: 45px; object-fit: contain; margin: 4px 0; filter: drop-shadow(0 0 6px rgba(251, 191, 36, 0.5)); }

@keyframes glowUpgrade {
    0% { box-shadow: 0 0 5px #10b981; border-color: #10b981; }
    50% { box-shadow: 0 0 20px #34d399; border-color: #34d399; }
    100% { box-shadow: 0 0 5px #10b981; border-color: #10b981; }
}
.can-upgrade { animation: glowUpgrade 1.2s infinite !important; }

.tutorial-content { text-align: left; max-width: 320px; overflow-y: auto; max-height: 400px; padding-right: 8px; margin-top: 10px; }
.tutorial-content::-webkit-scrollbar { width: 6px; }
.tutorial-content::-webkit-scrollbar-track { background: #0f172a; border-radius: 4px; }
.tutorial-content::-webkit-scrollbar-thumb { background: #38bdf8; border-radius: 4px; }
.tutorial-content h3 { font-size: 1.05rem; margin-top: 12px; margin-bottom: 4px; }
.tutorial-content p { color: #94a3b8; font-size: 0.85rem; line-height: 1.4; margin-bottom: 8px; }


/* Arena PvP experimental */
.pvp-stick {
    width: 112px; height: 112px; border-radius: 50%;
    border: 2px solid rgba(56,189,248,.65); background: rgba(15,23,42,.58);
    box-shadow: inset 0 0 24px rgba(56,189,248,.14), 0 0 14px rgba(0,0,0,.5);
    z-index: 3; touch-action: none; user-select: none; display:flex; align-items:center; justify-content:center;
}
.pvp-stick-fire { border-color: rgba(244,63,94,.75); }
.pvp-stick-knob { width:48px; height:48px; border-radius:50%; background:rgba(56,189,248,.9); box-shadow:0 0 12px #38bdf8; pointer-events:none; }
.pvp-stick-fire .pvp-stick-knob { background:rgba(244,63,94,.9); box-shadow:0 0 12px #fb7185; }
.pvp-stick small { position:absolute; bottom:-18px; width:150px; color:#e2e8f0; font-size:.55rem; font-weight:800; text-align:center; pointer-events:none; text-shadow:0 2px 3px #000; }
