:root {
    --bg: #0f0f16;
    --panel: #161722;
    --text: #f7f7f7;
    --accent: #66ff96;
    --accent-2: #6d9cff;
    --danger: #ff5c8a;
    --muted: #b5b5c3;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: radial-gradient(circle at top, #2f1f63 0%, #130f1f 60%);
    color: var(--text);
}

.container {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 24px;
}

h1 {
    margin: 0;
    font-size: clamp(2rem, 3vw, 3rem);
}

p {
    margin: 0;
}

.button {
    display: inline-block;
    background: var(--accent);
    color: #111114;
    text-decoration: none;
    padding: 12px 24px;
    border-radius: 12px;
    font-weight: 700;
    transition: transform 0.15s ease, filter 0.15s ease;
}

.button:hover {
    transform: translateY(-1px);
    filter: brightness(1.05);
}

.button.secondary {
    background: rgba(255,255,255,0.08);
    color: var(--text);
}

.auth-container,
.game-container {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 24px;
    padding: 28px;
    backdrop-filter: blur(8px);
}

.auth-container {
    max-width: 420px;
    margin: 40px auto;
}

/* El juego ocupa todo el ancho de la pantalla */
.game-container {
    width: 100%;
    max-width: none;
}

.auth-container h1 {
    margin-bottom: 20px;
}

.auth-container label {
    display: block;
    margin-top: 14px;
    margin-bottom: 6px;
    color: var(--muted);
}

.auth-container input {
    width: 100%;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.05);
    color: var(--text);
}

.auth-container button {
    margin-top: 20px;
    width: 100%;
    border: none;
}

.alert {
    background: rgba(255, 50, 50, 0.12);
    border: 1px solid rgba(255, 50, 50, 0.25);
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 18px;
}

.scoreboard {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 24px;
}

.scoreboard th,
.scoreboard td {
    padding: 14px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    text-align: left;
}

.scoreboard th {
    color: var(--accent);
}

.hero {
    text-align: center;
    margin-bottom: 28px;
}

.hero h2 {
    margin-bottom: 10px;
    font-size: 2rem;
}

.actions {
    display: flex;
    justify-content: center;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 28px;
}

.story {
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08);
    padding: 18px;
    border-radius: 18px;
}

.game-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.game-grid {
    display: grid;
    grid-template-columns: 1fr minmax(560px, 1.5fr) 1fr;
    gap: 18px;
}

.instructions,
.game-info {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 18px;
    padding: 18px;
}

