/* =============================================================
   Motion. Two dials from the words:
     data-motion        still | calm | lively      (how much)
     data-motion-style  rise · blur · mask · slide · type · slam · skew · flicker  (what kind)
   …and a page-change transition chosen from the style (data-vt).
   Everything here switches off under prefers-reduced-motion.
   ============================================================= */

:root {
  --amp: 1;
  --rv-dur: .95s;
  --rv-stagger: 80ms;
  --w-stagger: 45ms;
  --rv-ease: var(--ease);
}
html[data-motion="calm"]   { --amp: .55; --rv-dur: 1.05s; --rv-stagger: 60ms; --w-stagger: 32ms; }
html[data-motion="lively"] { --amp: 1;   --rv-dur: .95s;  --rv-stagger: 85ms; --w-stagger: 55ms; }

[data-motion-style="rise"]    { --rv-block: rv-rise;    --rv-word: w-rise; }
[data-motion-style="blur"]    { --rv-block: rv-blur;    --rv-word: w-blur; }
[data-motion-style="mask"]    { --rv-block: rv-mask;    --rv-word: w-rise; }
[data-motion-style="slide"]   { --rv-block: rv-slide;   --rv-word: w-slide; }
[data-motion-style="type"]    { --rv-block: rv-type;    --rv-word: w-type; --rv-ease: steps(14, end); --w-stagger: 70ms; }
[data-motion-style="slam"]    { --rv-block: rv-slam;    --rv-word: w-slam; --rv-ease: cubic-bezier(.2, 1.4, .3, 1); }
[data-motion-style="skew"]    { --rv-block: rv-skew;    --rv-word: w-skew; }
[data-motion-style="flicker"] { --rv-block: rv-flicker; --rv-word: w-flicker; --rv-ease: linear; }
/* still = quiet fades, whatever the style */
html[data-motion="still"] { --rv-block: rv-fade; --rv-word: w-fade; --rv-dur: .5s; --rv-stagger: 30ms; --w-stagger: 0ms; --rv-ease: ease-out; }

/* ---------- entrances: blocks ---------- */

.js [data-rv]:not(.in) { opacity: 0; }
.js [data-rv].in {
  animation: var(--rv-block, rv-rise) var(--rv-dur) var(--rv-ease) backwards;
  animation-delay: calc(var(--i, 0) * var(--rv-stagger));
}

