:root {
  color-scheme: dark;
  --fondo: #1c1d42;
  --crema: #fff3cf;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--fondo);
}

main {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#escena {
  position: absolute;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#fundido {
  position: absolute;
  inset: 0;
  background: #0f1030;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s steps(6);
}
#fundido.activo { opacity: 1; }

/* Replay (abajo a la derecha) y sonido (abajo a la izquierda): mismo marco. */
#repetir,
#sonido {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom));
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 2px solid var(--crema);
  border-radius: 0;
  background: rgba(15, 16, 48, 0.82);
  /* sombra dura de 2 px, como el título */
  box-shadow: 2px 2px 0 #120e22;
  color: var(--crema);
  cursor: pointer;
  animation: aparecer 0.9s steps(8) both;
}
#repetir { right: max(16px, env(safe-area-inset-right)); }
#sonido { left: max(16px, env(safe-area-inset-left)); }
#repetir[hidden], #sonido[hidden] { display: none; }
#repetir:hover, #sonido:hover { background: #2a2350; color: #ffffff; }
#repetir:active, #sonido:active { transform: translate(2px, 2px); box-shadow: none; }
/* foco de teclado: doble anillo crema/oscuro, visible sobre cielo y suelo */
#repetir:focus-visible, #sonido:focus-visible { outline: 3px solid #ffc870; outline-offset: 3px; box-shadow: 0 0 0 3px #120e22; }
#repetir svg, #sonido svg { display: block; image-rendering: pixelated; }
/* apagado: altavoz con X; encendido: altavoz con ondas */
#sonido .ondas, #sonido.encendido .mudo { display: none; }
#sonido.encendido .ondas { display: inline; }

/* Botones de texto (Jugar, Reintentar): el mismo marco pixelado que Ver de nuevo. */
.boton-texto {
  min-width: 48px;
  min-height: 48px;
  padding: 0 24px;
  border: 2px solid var(--crema);
  border-radius: 0;
  background: rgba(15, 16, 48, 0.82);
  box-shadow: 2px 2px 0 #120e22;
  color: var(--crema);
  font: 700 20px/1 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
  cursor: pointer;
}
.boton-texto[hidden] { display: none; }
.boton-texto:hover { background: #2a2350; color: #ffffff; }
.boton-texto:active { transform: translate(2px, 2px); box-shadow: none; }
.boton-texto:focus-visible { outline: 3px solid #ffc870; outline-offset: 3px; box-shadow: 0 0 0 3px #120e22; }

/* Abajo al centro, a la altura de Ver de nuevo: en horizontal cae sobre la vía,
   por debajo de la pareja; en vertical, sobre el pasto. */
#jugar {
  position: absolute;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  width: 136px;
  margin-left: -68px;
  animation: aparecer 0.9s steps(8) both;
}

.resultado,
.pista,
.aviso,
.rutas {
  color: var(--crema);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-weight: 700;
}
.resultado[hidden], .pista[hidden], .aviso[hidden], .rutas[hidden] { display: none; }

/* Puntaje tras ganar, arriba a la izquierda (el título va centrado). */
.resultado {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  top: max(12px, env(safe-area-inset-top));
  max-width: calc(100% - 24px);
  margin: 0;
  padding: 6px 10px;
  border: 2px solid var(--crema);
  background: rgba(15, 16, 48, 0.82);
  box-shadow: 2px 2px 0 #120e22;
  font-size: 14px;
  line-height: 1.3;
  animation: aparecer 0.9s steps(8) both;
}

/* Ayuda al empezar: no tapa los toques. */
.pista {
  position: absolute;
  left: 50%;
  top: 30%;
  width: min(90vw, 360px);
  margin: 0 0 0 calc(min(90vw, 360px) / -2);
  text-align: center;
  font-size: 16px;
  line-height: 1.4;
  padding: 8px 10px;
  background: rgba(15, 16, 48, 0.6);
  text-shadow: 2px 2px 0 #120e22;
  pointer-events: none;
  animation: aparecer 0.6s steps(6) both;
}

.aviso,
.rutas {
  position: absolute;
  left: 50%;
  top: 22%;
  width: min(88vw, 340px);
  margin-left: calc(min(88vw, 340px) / -2);
  padding: 16px 16px 18px;
  border: 2px solid var(--crema);
  background: rgba(15, 16, 48, 0.9);
  box-shadow: 2px 2px 0 #120e22;
  text-align: center;
  animation: aparecer 0.5s steps(5) both;
}
.aviso-titulo { margin: 0 0 8px; font-size: 22px; color: #ffc870; }
.aviso-texto { margin: 0 0 8px; font-size: 15px; line-height: 1.4; font-weight: 400; }
.aviso-puntos { margin: 0 0 14px; font-size: 15px; }

/* Selector de ruta: dos botones grandes lado a lado; la marcada, en dorado. */
.rutas-opciones { display: flex; gap: 10px; }
.boton-ruta {
  flex: 1 1 0;
  min-height: 72px;
  padding: 10px 6px;
  border: 2px solid var(--crema);
  border-radius: 0;
  background: rgba(15, 16, 48, 0.82);
  box-shadow: 2px 2px 0 #120e22;
  color: var(--crema);
  font-family: inherit;
  cursor: pointer;
}
.boton-ruta.marcada { border-color: #ffc870; background: #2a2350; color: #ffffff; }
.boton-ruta:hover { background: #2a2350; color: #ffffff; }
.boton-ruta:active { transform: translate(2px, 2px); box-shadow: none; }
.boton-ruta:focus-visible { outline: 3px solid #ffc870; outline-offset: 3px; }
.ruta-nombre { display: block; font-size: 19px; font-weight: 700; letter-spacing: 0.04em; }
.ruta-detalle { display: block; margin-top: 6px; font-size: 12px; font-weight: 400; line-height: 1.3; }
.rutas-ayuda { margin: 12px 0 0; font-size: 12px; font-weight: 400; opacity: 0.85; }
/* En pantallas táctiles la ayuda de teclado sobra. */
@media (pointer: coarse) { .rutas-ayuda { display: none; } }

/* Durante el juego, tocar la pantalla es saltar: sin scroll, zoom ni selección. */
body.jugando main {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: pointer;
}

/* Mide la muesca del móvil para bajar el marcador del juego. */
#sonda-seguro {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: env(safe-area-inset-top, 0px);
  visibility: hidden;
  pointer-events: none;
}

@keyframes aparecer {
  from { opacity: 0; }
  to { opacity: 1; }
}

.oculto {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.sin-js {
  color: var(--crema);
  font: 700 2rem/1.2 monospace;
  text-align: center;
  margin-top: 40vh;
}

@media (prefers-reduced-motion: reduce) {
  #repetir, #sonido, #jugar, .resultado, .pista, .aviso, .rutas { animation: none; }
  #fundido { transition: none; }
}
