/*
  Estilo "Game Boy Color".
  Todos los colores están aquí arriba como variables: si quieres otra paleta,
  solo cambias estas líneas.
*/
@font-face {
  font-family: "PressStart";
  src: url("../fonts/PressStart2P-Regular.ttf") format("truetype");
  font-display: swap;
}

:root {
  --carcasa: #3f9b3a;        /* verde hoja de Pikmin (en Pokégotchi es rojo: #d42a2f) */
  --carcasa-sombra: #23661f;
  --fondo: #1f1f28;
  --pantalla: #f8f8e8;       /* blanco roto de la pantalla */
  --tinta: #202028;
  --tinta-suave: #686878;
  --acento: #e03838;
  --marco: #3a3a48;
  --boton: #f8f8e8;
  --pixel: 4px;              /* tamaño de un "píxel" de la interfaz */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--fondo);
  color: var(--tinta);
  font-family: "PressStart", monospace;
  font-size: 11px;
  line-height: 1.6;
  /* Evita que el móvil haga zoom con doble toque mientras juegas */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  justify-content: center;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}

/* La "consola": la carcasa roja que rodea la pantalla */
.consola {
  width: 100%;
  max-width: 420px;
  background: var(--carcasa);
  border-radius: 12px 12px 48px 12px;
  padding: 20px 20px 16px;
  box-shadow: inset -6px -6px 0 var(--carcasa-sombra);
}

