/* ==========================================================================
   TRILOT — MOTION LAYER
   Scroll-driven animations where the engine supports them, an
   IntersectionObserver-driven parity layer where it does not.
   Nothing here is decorative-only: motion always carries hierarchy.
   ========================================================================== */

/* --- Reveal primitives ---------------------------------------------------- */
[data-reveal] {
  --reveal-shift: 28px;
  opacity: 0;
  translate: 0 var(--reveal-shift);
  filter: blur(6px);
  transition:
    opacity var(--dur-slow) var(--ease-out),
    translate var(--dur-slow) var(--ease-out),
    filter var(--dur-slow) var(--ease-out);
  transition-delay: var(--delay, 0ms);
}
[data-reveal='fade']  { --reveal-shift: 0px; filter: none; }
[data-reveal='left']  { --reveal-shift: 0px; translate: -32px 0; }
[data-reveal='right'] { --reveal-shift: 0px; translate: 32px 0; }
[data-reveal='scale'] { --reveal-shift: 0px; scale: 0.965; filter: blur(10px); }
[data-reveal].is-in {
  opacity: 1;
  translate: 0 0;
  scale: 1;
  filter: blur(0);
}

/* Word-by-word display reveal — the markup carries <span class="w">…</span>. */
.line-mask { display: block; overflow: clip; padding-block: 0.06em; }
.line-mask > * {
  display: block;
  translate: 0 110%;
  rotate: 2.2deg;
  transition: translate 1s var(--ease-glide), rotate 1.2s var(--ease-glide);
  transition-delay: calc(var(--i, 0) * 90ms + var(--delay, 0ms));
}
.is-in .line-mask > *, .line-mask.is-in > * { translate: 0 0; rotate: 0deg; }

/* Ink stroke draw-on for inline SVG. */
.draw [data-draw] {
  stroke-dasharray: var(--len, 1200);
  stroke-dashoffset: var(--len, 1200);
  transition: stroke-dashoffset 1.6s var(--ease-glide);
  transition-delay: calc(var(--i, 0) * 160ms);
}
.draw.is-in [data-draw] { stroke-dashoffset: 0; }

/* --- Scroll-driven animation --------------------------------------------- */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    /* Hairline rules that draw themselves as the section enters. */
    .rule-draw {
      --rule: 0%;
      animation: rule-draw linear both;
      animation-timeline: view();
      animation-range: entry 10% cover 34%;
    }
    @keyframes rule-draw { to { --rule: 100%; } }

    /* Parallax drift for images and numerals. */
    .drift {
      animation: drift linear both;
      animation-timeline: view();
      animation-range: cover;
    }
    @keyframes drift { from { translate: 0 6%; } to { translate: 0 -6%; } }

    /* Timeline rail: fills as you scroll the operator history. */
    .rail__fill {
      animation: rail-fill linear both;
      animation-timeline: view();
      animation-range: cover 12% cover 82%;
      scale: 1 0;
      transform-origin: top;
    }
    @keyframes rail-fill { to { scale: 1 1; } }

    /* Section numerals gain their accent as they cross the midline. */
    .numeral {
      animation: numeral-ink linear both;
      animation-timeline: view();
      animation-range: entry 40% cover 30%;
    }
    @keyframes numeral-ink { to { --sat: 1; color: var(--accent); } }

    /* Horizontal brand rail driven by vertical scroll (no scroll-jacking). */
    .rail-x {
      animation: rail-x linear both;
      animation-timeline: view(block 100%);
      animation-range: cover 0% cover 100%;
    }
    @keyframes rail-x { to { translate: calc(-1 * var(--rail-travel, 0px)) 0; } }

    /* Hero type scales out as it leaves — depth without opacity tricks. */
    .hero-type {
      animation: hero-out linear both;
      animation-timeline: scroll(root);
      animation-range: 0 60vh;
    }
    @keyframes hero-out { to { scale: 0.94; filter: blur(7px); opacity: 0.15; } }

    /* Preloader curtain is time-driven; the canvases are scroll-driven. */
    .scroll-progress {
      animation: grow-x linear both;
      animation-timeline: scroll(root);
      transform-origin: left;
      scale: 0 1;
    }
    @keyframes grow-x { to { scale: 1 1; } }
  }
}

