/* ==========================================================================
   Hero 3D (oct 2026)
   Referencia: "Hero Loop" (Webflow) + diseño del hero de Magna (oct 2026).
   Tres frases que rotan en 3D, sincronizadas con escenas en capas: una línea
   de color al fondo y personas recortadas al frente, a distinta profundidad,
   que se inclinan con el cursor (o el giroscopio en celular).
   Sin librerías: CSS + JS propio.
   ========================================================================== */

.hx {
  --accent: var(--magna-empresas);
  --rx: 0deg;            /* inclinación del escenario (JS, cursor) */
  --ry: 0deg;
  --px: 0;               /* parallax normalizado -1..1 (JS, cursor) */
  --py: 0;
  position: relative;
  min-height: min(calc(100svh - 5.5rem), 60rem);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--space-4) 0 var(--space-3);
  overflow: hidden;
}
.hx[data-slide="1"] { --accent: #2bb0ef; }               /* Gobiernos, aclarado para fondo tinta */
.hx[data-slide="2"] { --accent: var(--magna-core); }

/* ---- Fondo: foto del escritorio (ya viene oscurecida desde diseño) ---- */
.hx-bg { position: absolute; inset: 0; z-index: 0; overflow: hidden; }
.hx-bg-img {
  position: absolute;
  inset: -4%;
  transform: translate3d(calc(var(--px) * -14px), calc(var(--py) * -10px), 0) scale(1.04);
}
.hx-bg-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hx-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  /* solo un velo a la izquierda para que el texto se lea bien */
  background: linear-gradient(90deg, rgba(20,20,20,0.72) 0%, rgba(20,20,20,0.38) 42%, rgba(20,20,20,0) 68%);
}

.hx-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  align-items: center;
  gap: var(--space-5);
  width: 100%;
}
.hx-copy { position: relative; z-index: 2; }
/* magna.css pone ".field > .wrap" en position: relative; aquí el grid no debe
   serlo, para que el escenario se ubique respecto a todo el hero */
.hx > .wrap.hx-grid { position: static; }
.hx > .wrap.hx-controls { z-index: 2; }

/* ---- Rotador de frases en 3D ---- */
.hx-title {
  margin: 0;
  font-size: clamp(2.3rem, 0.9rem + 3.5vw, 4.75rem);
  line-height: 1;
  letter-spacing: -0.035em;
  font-weight: 900;
}
.hx-rotator {
  display: grid;
  align-items: end;
  perspective: 900px;
  perspective-origin: 30% 50%;
}
.hx-phrase { grid-area: 1 / 1; display: block; text-wrap: balance; }
.hx-w {
  display: inline-block;
  transform-style: preserve-3d;
}
.hx-w > span {
  display: inline-block;
  transform-origin: 50% 100% -0.45em;
  transform: rotateX(-96deg);
  opacity: 0;
  transition:
    transform 0.55s cubic-bezier(0.55, 0, 0.75, 0.2),
    opacity 0.35s ease;
  transition-delay: calc(var(--i, 0) * 45ms);
  backface-visibility: hidden;
}
.hx-phrase.is-in .hx-w > span {
  transform: rotateX(0deg);
  opacity: 1;
  transition:
    transform 1.1s var(--ease-out-expo),
    opacity 0.6s ease;
  transition-delay: calc(240ms + var(--i, 0) * 80ms);
}
.hx-phrase.is-out .hx-w > span { transform: rotateX(96deg); opacity: 0; }
.hx-accent { position: relative; color: var(--accent); transition: color 0.6s ease; }
.hx-accent::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0.12em;
  bottom: -0.06em;
  height: 0.09em;
  border-radius: 999px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.9s var(--ease-out-expo);
}
.hx-phrase.is-in .hx-accent::after { transform: scaleX(1); transition-delay: 0.8s; }

