/* ==========================================================================
   404 INVADERS — ESTILO "SYSTEM DEFENSE PROTOCOL"
   Negro + naranja + blanco, marcos finos con esquinas, tipografía pixel/terminal
   ========================================================================== */
:root {
  --orange: #D77400;
  --orange-soft: rgba(215, 116, 0, 0.35);
  --orange-faint: rgba(215, 116, 0, 0.12);
  --white: #f2f2f2;
  --grey: #8a8a8a;
  --red: #ff4444;
  --cyan: #58d8ff;
  --green: #5dff8a;
  --font-pixel: 'Press Start 2P', 'Courier New', monospace;
  --font-mono: 'Share Tech Mono', 'Courier New', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%; height: 100%; overflow: hidden;
  /* Sin scroll, sin "tirar para recargar" ni zoom con gestos: la pantalla queda fija en el juego */
  overscroll-behavior: none; touch-action: none; -webkit-touch-callout: none;
  position: fixed; inset: 0;
  background: #000; color: var(--white);
  font-family: var(--font-mono);
}

/* ---------- OVERLAYS CRT ---------- */
.crt-overlay {
  position: fixed; inset: 0; pointer-events: none; z-index: 200;
  background:
    linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.22) 50%),
    linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.03));
  background-size: 100% 3px, 3px 100%;
}
.vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 199;
  box-shadow: inset 0 0 120px rgba(0, 0, 0, 0.85), inset 0 0 50px rgba(215, 116, 0, 0.12);
}
#flash-overlay { position: fixed; inset: 0; pointer-events: none; z-index: 150; background: #fff; opacity: 0; }

#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; display: block; touch-action: none; }

/* ---------- CAPAS DE INTERFAZ ---------- */
.ui-layer {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; justify-content: flex-start; align-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  pointer-events: none; opacity: 0; visibility: hidden;
  transition: opacity 0.35s ease, visibility 0s linear 0.35s;
  overflow-y: auto;
}
/* Centrado que no corta el contenido si no cabe (se puede hacer scroll) */
.ui-layer > * { margin-top: auto; margin-bottom: auto; flex-shrink: 0; }
.ui-layer.active { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity 0.35s ease; }
.ui-layer.active .panel, .ui-layer.active .menu-layout { animation: panelIn 0.4s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes panelIn {
  0% { opacity: 0; transform: scaleY(0.02) scaleX(1.1); filter: brightness(3); }
  50% { opacity: 1; transform: scaleY(1.03) scaleX(1); }
  100% { transform: none; filter: none; }
}

/* Fondo de menús con rejilla (cuando no hay partida detrás) */
#menu-screen, #difficulty-screen, #briefing-screen, #scores-screen, #achievements-screen, #name-screen, #tut-offer-screen, #tut-done-screen {
  background:
    linear-gradient(rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.85)),
    repeating-linear-gradient(0deg, transparent 0 39px, var(--orange-faint) 39px 40px),
    repeating-linear-gradient(90deg, transparent 0 39px, var(--orange-faint) 39px 40px);
}
#pause-screen, #settings-screen, #summary-screen, #lose-screen, #win-screen { background: rgba(0, 0, 0, 0.72); }
/* Menús que se abren durante la partida: por encima del HUD y de los controles táctiles,
   con fondo casi opaco para que el juego no se transparente detrás (antes el hangar quedaba debajo) */
#pause-screen, #settings-screen, #skins-screen, #keys-screen { z-index: 120; background: rgba(0, 0, 0, 0.9); }
#pause-screen .panel, #settings-screen .panel, #skins-screen .panel, #keys-screen .panel, #mod-screen .panel { background: rgba(8, 5, 2, 0.97); }
#mod-screen { background: rgba(0, 0, 0, 0.85); }