.pantalla {
  background: var(--pantalla);
  border: var(--pixel) solid var(--marco);
  border-radius: 4px;
  outline: 12px solid var(--marco);
  outline-offset: 0;
  margin: 12px;
  /* Altura fija, la de la pantalla principal: así la consola no cambia de tamaño
     al pasar de una pantalla a otra. Si algo no cabe, se desplaza por dentro. */
  height: 720px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
/* Nada se aplasta para caber: si no hay sitio, la pantalla se desplaza por dentro */
.pantalla > * { flex-shrink: 0; }

.marca {
  text-align: center;
  color: #fff4f0;
  font-size: 10px;
  margin: 24px 0 0;
  letter-spacing: 1px;
}
.marca span { color: #ffd84a; }

h1, h2 { font-size: 12px; margin: 0; text-align: center; font-weight: normal; }
p { margin: 0; }
.cargando { margin: auto; }
.suave { color: var(--tinta-suave); }
.centro { text-align: center; }

/* Los sprites son diminutos (56x56). "pixelated" los amplía sin difuminarlos. */
.sprite {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

/* --- Pantalla de elegir inicial --- */
.iniciales {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.inicial {
  font: inherit;
  font-size: 8px;
  color: var(--tinta);
  background: none;
  border: var(--pixel) solid transparent;
  padding: 4px 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.inicial .sprite { width: 108px; max-width: 100%; aspect-ratio: 1; } /* 36 px x3 */
.inicial[aria-pressed="true"] { border-color: var(--tinta); }

/* Caja de texto como la de los juegos */
.dialogo {
  border: var(--pixel) double var(--tinta);
  border-width: 6px;
  padding: 10px;
  min-height: 72px;
}

/* --- Pantalla principal --- */
.cabecera { display: flex; justify-content: space-between; font-size: 9px; }
.escenario {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
/* El canvas mide 64x64 "píxeles de consola"; aquí lo ampliamos x4 */
.escenario .sprite { width: 256px; max-width: 100%; aspect-ratio: 1; }

/* Reacciones extra con CSS. steps() hace que vayan "a saltos", como en una consola antigua */
.escenario .sprite.niega { animation: niega 0.4s steps(4) 2; }
.escenario .sprite.evoluciona { animation: evoluciona 0.25s steps(2) 8; }

@keyframes niega {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(calc(var(--pixel) * -2)); }
  75% { transform: translateX(calc(var(--pixel) * 2)); }
}
/* Parpadeo en blanco, como la animación de evolución de los juegos */
@keyframes evoluciona {
  from { filter: brightness(1); }
  to { filter: brightness(0) invert(1); }
}

.zzz {
  position: absolute;
  top: 16px;
  right: 24px;
  font-size: 10px;
  color: var(--tinta-suave);
  animation: respira 1.2s steps(2) infinite;
}

/* Caja de texto con el retrato a la izquierda, como en Mundo Misterioso */
.dialogo.con-retrato { display: flex; gap: 10px; align-items: flex-start; }
.retrato {
  width: 80px;
  height: 80px;
  flex: none;
  image-rendering: pixelated;
  border: 2px solid var(--tinta);
}

.creditos { display: flex; flex-direction: column; gap: 12px; font-size: 9px; overflow-wrap: anywhere; }

/* Barras de COMIDA, ÁNIMO e HIGIENE, al estilo de la barra de PS */
.barras { display: flex; flex-direction: column; gap: 6px; font-size: 8px; }
.fila-barra { display: grid; grid-template-columns: 9ch 1fr; align-items: center; gap: 8px; }
.barra {
  height: 10px;
  border: 2px solid var(--tinta);
  background: #fff;
  padding: 1px;
}
.relleno { height: 100%; transition: width 0.4s steps(6); }
.relleno.verde { background: #38b848; }
.relleno.amarilla { background: #f8c030; }
.relleno.roja { background: #e03838; }

.pruebas {
  border: 2px dashed var(--tinta-suave);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 8px;
}

/* Animación muy simple: sube y baja 1 "píxel", a saltos, como en Game Boy */
@keyframes respira {
  from { transform: translateY(0); }
  to   { transform: translateY(calc(var(--pixel) * -1)); }
}
@media (prefers-reduced-motion: reduce) {
  .escenario .sprite.niega, .escenario .sprite.evoluciona, .zzz { animation: none; }
}

/* --- Botones --- */
.botones { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.boton {
  font: inherit;
  font-size: 9px;
  color: var(--tinta);
  background: var(--boton);
  border: var(--pixel) solid var(--tinta);
  box-shadow: var(--pixel) var(--pixel) 0 var(--tinta);
  padding: 10px 4px;
  cursor: pointer;
}
.boton:active:not(:disabled) { transform: translate(var(--pixel), var(--pixel)); box-shadow: none; }
.boton:disabled { color: var(--tinta-suave); border-color: var(--tinta-suave); box-shadow: none; cursor: default; }
.boton.principal { background: var(--acento); color: #fff; }
.boton.ancho { grid-column: 1 / -1; }

input[type="text"] {
  font: inherit;
  width: 100%;
  padding: 8px;
  border: var(--pixel) solid var(--tinta);
  background: #fff;
  color: var(--tinta);
}

.pie { display: flex; justify-content: space-between; }
.enlace {
  font: inherit; font-size: 8px; background: none; border: none;
  color: var(--tinta-suave); text-decoration: underline; cursor: pointer; padding: 4px;
}

/* ---------- Paso 3: huevos, guardería y Pokédex ---------- */
.huevo { image-rendering: pixelated; width: 48px; height: 56px; display: block; }
.huevo.grande { width: 72px; height: 84px; }
.huevo.mece { animation: mece 2s steps(1) infinite; transform-origin: 50% 90%; }
.huevo.tiembla { animation: tiembla 0.6s steps(1) infinite; transform-origin: 50% 90%; }
@keyframes mece {
  0%, 70%, 100% { transform: rotate(0); }
  80% { transform: rotate(-10deg); }
  90% { transform: rotate(10deg); }
}
@keyframes tiembla {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-12deg); }
  75% { transform: rotate(12deg); }
}
.boton-huevo {
  position: absolute;
  right: 4px;
  bottom: 8px;
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
}

.botones.dos { grid-template-columns: 1fr 1fr; }
.boton { position: relative; }
.aviso {
  position: absolute;
  top: -10px;
  right: -6px;
  background: var(--acento);
  color: #fff;
  border: 2px solid var(--tinta);
  padding: 2px 5px;
  font-size: 9px;
  animation: respira 0.8s steps(2) infinite;
}

.oferta { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.oferta .boton { width: 100%; }

.fichas { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ficha {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 2px solid var(--tinta);
  padding: 6px;
  font-size: 9px;
}
.ficha-texto { flex: 1; min-width: 0; }
.retrato.mini { width: 40px; height: 40px; border-width: 2px; }
.boton.pequeno { font-size: 8px; padding: 8px 6px; }

.rejilla {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}
.casilla {
  font: inherit;
  font-size: 6px;
  color: var(--tinta);
  background: #fff;
  border: 2px solid var(--tinta);
  padding: 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}
.casilla img { width: 100%; height: auto; image-rendering: pixelated; aspect-ratio: 1; }
.casilla.activa { outline: 3px solid var(--acento); }
.casilla.vacia { background: transparent; border-style: dashed; border-color: var(--tinta-suave); color: var(--tinta-suave); cursor: default; }
.interrogante { font-size: 14px; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; width: 100%; }
.creditos-mini { font-size: 7px; overflow-wrap: anywhere; }

/* ---------- Fondos de bioma ---------- */
/* El escenario es un cuadrado con el dibujo del bioma (64x64) ampliado sin difuminar */
.escenario.bioma {
  width: 256px;
  max-width: 100%;
  aspect-ratio: 1;
  margin: 0 auto;
  flex: none;
  background-size: 100% 100%;
  image-rendering: pixelated;
  border: var(--pixel) solid var(--tinta);
  overflow: hidden;
}
.escenario.bioma .sprite { width: 100%; }
/* De noche: un velo azul oscuro por encima del fondo, pero por debajo del Pokémon */
.escenario.bioma::before {
  content: "";
  position: absolute;
  inset: 0;
  background: #101840;
  opacity: 0;
  pointer-events: none;
}
.escenario.bioma.noche::before { opacity: 0.55; }
.escenario.bioma > * { position: relative; }
.escenario.bioma > .boton-huevo, .escenario.bioma > .zzz,
.escenario.bioma > .caca, .escenario.bioma > .corazon-flota,
.escenario.bioma > .mancha, .escenario.bioma > .mosca { position: absolute; }
.escenario.bioma .zzz { color: #e8e8f8; }

/* ---------- Cacas, bayas, caricias y variocolores ---------- */
.caca {
  position: absolute;
  width: 10%;
  height: auto;
  image-rendering: pixelated;
  pointer-events: none;
}
.escenario .sprite[role="button"] { cursor: pointer; }
.corazon-flota {
  position: absolute;
  left: 46%;
  top: 30%;
  width: 28px;
  height: auto;
  image-rendering: pixelated;
  pointer-events: none;
  animation: flota 1.2s steps(6) forwards;
}
@keyframes flota {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(-48px); opacity: 0; }
}
.vinculo { display: flex; align-items: center; gap: 4px; font-size: 8px; }
.vinculo span { width: 9ch; margin-right: 4px; }
.vinculo img { width: 14px; height: 12px; image-rendering: pixelated; }

.botones.bayas { grid-template-columns: 1fr 1fr 1fr auto; }
.boton.baya { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 8px; padding: 6px 2px; }
.boton.baya img { width: 20px; height: 18px; image-rendering: pixelated; }
.boton.baya .fav { position: absolute; top: 3px; right: 3px; width: 10px; height: 9px; }
.boton.cerrar { padding: 6px 10px; }

.estrella { color: #e8a800; }
.casilla { position: relative; }
.estrella.esquina { position: absolute; top: 1px; right: 2px; font-size: 7px; }
.retratos-ficha { display: flex; flex-direction: column; gap: 4px; }
@media (prefers-reduced-motion: reduce) { .corazon-flota { animation: none; opacity: 0; } }

/* Aviso de descarga de los 151, debajo de la pantalla */
.descarga {
  margin: 16px 12px 0;
  font-size: 8px;
  color: #fff4f0;
  text-align: center;
}

/* ---------- Minijuego: Salta obstáculos ---------- */
.marcador { text-align: center; font-size: 9px; }
.escenario.bioma.juego {
  background-repeat: repeat-x;
  cursor: pointer;
  touch-action: none;   /* que tocar no haga scroll ni zoom */
  user-select: none;
}
.escenario.bioma.juego > .corredor { position: absolute; inset: 0; width: 100%; }
.escenario.bioma.juego > .obstaculo {
  position: absolute;
  width: 18.75%;        /* 12 píxeles de 64 */
  transform: translateX(-50%);
  image-rendering: pixelated;
  pointer-events: none;
}
.escenario.bioma.juego > .baya-juego { width: 15.6%; } /* 10 de 64 */
.escenario.bioma.juego > .aviso-juego {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: var(--pantalla);
  border: 3px solid var(--tinta);
  padding: 6px 10px;
  font-size: 10px;
}
.tiembla-juego { animation: niega 0.3s steps(4) 2; }

/* Suciedad: manchas sobre el Pokémon y moscas revoloteando */
.mancha { width: 11%; height: auto; image-rendering: pixelated; pointer-events: none; }
.mosca { width: 4.7%; height: auto; image-rendering: pixelated; pointer-events: none; animation: zumba 0.9s steps(4) infinite; }
.mosca.m1 { animation-delay: -0.45s; }
@keyframes zumba {
  0% { transform: translate(0, 0); }
  25% { transform: translate(8px, -6px); }
  50% { transform: translate(14px, 2px); }
  75% { transform: translate(4px, 6px); }
  100% { transform: translate(0, 0); }
}
@media (prefers-reduced-motion: reduce) { .mosca { animation: none; } }

/* El último elemento de cada pantalla (VOLVER, el pie…) se queda abajo del todo */
.pantalla > :last-child { margin-top: auto; }

/* Botón grande de saltar en el minijuego: ocupa el hueco libre */
.boton.saltar {
  flex: 1;
  min-height: 96px;
  font-size: 14px;
  touch-action: none;
  user-select: none;
}

/* ---------- Racha, rarezas y evolución confirmada ---------- */
.fila-barra.racha span:last-child { font-size: 8px; }
.huevo.legendario { filter: drop-shadow(0 0 3px #f8d860) drop-shadow(0 0 6px #f8d860); }
.huevo.raro { filter: drop-shadow(0 0 3px #78a8f8); }
/* Mientras decides si evoluciona, parpadea despacio (blanco ↔ normal) */
.escenario .sprite.evolucionando { animation: evoluciona 0.5s steps(2) infinite; }
/* En la pantalla de elegir, la rejilla de tu Pokédex va justo debajo (no pegada al fondo) */
.pantalla[data-vista="elegir"] > :last-child { margin-top: 0; }
.rejilla .casilla span { overflow-wrap: anywhere; }

/* ---------- Menú de minijuegos ---------- */
.lista-juegos { display: flex; flex-direction: column; gap: 12px; }
.boton.juego-opcion { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 12px; text-align: left; }
.juego-nombre { font-size: 11px; }

/* ---------- Tres carriles y Sube a las nubes ---------- */
/* El camino: hierba a los lados y tres carriles de tierra en medio (colores según el bioma) */
.escenario.bioma.juego.carriles {
  background: linear-gradient(to right, var(--hierba) 0 4%, var(--camino) 4% 96%, var(--hierba) 96%);
}
.raya-carril {
  position: absolute !important;
  top: 0; bottom: 0;
  width: 2%;
  transform: translateX(-50%);
  background: repeating-linear-gradient(to bottom, rgba(255,255,255,0.7) 0 8%, transparent 8% 16%);
  background-size: 100% 50%;
  pointer-events: none;
}
.escenario.bioma.juego > .corredor-carril {
  position: absolute;
  bottom: 0;
  width: 70%;
  transform: translateX(-50%);
  transition: left 0.1s steps(2);
  pointer-events: none;
}
.escenario.bioma.juego > .cosa-carril {
  position: absolute;
  width: 18.75%;
  transform: translateX(-50%);
  image-rendering: pixelated;
  pointer-events: none;
}
.escenario.bioma.juego > .cosa-carril.baya-juego { width: 15.6%; }
/* Los dos botones grandes ◀ ▶ ocupan el hueco libre */
.controles-carril { display: flex; gap: 12px; flex: 1; }
.boton.mover { flex: 1; min-height: 96px; font-size: 22px; touch-action: none; user-select: none; }

/* Sube a las nubes: el dibujo del bioma abajo y el cielo encima (el color lo pone el JS) */
.escenario.bioma.juego.nubes { background-repeat: no-repeat; }
.escenario.bioma.juego > .saltarin {
  position: absolute;
  width: 40%;
  transform: translateX(-50%);
  pointer-events: none;
}
.escenario.bioma.juego > .nube,
.escenario.bioma.juego > .baya-nube {
  position: absolute;
  width: 24%;
  transform: translateX(-50%);
  image-rendering: pixelated;
  pointer-events: none;
}
.escenario.bioma.juego > .baya-nube { width: 12%; }
/* Muy arriba, salen estrellas (reutilizamos la capa de la noche) */
.escenario.bioma.nubes.estrellas::before {
  opacity: 1;
  background:
    radial-gradient(circle, #fff 0 1px, transparent 1.5px) 0 0 / 37px 41px,
    radial-gradient(circle, #ffe 0 1px, transparent 1.5px) 13px 19px / 53px 47px;
}
