/* Paleta del juego: noche de Oviedo, papel de recetario y un amarillo de pista.
 * Nada se distingue solo por el color: Jorge es daltónico, así que los estados
 * llevan también texto, forma o icono. */
:root {
  --noche: #1d1b2e;
  --noche-2: #2c2a44;
  --noche-3: #3a3858;
  --papel: #f4ecd8;
  --papel-2: #e2d6b8;
  --pista: #f2c94c;
  --tinta: #1d1b2e;
  --fuente: 'Pixelify Sans', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0f0e19; }
body { display: grid; place-items: center; font-family: var(--fuente); color: var(--papel); overflow: hidden; }
button { font: inherit; }
.oculto { display: none !important; }

/* El juego mantiene 16:9 y ocupa lo que puede de la pantalla. */
.juego {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  aspect-ratio: 16 / 9;
  background: var(--noche);
  font-size: clamp(12px, 2.1vw, 22px);
  user-select: none;
}
#lienzo { width: 100%; height: 100%; display: block; image-rendering: pixelated; cursor: default; }
#lienzo.sobre-algo { cursor: pointer; }

.boton {
  padding: 0.45em 1em; border: 0.18em solid var(--tinta); background: var(--pista); color: var(--tinta);
  box-shadow: 0.18em 0.18em 0 var(--tinta); cursor: pointer; font-weight: 600;
}
.boton:hover { transform: translate(-1px, -1px); box-shadow: 0.24em 0.24em 0 var(--tinta); }
.boton:active { transform: translate(2px, 2px); box-shadow: none; }
.boton--sutil { background: var(--papel); }
.boton:disabled { opacity: 0.45; cursor: default; transform: none; box-shadow: 0.18em 0.18em 0 var(--tinta); }

/* Marcador de estrellas y rótulo de lo que hay bajo el ratón. */
.marcador {
  position: absolute; top: 2.5%; right: 2%; display: flex; align-items: center; gap: 0.4em;
  padding: 0.2em 0.6em; background: var(--papel); color: var(--tinta); border: 0.15em solid var(--tinta); font-size: 0.8em;
}
.marcador__icono {
  width: 1em; height: 1em; background: var(--pista);
  clip-path: polygon(50% 0, 62% 36%, 100% 38%, 70% 60%, 80% 100%, 50% 76%, 20% 100%, 30% 60%, 0 38%, 38% 36%);
}
.marcador.gana { animation: gana 0.6s steps(3) 2; }
@keyframes gana { 50% { transform: scale(1.15); } }
.rotulo {
  position: absolute; left: 50%; top: 2.5%; transform: translateX(-50%);
  padding: 0.15em 0.6em; background: rgba(15, 14, 25, 0.8); color: var(--papel); font-size: 0.8em; pointer-events: none;
}

/* Pantalla de título. */
.titulo {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.6em;
  background: rgba(15, 14, 25, 0.55); text-align: center;
}
.titulo h1 { margin: 0; font-size: 2.6em; line-height: 1; letter-spacing: 0.02em; text-shadow: 0.08em 0.08em 0 var(--tinta); }
.titulo h1 span { color: var(--pista); font-size: 1.25em; }
.titulo__sub { margin: 0.2em 0 0.8em; color: var(--papel-2); }
.titulo__botones { display: flex; gap: 0.8em; }

/* Diálogo: caja abajo, retrato a la izquierda. */
.dialogo {
  position: absolute; left: 2%; right: 2%; bottom: 3%; display: flex; gap: 0.8em; align-items: flex-start;
  min-height: 26%; padding: 0.7em 0.9em; background: var(--papel); color: var(--tinta);
  border: 0.2em solid var(--tinta); box-shadow: 0.25em 0.25em 0 rgba(0, 0, 0, 0.45); cursor: pointer;
}
.dialogo__retrato { width: 4.2em; height: 4.2em; image-rendering: pixelated; background: var(--noche-2); border: 0.15em solid var(--tinta); flex: none; }
.dialogo__cuerpo { flex: 1; }
.dialogo__quien { display: block; margin-bottom: 0.2em; }
.dialogo__texto { margin: 0; line-height: 1.3; }
.dialogo__seguir { position: absolute; right: 0.7em; bottom: 0.4em; animation: parpadeo 1s steps(2) infinite; }
.dialogo.grito .dialogo__texto { font-size: 1.35em; font-weight: 600; animation: temblor 0.25s steps(2) 3; }
@keyframes parpadeo { 50% { opacity: 0; } }
@keyframes temblor { 50% { transform: translateX(0.12em); } }