/* ---- Texto existente, distribuido: el fragmento de cada frase se ilumina ---- */
.hx-story {
  margin: var(--space-3) 0 0;
  max-width: 34rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.15rem, 0.9rem + 0.7vw, 1.5rem);
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.hx-step {
  color: rgba(255,255,255,0.42);
  background-image: linear-gradient(var(--accent), var(--accent));
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 0% 2px;
  transition: color 0.6s ease, background-size 0.9s var(--ease-out-expo);
}
.hx-step.is-on { color: #fff; background-size: 100% 2px; }
.hx-lede {
  margin: var(--space-3) 0 0;
  max-width: 36rem;
  font-size: 1.05rem;
  line-height: 1.6;
  color: rgba(255,255,255,0.8);
}
.hx-lede .hx-step { color: rgba(255,255,255,0.8); font-weight: 600; }
.hx-lede .hx-step.is-on { color: #fff; }
.field-ink .hx-lede a.hx-front {
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.22em;
  transition: color 0.2s ease, text-decoration-color 0.2s ease;
}
.field-ink .hx-lede a.hx-front[data-front="gobiernos"] { color: #6cc8f2; text-decoration-color: rgba(108,200,242,0.45); }
.field-ink .hx-lede a.hx-front[data-front="empresas"] { color: var(--magna-empresas); text-decoration-color: rgba(255,171,0,0.45); }
.field-ink .hx-lede a.hx-front[data-front="personas"] { color: #ff7d9c; text-decoration-color: rgba(255,125,156,0.45); }
.field-ink .hx-lede a.hx-front:hover { text-decoration-color: currentColor; }
.hx .hero-actions { margin: var(--space-3) 0 0; }

/* ---- Escenario 3D: escenas en capas (línea atrás, personas adelante) ----
   En escritorio ocupa la mitad derecha del hero, de arriba abajo, como en el
   diseño. Las imágenes son cuadradas (1100×1108) con fondo transparente. */
.hx-stage {
  position: absolute;
  z-index: 1;
  bottom: -2%;
  right: min(0px, calc((100vw - 80rem) * 0.5));
  height: 102%;
  aspect-ratio: 1100 / 1108;
  perspective: 1600px;
  perspective-origin: 50% 40%;
}
.hx-rig {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform-origin: 50% 70%;
  transform: rotateX(calc(var(--rx) * 0.55)) rotateY(calc(var(--ry) * 0.55));
}
.hx-card {
  position: absolute;
  inset: 0;
  margin: 0;
  transform-style: preserve-3d;
  pointer-events: none;
  transition: transform 1.2s var(--ease-out-expo), opacity 0.9s ease;
}
.hx-line, .hx-people {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  -webkit-user-drag: none;
  user-select: none;
}
/* La línea va 140px más atrás (escalada para compensar la perspectiva) y
   se "dibuja" de derecha a izquierda cuando entra su frase */
.hx-line {
  transform: translate3d(calc(var(--px) * -12px), calc(var(--py) * -8px), -140px) scale(1.09);
  clip-path: inset(0 0 0 100%);
  transition: clip-path 1.3s cubic-bezier(0.65, 0, 0.35, 1);
}
.hx-card[data-pos="0"] .hx-line { clip-path: inset(0 0 0 0); transition-delay: 0.25s; }
.hx-people { transform: translate3d(calc(var(--px) * 8px), calc(var(--py) * 6px), 30px); }

.hx-card[data-pos="0"] { opacity: 1; z-index: 3; }
.hx-card[data-pos="1"],
.hx-card[data-pos="2"] { transform: translate3d(14%, 4%, -240px) rotateY(-14deg); opacity: 0; z-index: 1; }
.hx-card[data-pos="out"] {
  transform: translate3d(-42%, 6%, 140px) rotateY(28deg);
  opacity: 0;
  z-index: 4;
  transition: transform 0.8s cubic-bezier(0.55, 0, 0.75, 0.2), opacity 0.6s ease 0.1s;
}

/* Etiquetas flotantes (capítulos) — cambian con cada frase */
.hx-chips { position: absolute; inset: 0; transform-style: preserve-3d; pointer-events: none; }
.hx-chip {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.9rem;
  white-space: nowrap;
  box-shadow: 0 1rem 2rem -0.75rem rgba(0,0,0,0.6);
  opacity: 0;
  transition: opacity 0.5s ease, transform 0.9s var(--ease-out-expo);
}
.hx-chip::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--accent);
  transition: background 0.6s ease;
}
.hx-chip.is-a { top: 46%; left: 10%; transform: translateZ(60px) translateY(10px); }
.hx-chip.is-b { top: 62%; right: 8%; transform: translateZ(130px) translateY(10px); }
.hx-chip.is-on { opacity: 1; }
.hx-chip.is-a.is-on { transform: translateZ(60px); transition-delay: 0.45s; }
.hx-chip.is-b.is-on { transform: translateZ(130px); transition-delay: 0.6s; }

/* Sello circular "19 años" */
.hx-badge {
  position: absolute;
  right: 4%;
  top: 7%;
  width: 7.5rem;
  height: 7.5rem;
  transform: translateZ(120px);
  border-radius: 50%;
  background: var(--accent);
  color: var(--ink);
  display: grid;
  place-items: center;
  box-shadow: 0 1.25rem 2.5rem -0.75rem rgba(0,0,0,0.65);
  transition: background 0.8s ease;
}
.hx-badge svg { position: absolute; inset: 0; width: 100%; height: 100%; animation: hx-spin 22s linear infinite; }
.hx-badge text { font-family: var(--font-display); font-weight: 800; font-size: 10.2px; letter-spacing: 0.14em; fill: var(--ink); text-transform: uppercase; }
.hx-badge-core { text-align: center; line-height: 0.9; font-family: var(--font-display); }
.hx-badge-core strong { display: block; font-size: 2.35rem; font-weight: 900; letter-spacing: -0.04em; }
.hx-badge-core span { font-size: 0.8rem; font-weight: 800; }
@keyframes hx-spin { to { transform: rotate(360deg); } }

/* ---- Controles: pestañas con progreso, flechas y pausa ---- */
.hx-controls {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-4);
  width: 100%;
}
/* en escritorio los controles quedan bajo el texto, sin tapar a las personas */
.hx-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2); flex: 0 1 32rem; min-width: 0; }
/* anterior/siguiente se reemplazan por las pestañas (clic o flechas del teclado) */
.hx-btns .hx-prev, .hx-btns .hx-next { display: none; }
.hx-tab {
  position: relative;
  padding: 0.85rem 0 0;
  border: 0;
  background: none;
  color: rgba(255,255,255,0.55);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.3s ease;
}
.hx-tab::before, .hx-tab-bar {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  height: 3px;
  border-radius: 999px;
}
.hx-tab::before { right: 0; background: rgba(255,255,255,0.2); }
.hx-tab-bar { width: 0; background: var(--accent); transition: background 0.6s ease; }
.hx-tab:hover, .hx-tab[aria-selected="true"] { color: #fff; }
.hx-tab[aria-selected="true"] .hx-tab-bar { animation: hx-progress var(--hx-dur, 6500ms) linear forwards; }
.hx.is-paused .hx-tab[aria-selected="true"] .hx-tab-bar { animation-play-state: paused; }
@keyframes hx-progress { from { width: 0; } to { width: 100%; } }
.hx-tab:focus-visible, .hx-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }

