:root {
  --primary: #7a61a1;
  --primary-dark: #5c4580;
  --primary-glow: rgba(122, 97, 161, 0.45);
  --accent: #ecabce;
  --accent-hot: #ff8fab;
  --surface: #0f1118;
  --surface-2: #1a1d2e;
  --card: #232838;
  --card-hover: #2c3148;
  --text: #f4f5f9;
  --text-muted: #a8b0c8;
  --gold: #ffd54f;
  --gold-dim: #c9a227;
  --ok: #4ade80;
  --ok-dim: #166534;
  --bad: #f87171;
  --bad-dim: #991b1b;
  --warn: #fb923c;
  --radius: 18px;
  --radius-sm: 12px;
  --font: "Poppins", system-ui, sans-serif;
  --focus: 0 0 0 3px var(--primary-glow);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--surface);
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(122, 97, 161, 0.35), transparent),
    radial-gradient(ellipse 60% 40% at 100% 50%, rgba(236, 171, 206, 0.12), transparent);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
  border: none;
}

a {
  color: var(--accent);
}

#confettiLayer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 200;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -12px;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  animation: confetti-fall 2s ease-out var(--delay, 0s) forwards;
  transform: rotate(var(--rot, 0deg));
}

@keyframes confetti-fall {
  to {
    transform: translateY(110vh) rotate(720deg);
    opacity: 0;
  }
}

.hud {
  position: sticky;
  top: 0;
  z-index: 40;
  background: linear-gradient(180deg, var(--surface-2) 0%, rgba(26, 29, 46, 0.92) 100%);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(236, 171, 206, 0.2);
  padding: 0.65rem 1rem 0.75rem;
}

.hud-top {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.hud-avatar {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--accent-hot));
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  box-shadow: 0 4px 16px var(--primary-glow);
  flex-shrink: 0;
  overflow: hidden;
}

.hud-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.55rem;
  margin: 1rem 0;
}

.avatar-opt {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 3px solid transparent;
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
  padding: 4px;
  overflow: hidden;
}

.avatar-opt img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

.avatar-opt.elegido {
  border-color: var(--gold);
  transform: scale(1.06);
  box-shadow: 0 0 16px rgba(255, 213, 79, 0.45);
}

.avatar-maker {
  margin: 0.75rem 0 1rem;
}

.avatar-maker-preview {
  display: flex;
  justify-content: center;
  margin-bottom: 0.85rem;
}

.avatar-maker-preview img {
  width: 112px;
  height: 112px;
  border-radius: 22px;
  border: 3px solid var(--gold);
  box-shadow: 0 8px 24px rgba(122, 97, 161, 0.35);
  background: var(--surface-2);
}

.avatar-maker-aviso {
  font-size: 0.82rem;
  color: #f87171;
  text-align: center;
  margin: 0 0 0.5rem;
}

.avatar-maker-fila {
  margin-bottom: 0.65rem;
}

