/*
 * Motion layer added on top of theme.css (2026-09-28).
 * Spec: docs/superpowers/specs/2026-09-28-site-motion-design.md
 * Rules: only transform / opacity / clip-path are animated; everything
 * scroll-linked lives under @supports (animation-timeline: view()) and
 * prefers-reduced-motion: no-preference, so unsupported browsers and
 * reduced-motion visitors see the final state.
 */

/* === Headings reveal as one block (spec 4.8) === */
/* theme.css staggers per-word spans by --delay; the block now moves as one. */
h1.animate_show.top > span,
h1.animate_show.bottom > span,
h2.animate_show.top > span,
h2.animate_show.bottom > span {
  animation-delay: 0s !important;
}

/* === Reduced motion for the theme's own reveals (spec 5) === */
/* theme.css has no prefers-reduced-motion rule at all. */
@media (prefers-reduced-motion: reduce) {
  .pre_animate_show,
  .pre_animate_show > *,
  .animate_show.fade,
  .animate_show.top > *,
  .animate_show.bottom > *,
  .animate_show.rotate img {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
  header {
    animation: none !important;
  }
}

/* === Header hides on scroll down (spec 4.2) === */
/* theme.css plays show_header with fill-mode forwards, which would pin
   transform: translateY(0) and override .hidden; its end state equals the
   default, so dropping the fill loses nothing. */
header {
  animation-fill-mode: none;
  transition: background var(--dur-hover), box-shadow var(--dur-hover), transform 0.35s var(--ease-out);
}
header.hidden {
  transform: translateY(-100%);
}

/* === Hero slides (spec 4.1) === */
#home .background_video .video { overflow: hidden; }
#home .background_video .hero-media {
  position: absolute;
  inset: 0;
  opacity: 0;
}
#home .background_video .hero-media.is-active { opacity: 1; z-index: 2; }
#home .background_video .hero-media.is-leaving { opacity: 1; z-index: 1; }
#home .background_video .hero-media.is-active.is-animated {
  animation: hero-slide-in 0.6s var(--ease-out) both;
}
@keyframes hero-slide-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}
#home .background_video .hero-media video,
#home .background_video .hero-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#home .background_video .overlay { align-items: flex-end; }
#home .background_video .hero-card {
  max-width: 36rem;
  padding: 2rem 2rem 1.25rem;
  border-radius: var(--radius);
  background: linear-gradient(160deg, rgba(13, 86, 147, 0.82), rgba(11, 14, 16, 0.78));
  backdrop-filter: blur(6px);
}
/* Same specificity as theme.css's `.overlay .text_container h1` (1,3,1);
   motion.css loads later, so h1 and h2 slides render identically. */
#home .background_video .overlay .hero-card :is(h1, h2) {
  font-family: var(--font-heading);
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1.12;
  color: var(--text-on-dark);
  margin-bottom: 1rem;
  max-width: 22ch;
}
#home .background_video .hero-card-body { animation: hero-text-in 0.3s ease-out both; }
@keyframes hero-text-in { from { opacity: 0; } to { opacity: 1; } }
#home .background_video .hero-text {
  color: var(--text-muted-dark);
  margin-bottom: 1.5rem;
  max-width: 60ch;
}
#home .background_video .hero-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1.5rem;
}
#home .background_video .hero-progress { display: flex; gap: 6px; flex: 1; }
#home .background_video .hero-progress button {
  flex: 1;
  height: 16px;            /* hit area; the bar itself is the 3px span */
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}
#home .background_video .hero-progress button span {
  display: block;
  height: 3px;
  background: var(--line-dark);
  position: relative;
  overflow: hidden;
}
#home .background_video .hero-progress button span::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--text-on-dark);
  transform-origin: left;
  transform: scaleX(0);
}
#home .background_video .hero-progress button.is-done span::after { transform: scaleX(1); }
#home .background_video .hero-progress button.is-current span::after {
  animation: hero-progress 7s linear forwards; /* = HERO_SLIDE_MS */
  animation-play-state: paused;
}
#home .background_video.is-running .hero-progress button.is-current span::after {
  animation-play-state: running;
}
@keyframes hero-progress { to { transform: scaleX(1); } }
#home .background_video .hero-pause {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 1px solid var(--text-on-dark);
  background: transparent;
  color: var(--text-on-dark);
  font-size: 0.7rem;
  cursor: pointer;
}
#home .background_video .hero-progress button:focus-visible,
#home .background_video .hero-pause:focus-visible {
  outline: 2px solid var(--text-on-dark);
  outline-offset: 2px;
}
@media (max-width: 700px) {
  #home .background_video .overlay { padding: 1rem; }
  #home .background_video .hero-card { padding: 1.25rem; }
  #home .background_video .overlay .hero-card :is(h1, h2) { font-size: 1.6rem; }
}
@media (prefers-reduced-motion: reduce) {
  #home .background_video .hero-media.is-active.is-animated,
  #home .background_video .hero-card-body { animation: none; }
  #home .background_video .hero-progress button.is-current span::after {
    animation: none;
    transform: scaleX(1);
  }
}

