/**
 * Westmark v6.0.5 — Vengeance UI effects, round 2, ported to plain CSS/JS.
 *
 * Four effects, adapted from Vengeance UI (MIT License, Copyright (c)
 * Ashutosh — https://github.com/Ashutoshx7/VengeanceUI):
 *   1. Flip Text        (components/ui/flip-text.tsx)
 *   2. Morph Text       (components/ui/morph-text.tsx)
 *   3. Line Hover Link  (components/ui/line-hover-link.tsx)
 *   4. Stagger Text     (components/ui/staggerText.tsx)
 *      + Animated Number (components/ui/animated-number.tsx) — the
 *        count-up below is the plain-JS equivalent of its count
 *        behaviour (the original rolls digit strips with Framer
 *        Motion; the theme counts 0 -> target on scroll into view).
 *
 * The originals are React + Tailwind (+ Framer Motion for 3 and 4).
 * This file is the plain-CSS half of the port; the wiring lives in
 * assets/js/vengeance-effects-2.js. No React, no Tailwind, no build
 * step, no extra libraries.
 *
 * Colours are Westmark's own: yellow #ffd400 on black.
 *
 * LESSONS from v6.0.4 (do not repeat):
 *   - Any absolutely-positioned effect layer gets its own positioned
 *     containing block on the effect class itself — never assume
 *     .service-card / .price-card is positioned. Every class below
 *     that positions a child sets position: relative on itself.
 *   - Nothing here paints over card faces or text: no z-index: -1
 *     layers inside an isolated stacking context (that washed the
 *     v6.0.4 glow cards yellow until the ring-mask fix).
 *   - All effect text stays readable and present with JS off: the
 *     CSS below only hides/moves text once JS has added the effect
 *     class, and the JS never runs under prefers-reduced-motion.
 */

/* ================================================================
   1. FLIP TEXT — hero H1 flip-in on page load
   Faithful to the registry contract: each character gets
   --wm-flip-duration (2.2s, the original's default) and a
   --wm-flip-delay set by the JS with the original's sine stagger:
   delay = sin(globalIndex / totalChars * PI/2) * duration * 0.25.
   NOTE: the registry TSX carries no keyframes (they live in the
   demo site's globals, not in the registry file), so the rotateX
   keyframes below are reconstructed to that contract: chars flip
   in from rotateX(90deg) and settle at rotateX(0deg). Play-once
   (the original loops by default; the hero entrance plays once).
   The H1 itself keeps perspective: 1000px, as in the original.
   ================================================================ */

.wm-flip {
  perspective: 1000px;
}
.wm-flip-word {
  display: inline-block;
  white-space: nowrap;
  transform-style: preserve-3d;
}
.wm-flip-char {
  display: inline-block;
  position: relative;
  transform-style: preserve-3d;
  animation: wm-flip-char var(--wm-flip-duration, 2.2s) var(--wm-flip-delay, 0s) 1 both;
}
@keyframes wm-flip-char {
  0% {
    transform: rotateX(90deg);
    opacity: 0;
  }
  55%,
  100% {
    transform: rotateX(0deg);
    opacity: 1;
  }
}

/* ================================================================
   2. MORPH TEXT — trade word blur-morph cycler (hero trust line)
   Ported from the original's own keyframes (morph-word-rotate)
   and its per-word timing: each word runs the full cycle
   (total = interval x word count, 3s x 6 = 18s here) with a delay
   of its index x interval, so words cross-fade/blur through each
   other — that overlap IS the morph. The slot is position:
   relative (its own containing block for the absolute words) and
   its width is set by the JS to the widest word, so the sentence
   never reflows as words change.
   The original also applies a gooey SVG threshold filter
   (feColorMatrix) to the container. It is deliberately NOT applied
   here: at this small inline size the threshold erodes thin
   letterforms; the blur keyframes alone give the morph.
   ================================================================ */

.wm-morph-slot {
  position: relative; /* containing block for the absolute words */
  display: inline-block;
  height: 1.2em;
  vertical-align: middle;
}
.wm-morph-word {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0;
  white-space: nowrap;
  animation-name: wm-morph-word-rotate;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-fill-mode: both;
  animation-duration: var(--wm-morph-total, 18s);
  animation-delay: var(--wm-morph-delay, 0s);
}
@keyframes wm-morph-word-rotate {
  0% {
    opacity: 0;
    filter: blur(20px);
    transform: translate(-50%, -50%) scale(0.8);
  }
  5% {
    opacity: 0.5;
    filter: blur(10px);
  }
  15%,
  35% {
    opacity: 1;
    filter: blur(0px);
    transform: translate(-50%, -50%) scale(1);
  }
  45% {
    opacity: 0.5;
    filter: blur(10px);
  }
  50%,
  100% {
    opacity: 0;
    filter: blur(20px);
    transform: translate(-50%, -50%) scale(1.2);
  }
}

