/* ==========================================================================
   Motion
   Every animation's starting/ending state lives here.

   How it works:
   - An inline script adds `.js` and `.loading` before the first paint.
     All hidden "before" states are scoped to `.js`, so if JavaScript is off
     the page is fully visible with no animation.
   - When the preloader finishes, JS swaps `.loading` for `.ready`.
   - Scroll reveals mark off-screen [data-reveal] elements `.is-pending`
     and remove it when they scroll into view.
   - `.motion-off` (Pause motion button) and the OS reduced-motion setting
     switch everything to its final state.
   ========================================================================== */

/* ---- Preloader ---- */
.preloader {
  display: none;
}

.js.loading .preloader,
.js .preloader.is-done {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  padding: clamp(24px, 5.5vw, 80px);
  background:
    radial-gradient(ellipse 34% 48% at 64% 36%, rgba(255, 255, 255, .22), transparent 70%),
    radial-gradient(ellipse 60% 40% at 22% 96%, rgba(255, 255, 255, .1), transparent 70%),
    linear-gradient(155deg, #4a4744 0%, #1f1e1d 52%, #0e0e0e 100%);
  color: #f4f1ec;
  transition: transform .5s var(--ease);
}

.js .preloader.is-done {
  transform: translateY(-100%);
}

.js.loading .preloader { pointer-events: auto; }
.js.loading .hero__name .char,
.js.loading [data-hero-fade] { transition: none; }

/* Centred lockup: monogram, wordmark, sub line */
.preloader__brand {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.preloader__brand .monogram {
  width: clamp(48px, 6vw, 72px);
  margin-bottom: 20px;
}

.preloader__brand .wordmark {
  font-size: clamp(18px, 2.4vw, 28px);
  padding-left: .16em;   /* balances the trailing letter-spacing */
}

.preloader__brand .wordmark-sub {
  padding-left: .62em;
  opacity: .9;
}

.preloader__row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
  font: 500 9px / 1 var(--font-body);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--color-on-dark);
}

.preloader__count {
  font-variant-numeric: tabular-nums;
}

.preloader__bar {
  height: 1px;
  background: rgba(237, 232, 227, .2);
}

.preloader__bar i {
  display: block;
  height: 100%;
  background: var(--color-on-band);
  transform: scaleX(0);
  transform-origin: left;
}

/* ---- Page scroll progress bar (top of viewport) ---- */
.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 2px;
  background: var(--color-ink);
  transform: scaleX(0);
  transform-origin: left;
}

/* ---- Hero entrance (runs when the brand intro finishes) ---- */
.js .hero__name .char {
  transform: translateY(115%);
  transition: transform 800ms var(--ease);
}

.js.ready .hero__name .char {
  transform: none;
}

/* The fade moves with `translate` so `transform` stays free for the
   hero card's pointer tilt (scripts/features/cards.js). */
.js [data-hero-fade] {
  opacity: 0;
  translate: 0 24px;
  transition: opacity 600ms 160ms, translate 700ms 160ms var(--ease);
}

.js.ready [data-hero-fade] {
  opacity: 1;
  translate: none;
}

.js .bcard[data-hero-fade] {
  transition: opacity 600ms 160ms, translate 700ms 160ms var(--ease);
}

/* ---- Scroll reveal (armed by scripts/features/reveal.js) ---- */
[data-reveal] {
  transition: opacity 600ms var(--ease) var(--reveal-delay, 0ms), transform 700ms var(--ease) var(--reveal-delay, 0ms);
}

[data-reveal].is-pending {
  opacity: 0;
  transform: translateY(28px);
}

[data-reveal]:focus-within {
  opacity: 1;
  transform: none;
  transition: none;
}

/* Reveal variant: section titles wipe up from behind a mask.
   The negative insets keep descenders and tracking from being clipped. */
.section-title[data-reveal] {
  clip-path: inset(-.2em -.2em -.25em -.2em);
  transition: clip-path 900ms var(--ease) var(--reveal-delay, 0ms), transform 900ms var(--ease) var(--reveal-delay, 0ms);
}

.section-title[data-reveal].is-pending {
  opacity: 1;
  clip-path: inset(-.2em -.2em 100% -.2em);
  transform: translateY(.4em);
}

/* Reveal variant: the portrait frame is uncovered from the bottom up */
.about__portrait[data-reveal] {
  clip-path: inset(-15%);   /* extra room so the card is not clipped while it flips */
  transition: clip-path 1100ms var(--ease) var(--reveal-delay, 0ms);
}

.about__portrait[data-reveal].is-pending {
  opacity: 1;
  transform: none;
  clip-path: inset(100% 0 0 0);
}

/* Project screenshots settle from a slight zoom as their card appears */
.card.is-pending .tile__shot {
  transform: scale(1.14);
}

/* Stat rules draw from left to right */
.stat::before {
  transition: transform 1000ms var(--ease) var(--reveal-delay, 0ms);
}

.stat.is-pending::before {
  transform: scaleX(0);
}

/* ---- Statement: words light up as you scroll ---- */
.js .statement__text .word {
  opacity: .45;
  transition: opacity .35s;
}