/* Puzle: una hoja de papel sobre la escena. */
.puzle {
  position: absolute; inset: 3% 4%; display: flex; flex-direction: column; gap: 0.5em;
  padding: 0.8em 1em; background: var(--papel); color: var(--tinta); border: 0.22em solid var(--tinta);
  box-shadow: 0.3em 0.3em 0 rgba(0, 0, 0, 0.5); overflow: auto;
}
.puzle__cabeza { display: flex; align-items: baseline; gap: 0.6em; border-bottom: 0.12em dashed var(--tinta); padding-bottom: 0.3em; }
.puzle__cabeza h2 { margin: 0; font-size: 1.15em; flex: 1; }
.puzle__numero { background: var(--tinta); color: var(--papel); padding: 0 0.4em; }
.puzle__premio { font-size: 0.8em; }
.puzle__cuerpo { display: flex; gap: 1em; align-items: flex-start; }
.puzle__dibujo { width: 36%; image-rendering: pixelated; background: var(--noche-2); border: 0.15em solid var(--tinta); flex: none; }
.puzle__enunciado { line-height: 1.3; font-size: 0.92em; }
.puzle__enunciado p { margin: 0 0 0.5em; }
.puzle__respuesta { display: flex; gap: 0.6em; flex-wrap: wrap; align-items: center; }
.puzle__respuesta input {
  width: 6em; padding: 0.3em 0.5em; font: inherit; font-size: 1.2em; text-align: center;
  border: 0.15em solid var(--tinta); background: #fff; color: var(--tinta);
}
.puzle__opcion { padding: 0.35em 0.8em; border: 0.15em solid var(--tinta); background: #fff; color: var(--tinta); cursor: pointer; }
.puzle__opcion[aria-pressed='true'] { background: var(--tinta); color: var(--papel); }
.puzle__opcion[aria-pressed='true']::before { content: '▶ '; }
.puzle__mensaje { margin: 0; min-height: 1.3em; font-weight: 600; }
.puzle__pie { display: flex; gap: 0.6em; justify-content: flex-end; flex-wrap: wrap; margin-top: auto; }
.puzle__pistas { margin: 0; padding-left: 1.3em; font-size: 0.85em; }
.puzle__pistas li { margin-bottom: 0.25em; }
.puzle__pistas li::marker { content: '✦ '; }

@media (max-aspect-ratio: 4/3) {
  .puzle__cuerpo { flex-direction: column; }
  .puzle__dibujo { width: 60%; align-self: center; }
}

/* Pantalla final: la carta de Chetis. */
.final {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.7em; padding: 1.5em; text-align: center; background: rgba(15, 14, 25, 0.88);
}
.final__caso { margin: 0; padding: 0.1em 0.7em; background: var(--pista); color: var(--tinta); font-weight: 600; }
.final h2 { margin: 0; font-size: 1.4em; }
.final__mensaje {
  margin: 0.4em 0; max-width: 34em; padding: 1em 1.3em; background: var(--papel); color: var(--tinta);
  border: 0.2em solid var(--tinta); box-shadow: 0.3em 0.3em 0 rgba(0, 0, 0, 0.5); font-size: 1.05em; line-height: 1.35;
}
.final__mensaje p { margin: 0 0 0.5em; }
.final__mensaje footer { text-align: right; font-weight: 600; }
.final__datos { margin: 0; color: var(--papel-2); font-size: 0.85em; }

/* Puzle de deslizar: la parada de autobuses. Las piezas se distinguen por la
 * forma (autobús largo con ventanillas, coche corto, Chetis con su cara), no por
 * el color. */
.tablero {
  position: relative; width: min(100%, 15em); aspect-ratio: 1; flex: none;
  background: #8a8a96; border: 0.2em solid var(--tinta); touch-action: none;
  background-image: linear-gradient(rgba(255,255,255,0.18) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.18) 1px, transparent 1px);
  background-size: calc(100% / var(--n)) calc(100% / var(--n));
}
.tablero__salida {
  position: absolute; left: 100%; height: calc(100% / var(--n)); display: flex; align-items: center;
  padding: 0 0.3em; background: var(--pista); color: var(--tinta); font-size: 0.6em; font-weight: 600; white-space: nowrap;
  border: 0.15em solid var(--tinta); border-left: 0;
}
.tablero__pieza {
  position: absolute; padding: 0; border: 0.15em solid var(--tinta); cursor: grab; transition: left 0.12s, top 0.12s;
  box-shadow: inset 0 0 0 0.12em rgba(255,255,255,0.35); font: inherit; color: var(--tinta);
}
.tablero__pieza:focus-visible { outline: 0.2em dashed var(--pista); outline-offset: 0.05em; z-index: 2; }
.tablero__pieza--arrastrando { transition: none; cursor: grabbing; z-index: 3; }
.tablero__pieza--fuera { transition: left 0.6s ease-in; }
/* Autobús: largo, con fila de ventanillas. */
.tablero__pieza--bus { background-color: #f4ecd8; border-radius: 0.35em; }
.tablero__pieza--bus.tablero__pieza--h { background-image: repeating-linear-gradient(90deg, transparent 0 0.25em, #3a3858 0.25em 0.75em); background-size: 100% 35%; background-repeat: no-repeat; background-position: 0 25%; }
.tablero__pieza--bus.tablero__pieza--v { background-image: repeating-linear-gradient(180deg, transparent 0 0.25em, #3a3858 0.25em 0.75em); background-size: 35% 100%; background-repeat: no-repeat; background-position: 25% 0; }
/* Coche: corto, con un parabrisas. */
.tablero__pieza--coche { background-color: #c9c4d6; border-radius: 0.6em; }
.tablero__pieza--coche::after { content: ''; position: absolute; inset: 30%; background: #3a3858; border-radius: 0.2em; }
/* Chetis: su cara y su nombre. */
.tablero__pieza--chetis {
  display: flex; align-items: center; justify-content: center; gap: 0.3em; background: var(--pista); border-radius: 0.5em;
  font-size: 0.75em; font-weight: 600;
}
.tablero__cara { width: 1.8em; height: 1.8em; image-rendering: pixelated; }
.tablero__reiniciar { align-self: flex-end; }
.puzle__respuesta:has(.tablero) { align-items: flex-end; gap: 2.6em; }
