html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--blue-night);
  cursor: none;
}

#stage {
  --scene-fade-duration: 1200ms;
  --scene-motion-duration: 1500ms;
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  color: white;
  background: linear-gradient(135deg, var(--blue-bright) 0%, var(--blue) 52%, var(--ink) 100%);
}

/* Transicion entre escenas.
   La escena entrante va SIEMPRE encima (z-index) y hace el fundido; la
   saliente mantiene su opacidad y se corta cuando ya esta tapada del todo.
   Si ambas se fundieran a la vez, a mitad de camino se veria el fondo de la
   pagina entre las dos y la transicion daria un bajon de luz. */
.scene {
  position: absolute;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  transform: scale(1.012);
  transition:
    opacity 1ms linear var(--scene-fade-duration),
    visibility 1ms linear var(--scene-fade-duration),
    transform var(--scene-motion-duration) cubic-bezier(.22, .61, .36, 1);
  pointer-events: none;
  z-index: 1;
}

.scene.active {
  opacity: 1;
  visibility: visible;
  transform: scale(1);
  z-index: 2;
  transition:
    opacity var(--scene-fade-duration) cubic-bezier(.22, .61, .36, 1),
    visibility 0s,
    transform var(--scene-motion-duration) cubic-bezier(.22, .61, .36, 1);
}

/* El texto del interviniente cambia sin cambiar de escena: se funde en vez
   de saltar de golpe. */
.speaker-copy {
  transition: opacity 220ms ease, transform 220ms ease;
}

.speaker-copy.swapping {
  opacity: 0;
  transform: translateY(-10px);
}

/* Con "reducir movimiento" se quita el desplazamiento y el zoom, pero se
   mantiene el fundido: un crossfade no es movimiento, y sin el los cambios
   de escena vuelven a ser secos. */
@media (prefers-reduced-motion: reduce) {
  .scene,
  .scene.active { transform: none; }
  .speaker-copy.swapping { transform: none; }
}

.brand-image {
  display: block;
  width: min(68vw, 1320px);
  max-height: 52vh;
  object-fit: contain;
  filter: drop-shadow(0 10px 26px rgba(12, 28, 57, 0.12));
}

.brand-crop {
  position: relative;
  width: min(66vw, 1280px);
  aspect-ratio: 3.25 / 1;
  overflow: hidden;
}
.brand-crop img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.center {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 6vh 7vw;
  text-align: center;
}

.logo-scene {
  background: var(--blue);
}

/*
 * Logo loop
 * The source artwork is split into four animated crops so the official logo
 * keeps its exact geometry. The first and last frames are the same: NNGG on
 * its own, centred on screen. This makes the 14-second sequence seamless.
 */
.logo-loop {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
}

.logo-loop-artwork {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(86vw, 1500px);
  aspect-ratio: 1721 / 324;
  transform: translate(-50%, -50%) translateX(34%);
  transform-origin: 16% 50%;
  will-change: transform;
}

.logo-loop-layer {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  will-change: clip-path, opacity, transform;
}

/* NNGG occupies the first 32% of the source artwork. */
.logo-loop-mark {
  clip-path: inset(0 68% 64% 0);
}

.logo-loop-letters {
  clip-path: inset(36% 68% 0 0);
}

.logo-loop-divider {
  opacity: 0;
  clip-path: inset(0 61.8% 0 37.2%);
  transform: scaleY(0);
  transform-origin: center;
}

.logo-loop-alicante {
  opacity: 0;
  clip-path: inset(0 56.8% 0 43.2%);
}

.logo-scene.active .logo-loop-artwork {
  animation: logo-loop-position 14s cubic-bezier(.4, 0, .2, 1) infinite;
}

.logo-scene.active .logo-loop-mark {
  animation: logo-loop-mark 14s cubic-bezier(.4, 0, .2, 1) infinite;
}

.logo-scene.active .logo-loop-letters {
  animation: logo-loop-letters 14s cubic-bezier(.4, 0, .2, 1) infinite;
}

.logo-scene.active .logo-loop-divider {
  animation: logo-loop-divider 14s cubic-bezier(.4, 0, .2, 1) infinite;
}

.logo-scene.active .logo-loop-alicante {
  animation: logo-loop-alicante 14s cubic-bezier(.4, 0, .2, 1) infinite;
}

@keyframes logo-loop-position {
  0%, 14% {
    transform: translate(-50%, -50%) translateX(34%) scale(1);
  }
  18%, 38% {
    transform: translate(-50%, -50%) translateX(34%) scale(1.35);
  }
  46%, 50% {
    transform: translate(-50%, -50%) translateX(34%) scale(1);
  }
  56%, 90% {
    transform: translate(-50%, -50%) translateX(0) scale(1);
  }
  96%, 100% {
    transform: translate(-50%, -50%) translateX(34%) scale(1);
  }
}