/* === Hero recedes under the next section (spec 4.2) === */
/* Every later section paints above the hero; a positioned hero would
   otherwise cover the non-positioned sections of theme.css. */
#home > :not(.background_video) { position: relative; z-index: 1; }
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    /* Sticky only where the fade-out below also runs: without it the hero
       would stay pinned behind the whole page. */
    #home .background_video {
      position: sticky;
      top: 0;
      z-index: 0;
      animation: hero-gone linear both;
      animation-timeline: scroll(root);
      animation-range: 100vh 160vh;
    }
    #home .background_video .video {
      animation: hero-recede linear both;
      animation-timeline: scroll(root);
      animation-range: 0 100vh;
    }
    #home .background_video .overlay {
      animation: hero-card-out linear both;
      animation-timeline: scroll(root);
      animation-range: 0 60vh;
    }
  }
}
@keyframes hero-recede {
  to { transform: scale(0.9); clip-path: inset(0 round 1.5rem); opacity: 0.8; }
}
@keyframes hero-gone {
  to { opacity: 0; visibility: hidden; }
}
@keyframes hero-card-out {
  to { transform: translateY(-15vh); opacity: 0; }
}

/* === About: three moving lines (spec 4.3) === */
#home .about.about--motion {
  padding: 6rem 0 5rem;
  background: var(--blue-dark);
  color: var(--text-on-dark);
  overflow: hidden;
  text-align: center;
}
#home .about.about--motion .section-label { color: var(--text-on-dark); }
#home .about .about-stage { position: relative; margin: 2rem 0 4rem; }
#home .about .about-lines {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: clamp(3rem, 12vw, 11rem);
  line-height: 0.95;
  font-weight: 700;
  color: var(--text-on-dark);
  white-space: nowrap;
}
#home .about .about-line { display: block; }
#home .about .about-line--2 { opacity: 0.7; }
#home .about .about-line--3 { opacity: 0.4; }
#home .about .about-float {
  position: absolute;
  right: 12%;
  bottom: -10%;
  width: min(22rem, 40vw);
  z-index: 1;
}
#home .about .about-float img { width: 100%; border-radius: var(--radius); }

/* === About: statement lit word by word (spec 4.4) === */
#home .about .statement {
  max-width: 34ch;
  margin: 0 auto 2.5rem;
  font-size: clamp(1.4rem, 2.6vw, 2.4rem);
  line-height: 1.35;
  color: var(--text-on-dark);
}
#home .about .buttons { display: flex; gap: 1rem; justify-content: center; }

@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    #home .about .statement { view-timeline: --statement block; }
    #home .about .statement .word {
      opacity: 0.4;
      animation: word-lit linear both;
      animation-timeline: --statement;
      /* Words light up one after another while the paragraph crosses the
         middle of the viewport: cover 25%..65%, split evenly by word. */
      animation-range:
        cover calc(25% + 40% * var(--i) / var(--words))
        cover calc(25% + 40% * (var(--i) + 1) / var(--words));
    }
  }
}
@keyframes word-lit { from { opacity: 0.4; } to { opacity: 1; } }
@media (max-width: 700px) {
  /* Narrow screens: a smaller photo at the edge, so the words stay legible. */
  #home .about .about-float { right: -6%; bottom: -30%; width: 32vw; }
}

/* === Solutions: photo collage with depth (spec 4.5) === */
#home .services .collage {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 1.5rem;
  align-items: start;
  max-width: 72rem;
  margin: 0 auto 5rem;
}
#home .services .collage-tile { margin: 0; }
#home .services .collage-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
  box-shadow: var(--shadow-card);
}
#home .services .collage-tile--s { grid-column: span 1; aspect-ratio: 1 / 1; margin-top: 4rem; }
#home .services .collage-tile--m { grid-column: span 2; aspect-ratio: 4 / 3; }
#home .services .collage-tile--l { grid-column: span 3; aspect-ratio: 16 / 10; margin-top: 2rem; }
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) and (min-width: 768px) {
    #home .services .collage-tile {
      animation: collage-depth linear both;
      animation-timeline: view();
    }
  }
}
@keyframes collage-depth {
  from { transform: translateY(calc(var(--depth) * 12vh)); }
  to { transform: translateY(calc(var(--depth) * -12vh)); }
}
@media (max-width: 767px) {
  #home .services .collage { grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
  #home .services .collage-tile--s,
  #home .services .collage-tile--m,
  #home .services .collage-tile--l { grid-column: span 1; margin-top: 0; aspect-ratio: 1 / 1; }
}

