/* ==========================================================================
   Cielo de ITPS One · dirección de arte de las nubes en la apertura
   - Nubes "de vidrio": sombras índigo, cuerpo azul, luz casi blanca y borde menta,
     iluminadas desde arriba a la derecha como el aro.
   - Capas a distintas profundidades: lejos (banda), medio (grupos chicos) y cerca (grupo grande).
   - Al hacer scroll, las capas de día pasan junto a la cámara y el aro muestra el mismo cielo de noche.
   - Las tres piezas del símbolo nacen de tres nubes que se condensan.
   Recursos en assets/editorial/cielo/ (generados desde cifras-nubes*.webp).
   ========================================================================== */

/* Retira las capas anteriores sin tocar el resto de la apertura */
.ap-hero-clouds, .ap-cloud-far { display: none !important; }
.ap-on .ap-numbers-clouds::before { content: none !important; }

/* ---------- Capas: estructura común ---------- */
.sky, .psky {
  --d: .5;          /* profundidad para el paralaje del cursor */
  --fx: 0px; --fy: 0px; --fs: .6; --fb: 6px;   /* cómo pasan junto a la cámara */
  position: absolute;
  display: block;
  pointer-events: none;
  will-change: transform, opacity;
}
.sky > b, .psky > b {
  display: block;
  width: 100%;
  background: center / contain no-repeat;
  animation: sky-drift var(--drift, 26s) ease-in-out infinite alternate;
  animation-delay: var(--drift-delay, 0s);
}
@keyframes sky-drift {
  from { transform: translate3d(calc(var(--dx, 1.6%) * -1), calc(var(--dy, .8%) * -1), 0); }
  to { transform: translate3d(var(--dx, 1.6%), var(--dy, .8%), 0); }
}

/* ---------- 2 · Portada: cielo de día alrededor del aro ---------- */
.ap-sky { position: absolute; inset: 0; pointer-events: none; }
.ap-sky-back { z-index: 1; }
.ap-sky-front { z-index: 2; }
.ap-on .ap-sky { opacity: calc(1 - var(--fly-o, 0)); }

