/* Motion layer: Motion A "Precise", trimmed (claude/build/SSG-Motion-Spec-for-Build.md).
   Every movement has a job: feedback, orientation or sequence. Nothing loops.
   Refined Nov 16: one easing family, entrances that play once on time (never tied to scroll position),
   underlines that draw in from the left and leave to the right, and a soft cross-fade between pages.
   The whole layer is switched on by html.motion (set in <head>) and is off under prefers-reduced-motion.
   Remove the class to turn motion off entirely. */

:root {
  --ease-out: cubic-bezier(.16, 1, .3, 1);   /* arrivals */
  --ease-io: cubic-bezier(.65, 0, .35, 1);   /* wipes, state swaps */
  --t-fast: 160ms;
  --t-mid: 320ms;
  --t-slow: 640ms;
}

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

  /* ---------- Feedback: buttons ----------
     Immediate and precise: the color answers the cursor in 120ms, the press
     answers the finger in 80ms. No wipe, no lag, no sticky hover on touch. */
  .motion .btn {
    transition: background-color 120ms var(--ease-out), color 120ms var(--ease-out),
                box-shadow 120ms var(--ease-out), transform 240ms var(--ease-out);
  }
  .motion .btn:active { transform: scale(.97); background-color: var(--btn-press); transition-duration: 60ms; }

  /* Primary (red) buttons: the label rolls up and a fresh copy rises in from below.
     The copy is a text-shadow, so screen readers hear the label once. */
  .motion .btn__roll { display: block; overflow: hidden; line-height: 1.3; }
  .motion .btn__label {
    display: block; text-shadow: 0 1.3em currentColor;
    transition: transform 280ms var(--ease-out);
  }
  /* Call buttons: the phone tips once when the pointer arrives (a nod, not a shake). Plays once, never loops. */
  @keyframes phone-ring { 0% { transform: rotate(0); } 35% { transform: rotate(-10deg); } 70% { transform: rotate(4deg); } 100% { transform: rotate(0); } }
  @media (hover: hover) and (pointer: fine) {
    .motion .btn:hover img { animation: phone-ring 480ms var(--ease-io) 1; }
  }
  @media (hover: hover) and (pointer: fine) {
    .motion .btn:hover .btn__label, .motion .btn:focus-visible .btn__label { transform: translateY(-1.3em); }
  }

  /* ---------- Feedback: arrow links (underline draws toward the arrow, arrow nudges 4px) ---------- */
  .motion .arrow-link { position: relative; }
  .motion .arrow-link .arrow { transition: transform var(--t-mid) var(--ease-out); }
  .motion .arrow-link .txt { background: linear-gradient(currentColor, currentColor) right bottom / 0 1.5px no-repeat; transition: background-size var(--t-mid) var(--ease-io); padding-bottom: 1px; }
  .motion .arrow-link:hover .arrow { transform: translateX(4px); }
  .motion .arrow-link:hover .txt { background-size: 100% 1.5px; background-position: left bottom; }
  @media (hover: hover) and (pointer: fine) { .motion .fork:hover .arrow { transform: translateX(4px); } .motion .fork:hover .fork__link .txt { background-size: 100% 1.5px; background-position: left bottom; } }
  .motion .text-link { background: linear-gradient(currentColor, currentColor) right bottom / 0 1px no-repeat; transition: background-size var(--t-mid) var(--ease-io); }
  .motion .text-link:hover { background-size: 100% 1px; background-position: left bottom; }

  /* Every underline on the site behaves the same way: it draws in from the left and leaves to the right.
     (The line is anchored right at rest and left on hover; only its length animates.) */
  .motion .nav__links a::after { transition: transform var(--t-mid) var(--ease-io); }
  .motion .nav__links a:hover::after { transform: scaleX(1); transform-origin: left; }
  .motion .footer__col a, .motion .nav__phone, .motion .callcard__phone, .motion .area__call a, .motion .quiet a {
    background: linear-gradient(currentColor, currentColor) right bottom / 0 1px no-repeat; transition: background-size var(--t-mid) var(--ease-io);
  }
  .motion .footer__col a:hover, .motion .nav__phone:hover, .motion .area__call a:hover, .motion .quiet a:hover { background-size: 100% 1px; background-position: left bottom; }

  /* Call band phone: underline draws on hover */
  .motion .callband__phone::after { transition: transform var(--t-mid) var(--ease-io); }
  .motion .callband__phone:hover::after { transform: scaleX(1); transform-origin: left; }

  /* ---------- Feedback: fork cards ----------
     Immediate, like the buttons (Nov 14): the red top rule appears in 120ms, the arrow
     nudges, the press settles to 98%. The photo eases 3% closer over a second and eases back
     (Nov 17; slow enough to read as attention, not a zoom). Hover only on pointer devices. */
  .motion .fork__media img { transition: transform 1100ms var(--ease-out); }
  .motion .fork::before {
    content: ""; position: absolute; left: 0; right: 0; top: 0; z-index: 2; height: 3px; background: var(--red);
    opacity: 0; transition: opacity 120ms var(--ease-out);
  }
  .motion .fork:focus-within::before { opacity: 1; }
  .motion .fork { transition: transform 240ms var(--ease-out); }
  .motion .fork:active { transform: scale(.98); transition-duration: 60ms; }
  .motion .fork__arrow { transition: transform var(--t-fast) var(--ease-out); }
  @media (hover: hover) and (pointer: fine) {
    .motion .fork:hover::before { opacity: 1; }
    .motion .fork:hover .fork__arrow { transform: translateX(4px); }
    .motion .fork:hover .fork__media img { transform: scale(1.03); }
  }

  /* ---------- Feedback: form controls ---------- */
  .motion .input { background-repeat: no-repeat; background-position: right 14px center; background-size: 0 0;
    transition: border-color var(--t-fast) var(--ease-out), box-shadow var(--t-fast) var(--ease-out), background-size 360ms var(--ease-out); }
  .motion .input.is-valid { background-size: 18px 18px; }
  /* Touch: plain icons and menu rows dim under the finger and recover */
  .motion .icon-btn, .motion .stickybar__action, .motion .mmenu__links a { transition: opacity 240ms var(--ease-out); }
  .motion .icon-btn:active, .motion .stickybar__action:active, .motion .mmenu__links a:active { transition-duration: 0ms; }
  .motion .starter__field { transition: box-shadow var(--t-mid) var(--ease-out); }
  .motion .segmented__thumb { transition: transform 280ms var(--ease-out); }
  .motion .segmented label { transition: color 200ms var(--ease-io); }
  .motion .field__error, .motion .starter__error { animation: msg-in var(--t-mid) var(--ease-out); }
  .motion .is-valid::after { animation: check-in var(--t-mid) var(--ease-out); }
  .motion .round-btn { transition: background-color var(--t-fast), color var(--t-fast), transform var(--t-fast) var(--ease-out); }
  .motion .round-btn:not([disabled]):hover { background: var(--ink); color: var(--white); }
  .motion .round-btn:not([disabled]):active { transform: scale(.94); }

  /* Optional fields open with a short rise */
  .motion .form-extra:not([hidden]) { animation: rise 420ms var(--ease-out) both; }

  /* Submit: the label rolls up to "Sending…" (same roll as the hover, one step further), a progress rule
     runs along the bottom, then the form fades out and the confirmation rises in with a drawn check. */
  .motion .btn__label { position: relative; }
  .motion .btn__label::after { content: attr(data-busy); position: absolute; left: 0; right: 0; top: 2.6em; text-align: center; text-shadow: none; }
  .motion .is-sending .btn .btn__label { transform: translateY(-2.6em); transition-duration: 360ms; }
  .motion form.is-leaving { animation: fade-out 160ms var(--ease-io) both; pointer-events: none; }
  .motion .form-success:not([hidden]) > :nth-child(2) { animation: rise 560ms 120ms var(--ease-out) both; }
  .motion .form-success:not([hidden]) > :nth-child(n+3) { animation: rise 560ms 200ms var(--ease-out) both; }
  .motion .is-sending .btn::after { content: ""; position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: rgba(255,255,255,.7); transform-origin: left; animation: progress 1.2s var(--ease-io) infinite; }
  .motion .form-success:not([hidden]) { animation: rise var(--t-slow) var(--ease-out) both; }
  .motion .form-success__check path { stroke-dasharray: 30; stroke-dashoffset: 30; animation: draw 480ms 200ms var(--ease-out) forwards; }

  /* Hero ZIP starter: the answer arrives as a reply, not a swap.
     The ZIP step fades out (140ms); the answer line ("Yes, we cover Marietta.") rises in first,
     then the fields follow 50ms apart, and the small print below settles last. About 0.7s in all.
     The name field has focus from the first frame, so typing is never held up. */
  .motion .starter [data-step].is-leaving { opacity: 0; transition: opacity 140ms var(--ease-io); pointer-events: none; }
  .motion .starter [data-step].is-entering > .starter__label,
  .motion .starter [data-step].is-entering > .hero__sub { animation: rise 560ms var(--ease-out) both; }
  .motion .starter [data-step].is-entering > .starter__form,
  .motion .starter [data-step].is-entering .starter__step2 > * { animation: answer-in 520ms var(--ease-out) both; animation-delay: 110ms; }
  .motion .starter [data-step].is-entering .starter__step2 > :nth-child(2) { animation-delay: 160ms; }
  .motion .starter [data-step].is-entering .starter__step2 > :nth-child(3) { animation-delay: 210ms; }
  .motion .starter [data-step].is-entering .starter__step2 > :nth-child(4) { animation-delay: 260ms; }
  .motion .starter [data-step].is-entering .starter__step2 > :nth-child(5) { animation-delay: 310ms; }
  .motion .starter [data-step].is-entering ~ [data-quiet] { animation: fade-in 480ms 260ms var(--ease-out) both; }

  /* ZIP result replaces copy in place */
  .motion .zip-result:not([hidden]) { animation: rise var(--t-mid) var(--ease-out) both; }

  /* ---------- Orientation: header compresses after the hero (92 → 72) ---------- */
  .motion .nav { transition: height var(--t-mid) var(--ease-out); }
  .motion .site-header.is-compact .nav { height: 72px; }
  .motion .site-header { transition: box-shadow var(--t-mid) var(--ease-out); }
  .motion .site-header.is-compact { box-shadow: 0 1px 0 rgba(255,255,255,.08); }

  /* Mobile menu: icon morphs to ×; the panel fades in and its items rise in a short stagger
     (links 40ms apart, then the buttons, then the note; done in about half a second). Closes with a 160ms fade. */
  .motion .menu-icon span { transition: transform 220ms var(--ease-io), top 220ms var(--ease-io), opacity 120ms; }
  .motion .mmenu { animation: fade-in 200ms var(--ease-out); }
  .motion .mmenu.is-closing { animation: fade-out 160ms var(--ease-io) both; pointer-events: none; }
  .motion .mmenu__links li,
  .motion .mmenu__actions > *,
  .motion .mmenu__note { animation: menu-up 320ms var(--ease-out) both; }
  .motion .mmenu__links li:nth-child(1) { animation-delay: 40ms; }
  .motion .mmenu__links li:nth-child(2) { animation-delay: 80ms; }
  .motion .mmenu__links li:nth-child(3) { animation-delay: 120ms; }
  .motion .mmenu__links li:nth-child(4) { animation-delay: 160ms; }
  .motion .mmenu__links li:nth-child(5) { animation-delay: 200ms; }
  .motion .mmenu__links li:nth-child(6) { animation-delay: 240ms; }
  .motion .mmenu__links li:nth-child(7) { animation-delay: 280ms; }
  .motion .mmenu__actions > :nth-child(1) { animation-delay: 320ms; }
  .motion .mmenu__actions > :nth-child(2) { animation-delay: 360ms; }
  .motion .mmenu__actions > :nth-child(3) { animation-delay: 400ms; }
  .motion .mmenu__note { animation-delay: 440ms; }

  /* Logo bar on phones and tablets: a slow, continuous scroll (approved by John McHale, Nov 14, as the one
     exception to "nothing loops"). The list is doubled by site.js and moves half its width, so the loop
     has no seam. Pauses while touched, hovered or focused. Desktop keeps the static row. */
  @media (max-width: 1023px) {
    .motion .logobar__viewport:has(.is-marquee) { overflow: hidden; }
    .motion .logobar__viewport:has(.is-marquee)::before { content: ""; position: absolute; z-index: 1; top: 0; left: 0; bottom: 0; width: 40px; background: linear-gradient(270deg, rgba(255,255,255,0), var(--surface, var(--white))); pointer-events: none; }
    .motion .logobar__viewport:has(.is-marquee)::after { z-index: 1; width: 40px; }
    .motion .logobar__list.is-marquee { width: max-content; overflow: visible; scroll-snap-type: none; padding-right: 40px; animation: logo-marquee 36s linear infinite; }
    .motion .logobar__viewport:hover .is-marquee, .motion .logobar__viewport:focus-within .is-marquee, .motion .logobar__viewport:active .is-marquee { animation-play-state: paused; }
  }
  @keyframes logo-marquee { from { transform: translateX(0); } to { transform: translateX(-50%); } }

  /* Sticky action bar slides in once the hero CTAs leave the screen */
  .motion .stickybar { transition: transform 240ms var(--ease-io), visibility 0s linear 240ms; }
  .motion .stickybar.is-visible { transition: transform 420ms var(--ease-out), visibility 0s; }

  /* FAQ: open to height, + folds to − */
  .motion .faq__a { transition: height 420ms var(--ease-out); }
  .motion .faq__a p { transition: opacity var(--t-mid) var(--ease-out), transform var(--t-mid) var(--ease-out); }
  .motion .faq__item:not(.is-open) .faq__a p { opacity: 0; transform: translateY(-4px); }
  .motion .faq__icon::after { transition: transform 320ms var(--ease-out); }
  .motion .faq__item { transition: border-color var(--t-fast) var(--ease-out); }
  @media (hover: hover) and (pointer: fine) { .motion .faq__item:hover { border-top-color: var(--ink); } }

  /* ---------- Orientation: hero load (one orchestrated moment, about 1s; the same on every page) ---------- */
  .motion .hero__title .w, .motion .phero__title .w { display: inline-block; overflow: hidden; vertical-align: top; padding-bottom: .06em; margin-bottom: -.06em; }
  .motion .hero__title .w > span, .motion .phero__title .w > span { display: inline-block; animation: word-up 800ms var(--ease-out) both; animation-delay: calc(60ms + var(--i, 0) * 45ms); }
  .motion .hero__sub { animation: rise 640ms 320ms var(--ease-out) both; }
  .motion .starter { animation: rise 640ms 440ms var(--ease-out) both; }
  .motion .hero__john { animation: john-in 900ms 120ms var(--ease-out) both; }
  .motion .hero__glow { animation: fade-in 1200ms var(--ease-out) both; }
  .motion .nametag { animation: tag-in 560ms 620ms var(--ease-out) both; }
  .motion .hero__rule { animation: rule-in 640ms 520ms var(--ease-io) both; transform-origin: left; }

  /* ---------- Hierarchy: section headlines and card rows rise in ----------
     Triggered once when the element enters view, then played on time (site.js adds .in-view).
     Not tied to scroll position, so nothing is ever left half faded. Cards in a row follow 70ms apart.
     html.reveal-on is set in <head> only when the browser can run it; without it the page is simply complete. */
  .motion.reveal-on .reveal, .motion.reveal-on .reveal-group > * {
    opacity: 0; transform: translateY(20px);
    transition: opacity 700ms var(--ease-out), transform 900ms var(--ease-out);
  }
  .motion.reveal-on .reveal-group > *:nth-child(2) { transition-delay: 70ms; }
  .motion.reveal-on .reveal-group > *:nth-child(3) { transition-delay: 140ms; }
  .motion.reveal-on .reveal-group > *:nth-child(4) { transition-delay: 210ms; }
  .motion.reveal-on .reveal-group > *:nth-child(n+5) { transition-delay: 280ms; }
  .motion.reveal-on .in-view.reveal, .motion.reveal-on .in-view.reveal-group > * { opacity: 1; transform: none; }
  /* Already above the screen (deep link, back button): show without animating */
  .motion.reveal-on .is-past.reveal, .motion.reveal-on .is-past.reveal-group > * { transition: none; }

  /* Steps: when the row comes into view, play once 1 → 2 → 3 (badge turns on, then its line fills),
     then stay complete (about 1.3s, tightened Nov 17). Time-based, not scroll-linked, so the lines never stop half drawn. */
  .motion .step__badge { transition: background-color 240ms var(--ease-out), color 240ms var(--ease-out); }
  .motion .step__line::after { transition: transform 420ms var(--ease-io); }
  .motion .steps.in-view .step__badge { background-color: var(--ink); color: var(--white); }
  .motion .steps.in-view .step__line::after { transform: none; }
  .motion .steps.in-view .step:nth-child(1) .step__line::after { transition-delay: 100ms; }
  .motion .steps.in-view .step:nth-child(2) .step__badge { transition-delay: 400ms; }
  .motion .steps.in-view .step:nth-child(2) .step__line::after { transition-delay: 500ms; }
  .motion .steps.in-view .step:nth-child(3) .step__badge { transition-delay: 800ms; }
  .motion .steps.in-view .step:nth-child(3) .step__line::after { transition-delay: 900ms; }

  /* ---------- Orientation: moving between pages ----------
     A short cross-fade instead of a hard cut (Chrome, Edge, Safari 18.2+; other browsers load as usual).
     The header is held in place so only the page beneath it changes. */
  @view-transition { navigation: auto; }
  .site-header { view-transition-name: site-header; }
  ::view-transition-old(root) { animation: fade-out 140ms var(--ease-io) both; }
  ::view-transition-new(root) { animation: fade-in 260ms var(--ease-out) both; }
  ::view-transition-group(site-header) { animation-duration: 260ms; animation-timing-function: var(--ease-out); }
}

@keyframes word-up { from { transform: translateY(105%); } to { transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes menu-up { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes john-in { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
@keyframes tag-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes rule-in { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes fill-x { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes fill-y { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes badge-on { from { background-color: var(--paper-2); color: var(--grey-text); } to { background-color: var(--ink); color: var(--white); } }
@keyframes answer-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes msg-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes check-in { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: none; } }
@keyframes progress { 0% { transform: scaleX(0); } 60% { transform: scaleX(1); opacity: 1; } 100% { transform: scaleX(1); opacity: 0; } }
@keyframes draw { to { stroke-dashoffset: 0; } }

/* Mobile nametag is centered with a transform; keep it centered while it animates */
@media (max-width: 1023px) {
  @keyframes tag-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
}

/* Thank-you check draws in once (400ms) */
@media (prefers-reduced-motion: no-preference) {
  .motion .ty__tick { stroke-dasharray: 40; stroke-dashoffset: 40; animation: ty-draw 400ms var(--ease-out) 200ms forwards; }
  @keyframes ty-draw { to { stroke-dashoffset: 0; } }
}