.js .statement__text .word.is-lit {
  opacity: 1;
}

/* ---- Footer headline: lines slide up ---- */
.js .site-footer__title .slide-line {
  display: block;
  transform: translateY(115%);
  transition: transform 800ms var(--ease);
}

.js .site-footer__title .mask-line:nth-child(2) .slide-line {
  transition-delay: .12s;
}

.js .site-footer__title.is-visible .slide-line {
  transform: none;
}

/* ---- Custom cursor: transform-only feedback, native pointer stays ---- */
.cursor {
  display: none;
}

.has-custom-cursor .cursor {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 150;
  display: block;
  pointer-events: none;
  opacity: 0;
  mix-blend-mode: difference;   /* light on dark sections, dark on light ones */
  transition: opacity 160ms;
}

/* With a label the cursor is a solid bone disc instead */
.cursor.is-view {
  mix-blend-mode: normal;
}

.cursor.is-view i {
  background: var(--color-paper);
  box-shadow: 0 0 0 1px rgb(var(--ink-rgb) / .3);
}

.cursor.is-active {
  opacity: 1;
}

.cursor i {
  position: absolute;
  top: -40px;
  left: -40px;
  display: grid;
  place-items: center;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: #fff;
  transform: scale(.15);
  transition: transform 200ms var(--ease), opacity 160ms;
}

.cursor b {
  font: 500 9px / 1 var(--font-body);
  letter-spacing: .24em;
  text-transform: uppercase;
  color: var(--color-ink);
  opacity: 0;
  transition: opacity 160ms;
}

.cursor.is-link i { transform: scale(.5); opacity: .45; }
.cursor.is-view i { transform: scale(1); opacity: 1; }
.cursor.is-view b { opacity: 1; }

/* ---- Floating "Pause motion" control ---- */
.motion-toggle {
  position: fixed;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 80;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-pill);
  background: var(--color-paper);
  color: var(--color-ink);
  font: 500 9px var(--font-body);
  letter-spacing: .2em;
  text-transform: uppercase;
  box-shadow: 0 4px 20px rgba(30, 30, 30, .08);
  cursor: pointer;
}

.motion-toggle:disabled {
  cursor: default;
}

/* Phones: a 40px round button with a pause / play icon, so it no longer
   covers text. The label stays in the button for screen readers
   (font-size 0 only hides it visually). */
@media (max-width: 700px) {
  .motion-toggle {
    display: grid;
    place-items: center;
    width: 40px;
    min-height: 40px;
    height: 40px;
    padding: 0;
    font-size: 0;
    letter-spacing: 0;
    background: rgb(var(--paper-rgb) / .9);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }
  .motion-toggle[hidden],
  .motion-toggle:disabled { display: none; }

  /* pause: two bars */
  .motion-toggle::before {
    content: '';
    box-sizing: border-box;
    width: 10px;
    height: 12px;
    border-inline: 3px solid currentColor;
  }

  /* paused: a play triangle */
  .motion-toggle[aria-pressed="true"]::before {
    width: 0;
    height: 0;
    margin-left: 3px;
    border-block: 6px solid transparent;
    border-inline: 10px solid currentColor;
    border-inline-end-width: 0;
  }
}

/* ---- Theme switch: the whole page cross-fades (scripts/features/theme.js).
        While it runs, per-tile transition names are switched off so only the
        page as a whole is animated. ---- */
html.is-theme-switching .site {
  view-transition-name: none !important;
}

html.is-theme-switching::view-transition-old(root),
html.is-theme-switching::view-transition-new(root) {
  animation-duration: 350ms;
}

/* ---- Keyboard users: no waiting on transitions ---- */
html.is-keyboard *,
html.is-keyboard *::before,
html.is-keyboard *::after {
  transition-duration: 0s !important;
  transition-delay: 0s !important;
}

/* ---- Motion paused by the visitor ---- */
html.motion-off *,
html.motion-off *::before,
html.motion-off *::after {
  transition: none !important;
  animation: none !important;
  scroll-behavior: auto !important;
}

html.motion-off .cursor {
  display: none;
}

html.motion-off .hero__name .char,
html.motion-off [data-hero-fade],
html.motion-off [data-reveal],
html.motion-off .site-footer__title .slide-line,
html.motion-off .statement__text .word {
  opacity: 1;
  transform: none;
  translate: none;
}

html.motion-off [data-reveal] {
  clip-path: none;
  translate: none;
}

html.motion-off .case::details-content,
html.motion-off .faq__item::details-content {
  transition: none;
}

/* ---- OS "reduce motion" setting ---- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }

  .js .hero__name .char,
  .js [data-hero-fade],
  [data-reveal].is-pending,
  .js .site-footer__title .slide-line,
  .js .statement__text .word {
    opacity: 1;
    transform: none;
    translate: none;
  }

  [data-reveal].is-pending,
  .stat.is-pending::before,
  .card.is-pending .tile__shot {
    clip-path: none;
    transform: none;
  }

  .case::details-content,
  .faq__item::details-content {
    transition: none;
  }

  .cursor {
    display: none !important;
  }
}