/* ---------- RESUMEN DE LA NAVE (pausa y pantalla de mods) ---------- */
.build-panel { border: 1px dashed var(--orange-soft); padding: 8px 10px; margin: 0 0 14px; text-align: left; font-size: 11px; letter-spacing: 1px; }
#mod-build { margin: 14px 0 0; }
.build-panel:empty { display: none; }
.build-head { color: var(--orange); margin-bottom: 6px; display: flex; justify-content: space-between; }
.build-head small { color: var(--grey); }
.build-mods, .build-pus { display: flex; flex-wrap: wrap; gap: 4px 6px; }
.build-pus { margin-top: 6px; }
.bm { border: 1px solid rgba(255, 255, 255, 0.15); padding: 2px 6px; color: #ddd; }
.bm b { color: var(--orange); }
.bm.star { border-color: rgba(255, 210, 63, 0.5); }
.bm.max { border-color: #ffd23f; box-shadow: 0 0 8px rgba(255, 210, 63, 0.4); }
.bm.none { color: var(--grey); }
.bp { padding: 2px 4px; color: #ddd; }

/* ---------- JOYSTICK VIRTUAL (modo JOYSTICK) ---------- */
.joy { display: none; position: relative; width: 150px; height: 84px; touch-action: none;
  border: 1px solid rgba(215, 116, 0, 0.6); border-radius: 42px; background: rgba(0, 0, 0, 0.6);
  box-shadow: inset 0 0 16px rgba(215, 116, 0, 0.2); }
.joy::before, .joy::after { content: '◄'; position: absolute; top: 50%; transform: translateY(-50%); left: 12px; color: rgba(215, 116, 0, 0.5); font-size: 14px; }
.joy::after { content: '►'; left: auto; right: 12px; }
.joy-knob { position: absolute; left: 50%; top: 50%; width: 60px; height: 60px; margin: -30px 0 0 -30px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, rgba(255, 179, 71, 0.9), rgba(215, 116, 0, 0.75)); box-shadow: 0 0 14px rgba(215, 116, 0, 0.6); }
.joy.active { border-color: var(--orange); }
body.joy-mode .move-group .touch-btn { display: none; }
body.joy-mode .joy { display: block; }
body.phone .joy { width: 170px; height: 96px; border-radius: 48px; }
body.phone .joy-knob { width: 68px; height: 68px; margin: -34px 0 0 -34px; }

/* ---------- TUTORIAL: cuadro de instrucciones sobre el campo de juego ---------- */
#tut-box {
  position: absolute; left: 50%; top: 42%; transform: translateX(-50%); z-index: 25;
  width: min(420px, calc(100% - 32px)); display: none; pointer-events: none; text-align: center;
  background: rgba(0, 0, 0, 0.75); border: 1px solid var(--orange-soft); padding: 10px 14px 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
body.tutorial.playing #tut-box { display: block; }
.tut-head { display: flex; justify-content: space-between; font-size: 10px; letter-spacing: 2px; color: var(--orange); margin-bottom: 6px; }
#tut-title { display: block; font-family: var(--font-pixel); font-weight: normal; font-size: 13px; color: #fff; margin-bottom: 6px; }
#tut-text { margin: 0; font-size: 14px; line-height: 1.4; color: #ddd; }
#tut-text kbd { border: 1px solid var(--orange); padding: 0 5px; color: var(--orange); font-family: inherit; }
#tut-box.ok { border-color: #5dff8a; box-shadow: 0 0 18px rgba(93, 255, 138, 0.35); }
#tut-box.ok #tut-title { color: #5dff8a; }
#tut-box.ok #tut-title::after { content: ' ✓'; }

/* ---------- LOADOUT: pestañas NAVE / BOMBA ---------- */
.lo-tabs { display: flex; gap: 8px; margin-bottom: 10px; }
.lo-tab { flex: 1; justify-content: center; padding-left: 0; font-size: 12px; letter-spacing: 3px; }
.lo-tab.active { border-color: var(--orange); color: var(--orange); box-shadow: inset 0 -3px 0 var(--orange); }
.lo-tab.active.focused, .lo-tab.active:hover { color: #000; }
.lo-bomb-desc { min-height: 0; margin: 4px 0 10px; font-size: 13px; color: #ddd; letter-spacing: 1px; }
.lo-bomb-desc:empty { display: none; }
.bomb-ico { display: inline-block; width: 22px; margin-right: 8px; text-align: center; }
#briefing-bomb { margin-bottom: 10px; }

/* ---------- CARTAS DE MOD (rareza y habilidades de nivel 5 / 10) ---------- */
.mod-card .rar { font-style: normal; margin-right: 6px; letter-spacing: 1px; }
.mod-card .rar.new { color: var(--green, #5dff8a); }
.mod-card em.milestone { color: #ffd23f; display: block; margin-top: 4px; }
.mod-card.rarity-rare { border-color: rgba(88, 216, 255, 0.7); box-shadow: inset 0 0 14px rgba(88, 216, 255, 0.15); }
.mod-card.rarity-epic { border-color: rgba(255, 43, 214, 0.8); box-shadow: inset 0 0 18px rgba(255, 43, 214, 0.2); animation: epicGlow 1.2s ease-in-out infinite alternate; }
@keyframes epicGlow { to { box-shadow: inset 0 0 26px rgba(255, 43, 214, 0.35), 0 0 12px rgba(255, 43, 214, 0.3); } }

/* ---------- PRELOADERS ---------- */
#preloader-lab { background: #000; z-index: 50; gap: 28px; }
#preloader-lab, #preloader-bm { justify-content: center; }
#preloader-lab > *, #preloader-bm > * { margin-top: 0; margin-bottom: 0; }
#preloader-bm { background: #FFF6E5; z-index: 49; }
.logo-lab { width: 180px; animation: logoBreathe 2s ease-in-out infinite alternate; filter: drop-shadow(0 0 20px rgba(215, 116, 0, 0.6)); }
#logo-bm-img { width: 190px; animation: logoSlideIn 1.2s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
.boot-text { font-size: 13px; letter-spacing: 4px; color: var(--orange); }
.cursor { animation: blink 0.8s steps(1) infinite; }
@keyframes logoBreathe { 0% { transform: scale(0.95); opacity: 0.8; } 100% { transform: scale(1.05); opacity: 1; } }
@keyframes logoSlideIn { 0% { transform: translateY(30px); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- MARCO CON ESQUINAS (como la portada) ---------- */
.panel, .term {
  position: relative;
  background: rgba(5, 5, 5, 0.88);
  border: 1px solid var(--orange-soft);
  box-shadow: 0 0 30px rgba(215, 116, 0, 0.15), inset 0 0 30px rgba(215, 116, 0, 0.05);
}
.panel::before, .panel::after, .term::before, .term::after {
  content: ''; position: absolute; width: 14px; height: 14px; border: 2px solid var(--orange); pointer-events: none;
}
.panel::before, .term::before { top: -3px; left: -3px; border-right: none; border-bottom: none; }
.panel::after, .term::after { bottom: -3px; right: -3px; border-left: none; border-top: none; }

.panel { width: min(560px, 100%); padding: 22px 26px 26px; text-align: center; }
.panel-head {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 11px; letter-spacing: 2px; color: var(--orange);
  border-bottom: 1px dashed var(--orange-soft); padding-bottom: 8px; margin-bottom: 18px;
}
.panel-error { border-color: rgba(255, 68, 68, 0.5); }
.panel-error::before, .panel-error::after { border-color: var(--red); }
.panel-error .panel-head { color: var(--red); border-color: rgba(255, 68, 68, 0.4); }

/* ---------- TIPOGRAFÍA ---------- */
h1, h2 { font-family: var(--font-pixel); font-weight: normal; }
.panel-title {
  font-size: clamp(16px, calc(var(--vw, 1vw) * 4.6), 26px); line-height: 1.4; letter-spacing: 2px; margin-bottom: 16px;
  color: var(--white); text-shadow: 0 0 12px rgba(215, 116, 0, 0.8);
}
.panel-error .panel-title { text-shadow: 0 0 14px rgba(255, 68, 68, 0.9); }
.subtitle { color: var(--orange); font-size: 14px; letter-spacing: 4px; margin-bottom: 16px; text-transform: uppercase; }
.description { color: #bbb; font-size: 15px; line-height: 1.6; margin: 12px 0 16px; }
.description.unlock { color: var(--green); }
.hint { color: var(--grey); font-size: 12px; letter-spacing: 1px; margin: 10px 0 16px; }
.warn { color: var(--red); }
.ok { color: var(--green); }

/* Efecto glitch con separación RGB */
.glitch { position: relative; display: inline-block; }
.glitch::before, .glitch::after {
  content: attr(data-text); position: absolute; inset: 0; pointer-events: none; opacity: 0.8;
}
.glitch::before { color: var(--red); transform: translate(-2px, 0); clip-path: inset(0 0 60% 0); animation: glitchA 3.2s infinite steps(1); mix-blend-mode: screen; }
.glitch::after { color: var(--cyan); transform: translate(2px, 0); clip-path: inset(55% 0 0 0); animation: glitchB 2.7s infinite steps(1); mix-blend-mode: screen; }
@keyframes glitchA {
  0%, 88%, 100% { transform: translate(0); clip-path: inset(0 0 100% 0); }
  89% { transform: translate(-4px, -1px); clip-path: inset(10% 0 60% 0); }
  92% { transform: translate(3px, 1px); clip-path: inset(40% 0 30% 0); }
  95% { transform: translate(-2px, 0); clip-path: inset(70% 0 5% 0); }
}
@keyframes glitchB {
  0%, 84%, 100% { transform: translate(0); clip-path: inset(100% 0 0 0); }
  85% { transform: translate(4px, 1px); clip-path: inset(60% 0 10% 0); }
  89% { transform: translate(-3px, 0); clip-path: inset(20% 0 55% 0); }
  93% { transform: translate(2px, -1px); clip-path: inset(5% 0 80% 0); }
}

/* ---------- MENÚ PRINCIPAL ---------- */
.menu-layout { width: min(520px, 100%); display: flex; flex-direction: column; align-items: center; gap: 18px; }
.title-block { text-align: center; display: flex; flex-direction: column; align-items: center; }
.kicker { font-size: 11px; letter-spacing: 3px; color: var(--orange); margin-bottom: 10px; }
.title-404 {
  font-size: clamp(64px, calc(var(--vw, 1vw) * 20), 120px); line-height: 1; color: var(--white);
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.35), 4px 4px 0 rgba(215, 116, 0, 0.35);
}
.jp { font-size: 11px; letter-spacing: 3px; color: var(--orange); margin: 8px 0 6px; }
.title-invaders { font-size: clamp(22px, calc(var(--vw, 1vw) * 7.5), 42px); color: var(--orange); text-shadow: 0 0 18px rgba(215, 116, 0, 0.8); letter-spacing: 2px; }
.tag-box { display: inline-block; margin-top: 14px; border: 1px solid var(--orange-soft); padding: 6px 14px; font-size: 12px; letter-spacing: 3px; color: #ddd; }

.term { width: 100%; }
.term-bar {
  display: flex; justify-content: space-between; background: var(--orange); color: #000;
  font-size: 12px; letter-spacing: 1px; padding: 4px 10px; font-weight: bold;
}
.term-body { padding: 12px; }
.menu-footer { width: 100%; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 11px; letter-spacing: 2px; color: var(--grey); }
.menu-footer b { color: var(--orange); }
.blink-alert { color: var(--orange); animation: blink 1.6s steps(1) infinite; }

/* ---------- BOTONES ESTILO TERMINAL ---------- */
.menu-list { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.btn {
  position: relative; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; padding: 11px 14px 11px 30px;
  background: transparent; color: var(--white);
  border: 1px solid rgba(215, 116, 0, 0.25);
  font-family: var(--font-mono); font-size: 16px; letter-spacing: 3px; text-transform: uppercase; text-align: left;
  cursor: pointer; transition: background 0.12s, color 0.12s, border-color 0.12s;
  outline: none;
}
.btn::before { content: '>'; position: absolute; left: 12px; color: var(--orange); opacity: 0; transition: opacity 0.12s; }
.btn em { font-style: normal; font-size: 12px; letter-spacing: 1px; color: var(--grey); text-align: right; }
.btn:hover, .btn:focus-visible, .btn.focused {
  background: var(--orange); color: #000; border-color: var(--orange);
  box-shadow: 0 0 18px rgba(215, 116, 0, 0.55);
}
.btn:hover::before, .btn:focus-visible::before, .btn.focused::before { opacity: 1; color: #000; animation: blink 0.8s steps(1) infinite; }
.btn:hover em, .btn:focus-visible em, .btn.focused em { color: #222; }
.btn:disabled, .btn.disabled { opacity: 0.35; cursor: not-allowed; }
/* Un botón desactivado no se ilumina al pasar el ratón por encima */
.btn:disabled:hover, .btn.disabled:hover { background: transparent; color: var(--white); border-color: rgba(215, 116, 0, 0.25); box-shadow: none; }
.btn:disabled:hover::before, .btn.disabled:hover::before { opacity: 0; animation: none; }
.btn:disabled:hover em, .btn.disabled:hover em { color: inherit; }
.btn-primary { border-color: var(--orange); background: rgba(215, 116, 0, 0.14); justify-content: center; margin-top: 6px; }
.btn-danger { border-color: rgba(255, 68, 68, 0.4); }
.btn-danger:hover, .btn-danger:focus-visible, .btn-danger.focused { background: var(--red); border-color: var(--red); box-shadow: 0 0 18px rgba(255, 68, 68, 0.55); }
.btn-back { justify-content: center; color: var(--grey); margin-top: 10px; }
.btn-diff { flex-direction: column; align-items: flex-start; gap: 4px; }
.btn-diff b { font-family: var(--font-pixel); font-weight: normal; font-size: 13px; letter-spacing: 2px; }
.btn-diff em { text-align: left; }

/* ---------- LOG DE TERMINAL (briefing / game over) ---------- */
.terminal-log {
  text-align: left; font-family: var(--font-mono); font-size: 14px; line-height: 1.55;
  color: #cfcfcf; background: rgba(215, 116, 0, 0.05); border-left: 2px solid var(--orange);
  padding: 10px 12px; margin-bottom: 16px; white-space: pre-wrap; min-height: 3em;
}
.error-log { color: #ff9a9a; border-color: var(--red); background: rgba(255, 68, 68, 0.06); }
.ok-log { color: #b8ffcb; border-color: var(--green); background: rgba(93, 255, 138, 0.05); }
.controls-help { display: flex; gap: 12px; text-align: left; font-size: 13px; color: #bbb; margin-bottom: 16px; flex-wrap: wrap; }
.ctrl-col { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 5px; border: 1px dashed var(--orange-soft); padding: 10px; }
.ctrl-col b { color: var(--orange); font-weight: normal; letter-spacing: 2px; }
kbd { font-family: var(--font-mono); border: 1px solid var(--orange-soft); padding: 0 5px; margin-right: 2px; color: var(--white); }
.touch-only { display: none; }
@media (pointer: coarse) { .touch-only { display: flex; } .desktop-only { display: none; } }

/* ---------- AJUSTES ---------- */
.settings-list { display: flex; flex-direction: column; gap: 10px; }
.setting { display: grid; grid-template-columns: 90px 1fr 46px; align-items: center; gap: 12px; text-align: left; font-size: 15px; letter-spacing: 2px; padding: 8px 0; }
.setting output { color: var(--orange); text-align: right; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; background: var(--orange-faint); border: 1px solid var(--orange-soft); outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 22px; background: var(--orange); border: none; cursor: pointer; box-shadow: 0 0 10px var(--orange); }
input[type=range]::-moz-range-thumb { width: 16px; height: 22px; background: var(--orange); border: none; border-radius: 0; cursor: pointer; }
input[type=range]:focus-visible, input[type=range].focused { box-shadow: 0 0 0 2px var(--orange); }
.setting-btn em { color: var(--orange); font-size: 15px; }

/* ---------- TABLAS ---------- */
.stats-table, .scores-table { width: 100%; border-collapse: collapse; font-size: 15px; letter-spacing: 1px; margin-bottom: 8px; }
.stats-table td { padding: 5px 4px; text-align: left; color: #bbb; }
.stats-table td:last-child { text-align: right; color: var(--white); font-variant-numeric: tabular-nums; }
.stats-table tr.sep td { border-top: 1px dashed var(--orange-soft); padding-top: 10px; }
.stats-table tr.total td { border-top: 1px solid var(--orange); padding-top: 10px; color: var(--orange); font-family: var(--font-pixel); font-size: 13px; }
.scores-table td, .scores-table th { padding: 6px 4px; text-align: left; }
.scores-table th { color: var(--orange); font-weight: normal; font-size: 11px; letter-spacing: 2px; border-bottom: 1px solid var(--orange-soft); }
.scores-table td:nth-child(3), .scores-table th:nth-child(3) { text-align: right; font-variant-numeric: tabular-nums; }
.scores-table td:nth-child(4), .scores-table th:nth-child(4) { text-align: right; padding-left: 18px; color: var(--grey); font-size: 13px; }
.scores-table tr.me td:nth-child(4) { color: #222; }
.scores-table tr.me td { color: #000; background: var(--orange); }
.scores-table .empty { text-align: center; color: var(--grey); padding: 20px; }
.tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.tab { justify-content: center; padding-left: 14px; }
.tab.active { border-color: var(--orange); color: var(--orange); }
.tab.active:hover, .tab.active.focused, .tab.active:focus-visible { color: #000; }
.tab::before { display: none; }

/* ---------- LOGROS ---------- */
.ach-list { list-style: none; text-align: left; max-height: calc(var(--vh, 1vh) * 50); overflow-y: auto; margin-bottom: 8px; }
.ach-list li { display: grid; grid-template-columns: 26px 1fr; gap: 10px; padding: 8px 4px; border-bottom: 1px dashed rgba(215, 116, 0, 0.18); }
.ach-list li .ico { color: var(--orange); font-size: 18px; }
.ach-list li b { display: block; font-weight: normal; letter-spacing: 2px; color: var(--white); }
.ach-list li span { font-size: 13px; color: var(--grey); }
.ach-list li.locked b { color: var(--grey); }
.ach-list li.locked .ico { color: #444; }

/* ---------- NOMBRE ---------- */
.name-slots { display: flex; justify-content: center; gap: 18px; margin: 6px 0; }
.name-slot { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.name-slot button { width: 52px; height: 34px; background: transparent; border: 1px solid var(--orange-soft); color: var(--orange); font-size: 14px; cursor: pointer; }
.name-slot button:active { background: var(--orange); color: #000; }
.slot-char { font-family: var(--font-pixel); font-size: 34px; width: 52px; text-align: center; padding: 8px 0; border-bottom: 3px solid #333; }
.name-slot.active .slot-char { color: var(--orange); border-color: var(--orange); animation: blink 1s steps(1) infinite; }

/* ---------- AVISO DE LOGRO ---------- */
#toast {
  position: fixed; top: max(14px, env(safe-area-inset-top)); left: 50%; z-index: 180;
  transform: translate(-50%, -150%); transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  background: #000; border: 1px solid var(--orange); box-shadow: 0 0 24px rgba(215, 116, 0, 0.6);
  padding: 10px 18px; text-align: center; min-width: 240px; pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); }
.toast-kicker { display: block; font-size: 11px; letter-spacing: 2px; color: var(--orange); margin-bottom: 4px; }
#toast b { font-family: var(--font-pixel); font-weight: normal; font-size: 11px; letter-spacing: 1px; }

/* ---------- HUD ---------- */
#hud {
  position: absolute; top: 0; left: 0; width: 100%; z-index: 20;
  padding: max(14px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 10px max(18px, env(safe-area-inset-left));
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
  pointer-events: none; opacity: 0; transition: opacity 0.4s ease;
  border-bottom: 1px solid rgba(215, 116, 0, 0.15);
  background: linear-gradient(rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0));
}
#hud.visible { opacity: 1; }
.hud-stat { display: flex; flex-direction: column; flex: 1 1 0; min-width: 0; gap: 3px; }
.hud-stat:nth-child(2) { text-align: center; }
.hud-stat:nth-child(3) { text-align: right; }
.hud-stat label { font-size: 10px; letter-spacing: 2px; color: var(--orange); }
.hud-stat span { font-family: var(--font-pixel); font-size: clamp(11px, calc(var(--vw, 1vw) * 3.4), 16px); color: var(--white); text-shadow: 0 0 8px rgba(215, 116, 0, 0.7); white-space: nowrap; }
.hud-stat small { font-size: 12px; letter-spacing: 1px; color: var(--grey); min-height: 14px; }
#lives-display { color: var(--red); letter-spacing: 2px; }
.mult { color: var(--orange) !important; transition: transform 0.15s; display: inline-block; }
.mult.bump { transform: scale(1.5); }
.pause-btn {
  pointer-events: auto; width: 38px; height: 38px; flex: 0 0 38px; align-self: center;
  border: 1px solid var(--orange); background: rgba(0, 0, 0, 0.7); color: var(--orange);
  font-family: var(--font-pixel); font-size: 11px; cursor: pointer;
}
#hud:not(.visible) .pause-btn { pointer-events: none; }

/* ---------- CONTROLES TÁCTILES ---------- */
#mobile-controls {
  position: absolute; left: 0; width: 100%; z-index: 30;
  bottom: max(16px, env(safe-area-inset-bottom));
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  display: none; justify-content: space-between; align-items: center;
  visibility: hidden; pointer-events: none;
}
body.playing #mobile-controls { visibility: visible; pointer-events: auto; }
body.drag-mode .move-group { visibility: hidden; }
.touch-group { display: flex; gap: 12px; align-items: center; }
.touch-btn {
  width: 64px; height: 64px; display: flex; justify-content: center; align-items: center;
  background: rgba(0, 0, 0, 0.6); border: 1px solid rgba(215, 116, 0, 0.6);
  color: var(--white); font-family: var(--font-pixel); font-size: 16px;
  clip-path: polygon(12% 0, 100% 0, 100% 88%, 88% 100%, 0 100%, 0 12%);
  box-shadow: inset 0 0 14px rgba(215, 116, 0, 0.2);
}
.touch-btn.small { width: 48px; height: 48px; font-size: 18px; }
.touch-btn.fire { width: 76px; height: 76px; font-size: 12px; color: var(--orange); border-color: var(--orange); }
.touch-btn.pressed, .touch-btn:active { background: rgba(215, 116, 0, 0.45); }
.touch-btn.disabled { opacity: 0.3; }
/* Los menús sí pueden desplazarse en vertical y los deslizadores moverse */
.ui-layer { touch-action: pan-y; }
input[type=range] { touch-action: pan-x; }
.touch-btn { touch-action: none; }
/* Medidor / botón del Ataque 404 (bajo el HUD, a la derecha) */
.btn-404 {
  position: absolute; top: 100%; right: max(18px, env(safe-area-inset-right)); margin-top: 6px;
  display: flex; gap: 3px; padding: 4px; pointer-events: auto; cursor: pointer;
  background: rgba(0, 0, 0, 0.6); border: 1px solid rgba(255, 43, 214, 0.35);
  font-family: var(--font-pixel); font-size: 12px; touch-action: none;
}
.btn-404 span { width: 20px; height: 22px; display: flex; align-items: center; justify-content: center; color: rgba(255, 255, 255, 0.18); border: 1px solid rgba(255, 43, 214, 0.2); }
.btn-404 span.lit { color: #fff; border-color: var(--magenta, #ff2bd6); text-shadow: 0 0 8px #ff2bd6; background: rgba(255, 43, 214, 0.25); }.btn-404.ready { border-color: #ff2bd6; animation: ready404 0.5s steps(2) infinite; }
@keyframes ready404 { 50% { box-shadow: 0 0 18px #ff2bd6; background: rgba(255, 43, 214, 0.35); } }
#hud:not(.visible) .btn-404 { pointer-events: none; }
body.phone .btn-404 { font-size: 15px; }
body.phone .btn-404 span { width: 28px; height: 30px; }
/* Botones de ajustes que solo tienen sentido en táctil o en teclado */
.touch-only-btn { display: none; }
@media (pointer: coarse) { .touch-only-btn { display: flex; } .desktop-only-btn { display: none; } }
.key-row em { min-width: 90px; text-align: right; }
.key-row.waiting em { color: #ff2bd6; animation: ready404 0.5s steps(2) infinite; }
#help-keys { display: flex; flex-direction: column; gap: 4px; }
.btn-charge-auto { box-shadow: 0 0 16px #58d8ff, inset 0 0 14px rgba(88, 216, 255, 0.5) !important; }
/* THE VOID: el campo de juego con colores invertidos */
body.void-mode #game-canvas { filter: invert(1) hue-rotate(180deg); }
body.void-mode #hud { background: rgba(0, 0, 0, 0.88); border-bottom-color: rgba(255, 255, 255, 0.4); }
.panel-void { border-color: #fff !important; box-shadow: 0 0 40px rgba(255, 255, 255, 0.35); }
.panel-void .panel-title { color: #fff; }
/* Virus */
.virus-card b { color: #ff4444; }
.virus-card i { font-style: normal; font-size: 0.75em; color: #5dff8a; margin-left: 6px; }
.virus-card.focused i, .virus-card:hover i, .virus-card.focused b, .virus-card:hover b { color: #000; }
/* Skins */
#skin-preview { display: block; margin: 0 auto 10px; width: 240px; height: 128px; border: 1px solid rgba(215, 116, 0, 0.25); background: rgba(0, 0, 0, 0.5); }
.skins-list { max-height: calc(var(--vh, 1vh) * 36); overflow-y: auto; margin-bottom: 8px; }
.skin-card .swatch { display: inline-block; width: 12px; height: 12px; margin-right: 10px; vertical-align: middle; box-shadow: 0 0 8px currentColor; }
.skin-card.locked { opacity: 0.45; }
.skin-card.equipped em { color: #5dff8a; }
/* Consejos */
.tip-line { font-family: var(--font-mono); font-size: 13px; color: #ffb347; opacity: 0.85; margin: 8px auto 4px; max-width: 520px; text-align: center; }
.tip-line:empty { display: none; }
#boot-tip { position: absolute; bottom: max(28px, env(safe-area-inset-bottom)); left: 0; right: 0; padding: 0 20px; }
/* Estadísticas (pantalla de logros) */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 4px 0 12px; }
.stats-grid div { border: 1px solid rgba(215, 116, 0, 0.3); background: rgba(215, 116, 0, 0.06); padding: 6px 4px; text-align: center; }
.stats-grid b { display: block; font-family: var(--font-pixel); font-weight: normal; font-size: 12px; color: #fff; }
.stats-grid span { display: block; font-size: 10px; letter-spacing: 1px; color: var(--orange); margin-top: 3px; }
/* Compartir resultado */
.btn-share { margin-top: 10px; justify-content: center; padding-left: 14px; border-color: rgba(93, 255, 138, 0.55); color: #5dff8a; font-size: 13px; letter-spacing: 2px; }
.btn-share::before { content: '⇪'; margin-right: 8px; }
.btn-share:hover, .btn-share.focused { background: rgba(93, 255, 138, 0.15); color: #fff; }
/* Reto diario */
.daily-rule { display: flex; flex-direction: column; gap: 8px; padding: 14px; margin: 6px 0 12px; border: 1px solid rgba(255, 43, 214, 0.5); background: rgba(255, 43, 214, 0.08); text-align: left; }
.daily-rule b { font-family: var(--font-pixel); font-weight: normal; font-size: 14px; color: #ff2bd6; text-shadow: 0 0 10px rgba(255, 43, 214, 0.6); }
.daily-rule span { font-size: 15px; color: var(--white); }
.daily-rule em { font-style: normal; font-size: 13px; color: var(--orange); }
#daily-info { color: #ff2bd6; }
/* Llamada a la acción de marca */
a.btn { text-decoration: none; }
.btn-cta { margin-top: 10px; justify-content: center; padding-left: 14px; border-color: rgba(88, 216, 255, 0.55); color: #58d8ff; font-size: 13px; letter-spacing: 2px; }
.btn-cta::after { content: '↗'; margin-left: 8px; }
.btn-cta:hover, .btn-cta.focused { background: rgba(88, 216, 255, 0.18); color: #fff; }
/* Línea de historia entre niveles */
.story-log { font-family: var(--font-mono); font-size: 14px; color: #5dff8a; margin: 10px 0 4px; text-align: left; opacity: 0.9; }
.story-log::before { content: '> LOG: '; color: rgba(93, 255, 138, 0.6); }
.story-log:empty { display: none; }
.mod-card i { font-style: normal; font-size: 0.75em; color: var(--orange); margin-left: 6px; }
.mod-card.focused i, .mod-card:hover i, .mod-card:focus i { color: #000; }
.touch-stack { display: flex; gap: 12px; align-items: center; }

/* Botón táctil del Ataque 404, encima de FIRE (en táctil sustituye al medidor de la esquina del HUD) */
.touch-fire-col { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.touch-btn.b404 { width: 76px; height: 40px; gap: 3px; font-size: 12px; border-color: rgba(255, 43, 214, 0.45); box-shadow: inset 0 0 12px rgba(255, 43, 214, 0.15); }
.touch-btn.b404 span { width: 18px; height: 22px; display: flex; align-items: center; justify-content: center; color: rgba(255, 255, 255, 0.2); border: 1px solid rgba(255, 43, 214, 0.25); }
.touch-btn.b404 span.lit { color: #fff; border-color: #ff2bd6; text-shadow: 0 0 8px #ff2bd6; background: rgba(255, 43, 214, 0.25); }
.touch-btn.b404.ready { border-color: #ff2bd6; animation: ready404 0.5s steps(2) infinite; }
@media (max-width: 768px), (pointer: coarse) { #hud .btn-404 { display: none; } }

/* Celular: controles grandes (bomba y carga apiladas junto a FIRE para que todo quepa) */
body.phone #mobile-controls { align-items: flex-end; bottom: max(14px, env(safe-area-inset-bottom)); padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left)); }
body.phone .touch-group { gap: 10px; }
body.phone .touch-stack { flex-direction: column; gap: 10px; }
body.phone .touch-btn { width: 76px; height: 76px; font-size: 22px; }
body.phone .touch-btn.small { width: 54px; height: 54px; font-size: 22px; }
body.phone .touch-btn.fire { width: 96px; height: 100px; font-size: 16px; }
body.phone .touch-btn.b404 { width: 96px; height: 48px; font-size: 15px; gap: 4px; }
body.phone .touch-btn.b404 span { width: 24px; height: 30px; }
body.phone .hud-stat label { font-size: 11px; }
body.phone .hud-stat span { font-size: 15px; }
body.phone .pause-btn { width: 46px; height: 46px; flex-basis: 46px; font-size: 13px; }

@media (max-width: 768px), (pointer: coarse) { #mobile-controls { display: flex; } }

@media (max-width: 480px) {
  .panel { padding: 16px 16px 20px; }
  .btn { font-size: 14px; letter-spacing: 2px; padding: 10px 12px 10px 28px; }
  .panel-head { font-size: 10px; letter-spacing: 1px; }
  .terminal-log { font-size: 13px; }
}
@media (max-height: 820px) {
  .title-404 { font-size: clamp(48px, calc(var(--vh, 1vh) * 11), 96px); }
  .title-invaders { font-size: clamp(20px, calc(var(--vh, 1vh) * 4.5), 36px); }
  .menu-layout { gap: 12px; }
  .jp { margin: 4px 0; }
  .tag-box { margin-top: 8px; }
}
@media (max-height: 640px) {
  .title-404 { font-size: clamp(48px, calc(var(--vh, 1vh) * 14), 90px); }
  .menu-layout { gap: 10px; }
  .btn { padding-top: 8px; padding-bottom: 8px; }
}

/* ===== Preloader BM LAB en vídeo ===== */
.lab-video { display: block; height: min(calc(var(--vh, 1vh) * 66), 560px); width: auto; max-width: 86%; background: #000; pointer-events: none; }
.lab-fallback { display: none; width: 180px; }
