:root {
  --sky-top: #4a90d9;
  --sky-bottom: #bfe3ff;
  --ring: rgba(29, 53, 87, 0.18);
  --accent: #c1121f;
  --accent-dark: #8d0f1a;
  --whatsapp: #25d366;
  --card-bg: #ffffff;
  --ink: #1d3557;
  --cyan: #3fe0e8;
  --void: #0d0917;
  --panel: #1a1430;
  --panel-lit: #3a3453;
  --panel-dark: #241f38;
  --text: #e8e4f5;
  --pixel: "Press Start 2P", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  overflow: hidden;
  background: #050b16;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

.scene {
  position: relative;
  width: min(100vw, 100dvh * 0.59802711);
  height: min(100dvh, 100vw * 1.67216495);
  overflow: hidden;
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.5);
  background: var(--void);
}

.map-layer,
.maze-shell {
  position: absolute;
  inset: 0;
}

.map-layer[hidden],
.maze-shell[hidden] {
  display: none;
}

.mute-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 60;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(10, 20, 40, 0.55);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}
.mute-btn:active { transform: scale(0.92); }

.map-bg {
  position: absolute;
  inset: 0;
  background-image: url("assets/mapa.png");
  background-size: 100% 100%;
  background-repeat: no-repeat;
}

.hero {
  position: absolute;
  left: 12%;
  top: 15%;
  z-index: 6;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.25));
  transform: translate(-50%, -50%);
}
.hero img {
  display: block;
  width: 15vw;
  min-width: 64px;
  max-width: 120px;
  height: auto;
  pointer-events: none;
}

.target {
  position: absolute;
  width: 48px;
  height: 48px;
  border: none;
  background: transparent;
  cursor: pointer;
  transform: translate(-50%, -50%);
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
}
.target-dot {
  width: 36px;
  height: 36px;
  display: block;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}
.target-pulse {
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(193, 18, 31, 0.5);
  animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(2.6); opacity: 0; }
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 20, 40, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 5vw;
}
.overlay[hidden] { display: none; }

.card {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}
.card-emoji {
  font-size: 48px;
  margin-bottom: 8px;
}
.card h1,
.card h2 {
  font-size: clamp(20px, 5vw, 26px);
  margin: 0 0 12px;
}
.card p {
  margin: 0 0 20px;
  color: #4a5568;
  line-height: 1.5;
}

.btn {
  display: inline-block;
  border: none;
  border-radius: 999px;
  padding: 14px 28px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  background: var(--accent);
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 8px 16px rgba(0,0,0,0.2); }
.btn:active { transform: translateY(0); }

.btn-whatsapp {
  background: var(--whatsapp);
  width: 100%;
  margin-top: 4px;
}

.banner {
  position: absolute;
  top: 5%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.95);
  padding: 8px 20px 8px 12px;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: 0 6px 16px rgba(0,0,0,0.2);
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 90%;
  text-align: left;
}
.banner[hidden] { display: none; }
.banner-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.code {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 2px;
  background: #f1f5f9;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 20px;
  color: var(--accent-dark);
}

/* ===== Laberinto Laser ===== */
.maze-shell {
  display: flex;
  flex-direction: column;
  background: var(--void);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

.maze-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: 6px;
  overflow: hidden;
}

#game {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.pad {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px clamp(12px, 5vw, 34px) clamp(16px, 4vh, 28px);
}

.dpad {
  --k: clamp(52px, 15vw, 74px);
  display: grid;
  grid-template-columns: repeat(3, var(--k));
  grid-template-rows: repeat(3, var(--k));
  gap: 3px;
  touch-action: none;
}

.dbtn {
  border: none;
  border-radius: 50%;
  background: #8f87b8;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.28), inset 0 5px 0 rgba(255, 255, 255, 0.22);
  cursor: pointer;
  touch-action: none;
  position: relative;
}

.dbtn.on {
  background: var(--cyan);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.3);
}