.hx-btns { display: flex; gap: 0.5rem; flex-shrink: 0; }
.hx-btn {
  width: 2.75rem;
  height: 2.75rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.4);
  background: rgba(20,20,20,0.3);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s var(--ease-out-expo);
}
.hx-btn:hover { border-color: #fff; background: rgba(255,255,255,0.12); transform: translateY(-1px); }
.hx-btn svg { width: 1.1rem; height: 1.1rem; }
.hx-btn .i-play { display: none; }
.hx.is-user-paused .hx-btn .i-play { display: block; }
.hx.is-user-paused .hx-btn .i-pause { display: none; }

/* ---- Gesto táctil: la escena de adelante sigue al dedo ---- */
.hx-card[data-pos="0"] {
  transform:
    translate3d(var(--dx, 0px), 0, 0)
    rotateY(calc(var(--dr, 0) * 1deg))
    rotateZ(calc(var(--dr, 0) * -0.12deg));
}
.hx.is-dragging .hx-card { transition: none; }
.hx-card[data-pos="out-r"] {
  transform: translate3d(42%, 6%, 140px) rotateY(-28deg);
  opacity: 0;
  z-index: 4;
  transition: transform 0.8s cubic-bezier(0.55, 0, 0.75, 0.2), opacity 0.6s ease 0.1s;
}

/* Escritorio angosto: escena un poco más pequeña y corrida a la derecha
   para no montarse sobre el texto */
@media (min-width: 961px) and (max-width: 1200px) {
  .hx-stage { height: 90%; bottom: 0; right: calc((100vw - 80rem) * 0.7); }
}

/* ---- Responsive ----
   Tablet y celular: la escena 3D va primero (arriba), luego las pestañas
   como barras de historia y después el texto. Así las fotos se ven al abrir
   la página en vez de quedar al fondo. .hx-grid se "disuelve" con
   display: contents para poder reordenar escenario, controles y texto. */
@media (max-width: 960px) {
  .hx {
    min-height: auto;
    justify-content: flex-start;
    padding: var(--space-3) 0 var(--space-4);
    overflow: hidden;
  }
  .hx-grid { display: contents; }
  .hx-copy { position: relative; z-index: 2; }
  .hx-stage {
    order: 1;
    position: relative;
    z-index: 1;
    right: auto;
    bottom: auto;
    height: auto;
    width: min(100%, 34rem);
    margin: 0 auto;
    perspective: 1200px;
    touch-action: pan-y;               /* el scroll vertical sigue funcionando */
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  .hx-controls { order: 2; margin-top: calc(var(--space-4) * -1); }
  .hx-tabs { flex: 1; }
  /* la parte de abajo de las personas se desvanece hacia las pestañas */
  .hx-people, .hx-line {
    -webkit-mask-image: linear-gradient(180deg, #000 72%, transparent 98%);
    mask-image: linear-gradient(180deg, #000 72%, transparent 98%);
  }
  .hx-copy {
    order: 3;
    width: 100%;
    max-width: 78rem;
    margin: var(--space-3) auto 0;
    padding: 0 var(--space-3);
  }
  .hx-bg::after {
    background: linear-gradient(180deg, rgba(20,20,20,0.1) 0%, rgba(20,20,20,0.45) 40%, rgba(20,20,20,0.85) 70%);
  }
  .hx-chip.is-a { top: 34%; left: 4%; }
  .hx-chip.is-b { top: 62%; right: 6%; }
  .hx-badge { width: 6.75rem; height: 6.75rem; right: 4%; top: 6%; left: auto; bottom: auto; }
  .hx-badge-core strong { font-size: 1.85rem; }
  .hx-badge text { font-size: 8.4px; }
}
@media (max-width: 760px) {
  .hx { padding-top: var(--space-2); }
  .hx-stage { width: 100%; }
  .hx-controls { gap: var(--space-2); }
  .hx-tabs { gap: 0.6rem; }
  .hx-tab { font-size: 0.75rem; white-space: normal; line-height: 1.25; overflow: visible; padding-top: 0.7rem; }
  .hx-btn { width: 2.5rem; height: 2.5rem; }
  .hx-copy { margin-top: var(--space-3); display: flex; flex-direction: column; }
  .hx-copy .hero-actions { order: 1; }   /* botones antes del párrafo largo */
  .hx-copy .hx-lede { order: 2; }
  .hx-title { font-size: clamp(2.15rem, 1.2rem + 4.4vw, 2.9rem); }
  /* Cada frase con su propio tamaño para que ocupen casi el mismo alto
     y no quede un hueco grande sobre "Tú imaginas." */
  .hx-phrase[data-phrase="0"] { font-size: 1.22em; }
  .hx-phrase[data-phrase="2"] { font-size: 0.8em; line-height: 1.04; }
  .hx-story { margin-top: var(--space-2); font-size: 1.12rem; }
  .hx-lede { margin-top: var(--space-3); font-size: 1rem; line-height: 1.55; }
  .hx .hero-actions { flex-wrap: nowrap; margin-top: var(--space-3); }
  .hx .hero-actions .btn { flex: 1 1 0; justify-content: center; white-space: nowrap; font-size: 0.95rem; padding: 0.9rem 0.75rem; }
  .hx-chip { font-size: 0.74rem; padding: 0.4rem 0.75rem; gap: 0.4rem; }
  /* Menos profundidad (translateZ) en celular: con la perspectiva, lo que
     está muy "adelante" se agranda y se sale del borde de la pantalla */
  .hx-chip.is-a { top: 34%; left: 6%; transform: translateZ(45px) translateY(10px); }
  .hx-chip.is-b { top: 62%; right: 7%; transform: translateZ(55px) translateY(10px); }
  .hx-chip.is-a.is-on { transform: translateZ(45px); }
  .hx-chip.is-b.is-on { transform: translateZ(55px); }
  .hx-badge { width: 5.25rem; height: 5.25rem; right: 8%; top: 6%; transform: translateZ(50px); }
  .hx-badge-core strong { font-size: 1.5rem; }
  .hx-badge-core span { font-size: 0.68rem; }
  .hx-badge text { font-size: 8.6px; letter-spacing: 0.1em; }
}
@media (max-width: 480px) {
  /* "Tú / imaginas." grande en dos líneas: llena el mismo alto que la frase larga */
  .hx-phrase[data-phrase="0"] { font-size: clamp(2.6rem, 14.5vw, 4.25rem); line-height: 0.98; }
  .hx-phrase[data-phrase="0"] .hx-w { display: block; width: fit-content; }
}
@media (max-width: 340px) {
  .hx .hero-actions { flex-wrap: wrap; }
  .hx .hero-actions .btn { flex-basis: 100%; }
}

/* ---- Movimiento reducido: sin 3D ni giros; las frases y fotos solo
   aparecen y desaparecen suavemente (fundido) ---- */
@media (prefers-reduced-motion: reduce) {
  .hx-rig { transform: none; }
  .hx-badge svg { animation: none; }
  .hx-w > span { transform: none !important; }
  .hx-phrase.is-out { visibility: hidden; }
  .hx-bg-img, .hx-line, .hx-people { transform: none; }
  .hx-line { clip-path: none; transition: none; }
  .hx-card, .hx-card[data-pos] { transform: none !important; transition: opacity 0.8s ease; filter: none; }
  .hx-card:not([data-pos="0"]) { opacity: 0; }
}
