/* ==========================================================================
   Motion animation support

   Everything here is scoped to .js-anim, a class set by an inline snippet in
   <head>. That class is never added when JavaScript is off, and is removed
   again when the visitor prefers reduced motion or the Motion CDN can't be
   reached - so the site always falls back to rendering exactly as it did
   before this file existed. Nothing can be left permanently invisible.

   Kept separate from main.scss / main.css on purpose: those two are a
   compiled pair and sass isn't installed here, so hand-editing them risks
   the .scss and .css drifting apart.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Initial hidden states

   Structural selectors rather than markup hooks, so the seven HTML pages need
   no per-element attributes. Motion writes inline styles when it animates,
   and inline always beats these rules.
   -------------------------------------------------------------------------- */
/* The anchor only - it wraps an <img class="logo"> that matches the same
   bare .logo selector, and the image inherits the anchor's opacity. */
.js-anim header a.logo,
.js-anim header nav ul li,
.js-anim .carousel-slide .container > *,
.js-anim #about h2,
.js-anim #about .descriptions > p,
.js-anim #about .descriptions > ul > li,
.js-anim #home-projects h2,
.js-anim #home-projects h4,
.js-anim #home-projects .buttons,
.js-anim #clients h2,
.js-anim .highlights .item,
.js-anim #home-projects .project-grid .project,
.js-anim .clients-grid,
.js-anim .menu-projects a,
.js-anim #projects .imgs .item,
.js-anim #projects .desc {
  opacity: 0;
}

/* --------------------------------------------------------------------------
   Hero parallax

   .carousel-slide .img is an absolutely positioned, inset:0 backdrop at
   opacity .3. Translating it would expose a gap top and bottom, so it gets
   vertical headroom and the slide clips the overflow. The 9% offset covers
   the 80px of travel applied in animations.js at every realistic viewport
   height.

   Scoped to .carousel-slide, NOT to #home. The service pages reuse #home for
   a 170px band whose .menu-projects bar deliberately overflows it, the same
   way .highlights overflows its section - clipping #home would cut that bar
   in half. Their hero is too short for parallax to read anyway.
   -------------------------------------------------------------------------- */
.js-anim #home .carousel-slide {
  overflow: hidden;
}

.js-anim #home .carousel-slide .img {
  height: 118%;
  top: -9%;
}

/* --------------------------------------------------------------------------
   Header condense on scroll

   main.js already toggles .active past 100px; today that only swaps the
   background colour. This adds the matching size change.

   Desktop only: the mobile menu is a fixed panel anchored at top:70px, which
   would no longer line up with a shorter header.
   -------------------------------------------------------------------------- */
@media (min-width: 641px) {
  .js-anim header {
    transition:
      padding 0.35s ease,
      background-color 0.35s ease,
      box-shadow 0.35s ease;
  }

  .js-anim header .logo img {
    transform-origin: left center;
    transition: transform 0.35s ease;
  }

  .js-anim header.active {
    box-shadow: 0 1px 24px rgba(0, 0, 0, 0.28);
    padding: 10px 0;
  }

  .js-anim header.active .logo img {
    transform: scale(0.88);
  }
}

/* --------------------------------------------------------------------------
   Micro-interactions

   Left to CSS rather than Motion - cheaper, and they inherit the existing
   prefers-reduced-motion block in main.css for free.
   -------------------------------------------------------------------------- */
.js-anim #home-projects .project-grid .project img,
.js-anim #projects .imgs .item img {
  transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.js-anim #home-projects .project-grid .project:hover img,
.js-anim #home-projects .project-grid .project:focus-visible img,
.js-anim #projects .imgs .item:hover img,
.js-anim #projects .imgs .item:focus-visible img {
  transform: scale(1.04);
}

.js-anim .clients-grid img {
  transition: transform 0.3s ease;
}

.js-anim .clients-grid img:hover {
  transform: translateY(-3px);
}

.js-anim a.button svg {
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.js-anim a.button:hover svg {
  transform: translate(3px, -3px);
}

/* Images scale on hover, so their frame has to clip. */
.js-anim #home-projects .project-grid .project,
.js-anim #projects .imgs .item {
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   Reduced motion

   animations.js strips .js-anim in this case, which disables everything
   above. This block is a second line of defence in case the class is still
   present - it must never be possible to leave content at opacity 0.
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .js-anim header a.logo,
  .js-anim header nav ul li,
  .js-anim .carousel-slide .container > *,
  .js-anim #about h2,
  .js-anim #about .descriptions > p,
  .js-anim #about .descriptions > ul > li,
  .js-anim #home-projects h2,
  .js-anim #home-projects h4,
  .js-anim #home-projects .buttons,
  .js-anim #clients h2,
  .js-anim .highlights .item,
  .js-anim #home-projects .project-grid .project,
  .js-anim .clients-grid,
  .js-anim .menu-projects a,
  .js-anim #projects .imgs .item,
  .js-anim #projects .desc {
    opacity: 1 !important;
  }

  .js-anim #home .carousel-slide .img {
    height: 100%;
    top: 0;
  }
}