@keyframes logo-loop-mark {
  0%, 10% {
    opacity: 1;
    clip-path: inset(0 68% 64% 0);
  }
  14%, 18% {
    opacity: 0;
    clip-path: inset(0 96.5% 64% 0);
  }
  20% {
    opacity: 1;
    clip-path: inset(0 96.5% 64% 0);
  }
  30%, 100% {
    opacity: 1;
    clip-path: inset(0 68% 64% 0);
  }
}

@keyframes logo-loop-letters {
  0%, 10% {
    opacity: 1;
    transform: translateY(0) scale(1);
    clip-path: inset(36% 68% 0 0);
  }
  14%, 27% {
    opacity: 0;
    transform: translateY(5%) scale(.98);
    clip-path: inset(36% 68% 64% 0);
  }
  38%, 100% {
    opacity: 1;
    transform: translateY(0) scale(1);
    clip-path: inset(36% 68% 0 0);
  }
}

@keyframes logo-loop-divider {
  0%, 52% {
    opacity: 0;
    transform: scaleY(0);
  }
  57%, 88% {
    opacity: 1;
    transform: scaleY(1);
  }
  93%, 100% {
    opacity: 0;
    transform: scaleY(0);
  }
}

@keyframes logo-loop-alicante {
  0%, 54% {
    opacity: 0;
    clip-path: inset(0 56.8% 0 43.2%);
  }
  56% {
    opacity: 1;
    clip-path: inset(0 56.8% 0 43.2%);
  }
  64%, 86% {
    opacity: 1;
    clip-path: inset(0 0 0 43.2%);
  }
  92%, 100% {
    opacity: 0;
    clip-path: inset(0 56.8% 0 43.2%);
  }
}

.logo-scene::after,
.welcome-scene::after,
.speaker-scene::after,
.closing-scene::after,
.safe-scene::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 75% 18%, rgba(255,255,255,.12), transparent 26%),
    radial-gradient(circle at 18% 82%, rgba(255,255,255,.06), transparent 25%);
  pointer-events: none;
}

.scene-copy { position: relative; z-index: 2; }
.eyebrow {
  font-size: clamp(18px, 1.65vw, 34px);
  letter-spacing: .22em;
  font-weight: 500;
  text-transform: uppercase;
  margin-bottom: 2vh;
}

.display-title {
  max-width: 82vw;
  font-size: clamp(58px, 7.7vw, 150px);
  line-height: .92;
  letter-spacing: -.045em;
  font-weight: 500;
  margin: 0;
}

.display-subtitle {
  max-width: 74vw;
  margin: 2.2vh auto 0;
  font-size: clamp(24px, 2.35vw, 48px);
  line-height: 1.15;
  font-weight: 300;
}

.event-meta {
  margin-top: 5vh;
  display: flex;
  gap: 2vw;
  justify-content: center;
  flex-wrap: wrap;
  font-size: clamp(17px, 1.4vw, 28px);
  font-weight: 500;
  letter-spacing: .03em;
}

/* El logo sustituye al rotulo de texto en la bienvenida y en el cierre. */
/* El logo va anclado al borde de la pantalla, centrado en horizontal, y el
   texto sigue centrado en el alto sin tenerlo en cuenta. */
.scene-logo {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: min(26vw, 470px);
  z-index: 3;
}

.scene-logo.at-top { top: 7vh; }
.scene-logo.at-bottom { bottom: 7vh; }

.ambient-scene { background: var(--ink); }

/* Escena Video: el archivo a pantalla completa, sin recortes ni capas
   encima. Si el video no es 16:9, las bandas quedan en el azul de fondo. */
.video-scene { background: var(--blue-night); }
.scene-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.ambient-video,
.ambient-fallback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.ambient-video {
  object-fit: cover;
  filter: saturate(.72) contrast(1.02);
  /* El video trae marcas de agua a la izquierda, arriba y abajo. Se amplia
     anclando el zoom al centro del lado derecho: asi se sale de cuadro el 25%
     izquierdo, que se lleva las dos, y ademas se recorta un 12,5% por arriba y
     otro 12,5% por abajo.
     Anclarlo abajo a la derecha, como estaba antes, no valia: el borde
     inferior no se movia y la marca de abajo seguia dentro. */
  transform: scale(1.25);
  transform-origin: right center;
}
.ambient-fallback {
  background:
    radial-gradient(circle at 73% 23%, rgba(255,255,255,.13), transparent 24%),
    linear-gradient(125deg, var(--blue-bright) 0%, var(--blue) 45%, var(--blue-night) 100%);
}
.ambient-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(12, 28, 57, .78), rgba(28, 67, 135, .48) 48%, rgba(12, 28, 57, .70));
}
.ambient-lockup {
  position: absolute;
  left: 6vw;
  bottom: 7vh;
  z-index: 3;
  text-align: left;
}
.ambient-lockup .mini-logo {
  width: min(42vw, 760px);
  max-height: 22vh;
  object-fit: cover;
}
.ambient-lockup .ambient-date {
  margin-top: 2vh;
  letter-spacing: .20em;
  font-size: clamp(18px, 1.5vw, 30px);
  font-weight: 500;
}

