/* ==========================================================================
   Legado 7 — Dobra 02: do marketing fragmentado ao marketing conectado
   Sequência automática quando a seção entra na tela (conexao.js marca as fases):
     .is-in            → tudo solto + mensagem inicial
     .fase-l7          → o símbolo da Legado 7 surge no centro
     .fase-organiza    → as peças se organizam em torno dele
     .fase-conecta     → as linhas conectam tudo
     .fase-movimento   → pulsos percorrem a estrutura + mensagem final
   Sem JS ou com movimento reduzido: a composição aparece pronta (estado final).
   ========================================================================== */

.conexao { position: relative; background: var(--l7-abismo); }

.conexao__stage {
  position: relative; overflow: clip;
  display: grid; grid-template-rows: auto 1fr auto; justify-items: center;
  padding: clamp(72px, 10vh, 120px) var(--gutter) clamp(56px, 8vh, 96px);
}
.is-animated .conexao__stage {
  height: 100vh; height: 100svh; min-height: 620px;
  padding-top: calc(var(--header-h) + clamp(12px, 3vh, 32px));
  padding-bottom: clamp(20px, 4vh, 40px);
}

/* Fundo: continua a Hero e ganha uma grade "de planta" quando a estrutura se forma */
.conexao__bg { position: absolute; inset: 0; z-index: -1; pointer-events: none; }
.conexao__bg::before {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(45% 45% at 50% 55%, rgba(164, 5, 78, .26), transparent 70%),
    radial-gradient(60% 50% at 0% 100%, rgba(7, 30, 65, .7), transparent 70%),
    radial-gradient(50% 40% at 100% 0%, rgba(4, 31, 87, .45), transparent 70%);
  transition: opacity 1.4s var(--ease);
}
.conexao__bg::after {
  content: ""; position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, .05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .05) 1px, transparent 1px);
  background-size: 48px 48px; background-position: center;
  -webkit-mask-image: radial-gradient(55% 50% at 50% 55%, #000, transparent 80%);
  mask-image: radial-gradient(55% 50% at 50% 55%, #000, transparent 80%);
  transition: opacity 1.6s var(--ease);
}

/* Textos ------------------------------------------------------------------ */
.conexao__intro { text-align: center; width: 100%; max-width: 1000px; transition: opacity 1s var(--ease), transform 1s var(--ease); }
.conexao__title, .conexao__punch {
  margin: 0; font-weight: 800; letter-spacing: -.025em; line-height: 1.08;
  font-size: clamp(28px, 2.3vw + 12px, 50px); text-wrap: balance;
}
.conexao__punch { margin-top: .12em; color: var(--l7-rosa-glow); }
/* "sem conexão": sublinhado partido, em pedaços soltos */
.conexao__broken {
  padding-bottom: .1em;
  background: repeating-linear-gradient(90deg, currentColor 0 .5em, transparent .5em .8em) left bottom / 100% .06em no-repeat;
}

.conexao__outro { display: grid; justify-items: center; gap: 14px; text-align: center; }
.conexao__final {
  margin: 0; max-width: 30ch;
  font-weight: 700; letter-spacing: -.02em; line-height: 1.2;
  font-size: clamp(22px, 1.3vw + 13px, 36px); text-wrap: balance;
}
.conexao__highlight {
  position: relative; display: inline-block; font-style: normal; color: var(--l7-rosa-glow);
  text-shadow: 0 0 28px rgba(255, 26, 94, .35);
}
.conexao__highlight::after {
  content: ""; position: absolute; left: .04em; right: .04em; bottom: -.04em; height: .07em; min-height: 2px;
  background: linear-gradient(90deg, var(--l7-magenta), var(--l7-rosa-glow)); border-radius: 2px;
  transform-origin: left;
}
.conexao__highlight::before {
  content: ""; position: absolute; right: -.02em; bottom: -.1em; width: .17em; height: .17em; min-width: 7px; min-height: 7px;
  background: var(--l7-rosa-glow); border-radius: 2px; transform: rotate(45deg);
  box-shadow: 0 0 12px rgba(255, 26, 94, .9);
}
.conexao__next {
  margin: 0; display: inline-flex; align-items: center; gap: 10px;
  font-family: var(--l7-mono); font-size: 11px; letter-spacing: .2em; text-transform: uppercase; color: var(--l7-texto-suave);
}
.conexao__next::after {
  content: ""; width: 7px; height: 7px; border-right: 1.5px solid var(--l7-rosa-glow); border-bottom: 1.5px solid var(--l7-rosa-glow);
  transform: rotate(45deg) translateY(-2px);
}

/* Palco da composição ----------------------------------------------------- */
.conexao__board-wrap { position: relative; width: 100%; max-width: var(--max); margin: clamp(16px, 3vh, 32px) 0; }
.conexao__board { position: relative; width: 100%; aspect-ratio: 1200 / 520; margin: 0 auto; }
.is-animated .conexao__board-wrap { min-height: 0; }
.is-animated .conexao__board { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }

.conexao__lines { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.conexao__lines--mobile { display: none; }
.conexao__stubs path {
  fill: none; stroke: rgba(255, 255, 255, .22); stroke-width: 1.2; stroke-dasharray: 3 5; stroke-linecap: round;
  opacity: 0; transition: opacity .6s var(--ease);
}
.conexao__links path {
  fill: none; stroke: rgba(255, 26, 94, .75); stroke-width: 1.5;
  stroke-linejoin: round; stroke-linecap: round;
  filter: drop-shadow(0 0 4px rgba(255, 26, 94, .55));
}
.conexao__links .conexao__direction { stroke: var(--l7-rosa-glow); stroke-width: 2; }
.conexao__joints circle { fill: var(--l7-rosa-glow); filter: drop-shadow(0 0 5px rgba(255, 26, 94, .9)); transition: opacity .5s var(--ease) .7s; }

/* pulsos percorrendo as conexões (criados pelo JS) */
.conexao__flow path { fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-dasharray: 8 600; opacity: 0; }

/* Peças -------------------------------------------------------------------- */
.conexao__nodes { position: absolute; inset: 0; margin: 0; padding: 0; list-style: none; }
.conexao__chip, .conexao__core {
  position: absolute;
  left: calc(var(--fx) * 100% / 1200); top: calc(var(--fy) * 100% / 520);
}
.conexao__chip {
  width: 220px;
  transform: translate(-50%, -50%) translate(0px, 0px) rotate(0deg) scale(var(--s, 1));
}
.conexao__chip-inner {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 10px;
  height: 52px; padding: 0 18px; border-radius: 999px;
  background: linear-gradient(180deg, rgba(14, 24, 62, .96), rgba(8, 14, 42, .96));
  border: 1px solid rgba(255, 26, 94, .42);
  box-shadow: 0 14px 34px -14px rgba(0, 0, 0, .8), inset 0 1px 0 rgba(255, 255, 255, .06);
  font-size: 12.5px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: #DDE0EE;
  white-space: nowrap;
  transition: border-color .8s var(--ease);
}
.conexao__chip-inner svg {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: var(--l7-rosa-glow); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}

/* Núcleo: o símbolo da Legado 7 (centro do emblema = ponto da composição) */
.conexao__core {
  --core-y: 48px;
  z-index: 2; display: grid; justify-items: center; gap: 10px;
  transform: translate(-50%, calc(var(--core-y) * -1)) scale(var(--s, 1));
  transform-origin: 50% var(--core-y);
}
.conexao__core-emblem {
  position: relative; display: grid; place-items: center;
  width: calc(var(--core-y) * 2); height: calc(var(--core-y) * 2); border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #1a2a66, var(--l7-navy) 70%);
  border: 1px solid rgba(255, 26, 94, .55);
  box-shadow: 0 0 0 8px rgba(230, 11, 79, .08), 0 0 50px rgba(230, 11, 79, .45);
}
.conexao__core-emblem svg { width: 52%; height: auto; fill: var(--l7-rosa-glow); filter: drop-shadow(0 0 10px rgba(255, 26, 94, .7)); }
.conexao__core-emblem::after { /* onda de choque quando surge */
  content: ""; position: absolute; inset: -2px; border-radius: 50%;
  border: 1.5px solid rgba(255, 26, 94, .7); opacity: 0; pointer-events: none;
}
.conexao__core-label {
  font-family: var(--l7-mono); font-size: 11px; letter-spacing: .22em; text-transform: uppercase; color: #fff;
}

/* --------------------------------------------------------------------------
   Estados da animação (só existem com JS e sem movimento reduzido)
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: no-preference) {
  /* 1. Tudo solto */
  .is-animated .conexao__bg::before { opacity: .45; }
  .is-animated .conexao__bg::after { opacity: .12; }
  .is-animated .conexao__stubs path { opacity: 1; }
  .is-animated .conexao__chip {
    transform: translate(-50%, -50%) translate(calc(var(--dx, 0) * var(--u, 1px)), calc(var(--dy, 0) * var(--u, 1px))) rotate(calc(var(--r, 0) * 1deg)) scale(calc(var(--s, 1) * .92));
    opacity: .62;
    transition: transform 1.3s cubic-bezier(.7, 0, .25, 1) var(--atraso, 0s), opacity .9s var(--ease) var(--atraso, 0s);
  }
  .is-animated .conexao__chip-inner { border-color: rgba(255, 255, 255, .12); animation: conexao-flutuar 5.5s ease-in-out infinite alternate; }
  .is-animated .conexao__chip:nth-child(2) { --atraso: .06s; }
  .is-animated .conexao__chip:nth-child(3) { --atraso: .12s; }
  .is-animated .conexao__chip:nth-child(4) { --atraso: .03s; }
  .is-animated .conexao__chip:nth-child(5) { --atraso: .09s; }
  .is-animated .conexao__chip:nth-child(6) { --atraso: .15s; }
  .is-animated .conexao__chip:nth-child(2) .conexao__chip-inner { animation-duration: 6.4s; animation-delay: -2s; }
  .is-animated .conexao__chip:nth-child(3) .conexao__chip-inner { animation-duration: 5s; animation-delay: -1s; }
  .is-animated .conexao__chip:nth-child(4) .conexao__chip-inner { animation-duration: 7s; animation-delay: -3s; }
  .is-animated .conexao__chip:nth-child(5) .conexao__chip-inner { animation-duration: 6s; animation-delay: -4s; }
  .is-animated .conexao__chip:nth-child(6) .conexao__chip-inner { animation-duration: 5.8s; animation-delay: -2.5s; }

  .is-animated .conexao__core { opacity: 0; transform: translate(-50%, calc(var(--core-y) * -1)) scale(calc(var(--s, 1) * .3)); }
  .is-animated .conexao__core-label { opacity: 0; transform: translateY(-6px); transition: opacity .6s var(--ease) .5s, transform .6s var(--ease) .5s; }
  .is-animated .conexao__links path { stroke-dasharray: 1; stroke-dashoffset: 1; transition: stroke-dashoffset .9s cubic-bezier(.6, 0, .3, 1); }
  .is-animated .conexao__joints circle { opacity: 0; }
  .is-animated .conexao__final { opacity: 0; transform: translateY(18px); transition: opacity .9s var(--ease), transform .9s var(--ease); }
  .is-animated .conexao__highlight::after { transform: scaleX(0); transition: transform .7s var(--ease) 1s; }
  .is-animated .conexao__highlight::before { transform: rotate(45deg) scale(0); transition: transform .4s var(--ease) 1.6s; }
  .is-animated .conexao__next { opacity: 0; transition: opacity .8s var(--ease) 1.8s; }

  /* Mensagem inicial */
  .is-animated .conexao__title, .is-animated .conexao__punch { opacity: 0; transform: translateY(18px); transition: opacity .8s var(--ease), transform .8s var(--ease); }
  .is-animated .conexao__punch { transition-delay: .45s; }
  .is-animated.is-in .conexao__title, .is-animated.is-in .conexao__punch { opacity: 1; transform: none; }

  /* 2. A Legado 7 surge */
  .is-animated.fase-l7 .conexao__bg::before { opacity: 1; }
  .is-animated.fase-l7 .conexao__core { animation: conexao-surgir .9s cubic-bezier(.2, 1.4, .4, 1) both; }
  .is-animated.fase-l7 .conexao__core-emblem::after { animation: conexao-onda 1.4s cubic-bezier(.2, .7, .3, 1) .25s; }
  .is-animated.fase-l7 .conexao__core-label { opacity: 1; transform: none; }

  /* 3. Tudo se organiza em torno dela */
  .is-animated.fase-organiza .conexao__chip { transform: translate(-50%, -50%) translate(0px, 0px) rotate(0deg) scale(var(--s, 1)); opacity: 1; }
  .is-animated.fase-organiza .conexao__chip-inner { animation: none; }
  .is-animated.fase-organiza .conexao__stubs path { opacity: 0; }

  /* 4. Conexão */
  .is-animated.fase-conecta .conexao__bg::after { opacity: 1; }
  .is-animated.fase-conecta .conexao__chip-inner { border-color: rgba(255, 26, 94, .42); }
  .is-animated.fase-conecta .conexao__links path { stroke-dashoffset: 0; }
  .is-animated.fase-conecta .conexao__links path:nth-child(2), .is-animated.fase-conecta .conexao__links path:nth-child(5) { transition-delay: .12s; }
  .is-animated.fase-conecta .conexao__links path:nth-child(3), .is-animated.fase-conecta .conexao__links path:nth-child(6) { transition-delay: .24s; }
  .is-animated.fase-conecta .conexao__links path:nth-child(7) { transition-delay: .3s; }
  .is-animated.fase-conecta .conexao__joints circle { opacity: 1; }
  .is-animated.fase-conecta .conexao__links .conexao__direction { stroke-dashoffset: 1; transition-delay: 0s; }

  /* 5. Movimento: a estrutura ganha vida */
  .is-animated.fase-movimento .conexao__links .conexao__direction { stroke-dashoffset: 0; transition-duration: .8s; }
  .is-animated.fase-movimento .conexao__final { opacity: 1; transform: none; transition-delay: .35s; }
  .is-animated.fase-movimento .conexao__highlight::after { transform: scaleX(1); }
  .is-animated.fase-movimento .conexao__highlight::before { transform: rotate(45deg) scale(1); }
  .is-animated.fase-movimento .conexao__next { opacity: 1; }
  .is-animated.fase-movimento .conexao__flow path { opacity: .9; animation: conexao-fluxo 2.6s linear infinite; }
  .is-animated.fase-movimento .conexao__flow path:nth-child(2n) { animation-delay: -.9s; }
  .is-animated.fase-movimento .conexao__flow path:nth-child(3n) { animation-delay: -1.7s; }
  .is-animated.fase-movimento .conexao__core-emblem { animation: conexao-pulsar 2.6s ease-in-out infinite; }
}

@keyframes conexao-flutuar { from { transform: translate3d(0, -4px, 0); } to { transform: translate3d(0, 5px, 0); } }
@keyframes conexao-surgir {
  0% { opacity: 0; transform: translate(-50%, calc(var(--core-y) * -1)) scale(calc(var(--s, 1) * .3)); }
  100% { opacity: 1; transform: translate(-50%, calc(var(--core-y) * -1)) scale(var(--s, 1)); }
}
@keyframes conexao-onda { 0% { opacity: .9; transform: scale(1); } 100% { opacity: 0; transform: scale(4.2); } }
@keyframes conexao-pulsar {
  0%, 100% { box-shadow: 0 0 0 8px rgba(230, 11, 79, .08), 0 0 50px rgba(230, 11, 79, .45); }
  50% { box-shadow: 0 0 0 14px rgba(230, 11, 79, .05), 0 0 70px rgba(255, 26, 94, .7); }
}
@keyframes conexao-fluxo { from { stroke-dashoffset: 608; } to { stroke-dashoffset: 0; } }

/* Celular e tablet em pé: composição própria (2 colunas + núcleo abaixo) */
@media (max-width: 760px), (max-width: 1100px) and (orientation: portrait) {
  .conexao__intro { max-width: 22rem; }
  .conexao__title, .conexao__punch { font-size: clamp(23px, 6.4vw, 30px); }
  .conexao__final { font-size: clamp(19px, 5.2vw, 24px); max-width: 22ch; }
  .conexao__board-wrap { margin: 10px 0; }
  .conexao__outro { gap: 10px; }
  .is-animated .conexao__stage { padding-top: calc(var(--header-h) + 8px); padding-bottom: 16px; }

  .conexao__board { aspect-ratio: 340 / 460; max-width: 360px; }
  .is-animated .conexao__board { max-width: none; }
  .conexao__lines--desktop { display: none; }
  .conexao__lines--mobile { display: block; }
  .conexao__joints { display: none; }
  .conexao__chip, .conexao__core { left: calc(var(--mx) * 100% / 340); top: calc(var(--my) * 100% / 460); }
  .conexao__chip { width: 150px; }
  .conexao__chip-inner { height: 44px; padding: 0 12px; gap: 7px; font-size: 10.5px; letter-spacing: .1em; }
  .conexao__chip-inner svg { width: 15px; height: 15px; }
  .conexao__core { --core-y: 40px; gap: 8px; }
  .conexao__core-label { font-size: 10px; }
}