.dbtn::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 30%;
  height: 30%;
  border-top: 5px solid #241f38;
  border-right: 5px solid #241f38;
  transform: translate(-50%, -50%) rotate(var(--rot));
}

.dbtn.up { grid-area: 1 / 2; --rot: -45deg; }
.dbtn.left { grid-area: 2 / 1; --rot: -135deg; }
.dbtn.right { grid-area: 2 / 3; --rot: 45deg; }
.dbtn.down { grid-area: 3 / 2; --rot: 135deg; }

.tp-btn {
  --cd: 1;
  position: relative;
  width: clamp(64px, 19vw, 92px);
  height: clamp(64px, 19vw, 92px);
  border: none;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.28), inset 0 5px 0 rgba(255, 255, 255, 0.3);
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: none;
  overflow: hidden;
}

.tp-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(transparent calc(var(--cd) * 360deg), rgba(9, 14, 26, 0.68) 0);
  pointer-events: none;
}

.tp-btn.cooling {
  background: #5d8f96;
}

.tp-btn:active:not(.cooling) {
  box-shadow: inset 0 5px 0 rgba(0, 0, 0, 0.32);
  transform: translateY(2px);
}

.tp-icon {
  position: relative;
  width: 52%;
  height: 44%;
  display: block;
}

.tp-icon::before,
.tp-icon::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 62%;
  height: 62%;
  border-top: 5px solid #0d2b31;
  border-right: 5px solid #0d2b31;
  transform: translateY(-50%) rotate(45deg);
}

.tp-icon::before { left: 0; }
.tp-icon::after { left: 34%; }

.exit-flash {
  position: absolute;
  left: 50%;
  top: 62px;
  transform: translateX(-50%);
  z-index: 4;
  padding: 8px 14px;
  background: var(--cyan);
  color: #06232a;
  border: 2px solid #0d0917;
  font-family: var(--pixel);
  font-size: 10px;
  pointer-events: none;
  animation: pop 0.3s steps(3);
}

@keyframes pop {
  from {
    transform: translateX(-50%) scale(0.6);
    opacity: 0;
  }
}

.maze-overlay {
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(13, 9, 23, 0.9);
  z-index: 30;
  overflow-y: auto;
}

.maze-card {
  width: min(340px, 100%);
  padding: 22px 18px;
  background: var(--panel);
  border: 3px solid #0d0917;
  border-radius: 0;
  box-shadow: inset 0 3px 0 var(--panel-lit), inset 0 -3px 0 var(--panel-dark);
  text-align: center;
  color: var(--text);
  animation: cardIn 0.24s steps(4);
}

@keyframes cardIn {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
}

.maze-card h1,
.maze-card h2 {
  font-family: var(--pixel);
  font-size: clamp(15px, 4.5vw, 20px);
  line-height: 1.5;
  color: var(--cyan);
  text-shadow: 0 3px 0 #0d0917;
  margin-bottom: 14px;
}

.maze-card h1.danger,
.maze-card h2.danger {
  color: var(--accent);
}

.maze-card p {
  font-size: 14px;
  line-height: 1.55;
  opacity: 0.8;
  margin-bottom: 12px;
  color: var(--text);
}

.maze-card .btn,
#retryBtn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 14px 10px;
  border: 3px solid #0d0917;
  border-radius: 0;
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.28), inset 0 -3px 0 rgba(0, 0, 0, 0.35);
  background: var(--accent);
  color: #fff;
  font-family: var(--pixel);
  font-size: clamp(9px, 2.8vw, 11px);
  line-height: 1.5;
}

@media (prefers-reduced-motion: reduce) {
  .maze-card,
  .exit-flash {
    animation: none;
  }
}

@media (max-width: 480px) {
  html, body {
    background: #050b16;
  }

  body {
    align-items: stretch;
  }

  .scene {
    width: 100vw;
    height: 100dvh;
    box-shadow: none;
  }

  .card { padding: 24px 20px; }
}
