/* =============================================================================
 * fundamento.css — seção "Constelação dos princípios"
 *
 * Aparece entre #material-demo e #cadastro. Apresenta os 16 princípios da
 * ciência da aprendizagem que fundamentam o material gerado, em 3 camadas
 * narrativas:
 *   1) Header dramático (eyebrow + título Cormorant + lead)
 *   2) Constelação SVG interativa (16 nós + linhas de cluster)
 *   3) Grid 4×4 de cards detalhados com contador animado
 *   4) Footer com nota de fundamento total
 *
 * Estética alinhada ao site: dark + dourado (#d4a857) + Cormorant Garamond
 * para títulos, Inter para corpo, glass panels com backdrop-filter.
 *
 * Animações principais:
 *   - .reveal já existente (alien.js#setupReveal) controla fade da seção
 *   - Estrelas da constelação acendem em sequência via .is-lit (stagger)
 *   - Linhas se desenham via stroke-dashoffset → 0
 *   - Contador dos números (data-target) controlado por fundamento.js
 *
 * Acessibilidade: prefers-reduced-motion zera todas as animações; constelação
 * fica visível instantaneamente; números aparecem prontos.
 * ============================================================================= */

.fundamento-section {
  position: relative;
  /* Altura fixa 100dvh pra alinhar com o scroll-snap manual (1 rolada = 1 tela).
     Padding mínimo: só pra não colar nas bordas. Topbar sticky tampa os
     primeiros ~112px, então padding-top precisa só compensar isso + respiro. */
  min-height: 100dvh;
  max-height: 100dvh;
  padding: clamp(40px, 5vh, 70px) 0 clamp(24px, 3vh, 40px);
  display: flex;
  align-items: center;
  overflow: hidden;
}
.fundamento-section .wrap {
  width: 100%;
}

.fundamento-section .wrap {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 clamp(20px, 4vw, 40px);
}

/* ---------- Header ---------- */

.fundamento-header {
  text-align: center;
  max-width: 780px;
  margin: 0 auto clamp(24px, 3.5vh, 44px);
}

/* Glass panel espelhando o card do hero "O destino da educação" (vidro mais
   transparente, blur leve). Override do .panel global pra ficar mais
   discreto sobre a pintura. */
.fundamento-header.panel {
  background: rgba(14, 10, 6, .36);
  border: 1px solid rgba(212, 168, 87, .18);
  box-shadow: 0 14px 40px rgba(0, 0, 0, .28);
  -webkit-backdrop-filter: blur(14px) saturate(1.18);
  backdrop-filter: blur(14px) saturate(1.18);
  border-radius: 14px;
  padding: clamp(28px, 3.6vmin, 44px) clamp(24px, 3.5vmin, 40px);
}
.fundamento-header.panel .fundamento-title {
  margin-bottom: 0;
}

.fundamento-eyebrow {
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: clamp(11px, 1.4vmin, 13px);
  letter-spacing: .28em;
  text-transform: uppercase;
  color: rgba(212, 168, 87, .82);
  margin-bottom: 18px;
  display: inline-block;
}

.fundamento-title {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-weight: 600;
  font-size: clamp(34px, 5.4vmin, 64px);
  line-height: 1.06;
  letter-spacing: -.012em;
  color: #f7eccd;
  margin: 0 0 18px;
  text-wrap: balance;
  text-shadow: 0 2px 14px rgba(0, 0, 0, .42);
}

