/* ==========================================================================
   CrossX motion layer — motion.css            Contract: docs/MOTION.md
   Pairs with static/js/motion.js. Consumes site.css tokens only.

   Safety model: every "before" (hidden) state below requires ALL of
     - :root.mx-ready      motion.js finished setting up without errors
     - :not(.no-reveal)    boot.js failsafe has not fired
     - screen + prefers-reduced-motion: no-preference
   so no-JS, a failed script, print and reduced motion all show content as-is.
   Only transform / opacity / clip-path are animated.
   ========================================================================== */

:root {
  --mx-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --mx-ease-in-out: cubic-bezier(0.7, 0, 0.2, 1);
  --mx-dur: 760ms;
  --mx-rise: 22px;
}

/* ---------- 0. Pre-hide above-the-fold hero copy (no flash before JS) ----
   Only until motion.js adds .mx-ready (or .mx-off on failure). If motion.js
   never runs, the 2.4s failsafe animation fades the copy in anyway. */
@media screen and (prefers-reduced-motion: no-preference) {
  :root.js:not(.mx-ready):not(.mx-off):not(.no-reveal) :is(.hero__inner, .page-hero__inner) > * {
    animation: mx-failsafe 400ms 2.4s both;
  }
}
@keyframes mx-failsafe { from { opacity: 0; } to { opacity: 1; } }

/* ---------- 1. Reveal + stagger (data-mx-item, set by motion.js) --------- */

@media screen and (prefers-reduced-motion: no-preference) {
  :root.mx-ready:not(.no-reveal) [data-mx-item]:not(.is-visible) {
    opacity: 0;
    transform: translate3d(0, var(--mx-rise), 0);
  }
  /* A block that holds a split headline only fades: the words do the rising. */
  :root.mx-ready:not(.no-reveal) [data-mx-item]:has([data-mx-split]):not(.is-visible) {
    transform: none;
  }
  :root.mx-ready [data-mx-item]:not(.mx-done) {
    transition:
      opacity var(--mx-dur) var(--mx-ease-out) var(--mx-delay, 0ms),
      transform var(--mx-dur) var(--mx-ease-out) var(--mx-delay, 0ms);
  }

  /* Crosshair marks spin in with their block. */
  :root.mx-ready .kicker::before,
  :root.mx-ready .meta-list > li::before {
    transition: transform 900ms var(--mx-ease-out) calc(var(--mx-delay, 0ms) + 140ms);
  }
  :root.mx-ready:not(.no-reveal) [data-mx-item]:not(.is-visible) .kicker::before,
  :root.mx-ready:not(.no-reveal) .kicker[data-mx-item]:not(.is-visible)::before,
  :root.mx-ready:not(.no-reveal) .meta-list > [data-mx-item]:not(.is-visible)::before {
    transform: rotate(-135deg) scale(0.2);
  }
}

/* ---------- 2. Split headlines (data-mx-split) --------------------------- */

@media screen and (prefers-reduced-motion: no-preference) {
  /* clip-path (not overflow) masks each word: no effect on layout or baseline. */
  .mx-w {
    display: inline-block;
    clip-path: inset(-0.3em -0.25em -0.32em -0.25em);
  }
  .mx-wi {
    display: inline-block;
    transform-origin: 0 100%;
    transition: transform 1000ms var(--mx-ease-out)
      calc(var(--mx-delay, 0ms) + var(--mx-l, 0) * 110ms + var(--mx-wl, 0) * 36ms);
  }
  :root.mx-ready:not(.no-reveal) [data-mx-split]:not(.is-visible) .mx-wi {
    transform: translate3d(0, 140%, 0) rotate(5deg);
  }
  [data-mx-split].mx-done .mx-w { clip-path: none; }
}

/* ---------- 3. Draw: the X signature ------------------------------------- */

