/* ===== SCROLL SNAP & BIDIRECTIONAL SECTION ANIMATIONS ===== */

html {
  scroll-snap-type: none; /* Disabled to fix jumpy scroll on mobile */
  scroll-padding-top: 0;
}

body {
  scroll-snap-type: none;
}

html.nav-scrolling {
  scroll-snap-type: none;
}

.app-shell,
.portfolio-main > section,
footer {
  /* scroll-snap-align disabled for smoother mobile scrolling */
}

.app-shell {
  min-height: 100svh;
}

.portfolio-main {
  position: relative;
  overflow: visible;
}

.intro-section,
.portfolio-section,
.contact-section {
  width: 100%;
  max-width: 100%;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-inline: max(1.5rem, calc((100vw - 80rem) / 2 + 1.5rem));
  background: #fff;
  backface-visibility: hidden;
  transform: translateZ(0);
  will-change: transform;
}

.intro-section > *,
.portfolio-section > *,
.contact-section > * {
  width: min(100%, 80rem);
  margin-left: auto;
  margin-right: auto;
}

.intro-section,
.stack-section,
.education-section {
  background: var(--alt-bg);
}

@media (min-width: 900px) {
  html,
  body {
    scroll-snap-type: none; /* Disabled to fix reverse scroll jumping bug with position: sticky */
  }

  body {
    scroll-snap-type: none;
  }

  .intro-section,
  .portfolio-section,
  .contact-section {
    position: sticky;
    top: 0;
    box-shadow: 0 -1px 0 rgba(231, 235, 230, 0.75), 0 -28px 70px rgba(17, 20, 17, 0.06);
  }

  .intro-section { z-index: 1; }
  #work { z-index: 2; }
  #stack { z-index: 3; }
  #experience { z-index: 4; }
  #education { z-index: 5; }
  #contact { z-index: 6; }
}

@media (max-width: 899px) {
  html,
  body {
    scroll-snap-type: none;
  }

  body {
    scroll-snap-type: none;
  }

  .intro-section,
  .portfolio-section,
  .contact-section {
    min-height: auto;
  }
}

/* ---- Base reveal ---- */
.reveal {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 420ms cubic-bezier(0.22, 1, 0.36, 1),
              transform 420ms cubic-bezier(0.22, 1, 0.36, 1);
}

.reveal--left  { transform: translateX(-14px); }
.reveal--right { transform: translateX(14px); }

.reveal--scale {
  transform: translateY(18px) scale(0.985);
  transition: opacity 380ms cubic-bezier(0.22, 1, 0.36, 1),
              transform 380ms cubic-bezier(0.22, 1, 0.36, 1);
}

.reveal--blur {
  filter: none;
  transform: translateY(14px);
  transition: opacity 380ms cubic-bezier(0.22, 1, 0.36, 1),
              transform 380ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---- Visible (entering) ---- */
.reveal.visible {
  opacity: 1;
  transform: translateY(0) translateX(0) scale(1);
  filter: none;
}

/* ---- Stagger: project cards ---- */
.project-grid .project-card.reveal:nth-child(1) { transition-delay: 0ms; }
.project-grid .project-card.reveal:nth-child(2) { transition-delay: 38ms; }
.project-grid .project-card.reveal:nth-child(3) { transition-delay: 76ms; }
.project-grid .project-card.reveal:nth-child(4) { transition-delay: 114ms; }

/* When leaving (not visible), reset delay so reverse is instant */
.project-grid .project-card.reveal:not(.visible) { transition-delay: 0ms; }

/* ---- Stagger: timeline ---- */
.timeline article.reveal:nth-child(1) { transition-delay: 0ms; }
.timeline article.reveal:nth-child(2) { transition-delay: 55ms; }
.timeline article.reveal:nth-child(3) { transition-delay: 110ms; }
.timeline article.reveal:not(.visible) { transition-delay: 0ms; }

/* ---- Stack grid chips ---- */
.stack-grid span {
  opacity: 0;
  transform: translateY(10px) scale(0.98);
  transition: opacity 280ms cubic-bezier(0.22, 1, 0.36, 1),
              transform 280ms cubic-bezier(0.22, 1, 0.36, 1);
}

.stack-grid.visible span { opacity: 1; transform: translateY(0) scale(1); }

.stack-grid.visible span:nth-child(1)  { transition-delay: 10ms; }
.stack-grid.visible span:nth-child(2)  { transition-delay: 24ms; }
.stack-grid.visible span:nth-child(3)  { transition-delay: 38ms; }
.stack-grid.visible span:nth-child(4)  { transition-delay: 52ms; }
.stack-grid.visible span:nth-child(5)  { transition-delay: 66ms; }
.stack-grid.visible span:nth-child(6)  { transition-delay: 80ms; }
.stack-grid.visible span:nth-child(7)  { transition-delay: 94ms; }
.stack-grid.visible span:nth-child(8)  { transition-delay: 108ms; }
.stack-grid.visible span:nth-child(9)  { transition-delay: 122ms; }
.stack-grid.visible span:nth-child(10) { transition-delay: 136ms; }
.stack-grid.visible span:nth-child(11) { transition-delay: 150ms; }
.stack-grid.visible span:nth-child(12) { transition-delay: 164ms; }
.stack-grid.visible span:nth-child(13) { transition-delay: 178ms; }

/* Reset chip delays on exit */
.stack-grid:not(.visible) span { transition-delay: 0ms !important; }

/* ---- Contact section ---- */
.contact-section.reveal {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 420ms cubic-bezier(0.22, 1, 0.36, 1),
              transform 420ms cubic-bezier(0.22, 1, 0.36, 1);
}

.contact-section.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

.contact-email {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 360ms cubic-bezier(0.22, 1, 0.36, 1) 80ms,
              transform 360ms cubic-bezier(0.22, 1, 0.36, 1) 80ms;
}
.contact-section.visible .contact-email { opacity: 1; transform: translateY(0); }
.contact-section:not(.visible) .contact-email { transition-delay: 0ms; }

.socials a {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 260ms ease, transform 260ms ease;
}
.contact-section.visible .socials a { opacity: 1; transform: translateY(0); }
.contact-section.visible .socials a:nth-child(1) { transition-delay: 150ms; }
.contact-section.visible .socials a:nth-child(2) { transition-delay: 180ms; }
.contact-section.visible .socials a:nth-child(3) { transition-delay: 210ms; }
.contact-section.visible .socials a:nth-child(4) { transition-delay: 240ms; }
.contact-section:not(.visible) .socials a { transition-delay: 0ms !important; }

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  .reveal, .stack-grid span, .contact-email, .socials a {
    transition: none !important;
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
  }
}
