/* ==========================================================================
   Animación "Contraseñas" — 3 slides en loop (15 s)
   Todas las medidas están en puntos de la mesa de trabajo de Illustrator
   (780.48 × 399.097) multiplicados por --u, así escala con el ancho del modal.
   ========================================================================== */

@font-face {
  font-family: "MONTECH";
  src: url("../assets/fonts/MONTECHV01-Regular.otf") format("opentype");
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

.csa {
  /* 1 punto de Illustrator = --u */
  --u: calc(100cqw / 780.48);

  /* Tiempos (el JS lee estos mismos valores) */
  --csa-in: 700ms;       /* entrada / salida del personaje */
  --csa-pop: 500ms;      /* burbuja de diálogo */

  position: relative;
  width: 100%;
  aspect-ratio: 780.48 / 399.097;
  overflow: hidden;
  container-type: inline-size;
  background: #0a8fd9 linear-gradient(100deg, #00c3e8 0%, #0a8fd9 50%, #0d6fd0 100%);
  user-select: none;
}

.csa img {
  display: block;
  max-width: none;
}

/* ---- Fondo (fijo, no se anima) ---- */
.csa-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ---- Slides ---- */
.csa-slide {
  position: absolute;
  inset: 0;
  visibility: hidden;
}
.csa-slide.is-active { visibility: visible; }

.csa-panel,
.csa-actor,
.csa-bubble {
  position: absolute;
  inset: 0;
}
.csa-panel > img,
.csa-actor > img,
.csa-bubble > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Estado inicial del personaje + burbuja: fuera de escena, a la derecha */
.csa-actor {
  transform: translateX(105%);
  will-change: transform;
}

/* Entrada: derecha → posición final */
.csa-slide.is-in .csa-actor {
  transform: none;
  transition: transform var(--csa-in) cubic-bezier(.65, 0, .35, 1);   /* misma curva que la salida: no se pisan */
}

/* Salida: personaje + burbuja se van por la izquierda (la ventana queda fija) */
.csa-slide.is-out .csa-actor {
  transform: translateX(-105%);
  transition: transform var(--csa-in) cubic-bezier(.65, 0, .35, 1);
}

/* ---- Cartel de alerta: aparece cuando termina el tipeo ---- */
.csa-alert {
  transform-origin: calc(313 * var(--u)) calc(84 * var(--u));
  transform: scale(0);
  opacity: 0;
}
.csa.is-alert .csa-alert {
  animation: csa-alert 650ms cubic-bezier(.3, .7, .4, 1) both;
}
.csa.is-alert-out .csa-alert {
  animation: csa-alert-out 220ms ease-in both;
}
@keyframes csa-alert {
  0%   { transform: scale(0) rotate(-14deg);   opacity: 0; }
  15%  { opacity: 1; }
  40%  { transform: scale(1.18) rotate(7deg);  opacity: 1; }
  60%  { transform: scale(.94) rotate(-5deg); }
  80%  { transform: scale(1.03) rotate(2deg); }
  100% { transform: scale(1) rotate(0);        opacity: 1; }
}
@keyframes csa-alert-out {
  0%   { transform: scale(1); opacity: 1; }
  100% { transform: scale(0); opacity: 0; }
}

/* ---- Burbuja de diálogo ---- */
.csa-bubble {
  /* --ox / --oy = punta de la burbuja: desde ahí "crece" */
  transform-origin: calc(var(--ox) * var(--u)) calc(var(--oy) * var(--u));
  transform: scale(0);
  opacity: 0;
}
.csa-slide.is-bubble .csa-bubble {
  animation: csa-pop var(--csa-pop) cubic-bezier(.3, .7, .4, 1) both;
}
@keyframes csa-pop {
  0%   { transform: scale(0);    opacity: 0; }
  20%  { opacity: 1; }
  55%  { transform: scale(1.09); opacity: 1; }
  78%  { transform: scale(.97); }
  100% { transform: scale(1);    opacity: 1; }
}

.csa-bubble-text {
  position: absolute;
  left: calc(var(--bx) * var(--u));
  top: calc((var(--by) - 15.48) * var(--u));   /* --by = línea base del 1er renglón */
  margin: 0;
  font-family: "DM Sans", system-ui, sans-serif;
  font-weight: 400;
  font-optical-sizing: none;
  font-variation-settings: "opsz" 9;
  font-size: calc(18 * var(--u));
  letter-spacing: -0.025em;
  color: #fff;
  white-space: nowrap;
}
.csa-bubble-text span {
  display: block;
  height: 1.08em;       /* interlineado del .ai */
  line-height: 0;
}
.csa-bubble-text span::before {   /* fija la línea base sin depender de las métricas de la fuente */
  content: "";
  display: inline-block;
  height: .86em;
}

/* ---- Texto del input + cursor ---- */
.csa-input {
  position: absolute;
  left: calc(var(--tx) * var(--u));
  top: calc((var(--ty) - 30) * var(--u));      /* --ty = línea base del texto */
  height: calc(30 * var(--u));
  line-height: 0;
  white-space: nowrap;
  font-family: "MONTECH", ui-monospace, monospace;
  font-size: calc(22.6778 * var(--u));
  letter-spacing: .25em;
  color: #006ed2;
}
.csa-input::before {
  content: "";
  display: inline-block;
  height: calc(30 * var(--u));
}
.csa-typed { transition: opacity 180ms linear; }
.csa.is-clearing .csa-typed { opacity: 0; }   /* el texto se borra al cambiar de slide */
.csa-caret {
  display: inline-block;
  width: max(1px, calc(1.2 * var(--u)));
  height: calc(34 * var(--u));
  vertical-align: calc(-9 * var(--u));
  background: #006ed0;
  animation: csa-blink 900ms steps(1, end) infinite;
}
.csa.is-typing .csa-typed { transition: opacity 180ms linear; }
.csa.is-clearing .csa-typed { opacity: 0; }   /* el texto se borra al cambiar de slide */
.csa-caret { animation: none; }   /* fijo mientras escribe */
@keyframes csa-blink {
  0%, 55%   { opacity: 1; }
  55.01%, 100% { opacity: 0; }
}

/* ---- Accesibilidad: sin desplazamientos si el usuario pide menos movimiento ---- */
@media (prefers-reduced-motion: reduce) {
  .csa-actor { transform: none; opacity: 0; }
  .csa-slide.is-in .csa-actor { opacity: 1; transition: opacity 400ms linear; }
  .csa-slide.is-out .csa-actor { transform: none; opacity: 0; transition: opacity 400ms linear; }
  .csa.is-alert .csa-alert { animation: none; transform: none; opacity: 1; }
  .csa.is-alert-out .csa-alert { animation: none; }
  .csa-slide.is-bubble .csa-bubble { animation: none; transform: none; opacity: 1; }
}