.welcome-scene,
.closing-scene,
.safe-scene {
  background: linear-gradient(135deg, var(--blue-bright) 0%, var(--blue) 55%, var(--ink) 100%);
}

.speaker-scene {
  background: linear-gradient(120deg, var(--blue-night) 0%, var(--blue-deep) 62%, var(--blue) 100%);
}
.speaker-layout {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  padding: 8vh 7vw;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, .7fr);
  align-items: center;
  gap: 5vw;
}
.speaker-copy { align-self: center; }
.speaker-name {
  font-size: clamp(66px, 8.4vw, 165px);
  letter-spacing: -.055em;
  line-height: .90;
  font-weight: 500;
  margin: 0;
  max-width: 64vw;
}
.speaker-role {
  margin-top: 2.5vh;
  font-size: clamp(24px, 2.5vw, 52px);
  line-height: 1.1;
  font-weight: 400;
  max-width: 58vw;
}
.speaker-instagram {
  margin-top: 2vh;
  font-size: clamp(19px, 1.7vw, 34px);
  font-weight: 500;
  letter-spacing: .01em;
}
.speaker-brand {
  align-self: end;
  justify-self: end;
  width: min(31vw, 550px);
  opacity: .95;
}
.speaker-brand img {
  width: 100%;
  display: block;
  object-fit: cover;
}
.toast-scene {
  background:
    radial-gradient(circle at 50% -15%, rgba(255,255,255,.48), transparent 34%),
    linear-gradient(135deg, #e3c063 0%, #b88820 38%, #f0d178 70%, #af7c17 100%);
  color: var(--ink);
}
.toast-scene::after {
  content: "";
  position: absolute;
  inset: 2.6vh 2.2vw;
  border: max(3px, .22vw) solid rgba(17, 41, 82, .78);
  border-radius: 2px;
}
.toast-scene .display-title { max-width: 80vw; }
.toast-brand {
  margin-top: 5vh;
  width: min(33vw, 620px);
  max-height: 14vh;
  object-fit: cover;
  filter: none;
}

.safe-logo { width: min(52vw, 980px); }

.connection-badge {
  position: absolute;
  right: 24px;
  bottom: 18px;
  z-index: 50;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 14px;
  background: rgba(0,0,0,.32);
  color: rgba(255,255,255,.68);
  opacity: 0;
  transition: opacity .2s ease;
}
.connection-badge.visible { opacity: 1; }
.connection-badge.error { color: #ffd6d8; }

@media (max-aspect-ratio: 4/3) {
  .speaker-layout { grid-template-columns: 1fr; }
  .speaker-brand { display: none; }
  .speaker-name, .speaker-role { max-width: 86vw; }
}

@media (prefers-reduced-motion: reduce) {
  .scene { transition: none; }
}

/* ------------------------------------------------------------------
   TEMA CLARO POR ESCENA
   Se elige escena a escena en /control. Invierte la pareja: fondo claro y
   texto en azul de marca. El logo cambia al archivo azul desde tv.js,
   porque el blanco sobre blanco no se veria.
   ------------------------------------------------------------------ */
.scene.theme-light { color: var(--blue); }

.scene.theme-light.logo-scene,
.scene.theme-light.safe-scene { background: var(--white); }

.scene.theme-light.welcome-scene,
.scene.theme-light.closing-scene {
  background: linear-gradient(135deg, var(--white) 0%, var(--paper) 55%, var(--paper-2) 100%);
}

.scene.theme-light.speaker-scene {
  background: linear-gradient(120deg, var(--paper-2) 0%, var(--paper) 62%, var(--white) 100%);
}

.scene.theme-light.ambient-scene { background: var(--paper); }

.scene.theme-light .ambient-fallback {
  background:
    radial-gradient(circle at 73% 23%, rgba(28, 67, 135, .06), transparent 24%),
    linear-gradient(125deg, var(--white) 0%, var(--paper) 45%, var(--paper-2) 100%);
}

.scene.theme-light .ambient-shade {
  background: linear-gradient(90deg, rgba(246, 248, 251, .78), rgba(231, 237, 245, .48) 48%, rgba(246, 248, 251, .70));
}

/* Los brillos del fondo son blancos: sobre claro no se verian, asi que
   pasan a un tinte azul muy suave. */
.scene.theme-light::after {
  background:
    radial-gradient(circle at 75% 18%, rgba(28, 67, 135, .07), transparent 26%),
    radial-gradient(circle at 18% 82%, rgba(28, 67, 135, .04), transparent 25%);
}