/* --- Marquee -------------------------------------------------------------- */
.marquee {
  --speed: 42s;
  display: flex;
  overflow: clip;
  mask-image: linear-gradient(90deg, transparent, #000 8%, #000 92%, transparent);
}
.marquee__track {
  display: flex;
  flex: none;
  gap: var(--space-xl);
  padding-inline-end: var(--space-xl);
  animation: marquee var(--speed) linear infinite;
  will-change: translate;
}
.marquee:hover .marquee__track { animation-play-state: paused; }
@keyframes marquee { to { translate: -100% 0; } }

/* --- Cursor --------------------------------------------------------------- */
.cursor { display: none; }
@media (hover: hover) and (pointer: fine) {
  .cursor {
    position: fixed;
    inset: 0 auto auto 0;
    z-index: var(--z-cursor);
    display: grid;
    place-items: center;
    pointer-events: none;
    translate: -50% -50%;
    mix-blend-mode: difference;
    transition: opacity var(--dur) var(--ease-out);
  }
  .cursor__dot {
    width: 7px; aspect-ratio: 1; border-radius: 50%;
    background: oklch(1 0 0);
    transition: scale 260ms var(--ease-spring), opacity 200ms linear;
  }
  .cursor__ring {
    position: absolute;
    width: 40px; aspect-ratio: 1; border-radius: 50%;
    border: 1px solid oklch(1 0 0 / 0.6);
    transition: width 320ms var(--ease-spring), height 320ms var(--ease-spring),
                border-color 240ms linear, opacity 240ms linear, scale 420ms var(--ease-spring);
  }
  .cursor__label {
    position: absolute;
    font: 500 var(--step--2) / 1 var(--font-mono);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    color: oklch(1 0 0);
    opacity: 0;
    translate: 0 0;
    transition: opacity 200ms linear, translate 300ms var(--ease-out);
    white-space: nowrap;
  }
  .cursor[data-state='link'] .cursor__ring { width: 64px; border-color: oklch(1 0 0); }
  .cursor[data-state='link'] .cursor__dot { scale: 0; }
  .cursor[data-state='label'] .cursor__ring { width: 92px; height: 92px; border-color: transparent; background: oklch(1 0 0); }
  .cursor[data-state='label'] .cursor__dot { scale: 0; }
  .cursor[data-state='label'] .cursor__label { opacity: 1; color: oklch(0 0 0); mix-blend-mode: normal; }
  .cursor[data-state='down'] .cursor__ring { scale: 0.82; }
  .cursor.is-hidden { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .cursor { display: none !important; }
}

/* --- Preloader ------------------------------------------------------------ */
.preloader {
  position: fixed;
  inset: 0;
  z-index: var(--z-preloader);
  display: grid;
  place-items: center;
  background: var(--bg-sunken);
  transition: opacity 700ms var(--ease-out), visibility 700ms;
}
.preloader__inner { display: grid; gap: var(--space-m); justify-items: center; width: min(22rem, 74vw); }
.preloader__strokes { width: min(15rem, 50vw); overflow: visible; }
.preloader__strokes path {
  fill: none;
  stroke-linecap: round;
  stroke-width: 2.4;
  stroke-dasharray: 320;
  stroke-dashoffset: 320;
  animation: stroke-in 1.15s var(--ease-glide) forwards;
}
.preloader__strokes path:nth-child(1) { stroke: var(--sage); animation-delay: 0.05s; }
.preloader__strokes path:nth-child(2) { stroke: var(--rust); animation-delay: 0.19s; }
.preloader__strokes path:nth-child(3) { stroke: var(--sky);  animation-delay: 0.33s; }
@keyframes stroke-in { to { stroke-dashoffset: 0; } }
.preloader__meta {
  display: flex; justify-content: space-between; width: 100%;
  font: 400 var(--step--2) / 1 var(--font-mono);
  letter-spacing: var(--tracking-mono); text-transform: uppercase; color: var(--fg-faint);
}
.preloader__bar { height: 1px; width: 100%; background: var(--line); overflow: hidden; }
.preloader__bar span { display: block; height: 100%; background: var(--fg); scale: 0 1; transform-origin: left; }
.preloader__count { font-variant-numeric: tabular-nums; color: var(--fg-muted); }
body.is-loading { overflow: hidden; }
.preloader.is-done { opacity: 0; visibility: hidden; }
.preloader.is-done .preloader__inner { translate: 0 -14px; transition: translate 700ms var(--ease-out); }

/* --- Page transition (same-document curtain + cross-document VT) ---------- */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: vt-out 320ms var(--ease-glide) both; }
::view-transition-new(root) { animation: vt-in 520ms var(--ease-glide) both; }
@keyframes vt-out { to { opacity: 0; filter: blur(6px); scale: 1.01; } }
@keyframes vt-in  { from { opacity: 0; filter: blur(10px); scale: 0.99; } }
/* The nav wordmark flies between pages rather than re-rendering. */
.nav__mark { view-transition-name: brand; }

.curtain {
  position: fixed;
  inset: 0;
  z-index: var(--z-preloader);
  background: var(--bg-sunken);
  scale: 1 0;
  transform-origin: bottom;
  pointer-events: none;
}
.curtain.is-closing { animation: curtain-in 420ms var(--ease-glide) both; }
@keyframes curtain-in { from { scale: 1 0; } to { scale: 1 1; } }

/* --- Buttons & links ------------------------------------------------------ */
.btn {
  --lift: 0px;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.6em;
  padding: 0.86em 1.5em;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  font: var(--weight-medium) var(--step--1) / 1 var(--font-sans);
  letter-spacing: 0.01em;
  color: var(--fg);
  background: transparent;
  isolation: isolate;
  overflow: hidden;
  translate: 0 var(--lift);
  transition: translate 420ms var(--ease-spring), border-color 300ms linear, color 300ms linear;
}
.btn::before {
  content: '';
  position: absolute; inset: 0; z-index: -1;
  background: var(--accent);
  scale: 0 1; transform-origin: bottom;
  transition: scale 520ms var(--ease-glide);
}
.btn:hover, .btn:focus-visible { --lift: -3px; border-color: transparent; color: var(--accent-ink); }
.btn:hover::before, .btn:focus-visible::before { scale: 1 1; }
.btn:active { --lift: 0px; }
.btn--solid { background: var(--fg); color: var(--bg); border-color: transparent; }
.btn--solid::before { background: var(--accent); }
.btn--solid:hover, .btn--solid:focus-visible { color: var(--accent-ink); }
.btn--ghost { border-color: transparent; padding-inline: 0.2em; }
.btn--ghost::before { display: none; }
.btn__arrow { transition: translate 380ms var(--ease-spring); }
.btn:hover .btn__arrow { translate: 4px -4px; }

/* Underline that draws from the left, then retracts from the right. */
.link-ink {
  position: relative;
  display: inline-block;
  padding-block-end: 0.12em;
}
.link-ink::after {
  content: '';
  position: absolute; inset: auto 0 0 0; height: 1px;
  background: currentColor;
  scale: 0 1; transform-origin: right;
  transition: scale 420ms var(--ease-glide);
}
.link-ink:hover::after, .link-ink:focus-visible::after { scale: 1 1; transform-origin: left; }

/* --- Nav ------------------------------------------------------------------ */
.nav {
  position: fixed;
  inset-block-start: 0;
  inset-inline: 0;
  z-index: var(--z-nav);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-m);
  padding: clamp(0.7rem, 1.6vw, 1.15rem) var(--gutter);
  border-block-end: 1px solid transparent;
  transition: background-color 400ms var(--ease-out), border-color 400ms var(--ease-out),
              backdrop-filter 400ms var(--ease-out), padding 400ms var(--ease-out);
}
.nav.is-stuck {
  background: color-mix(in oklab, var(--bg) 78%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  border-block-end-color: var(--line);
  padding-block: 0.6rem;
}
.nav__links { display: none; gap: clamp(1rem, 2vw, 2rem); align-items: center; }
@media (min-width: 62rem) { .nav__links { display: flex; } }
.nav__link {
  position: relative;
  font: var(--weight-body) var(--step--1) / 1 var(--font-sans);
  color: var(--fg-muted);
  transition: color 240ms linear;
}
.nav__link:hover, .nav__link[aria-current='page'] { color: var(--fg); }
.nav__link[aria-current='page']::after {
  content: '';
  position: absolute; inset-inline: 0; inset-block-end: -0.45em; height: 1px;
  background: var(--accent);
}
.nav__actions { display: flex; align-items: center; gap: var(--space-2xs); }
.icon-btn {
  display: grid; place-items: center;
  width: 2.4rem; aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  color: var(--fg-muted);
  transition: color 240ms linear, border-color 240ms linear, rotate 520ms var(--ease-spring);
}
.icon-btn:hover { color: var(--fg); border-color: var(--line-strong); rotate: 18deg; }

/* Mobile drawer */
.drawer {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer);
  display: grid;
  align-content: center;
  gap: var(--space-s);
  padding: var(--gutter);
  background: var(--bg-sunken);
  clip-path: inset(0 0 100% 0);
  transition: clip-path 720ms var(--ease-glide), visibility 720ms;
  visibility: hidden;
}
.drawer[data-open='true'] { clip-path: inset(0 0 0 0); visibility: visible; }
.drawer a {
  font: var(--weight-light) var(--step-4) / 1.05 var(--font-display);
  letter-spacing: var(--tracking-display);
  opacity: 0;
  translate: 0 24px;
  transition: opacity 500ms var(--ease-out), translate 620ms var(--ease-out);
  transition-delay: calc(var(--i) * 60ms + 120ms);
}
.drawer[data-open='true'] a { opacity: 1; translate: 0 0; }