.fundamento-title em {
  font-style: italic;
  font-weight: 600;
  background: linear-gradient(120deg, #fbe8b4 0%, #e8c477 60%, #d4a857 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.fundamento-lead {
  font-family: Inter, system-ui, sans-serif;
  font-size: clamp(15px, 1.9vmin, 18px);
  font-weight: 400;
  line-height: 1.55;
  color: rgba(247, 236, 205, .76);
  max-width: 560px;
  margin: 0 auto;
  text-wrap: balance;
}

/* ---------- Constelação SVG ---------- */

.fundamento-constellation {
  position: relative;
  width: 100%;
  max-width: 1100px;
  /* Sem margin-bottom: agora a constelação é o ÚNICO elemento principal da
     section, junto com o header. O flex-center vertical do .fundamento-section
     centraliza tudo no viewport. */
  margin: 0 auto;
  aspect-ratio: 16 / 9;
  /* Limita altura pra que header + constelação caibam em 100dvh (1080px típico
     de desktop tem 619px disponíveis pra constelação após topbar + header). */
  max-height: calc(100dvh - 320px);
  /* Camada de contraste robusta: a constelação precisa funcionar em QUALQUER
     pintura de fundo (céus claros, escuros, abstratos). Em vez de glass leve,
     usamos um veil mais opaco no centro com falloff suave nas bordas — assim
     mantemos a "moldura" se integrando à pintura mas garante contraste no
     interior pra estrelas e linhas serem legíveis. */
  background:
    radial-gradient(ellipse at 50% 50%, rgba(5, 9, 18, .82) 0%, rgba(5, 9, 18, .68) 55%, rgba(5, 9, 18, .42) 85%, rgba(5, 9, 18, .18) 100%);
  border: 1px solid rgba(212, 168, 87, .22);
  border-radius: 22px;
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
  backdrop-filter: blur(14px) saturate(1.15);
  overflow: hidden;
  box-shadow:
    0 24px 60px rgba(0, 0, 0, .45),
    inset 0 1px 0 rgba(255, 237, 180, .08),
    inset 0 0 80px rgba(0, 0, 0, .35);
}

.fundamento-constellation__svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Linhas conectivas entre nós do mesmo cluster temático.
   Estratégia dupla pra garantir visibilidade em qualquer pintura: usamos
   duas linhas sobrepostas — uma "shadow" escura larga atrás e a linha
   dourada brilhante por cima. Aqui setamos a linha principal; a sombra é
   adicionada por JS com a mesma geometria (classe .fundamento-line__shadow).
   Stroke-dasharray + stroke-dashoffset animado pra "desenhar" ao entrar. */
.fundamento-line {
  fill: none;
  stroke: rgba(251, 232, 180, .62);
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-dasharray: var(--len, 1000);
  stroke-dashoffset: var(--len, 1000);
  filter: drop-shadow(0 0 4px rgba(251, 232, 180, .55));
  transition: stroke-dashoffset 1.4s cubic-bezier(.22, .61, .36, 1),
              stroke 0.3s ease,
              stroke-width 0.3s ease,
              filter 0.3s ease;
}

.fundamento-line__shadow {
  fill: none;
  stroke: rgba(0, 0, 0, .68);
  stroke-width: 3.4;
  stroke-linecap: round;
  stroke-dasharray: var(--len, 1000);
  stroke-dashoffset: var(--len, 1000);
  transition: stroke-dashoffset 1.4s cubic-bezier(.22, .61, .36, 1);
}

.fundamento-constellation.is-drawn .fundamento-line,
.fundamento-constellation.is-drawn .fundamento-line__shadow {
  stroke-dashoffset: 0;
}

.fundamento-line.is-active {
  stroke: #fff5d6;
  stroke-width: 2;
  filter: drop-shadow(0 0 8px rgba(255, 245, 214, .9));
}

/* Cada nó: <g> com círculo + halo + label. Posicionado via transform via JS
   (cx/cy do círculo + transform do <g>). Estado inicial: invisível e pequeno. */
.fundamento-node {
  cursor: pointer;
  opacity: 0;
  transform: scale(.6);
  transform-origin: center center;
  transform-box: fill-box;
  transition: opacity .8s cubic-bezier(.22, .61, .36, 1),
              transform .8s cubic-bezier(.34, 1.56, .64, 1);
  transition-delay: var(--delay, 0s);
}

.fundamento-constellation.is-drawn .fundamento-node {
  opacity: 1;
  transform: scale(1);
}

/* "Scrim" escuro grande atrás de cada nó — garante contraste em pinturas
   claras (ex: Monet, Vermeer luminoso) sem prejudicar fundos escuros. */
.fundamento-node__scrim {
  fill: rgba(0, 0, 0, .55);
  filter: blur(.8px);
  transition: opacity .25s ease;
}

.fundamento-node__halo {
  fill: rgba(251, 232, 180, .35);
  transition: fill .25s ease, r .25s ease;
}

.fundamento-node__core {
  fill: #ffffff;
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, .95))
          drop-shadow(0 0 14px rgba(251, 232, 180, .9))
          drop-shadow(0 0 26px rgba(212, 168, 87, .75));
  transition: r .25s ease, filter .25s ease;
}

/* Pulse contínuo discreto no halo — anima escala, não tira do fluxo. */
@keyframes fundamentoNodePulse {
  0%, 100% { opacity: .35; transform: scale(1); }
  50%      { opacity: .7;  transform: scale(1.15); }
}

