/* ==========================================================================
   327Labs Custom Animation System
   Compositor-only motion (transform / opacity) with strict reduced-motion safety
   ========================================================================== */

:root {
  --ease-swiss: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ==========================================================================
   1. Hairline Scroll Progress Bar (Pinned to bottom edge of sticky header)
   ========================================================================== */

.scroll-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background-color: var(--accent);
  transform-origin: left center;
  transform: scaleX(var(--scroll-progress, 0));
  pointer-events: none;
  z-index: 101;
}

@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: scroll()) {
    @keyframes scroll-progress-grow {
      from {
        transform: scaleX(0);
      }
      to {
        transform: scaleX(1);
      }
    }

    .scroll-progress {
      transform: scaleX(0);
      animation: scroll-progress-grow linear both;
      animation-timeline: scroll(root block);
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  .scroll-progress {
    display: none;
  }
}

/* ==========================================================================
   2. Navbar Active Scrollspy Indicator
   ========================================================================== */

.nav-link {
  position: relative;
  padding-block: 0.25rem;
}

.nav-link::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -2px;
  height: 2px;
  background-color: var(--accent);
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 220ms var(--ease-swiss);
}

.nav-link.is-active {
  color: var(--text-primary);
}

.nav-link.is-active::after {
  transform: scaleX(1);
}

/* ==========================================================================
   3. Hero Entrance Choreography & Accent Underline Draw-In
   ========================================================================== */

@media (prefers-reduced-motion: no-preference) {
  @keyframes hero-enter {
    from {
      opacity: 0;
      transform: translate3d(0, 14px, 0);
    }
    to {
      opacity: 1;
      transform: translate3d(0, 0, 0);
    }
  }

  @keyframes accent-underline-draw {
    from {
      background-size: 0% 3px;
    }
    to {
      background-size: 100% 3px;
    }
  }

  .hero-kicker,
  .hero-title,
  .hero-subtitle,
  .hero-actions,
  .deploy-terminal,
  .stack-cell {
    animation: hero-enter 560ms var(--ease-swiss) both;
  }

  .hero-kicker {
    animation-delay: 0ms;
  }

  .hero-title {
    animation-delay: 70ms;
  }

  .hero-subtitle {
    animation-delay: 140ms;
  }

  .hero-actions {
    animation-delay: 200ms;
  }

  .deploy-terminal {
    animation-delay: 160ms;
  }

  .stack-cell:nth-child(1) {
    animation-delay: 250ms;
  }
  .stack-cell:nth-child(2) {
    animation-delay: 300ms;
  }
  .stack-cell:nth-child(3) {
    animation-delay: 350ms;
  }
  .stack-cell:nth-child(4) {
    animation-delay: 400ms;
  }

  .hero-accent-phrase {
    text-decoration: none;
    background-image: linear-gradient(var(--accent), var(--accent));
    background-repeat: no-repeat;
    background-position: 0 96%;
    background-size: 0% 3px;
    padding-bottom: 2px;
    animation: accent-underline-draw 520ms var(--ease-swiss) 320ms forwards;
  }
}

/* ==========================================================================
   4. Seamless Manifesto Marquee Ticker
   ========================================================================== */

.manifesto-band {
  overflow: hidden;
}

.manifesto-marquee {
  display: flex;
  width: 100%;
  overflow: hidden;
}

.manifesto-track {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 2.5rem;
  padding-right: 2.5rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-on-dark-muted);
  white-space: nowrap;
}

@media (prefers-reduced-motion: no-preference) {
  @keyframes manifesto-scroll {
    from {
      transform: translate3d(0, 0, 0);
    }
    to {
      transform: translate3d(-100%, 0, 0);
    }
  }

  .manifesto-track {
    animation: manifesto-scroll 28s linear infinite;
    will-change: transform;
  }

  .manifesto-marquee:hover .manifesto-track {
    animation-play-state: paused;
  }
}

@media (prefers-reduced-motion: reduce) {
  .manifesto-marquee {
    max-width: var(--container-max);
    margin-inline: auto;
    padding-inline: var(--gutter);
  }

  .manifesto-track {
    flex-wrap: wrap;
    white-space: normal;
    gap: 0.625rem 1.5rem;
    padding-right: 0;
  }

  .manifesto-track[aria-hidden='true'] {
    display: none;
  }
}

