/* ═══════════════════════════════════════════════════════════════
   MOTION — tokens e transições compartilhadas (home, hub, cases)
   Carrega por último. Regras:
   · entrada = ease-out forte; saída = ease-in curto (≈ 60% da entrada)
   · hover/press 120–200ms; estado 220–360ms; revelação 700–1000ms
   · só transform / opacity / clip-path / filter leve no que se move
   · tudo desliga em prefers-reduced-motion
   ═══════════════════════════════════════════════════════════════ */

:root {
  --ease-out:      cubic-bezier(0.23, 1, 0.32, 1);    /* UI: começo rápido, pouso suave */
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);     /* revelações, cenas */
  --ease-in:       cubic-bezier(0.55, 0, 0.85, 0.35); /* saídas */
  --ease-in-out:   cubic-bezier(0.65, 0, 0.35, 1);    /* mudança de estado */
  /* mola amortecida (k 170 / c 21): ~1.4% de overshoot, assenta em 700ms */
  --ease-spring: linear(0, 0.045, 0.149, 0.281, 0.418, 0.546, 0.659, 0.754, 0.831, 0.89, 0.934, 0.965, 0.986, 1, 1.008, 1.013, 1.014, 1.014, 1.012, 1.011, 1.009, 1.007, 1.005, 1.004, 1.003, 1.002, 1.001, 1.001, 1);
  --ease: var(--ease-out);

  --dur-press: 120ms;
  --dur-hover: 180ms;
  --dur-state: 280ms;
  --dur-panel: 420ms;
  --dur-reveal: 900ms;
}

/* ── Revelação no scroll (cascata em lote, via script.js) ── */
.reveal-element:not(.is-visible) {
  opacity: 0;
  transform: translate3d(0, 26px, 0);
}
.reveal-element.is-visible:not(.is-settled) {
  transition:
    opacity 0.7s var(--ease-out) var(--reveal-delay, 0ms),
    transform var(--dur-reveal) var(--ease-out-expo) var(--reveal-delay, 0ms);
}
.project-page--website [data-stagger] > .reveal-element.is-visible:not(.is-settled) {
  --reveal-delay: calc(var(--stagger-i, 0) * 70ms);
}

/* ── Press: escala independente (não briga com o magnético do GSAP) ── */
.btn, .contact__submit, .topbar__cta, .topbar__home, .mobile-menu__cta,
.wh-feature__cta, .dock__item, .lang-switch__btn, .tabs__btn, .topbar__menu,
.lightbox__nav, .lightbox__close, .journey-stat, .course-semester__summary {
  transition-property: transform, scale, translate, background-color, border-color, color, box-shadow, filter, opacity;
  transition-duration: var(--dur-state), var(--dur-press), var(--dur-state), var(--dur-hover), var(--dur-hover), var(--dur-hover), var(--dur-state), var(--dur-hover), var(--dur-hover);
  transition-timing-function: var(--ease-out);
}
.btn:active, .contact__submit:active, .topbar__cta:active, .topbar__home:active,
.mobile-menu__cta:active, .wh-feature__cta:active, .dock__item:active,
.lang-switch__btn:active, .tabs__btn:active, .topbar__menu:active,
.lightbox__nav:active, .lightbox__close:active, .journey-stat:active {
  scale: 0.97;
}

/* hover que "levanta" só em ponteiro fino — evita estado preso no toque */
@media (hover: none) {
  .btn--accent:hover, .btn--primary:hover, .btn--dark:hover,
  .glass-card:hover, .mobile-menu__cta:hover { transform: none; }
}

/* ── Foco: anel que encosta ── */
:focus-visible {
  transition: outline-offset var(--dur-hover) var(--ease-out);
}

/* ── Pílulas e indicadores deslizam com mola ── */
.lang-switch__pill,
.tabs__indicator {
  transition:
    transform 0.7s var(--ease-spring),
    width 0.7s var(--ease-spring);
}

