/* ==========================================================
   SPACE INVADERS ARCADE - HOJA DE ESTILOS PROFESIONAL
   Diseño responsivo con contención automática de aspect-ratio (4:3)
   Ajuste 100% perfecto a la altura de pantalla sin necesidad de zoom
   ========================================================== */

:root {
    --color-bg-dark: #070818;
    --color-bg-panel: rgba(18, 22, 45, 0.85);
    --color-primary: #6366f1;
    --color-primary-glow: rgba(99, 102, 241, 0.5);
    --color-accent: #facc15;
    --color-accent-glow: rgba(250, 204, 21, 0.6);
    --color-danger: #ef4444;
    --color-success: #10b981;
    --color-boss: #c026d3;
    --font-arcade: 'Press Start 2P', monospace, cursive;
}

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

html, body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    background-color: var(--color-bg-dark);
    font-family: var(--font-arcade);
    color: #ffffff;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at center, #131738 0%, #08091a 70%, #03040c 100%);
    position: relative;
}

/* ================ CONTENEDOR PRINCIPAL AUTOCONTENIDO ================ */
.game-layout {
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 960px;
    height: 100%;
    max-height: 100dvh;
    padding: 8px 12px;
    gap: 6px;
}

/* ================ CABECERA Y HUD ================ */
.game-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--color-bg-panel);
    border: 2px solid rgba(99, 102, 241, 0.4);
    border-radius: 8px;
    padding: 6px 14px;
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    flex-shrink: 0;
    gap: 8px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.game-title {
    font-size: 14px;
    letter-spacing: 1px;
    color: #818cf8;
    text-shadow: 0 0 10px var(--color-primary-glow);
    white-space: nowrap;
}

.game-stats {
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.stat-label {
    font-size: 8px;
    color: #94a3b8;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 13px;
    color: var(--color-accent);
    text-shadow: 0 0 6px var(--color-accent-glow);
}

/* Barra gráfica de escudos */
.shield-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    min-width: 110px;
}

.shield-bar-wrapper {
    width: 100%;
    height: 10px;
    background: #1e293b;
    border: 1px solid #475569;
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.shield-bar-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #10b981, #34d399);
    transition: width 0.25s ease, background 0.3s ease;
    box-shadow: 0 0 8px #10b981;
}

.shield-bar-fill.warning {
    background: linear-gradient(90deg, #f59e0b, #fbbf24);
    box-shadow: 0 0 8px #f59e0b;
}

.shield-bar-fill.danger {
    background: linear-gradient(90deg, #ef4444, #f87171);
    box-shadow: 0 0 8px #ef4444;
    animation: shield-flash 0.5s infinite alternate;
}

@keyframes shield-flash {
    from { opacity: 1; }
    to   { opacity: 0.4; }
}

/* Botones rápidos en cabecera */
.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.icon-btn {
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid #475569;
    color: #e2e8f0;
    border-radius: 6px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background: #4338ca;
    border-color: #818cf8;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.6);
}

.icon-btn:active {
    transform: scale(0.95);
}

.icon-btn.active {
    background: #4f46e5;
    border-color: #a5b4fc;
    color: #facc15;
}

/* ================ CONTENEDOR DEL CANVAS (4:3 AUTO-FIT) ================ */
.canvas-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1;
    width: 100%;
    min-height: 0;
    overflow: hidden;
}

#gameCanvas {
    aspect-ratio: 4 / 3;
    max-height: 100%;
    max-width: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    background-color: #0b0f1e;
    display: block;
    border: 3px solid #4f46e5;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.4), inset 0 0 30px rgba(0, 0, 0, 0.7);
    transition: border-color 0.4s ease, box-shadow 0.4s ease;
}

.voice-caption {
    position: absolute;
    left: 50%;
    bottom: 7%;
    z-index: 20;
    width: min(78%, 620px);
    padding: 9px 14px;
    border: 1px solid rgba(103, 232, 249, 0.65);
    border-radius: 6px;
    background: rgba(5, 7, 18, 0.88);
    color: #e0f2fe;
    font-family: var(--font-arcade);
    font-size: clamp(7px, 1.2vw, 10px);
    line-height: 1.55;
    text-align: center;
    text-shadow: 0 0 8px #38bdf8;
    opacity: 0;
    transform: translate(-50%, 8px);
    transition: opacity 0.18s ease, transform 0.18s ease;
    pointer-events: none;
}

.voice-caption.visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

.powerup-status {
    position: absolute;
    top: 7%;
    right: 4%;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    pointer-events: none;
}

.powerup-status[hidden],
.powerup-chip[hidden] {
    display: none;
}

.powerup-chip {
    padding: 6px 9px;
    border: 1px solid currentColor;
    border-radius: 5px;
    background: rgba(5, 7, 18, 0.88);
    font-family: var(--font-arcade);
    font-size: clamp(6px, 1vw, 9px);
    line-height: 1.2;
    text-shadow: 0 0 7px currentColor;
}