/* === Projects ribbon, active card larger (spec 4.6) === */
#home .projects .projects_ribbon {
  --card-w: 16rem;
  --card-active-w: 28rem;
  --gap: 1rem;
  overflow: hidden;
  /* Centre the active card: left pad = half the viewport minus half a card. */
  padding: 1rem 0 0 calc(50% - var(--card-active-w) / 2);
}
#home .projects .ribbon-track {
  display: flex;
  align-items: flex-end;
  gap: var(--gap);
  transform: translateX(calc(var(--active) * -1 * (var(--card-w) + var(--gap))));
  transition: transform 0.6s var(--ease-out);
}
/* height/flex-basis: 8 cards, user-triggered only, not scroll-linked */
#home .projects .ribbon-track .project {
  flex: 0 0 var(--card-w);
  display: block;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--blue-dark);
  transition: flex-basis 0.6s var(--ease-out);
  cursor: pointer;
}
#home .projects .ribbon-track .project.active { flex-basis: var(--card-active-w); }
#home .projects .ribbon-track .project figure {
  height: 11rem;
  overflow: hidden;
  transition: height 0.6s var(--ease-out);
}
#home .projects .ribbon-track .project.active figure { height: 16rem; }
#home .projects .ribbon-track .project img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: grayscale(60%);
  transition: filter 0.6s;
}
#home .projects .ribbon-track .project.active img { filter: none; }
#home .projects .ribbon-track .project p {
  padding: 1rem;
  min-height: 5rem;
  color: var(--text-on-dark);
  font-family: var(--font-heading);
  font-weight: 600;
}
#home .projects .ribbon-track .project:focus-visible {
  outline: 2px solid var(--text-on-dark);
  outline-offset: 3px;
}
/* Dots keep the theme's look (it scoped them under .projects_carousel). */
#home .projects .projects_ribbon .dots {
  display: flex;
  justify-content: center;
  gap: 3px;
  margin: 2rem 0 0 calc(-1 * (50% - var(--card-active-w) / 2));
}
#home .projects .projects_ribbon .dots .dot {
  width: 5px;
  height: 5px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: var(--line-dark);
  opacity: 0.7;
  cursor: pointer;
  transition: all 0.5s;
}
#home .projects .projects_ribbon .dots .dot.active {
  opacity: 1;
  width: 2rem;
  background: var(--accent);
}
@media (max-width: 700px) {
  #home .projects .projects_ribbon { --card-w: 55vw; --card-active-w: 80vw; }
  #home .projects .ribbon-track .project figure { height: 9rem; }
  #home .projects .ribbon-track .project.active figure { height: 12rem; }
}
@media (prefers-reduced-motion: reduce) {
  #home .projects .ribbon-track,
  #home .projects .ribbon-track .project,
  #home .projects .ribbon-track .project figure { transition: none; }
}

/* === Reveal media on inner pages (spec 4.9) === */
.reveal-media { overflow: hidden; }
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .reveal-media {
      animation: reveal-clip linear both;
      animation-timeline: view();
      animation-range: entry 0% cover 40%;
    }
    /* scale/translate, not transform, so a theme hover transform survives. */
    .reveal-media img {
      scale: 1.12;
      animation: reveal-parallax linear both;
      animation-timeline: view();
    }
  }
}
@keyframes reveal-clip { from { clip-path: inset(0 12%); } to { clip-path: inset(0 0); } }
@keyframes reveal-parallax { from { translate: 0 -6%; } to { translate: 0 6%; } }

/* === Narrow screens: keep A, B and D only (spec 9) === */
/* Measured 2026-09-28 at 390px with CPU x4: the full layer doubled the median
   frame time (7 -> 14 ms). Moving lines and the float go static here, and the
   hero card drops its blur, which is costly over a playing video. */
@media (max-width: 767px) {
  #home .about .about-line,
  #home .about .about-float { animation: none !important; }
  #home .background_video .hero-card { backdrop-filter: none; background: rgba(13, 86, 147, 0.88); }
}