.fundamento-constellation.is-drawn .fundamento-node__halo {
  animation: fundamentoNodePulse 3.6s ease-in-out infinite;
  animation-delay: var(--delay, 0s);
  transform-origin: center;
  transform-box: fill-box;
}

.fundamento-node__label {
  font-family: Inter, system-ui, sans-serif;
  /* Unidades do viewBox (100×56.25). 1.7 ≈ 18px na tela em viewBox 1063×598. */
  font-size: 1.7px;
  font-weight: 600;
  letter-spacing: .03em;
  fill: #f7eccd;
  text-anchor: middle;
  pointer-events: none;
  /* paint-order + stroke = "outline" escuro pra labels serem legíveis em
     qualquer pintura (claras ou escuras). Stroke fica por baixo da fill,
     funciona como halo de leitura. */
  paint-order: stroke fill;
  stroke: rgba(0, 0, 0, .85);
  stroke-width: 0.32px;
  stroke-linejoin: round;
  transition: fill .25s ease, font-weight .25s ease;
}

/* Estados de hover/active na constelação */
.fundamento-node:hover .fundamento-node__halo,
.fundamento-node.is-hover .fundamento-node__halo {
  fill: rgba(255, 245, 214, .7);
  animation: none;
  transform: scale(1.5);
}

.fundamento-node:hover .fundamento-node__core,
.fundamento-node.is-hover .fundamento-node__core {
  filter: drop-shadow(0 0 10px rgba(255, 255, 255, 1))
          drop-shadow(0 0 22px rgba(251, 232, 180, 1))
          drop-shadow(0 0 40px rgba(212, 168, 87, 1));
}

/* Labels respondem ao hover via classe is-hover-label aplicada por JS quando
   o nó correspondente fica em hover (já que label fica fora do <g> do nó). */
.fundamento-node__label.is-hover-label {
  fill: #fbe8b4;
  font-weight: 700;
}

/* Tooltip dourado que segue o cursor / fixa no nó hover */
.fundamento-tooltip {
  position: absolute;
  pointer-events: none;
  background: linear-gradient(160deg,
    rgba(28, 18, 8, .96) 0%,
    rgba(14, 10, 6, .96) 100%);
  border: 1px solid rgba(212, 168, 87, .42);
  border-radius: 12px;
  padding: 14px 18px;
  max-width: 280px;
  color: #f7eccd;
  font-family: Inter, system-ui, sans-serif;
  box-shadow:
    0 16px 40px rgba(0, 0, 0, .55),
    0 0 0 1px rgba(255, 237, 180, .08) inset;
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  backdrop-filter: blur(12px) saturate(1.2);
  opacity: 0;
  transform: translateY(8px) scale(.96);
  transition: opacity .22s ease, transform .22s ease;
  z-index: 5;
}

.fundamento-tooltip.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.fundamento-tooltip__name {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-weight: 700;
  font-size: 18px;
  line-height: 1.15;
  margin-bottom: 6px;
  background: linear-gradient(120deg, #fbe8b4 0%, #e8c477 60%, #d4a857 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.fundamento-tooltip__base {
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: rgba(212, 168, 87, .82);
  margin-bottom: 8px;
}

.fundamento-tooltip__desc {
  font-size: 13px;
  line-height: 1.5;
  color: rgba(247, 236, 205, .82);
}

/* Legenda dos clusters embaixo da constelação */
.fundamento-legend {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px 22px;
  padding: 0 16px;
  font-family: Inter, system-ui, sans-serif;
  font-size: 10.5px;
  letter-spacing: .03em;
  color: rgba(247, 236, 205, .58);
  pointer-events: none;
}

.fundamento-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.fundamento-legend__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(212, 168, 87, .85);
  box-shadow: 0 0 6px rgba(212, 168, 87, .5);
}

/* ---------- Grid 4×4 de cards detalhados ----------
   Compactado pra caber em 100dvh (16 cards em 4 colunas × 4 linhas + footer
   na mesma section #principios). Cards menores que a versão original. */

.fundamento-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: stretch;
  gap: clamp(10px, 1.2vw, 16px);
  margin: 0 auto;
  grid-auto-rows: 1fr;
}