/* --- Scroll progress + grain + noise ------------------------------------- */
.scroll-progress {
  position: fixed;
  inset-block-start: 0;
  inset-inline: 0;
  height: 2px;
  z-index: var(--z-nav);
  background: linear-gradient(90deg, var(--sage), var(--rust) 50%, var(--sky));
  scale: 0 1;
  transform-origin: left;
  pointer-events: none;
}
@supports not (animation-timeline: scroll(root)) {
  .scroll-progress { scale: 1 1; transform-origin: left; transform: scaleX(var(--sp, 0)); }
}
.grain {
  position: fixed;
  inset: -120%;
  z-index: var(--z-grain);
  pointer-events: none;
  opacity: var(--grain-opacity);
  mix-blend-mode: var(--grain-blend);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.86' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  animation: grain-shift 6s steps(6) infinite;
  will-change: transform;
}
@keyframes grain-shift {
  0%, 100% { transform: translate3d(0, 0, 0); }
  20% { transform: translate3d(-3%, 2%, 0); }
  40% { transform: translate3d(2%, -3%, 0); }
  60% { transform: translate3d(-2%, -2%, 0); }
  80% { transform: translate3d(3%, 1%, 0); }
}

/* --- Hero + ambient light ------------------------------------------------ */
.hero__canvas, .scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.hero__aura {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(46% 40% at 63% 44%, color-mix(in oklab, var(--sage) 9%, transparent), transparent 70%),
    radial-gradient(38% 34% at 82% 66%, color-mix(in oklab, var(--sky) 7%, transparent), transparent 72%),
    radial-gradient(42% 36% at 24% 74%, color-mix(in oklab, var(--rust) 8%, transparent), transparent 72%);
  animation: aura-breathe 16s var(--ease-in-out) infinite alternate;
  pointer-events: none;
}
/* Cinematic vignette: keeps type readable over whatever the GPU is doing. */
.hero__vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg,
      color-mix(in oklab, var(--bg) 62%, transparent) 0%,
      transparent 18%,
      transparent 52%,
      color-mix(in oklab, var(--bg) 82%, transparent) 100%),
    radial-gradient(118% 78% at 52% 44%, transparent 38%, color-mix(in oklab, var(--bg) 58%, transparent) 100%);
}
@keyframes aura-breathe {
  from { opacity: 0.75; scale: 1; }
  to   { opacity: 1;    scale: 1.08; }
}