.powerup-chip.twin { color: #a5b4fc; }
.powerup-chip.rapid { color: #67e8f9; }
.powerup-chip.barrier { color: #22d3ee; }

/* Modo Jefe en Canvas */
body.boss-battle #gameCanvas {
    border-color: var(--color-boss);
    box-shadow: 0 0 25px rgba(192, 38, 211, 0.7), inset 0 0 30px rgba(192, 38, 211, 0.2);
    animation: boss-pulse 1.5s infinite;
}

@keyframes boss-pulse {
    0%, 100% { border-color: #c026d3; box-shadow: 0 0 20px rgba(192, 38, 211, 0.6); }
    50%      { border-color: #facc15; box-shadow: 0 0 35px rgba(250, 204, 21, 0.8); }
}

/* Efecto Pantalla Shake */
body.shake {
    animation: screen-shake 0.35s ease-in-out;
}

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

/* ================ FILTRO CRT / SCANLINES RETRO ================ */
.crt-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 15;
    display: none;
    border-radius: 8px;
}

body.crt-enabled .crt-overlay {
    display: block;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.32) 50%),
                linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.03));
    background-size: 100% 4px, 6px 100%;
    box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.6);
}

/* ================ CONTROLES MÓVILES (SOLO TOUCH / PANTALLA ESTRECHA) ================ */
.mobile-controls {
    display: none;
    width: 100%;
    justify-content: space-between;
    align-items: center;
    padding: 4px 8px;
    gap: 12px;
    flex-shrink: 0;
}

@media (max-width: 768px) and (hover: none), (pointer: coarse) and (max-width: 900px) {
    .mobile-controls {
        display: flex;
    }
}

.mobile-direction-group {
    display: flex;
    gap: 10px;
}

.control-btn {
    background: linear-gradient(135deg, #3730a3, #1e1b4b);
    border: 2px solid #6366f1;
    border-radius: 10px;
    color: #ffffff;
    font-family: var(--font-arcade);
    font-size: 12px;
    padding: 12px 18px;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
    touch-action: manipulation;
    transition: transform 0.1s, filter 0.1s;
}

.control-btn:active {
    transform: scale(0.92);
    filter: brightness(1.3);
    border-color: #a5b4fc;
}

#shootBtn {
    background: linear-gradient(135deg, #b91c1c, #7f1d1d);
    border-color: #ef4444;
    padding: 12px 26px;
    color: #fff;
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.4);
}

#shootBtn:active {
    border-color: #fca5a5;
    box-shadow: 0 0 18px rgba(239, 68, 68, 0.8);
}

/* Barra inferior con atajos de ayuda en escritorio */
.desktop-hints {
    display: flex;
    justify-content: center;
    gap: 14px;
    font-size: 8px;
    color: #64748b;
    flex-shrink: 0;
    padding: 2px 0;
}

.desktop-hints kbd {
    background: #1e293b;
    border: 1px solid #475569;
    border-radius: 3px;
    padding: 2px 4px;
    color: #cbd5e1;
}

@media (max-width: 768px) {
    .desktop-hints {
        display: none;
    }
    .game-title {
        font-size: 11px;
    }
    .stat-label {
        font-size: 7px;
    }
    .stat-value {
        font-size: 10px;
    }
    .shield-container {
        min-width: 80px;
    }
}

/* ================ PANTALLAS OVERLAY (INICIO, PAUSA, GAME OVER) ================ */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(4, 6, 16, 0.88);
    backdrop-filter: blur(6px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
    transition: opacity 0.2s ease;
}

.overlay.hidden {
    display: none !important;
}