/* 3a. x-divider: static without JS, draws in with it. Decorative only. */
[data-motion~="x-divider"] {
  --mx-xd-gap: 26px;
  position: relative;
  display: block;
  width: min(100% - 2 * var(--cx-gutter), var(--cx-max));
  height: 44px;
  margin: clamp(8px, 2vw, 24px) auto;
  color: var(--cx-accent);
  background: linear-gradient(90deg,
      transparent,
      var(--cx-line) 18%,
      var(--cx-line) calc(50% - var(--mx-xd-gap)),
      transparent calc(50% - var(--mx-xd-gap)),
      transparent calc(50% + var(--mx-xd-gap)),
      var(--cx-line) calc(50% + var(--mx-xd-gap)),
      var(--cx-line) 82%,
      transparent) center / 100% 1px no-repeat;
}
.container [data-motion~="x-divider"],
[data-motion~="x-divider"].container { width: auto; }
[data-motion~="x-divider"]::before,
[data-motion~="x-divider"]::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 30px;
  height: 2px;
  margin: -1px 0 0 -15px;
  background: var(--cx-ink-muted);
  transform: rotate(45deg);
}
[data-motion~="x-divider"]::after { background: currentColor; transform: rotate(-45deg); }

@media screen and (prefers-reduced-motion: no-preference) {
  :root.mx-ready [data-motion~="x-divider"] {
    transition: clip-path 1200ms var(--mx-ease-in-out) calc(var(--mx-delay, 0ms) + 420ms);
  }
  :root.mx-ready [data-motion~="x-divider"]::before,
  :root.mx-ready [data-motion~="x-divider"]::after {
    transition: transform 700ms var(--mx-ease-out) var(--mx-delay, 0ms);
  }
  :root.mx-ready [data-motion~="x-divider"]::after { transition-delay: calc(var(--mx-delay, 0ms) + 170ms); }
  :root.mx-ready:not(.no-reveal) [data-motion~="x-divider"]:not(.is-visible) {
    clip-path: inset(0 calc(50% - 24px));
  }
  :root.mx-ready:not(.no-reveal) [data-motion~="x-divider"]:not(.is-visible)::before { transform: rotate(45deg) scaleX(0); }
  :root.mx-ready:not(.no-reveal) [data-motion~="x-divider"]:not(.is-visible)::after { transform: rotate(-45deg) scaleX(0); }

  /* 3b. Sub-page hero crossing strokes (site.css .page-hero::before/::after):
         wiped along their length with clip-path, so site.css keeps the angle. */
  :root.mx-ready .page-hero[data-mx-draw]::before,
  :root.mx-ready .page-hero[data-mx-draw]::after {
    transition: clip-path 1200ms var(--mx-ease-in-out) calc(var(--mx-delay, 0ms) + 250ms);
  }
  :root.mx-ready .page-hero[data-mx-draw]::after { transition-delay: calc(var(--mx-delay, 0ms) + 560ms); }
  :root.mx-ready:not(.no-reveal) .page-hero[data-mx-draw]:not(.is-visible)::before { clip-path: inset(0 100% 0 0); }
  :root.mx-ready:not(.no-reveal) .page-hero[data-mx-draw]:not(.is-visible)::after { clip-path: inset(0 0 0 100%); }

  /* 3c. Service-card corner X: strokes grow out of the crossing point. */
  :root.mx-ready .service-card[data-mx-draw]::before,
  :root.mx-ready .service-card[data-mx-draw]::after {
    transition:
      background-color 220ms,
      transform 300ms var(--cx-ease),
      clip-path 800ms var(--mx-ease-out) calc(var(--mx-delay, 0ms) + 320ms);
  }
  :root.mx-ready:not(.no-reveal) .service-card[data-mx-draw]:not(.is-visible)::before,
  :root.mx-ready:not(.no-reveal) .service-card[data-mx-draw]:not(.is-visible)::after {
    clip-path: inset(0 50%);
  }

  /* 3d. Crosshair registration marks spin in. */
  :root.mx-ready .crosshair[data-mx-draw] {
    transition:
      transform 1000ms var(--mx-ease-out) calc(var(--mx-delay, 0ms) + 380ms),
      opacity 500ms linear calc(var(--mx-delay, 0ms) + 380ms);
  }
  :root.mx-ready:not(.no-reveal) .crosshair[data-mx-draw]:not(.is-visible) {
    opacity: 0;
    transform: rotate(-180deg) scale(0);
  }

  /* 3e. Generic: SVG strokes (stroke-dashoffset) or a left-to-right wipe. */
  :root.mx-ready .mx-stroke {
    stroke-dasharray: var(--mx-dash);
    transition: stroke-dashoffset 1100ms var(--mx-ease-in-out)
      calc(var(--mx-delay, 0ms) + var(--mx-si, 0) * 150ms);
  }
  :root.mx-ready:not(.no-reveal) [data-mx-draw]:not(.is-visible) .mx-stroke {
    stroke-dashoffset: var(--mx-off);
  }
  :root.mx-ready .mx-draw-wipe {
    transition: clip-path 1000ms var(--mx-ease-in-out) var(--mx-delay, 0ms);
  }
  :root.mx-ready:not(.no-reveal) .mx-draw-wipe:not(.is-visible) {
    clip-path: inset(0 100% 0 0);
  }
}

