/* Motion module: preloader, cursor, reveals, manifesto, services, process, smooth scroll.
   Owner: js/motion.js. Tokens: css/tokens.css. Rules: design.md (Motion). */

/* ---------- scroll ---------- */
html.is-locked { overflow: hidden; }
html.lenis, html.lenis body { height: auto; }
html.lenis.lenis-smooth { scroll-behavior: auto; }
html.lenis.lenis-stopped { overflow: clip; }

/* ---------- 1. preloader (styled only under html.js, so it never blocks a no-JS visit) ---------- */
.preloader { display: none; }
html.js .preloader {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-content: center;
  background: var(--bg);
  /* SLOW_OK: fail-safe only - if the motion module never runs, the layer gets out of the way after 6s */
  animation: preloader-failsafe 1ms linear 6s forwards;
}
.preloader__name {
  font-family: var(--font-display);
  font-size: var(--fs-display);
  font-weight: 800;
  line-height: 1.15;
}
.preloader__count {
  position: absolute;
  inset-block-end: var(--gutter);
  inset-inline-end: var(--gutter);
  font-family: var(--font-mono);
  font-size: var(--fs-h3);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  unicode-bidi: isolate;
  color: var(--ink-muted);
}
.preloader__curtain {
  position: absolute;
  inset: 0;
  background: var(--ink);
  transform: scaleX(0);
  /* the inline-start edge, from the --dir token */
  transform-origin: calc(50% - 50% * var(--dir)) 50%;
}
@keyframes preloader-failsafe { to { visibility: hidden; } }

/* ---------- 9. cursor (fine pointers only; JS adds html.has-cursor) ---------- */
.cursor { display: none; }
html.has-cursor .cursor {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 99;
  pointer-events: none;
  direction: ltr; /* children are placed in clientX space */
  mix-blend-mode: difference;
  opacity: 0;
  transition: opacity var(--dur-base) ease;
}
html.has-cursor .cursor.is-on { opacity: 1; }
html.has-cursor .cursor.is-hidden { opacity: 0; }
.cursor > span {
  position: absolute;
  inset-block-start: 0;
  inset-inline-start: 0;
  border-radius: var(--r-full);
  translate: -50% -50%;
}
.cursor__dot { inline-size: 10px; block-size: 10px; background: var(--surface); }
.cursor__ring {
  inline-size: 44px;
  block-size: 44px;
  border: 1px solid var(--surface);
  transition: scale var(--dur-base) var(--ease-out);
}
.cursor.is-hover .cursor__ring { scale: 1.8; }
html.has-cursor, html.has-cursor * { cursor: none; }
html.has-cursor :is(input, select, [contenteditable="true"], .contact textarea) { cursor: auto; }

/* ---------- 3. reveals (hidden only under html.js; a class + transition, once) ---------- */
html.js [data-reveal] {
  opacity: 0;
  translate: 0 var(--sp-3);
  filter: blur(var(--sp-1));
  transition:
    opacity var(--dur-slow) var(--ease-out) var(--stagger, 0ms),
    translate var(--dur-slow) var(--ease-out) var(--stagger, 0ms),
    filter var(--dur-slow) var(--ease-out) var(--stagger, 0ms);
}
html.js [data-reveal].is-in { opacity: 1; translate: none; filter: none; }
/* Buttons keep their own press and hover transitions next to the reveal. */
html.js .btn[data-reveal] {
  transition:
    opacity var(--dur-slow) var(--ease-out) var(--stagger, 0ms),
    translate var(--dur-slow) var(--ease-out) var(--stagger, 0ms),
    filter var(--dur-slow) var(--ease-out) var(--stagger, 0ms),
    transform var(--dur-fast) var(--ease-out),
    scale var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) ease,
    box-shadow var(--dur-base) ease;
}