.overlay-content {
    background: linear-gradient(145deg, #0f172a, #1e293b);
    border: 2px solid #6366f1;
    border-radius: 16px;
    padding: 24px 20px;
    text-align: center;
    max-width: 480px;
    width: 90%;
    box-shadow: 0 0 35px rgba(99, 102, 241, 0.4), inset 0 0 20px rgba(0, 0, 0, 0.5);
    animation: modal-enter 0.3s ease-out;
}

@keyframes modal-enter {
    from { transform: scale(0.92); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}

.overlay-title {
    font-size: 18px;
    color: var(--color-accent);
    margin-bottom: 16px;
    text-shadow: 0 0 12px var(--color-accent-glow);
    letter-spacing: 1px;
}

.game-over-title {
    color: var(--color-danger);
    text-shadow: 0 0 15px rgba(239, 68, 68, 0.8);
    animation: game-over-flicker 1.2s infinite;
}

@keyframes game-over-flicker {
    0%, 100% { opacity: 1; text-shadow: 0 0 15px rgba(239, 68, 68, 0.8); }
    50%      { opacity: 0.85; text-shadow: 0 0 25px rgba(245, 158, 11, 0.9); }
}

.overlay-instructions {
    font-size: 9px;
    line-height: 1.8;
    color: #cbd5e1;
    margin-bottom: 18px;
    text-align: left;
    background: rgba(15, 23, 42, 0.6);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #334155;
}

.instruction-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.instruction-row:last-child {
    margin-bottom: 0;
}

.powerup-preview {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed #475569;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    gap: 8px 12px;
    font-size: 8px;
}

.difficulty-control {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 0 0 16px;
    color: #94a3b8;
    font-size: 8px;
}

.difficulty-control select {
    appearance: none;
    min-width: 120px;
    padding: 8px 24px 8px 10px;
    border: 1px solid #6366f1;
    border-radius: 6px;
    background: #0f172a;
    color: #facc15;
    font: inherit;
    text-align: center;
    cursor: pointer;
}

.difficulty-control select:focus-visible {
    outline: 2px solid #38bdf8;
    outline-offset: 2px;
}

.pilot-control {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 8px 10px;
    max-width: 320px;
    margin: 0 auto 8px;
    color: #94a3b8;
    font-size: 8px;
    text-align: left;
}

.pilot-control input {
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid #6366f1;
    border-radius: 6px;
    background: #0f172a;
    color: #facc15;
    font: inherit;
    text-transform: uppercase;
}

.pilot-control input:focus-visible {
    outline: 2px solid #38bdf8;
    outline-offset: 2px;
}

.pilot-control span {
    grid-column: 2;
    color: #64748b;
    font-size: 6px;
    line-height: 1.4;
}

.overlay-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 16px 0;
}

.overlay-stat-card {
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 8px 4px;
}

.overlay-stat-card .label {
    font-size: 7px;
    color: #94a3b8;
    margin-bottom: 4px;
}

.overlay-stat-card .value {
    font-size: 13px;
    color: var(--color-accent);
    text-shadow: 0 0 8px var(--color-accent-glow);
}

.btn-primary {
    background: linear-gradient(135deg, #10b981, #059669);
    border: 2px solid #34d399;
    border-radius: 10px;
    color: white;
    font-family: var(--font-arcade);
    font-size: 12px;
    padding: 12px 24px;
    cursor: pointer;
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.5);
    transition: all 0.2s ease;
    margin-top: 8px;
    letter-spacing: 1px;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 25px rgba(16, 185, 129, 0.8);
    filter: brightness(1.1);
}

.btn-primary:active {
    transform: scale(0.95);
}

.btn-secondary {
    background: transparent;
    border: 1px solid #64748b;
    border-radius: 8px;
    color: #94a3b8;
    font-family: var(--font-arcade);
    font-size: 9px;
    padding: 8px 14px;
    cursor: pointer;
    margin-top: 8px;
    transition: all 0.2s ease;
}

.btn-secondary:hover {
    color: #fff;
    border-color: #cbd5e1;
    background: rgba(255, 255, 255, 0.05);
}

.submission-status {
    min-height: 18px;
    margin: 4px 0;
    color: #38bdf8;
    font-size: 7px;
    line-height: 1.5;
}

.leaderboard-content {
    max-width: 620px;
}

.leaderboard-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin-bottom: 14px;
}

.leaderboard-tab {
    padding: 9px 5px;
    border: 1px solid #475569;
    border-radius: 6px;
    background: #0f172a;
    color: #94a3b8;
    font-family: var(--font-arcade);
    font-size: 7px;
    cursor: pointer;
}

.leaderboard-tab.active {
    border-color: #facc15;
    color: #facc15;
    box-shadow: 0 0 10px rgba(250, 204, 21, 0.25);
}

.leaderboard-table-wrap {
    min-height: 250px;
    max-height: min(55vh, 390px);
    overflow-y: auto;
    border: 1px solid #334155;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.65);
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 8px;
}

.leaderboard-table th,
.leaderboard-table td {
    padding: 9px 6px;
    border-bottom: 1px solid #1e293b;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leaderboard-table th {
    position: sticky;
    top: 0;
    background: #111827;
    color: #94a3b8;
    font-size: 7px;
}

.leaderboard-table th:nth-child(1),
.leaderboard-table td:nth-child(1) { width: 10%; color: #facc15; }
.leaderboard-table th:nth-child(2),
.leaderboard-table td:nth-child(2) { width: 45%; text-align: left; }
.leaderboard-table th:nth-child(3),
.leaderboard-table td:nth-child(3) { width: 27%; color: #38bdf8; }
.leaderboard-table th:nth-child(4),
.leaderboard-table td:nth-child(4) { width: 18%; }

.leaderboard-status {
    margin: 24px 12px;
    color: #64748b;
    font-size: 7px;
    line-height: 1.6;
}

/* Accesibilidad */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
