/* REVIRES: herói do Início (InicioB, InicioMobileB, HeroMontagemB + HeroFotosB).
   O mapa da rede é um SVG escrito no HTML; o CSS anima, o js/hero.js só troca a foto, pausa e reage ao ecrã.
   Sem JS ou com movimento reduzido: a rede aparece completa e estática, com a primeira foto.
   Estados (classes postas pelo JS):
     html.js              há JS: a montagem pode correr
     html.rv-hero-seen    já se montou nesta sessão: aparece logo completa (sessionStorage)
     .rv-hero.is-ready    a montagem acabou: começam os pulsos e a rotação das fotos
     .rv-hero.is-paused   o visitante carregou em Pausar
     .rv-hero.is-idle     o herói saiu do ecrã ou a aba está escondida (pausa automática)
   No Astro: HeroRede.astro, com este CSS e o <script> de hero.js. */

.rv-hero__inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 40px;
  align-items: center;
  padding-block: 72px 88px;
}

.rv-hero__text { display: flex; flex-direction: column; gap: 20px; }
.rv-hero__text h1 {
  font-size: clamp(2.5rem, 1.6rem + 2.8vw, 4rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
  max-width: 11em;
}
.rv-hero__lead { font-size: var(--text-body); color: var(--color-text-secondary); max-width: 26em; }
.rv-hero__actions { display: flex; flex-wrap: wrap; gap: 20px; align-items: center; margin-top: var(--space-1); }

/* ---------- palco: grafo + cartão + Pausar ---------- */

.rv-hero__stage { position: relative; aspect-ratio: 560 / 460; min-width: 0; }
.rv-hero__graph { position: absolute; inset: 0; }
.rv-hero__svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }

.rv-hero__polo { fill: var(--color-linen); }
.rv-hero__river { fill: none; stroke: var(--color-khaki-300); stroke-width: 1.5; stroke-dasharray: 1 5; stroke-linecap: round; }
.rv-hero__links { fill: none; }
.rv-hero__links--hub { stroke: var(--color-khaki); stroke-width: 1.5; }
.rv-hero__links--mesh { stroke: var(--color-khaki-300); stroke-width: 1; }
.rv-hero__links--far { stroke: var(--color-khaki); stroke-width: 1; stroke-dasharray: 2 5; stroke-linecap: round; }
.rv-hero__pulses { fill: none; stroke: var(--color-khaki-dark); stroke-width: 3; stroke-linecap: round; display: none; }
.rv-hero__pulses path { stroke-dasharray: 4 100; stroke-dashoffset: 60; }
.rv-hero__node { fill: var(--color-khaki); stroke: var(--color-white); stroke-width: 3; }
.rv-hero__node--strong { fill: var(--color-graphite); }
.rv-hero__ping { fill: none; stroke: var(--color-graphite); stroke-width: 1; opacity: 0; }

/* Reitoria: círculo com o logótipo */
.rv-hero__hub {
  position: absolute;
  left: 58.9%;
  top: 65.2%;
  translate: -50% -50%;
  width: 96px;
  height: 96px;
  border-radius: var(--radius-pill);
  background: var(--color-white);
  border: 1.5px solid var(--color-khaki);
  box-shadow: 0 0 0 8px var(--color-white), 0 12px 32px rgba(31, 30, 26, .10);
  display: flex;
  align-items: center;
  justify-content: center;
}
.rv-hero__hub img { width: 58px; height: auto; }

/* Textos sobre o grafo (posições em % da caixa 560 × 460) */
.rv-hero__unit,
.rv-hero__polo-name,
.rv-hero__river-name,
.rv-hero__hub-name {
  position: absolute;
  translate: -50% -50%;
  white-space: nowrap;
  line-height: 1.2;
}
.rv-hero__unit { font-size: 0.75rem; font-weight: var(--weight-bold); letter-spacing: 0.03em; color: var(--color-text-secondary); }
.rv-hero__polo-name { font-size: 0.6875rem; font-weight: var(--weight-black); letter-spacing: 0.14em; text-transform: uppercase; color: var(--color-khaki-dark); }
.rv-hero__river-name { font-size: 0.6875rem; font-style: italic; color: var(--color-khaki-dark); }
.rv-hero__hub-name { font-size: 0.75rem; font-weight: var(--weight-black); letter-spacing: 0.03em; color: var(--color-graphite); }