.game-stage {
    position: relative;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 24px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.start-overlay {
    position: absolute;
    inset: 0;
    z-index: 6;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(8, 4, 16, 0.72);
    backdrop-filter: blur(3px);
    border-radius: 24px;
    text-align: center;
}

.start-btn {
    font-size: 1.4rem;
    font-weight: 900;
    color: #04121a;
    padding: 18px 34px;
    border: none;
    border-radius: 16px;
    background: linear-gradient(135deg, #00e5ff, #2dffa6);
    box-shadow: 0 0 28px rgba(0, 229, 255, 0.55);
    cursor: pointer;
    transition: transform 0.12s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.start-btn:active { transform: scale(0.96); }
.start-hint { color: #cdd6ff; font-size: 0.95rem; }

.pause-btn {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 4;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.2);
    background: rgba(8,4,16,0.55);
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.pause-btn:hover { background: rgba(8,4,16,0.85); }

.pause-overlay {
    position: absolute;
    inset: 0;
    z-index: 7;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: rgba(8,4,16,0.8);
    backdrop-filter: blur(3px);
    border-radius: 24px;
    text-align: center;
}
.pause-overlay .pause-title { font-size: 2rem; font-weight: 900; color: #fff; }

.status-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.bars { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 220px; }
.bar-row { display: flex; align-items: center; gap: 8px; }
.bar-row .bl { font-size: 0.78rem; font-weight: 700; width: 64px; flex: none; color: #cdd6ff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row .life-bar { flex: 1; }

.score-label {
    font-weight: 700;
}

.life-bar {
    height: 16px;
    background: rgba(255,255,255,0.08);
    border-radius: 999px;
    overflow: hidden;
}

.life-fill {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #60ff75, #00c8ff);
    transition: width 0.2s ease;
}

.life-fill.rival {
    background: linear-gradient(90deg, #ff2db3, #b14dff);
}

.game-panel {
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

.character-card {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 18px;
    padding: 18px;
    flex: 1;
    text-align: center;
}

.character-card.player {
    border-color: var(--accent);
}

.character-name {
    font-size: 1.05rem;
    font-weight: 700;
}

#gameCanvas {
    width: 100%;
    border-radius: 20px;
    background: radial-gradient(circle at center, rgba(255,255,255,0.06), rgba(0,0,0,0.3));
    display: block;
}

.week-select {
    margin-top: 18px;
}

.week-select label {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
}

.week-select select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(0,0,0,0.3);
    color: var(--text);
}

.controls-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.controls-grid div {
    background: rgba(255,255,255,0.06);
    padding: 14px;
    border-radius: 14px;
    text-align: center;
    font-weight: 700;
}

.touch-pads {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.touch-pads .pad {
    font-size: 1.6rem;
    font-weight: 900;
    color: #fff;
    padding: 16px 0;
    border-radius: 14px;
    border: 2px solid rgba(255,255,255,0.2);
    background: rgba(255,255,255,0.06);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: transform 0.06s ease, background 0.1s ease;
}

.touch-pads .pad-left { border-color: #ff4d6d; color: #ff8aa0; }
.touch-pads .pad-down { border-color: #4dc5ff; color: #93dcff; }
.touch-pads .pad-up { border-color: #95ff4d; color: #bdff93; }
.touch-pads .pad-right { border-color: #ffd54d; color: #ffe793; }
.touch-pads .pad.active,
.touch-pads .pad:active { background: rgba(255,255,255,0.2); transform: scale(0.95); }

@media (max-width: 1040px) {
    .game-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .container { width: 100%; padding: 8px; }
    .game-container { padding: 10px; border-radius: 14px; }
    .game-header { gap: 8px; margin-bottom: 12px; }
    .game-header h1 { font-size: 1.5rem; }

    /* El juego ocupa la pantalla: stage primero, paneles de texto ocultos */
    .game-grid { display: flex; flex-direction: column; gap: 10px; }
    .game-stage { order: -1; padding: 0.5rem; gap: 10px; }
    .instructions, .game-info { display: none; }

    .status-bar { grid-template-columns: auto 1fr auto; gap: 8px; font-size: 0.95rem; }

    /* Canvas alto (vertical) para flechas y personajes grandes */
    #gameCanvas { aspect-ratio: 4 / 5; }

    /* Las tarjetas KEV/MIA ya están dibujadas en el canvas: las ocultamos para ganar espacio */
    .game-panel { display: none; }

    /* Pads táctiles grandes — control principal en celu */
    .touch-pads { gap: 8px; }
    .touch-pads .pad { font-size: 2.4rem; padding: 26px 0; border-width: 3px; }
}

/* Los pads son sobre todo para touch; en pantallas grandes con mouse igual sirven */
@media (hover: hover) and (pointer: fine) and (min-width: 641px) {
    .touch-pads { opacity: 0.85; }
}

/* ===== BOTÓN FLOTANTE DE CONTROLES ===== */
.floating-controls-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6d9cff 0%, #66ff96 100%);
    border: 2px solid rgba(102, 255, 150, 0.5);
    color: #04121a;
    font-size: 28px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1999;
    box-shadow: 0 4px 20px rgba(102, 255, 150, 0.3), 0 0 15px rgba(109, 156, 255, 0.2);
    transition: all 0.3s ease;
    font-weight: 700;
}

.floating-controls-btn:hover {
    transform: scale(1.1) translateY(-4px);
    box-shadow: 0 6px 30px rgba(102, 255, 150, 0.5), 0 0 20px rgba(109, 156, 255, 0.3);
    border-color: rgba(102, 255, 150, 0.8);
}

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

/* Ocultar botón flotante en móviles (solo mostrar en desktop) */
@media (max-width: 768px) {
    .floating-controls-btn {
        display: none !important;
    }
}

/* ===== ESTILOS DEL MODAL DE CONFIGURACIÓN ===== */
.config-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.config-modal-content {
    background: linear-gradient(135deg, var(--panel) 0%, rgba(22, 23, 34, 0.9) 100%);
    border: 2px solid rgba(102, 255, 150, 0.3);
    border-radius: 20px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(102, 255, 150, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.config-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid rgba(102, 255, 150, 0.2);
}

.config-header h2 {
    margin: 0;
    color: var(--accent);
    font-size: 1.4rem;
}

.close-btn {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1.8rem;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: rgba(255, 92, 138, 0.2);
    color: var(--danger);
}

.config-body {
    padding: 24px;
}

.config-info {
    margin: 0 0 20px 0;
    color: var(--muted);
    font-size: 0.95rem;
}

.key-config-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.key-config-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.key-config-item label {
    font-size: 0.9rem;
    color: var(--muted);
    font-weight: 600;
}

.key-input {
    background: rgba(109, 156, 255, 0.15);
    border: 2px solid rgba(109, 156, 255, 0.4);
    color: var(--accent-2);
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.key-input:hover {
    background: rgba(109, 156, 255, 0.25);
    border-color: rgba(109, 156, 255, 0.6);
    transform: translateY(-2px);
}

.key-input:active,
.key-input.listening {
    background: rgba(77, 197, 255, 0.3);
    border-color: var(--accent-2);
    box-shadow: 0 0 12px rgba(109, 156, 255, 0.4);
}

.config-hint {
    margin: 0;
    color: var(--muted);
    font-size: 0.85rem;
    font-style: italic;
    text-align: center;
    opacity: 0.8;
}

.config-footer {
    display: flex;
    gap: 12px;
    padding: 20px 24px;
    border-top: 1px solid rgba(102, 255, 150, 0.2);
    flex-wrap: wrap;
}

.config-footer .button {
    flex: 1;
    min-width: 140px;
    padding: 10px 16px;
    font-size: 0.95rem;
}

.config-footer .button.secondary {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.config-footer .button.secondary:hover {
    background: rgba(255, 255, 255, 0.12);
}

/* Responsive: botón flotante más pequeño en celulares */
@media (max-width: 640px) {
    .floating-controls-btn {
        width: 50px;
        height: 50px;
        font-size: 24px;
        bottom: 20px;
        right: 20px;
    }
    
    .config-modal-content {
        width: 95%;
        max-height: 90vh;
    }

    .key-config-grid {
        grid-template-columns: 1fr;
    }

    .config-footer {
        flex-direction: column;
    }

    .config-footer .button {
        width: 100%;
    }
}

/* ===== ESTILOS DEL MODAL DE CONFIGURACIÓN ===== */
.config-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.config-modal-content {
    background: linear-gradient(135deg, var(--panel) 0%, rgba(22, 23, 34, 0.9) 100%);
    border: 2px solid rgba(102, 255, 150, 0.3);
    border-radius: 20px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(102, 255, 150, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.config-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid rgba(102, 255, 150, 0.2);
}

.config-header h2 {
    margin: 0;
    color: var(--accent);
    font-size: 1.4rem;
}

.close-btn {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 1.8rem;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: rgba(255, 92, 138, 0.2);
    color: var(--danger);
}

.config-body {
    padding: 24px;
}

.config-info {
    margin: 0 0 20px 0;
    color: var(--muted);
    font-size: 0.95rem;
}

.key-config-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.key-config-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.key-config-item label {
    font-size: 0.9rem;
    color: var(--muted);
    font-weight: 600;
}

.key-input {
    background: rgba(109, 156, 255, 0.15);
    border: 2px solid rgba(109, 156, 255, 0.4);
    color: var(--accent-2);
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.key-input:hover {
    background: rgba(109, 156, 255, 0.25);
    border-color: rgba(109, 156, 255, 0.6);
    transform: translateY(-2px);
}

.key-input:active,
.key-input.listening {
    background: rgba(77, 197, 255, 0.3);
    border-color: var(--accent-2);
    box-shadow: 0 0 12px rgba(109, 156, 255, 0.4);
}

.config-hint {
    margin: 0;
    color: var(--muted);
    font-size: 0.85rem;
    font-style: italic;
    text-align: center;
    opacity: 0.8;
}

.config-footer {
    display: flex;
    gap: 12px;
    padding: 20px 24px;
    border-top: 1px solid rgba(102, 255, 150, 0.2);
    flex-wrap: wrap;
}

.config-footer .button {
    flex: 1;
    min-width: 140px;
    padding: 10px 16px;
    font-size: 0.95rem;
}

.config-footer .button.secondary {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.config-footer .button.secondary:hover {
    background: rgba(255, 255, 255, 0.12);
}

/* Estilos para radio buttons de posición */
.arrow-position-group {
    display: flex;
    gap: 16px;
    margin: 16px 0;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 10px 14px;
    border-radius: 10px;
    background: rgba(109, 156, 255, 0.1);
    border: 1px solid rgba(109, 156, 255, 0.3);
    transition: all 0.2s ease;
    font-size: 0.95rem;
    color: var(--text);
    user-select: none;
}

.radio-label:hover {
    background: rgba(109, 156, 255, 0.15);
    border-color: rgba(109, 156, 255, 0.5);
}

.radio-label input[type="radio"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
    accent-color: var(--accent-2);
}

.radio-label input[type="radio"]:checked + span {
    font-weight: 700;
    color: var(--accent-2);
}

/* Responsive: modal más chiquito en celulares */
@media (max-width: 640px) {
    .config-modal-content {
        width: 95%;
        max-height: 90vh;
    }

    .key-config-grid {
        grid-template-columns: 1fr;
    }

    .config-footer {
        flex-direction: column;
    }

    .config-footer .button {
        width: 100%;
    }
}