/* ================================================================
   3. LINE HOVER LINK — header nav underline (CSS only)
   Ported verbatim from the original's own stylesheet
   (lineHoverStyles in components/ui/line-hover-link.tsx): the
   "slide" variant (line slides in right-to-left) is the one
   applied to the nav; "grow" is included for reuse. The base
   uses currentColor; the nav override below makes the line
   Westmark yellow.
   ================================================================ */

.link-hover {
  cursor: pointer;
  position: relative;
  display: inline-flex;
  width: fit-content;
  white-space: nowrap;
  color: currentColor;
  text-decoration: none;
  outline: none;
}

.link-hover::before,
.link-hover::after {
  position: absolute;
  left: 0;
  top: 100%;
  width: 100%;
  height: 1px;
  background: currentColor;
  pointer-events: none;
}

.link-hover::before {
  content: "";
}

.link-hover:focus-visible {
  border-radius: 0.25rem;
  outline: 2px solid color-mix(in srgb, currentColor 45%, transparent);
  outline-offset: 0.25rem;
}

.link-hover--slide::before {
  transform: scale3d(0, 1, 1);
  transform-origin: 100% 50%;
  transition: transform 0.3s ease;
}

.link-hover--slide:hover::before,
.link-hover--slide:focus-visible::before {
  transform: scale3d(1, 1, 1);
  transform-origin: 0% 50%;
}

.link-hover--grow::before {
  transform: scale3d(0, 1, 1);
  transform-origin: 100% 50%;
  transition: transform 0.3s cubic-bezier(0.2, 1, 0.8, 1);
}

.link-hover--grow:hover::before,
.link-hover--grow:focus-visible::before {
  transform: scale3d(1, 2, 1);
  transform-origin: 0% 50%;
  transition-timing-function: cubic-bezier(0.7, 0, 0.2, 1);
}

.link-hover--grow::after {
  content: "";
  top: calc(100% + 4px);
  transform: scale3d(0, 1, 1);
  transform-origin: 100% 50%;
  transition: transform 0.4s 0.1s cubic-bezier(0.2, 1, 0.8, 1);
}

.link-hover--grow:hover::after,
.link-hover--grow:focus-visible::after {
  transform: scale3d(1, 1, 1);
  transform-origin: 0% 50%;
}

/* Westmark nav: the theme's nav links are display:block pills, so
   keep that (the base's inline-flex / fit-content must not shrink
   them) and make the sliding line Westmark yellow. */
.main-nav a.link-hover {
  display: block;
  width: auto;
}
.main-nav a.link-hover::before,
.main-nav a.link-hover::after {
  background: var(--yellow);
}

/* ================================================================
   4a. STAGGER TEXT — section titles reveal word-by-word on scroll
   Faithful to the original's motion values: words rise from
   y: 110% to y: 0 over 0.6s with ease [0.22, 1, 0.36, 1],
   staggered 0.05s per word, once only (whileInView once).
   Each word sits in an overflow-hidden wrapper so it rises out
   of its own line box. The hidden state exists ONLY once JS has
   added .wm-stagger — with JS off, titles render normally.
   ================================================================ */

.wm-stagger .wm-stagger-word {
  display: inline-block;
  overflow: hidden;
  position: relative;
  vertical-align: top;
}
.wm-stagger .wm-stagger-inner {
  display: inline-block;
  will-change: transform;
  transform: translateY(110%);
  transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  transition-delay: var(--wm-stagger-delay, 0s);
}
.wm-stagger.wm-stagger-in .wm-stagger-inner {
  transform: translateY(0);
}

/* ================================================================
   4b. ANIMATED NUMBER — price count-up (£0 -> £1,497 on scroll)
   Tabular figures keep the price from jittering sideways as the
   digits change. The number itself is swapped by the JS; the £
   and "/month" in the markup are never touched.
   ================================================================ */

.wm-count-num {
  font-variant-numeric: tabular-nums;
}

/* ================================================================
   Reduced motion + touch
   The JS never starts any of these effects under
   prefers-reduced-motion, so this is belt-and-braces: if the
   classes were somehow applied, nothing moves and the final
   text/number shows.
   ================================================================ */

@media (prefers-reduced-motion: reduce) {
  .wm-flip-char,
  .wm-morph-word,
  .wm-stagger .wm-stagger-inner,
  .link-hover,
  .link-hover *,
  .link-hover::before,
  .link-hover::after {
    animation: none !important;
    transition: none !important;
  }
  .wm-flip-char {
    transform: none;
    opacity: 1;
  }
  .wm-morph-word {
    opacity: 0;
    filter: none;
    transform: translate(-50%, -50%);
  }
  .wm-morph-word:first-child {
    opacity: 1;
  }
  .wm-stagger .wm-stagger-inner {
    transform: none;
  }
}