/* ── Topbar: some ao descer, volta ao subir; pílula da nav ── */
.topbar {
  transition:
    translate 0.55s var(--ease-out-expo),
    background-color var(--dur-state) var(--ease-out),
    border-color var(--dur-state) var(--ease-out),
    box-shadow var(--dur-state) var(--ease-out);
}
.topbar.topbar--hidden {
  translate: 0 calc(-100% - 1.5rem);
  transition-duration: 0.38s;
  transition-timing-function: var(--ease-in);
}

.topbar__nav { position: relative; isolation: isolate; }
.topbar__pill,
.topbar__ghost {
  position: absolute;
  top: 50%;
  left: 0;
  z-index: -1;
  height: 2.5rem;
  width: var(--pill-w, 0px);
  border-radius: 999px;
  transform: translate3d(var(--pill-x, 0px), -50%, 0);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 0.6s var(--ease-spring),
    width 0.6s var(--ease-spring),
    opacity var(--dur-state) var(--ease-out);
}
.topbar__pill {
  background: linear-gradient(180deg, rgba(96, 165, 250, 0.22), rgba(37, 99, 235, 0.14));
  box-shadow:
    inset 0 1px 0 rgba(191, 219, 254, 0.2),
    inset 0 0 0 1px rgba(147, 197, 253, 0.16);
}
.topbar__ghost { background: rgba(226, 232, 240, 0.07); }
.topbar__pill.is-on,
.topbar__ghost.is-on { opacity: 1; }
.has-pill .topbar__link,
.has-pill .topbar__link:hover,
.has-pill .topbar__link.is-active { background: transparent; }
.has-pill .topbar__link { transition: color var(--dur-hover) var(--ease-out); }