.fundamento-card {
  position: relative;
  background: rgba(14, 10, 6, .58);
  border: 1px solid rgba(212, 168, 87, .18);
  border-radius: 12px;
  padding: clamp(12px, 1.4vw, 18px) clamp(12px, 1.4vw, 18px) clamp(14px, 1.6vw, 20px);
  /* Blur reduzido de 14px pra 6px — em 16 cards o custo era altíssimo.
     Como o fundo já é bem opaco (.58), o blur só aparece nas bordas, e
     6px é praticamente indistinguível de 14px visualmente nessa proporção. */
  -webkit-backdrop-filter: blur(6px) saturate(1.15);
  backdrop-filter: blur(6px) saturate(1.15);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: background .25s ease,
              border-color .25s ease,
              transform .25s cubic-bezier(.22, .61, .36, 1),
              box-shadow .25s ease;
  overflow: hidden;
}

.fundamento-card:hover {
  background: rgba(28, 18, 8, .72);
  border-color: rgba(212, 168, 87, .55);
  transform: translateY(-3px);
  box-shadow:
    0 18px 40px rgba(0, 0, 0, .42),
    0 0 0 1px rgba(212, 168, 87, .25) inset;
}

/* Pequena luz dourada no canto superior esquerdo, espelha o nó da constelação */
.fundamento-card::before {
  content: "";
  position: absolute;
  top: 14px;
  left: 14px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fbe8b4;
  box-shadow: 0 0 8px rgba(251, 232, 180, .85),
              0 0 18px rgba(212, 168, 87, .55);
  opacity: .85;
}

.fundamento-card__base {
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 12.5px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: rgba(212, 168, 87, .72);
  margin-left: 18px;
}

.fundamento-card__name {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-weight: 600;
  /* Cards "curtos" (≤18 chars) — maioria. Cabem com folga até em fonte maior. */
  font-size: clamp(21px, 2.75vmin, 30px);
  line-height: 1.15;
  color: #f7eccd;
  letter-spacing: -.005em;
  margin: 4px 0 10px;
  white-space: nowrap;
  min-width: 0;
}
/* Cards "longos" (>18 chars: "Adaptação inteligente", "Visualização imersiva",
   "Narração multimodal", "Aprendizagem social") — fonte ligeiramente menor pra
   caber numa linha só sem estourar o card. Detectado por length em fundamento.js. */
.fundamento-card__name--long {
  font-size: clamp(18px, 2.35vmin, 25px);
}

/* Grid de 2 linhas:
     linha 1 — "até" (span em todas as colunas)
     linha 2 — num · % · + · kind (4 colunas, kind ocupa o restante)
   Grid trava a estrutura: kind NUNCA quebra pra uma terceira linha, mesmo
   com palavras longas tipo "aprendizagem" ou "produtividade". Tamanhos de
   fonte calibrados pra que o mais longo (13 chars Cormorant italic) caiba
   ao lado de "150%+" no card mais estreito do grid 4-col. */
.fundamento-card__metric {
  display: grid;
  grid-template-columns: auto auto auto minmax(0, 1fr);
  align-items: baseline;
  column-gap: 4px;
  row-gap: 0;
  margin: 8px 0 2px;
}

.fundamento-card__metric-prefix {
  grid-column: 1 / -1;
  font-family: Inter, system-ui, sans-serif;
  font-size: clamp(13px, 1.6vmin, 17px);
  font-weight: 500;
  color: rgba(247, 236, 205, .72);
  letter-spacing: .005em;
  margin-bottom: -4px;
}

/* Número, "%" e "+" compartilham o MESMO tamanho e a mesma "fonte bonita"
   (Inter 800 com gradient dourado). O "+" vem DEPOIS do "%". */