/* ==========================================================================
   5. Scroll-Triggered Staggered Reveals & Section Choreography
   ========================================================================== */

@media (prefers-reduced-motion: no-preference) {
  html.js-motion [data-reveal] {
    opacity: 0;
    transform: translate3d(0, 18px, 0);
    transition:
      opacity 540ms var(--ease-swiss) var(--reveal-delay, 0ms),
      transform 540ms var(--ease-swiss) var(--reveal-delay, 0ms);
  }

  html.js-motion [data-reveal].is-visible {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }

  /* Colophon Reader Progress Bar Sweep on Enter */
  html.js-motion .case-study-card .colophon-progress-fill {
    transform-origin: left center;
    transform: scaleX(0);
    transition: transform 850ms var(--ease-swiss) 240ms;
  }

  html.js-motion .case-study-card.is-visible .colophon-progress-fill {
    transform: scaleX(1);
  }

  /* Process Step Terracotta Top-Rail Sweep on Enter */
  .process-step::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background-color: var(--accent);
    transform-origin: left center;
    transform: scaleX(0);
    transition: transform 650ms var(--ease-swiss) calc(var(--reveal-delay, 0ms) + 180ms);
  }

  html.js-motion .process-step.is-visible::before,
  html:not(.js-motion) .process-step::before {
    transform: scaleX(1);
  }
}

/* ==========================================================================
   6. Tactile Micro-Interactions
   ========================================================================== */

/* Rotating + Corner Registration Marks */
.frame-mark {
  transition: transform 280ms var(--ease-swiss), color 200ms ease;
}

@media (prefers-reduced-motion: no-preference) {
  .frame-marked:hover .frame-mark {
    transform: rotate(90deg);
    color: var(--accent);
  }
}

/* Crisp Button Animations: Kinetic Fill Sweep, Sheen, Lift & Press Detent */
.btn {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  transition:
    background-color var(--ease-fast),
    color 220ms var(--ease-swiss),
    border-color var(--ease-fast),
    transform 160ms var(--ease-swiss);
}

.btn > * {
  position: relative;
  z-index: 1;
}

@media (prefers-reduced-motion: no-preference) {
  /* Primary CTA: Crisp hover lift + machined sheen sweep */
  .btn--primary::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
      110deg,
      transparent 20%,
      rgba(255, 255, 255, 0.22) 50%,
      transparent 80%
    );
    transform: translate3d(-115%, 0, 0);
    transition: transform 520ms var(--ease-swiss);
    pointer-events: none;
    z-index: 0;
  }

  .btn--primary:hover {
    transform: translate3d(0, -1px, 0);
  }

  .btn--primary:hover::after {
    transform: translate3d(115%, 0, 0);
  }

  /* Secondary CTA: Taut left-to-right high-contrast fill sweep */
  .btn--secondary::before {
    content: '';
    position: absolute;
    inset: 0;
    background-color: var(--border-strong);
    transform-origin: left center;
    transform: scaleX(0);
    transition: transform 260ms var(--ease-swiss);
    pointer-events: none;
    z-index: -1;
  }

  .btn--secondary:hover {
    background-color: var(--bg-surface);
    color: var(--bg-canvas);
    transform: translate3d(0, -1px, 0);
  }

  .btn--secondary:hover::before {
    transform: scaleX(1);
  }

  .btn:active {
    transform: translate3d(0, 0, 0) scale(0.975);
  }

  /* Theme toggle icon micro-rotation */
  .theme-toggle svg {
    transition: transform 240ms var(--ease-swiss);
  }

  .theme-toggle:hover svg {
    transform: rotate(18deg) scale(1.06);
  }

  .theme-toggle:active svg {
    transform: rotate(-12deg) scale(0.92);
  }
}

/* Audience Mode Crossfade */
@media (prefers-reduced-motion: no-preference) {
  [data-copy] {
    transition: opacity 150ms ease;
  }

  html.is-mode-switching [data-copy] {
    opacity: 0.25;
  }
}

.arrow-icon {
  display: inline-block;
  transition: transform 200ms var(--ease-swiss);
}

.btn:hover .arrow-icon--diag {
  transform: translate3d(3px, -3px, 0);
}

.case-study-action:hover .arrow-icon--right {
  transform: translate3d(5px, 0, 0);
}