/* ── Menu mobile: cortina + links em cascata ── */
.mobile-menu {
  clip-path: inset(0 0 100% 0);
  transition:
    clip-path 0.36s var(--ease-in),
    opacity 0.36s var(--ease-in),
    visibility 0s linear 0.36s;
}
.mobile-menu.is-open {
  clip-path: inset(0 0 0 0);
  transition:
    clip-path 0.62s var(--ease-out-expo),
    opacity 0.3s var(--ease-out),
    visibility 0s linear 0s;
}
.mobile-menu li,
.mobile-menu .lang-switch--mobile {
  opacity: 0;
  translate: 0 22px;
  transition: opacity 0.2s var(--ease-in), translate 0.25s var(--ease-in);
}
.mobile-menu.is-open li,
.mobile-menu.is-open .lang-switch--mobile {
  opacity: 1;
  translate: 0 0;
  transition:
    opacity 0.5s var(--ease-out) calc(0.12s + var(--mi, 0) * 45ms),
    translate 0.7s var(--ease-out-expo) calc(0.12s + var(--mi, 0) * 45ms);
}
.mobile-menu li:nth-child(1) { --mi: 0; }
.mobile-menu li:nth-child(2) { --mi: 1; }
.mobile-menu li:nth-child(3) { --mi: 2; }
.mobile-menu li:nth-child(4) { --mi: 3; }
.mobile-menu li:nth-child(5) { --mi: 4; }
.mobile-menu li:nth-child(6) { --mi: 5; }
.mobile-menu li:nth-child(7) { --mi: 6; }
.mobile-menu li:nth-child(8) { --mi: 7; }
.mobile-menu .lang-switch--mobile { --mi: 8; }
.mobile-menu__link {
  display: inline-block;
  transition: color var(--dur-hover) var(--ease-out), translate var(--dur-state) var(--ease-out);
}
.mobile-menu__link:hover { color: #93c5fd; translate: 4px 0; }

.topbar__menu span,
.header__menu span {
  transition: transform 0.42s var(--ease-spring), opacity var(--dur-hover) var(--ease-out);
}

/* ── Lightbox: entrada com escala, saída curta ── */
.lightbox.is-open .lightbox__backdrop { animation: mx-fade-in 0.32s var(--ease-out) both; }
.lightbox__figure { animation: mx-pop-in 0.5s var(--ease-out-expo) both; }
.lightbox.is-closing .lightbox__backdrop { animation: mx-fade-out 0.22s var(--ease-in) both; }
.lightbox.is-closing .lightbox__figure { animation: mx-pop-out 0.22s var(--ease-in) both; }
.lightbox.is-closing .lightbox__close,
.lightbox.is-closing .lightbox__nav { animation: mx-fade-out 0.18s var(--ease-in) both; }
.lightbox__img { transition: opacity 0.22s var(--ease-out), scale 0.45s var(--ease-out-expo); }
.lightbox__img.is-swapping { opacity: 0; scale: 0.985; transition-duration: 0.14s; transition-timing-function: var(--ease-in); }
.lightbox__caption { transition: opacity 0.22s var(--ease-out); }
.lightbox__img.is-swapping + .lightbox__caption { opacity: 0; }

@keyframes mx-fade-in  { from { opacity: 0; } }
@keyframes mx-fade-out { to { opacity: 0; } }
@keyframes mx-pop-in   { from { opacity: 0; transform: translate3d(0, 14px, 0) scale(0.96); } }
@keyframes mx-pop-out  { to { opacity: 0; transform: scale(0.97); } }

/* ── Mídia em cards: zoom lento e consistente ── */
.cs-card__media img, .work-card__shot img, .wh-feature__media img, .wh-shot img,
.project-gallery__trigger img, .project-gallery--bento .project-gallery__trigger img,
.project-page--website .project-gallery__trigger img, .project-page--website .bento__trigger img {
  transition: transform 0.9s var(--ease-out-expo);
}

/* ── Links de texto com seta: a seta anda, o texto não ── */
.glass-card__cta-link, .cs-card__cta, .cs-web__cta, .work-card__go, .project-back {
  transition: color var(--dur-hover) var(--ease-out), translate var(--dur-state) var(--ease-out);
}

/* ── Movimento reduzido: estados finais, sem deslocamento ── */
@media (prefers-reduced-motion: reduce) {
  .reveal-element:not(.is-visible),
  .reveal-element { opacity: 1; transform: none; transition: none; }
  .mobile-menu, .mobile-menu.is-open { clip-path: none; }
  .mobile-menu li, .mobile-menu .lang-switch--mobile { opacity: 1; translate: none; transition: none; }
  .topbar.topbar--hidden { translate: none; }
  .btn:active, .contact__submit:active, .topbar__cta:active, .dock__item:active { scale: 1; }
  .lightbox__figure, .lightbox.is-closing .lightbox__figure { animation: none; }
}

/* ═══════════════════════════════════════════════════════════════
   TOPBAR — vidro simétrico
   Geometria (desktop): controles de 40px com o mesmo respiro nos
   quatro lados (10px no topo da página, 7px encolhida), todos em
   cápsula, então as curvas ficam concêntricas com a da barra.
   Variáveis escritas pelo motion.js (initTopbarGlass):
     --nav-p    0 → 1 nos primeiros ~320px de scroll (suavizado)
     --mx/--my  cursor sobre a barra (px) → luz na borda
   ═══════════════════════════════════════════════════════════════ */
@property --spot { syntax: '<number>'; inherits: true; initial-value: 0; }

.topbar {
  --nav-p: 0;
  --mx: 50%;
  --my: 50%;
  isolation: isolate;
  top: calc(1rem - 0.3rem * var(--nav-p));
  background:
    linear-gradient(180deg,
      rgba(255, 255, 255, calc(0.055 - 0.025 * var(--nav-p))) 0%,
      rgba(255, 255, 255, 0) 70%),
    rgba(6, 10, 19, calc(0.34 + 0.42 * var(--nav-p)));
  border-color: transparent;
  -webkit-backdrop-filter:
    blur(calc(12px + 12px * var(--nav-p)))
    saturate(calc(1.3 + 0.3 * var(--nav-p)))
    brightness(calc(1 - 0.16 * var(--nav-p)));
  backdrop-filter:
    blur(calc(12px + 12px * var(--nav-p)))
    saturate(calc(1.3 + 0.3 * var(--nav-p)))
    brightness(calc(1 - 0.16 * var(--nav-p)));
  box-shadow:
    0 calc(8px + 12px * var(--nav-p)) calc(24px + 28px * var(--nav-p)) -12px
      rgba(0, 0, 0, calc(0.3 + 0.35 * var(--nav-p)));
  transition:
    translate 0.55s var(--ease-out-expo),
    --spot 0.45s var(--ease-out);
}
.topbar.is-lit { --spot: 1; }

/* borda especular: luz no topo e na base, acende perto do cursor */
.topbar::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  pointer-events: none;
  background:
    radial-gradient(180px 70px at var(--mx) var(--my),
      rgba(191, 219, 254, calc(0.55 * var(--spot))), transparent 70%),
    linear-gradient(180deg,
      rgba(255, 255, 255, 0.2) 0%,
      rgba(255, 255, 255, 0.05) 50%,
      rgba(147, 197, 253, 0.16) 100%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
}

/* sem backdrop-filter: vidro vira fumê sólido, ainda legível */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .topbar { background: rgba(8, 13, 24, calc(0.86 + 0.1 * var(--nav-p))); }
}