.fundamento-card__metric-num,
.fundamento-card__metric-pct,
.fundamento-card__metric-plus {
  font-family: Inter, system-ui, sans-serif;
  font-size: clamp(28px, 3.4vmin, 40px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.03em;
  background: linear-gradient(120deg, #fbe8b4 0%, #e8c477 55%, #d4a857 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.fundamento-card__metric-num {
  font-variant-numeric: tabular-nums;
}
.fundamento-card__metric-pct {
  margin-left: -3px;
}
.fundamento-card__metric-plus {
  margin-left: -3px;
}

/* "retenção" / "aprendizagem" / "produtividade" — Cormorant italic, médio
   pra puxar o olho sem competir com o número. Tamanho reduzido pra caber
   ao lado do "X%+" mesmo quando a palavra tem 13 chars. */
.fundamento-card__metric-kind {
  font-family: "Cormorant Garamond", Georgia, serif;
  font-style: italic;
  font-weight: 600;
  font-size: clamp(14px, 1.6vmin, 18px);
  line-height: 1.1;
  color: rgba(247, 236, 205, .92);
  letter-spacing: -.01em;
  margin-left: 5px;
  white-space: nowrap;
  min-width: 0;
}

.fundamento-card__desc {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  padding: clamp(14px, 1.6vw, 20px) clamp(14px, 1.6vw, 20px);
  margin: 0;
  font-family: Inter, system-ui, sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
  color: rgba(247, 236, 205, .92);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
}

.fundamento-card__base,
.fundamento-card__name,
.fundamento-card__metric {
  transition: opacity .22s ease;
}

.fundamento-card:hover .fundamento-card__desc,
.fundamento-card:focus-within .fundamento-card__desc,
.fundamento-card.is-spotlight .fundamento-card__desc {
  opacity: 1;
}

.fundamento-card:hover .fundamento-card__base,
.fundamento-card:hover .fundamento-card__name,
.fundamento-card:hover .fundamento-card__metric,
.fundamento-card:focus-within .fundamento-card__base,
.fundamento-card:focus-within .fundamento-card__name,
.fundamento-card:focus-within .fundamento-card__metric,
.fundamento-card.is-spotlight .fundamento-card__base,
.fundamento-card.is-spotlight .fundamento-card__name,
.fundamento-card.is-spotlight .fundamento-card__metric {
  opacity: 0;
}

/* Card destacado quando o usuário hover no nó da constelação correspondente. */
.fundamento-card.is-spotlight {
  background: rgba(28, 18, 8, .82);
  border-color: rgba(251, 232, 180, .68);
  box-shadow:
    0 22px 50px rgba(0, 0, 0, .5),
    0 0 0 1px rgba(251, 232, 180, .35) inset,
    0 0 32px rgba(212, 168, 87, .25);
  transform: translateY(-3px) scale(1.012);
}

/* ---------- Footer da seção ---------- */

.fundamento-footer {
  margin-top: clamp(16px, 2.2vh, 26px);
  text-align: center;
  font-family: Inter, system-ui, sans-serif;
  font-size: clamp(12px, 1.4vmin, 14px);
  color: rgba(247, 236, 205, .56);
  letter-spacing: .005em;
  line-height: 1.6;
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
}

.fundamento-footer strong {
  font-weight: 700;
  color: rgba(247, 236, 205, .78);
}

.fundamento-footer__sep {
  display: inline-block;
  margin: 0 10px;
  color: rgba(212, 168, 87, .42);
}

/* ---------- Responsivo ---------- */

@media (max-width: 1100px) {
  .fundamento-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .fundamento-constellation {
    aspect-ratio: 4 / 3;
  }
  .fundamento-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .fundamento-node__label {
    font-size: 9px;
  }
  .fundamento-legend {
    font-size: 9.5px;
    gap: 10px 16px;
  }
}

@media (max-width: 540px) {
  .fundamento-section {
    padding: clamp(60px, 9vh, 100px) 0 clamp(50px, 7vh, 80px);
  }
  .fundamento-constellation {
    aspect-ratio: 1 / 1;
    border-radius: 16px;
  }
  .fundamento-grid {
    grid-template-columns: 1fr;
  }
  .fundamento-node__label {
    /* labels em mobile pequenos atrapalham — escondidos, tooltip se ativa por tap */
    display: none;
  }
  .fundamento-legend {
    position: static;
    transform: none;
    margin: 14px auto 0;
  }
}

/* ---------- Reduced motion: zera tudo que pulsa/anima ---------- */

@media (prefers-reduced-motion: reduce) {
  .fundamento-line,
  .fundamento-node,
  .fundamento-card,
  .fundamento-card__desc {
    transition: none !important;
  }
  .fundamento-line {
    stroke-dashoffset: 0 !important;
  }
  .fundamento-node {
    opacity: 1 !important;
    transform: none !important;
  }
  .fundamento-node__halo {
    animation: none !important;
  }
}

/* ---------- data-perf=low: corta animação custosa ---------- */

[data-perf="low"] .fundamento-node__halo {
  animation: none !important;
}

[data-perf="low"] .fundamento-card {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  background: rgba(14, 10, 6, .82);
}

[data-perf="low"] .fundamento-constellation {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
