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; }
}

/* Logos generados por logo.js: SVG en linea pintado con currentColor, asi
   que el tema claro de cada escena (color: --blue) los vuelve azules solo. */
.brand-logo { display: block; }
.brand-logo svg { display: block; width: 100%; height: auto; overflow: visible; }

.brand-image {
  display: block;
  width: min(68vw, 1320px);
  max-height: 52vh;
  object-fit: contain;
  filter: drop-shadow(0 10px 26px rgba(var(--blue-night-rgb), 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 animado: lo compone tv.js con logo.js (marca del acto) y la
 * coreografia esta en logo.css. Aqui solo el lienzo que lo contiene.
 */
.logo-loop {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
}

.logo-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; }
.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;
}

/* El logo sustituye al rotulo de texto 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;
}

/* Escena Cartel (id "welcome"): la imagen a pantalla completa, igual que el
   video. Se hace a 3840x2160; en una pantalla que no sea 16:9 se ve entera
   con bandas en vez de recortar el logo o el texto de los bordes. */
.poster-scene { background: var(--blue-night); }
.poster-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  z-index: 1;
}
/* Cambio de cartel dentro de la escena: como entre escenas, el que entra va
   encima y funde; el que sale se queda entero debajo hasta estar tapado. */
.poster-image.shown { opacity: 1; }
.poster-image.incoming {
  z-index: 2;
  transition: opacity var(--scene-fade-duration) cubic-bezier(.22, .61, .36, 1);
}
.poster-empty { position: absolute; inset: 0; z-index: 3; }
.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(var(--blue-night-rgb), .78), rgba(var(--blue-rgb), .48) 48%, rgba(var(--blue-night-rgb), .70));
}
.ambient-lockup {
  position: absolute;
  left: 6vw;
  bottom: 7vh;
  z-index: 3;
  text-align: left;
}
.ambient-lockup .mini-logo {
  width: min(42vw, 760px);
}
.ambient-lockup .ambient-date {
  margin-top: 2vh;
  letter-spacing: .20em;
  font-size: clamp(18px, 1.5vw, 30px);
  font-weight: 500;
}

.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 .brand-logo { width: 100%; }
.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; }
}

/* ------------------------------------------------------------------
   ESCENA ELECCIONES
   Cuenta atras con un sobre entrando en una urna de cristal. La figura se
   mide en vh para que la urna guarde la proporcion en cualquier pantalla.
   ------------------------------------------------------------------ */
.elections-scene {
  background:
    radial-gradient(ellipse 70% 70% at 50% 62%, var(--blue-bright) 0%, var(--blue) 52%, var(--blue-deep) 100%);
}

/* Cinta con la bandera, colgando del borde de arriba. */
.elections-flag {
  position: absolute;
  top: 0;
  left: 50%;
  width: 9vh;
  height: 8vh;
  transform: translateX(-50%);
  background: linear-gradient(90deg, var(--flag-red) 0 25%, var(--flag-yellow) 25% 75%, var(--flag-red) 75%);
}

/* En vertical, como el cartel: la cuenta arriba y la urna debajo. */
.elections-layout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6vh;
  padding: 12vh 6vw 9vh;
  text-align: center;
}

.elections-figure {
  position: relative;
  width: 50vh;
  aspect-ratio: 520 / 380;
}

.elections-shadow {
  position: absolute;
  left: 4%;
  right: 4%;
  bottom: -3vh;
  height: 5vh;
  background: radial-gradient(closest-side, rgba(var(--blue-night-rgb), .55), transparent);
}

