@font-face {
  font-family: "Garamond MU";
  src: url("fonts/garamond.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Garamond MU";
  src: url("fonts/garamond-italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

:root {
  --noche: #030a1c;
  --noche-profunda: #01040e;
  --marfil: #f3ecdf;
  --oro: #e9c99a;
  --oro-luz: #fff1d6;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-seda: cubic-bezier(0.65, 0, 0.35, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--noche-profunda);
  color: var(--marfil);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  font-family: "Garamond MU", "Garamond", "Times New Roman", serif;
  overflow: hidden;
}

::selection {
  background: rgba(233, 201, 154, 0.32);
  color: var(--oro-luz);
}

/* ---------- Escena ---------- */

.escena {
  position: relative;
  height: 100vh;
  height: 100svh;
  min-height: 560px;
  overflow: hidden;
  isolation: isolate;
  background: radial-gradient(120% 80% at 50% 0%, #071537 0%, var(--noche) 45%, var(--noche-profunda) 100%);
}

/* Bahía de Zapallar: sube desde la oscuridad y respira lento */
.bahia {
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0;
  transform: translate3d(0, 6%, 0) scale(1.12);
  filter: blur(6px) brightness(0.6);
  transition:
    opacity 4.2s var(--ease-seda),
    transform 9s var(--ease-out),
    filter 4.2s var(--ease-seda);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, rgba(0, 0, 0, 0.25) 26%, #000 58%);
  mask-image: linear-gradient(to bottom, transparent 0%, rgba(0, 0, 0, 0.25) 26%, #000 58%);
}

/* Cada noche de Zapallar es un cuadro. El que entra nace desde la estrella del logo:
   una máscara circular que se abre desde ese punto (--cx/--cy los fija main.js). */
@property --abre {
  syntax: "<percentage>";
  inherits: false;
  initial-value: 0%;
}

.cuadro {
  position: absolute;
  inset: 0;
  overflow: hidden;
  visibility: hidden;
  --abre: 0%;
  -webkit-mask-image: radial-gradient(circle at var(--cx, 50%) var(--cy, 55%), #000 calc(var(--abre) - 18%), transparent var(--abre));
  mask-image: radial-gradient(circle at var(--cx, 50%) var(--cy, 55%), #000 calc(var(--abre) - 18%), transparent var(--abre));
}

.cuadro.is-activo,
.cuadro.is-saliendo {
  visibility: visible;
}

.cuadro.is-activo {
  z-index: 2;
  --abre: 190%;
}

.cuadro.is-saliendo {
  z-index: 1;
  --abre: 190%;
}

.cuadro.is-entrando {
  transition: --abre 3.2s cubic-bezier(0.55, 0.06, 0.25, 1);
}

.cuadro__medio {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 45%;
  animation: respirar-a 26s var(--ease-seda) infinite alternate;
  animation-play-state: paused;
}

.cuadro[data-mov="b"] .cuadro__medio {
  animation-name: respirar-b;
}
.cuadro[data-mov="c"] .cuadro__medio {
  animation-name: respirar-c;
}

.escena.paso-5 .is-activo .cuadro__medio,
.escena.paso-5 .is-saliendo .cuadro__medio {
  animation-play-state: running;
}

@keyframes respirar-a {
  from {
    transform: scale(1.02) translate3d(0, 0, 0);
  }
  to {
    transform: scale(1.1) translate3d(-1.5%, -1.8%, 0);
  }
}
@keyframes respirar-b {
  from {
    transform: scale(1.1) translate3d(1.5%, 0, 0);
  }
  to {
    transform: scale(1.02) translate3d(-1%, -1%, 0);
  }
}
@keyframes respirar-c {
  from {
    transform: scale(1.04) translate3d(-1%, 1%, 0);
  }
  to {
    transform: scale(1.12) translate3d(1%, -1.2%, 0);
  }
}

/* Luz de luna: la escena queda en penumbra salvo cerca del cursor (o del dedo) */
.luna {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 3s var(--ease-seda);
  background: radial-gradient(
    circle clamp(220px, 30vmax, 520px) at var(--lx, 50%) var(--ly, 70%),
    rgba(1, 4, 14, 0) 0%,
    rgba(1, 4, 14, 0.12) 45%,
    rgba(1, 4, 14, 0.42) 100%
  );
}

.escena.paso-5 .luna {
  opacity: 1;
}

/* Grano de película muy leve: une fotos y video en una sola textura */
.grano {
  position: absolute;
  inset: -50%;
  z-index: 4;
  pointer-events: none;
  opacity: 0.07;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.9 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  animation: grano 1.2s steps(6) infinite;
}

@keyframes grano {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-3%, 2%); }
  40% { transform: translate(2%, -3%); }
  60% { transform: translate(-2%, -1%); }
  80% { transform: translate(3%, 3%); }
  100% { transform: translate(0, 0); }
}

/* Cielo con estrellas (canvas) */
.cielo {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 42%, transparent 78%);
  mask-image: linear-gradient(to bottom, #000 0%, #000 42%, transparent 78%);
}

/* Velo: oscurece arriba para que la frase respire, viñeta en los bordes */
.velo {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(1, 4, 14, 0.82) 0%, rgba(1, 4, 14, 0.35) 42%, rgba(1, 4, 14, 0) 64%, rgba(1, 4, 14, 0.3) 100%),
    radial-gradient(140% 100% at 50% 40%, transparent 55%, rgba(1, 4, 14, 0.75) 100%);
}

/* ---------- Centro: frase + logo ---------- */

.centro {
  position: relative;
  z-index: 3;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: clamp(4.5rem, 13vh, 9rem) 1.5rem 0;
  text-align: center;
}

.frase {
  margin: 0;
  font-weight: 400;
  font-size: clamp(1.3rem, 1rem + 1.6vw, 2.55rem);
  line-height: 1.32;
  letter-spacing: 0.005em;
  color: var(--marfil);
  text-wrap: balance;
  max-width: 44ch;
  text-shadow: 0 2px 24px rgba(1, 4, 14, 0.9);
}

.frase__linea {
  display: block;
  white-space: nowrap;
  opacity: 0;
  filter: blur(14px);
  transform: translate3d(0, 0.35em, 0);
  letter-spacing: 0.08em;
  transition:
    opacity 2.6s var(--ease-out),
    filter 2.6s var(--ease-out),
    transform 2.6s var(--ease-out),
    letter-spacing 3.4s var(--ease-out);
}

.frase__linea--final {
  margin-top: 0.12em;
  font-style: italic;
  font-size: 1.28em;
  color: var(--oro-luz);
}

/* Sello: destello + logo */
.sello {
  position: relative;
  margin-top: clamp(1.6rem, 5vh, 3.4rem);
  width: clamp(230px, 34vw, 500px);
}

/* Sombra suave detrás del logo para que el oro se lea sobre las luces de la playa */
.sello::before {
  content: "";
  position: absolute;
  inset: -28% -22%;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(50% 50% at 50% 55%, rgba(1, 4, 14, 0.78) 0%, rgba(1, 4, 14, 0.5) 45%, rgba(1, 4, 14, 0) 100%);
  opacity: 0;
  transition: opacity 3s var(--ease-seda);
}

.escena.paso-5 .sello::before {
  opacity: 1;
}

.sello__logo {
  display: block;
  width: 100%;
  height: auto;
  opacity: 0;
  filter: drop-shadow(0 6px 30px rgba(233, 201, 154, 0.18));
  -webkit-mask-image: linear-gradient(100deg, #000 40%, transparent 60%);
  mask-image: linear-gradient(100deg, #000 40%, transparent 60%);
  -webkit-mask-size: 300% 100%;
  mask-size: 300% 100%;
  -webkit-mask-position: 100% 0;
  mask-position: 100% 0;
  transition:
    opacity 1.6s var(--ease-seda),
    -webkit-mask-position 3.6s var(--ease-seda),
    mask-position 3.6s var(--ease-seda);
}

/* Centro de la estrella dentro del logo recortado */
.sello__destello {
  position: absolute;
  left: 51.5%;
  top: 23.7%;
  width: 2px;
  height: 2px;
  pointer-events: none;
}

.sello__destello::before,
.sello__destello::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  border-radius: 50%;
  opacity: 0;
  scale: 0.2;
}

/* núcleo de luz */
.sello__destello::before {
  width: clamp(160px, 22vw, 320px);
  height: clamp(160px, 22vw, 320px);
  background: radial-gradient(circle, rgba(255, 246, 228, 0.95) 0%, rgba(255, 226, 180, 0.45) 9%, rgba(233, 201, 154, 0.12) 28%, transparent 60%);
}

/* rayos en cruz, como la estrella de la frase */
.sello__destello::after {
  width: clamp(380px, 60vw, 900px);
  height: clamp(380px, 60vw, 900px);
  border-radius: 0;
  background:
    linear-gradient(to right, transparent 0%, rgba(255, 240, 214, 0.75) 50%, transparent 100%) center / 100% 1.5px no-repeat,
    linear-gradient(to bottom, transparent 10%, rgba(255, 240, 214, 0.65) 50%, transparent 90%) center / 1.5px 70% no-repeat;
}

/* ---------- Coreografía (la activa main.js) ---------- */

.escena.paso-1 .frase__linea:nth-child(1),
.escena.paso-2 .frase__linea:nth-child(2),
.escena.paso-3 .frase__linea:nth-child(3) {
  opacity: 1;
  filter: blur(0);
  transform: none;
  letter-spacing: 0.005em;
}

.escena.paso-4 .sello__destello::before {
  animation: nacer 3.2s var(--ease-out) forwards;
}
.escena.paso-4 .sello__destello::after {
  animation: rayos 3.2s var(--ease-out) forwards;
}

@keyframes nacer {
  0% {
    opacity: 0;
    scale: 0.05;
  }
  22% {
    opacity: 1;
    scale: 1.15;
  }
  100% {
    opacity: 0;
    scale: 0.55;
  }
}

@keyframes rayos {
  0% {
    opacity: 0;
    scale: 0.05 0.05;
    rotate: 0deg;
  }
  20% {
    opacity: 1;
    scale: 1 1;
  }
  100% {
    opacity: 0;
    scale: 0.3 0.3;
    rotate: 12deg;
  }
}

.escena.paso-5 .sello__logo {
  opacity: 1;
  -webkit-mask-position: 0 0;
  mask-position: 0 0;
}

.escena.paso-5 .bahia {
  opacity: 1;
  transform: none;
  filter: none;
}


/* Brillo del logo que recorre las letras cada cierto tiempo */
.escena.paso-6 .sello::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(105deg, transparent 40%, rgba(255, 244, 222, 0.55) 50%, transparent 60%) no-repeat;
  background-size: 250% 100%;
  -webkit-mask: url("img/logo.webp") center / 100% 100% no-repeat;
  mask: url("img/logo.webp") center / 100% 100% no-repeat;
  mix-blend-mode: screen;
  animation: barrido 9s var(--ease-seda) 0.4s infinite;
}

@keyframes barrido {
  0% {
    background-position: 130% 0;
  }
  38%,
  100% {
    background-position: -30% 0;
  }
}

/* ---------- Teléfonos ---------- */

@media (max-aspect-ratio: 3/4) {
  .centro {
    padding-top: clamp(4.5rem, 14vh, 7rem);
  }
  .frase {
    max-width: 22ch;
  }
  .frase__linea {
    white-space: normal;
  }
  .sello {
    width: min(78vw, 360px);
  }
  .cuadro__medio {
    object-position: 50% 50%;
  }
  .bahia {
    top: 9%;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, rgba(0, 0, 0, 0.2) 34%, #000 64%);
    mask-image: linear-gradient(to bottom, transparent 0%, rgba(0, 0, 0, 0.2) 34%, #000 64%);
  }
}

@media (max-height: 640px) and (min-aspect-ratio: 1/1) {
  .centro {
    padding-top: 2.5rem;
  }
  .sello {
    width: clamp(200px, 26vw, 360px);
    margin-top: 1rem;
  }
}

/* ---------- Movimiento reducido: estado final, sin coreografía ---------- */

@media (prefers-reduced-motion: reduce) {
  .sello::before {
    opacity: 1;
  }
  .frase__linea,
  .sello__logo,
  .bahia {
    transition: none !important;
  }
  .frase__linea {
    opacity: 1;
    filter: none;
    transform: none;
    letter-spacing: 0.005em;
  }
  .sello__logo {
    opacity: 1;
    -webkit-mask-position: 0 0;
    mask-position: 0 0;
  }
  .bahia {
    opacity: 1;
    transform: none;
    filter: none;
  }
  .cuadro__medio,
  .grano,
  .sello::after,
  .sello__destello::before,
  .sello__destello::after {
    animation: none !important;
  }
}
