/* ═══════════════════════════════════════════════════════════
   Desbloquea mi Portafolio — paleta de marca: azul noche +
   cian/rosa neón (misma identidad que el resto del sitio)
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg: #0b0e1a;
  --bg-soft: #10131f;
  --panel: rgba(244, 246, 255, 0.06);
  --panel-strong: rgba(244, 246, 255, 0.1);
  --border: rgba(244, 246, 255, 0.12);
  --text: #f4f6ff;
  --text-dim: #9aa3c0;
  --cyan: #39d0ff;
  --cyan-soft: #7fe0ff;
  --pink: #ff5ea8;
  --pink-soft: #ff8cc4;
  --heart: #ff4d6d;
  --ok: #7bff8e;
  --radius: 16px;
  --radius-sm: 10px;
  font-family: -apple-system, system-ui, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app { position: fixed; inset: 0; }
#app canvas { display: block; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  color: inherit;
}

.hidden { display: none !important; }

/* ---------- vidrio reutilizable ---------- */
.glass {
  background: var(--panel);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border-radius: var(--radius);
}

/* ---------- HUD superior ---------- */
#hud {
  position: fixed;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  z-index: 20;
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 16px;
  font-weight: 900;
  letter-spacing: 0.08em;
  font-size: 15px;
}
.brand span { color: var(--cyan); }

.hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
}
.chip b { color: var(--text); font-weight: 700; }

#hud-vidas .life-track {
  display: flex;
  gap: 2px;
  font-size: 15px;
  line-height: 1;
}
.life-pip { color: rgba(255, 255, 255, 0.16); transition: color 0.2s ease, opacity 0.2s ease; }
.life-pip.full { color: var(--heart); opacity: 1; }
.life-pip.half { color: var(--heart); opacity: 0.55; }

#hud-escudo {
  color: var(--pink);
  border-color: rgba(255, 94, 168, 0.35);
  background: rgba(255, 94, 168, 0.1);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
#hud-escudo.hidden { opacity: 0; pointer-events: none; }

#hud-pair {
  color: var(--cyan-soft);
  border-color: rgba(57, 208, 255, 0.35);
  background: rgba(57, 208, 255, 0.1);
}

#hud-streak {
  color: var(--ok);
  border-color: rgba(123, 255, 142, 0.35);
  background: rgba(123, 255, 142, 0.1);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
#hud-streak.hidden { opacity: 0; pointer-events: none; }

/* ---------- flash de rayo (zona de muerte) ---------- */
#flash-overlay {
  position: fixed;
  inset: 0;
  z-index: 30; /* sobre el HUD (20), debajo de los overlays modales (40) */
  pointer-events: none;
  background: #fff2cc;
  opacity: 0;
}
#flash-overlay.flash { animation: lightningFlash 0.5s ease-out; }
@keyframes lightningFlash {
  0% { opacity: 0; }
  6% { opacity: 0.85; }
  100% { opacity: 0; }
}

/* ---------- botón QR ---------- */
#qr-btn {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 20;
  width: 52px;
  height: 52px;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#qr-btn:active { transform: scale(0.94); }

/* ---------- ayuda de controles ---------- */
#hud-help {
  position: fixed;
  bottom: 20px;
  left: 86px;
  z-index: 15;
  padding: 10px 16px;
  font-size: 12.5px;
  color: var(--text-dim);
}
#hud-help b { color: var(--cyan-soft); }

/* ---------- feed de colaboración ---------- */
#hud-feed {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 20;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  width: min(320px, 42vw);
  pointer-events: none;
  align-items: flex-end;
}
.feed-msg {
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  animation: feedIn 0.25s ease-out;
  max-width: 100%;
  text-align: right;
}
.feed-msg.leaving { animation: feedOut 0.4s ease forwards; }
@keyframes feedIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes feedOut {
  to { opacity: 0; transform: translateX(12px); }
}