.elections-box {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  transform: rotate(3deg);
  transform-origin: 50% 100%;
}
.elections-box .box-top { fill: var(--blue-soft); fill-opacity: .5; }
.elections-box .box-side { fill: var(--blue-deep); fill-opacity: .45; }
.elections-box .box-front { fill: var(--blue-soft); fill-opacity: .38; }
.elections-box .box-slot { fill: var(--blue-night); fill-opacity: .7; }
.elections-box .box-shine { fill: url(#electionsShine); }
.elections-box .shine-start { stop-color: var(--white); stop-opacity: .22; }
.elections-box .shine-end { stop-color: var(--white); stop-opacity: 0; }
.elections-box .box-edge {
  fill: none;
  stroke: var(--white);
  stroke-opacity: .55;
  stroke-width: 2;
  stroke-linejoin: round;
}
.elections-box .box-edge-back { stroke-opacity: .22; }
.elections-box .box-tag {
  fill: var(--white);
  fill-opacity: .9;
  font-family: var(--font);
  font-size: 96px;
  font-weight: 500;
  letter-spacing: -2px;
}
.elections-box .envelope-paper { fill: var(--white); }
.elections-box .envelope-flap {
  fill: none;
  stroke: var(--blue-soft);
  stroke-width: 2.5;
  stroke-linejoin: round;
}

/* Al entrar la escena, el sobre baja hasta la ranura: el voto entrando.
   Despues sube y baja suave sin parar. Sube como mucho 16 unidades del SVG:
   su borde de abajo sigue tapado por la tapa, asi que nunca se ve que se
   salga de la ranura. */
.elections-scene.active .envelope {
  animation:
    elections-drop 1.6s cubic-bezier(.22, .61, .36, 1) both,
    elections-bob 3.2s ease-in-out 1.6s infinite;
}
@keyframes elections-drop {
  from { transform: translateY(-70px); }
  to { transform: none; }
}
@keyframes elections-bob {
  0%, 100% { transform: none; }
  50% { transform: translateY(-16px); }
}
@media (prefers-reduced-motion: reduce) {
  .elections-scene.active .envelope { animation: none; }
}

/* Tres filas: cifras, unidades y el subtitulo. Columnas de ancho fijo para
   que los segundos no muevan nada al cambiar. */
.elections-counter {
  display: grid;
  grid-template-columns: repeat(4, 25vh);
  column-gap: 8vh;
}
.elections-counter[hidden],
.elections-today[hidden] { display: none; }
.elections-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.elections-value {
  font-size: 19vh;
  line-height: .8;
  font-weight: 500;
  letter-spacing: -.04em;
  font-variant-numeric: tabular-nums;
}
.elections-label {
  margin-top: 2vh;
  font-size: 3.8vh;
  font-weight: 400;
  color: var(--muted);
}
.elections-today {
  font-size: 18vh;
  line-height: .9;
  font-weight: 500;
  letter-spacing: -.045em;
}
/* En mayusculas y al ancho de la fila de cifras (4 x 25vh + 3 x 8vh =
   124vh). Si cambia el texto en config.js, hay que reajustar el cuerpo. */
.elections-subtitle {
  margin-top: 3.4vh;
  font-size: 6.85vh;
  line-height: 1.08;
  font-weight: 400;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.elections-brand {
  position: absolute;
  right: 6vw;
  bottom: 7vh;
  width: min(22vw, 420px);
}

/* ------------------------------------------------------------------
   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.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(var(--blue-rgb), .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(var(--blue-rgb), .07), transparent 26%),
    radial-gradient(circle at 18% 82%, rgba(var(--blue-rgb), .04), transparent 25%);
}

/* Acto archivado o que no existe: las reglas no dejan leerlo. */
.tv-unavailable {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--blue-night);
  color: var(--muted);
  font-size: clamp(24px, 3vw, 64px);
}

/* ------------------------------------------------------------------
   ROTULO, QR Y AGENDA
   ------------------------------------------------------------------ */
/* El rotulo usa el fondo y las letras del cierre (.closing-scene). */

.qr-scene,
.agenda-scene {
  background: linear-gradient(120deg, var(--blue-night) 0%, var(--blue-deep) 62%, var(--blue) 100%);
}

.qr-layout {
  position: relative;
  z-index: 2;
  height: 100%;
  padding: 8vh 7vw;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 6vw;
}
/* Oscuro sobre blanco y con margen: asi lo leen todos los moviles de lejos. */
.qr-card {
  width: min(62vh, 40vw);
  aspect-ratio: 1;
  background: var(--white);
  border-radius: 2.4vh;
  padding: 2.4vh;
  color: var(--ink);
  box-shadow: 0 2vh 6vh rgba(var(--blue-night-rgb), .45);
}
.qr-card svg { display: block; width: 100%; height: 100%; }
.qr-caption {
  margin: 0;
  font-size: clamp(40px, 5.6vw, 120px);
  font-weight: 500;
  line-height: 1.02;
  letter-spacing: -.03em;
}
.qr-url {
  margin-top: 3vh;
  font-size: clamp(18px, 2vw, 44px);
  color: var(--muted);
  word-break: break-word;
}

.agenda-layout {
  position: relative;
  z-index: 2;
  height: 100%;
  padding: 9vh 9vw 14vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.agenda-title {
  margin: 0 0 4vh;
  font-size: clamp(36px, 4.4vw, 96px);
  font-weight: 500;
  letter-spacing: -.02em;
}
.agenda-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1.6vh; }
.agenda-list li {
  display: grid;
  grid-template-columns: 9vw 1fr;
  gap: 3vw;
  align-items: baseline;
  font-size: clamp(22px, 2.6vw, 58px);
  line-height: 1.15;
  padding: 1.2vh 2vw;
  border-radius: 1.4vh;
}
.agenda-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.agenda-list li.past { opacity: .45; }
.agenda-list li.now { background: rgba(255, 255, 255, .12); }
.agenda-list li.now .agenda-time { color: var(--white); }

/* ------------------------------------------------------------------
   FOTO DEL INTERVINIENTE Y ROTULO INFERIOR
   ------------------------------------------------------------------ */
.speaker-photo {
  display: block;
  width: 26vh;
  height: 26vh;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 4vh;
  box-shadow: 0 2vh 5vh rgba(var(--blue-night-rgb), .45);
}

.lower-third {
  position: absolute;
  left: 5vw;
  right: 5vw;
  bottom: 6vh;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4vw;
  padding: 2.6vh 3vw;
  border-radius: 1.6vh;
  border-left: 1vh solid var(--blue-soft);
  background: rgba(var(--blue-night-rgb), .9);
  color: var(--white);
  opacity: 0;
  transform: translateY(140%);
  transition: opacity .6s ease, transform .6s cubic-bezier(.22, .61, .36, 1);
  pointer-events: none;
}
.lower-third.shown { opacity: 1; transform: translateY(0); }
.lt-name { font-size: clamp(28px, 3.6vw, 80px); font-weight: 500; line-height: 1.05; }
.lt-role { font-size: clamp(18px, 2vw, 44px); color: var(--muted); margin-top: .6vh; }
.lt-role:empty { display: none; }
.lt-logo { width: min(18vw, 340px); flex: none; }
.elections-brand,
.ambient-lockup { transition: opacity .6s ease; }
.lower-on .elections-brand,
.lower-on .ambient-lockup { opacity: 0; }