/* ---------- 8. magnetic: JS writes transform per frame, so transform must not transition here ---------- */
html.has-fine-pointer:not(.is-reduced) .btn[data-magnetic] {
  transition:
    opacity var(--dur-slow) var(--ease-out) var(--stagger, 0ms),
    translate var(--dur-slow) var(--ease-out) var(--stagger, 0ms),
    filter var(--dur-slow) var(--ease-out) var(--stagger, 0ms),
    scale var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) ease,
    box-shadow var(--dur-base) ease;
}
/* The inline transform overrides base .btn:active, so the press lives on `scale`. */
html.has-fine-pointer:not(.is-reduced) .btn[data-magnetic]:active { scale: 0.97; }

/* ---------- 4. manifesto ---------- */
.manifesto__text {
  margin-block-start: var(--sp-6);
  max-inline-size: 20ch;
  font-family: var(--font-display);
  font-size: var(--fs-display);
  font-weight: 700;
  line-height: 1.2;
  text-wrap: pretty;
}
.manifesto__word {
  display: inline-block; /* fixed to its heaviest width by JS, so the lines never reflow while the weight scrubs */
  font-variation-settings: "wght" var(--wght, 700);
}

/* ---------- 5. services ---------- */
.services__head { margin-block-end: var(--sp-7); }
.services__head .label { margin-block-end: var(--sp-3); }
.services__rail {
  display: grid;
  gap: var(--sp-5);
  max-inline-size: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.service {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  padding: var(--sp-6);
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  transition: box-shadow var(--dur-base) ease;
}
.service__idx.label {
  font-size: var(--fs-display);
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.service h3 { font-size: var(--fs-h3); font-weight: 600; line-height: 1.25; }
.service p { color: var(--ink-muted); }
.service__tags { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-block-start: auto; }
.service__tags li {
  padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-sm);
  background: var(--accent-soft);
  font-size: var(--fs-small);
  font-weight: 500;
}
@media (min-width: 48rem) {
  .services__rail { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* Desktop rail: JS adds .is-rail only at 64rem+ without reduced motion, and pins .services__pin. */
.services.is-rail .services__pin {
  min-block-size: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow-x: clip;
}
.services.is-rail .services__rail {
  display: flex;
  inline-size: max-content;
  max-inline-size: none;
  margin-inline: 0;
  padding-inline: max(var(--gutter), calc((100vw - var(--container)) / 2 + var(--gutter)));
}
.services.is-rail .service { flex: none; inline-size: clamp(22rem, 32vw, 30rem); min-block-size: 26rem; }

/* ---------- 6. process ---------- */
.process .container { display: flex; flex-direction: column; }
.process .container > .label { margin-block-end: var(--sp-3); }
.process__line {
  order: 1;
  margin-block: var(--sp-7) var(--sp-6);
  block-size: 2px;
  background: var(--line);
  border-radius: var(--r-full);
  overflow: hidden;
}
.process__line span {
  display: block;
  block-size: 100%;
  background: var(--accent);
  transform-origin: calc(50% - 50% * var(--dir)) 50%; /* the inline-start edge, from the --dir token */
}
.process__steps { order: 2; display: grid; gap: var(--sp-6); }
.step { display: flex; flex-direction: column; gap: var(--sp-3); }
.step__idx { font-variant-numeric: tabular-nums; color: var(--accent); }
.step h3 { font-size: var(--fs-h3); font-weight: 600; line-height: 1.25; }
.step p { color: var(--ink-muted); }
@media (min-width: 48rem) { .process__steps { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 64rem) { .process__steps { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* ---------- hover (hover-capable pointers only; :active stays outside) ---------- */
@media (hover: hover) {
  .service:hover { box-shadow: var(--shadow-1h); }
}

/* ---------- reduced motion: movement goes, opacity and colour stay ---------- */
@media (prefers-reduced-motion: reduce) {
  html.js [data-reveal], html.js .btn[data-reveal] {
    translate: none;
    filter: none;
    transition: opacity var(--dur-slow) ease, background-color var(--dur-fast) ease, box-shadow var(--dur-base) ease;
  }
}
@media (prefers-reduced-motion: no-preference) {
  html:not(.lenis) { scroll-behavior: smooth; }
}