/* ---------- overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 40%, rgba(16, 22, 46, 0.6), rgba(5, 6, 12, 0.9));
  transition: opacity 0.3s ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }

.panel {
  padding: 34px 38px;
  max-width: 420px;
  width: calc(100% - 48px);
  text-align: center;
}

.panel h1 {
  margin: 0 0 10px;
  font-size: clamp(30px, 7vw, 40px);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  background: linear-gradient(180deg, #ffffff 30%, #7f8cb3 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.panel h1 span {
  background: linear-gradient(180deg, var(--cyan-soft), var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.panel h2 {
  margin: 0 0 10px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.panel h2 span { color: var(--cyan); }
.panel .sub {
  color: var(--text-dim);
  font-size: 14.5px;
  line-height: 1.5;
  margin: 0 0 20px;
}

.panel img.qr {
  width: 168px;
  height: 168px;
  border-radius: 12px;
  background: #fff;
  padding: 8px;
  margin: 4px auto 14px;
  display: block;
}
.panel img.qr.qr-big {
  width: 208px;
  height: 208px;
}

.qr-lead {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
  color: var(--cyan-soft);
}

.panel .url {
  font-size: 12px;
  color: var(--text-dim);
  word-break: break-all;
  margin: 0 0 18px;
}

.cta {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--cyan-soft), var(--cyan));
  color: #04141f;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 24px rgba(57, 208, 255, 0.35);
}
.cta:active { transform: translateY(1px); }

.cta-ghost {
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 13.5px;
}

#loading {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text-dim);
  font-size: 14px;
  letter-spacing: 0.04em;
  transition: opacity 0.4s ease;
}
#loading.done { opacity: 0; pointer-events: none; }

/* ═══════════════════════════════════════════════════════════
   Celular — controller.html
   ═══════════════════════════════════════════════════════════ */

.ctl-body {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top, 14px) 18px calc(env(safe-area-inset-bottom, 14px) + 6px);
  overflow: hidden;
}

.ctl-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  margin-bottom: 14px;
}
#ctl-name { font-weight: 800; letter-spacing: 0.04em; font-size: 14px; }
.status { font-size: 12px; font-weight: 700; color: var(--text-dim); }
.status.connected { color: var(--ok); }
.status.error { color: var(--heart); }

.ctl-main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: end;
  gap: 16px;
}

.joy-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.joy-zone {
  width: 168px;
  height: 168px;
  border-radius: 50%;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.joy {
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.1), rgba(255,255,255,0.02));
  border: 1px solid var(--border);
  position: relative;
}
.joy-knob {
  position: absolute;
  top: 50%; left: 50%;
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--cyan-soft), var(--cyan));
  box-shadow: 0 0 22px rgba(57, 208, 255, 0.55);
  transition: transform 0.05s linear;
}
.joy-label { font-size: 11.5px; color: var(--text-dim); letter-spacing: 0.08em; }

.actions { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.big-btn {
  width: 140px;
  height: 76px;
  border-radius: 18px;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.08s ease, filter 0.08s ease;
}
.big-btn:active { transform: scale(0.95); filter: brightness(1.15); }

#jump-btn {
  background: linear-gradient(180deg, var(--cyan-soft), #1b7fb0);
  color: #04141f;
  box-shadow: 0 8px 22px rgba(57, 208, 255, 0.35);
}
#revive-btn {
  background: linear-gradient(180deg, var(--pink-soft), var(--pink));
  color: #3a0a24;
  box-shadow: 0 8px 22px rgba(255, 94, 168, 0.3);
}

#gyro-btn {
  margin-top: 6px;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  width: 100%;
}
#gyro-btn.active { color: var(--cyan); border-color: rgba(57, 208, 255, 0.4); }

.ctl-footer {
  text-align: center;
  padding-top: 12px;
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.7;
}

@media (max-width: 380px) {
  .joy-zone { width: 148px; height: 148px; }
  .joy { width: 116px; height: 116px; }
  .big-btn { width: 120px; height: 68px; font-size: 13px; }
}

.ctl-error {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  color: var(--text-dim);
}
.ctl-error p { margin: 0; font-size: 15px; }
.ctl-error .sub { font-size: 13px; opacity: 0.8; }

/* ═══════════════════════════════════════════════════════════
   Overlay táctil sobre el canvas 3D — jugador independiente en
   celular (rol 2): mismo joystick/botones que pair.html, pero
   flotando sobre la escena en vez de ser una página aparte.
   ═══════════════════════════════════════════════════════════ */
.touch-overlay {
  position: fixed;
  inset: 0;
  z-index: 25;
  pointer-events: none;
}
/* .touch-controls es un wrapper transparente: sus hijos (.joy-wrap/.actions)
   se posicionan solos vía fixed, no participan de ningún layout del padre. */
.touch-controls { display: contents; }

.touch-overlay .joy-wrap {
  position: fixed;
  left: 22px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
  pointer-events: auto;
}
.touch-overlay .actions {
  position: fixed;
  right: 22px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
  pointer-events: auto;
}

/* En pantallas táctiles, el joystick ocupa la esquina donde viven el botón
   de QR y la pista de controles — se reacomodan para no superponerse. */
@media (pointer: coarse) {
  #hud-help { display: none; }
  #qr-btn {
    left: 50%;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 20px);
    transform: translateX(-50%);
  }
  #qr-btn:active { transform: translateX(-50%) scale(0.94); }
}