@keyframes rv-fade    { from { opacity: 0; } }
@keyframes rv-rise    { from { opacity: 0; translate: 0 calc(52px * var(--amp)); } }
@keyframes rv-blur    { from { opacity: 0; filter: blur(calc(16px * var(--amp))); scale: calc(1 + .05 * var(--amp)); } }
@keyframes rv-mask    { from { clip-path: inset(0 0 100% 0); translate: 0 calc(28px * var(--amp)); } to { clip-path: inset(0 0 0 0); } }
@keyframes rv-slide   { from { opacity: 0; translate: calc(-72px * var(--amp)) 0; } }
@keyframes rv-type    { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes rv-slam    { from { opacity: 0; scale: calc(1 + .28 * var(--amp)); } 55% { opacity: 1; } }
@keyframes rv-skew    { from { opacity: 0; translate: 0 calc(46px * var(--amp)); transform: skewY(calc(6deg * var(--amp))); } }
@keyframes rv-flicker { 0% { opacity: 0; } 8% { opacity: .9; } 12% { opacity: .1; } 22% { opacity: 1; } 27% { opacity: .25; } 40%, 100% { opacity: 1; } }

/* ---------- entrances: headlines, word by word ---------- */

.w,
.w > span { display: inline-block; }
.w { max-width: 100%; overflow-wrap: anywhere; }
/* styles that slide words up from behind a baseline mask */
:is([data-motion-style="rise"], [data-motion-style="mask"], [data-motion-style="skew"]):not([data-motion="still"]) .w {
  overflow: clip;
  padding-block: .12em .24em;
  margin-block: -.12em -.24em;
}

.js .display[data-rv].in { animation: none; }
.js .display[data-rv] { opacity: 1; }
.js .display[data-rv]:not(.in) .w > span { opacity: 0; }
.js .display[data-rv].in .w > span {
  animation: var(--rv-word, w-rise) calc(var(--rv-dur) * .9) var(--rv-ease) backwards;
  animation-delay: calc(var(--wi, 0) * var(--w-stagger));
}
html[data-motion-style="type"] .display[data-rv].in .w > span { animation-duration: .01s; }

@keyframes w-fade    { from { opacity: 0; } }
@keyframes w-rise    { from { translate: 0 108%; } }
@keyframes w-blur    { from { opacity: 0; filter: blur(.28em); } }
@keyframes w-slide   { from { opacity: 0; translate: -.7em 0; } }
@keyframes w-type    { from { opacity: 0; } to { opacity: 1; } }
@keyframes w-slam    { from { opacity: 0; scale: 1.9; } 65% { opacity: 1; } }
@keyframes w-skew    { from { translate: 0 105%; transform: skewY(14deg); } }
@keyframes w-flicker { 0% { opacity: 0; } 18% { opacity: 1; } 26% { opacity: 0; } 44% { opacity: 1; } 52% { opacity: .2; } 70%, 100% { opacity: 1; } }

/* the bridge: the deck draws from idea to market, the marker walks to where we build */
html:not([data-motion="still"]) .bridge.in .bridge-deck { animation: deck-draw 1.4s var(--ease) .15s backwards; }
html:not([data-motion="still"]) .bridge.in .bridge-marker { animation: marker-walk 1.8s var(--ease) .35s backwards; }
@keyframes deck-draw { from { right: 100%; } }
@keyframes marker-walk { from { left: 6%; opacity: 0; } 20% { opacity: 1; } }

/* ---------- page changes ---------- */

::view-transition-group(root) { animation-duration: .85s; }
::view-transition-old(root) { animation: none; }
::view-transition-new(root) {
  mix-blend-mode: normal;
  animation: vt-iris .85s var(--ease) both;
}
html[data-vt="wipe"]::view-transition-new(root) { animation-name: vt-wipe; }
html[data-vt="blinds"]::view-transition-new(root) {
  animation-name: vt-blinds;
  -webkit-mask-image: linear-gradient(#000 var(--vt-p), #0000 var(--vt-p));
  mask-image: linear-gradient(#000 var(--vt-p), #0000 var(--vt-p));
  -webkit-mask-size: 100% 12.5vh;
  mask-size: 100% 12.5vh;
}
@property --vt-p { syntax: "<percentage>"; inherits: false; initial-value: 100%; }
@keyframes vt-iris { from { clip-path: circle(0 at var(--vt-x, 50%) var(--vt-y, 100%)); } to { clip-path: circle(150vmax at var(--vt-x, 50%) var(--vt-y, 100%)); } }
@keyframes vt-wipe { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes vt-blinds { from { --vt-p: 0%; } to { --vt-p: 100%; } }

/* ---------- scroll-driven: photographs move against the page ---------- */

@supports (animation-timeline: view()) {
  html:not([data-motion="still"]) .fig-media { view-timeline: --media block; }
  html:not([data-motion="still"]) .fig-media img {
    scale: var(--para-scale, 1.14);
    animation: parallax linear both;
    animation-timeline: --media;
  }
  html:not([data-motion="still"]) :is(.fig--full, .fig[data-shape="full"]) { --para: 9%; --para-scale: 1.22; }
  html[data-motion="calm"] { --para-dampen: .6; }
  @keyframes parallax {
    from { translate: 0 calc(-1 * var(--para, 5%) * var(--para-dampen, 1)); }
    to   { translate: 0 calc(var(--para, 5%) * var(--para-dampen, 1)); }
  }

  /* window holds its photograph perfectly still */
  .interlude[data-variant="window"] .fig-media img { animation: none; scale: 1; }

  /* zoom: a framed oval opens to the full screen while the section is pinned */
  html:not([data-motion="still"]) .interlude[data-variant="zoom"] { view-timeline: --zoom block; }
  html:not([data-motion="still"]) .interlude[data-variant="zoom"] .fig-media {
    animation: zoom-open linear both;
    animation-timeline: --zoom;
    animation-range: contain 0% contain 72%;
  }
  html:not([data-motion="still"]) .interlude[data-variant="zoom"] .fig-media img {
    animation: zoom-img linear both;
    animation-timeline: --zoom;
    animation-range: contain 0% contain 72%;
  }
  @keyframes zoom-open { from { clip-path: inset(22% 20% round 50%); } to { clip-path: inset(0 0 round 0); } }
  @keyframes zoom-img { from { scale: 1.35; } to { scale: 1.02; } }

  /* lively bursts turn slowly; the photograph inside stays upright */
  html[data-motion="lively"] .sec .fig[data-shape="burst"] .fig-media { animation: spin 70s linear infinite; }
  html[data-motion="lively"] .sec .fig[data-shape="burst"] .fig-media img {
    animation: parallax linear both, spin 70s linear infinite reverse;
    animation-timeline: --media, auto;
  }
}
@keyframes spin { to { rotate: 1turn; } }

/* ---------- living shapes and surfaces ---------- */

html:not([data-motion="still"]) .sec .fig[data-shape="blob"] .fig-media { animation: blob 18s ease-in-out infinite alternate; }
@keyframes blob {
  0%   { border-radius: 63% 37% 54% 46% / 55% 48% 52% 45%; }
  33%  { border-radius: 40% 60% 70% 30% / 50% 60% 30% 60%; }
  66%  { border-radius: 54% 46% 38% 62% / 49% 70% 30% 51%; }
  100% { border-radius: 61% 39% 52% 48% / 44% 59% 41% 56%; }
}

html[data-motion="lively"] body::after { animation: grain 1.1s steps(4) infinite; }
@keyframes grain {
  0%, 100% { background-position: 0 0; }
  25% { background-position: -37px 23px; }
  50% { background-position: 51px -41px; }
  75% { background-position: -13px 67px; }
}

/* ---------- marquee ---------- */

.s-work[data-variant="marquee"] .brand[data-rv] { opacity: 1; animation: none; }
html:not([data-motion="still"]) .s-work[data-variant="marquee"] .portfolio { animation: marquee 70s linear infinite; }
html[data-motion="lively"] .s-work[data-variant="marquee"] .portfolio { animation-duration: 48s; }
.s-work[data-variant="marquee"] .portfolio-frame:hover .portfolio { animation-play-state: paused; }
html[data-motion="still"] .s-work[data-variant="marquee"] .portfolio { flex-wrap: wrap; width: auto; }
html[data-motion="still"] .brand--clone { display: none; }
@keyframes marquee { to { translate: -50% 0; } }

/* ---------- small responses to the pointer ---------- */

html:not([data-motion="still"]) .s-specialties[data-variant="index"] .specialty-name { transition: translate .5s var(--ease), color .3s; }
html:not([data-motion="still"]) .s-specialties[data-variant="index"] .specialty:hover .specialty-name { translate: .18em 0; color: var(--accent); }
html:not([data-motion="still"]) :is(.s-specialties[data-variant="tiles"] .specialty, .s-work[data-variant="grid"] .brand) { transition: translate .35s var(--ease), rotate .35s var(--ease); }
html[data-motion="lively"] :is(.s-specialties[data-variant="tiles"] .specialty, .s-work[data-variant="grid"] .brand):hover { translate: 0 -6px; rotate: -1.2deg; }
html[data-motion="calm"] :is(.s-specialties[data-variant="tiles"] .specialty, .s-work[data-variant="grid"] .brand):hover { translate: 0 -3px; }

/* ---------- composer tip ----------
   The composer starts folded. Five seconds into the visit js/composer.js unhides "Remix the
   Site" over the fold: it pops up, then bounces every 2.4s until the bar is opened (which hides
   it for the rest of the visit). Each bounce crouches, leaps, lands, takes a smaller hop and
   settles. Rises ease out and falls ease in, like a ball under gravity. Unhiding restarts the
   animations, since a [hidden] element has no box. */

.composer-tip {
  animation:
    c-tip-in .5s cubic-bezier(.2, 1.4, .3, 1) backwards,
    c-tip-bounce 2.4s .8s infinite;
}
@keyframes c-tip-in { from { opacity: 0; transform: translateY(10px); scale: .6; } }
@keyframes c-tip-bounce {
  0%        { transform: translateY(0);     scale: 1;        animation-timing-function: ease-out; }
  6%        { transform: translateY(0);     scale: 1.08 .9;  animation-timing-function: cubic-bezier(.25, .6, .4, 1); }  /* crouch → leap */
  20%       { transform: translateY(-18px); scale: .97 1.04; animation-timing-function: cubic-bezier(.6, 0, .85, .4); }  /* apex → fall */
  32%       { transform: translateY(0);     scale: 1.08 .9;  animation-timing-function: cubic-bezier(.25, .6, .4, 1); }  /* land → hop */
  40%       { transform: translateY(-6px);  scale: 1;        animation-timing-function: cubic-bezier(.6, 0, .85, .4); }
  47%       { transform: translateY(0);     scale: 1.03 .97; animation-timing-function: ease-out; }                    /* settle */
  53%, 100% { transform: translateY(0);     scale: 1; }
}

/* ---------- composer menu flyout ----------
   Explore flies the word list up out of the bar: the panel grows from the button's corner, then
   the words cascade in (js/composer.js numbers them in --i; a group's label takes its first
   word's number). Closing drops it back; `display` transitions discretely so [hidden] waits for
   that, and browsers that can't transition `display` just close at once. */

.composer-panel {
  transform-origin: 2rem 100%;
  transition: opacity .2s, scale .45s var(--ease), translate .45s var(--ease);
}
@starting-style {
  .composer-panel { opacity: 0; scale: .92; translate: 0 14px; }
}
.composer-panel[hidden] {
  opacity: 0;
  scale: .97;
  translate: 0 8px;
  transition: opacity .18s, scale .2s, translate .2s, display .2s;
  transition-behavior: allow-discrete;
}
/* collapsing hides it at once, rather than squeezing it into the folding bar */
.composer.is-collapsed .composer-panel { transition: none; }
.composer-panel :is(.c-group-label, .c-chips > li) {
  animation: c-fly .4s var(--ease) backwards;
  animation-delay: calc(80ms + var(--i, 0) * 12ms);
}
@keyframes c-fly { from { opacity: 0; translate: 0 10px; } }

/* ---------- header: the primitives leave as it scrolls away; macro pulls back ---------- */

@supports (animation-timeline: view()) {
  html:not([data-motion="still"]) .hero { view-timeline: --hero block; }
  html:not([data-motion="still"]) .hero:not([data-variant="macro"]) [data-mark-hero] [data-prim] {
    animation: prim-out linear both;
    animation-timeline: --hero;
    animation-range: exit 0% exit 85%;
  }
  @keyframes prim-out { to { translate: var(--sx, 0) var(--sy, 0); rotate: var(--sr, 0deg); opacity: 0; } }

  html:not([data-motion="still"]) .hero[data-variant="macro"] { height: 240svh; padding: 0; }
  html:not([data-motion="still"]) .hero[data-variant="macro"] .hero-stage {
    position: sticky;
    top: var(--topbar-h);
    height: calc(100svh - var(--topbar-h));
    min-height: 0;
    overflow: hidden;
    align-content: center;
    padding: clamp(1.25rem, 4vw, 3rem) var(--gutter);
  }
  html:not([data-motion="still"]) .hero[data-variant="macro"] .hero-mark .mark {
    transform-origin: var(--fx, 50%) var(--fy, 50%);
    animation: macro-pull linear both;
    animation-timeline: --hero;
    animation-range: contain 0% contain 70%;
  }
  html:not([data-motion="still"]) .hero[data-variant="macro"] .hero-tag {
    animation: macro-tag linear both;
    animation-timeline: --hero;
    animation-range: contain 52% contain 78%;
  }
  @keyframes macro-pull { from { scale: var(--macro, 7); } to { scale: 1; } }
  @keyframes macro-tag { from { opacity: 0; translate: 0 28px; } }
}

html[data-motion="lively"] .hero[data-variant="field"] .hero-field { animation: field-drift 26s linear infinite; }
html[data-motion="calm"] .hero[data-variant="field"] .hero-field { animation: field-drift 60s linear infinite; }
@keyframes field-drift {
  to { -webkit-mask-position: var(--tile) 0; mask-position: var(--tile) 0; }
}

/* ---------- drift: speed shakes the page (js/drift.js sets --drift 0…1, --drift-dir ±1, --drift-phase) ---------- */

html.drifting .w { overflow: visible; } /* words fly free of their entrance masks */
html.drifting .display .w > span {
  translate: 0 calc(sin(calc(var(--drift-phase, 0) + var(--wi, 0) * .62)) * var(--drift, 0) * .34em);
}
html.drifting .display { transform: skewX(calc(var(--drift, 0) * var(--drift-dir, 1) * -10deg)); transform-origin: left center; }
html.drifting .fig-media { filter: hue-rotate(calc(var(--drift, 0) * var(--drift-dir, 1) * 70deg)) saturate(calc(1 + var(--drift, 0) * .8)); }
html.drifting body::after { opacity: calc(var(--grain) + var(--drift, 0) * .22); }
html.drifting .topbar [data-prim] {
  translate: calc(var(--px, 0px) * var(--drift, 0)) calc(var(--py, 0px) * var(--drift, 0));
  rotate: calc(var(--drift, 0) * var(--drift-dir, 1) * 25deg);
}

/* ---------- reduced motion: everything settles ---------- */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .js [data-rv],
  .js [data-rv] .w > span { opacity: 1 !important; animation: none !important; }
  .fig-media,
  .fig-media img,
  body::after,
  .portfolio,
  .bridge *,
  .composer-tip,
  .composer-panel :is(.c-group-label, .c-chips > li) { animation: none !important; }
  .composer,
  .composer-bar,
  .composer-tools,
  .composer-fields,
  .composer-panel,
  .c-fold path { transition: none !important; }
  .fig-media img { scale: 1 !important; translate: none !important; }
  .s-work[data-variant="marquee"] .portfolio { flex-wrap: wrap; width: auto; }
  .brand--clone { display: none; }
  .interlude[data-variant="zoom"] { height: auto !important; }
  .hero[data-variant="macro"] { height: auto !important; }
  .hero [data-prim],
  .hero-field,
  .hero .mark { animation: none !important; }
  .hero-guides line { animation: none !important; stroke-dashoffset: 0 !important; }
  html.drifting .display,
  html.drifting .display .w > span,
  html.drifting .topbar [data-prim] { transform: none !important; translate: none !important; rotate: none !important; }
  html.drifting .fig-media { filter: none !important; }
  .interlude[data-variant="zoom"] .fig--full { position: relative !important; }
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) { animation: none !important; }
}