.avatar-maker-etiq {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.avatar-maker-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.avatar-maker-chips .chip {
  border: 2px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
}

.avatar-maker-chips .chip.activo {
  border-color: var(--gold);
  background: rgba(255, 213, 79, 0.15);
}

.avatar-maker-acciones {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.btn-chico {
  padding: 0.4rem 0.75rem !important;
  font-size: 0.82rem !important;
  min-height: auto;
}

.avatar-maker-fondos {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.fondo-opt {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.fondo-opt.activo {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px var(--bg);
}

.radar-completado {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: rgba(74, 222, 128, 0.12);
  border: 1px solid rgba(74, 222, 128, 0.35);
  border-radius: var(--radius-sm);
}

.radar-completado span.icono {
  font-size: 1.5rem;
}

.hud-info {
  flex: 1;
  min-width: 0;
}

.hud-info h1 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-info span {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
}

.hud-xp {
  text-align: right;
  flex-shrink: 0;
}

.hud-xp b {
  display: block;
  font-size: 0.95rem;
  color: var(--gold);
}

.hud-xp small {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.xp-track {
  height: 8px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 999px;
  margin-top: 0.5rem;
  overflow: hidden;
}

.xp-track span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--gold));
  border-radius: 999px;
  transition: width 0.5s cubic-bezier(0.34, 1.4, 0.64, 1);
  box-shadow: 0 0 12px var(--primary-glow);
}

main {
  max-width: 520px;
  margin: 0 auto;
  padding: 1rem 1rem 6rem;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
  animation: screen-in 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes screen-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.panel {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.15rem;
  margin-bottom: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.panel h2 {
  margin: 0 0 0.4rem;
  font-size: 1.1rem;
  color: #fff;
}

.panel > p {
  margin: 0 0 0.85rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.tag {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  background: rgba(236, 171, 206, 0.15);
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  margin-bottom: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 50px;
  padding: 0.7rem 1.2rem;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.95rem;
  width: 100%;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s;
}

.btn:active {
  transform: scale(0.96);
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.btn-primario {
  background: linear-gradient(135deg, var(--primary) 0%, #9b7bc4 100%);
  color: #fff;
  box-shadow: 0 6px 20px var(--primary-glow);
}

.btn-secundario {
  background: rgba(236, 171, 206, 0.2);
  color: #fff;
  border: 2px solid rgba(236, 171, 206, 0.4);
}

.btn-fantasma {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.btn-oro {
  background: linear-gradient(135deg, var(--gold-dim), var(--gold));
  color: #1a1200;
  box-shadow: 0 6px 20px rgba(255, 213, 79, 0.35);
}

.btn-row {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 1rem;
}

.paso-indicador {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.barra-progreso {
  height: 10px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 999px;
  overflow: hidden;
  margin: 0.6rem 0 1rem;
}

.barra-progreso span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent-hot));
  border-radius: 999px;
  transition: width 0.4s cubic-bezier(0.34, 1.2, 0.64, 1);
}

.pregunta-titulo {
  font-size: 1.12rem;
  font-weight: 700;
  margin: 0 0 0.75rem;
  line-height: 1.35;
}

.opciones {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.opcion {
  text-align: left;
  padding: 0.9rem 1rem 0.9rem 3rem;
  background: var(--surface-2);
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 500;
  position: relative;
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
}

.opcion::before {
  content: attr(data-letra);
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: rgba(122, 97, 161, 0.35);
  font-size: 0.75rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  color: #fff;
}

.opcion:hover:not(:disabled) {
  border-color: var(--accent);
  transform: translateX(4px);
}

.opcion.elegida {
  border-color: var(--primary);
  background: rgba(122, 97, 161, 0.25);
}

.opcion.correcta {
  border-color: var(--ok);
  background: rgba(74, 222, 128, 0.15);
}

.opcion.incorrecta {
  border-color: var(--bad);
  background: rgba(248, 113, 113, 0.12);
}

.opcion:disabled {
  opacity: 0.85;
  cursor: default;
}

.caso {
  background: rgba(251, 146, 60, 0.12);
  border-left: 4px solid var(--warn);
  padding: 0.95rem 1rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 0.85rem 0;
  font-size: 0.92rem;
  line-height: 1.45;
}

.caso.peligro {
  border-left-color: var(--bad);
  background: rgba(248, 113, 113, 0.1);
}

.resultado {
  padding: 0.9rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0.85rem 0;
  animation: pop-in 0.35s ease;
}

.resultado.bien {
  background: rgba(74, 222, 128, 0.15);
  color: var(--ok);
  border: 1px solid rgba(74, 222, 128, 0.35);
}

.resultado.mal {
  background: rgba(248, 113, 113, 0.12);
  color: var(--bad);
  border: 1px solid rgba(248, 113, 113, 0.3);
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.pop {
  animation: pop-scale 0.4s cubic-bezier(0.34, 1.5, 0.64, 1);
}

@keyframes pop-scale {
  50% {
    transform: scale(1.04);
  }
}

.shake {
  animation: shake-anim 0.45s ease;
}

@keyframes shake-anim {
  20%,
  60% {
    transform: translateX(-6px);
  }
  40%,
  80% {
    transform: translateX(6px);
  }
}

textarea {
  width: 100%;
  min-height: 110px;
  padding: 0.8rem;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  resize: vertical;
  margin: 0.5rem 0;
}

textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus);
}

.lista-check {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0;
}

.lista-check label {
  display: flex;
  gap: 0.65rem;
  padding: 0.65rem 0;
  cursor: pointer;
  font-size: 0.9rem;
}

.lista-check input {
  width: 22px;
  height: 22px;
  accent-color: var(--primary);
}

.mapa-misiones {
  display: flex;
  flex-direction: column;
  gap: 0;
  position: relative;
  padding-left: 1.5rem;
}

.mapa-misiones::before {
  content: "";
  position: absolute;
  left: 0.55rem;
  top: 24px;
  bottom: 24px;
  width: 3px;
  background: linear-gradient(180deg, var(--primary), var(--accent));
  border-radius: 999px;
  opacity: 0.4;
}

.nodo-mision {
  display: flex;
  align-items: stretch;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  position: relative;
}

.nodo-punto {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 3px solid var(--primary);
  flex-shrink: 0;
  margin-top: 1.1rem;
  z-index: 1;
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  font-weight: 800;
}

.nodo-mision.completa .nodo-punto {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
}

.nodo-mision.bloqueada .nodo-punto {
  border-color: #444;
  background: #2a2a35;
  color: #666;
}

.nodo-mision.bloqueada .tarjeta-mision {
  opacity: 0.55;
  pointer-events: none;
}

.tarjeta-mision {
  flex: 1;
  text-align: left;
  padding: 1rem;
  background: var(--card);
  border-radius: var(--radius);
  border: 2px solid transparent;
  color: inherit;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.tarjeta-mision:not(:disabled):hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.tarjeta-mision.completa {
  border-color: var(--ok);
  background: rgba(74, 222, 128, 0.08);
}

.tarjeta-mision h3 {
  margin: 0;
  font-size: 0.98rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.tarjeta-mision small {
  display: block;
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-top: 0.2rem;
}

.tarjeta-mision .xp-chip {
  display: inline-block;
  margin-top: 0.45rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--gold);
  background: rgba(255, 213, 79, 0.15);
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
}

.input-apodo {
  width: 100%;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  border: 2px solid rgba(255, 255, 255, 0.12);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  margin: 0.5rem 0 1rem;
}

.input-apodo:focus {
  outline: none;
  border-color: var(--primary);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 150;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  animation: fade-overlay 0.25s ease;
}

.overlay.visible {
  display: flex;
}

@keyframes fade-overlay {
  from {
    opacity: 0;
  }
}

.overlay-card {
  background: linear-gradient(160deg, var(--card) 0%, var(--surface-2) 100%);
  border-radius: 24px;
  padding: 1.75rem 1.5rem;
  text-align: center;
  max-width: 340px;
  width: 100%;
  border: 2px solid var(--gold);
  box-shadow: 0 0 60px rgba(255, 213, 79, 0.25);
  animation: pop-in 0.4s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.overlay-emoji {
  font-size: 3.5rem;
  margin-bottom: 0.5rem;
  animation: float 1.5s ease-in-out infinite;
}

@keyframes float {
  50% {
    transform: translateY(-8px);
  }
}

.overlay-card h2 {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
}

.overlay-card p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0 0 1rem;
}

.overlay-xp {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--gold);
  margin-bottom: 1rem;
}

.medallas-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.medalla {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  background: rgba(122, 97, 161, 0.35);
  color: #e8d4ff;
}

.medalla.obtenida {
  background: rgba(255, 213, 79, 0.25);
  color: var(--gold);
}

.resumen-caja {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 1rem;
  font-size: 0.88rem;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0.75rem 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.nav-inferior {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(26, 29, 46, 0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0.45rem 1rem calc(0.45rem + env(safe-area-inset-bottom));
  display: flex;
  gap: 0.45rem;
  max-width: 520px;
  margin: 0 auto;
  z-index: 50;
}

.nav-inferior .btn {
  flex: 1;
  min-height: 44px;
  font-size: 0.82rem;
}

.aviso-red {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.racha-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: linear-gradient(90deg, #ff6b35, #ff8fab);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  margin-left: 0.35rem;
  animation: pop-in 0.3s ease;
}

.toast {
  position: fixed;
  bottom: 5.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--card);
  color: #fff;
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  border: 1px solid var(--gold);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 120;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.hero-inicio {
  text-align: center;
  padding: 0.5rem 0 1rem;
}

.hero-inicio .logo-grande {
  font-size: 2.5rem;
  margin-bottom: 0.25rem;
}

.enlaces-footer {
  font-size: 0.85rem;
  line-height: 1.8;
}

.enlaces-footer a {
  color: var(--accent);
}

@media (min-width: 480px) {
  .btn-row {
    flex-direction: row;
  }
  .btn-row .btn {
    flex: 1;
  }
}

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