:root {
  --noche: #0a1633;
  --azul-hondo: #102552;
  --cobalto: #2448b8;
  --azul-claro: #9db4e8;
  --piedra: #dbe1ec;
  --piedra-sombra: #b4bfd4;
  --luz: #ffd27f;
  --luz-clara: #fff1cf;
  --papel: #fbf9f4;
  --tinta: #142a63;
  --display: "Instrument Serif", "Times New Roman", serif;
  --texto: "Figtree", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--noche); }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--texto);
  color: var(--papel);
  background: linear-gradient(180deg, var(--noche) 0%, var(--azul-hondo) 45%, #1d3c7e 85%, #2b4f96 100%);
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow-x: hidden;
}
/* estrellas */
body::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 100%;
  max-height: 900px;
  pointer-events: none;
  background-image:
    radial-gradient(1.2px 1.2px at 12% 8%, #fff 99%, transparent),
    radial-gradient(1px 1px at 33% 14%, #dfe8ff 99%, transparent),
    radial-gradient(1.4px 1.4px at 71% 3%, #fff 99%, transparent),
    radial-gradient(1px 1px at 76% 18%, #cfdcff 99%, transparent),
    radial-gradient(1.2px 1.2px at 91% 10%, #fff 99%, transparent),
    radial-gradient(1px 1px at 22% 27%, #dfe8ff 99%, transparent),
    radial-gradient(1px 1px at 47% 31%, #fff 99%, transparent),
    radial-gradient(1.3px 1.3px at 84% 33%, #fff 99%, transparent),
    radial-gradient(1px 1px at 6% 41%, #cfdcff 99%, transparent),
    radial-gradient(1px 1px at 67% 44%, #fff 99%, transparent);
  opacity: .8;
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--luz); outline-offset: 3px; }

/* ── Cabecera ─────────────────────────────── */
.cabecera {
  position: relative;
  padding: max(28px, env(safe-area-inset-top)) 22px 8px;
  max-width: 560px;
  margin: 0 auto;
}
/* luna */
.cabecera::after {
  content: "";
  position: absolute;
  top: 34px;
  right: 30px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  box-shadow: 9px -5px 0 0 #f4ecd6;
  transform: rotate(-12deg);
  filter: drop-shadow(0 0 10px rgba(244, 236, 214, .45));
}
h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(3.4rem, 18vw, 4.8rem);
  line-height: .86;
  letter-spacing: -.01em;
}
h1 span {
  display: block;
  font-style: italic;
  font-size: .5em;
  line-height: 1.1;
  margin-top: .12em;
  color: var(--azul-claro);
}
.cuenta {
  margin: 16px 0 0;
  font-size: .98rem;
  font-variant-numeric: tabular-nums;
  color: #c9d6f5;
  min-height: 1.4em;
}
.pestanias {
  display: flex;
  gap: 4px;
  margin-top: 18px;
  padding: 4px;
  background: rgba(157, 180, 232, .12);
  border: 1px solid rgba(157, 180, 232, .22);
  border-radius: 999px;
  width: fit-content;
}
.pestanias button {
  border: 0;
  background: transparent;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: .94rem;
  font-weight: 600;
  color: #b9c9ee;
}
.pestanias button.activa { background: var(--papel); color: var(--tinta); }
.pestanias span { font-variant-numeric: tabular-nums; font-weight: 500; opacity: .7; }

main { max-width: 560px; margin: 0 auto; padding: 0 12px 40px; position: relative; }

/* ── Edificio ─────────────────────────────── */
.edificio {
  margin-top: 28px;
  position: relative;
  filter: drop-shadow(0 30px 40px rgba(3, 8, 25, .55));
}
.techo, .planta-baja { display: block; width: 100%; height: auto; }
.techo { margin-bottom: -1px; }
.planta-baja { margin-top: -1px; }

.ventanas {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 0 12px;
  background:
    linear-gradient(90deg, rgba(20, 40, 90, .10), transparent 12%, transparent 88%, rgba(20, 40, 90, .14)),
    var(--piedra);
  box-shadow: inset 8px 0 0 #e9edf4, inset -8px 0 0 #c7d0e0;
}
.ventana {
  position: relative;
  border: 0;
  background: transparent;
  padding: 40px 10px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* cornisa de cada piso */
  border-bottom: 6px solid #eef1f7;
  box-shadow: 0 3px 0 0 var(--piedra-sombra);
}
.vidrio {
  position: relative;
  width: 100%;
  aspect-ratio: 9 / 16;
  border-radius: 999px 999px 2px 2px;
  /* persiana baja */
  background:
    linear-gradient(180deg, rgba(255,255,255,.06), transparent 40%),
    repeating-linear-gradient(180deg, #24365f 0 6px, #1a2a4f 6px 7.5px);
  box-shadow:
    0 0 0 4px #f2f4f9,
    0 0 0 5px var(--piedra-sombra),
    inset 0 0 0 2px #0f1c3d;
  overflow: hidden;
  transition: background .9s ease, box-shadow .9s ease;
}
/* parteluz (solo se ve con luz) */
.vidrio::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity .9s ease;
  background:
    linear-gradient(90deg, transparent calc(50% - 1.5px), #7a4b22 calc(50% - 1.5px), #7a4b22 calc(50% + 1.5px), transparent calc(50% + 1.5px)),
    linear-gradient(180deg, transparent 33%, #7a4b22 33%, #7a4b22 calc(33% + 3px), transparent calc(33% + 3px)),
    /* cortinas */
    radial-gradient(ellipse 40% 90% at 0% 60%, rgba(36, 72, 184, .55), transparent 70%),
    radial-gradient(ellipse 40% 90% at 100% 60%, rgba(36, 72, 184, .55), transparent 70%);
}
/* reflejo de la luna en el vidrio */
.vidrio::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(118deg, transparent 36%, rgba(220, 232, 255, .10) 44%, transparent 52%);
}
.baranda {
  width: 116%;
  height: 16px;
  margin-top: -9px;
  position: relative;
  z-index: 1;
  border-top: 2.5px solid #0d1530;
  border-bottom: 2px solid #0d1530;
  background:
    radial-gradient(circle at 50% 55%, transparent 2.4px, #0d1530 2.6px, #0d1530 3.6px, transparent 3.8px) 0 0 / 8px 100%,
    linear-gradient(90deg, #0d1530 1.4px, transparent 1.4px) 0 0 / 8px 100%;
}
/* placa con el número, como las de los edificios */
.num {
  position: absolute;
  top: 9px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 34px;
  padding: 3px 8px 2px;
  border-radius: 999px;
  background: #f7f8fc;
  box-shadow: 0 0 0 1px var(--piedra-sombra), 0 2px 3px rgba(20, 40, 90, .18);
  font-family: var(--display);
  font-size: clamp(1.05rem, 4.8vw, 1.3rem);
  line-height: 1;
  text-align: center;
  color: var(--tinta);
  z-index: 2;
  font-variant-numeric: lining-nums;
}
.mini {
  position: absolute;
  bottom: 2px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: .66rem;
  font-weight: 600;
  color: var(--tinta);
  z-index: 2;
  font-variant-numeric: tabular-nums;
}

.ventana.abierta .vidrio {
  background: radial-gradient(ellipse 80% 70% at 50% 75%, var(--luz-clara) 0%, var(--luz) 45%, #e8913f 100%);
  box-shadow:
    0 0 0 4px #f2f4f9,
    0 0 0 5px var(--piedra-sombra),
    inset 0 0 0 2px #7a4b22,
    0 0 34px 6px rgba(255, 196, 100, .55);
}
.ventana.abierta .vidrio::before { opacity: 1; }
.ventana.abierta .num { background: var(--luz-clara); box-shadow: 0 0 0 1px #d9a556, 0 0 12px rgba(255, 196, 100, .7); }
.ventana.proxima .vidrio {
  box-shadow:
    0 0 0 4px #f2f4f9,
    0 0 0 5px var(--piedra-sombra),
    inset 0 0 0 2px #0f1c3d,
    inset 0 -6px 14px -4px rgba(255, 210, 127, .75);
}

.pie {
  text-align: center;
  font-family: var(--display);
  font-style: italic;
  font-size: 1.25rem;
  color: #c9d6f5;
  margin: 22px 0 0;
}

/* ── Hoja (modal) ─────────────────────────── */
.hoja {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 40px);
  border: 0;
  border-radius: 20px;
  padding: 0;
  background: var(--papel);
  color: var(--tinta);
  overflow: auto;
  box-shadow: 0 30px 80px rgba(3, 8, 25, .6);
}
.hoja::backdrop { background: rgba(6, 13, 34, .78); backdrop-filter: blur(3px); }
.hoja[open] { animation: subir .35s ease-out; }
@keyframes subir { from { transform: translateY(24px); opacity: 0; } }
#hoja-cuerpo { padding: 28px 24px 8px; }
.hoja h2 {
  margin: 0 0 2px;
  font-family: var(--display);
  font-weight: 400;
  font-size: 2.3rem;
  line-height: 1;
}
.hoja .fecha { margin: 0 0 18px; color: #6a7aa6; font-size: .9rem; }
.hoja .texto {
  font-size: 1.08rem;
  line-height: 1.65;
  white-space: pre-line;
  margin: 0;
  color: #1d2f5e;
}
.hoja .pregunta-texto {
  font-family: var(--display);
  font-size: 2rem;
  line-height: 1.12;
  white-space: pre-line;
  margin: 8px 0 6px;
}
.hoja .foto {
  width: 100%;
  border-radius: 12px;
  display: block;
  margin-bottom: 16px;
}
.boton {
  display: inline-block;
  margin-top: 18px;
  padding: 12px 20px;
  border-radius: 999px;
  background: var(--cobalto);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  border: 0;
}
.vale {
  background: #eaf0fd;
  border: 2px dashed #8ea6e2;
  border-radius: 14px;
  padding: 20px 18px;
}
.vale .vale-titulo { font-family: var(--display); font-size: 2rem; line-height: 1.05; margin: 0 0 10px; white-space: pre-line; }
.vale .vale-detalle { margin: 0; white-space: pre-line; line-height: 1.55; color: #2b3f75; }
.vale .vale-pie { margin: 14px 0 0; font-size: .85rem; font-weight: 600; color: var(--cobalto); }
.check { display: flex; align-items: center; gap: 10px; margin-top: 18px; font-weight: 600; }
.check input { width: 22px; height: 22px; accent-color: var(--cobalto); }

.premio {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid #e2e6f0;
}
.premio img { width: 84px; height: 84px; filter: drop-shadow(0 3px 5px rgba(10, 25, 70, .35)); }
.premio p { margin: 0; line-height: 1.35; }
.premio .boton { margin-top: 8px; padding: 9px 16px; font-size: .92rem; }
.premio.nueva img { animation: caer .6s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes caer { from { transform: translateY(-30px) rotate(-25deg) scale(.6); opacity: 0; } }

.cerrar {
  display: block;
  width: calc(100% - 48px);
  margin: 14px 24px 24px;
  padding: 12px;
  border-radius: 999px;
  border: 1.5px solid #cfd7ea;
  background: transparent;
  color: var(--tinta);
  font-weight: 600;
}

/* ── Aviso ─────────────────────────────── */
.aviso {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--papel);
  color: var(--tinta);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(3, 8, 25, .45);
  z-index: 50;
  width: max-content;
  max-width: calc(100vw - 32px);
  text-align: center;
}

/* ── Rompecabezas ─────────────────────────── */
.rompe-aviso {
  margin: 24px 8px;
  font-family: var(--display);
  font-size: 1.6rem;
  line-height: 1.25;
}
.tablero-wrap { display: flex; justify-content: center; margin-top: 12px; }
.tablero {
  position: relative;
  border-radius: 6px;
  background-color: rgba(5, 12, 35, .45);
  box-shadow: inset 0 0 0 1.5px rgba(157, 180, 232, .35);
  touch-action: none;
}
.tablero.completo {
  box-shadow: 0 0 0 3px var(--luz), 0 0 60px rgba(255, 196, 100, .7);
  transition: box-shadow 1.2s ease;
}
.pieza {
  position: absolute;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  touch-action: none;
  filter: drop-shadow(0 2px 3px rgba(3, 8, 25, .55));
}
.pieza.fija { filter: none; pointer-events: none; }
.pieza.flotante {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  filter: drop-shadow(0 12px 16px rgba(3, 8, 25, .6));
}
.bandeja {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 104px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  gap: 6px;
  overflow-x: auto;
  background: rgba(8, 18, 44, .94);
  border-top: 1px solid rgba(157, 180, 232, .25);
  z-index: 20;
}
.bandeja:empty { display: none; }
.bandeja img {
  flex: none;
  width: 80px;
  height: 80px;
  touch-action: pan-x;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .5));
}
.bandeja img.arrastrando { opacity: .25; }
.final {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -26px;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.final p {
  margin: 0;
  padding: 8px 24px 10px;
  border-radius: 999px;
  background: var(--papel);
  color: var(--tinta);
  font-family: var(--display);
  font-size: 2rem;
  box-shadow: 0 10px 30px rgba(3, 8, 25, .5);
  animation: subir .8s ease-out;
}
#vista-rompe { padding-bottom: 120px; }

/* ── Modo prueba (solo Lucas) ─────────────── */
.barra-vista {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  padding: 8px 14px;
  background: var(--luz);
  color: var(--tinta);
  font-size: .9rem;
}
.barra-vista[hidden] { display: none; }
.barra-vista select, .barra-vista button {
  font: inherit;
  padding: 5px 8px;
  border-radius: 8px;
  border: 1.5px solid var(--tinta);
  background: var(--papel);
  color: var(--tinta);
}
.barra-vista a { color: var(--tinta); margin-left: auto; }

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