/* ---------- 4. Parallax --------------------------------------------------- */

/* Host with content: motion.js prepends a layer that inherits the host's
   whole background stack, and moves that instead of the content. */
.mx-parallax-host { isolation: isolate; overflow: hidden; }
.mx-parallax-host.mx-rel { position: relative; }
.mx-parallax-layer {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: inherit;
}

@media screen and (prefers-reduced-motion: no-preference) {
  :root.mx-ready .mx-parallax {
    transform: translate3d(0, var(--mx-py, 0%), 0) scale(var(--mx-scale, 1.14));
    will-change: transform;
  }
  @supports (animation-timeline: view()) {
    :root.mx-ready .mx-parallax {
      animation: mx-parallax linear both;
      animation-timeline: view();
      animation-range: cover 0% cover 100%;
    }
  }
}
@keyframes mx-parallax {
  from { transform: translate3d(0, calc(-1 * var(--mx-depth, 6%)), 0) scale(var(--mx-scale, 1.14)); }
  to   { transform: translate3d(0, var(--mx-depth, 6%), 0) scale(var(--mx-scale, 1.14)); }
}

/* ---------- 5. Marquee ---------------------------------------------------- */

/* Before motion.js wraps it: one line, still scrollable, same height. */
@media screen and (prefers-reduced-motion: no-preference) {
  :root.js:not(.mx-off) [data-motion~="marquee"]:not(.mx-marquee__group) {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
}
.mx-marquee { position: relative; }
.mx-marquee__viewport {
  overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 7%, #000 93%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 7%, #000 93%, transparent);
}
.mx-marquee__track { display: flex; width: max-content; }
.mx-marquee__group {
  display: flex;
  flex: none;
  flex-wrap: nowrap;
  margin: 0;
  padding-inline-end: var(--mx-marquee-gap, var(--cx-space-2));
  animation: mx-marquee var(--mx-marquee-dur, 40s) linear infinite;
}
.mx-marquee--reverse .mx-marquee__group { animation-direction: reverse; }
.mx-marquee:hover .mx-marquee__group,
.mx-marquee:focus-within .mx-marquee__group,
.mx-marquee.is-paused .mx-marquee__group,
.mx-marquee.is-offscreen .mx-marquee__group,
:root.mx-hidden .mx-marquee__group { animation-play-state: paused; }
@keyframes mx-marquee { to { transform: translate3d(-100%, 0, 0); } }

.mx-marquee__toggle {
  position: absolute;
  top: 50%;
  right: 0;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-top: -15px;
  padding: 0;
  border: 1px solid var(--cx-line);
  border-radius: 6px;
  background: var(--cx-surface);
  color: var(--cx-ink);
  cursor: pointer;
}
.mx-marquee__toggle:hover { border-color: var(--cx-accent); color: var(--cx-accent); }
/* pause glyph (two bars) / play glyph (triangle) */
.mx-marquee__toggle::before {
  content: "";
  width: 10px;
  height: 11px;
  background:
    linear-gradient(currentColor, currentColor) left / 3px 100% no-repeat,
    linear-gradient(currentColor, currentColor) right / 3px 100% no-repeat;
}
.mx-marquee__toggle[aria-pressed="true"]::before {
  background: currentColor;
  clip-path: polygon(10% 0, 100% 50%, 10% 100%);
}
@media (prefers-reduced-motion: reduce) {
  .mx-marquee__group { animation: none; }
  .mx-marquee__toggle { display: none; }
}


.mx-magnetic { translate: var(--mx-mx, 0px) var(--mx-my, 0px); }

.mx-tilt-host { perspective: 1100px; }
.mx-tilt {
  isolation: isolate;
  rotate: var(--mx-ax, 0) var(--mx-ay, 1) 0 var(--mx-ang, 0deg);
}
.mx-spot {
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  transition: opacity 400ms var(--mx-ease-out);
  background:
    radial-gradient(280px circle at var(--mx-sx, 50%) var(--mx-sy, 50%),
      color-mix(in srgb, var(--cx-accent) 15%, transparent),
      color-mix(in srgb, var(--cx-accent-2) 5%, transparent) 45%,
      transparent 72%);
}
.mx-tilt.is-tilting .mx-spot { opacity: 1; }

@media (pointer: coarse), (prefers-reduced-motion: reduce) {
  }

/* ---------- 7. Header: scroll progress + condensed state ------------------ */

.mx-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  pointer-events: none;
  background: linear-gradient(90deg, var(--cx-accent), color-mix(in srgb, var(--cx-accent) 70%, #ffd2b8));
  transform-origin: 0 50%;
  transform: scaleX(var(--mx-progress, 0));
}
@supports (animation-timeline: scroll()) {
  @media (prefers-reduced-motion: no-preference) {
    .mx-progress.mx-sda {
      animation: mx-progress linear both;
      animation-timeline: scroll(root block);
    }
  }
}
@keyframes mx-progress { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.site-header { transition: box-shadow 300ms linear, background-color 300ms linear; }
.site-header.is-condensed {
  background: color-mix(in srgb, var(--cx-bg) 78%, transparent);
  box-shadow: 0 14px 34px -24px rgb(0 0 0 / 0.55);
}
.site-header .logo-mark { transition: transform 700ms var(--mx-ease-out); }
/* The mark turns a quarter: ink and accent strokes swap diagonals. */
.site-header.is-condensed .logo-mark { transform: rotate(90deg); }

/* ---------- 8. Counters --------------------------------------------------- */

[data-count-to],
.mx-count { font-variant-numeric: tabular-nums; }
.mx-count { display: inline-block; }

/* ---------- 9. Page transitions (View Transitions API) -------------------- */

@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }

  /* The header is identical on every page: keep it out of the wipe. */
  .site-header { view-transition-name: cx-header; }

  ::view-transition-old(root) {
    animation: mx-vt-out 640ms var(--mx-ease-in-out) both;
  }
  ::view-transition-new(root) {
    animation: mx-vt-in 640ms var(--mx-ease-in-out) both;
  }
}
@keyframes mx-vt-out {
  to { opacity: 0.4; transform: scale(0.985); }
}
/* New page arrives through an "X": hairline strokes shoot out from the
   centre, then the crossing widens until it covers the viewport. */
@keyframes mx-vt-in {
  0% {
    clip-path: polygon(50% 49.65%, 50% 49.65%, 50% 50.35%, 50.35% 50%, 50% 49.65%, 50% 50.35%, 50% 50.35%, 50% 50.35%, 50% 49.65%, 49.65% 50%, 50% 50.35%, 50% 49.65%);
  }
  36% {
    clip-path: polygon(50% 49.65%, 130% -30.35%, 130% -29.65%, 50.35% 50%, 130% 129.65%, 130% 130.35%, 50% 50.35%, -30% 130.35%, -30% 129.65%, 49.65% 50%, -30% -29.65%, -30% -30.35%);
  }
  100% {
    clip-path: polygon(50% -12%, 130% -92%, 130% 32%, 112% 50%, 130% 68%, 130% 192%, 50% 112%, -30% 192%, -30% 68%, -12% 50%, -30% 32%, -30% -92%);
  }
}

/* ---------- 10. Print ------------------------------------------------------ */

@media print {
  .mx-progress, }