/* Cursor-tracked spotlight used on cards (--mx/--my set by JS). */
.spot {
  position: relative;
  isolation: isolate;
  overflow: hidden;
}
.spot::after {
  content: '';
  position: absolute; inset: 0; z-index: -1;
  background: radial-gradient(
    22rem 22rem at var(--mx, 50%) var(--my, 50%),
    color-mix(in oklab, var(--accent) 16%, transparent), transparent 68%);
  opacity: 0;
  transition: opacity 480ms var(--ease-out);
}
.spot:hover::after, .spot:focus-within::after { opacity: 1; }

/* Card lift with a hard shadow — physical, not floaty. */
.lift {
  transition: translate 560ms var(--ease-spring), border-color 400ms linear, box-shadow 560ms var(--ease-out);
}
.lift:hover { translate: 0 -6px; box-shadow: var(--shadow-lift); border-color: var(--line-strong); }

/* --- Brand rail (horizontal) --------------------------------------------- */
.rail-x__track { display: flex; gap: clamp(1rem, 2vw, 2rem); will-change: translate; }

/* --- Notes deck ----------------------------------------------------------- */
.deck {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(min(24rem, 82vw), 1fr);
  gap: var(--space-m);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding-block-end: var(--space-s);
  scrollbar-width: thin;
}
.deck > * { scroll-snap-align: start; }

/* --- Accordion (services in depth) --------------------------------------- */
.accordion__panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 620ms var(--ease-glide);
}
.accordion__panel > div { overflow: hidden; }
.accordion[data-open='true'] .accordion__panel { grid-template-rows: 1fr; }
.accordion[data-open='true'] .accordion__sign { rotate: 45deg; }

/* --- Counters ------------------------------------------------------------- */
.tabular { font-variant-numeric: tabular-nums; }

/* --- Reduced motion ------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  [data-reveal] { opacity: 1; translate: none; scale: none; filter: none; }
  .line-mask > * { translate: none; rotate: none; }
  .preloader { display: none; }
  .hero-type { scale: 1; filter: none; opacity: 1; }
  .marquee__track { animation: none; }
}
