/* Scrollytelling: "El recorrido de una factura".
   El JS pone en #tablero la clase desde-N (N = 1..5) según la escena activa;
   cada elemento del escenario cambia con transform/opacity. */

:root { --alto-cabecera: 4.6rem; }

.historia {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 0.72fr) minmax(0, 1.28fr);
  gap: clamp(2rem, 4vw, 4rem);
  max-width: var(--ancho);
  margin: 0 auto;
  padding: var(--seccion) var(--gutter) 0;
}

/* ---------- Escenario fijo ---------- */
.historia__escena {
  grid-column: 2; grid-row: 1;
  position: sticky; top: var(--alto-cabecera);
  height: calc(100svh - var(--alto-cabecera));
  display: grid; place-items: center;
}

.tablero {
  container-type: inline-size;
  position: relative;
  width: min(100%, calc((100svh - var(--alto-cabecera) - 3rem) * 1.25));
  aspect-ratio: 5 / 4;
  border-radius: 10px;
  background:
    url("/img/contornos.svg") center / 180% auto no-repeat,
    linear-gradient(160deg, #F7FAF9, #E3EBEA);
  box-shadow: inset 0 0 0 1px rgba(46, 107, 122, 0.16);
  overflow: hidden;
  --t: 700ms;
}

/* Ruta de avance con el cóndor como marcador */
.tablero__ruta { position: absolute; left: 6%; right: 6%; bottom: 5%; height: 2px; background: var(--bruma); }
.tablero__avance {
  position: absolute; inset: 0; background: var(--agua);
  transform-origin: left; transform: scaleX(var(--avance, 0));
  transition: transform var(--t) var(--ease);
}
.tablero__marca {
  position: absolute; left: 0; bottom: 0.3cqw; width: 7cqw; max-width: none;
  transform: translateX(calc(var(--avance, 0) * 77cqw - 50%));
  transition: transform var(--t) var(--ease);
}

/* Factura */
.esc-factura {
  position: absolute; left: 7%; top: 9%; width: 47%;
  padding: 3.4cqw 3.4cqw 3cqw;
  background: var(--papel); border-radius: 3px;
  box-shadow: var(--sombra-doc);
  font-size: 2.1cqw; line-height: 1.35;
  transition: transform var(--t) var(--ease);
}
.esc-factura::before { content: ""; position: absolute; inset: 0 0 auto; height: 0.9cqw; background: var(--condor); border-radius: 3px 3px 0 0; }
.esc-factura__tipo { color: var(--texto-suave); }
.esc-factura__folio { font: 700 3.4cqw/1.1 var(--f-titulo); margin-bottom: 2.2cqw; }
.esc-factura dl { margin: 0 0 2.4cqw; }
.esc-factura dl div { display: flex; justify-content: space-between; gap: 1cqw; padding: 0.9cqw 0; border-top: 1px dashed var(--bruma); }
.esc-factura dt { color: var(--texto-suave); }
.esc-factura dd { margin: 0; font-weight: 600; }
.esc-factura__total { display: flex; justify-content: space-between; align-items: baseline; font: 760 4.6cqw/1 var(--f-titulo); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.esc-factura__total span { font: 400 2.1cqw/1 var(--f-texto); color: var(--texto-suave); letter-spacing: 0; }

.timbre {
  position: absolute; right: 3cqw; top: 3.6cqw;
  padding: 0.8cqw 1.6cqw; border: 0.45cqw solid currentColor; border-radius: 0.8cqw;
  font: 700 2.6cqw/1 var(--f-titulo); white-space: nowrap;
  opacity: 0; transform: rotate(-12deg) scale(1.6);
  transition: opacity 300ms, transform 450ms cubic-bezier(0.3, 1.6, 0.5, 1);
}
.timbre--cedida { color: var(--agua); }
.timbre--pagada { color: #4F7A2A; }

/* Calendario */
.esc-calendario {
  position: absolute; right: 7%; top: 9%; width: 25%;
  padding: 2cqw 0 2.4cqw; text-align: center;
  background: var(--fiordo); color: var(--glaciar); border-radius: 1.2cqw;
  box-shadow: 0 1.5cqw 3cqw -1.5cqw rgba(15, 42, 58, 0.6);
}
.esc-calendario__mes, .esc-calendario__de { font-size: 2.1cqw; color: var(--bruma); }
.esc-calendario__dia { font: 760 10cqw/1 var(--f-titulo); letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }

/* Cuentas por pagar */
.esc-cuentas {
  list-style: none; margin: 0; padding: 0;
  position: absolute; left: 7%; bottom: 13%; width: 47%;
  display: flex; flex-wrap: wrap; gap: 1.2cqw;
}
.esc-cuentas li {
  display: inline-flex; align-items: center; gap: 0.8cqw;
  padding: 1cqw 1.8cqw; border-radius: 99px;
  font-size: 2.1cqw; font-weight: 600;
  background: #F6DADE; color: var(--condor-oscuro);
  opacity: 0; transform: translateY(2cqw);
  transition: opacity 400ms, transform 500ms var(--ease), background-color 400ms, color 400ms;
}
.esc-cuentas li::before { content: "Vence"; font-weight: 400; }
.esc-cuentas li:nth-child(2) { transition-delay: 80ms; }
.esc-cuentas li:nth-child(3) { transition-delay: 160ms; }

/* Medidor de caja */
.esc-caja {
  position: absolute; right: 7%; bottom: 13%; width: 33%;
  padding: 2.2cqw; background: var(--papel); border-radius: 1.2cqw;
  box-shadow: 0 1.5cqw 3cqw -1.8cqw rgba(15, 42, 58, 0.5);
}
.esc-caja__titulo { font-size: 2.1cqw; color: var(--texto-suave); }
.esc-caja__medidor { height: 2.2cqw; margin: 1.4cqw 0; border-radius: 99px; background: var(--glaciar); overflow: hidden; }
.esc-caja__medidor span {
  display: block; height: 100%; border-radius: inherit;
  background: var(--nivel-color, var(--agua));
  transform-origin: left; transform: scaleX(var(--nivel, 0.2));
  transition: transform var(--t) var(--ease), background-color var(--t);
}
.esc-caja__estado { font: 700 3cqw/1.1 var(--f-titulo); color: var(--fiordo); transition: color 300ms; }

/* Cóndor que entra cuando Skyring participa */
.esc-condor {
  position: absolute; left: 22%; top: 1%; width: 48%; max-width: none;
  opacity: 0; transform: translate(-70%, -30%) rotate(-14deg) scale(0.7);
  transition: opacity 500ms, transform 1100ms var(--ease);
}

/* ---------- Estados por escena ---------- */
.tablero { --avance: 0; }
.tablero.desde-1 { --avance: 0.2; }
.tablero.desde-2 { --avance: 0.4; }
.tablero.desde-3 { --avance: 0.6; }
.tablero.desde-4 { --avance: 0.8; }
.tablero.desde-5 { --avance: 1; }

/* 1: vencen las cuentas, caja en rojo */
.desde-1 .esc-cuentas li { opacity: 1; transform: none; }
.desde-1 .esc-caja { --nivel: 0.06; --nivel-color: var(--condor); }
.desde-1 .esc-caja__estado { color: var(--condor); }

/* 2: la factura se cede, llega el cóndor */
.desde-2 .esc-factura { transform: translate(4%, 6%) rotate(-3deg); }
.desde-2 .timbre--cedida { opacity: 1; transform: rotate(-12deg) scale(1); }
.desde-2 .esc-condor { opacity: 1; transform: translate(6%, -34%) rotate(-6deg) scale(0.95); }

/* 3: entra el anticipo, las cuentas quedan pagadas */
.desde-3 .esc-caja { --nivel: 0.86; --nivel-color: #8FA63A; }
.desde-3 .esc-caja__estado { color: var(--fiordo); }
.desde-3 .esc-cuentas li { background: #E3EBCB; color: #3F5F1E; }
.desde-3 .esc-cuentas li::before { content: "Pagado"; }
.desde-3 .esc-condor { transform: translate(55%, -8%) rotate(-2deg) scale(0.62); }

/* 4: vence la factura y Skyring cobra */
.desde-4 .esc-factura { transform: translate(0, 0) rotate(0); }
.desde-4 .timbre--cedida { opacity: 0; transform: rotate(-12deg) scale(0.8); }
.desde-4 .timbre--pagada { opacity: 1; transform: rotate(-8deg) scale(1); }

/* 5: excedente */
.desde-5 .esc-caja { --nivel: 1; }
.desde-5 .esc-calendario { background: var(--agua); }

/* ---------- Texto de las escenas ---------- */
.historia__pasos { grid-column: 1; grid-row: 1; }
.historia__intro p { margin-top: 0.75rem; color: var(--texto-suave); font-size: var(--t-l); max-width: 30ch; }
.historia__lista { list-style: none; margin: 0; padding: 0 0 30svh; counter-reset: escena; }
.paso {
  counter-increment: escena;
  min-height: 78svh; display: flex; flex-direction: column; justify-content: center;
  padding-left: 3.75rem; position: relative;
  opacity: 0.28; transition: opacity 400ms var(--ease);
}
.paso.activo { opacity: 1; }
.paso::before {
  content: counter(escena);
  position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 2.6rem; height: 2.6rem; border-radius: 50%;
  display: grid; place-items: center;
  border: 2px solid var(--fiordo); font: 700 var(--t-m)/1 var(--f-titulo);
  background: var(--glaciar);
  transition: background-color 300ms, color 300ms, border-color 300ms;
}
.paso.activo::before { background: var(--fiordo); color: var(--papel); }
.paso h3 { font-size: var(--t-xl); letter-spacing: -0.025em; }
.paso p { margin-top: 0.75rem; font-size: var(--t-l); line-height: 1.5; color: var(--texto-suave); max-width: 30ch; }

/* Sin JS: todo el texto visible y el escenario en su estado final */
.sin-js .paso { opacity: 1; }

/* ---------- Móvil: escenario arriba, texto pasa por debajo ---------- */
@media (max-width: 860px) {
  .historia { grid-template-columns: minmax(0, 1fr); gap: 0; padding-top: calc(var(--seccion) * 0.6); }
  .historia__pasos { display: contents; }
  .historia__intro { grid-row: 1; }
  .historia__lista { grid-row: 3; position: relative; z-index: 1; }
  .historia__escena {
    grid-column: 1; grid-row: 2;
    height: auto; z-index: 2;
    padding: 0.75rem 0;
    background: var(--glaciar);
    box-shadow: 0 12px 16px -12px rgba(15, 42, 58, 0.25);
    margin: 0 calc(-1 * var(--gutter));
    padding-inline: var(--gutter);
  }
  .tablero { width: min(100%, calc(48svh * 1.25)); }
  .historia__intro { padding-bottom: 1.5rem; }
  .paso { min-height: 48svh; justify-content: flex-start; padding-top: 2.5rem; }
  .paso::before { top: 2.5rem; transform: none; }
  .paso h3 { font-size: var(--t-l); }
  .paso p { font-size: var(--t-m); }
}

@media (prefers-reduced-motion: reduce) {
  .tablero { --t: 1ms; }
  .tablero *, .paso { transition: none !important; }
}