/* ── Marca: monograma + nome ── */
.topbar__brand {
  gap: 0.6rem;
  font-size: 0.9375rem;
  color: #f1f5f9;
}
.topbar__mark {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 8px;
  background: linear-gradient(160deg, #3b82f6 0%, #1d4ed8 60%, #1e3a8a 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 4px 12px -2px rgba(37, 99, 235, 0.5);
}
/* mesmo desenho de assets/favicon/favicon.svg, com o viewBox recortado no "M"
   (embutido: máscara por arquivo externo não carrega via file://) */
.topbar__mark::after {
  content: "";
  position: absolute;
  inset: 18%;
  /* ajuste óptico: o peso do "M" fica no alto e a ponta de baixo é fina,
     então o centro geométrico parece alto; desce 7% do próprio tamanho */
  translate: 0 7%;
  background: #fff;
  --mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='1139 1139 1722 1722'%3E%3Cpath d='M2000,2829.019l-256.317-147.948c53.484-3.656,95.95-44.885,102.321-96.85v-651.322l-295.779-170.768v807.146l-410.554-236.195c58.068-3.965,103.147-52.228,103.147-110.431v-889.722l-103.147-161.95L2000,1667.69l860.329-496.711l-103.146,161.95v889.722c0,58.203,45.079,106.466,103.146,110.431l-410.554,236.195v-807.146l-295.779,170.768v651.322c6.371,51.965,48.836,93.195,102.321,96.85L2000,2829.019z'/%3E%3C/svg%3E");
  -webkit-mask: var(--mark) center / contain no-repeat;
  mask: var(--mark) center / contain no-repeat;
}

/* ── Links ── */
.topbar__link {
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 0.8125rem;
  letter-spacing: -0.005em;
  color: rgba(203, 213, 225, 0.74);
}
.topbar__link:hover { color: #f8fafc; }
.topbar__link.is-active { color: #fff; }

/* hub / páginas de caso */
.topbar__home { font-family: var(--font-ui); }

/* ── CTA: seta em disco que sai por um canto e volta pelo oposto ── */
.topbar__cta { gap: 0.65rem; }
.topbar__cta-icon {
  position: relative;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  overflow: hidden;
  border-radius: 50%;
  background: #f8fafc;
  color: #1d4ed8;
}
.topbar__cta-icon svg {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 12px;
  height: 12px;
  transition: translate 0.5s var(--ease-out-expo);
}
.topbar__cta-icon svg + svg { translate: -22px 22px; }
.topbar__cta:focus-visible .topbar__cta-icon svg:first-child { translate: 22px -22px; }
.topbar__cta:focus-visible .topbar__cta-icon svg + svg { translate: 0 0; }
@media (hover: hover) {
  .topbar__cta:hover .topbar__cta-icon svg:first-child { translate: 22px -22px; }
  .topbar__cta:hover .topbar__cta-icon svg + svg { translate: 0 0; }
}

/* tablet: o disco não pode engordar o botão */
@media (max-width: 899px) {
  .topbar__cta { padding-block: 0.25rem; padding-right: 0.3rem; }
}
/* 900–999px: sem o disco, para o botão não invadir a nav (rótulo em ES) */
@media (min-width: 900px) and (max-width: 999px) {
  .topbar .topbar__cta { padding-inline: 0.85rem; }
  .topbar__cta-icon { display: none; }
}

/* ═══ Desktop: grid de três colunas, laterais iguais → nav no centro exato ═══ */
@media (min-width: 900px) {
  .topbar {
    width: min(calc(1180px - 140px * var(--nav-p)), calc(100% - 1.5rem));
  }

  .topbar__inner,
  .topbar__inner--hub {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    column-gap: 0.5rem;
    height: calc(60px - 6px * var(--nav-p));
    padding: 0 calc(10px - 3px * var(--nav-p));
  }

  .topbar__brand {
    grid-column: 1;
    justify-self: start;
    gap: 0.7rem;
  }
  .topbar__mark {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }

  /* colunas iguais: o item do meio cai no eixo da barra */
  .topbar__nav,
  .topbar__inner--hub .topbar__nav {
    grid-column: 2;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 5.5rem;
    gap: 2px;
    margin: 0;
  }
  .topbar__link {
    display: grid;
    place-items: center;
    height: 2.5rem;
    padding: 0;
    white-space: nowrap;
  }
  .topbar__home {
    grid-column: 2;
    height: 40px;
    padding-block: 0;
  }

  .topbar__actions,
  .topbar__inner--hub .topbar__actions {
    grid-column: 3;
    justify-self: end;
    gap: 0.5rem;
    margin: 0;
  }

  .topbar__cta {
    height: 40px;
    padding: 0 5px 0 1.1rem;
    border-color: rgba(147, 197, 253, 0.3);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.18),
      0 6px 18px -6px rgba(37, 99, 235, 0.7);
  }
  .topbar__cta:hover {
    transform: none;
    background: #1d4ed8;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.22),
      0 10px 24px -6px rgba(37, 99, 235, 0.8);
  }

  /* idioma: três segmentos iguais, mesma altura do CTA */
  .topbar .lang-switch {
    display: inline-flex;
    height: 40px;
    padding: 3px;
    background: rgba(255, 255, 255, 0.035);
    border-color: rgba(148, 163, 184, 0.16);
  }
  .topbar .lang-switch__btn {
    width: 34px;
    height: 32px;
    padding: 0;
    border-radius: 999px;
  }
}

/* faixa estreita: só o monograma e colunas mais justas */
@media (min-width: 900px) and (max-width: 1099px) {
  .topbar__brand {
    width: 40px;
    gap: 0;
    overflow: hidden;
    font-size: 0;
  }
  .topbar__nav,
  .topbar__inner--hub .topbar__nav { grid-auto-columns: 4.5rem; }
  .topbar__cta { padding-left: 0.85rem; gap: 0.5rem; }
  .topbar .lang-switch__btn { width: 30px; }
}

/* ── Entrada (1ª visita da sessão): a barra pousa e o conteúdo
   se abre do centro para as pontas, em espelho ── */
.topbar--enter { animation: mx-bar-in 0.9s var(--ease-out-expo) backwards; }
.topbar--enter .topbar__brand,
.topbar--enter .topbar__actions,
.topbar--enter .topbar__home,
.topbar--enter .topbar__link {
  animation: mx-item-in 0.7s var(--ease-out-expo) backwards;
  animation-delay: calc(0.18s + var(--enter-i, 3) * 70ms);
}
@keyframes mx-bar-in  { from { opacity: 0; translate: 0 -14px; } }
@keyframes mx-item-in { from { opacity: 0; translate: 0 -6px; filter: blur(4px); } }

@media (prefers-reduced-motion: reduce) {
  .topbar { transition: none; }
  .topbar__pill, .topbar__ghost, .topbar__cta-icon svg { transition: none; }
}
