/* ==========================================================================
   Franco's Construction — Motion
   CSS-first: scroll-driven animations + cross-page View Transitions.
   Progressive enhancement: browsers without support just show the finished
   page (js/motion.js adds a small IntersectionObserver fallback for reveals).
   Everything that starts hidden lives inside the no-preference media query,
   so reduced-motion visitors always see the final state.
   Only opacity / transform / clip-path are animated (compositor-friendly).
   ========================================================================== */

/* Trust-strip counters count up while the strip scrolls into view */
@property --n { syntax: "<integer>"; inherits: false; initial-value: 0; }

/* Cross-document page transitions (Chrome/Edge/Safari recent; others navigate normally) */
@view-transition { navigation: auto; }

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
}

@media (prefers-reduced-motion: no-preference) {

  html { scroll-behavior: smooth; }

  /* ---------- Page transitions ---------- */
  ::view-transition-old(root) { animation: fc-vt-out 0.24s var(--ease) both; }
  ::view-transition-new(root) { animation: fc-vt-in 0.36s var(--ease) both; }
  .site-header { view-transition-name: site-header; }
  .action-bar { view-transition-name: action-bar; }
  .floating-cta { view-transition-name: floating-cta; }

  /* ---------- Framed photos: oversized so they can drift; zoom a touch more on hover ---------- */
  .parallax-frame img { --par: 6%; scale: 1.14; transition: scale 0.7s var(--ease); }
  /* Triggered from anywhere on the photo: mouse hover (any-hover also covers hybrid/touch laptops),
     a tap (JS toggles .is-active on touch), keyboard focus, or the moment of pressing. */
  @media (any-hover: hover) {
    .portfolio-item:hover .parallax-frame img,
    .about-media:hover .parallax-frame img { scale: 1.22; }
  }
  .portfolio-item.is-active .parallax-frame img,
  .about-media.is-active .parallax-frame img,
  .portfolio-item:focus-visible .parallax-frame img,
  .about-media:focus-visible .parallax-frame img { scale: 1.22; }
  .portfolio-item:active .parallax-frame img,
  .about-media:active .parallax-frame img { scale: 1.19; transition-duration: 0.15s; }

  /* ---------- Services list: rows shift and light up on hover / tap / focus ---------- */
  .service-num, .service-row h3, .service-row p { transition: translate 0.5s var(--ease), color 0.4s var(--ease); }
  .service-item:hover .service-num, .service-item.is-active .service-num,
  .service-item:focus-within .service-num, .service-item:active .service-num { translate: 6px 0; color: var(--color-primary); }
  .service-item:hover .service-row h3, .service-item.is-active .service-row h3,
  .service-item:focus-within .service-row h3, .service-item:active .service-row h3 { translate: 16px 0; }
  .service-item:hover .service-row p, .service-item.is-active .service-row p,
  .service-item:focus-within .service-row p, .service-item:active .service-row p { translate: 8px 0; color: var(--color-ink); }

  /* ---------- Hero: load sequence ---------- */
  .hero-photo { transform: scale(1.08); animation: fc-hero-zoom 2.4s var(--ease) forwards; }
  /* On wide screens the poster hands over to the video, so it must not zoom on its own */
  @media (min-width: 781px) { .hero-photo { transform: none; animation: none; } }
  .hero .eyebrow,
  .hero h1 .line,
  .hero-sub,
  .hero-ctas {
    opacity: 0;
    transform: translateY(26px);
    animation: fc-rise 0.9s var(--ease) forwards;
  }
  .hero .eyebrow { animation-delay: 0.2s; }
  .hero h1 .line:nth-child(1) { animation-delay: 0.34s; }
  .hero h1 .line:nth-child(2) { animation-delay: 0.46s; }
  .hero h1 .line:nth-child(3) { animation-delay: 0.58s; }
  .hero-sub { animation-delay: 0.8s; }
  .hero-ctas { animation-delay: 0.95s; }
  .hero-cue i { animation: fc-cue 2.2s ease-in-out infinite; }

  /* ---------- Scroll-driven (native) ---------- */
  @supports (animation-timeline: view()) {
    /* Blocks rise + fade in as they enter; --i staggers siblings */
    [data-reveal] {
      animation: fc-reveal linear both;
      animation-timeline: view();
      animation-range: entry calc(var(--i, 0) * 5%) entry calc(40% + var(--i, 0) * 5%);
    }
    /* Portfolio photos unveil with a clip-path wipe */
    .reveal-clip {
      animation: fc-clip linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 55%;
    }
    /* Subtle parallax inside a framed photo */
    /* The frame has overflow:hidden (so it is a scroll container); a bare view() would bind to it
       and never move. Name the frame's own timeline instead so it tracks the page scroll. */
    .parallax-frame { view-timeline: --frame block; }
    .parallax-frame img {
      animation: fc-parallax linear both;
      animation-timeline: --frame;
    }
    /* Hero photo drifts and scales slowly as the page scrolls away */
    .hero-media {
      animation: fc-hero-parallax linear both;
      animation-timeline: scroll(root);
      animation-range: 0 100svh;
    }
    /* Services: each row draws its hairline, then number, title and description slide in */
    .service-item { view-timeline: --row block; }
    .service-item[data-reveal] { animation: none; }
    .service-row::before { animation: fc-draw linear both; animation-timeline: --row; animation-range: entry 0% entry 55%; }
    .service-num { animation: fc-slide-in linear both; animation-timeline: --row; animation-range: entry 5% entry 45%; }
    .service-row h3 { animation: fc-slide-in linear both; animation-timeline: --row; animation-range: entry 10% entry 60%; }
    .service-row p { animation: fc-slide-in linear both; animation-timeline: --row; animation-range: entry 20% entry 75%; }
    /* Trust strip: numbers count up as the strip enters; the text stays for assistive tech and as the fallback */
    .stat-num:not(.stat-word) {
      font-size: 0;
      counter-reset: stat var(--n);
      counter-reset: stat round(var(--n)); /* some engines interpolate integers fractionally mid-animation */
      animation: fc-count linear both;
      animation-timeline: view();
      animation-range: entry 10% entry 90%;
    }
    .stat-num:not(.stat-word)::after { content: counter(stat); font-size: var(--stat-fs); line-height: 1; }
    .stat-num:not(.stat-word)::after { content: counter(stat) / ""; }
    /* Review cards: the centred card is full size, neighbours recede (timeline = the carousel's own scroll) */
    .review-card { animation: fc-card linear both; animation-timeline: view(inline); animation-range: entry 0% exit 100%; }
    /* Service-area map: lines reach out from Phoenix, then each city lights up in turn */
    .map-line { animation: fc-draw-line linear both; animation-timeline: view(); animation-range: entry var(--s) entry var(--e); }
    .map-pin { animation: fc-pin linear both; animation-timeline: view(); animation-range: entry var(--s) entry var(--e); transform-box: fill-box; transform-origin: center; }
    /* Gold rules draw in from the left */
    .section-heading .eyebrow::before,
    .about-copy .eyebrow::before,
    .cta-band .eyebrow::before {
      animation: fc-draw linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 90%;
    }
  }

  /* ---------- Fallback reveal (js/motion.js adds .reveal-fb when unsupported) ---------- */
  .reveal-fb [data-reveal],
  .reveal-fb .reveal-clip {
    opacity: 0;
    transform: translateY(24px);
    transition: opacity 0.8s var(--ease) calc(var(--i, 0) * 80ms), transform 0.8s var(--ease) calc(var(--i, 0) * 80ms);
  }
  .reveal-fb [data-reveal].is-in,
  .reveal-fb .reveal-clip.is-in { opacity: 1; transform: none; }

  .reveal-fb .service-row::before { transform: scaleX(0); transition: transform 0.9s var(--ease); }
  .reveal-fb .service-item.is-in .service-row::before { transform: none; }

  /* ---------- Keyframes ---------- */
  @keyframes fc-slide-in {
    from { opacity: 0; transform: translateX(-28px); }
    to { opacity: 1; transform: none; }
  }
  @keyframes fc-vt-out { to { opacity: 0; } }
  @keyframes fc-vt-in { from { opacity: 0; } }
  @keyframes fc-hero-zoom { to { transform: scale(1); } }
  @keyframes fc-rise { to { opacity: 1; transform: none; } }
  @keyframes fc-cue {
    0% { transform: scaleY(0); }
    50% { transform: scaleY(1); }
    100% { transform: scaleY(1); opacity: 0; }
  }
  @keyframes fc-reveal {
    from { opacity: 0; transform: translateY(24px); }
    to { opacity: 1; transform: none; }
  }
  @keyframes fc-clip {
    from { clip-path: inset(0 0 100% 0); }
    to { clip-path: inset(0 0 0 0); }
  }
  /* `translate` (not `transform`) so it composes with the hover `scale` */
  @keyframes fc-parallax {
    from { translate: 0 calc(var(--par) * -1); }
    to { translate: 0 var(--par); }
  }
  /* Zoom only (no translate): the media fills the hero exactly, so the video is never over-stretched */
  @keyframes fc-hero-parallax {
    from { transform: scale(1); }
    to { transform: scale(1.07); }
  }
  @keyframes fc-count { from { --n: 0; } to { --n: var(--to); } }
  @keyframes fc-step { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
  .contact-form.is-stepped .quiz-step.is-current { animation: fc-step 0.45s var(--ease) both; }
  @keyframes fc-card { 0% { opacity: 0.45; scale: 0.92; } 50% { opacity: 1; scale: 1; } 100% { opacity: 0.45; scale: 0.92; } }
  @keyframes fc-draw-line { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
  @keyframes fc-pin { from { opacity: 0; scale: 0.4; } to { opacity: 1; scale: 1; } }
  @keyframes fc-breathe { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
  .pin-ring { animation: fc-breathe 3.2s ease-in-out infinite; }
  @keyframes fc-draw {
    from { transform: scaleX(0); }
    to { transform: scaleX(1); }
  }

  /* Gentler on phones */
  @media (max-width: 780px) {
    .parallax-frame img { --par: 3%; }
  }
}