/* Foto rotativa: anel no nó, linha até à foto e chip de legenda no canto inferior esquerdo */
.rv-hero__photo { position: absolute; inset: 0; pointer-events: none; opacity: 0; }
.rv-hero__photo.is-active { opacity: 1; }
.rv-hero__photo line { stroke: var(--color-khaki); stroke-width: 1; }
.rv-hero__photo circle { fill: none; stroke: var(--color-khaki); stroke-width: 1.5; }
.rv-hero__figure {
  position: absolute;
  width: var(--size, 88px);
  height: var(--size, 88px);
  translate: -50% -50%;
}
.rv-hero__figure img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius-pill);
  border: 4px solid var(--color-white);
  box-shadow: 0 10px 28px rgba(31, 30, 26, .16);
}
.rv-hero__caption {
  position: absolute;
  left: 0;
  bottom: 0;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 36px;
  padding: 0 14px 0 6px;
  border-radius: var(--radius-pill);
  background: var(--color-graphite);
  color: var(--color-white);
  font-size: 0.75rem;
  font-weight: var(--weight-bold);
  white-space: nowrap;
}
.rv-hero__caption img { width: 26px; height: 26px; border-radius: var(--radius-pill); object-fit: cover; }

/* Cartão "A seguir na rede" (canto superior esquerdo) */
.rv-hero__next {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  gap: var(--space-3);
  align-items: center;
  padding: 10px var(--space-4) 10px 10px;
  border-radius: var(--radius-box);
  background: var(--color-white);
  border: var(--border);
  box-shadow: 0 8px 24px rgba(31, 30, 26, .08);
  color: var(--color-text);
  text-decoration: none;
  max-width: 50%;
}
.rv-hero__next:hover { color: var(--color-text); }
.rv-hero__next-date {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-control);
  background: var(--color-graphite);
  color: var(--color-white);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.rv-hero__next-date b { font-size: 1rem; }
.rv-hero__next-date span { font-size: 0.625rem; font-weight: var(--weight-bold); text-transform: uppercase; color: var(--color-khaki-400); }
.rv-hero__next-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.rv-hero__next-label { font-size: 0.6875rem; font-weight: var(--weight-bold); letter-spacing: 0.08em; text-transform: uppercase; color: var(--color-khaki-dark); }
.rv-hero__next-title { font-size: var(--text-small); font-weight: var(--weight-bold); line-height: 1.3; }

/* Pausar / Retomar (só aparece quando há movimento automático) */
.rv-hero__pause {
  position: absolute;
  right: 0;
  bottom: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--tap-min);
  padding: 0 14px;
  border-radius: var(--radius-pill);
  border: var(--border);
  background: var(--color-white);
  font-size: 0.75rem;
  font-weight: var(--weight-bold);
  color: var(--color-text-secondary);
}
.rv-hero__pause[hidden] { display: none; }
.rv-hero__pause:hover { background: var(--color-linen); color: var(--color-graphite); }
.rv-hero__pause svg { fill: currentColor; }
.rv-hero__play-icon { display: none; }
.rv-hero.is-paused .rv-hero__pause-icon { display: none; }
.rv-hero.is-paused .rv-hero__play-icon { display: block; }

/* Lista por polo: alternativa ao mapa. Acima de 720 px fica só para leitores de ecrã */
.rv-hero__legend {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.rv-hero__legend li {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: var(--space-3);
  padding-block: var(--space-3);
  border-top: var(--border);
  font-size: var(--text-small);
  line-height: 1.5;
}
.rv-hero__legend-polo { font-size: 0.75rem; font-weight: var(--weight-black); letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--color-khaki-dark); }

/* ---------- ≤ 960 px: texto em cima, mapa em baixo ---------- */
@media (max-width: 960px) {
  .rv-hero__inner { grid-template-columns: minmax(0, 1fr); padding-block: var(--space-8) var(--space-8); }
  .rv-hero__stage { width: 100%; max-width: 620px; justify-self: center; margin-top: var(--space-4); }
}

/* ---------- ≤ 720 px: só a montagem, sem siglas, fotos, cartão nem Pausar; aparece a lista por polo ---------- */
@media (max-width: 720px) {
  .rv-hero__inner { gap: var(--space-5); padding-block: var(--space-6) var(--space-7); }
  .rv-hero__text { gap: var(--space-4); }
  .rv-hero__lead { font-size: 1.0625rem; }
  .rv-hero__actions .rv-btn--primary { width: 100%; }
  .rv-hero__secondary { display: none; }
  .rv-hero__labels,
  .rv-hero__photo,
  .rv-hero__next,
  .rv-hero__pause,
  .rv-hero__pulses,
  .rv-hero__ping { display: none !important; }
  .rv-hero__stage { margin-top: 0; }
  .rv-hero__polo-name { font-size: 0.625rem; }
  .rv-hero__polo-prefix { display: none; }
  .rv-hero__hub { width: 64px; height: 64px; box-shadow: 0 0 0 5px var(--color-white); }
  .rv-hero__hub img { width: 40px; }
  .rv-hero__legend {
    position: static !important;
    width: auto; height: auto;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
  }
}