.sky {
  left: calc(var(--gx, 74vw) + var(--hx) * var(--gs, 70vh));
  top: calc(var(--gy, 55vh) + var(--hy) * var(--gs, 70vh));
  width: calc(var(--hw) * var(--gs, 70vh));
  opacity: var(--o, 1);
  transform:
    translate(-50%, -50%)
    translate3d(
      calc(var(--mx, 0) * var(--d) * 18px + var(--fly, 0) * var(--fx)),
      calc(var(--my, 0) * var(--d) * 10px + var(--fly, 0) * var(--fy)),
      0)
    scale(calc(1 + var(--fly, 0) * var(--fs)));
  filter: blur(calc(var(--fly, 0) * var(--fb)));
}
/* Lejos: banda baja, apenas azulada, deja aire bajo los botones */
.sky-banda {
  --hx: -.6; --hy: .44; --hw: 2.1; --o: .62; --d: .15;
  --fy: 12vh; --fs: .25; --fb: 3px; --drift: 34s; --dx: 1%; --dy: 0%;
  -webkit-mask-image: linear-gradient(90deg, transparent 4%, #000 30% 86%, transparent);
  mask-image: linear-gradient(90deg, transparent 4%, #000 30% 86%, transparent);
}
.sky-banda > b { aspect-ratio: 1800 / 282; background-image: url("./assets/editorial/cielo/dia-banda.webp"); }
/* Medio: grupo deshilachado que asoma a la derecha, detrás del aro */
.sky-c {
  --hx: .31; --hy: -.04; --hw: .44; --o: .9; --d: .45;
  --fx: 30vw; --fy: -6vh; --fs: 1.1; --fb: 8px; --drift: 24s; --dx: 2%; --dy: 1.2%;
}
.sky-c > b { aspect-ratio: 566 / 779; background-image: url("./assets/editorial/cielo/dia-c.webp"); }
/* Medio-lejos: nube chica arriba a la izquierda del aro, lejos del título */
.sky-b {
  --hx: -.25; --hy: -.31; --hw: .21; --o: .82; --d: .3;
  --fx: -14vw; --fy: -22vh; --fs: .9; --fb: 6px; --drift: 21s; --drift-delay: -6s; --dx: 2.4%; --dy: 2%;
}
.sky-b > b { aspect-ratio: 403 / 648; background-image: url("./assets/editorial/cielo/dia-b.webp"); }
/* Cerca: el grupo grande abraza la base del aro y pasa primero junto a la cámara */
.sky-a {
  --hx: -.01; --hy: .45; --hw: .4; --o: .97; --d: 1;
  --fx: -18vw; --fy: 46vh; --fs: 2.2; --fb: 14px; --drift: 18s; --drift-delay: -4s; --dx: 1.8%; --dy: 1.4%;
  filter: blur(calc(var(--fly, 0) * var(--fb))) drop-shadow(0 30px 40px #4343a326);
}
.sky-a > b { aspect-ratio: 666 / 942; background-image: url("./assets/editorial/cielo/dia-a.webp"); }

/* El halo del aro toma algo del azul del cielo para integrarlo */
.ap-glow { background: radial-gradient(circle at 50% 48%, #ffffff 0, #e2f6f4c4 30%, #c8d4f655 52%, #c9c8f500 68%); }
.ap-bg {
  background:
    radial-gradient(ellipse 34% 40% at 76% 30%, #ffffff 0%, transparent 70%),
    radial-gradient(ellipse 48% 60% at 74% 56%, #d6f2ef 0%, transparent 68%),
    radial-gradient(ellipse 50% 46% at 60% 104%, #cdd6f4 0%, transparent 72%),
    radial-gradient(ellipse 50% 50% at 10% 100%, #e1e1f7 0%, transparent 70%),
    linear-gradient(118deg, #f7f8fc 10%, #eef1f9 56%, #e7f1f2);
}

/* ---------- 3 · Por el aro: el mismo cielo, de noche ---------- */
.psky {
  /* Al abrirse, las nubes ya están dentro del hueco del aro y se expanden hacia el cielo de las cifras */
  left: calc((var(--numbers-x, 50vw) + var(--px) * var(--gs, 70vh)) * (1 - var(--sky, 1)) + var(--nx) * var(--sky, 1));
  top: calc((var(--numbers-y, 50vh) + var(--py) * var(--gs, 70vh)) * (1 - var(--sky, 1)) + var(--ny) * var(--sky, 1));
  width: calc(var(--pw) * var(--gs, 70vh) * (1 - var(--sky, 1)) + var(--nw) * var(--sky, 1));
  opacity: var(--o, 1);
  transform:
    translate(-50%, -50%)
    translate3d(
      calc(var(--mx, 0) * var(--d) * 14px),
      calc(var(--my, 0) * var(--d) * 8px - var(--sky-rise, 0) * var(--d) * 9vh),
      0)
    scale(calc(1 + var(--sky-rise, 0) * var(--d) * .12));
}
.psky-banda { --px: 0; --py: .2; --pw: .9; --nx: 50%; --ny: 92%; --nw: max(170vw, 1500px); --o: .9; --d: .2; --fy: 12vh; --fs: .25; --drift: 34s; --dx: 1%; --dy: 0%; }
.psky-banda > b { aspect-ratio: 1800 / 282; background-image: url("./assets/editorial/cielo/noche-banda.webp"); }
.psky-c { --px: .085; --py: -.07; --pw: .16; --nx: 90%; --ny: 44%; --nw: min(30vw, 60vh); --o: .85; --d: .5; --fx: 30vw; --fy: -6vh; --fs: 1.1; --drift: 24s; --dx: 2%; --dy: 1.2%; }
.psky-c > b { aspect-ratio: 566 / 779; background-image: url("./assets/editorial/cielo/noche-c.webp"); }
.psky-b { --px: -.05; --py: -.1; --pw: .09; --nx: 66%; --ny: 17%; --nw: min(14vw, 30vh); --o: .7; --d: .35; --fx: -14vw; --fy: -22vh; --fs: .9; --drift: 21s; --drift-delay: -6s; --dx: 2.4%; --dy: 2%; }
.psky-b > b { aspect-ratio: 403 / 648; background-image: url("./assets/editorial/cielo/noche-b.webp"); }
.psky-a { --px: -.04; --py: .1; --pw: .17; --nx: 9%; --ny: 76%; --nw: min(32vw, 66vh); --o: .95; --d: .8; --fx: -18vw; --fy: 46vh; --fs: 2.2; --drift: 18s; --drift-delay: -4s; --dx: 1.8%; --dy: 1.4%; }
.psky-a > b { aspect-ratio: 666 / 942; background-image: url("./assets/editorial/cielo/noche-a.webp"); }

/* Cielo detrás de las cifras: más profundo arriba, luz menta abajo a la derecha */
.ap-numbers {
  background:
    radial-gradient(ellipse 46% 40% at 82% 96%, #1a8a86 0%, transparent 62%),
    radial-gradient(ellipse 60% 54% at 24% 60%, #3b62ad 0%, transparent 70%),
    radial-gradient(ellipse 40% 30% at 62% 8%, #6b7fd8 0%, transparent 70%),
    linear-gradient(170deg, #1b1c58 0%, #2b2f80 48%, #22397c 100%);
}
.ap-numbers-clouds::after { background: linear-gradient(#1a1a52cc, #22226400 30%, #1c1c5400 70%, #1a1d5280); }
/* Las cifras se leen sobre un vidrio oscuro, no sobre la nube */
.ap-numbers .institutional-numbers-grid {
  background: #13163fd1;
  backdrop-filter: blur(10px) saturate(1.2);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
}

/* ---------- Pasaje: atravesar la capa de nubes ---------- */
.ap-cloud-passage::before {
  background:
    radial-gradient(ellipse 60% 50% at 62% 34%, #d9e6ff, transparent 72%),
    radial-gradient(ellipse 50% 40% at 30% 80%, #6fd8c0, transparent 70%),
    linear-gradient(160deg, #303c96, #5a7fcf 52%, #3d93ad);
}
.ap-passage-billows {
  mask-image: linear-gradient(transparent, #000 8%);
  opacity: .96;
}

/* ---------- 4 · Las nubes se juntan y forman el símbolo ---------- */
.ap-brand-mark::before {
  background:
    url("./assets/editorial/cielo/noche-capas.webp") center / 118% auto no-repeat,
    radial-gradient(ellipse at 50% 52%, #6f8be055, transparent 70%);
}
.ap-piece {
  --k: 0;
  position: absolute;
  inset: 0;
  transform:
    translate3d(calc((1 - var(--k)) * var(--from-x)), calc((1 - var(--k)) * var(--from-y)), 0)
    rotate(calc((1 - var(--k)) * var(--turn)));
}
.ap-piece-top { --k: var(--mark-top, 0); --from-x: 150%; --from-y: -95%; --turn: 14deg; --cx: 70%; --cy: 16%; --cw: 92%; }
.ap-piece-middle { --k: var(--mark-middle, 0); --from-x: -165%; --from-y: 20%; --turn: -10deg; --cx: 30%; --cy: 50%; --cw: 120%; }
.ap-piece-bottom { --k: var(--mark-bottom, 0); --from-x: 140%; --from-y: 105%; --turn: -14deg; --cx: 70%; --cy: 84%; --cw: 96%; }

/* La nube libre: llega grande, se achica y se condensa sobre su pieza */
.ap-piece-cloud {
  position: absolute;
  left: var(--cx);
  top: var(--cy);
  width: var(--cw);
  aspect-ratio: var(--ca);
  background: center / contain no-repeat;
  opacity: calc(clamp(0, calc(var(--k) * 4), 1) * (1 - clamp(0, calc((var(--k) - .5) * 2.4), 1)));
  transform: translate(-50%, -50%) scale(calc(1.75 - var(--k) * .95)) rotate(calc((1 - var(--k)) * -18deg));
  filter: blur(calc((1 - var(--k)) * 2px)) drop-shadow(0 0 calc(var(--k) * 24px) var(--glow));
}
.ap-piece-top .ap-piece-cloud { --ca: 403 / 648; --glow: #3cd2ad99; background-image: url("./assets/editorial/cielo/pieza-menta.webp"); }
.ap-piece-middle .ap-piece-cloud { --ca: 666 / 942; --glow: #6b6bf099; background-image: url("./assets/editorial/cielo/pieza-indigo.webp"); }
.ap-piece-bottom .ap-piece-cloud { --ca: 566 / 779; --glow: #247ecd99; background-image: url("./assets/editorial/cielo/pieza-azul.webp"); }

/* La pieza recortada: el mismo vapor, con el color del logo */
.ap-piece .ap-brand-cloud-piece {
  --piece-progress: var(--k);
  opacity: clamp(0, calc((var(--k) - .42) * 2.6), 1);
  transform: scale(calc(.9 + var(--k) * .1));
}
.ap-piece-top .ap-brand-cloud-piece {
  clip-path: polygon(14% 0%, 100% 0%, 100% 45%);
  background:
    url("./assets/editorial/cielo/pieza-menta.webp") 82% 22% / 120% auto no-repeat,
    linear-gradient(140deg, #9af0d6, #3cd2ad 50%, #178a7a);
}
.ap-piece-middle .ap-brand-cloud-piece {
  clip-path: polygon(0 7%, 67% 39%, 74% 48%, 70% 57%, 0 94%);
  background:
    url("./assets/editorial/cielo/pieza-indigo.webp") 20% 50% / 95% auto no-repeat,
    linear-gradient(160deg, #7a8fe6, #4343a3 52%, #26267a);
}
.ap-piece-bottom .ap-brand-cloud-piece {
  clip-path: polygon(14% 100%, 100% 54%, 100% 100%);
  background:
    url("./assets/editorial/cielo/pieza-azul.webp") 62% 34% / 150% auto no-repeat,
    linear-gradient(120deg, #5cc6ee, #247ecd 58%, #1a5aa3);
}

/* ---------- Móvil: las nubes acompañan el aro y el texto queda limpio ---------- */
@media (max-width: 800px), (max-width: 1024px) and (orientation: portrait) {
  .sky-banda { --hx: 0; --hy: .3; --hw: 2.6; }
  .sky-banda { -webkit-mask-image: none; mask-image: none; --o: .55; }
  .sky-c { --hx: .36; --hy: -.12; --hw: .36; }
  .sky-b { --hx: -.37; --hy: -.02; --hw: .2; }
  .sky-a { --hx: -.1; --hy: .4; --hw: .44; }
  .psky-a { --nx: 14%; --ny: 84%; --nw: 62vw; }
  .psky-c { --nx: 92%; --ny: 30%; --nw: 46vw; }
  .psky-b { --nx: 40%; --ny: 10%; --nw: 26vw; }
  .ap-piece-top { --from-x: 120%; --from-y: -120%; }
  .ap-piece-middle { --from-x: -130%; --from-y: 40%; }
  .ap-piece-bottom { --from-x: 110%; --from-y: 130%; }
}

/* Sin movimiento: cielo quieto y compuesto */
:root:not(.ap-on) :is(.ap-sky, .ap-numbers-clouds) {
  --fly: 0;
  --sky: 1;
  --sky-rise: 0;
  --mx: 0;
  --my: 0;
}
.motion-off .sky > b, .motion-off .psky > b { animation: none; }
@media (prefers-reduced-motion: reduce) { .sky > b, .psky > b { animation: none; } }