/* ---------- movimento: só sem preferência por movimento reduzido ---------- */
@media (prefers-reduced-motion: no-preference) {
  /* Montagem, uma vez por sessão: polos, rio, ligações, nós em cascata, siglas (≈ 3 s) */
  html.js:not(.rv-hero-seen) .rv-hero__polo,
  html.js:not(.rv-hero-seen) .rv-hero__node,
  html.js:not(.rv-hero-seen) .rv-hero__hub {
    transform-box: fill-box;
    transform-origin: center;
    animation: rv-hero-pop 700ms var(--ease-out) var(--d, 0s) both;
  }
  html.js:not(.rv-hero-seen) .rv-hero__polo { animation-name: rv-hero-blob; animation-duration: 900ms; }
  html.js:not(.rv-hero-seen) .rv-hero__links--hub path,
  html.js:not(.rv-hero-seen) .rv-hero__links--mesh path {
    stroke-dasharray: 100;
    animation: rv-hero-draw 600ms var(--ease-out) var(--d, 0s) both;
  }
  html.js:not(.rv-hero-seen) .rv-hero__river,
  html.js:not(.rv-hero-seen) .rv-hero__links--far path,
  html.js:not(.rv-hero-seen) .rv-hero__unit,
  html.js:not(.rv-hero-seen) .rv-hero__polo-name,
  html.js:not(.rv-hero-seen) .rv-hero__river-name,
  html.js:not(.rv-hero-seen) .rv-hero__hub-name {
    animation: rv-hero-fade 700ms var(--ease-out) var(--d, 0s) both;
  }
  html.js:not(.rv-hero-seen) .rv-hero__next { animation: rv-hero-rise 700ms var(--ease-out) 2.5s both; }
  html.js:not(.rv-hero-seen) .rv-hero__hub { animation-name: rv-hero-pop-hub; }

  /* Depois da montagem: pulsos nas ligações e anéis nos nós maiores */
  .rv-hero.is-ready .rv-hero__pulses { display: inline; animation: rv-hero-fade 700ms var(--ease-out) both; }
  .rv-hero.is-ready .rv-hero__pulses path { animation: rv-hero-travel 5s linear var(--pd, 0s) infinite; }
  .rv-hero.is-ready .rv-hero__ping {
    transform-box: fill-box;
    transform-origin: center;
    animation: rv-hero-ping 3.2s ease-out var(--pd, 0s) infinite;
  }

  /* Fotos: entram e saem em 400 ms e flutuam devagar */
  .rv-hero__photo { transition: opacity var(--dur-slow) var(--ease-out); }
  .rv-hero__photo .rv-hero__figure { transition: transform var(--dur-slow) var(--ease-out); transform: scale(.9); }
  .rv-hero__photo.is-active .rv-hero__figure { transform: none; }
  .rv-hero.is-ready .rv-hero__figure img { animation: rv-hero-float 6s ease-in-out infinite; }
  html.js .rv-hero:not(.is-ready) .rv-hero__photo { opacity: 0; }

  /* Pausar (e pausa automática fora do ecrã): tudo o que se repete para no sítio */
  .rv-hero.is-paused *,
  .rv-hero.is-idle * { animation-play-state: paused !important; }

  @keyframes rv-hero-pop { 0% { transform: scale(0); opacity: 0; } 60% { transform: scale(1.25); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
  @keyframes rv-hero-pop-hub { 0% { scale: 0; opacity: 0; } 60% { scale: 1.1; opacity: 1; } 100% { scale: 1; opacity: 1; } }
  @keyframes rv-hero-blob { 0% { transform: scale(.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
  @keyframes rv-hero-fade { 0% { opacity: 0; } 100% { opacity: 1; } }
  @keyframes rv-hero-rise { 0% { opacity: 0; transform: translateY(12px); } 100% { opacity: 1; transform: none; } }
  @keyframes rv-hero-draw { 0% { stroke-dashoffset: 100; } 100% { stroke-dashoffset: 0; } }
  @keyframes rv-hero-travel { from { stroke-dashoffset: 104; } to { stroke-dashoffset: 0; } }
  @keyframes rv-hero-ping { 0% { transform: scale(1); opacity: .6; } 100% { transform: scale(3.2); opacity: 0; } }
  @keyframes rv-hero-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
}

/* Movimento reduzido: rede completa, sem pulsos, uma foto fixa, sem Pausar */
@media (prefers-reduced-motion: reduce) {
  .rv-hero__pause { display: none !important; }
  .rv-hero__pulses, .rv-hero__ping { display: none !important; }
}
