/* Scroll animation layer (hero.motion = "on"; html.motion-on is set in <head>
   unless the visitor prefers reduced motion). motion/motion.js drives it.
   Everything here is scoped to html.motion-on, so with the setting off, with
   reduced motion, or if the script fails, the page renders as before.
   html.motion-3d (desktop, fine pointer) adds the building's scroll journey. */

/* ── Backdrop ────────────────────────────────────────────────────────
   Section colours are painted on one fixed layer (cross-faded by scroll), so
   the building layer can show through transparent sections. Backdrop (-2)
   and building layer (-1) sit under the page content without making <main>
   a stacking context, so the brand mark can blend with the backdrop. */
.m3d-backdrop {
  position: fixed;
  inset: 0;
  z-index: -2;
  overflow: hidden;
  pointer-events: none;
  background: var(--bg-warm);
}

.m3d-backdrop > div {
  position: absolute;
  inset: -48px;
  will-change: transform;
}

.m3d-glow {
  background:
    radial-gradient(ellipse 42% 38% at 68% 42%, var(--m3d-glow, rgba(255, 255, 255, 0.8)) 0%, rgba(255, 255, 255, 0) 70%),
    radial-gradient(ellipse 30% 30% at 18% 78%, var(--m3d-glow-2, rgba(255, 255, 255, 0.45)) 0%, rgba(255, 255, 255, 0) 70%);
}

/* Section colours: one solid band per section, placed by transform only
   (motion.js paintBackdrop), so scrolling never repaints the backdrop. */
.m3d-backdrop > .m3d-bands {
  inset: 0;
  will-change: auto;
}

.m3d-band {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  transform: scale3d(1, 0, 1);
  transform-origin: 0 0;
  will-change: transform;
}

/* Dotted drafting grid: dark and light dots cross-fade by opacity. */
.m3d-dots {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, rgba(26, 26, 26, 0.12) 1px, transparent 1.5px);
  background-size: 24px 24px;
  will-change: opacity;
}

.m3d-dots-light {
  background-image: radial-gradient(circle, rgba(255, 255, 255, 0.09) 1px, transparent 1.5px);
  opacity: 0;
}

.m3d-grid {
  -webkit-mask-image: radial-gradient(ellipse 85% 75% at 55% 45%, #000 35%, transparent 100%);
  mask-image: radial-gradient(ellipse 85% 75% at 55% 45%, #000 35%, transparent 100%);
}

/* Film grain */
.m3d-grain {
  opacity: 0.07; /* eased toward 0.04 over dark sections by motion.js */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.9 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

html.motion-on .hero.hero-3d,
html.motion-on .section-warm,
html.motion-on .section-white,
html.motion-on .section-dark,
html.motion-on .image-section {
  background: transparent;
}

/* While the building is interactive, empty parts of the page let the pointer
   through to it; text, links, controls and cards still take it. */
html.motion-3d.m3d-interactive body,
html.motion-3d.m3d-interactive main,
html.motion-3d.m3d-interactive main * {
  pointer-events: none;
}

html.motion-3d.m3d-interactive body > :not(main, .m3d-backdrop) {
  pointer-events: auto;
}

html.motion-3d.m3d-interactive main :is(a, button, input, textarea, select, label, summary, form, iframe, video,
  p, h1, h2, h3, h4, h5, h6, li, dt, dd, blockquote, figure, img, svg, [tabindex], [onclick],
  .service-card, .fixed-fee-card, .recommendation-card, .case-study-card, .stat-item, .logo-strip) {
  pointer-events: auto;
}

/* The hero's own stage (poster, hint) sits over the building: never in the way. */
html.motion-3d main .hero3d,
html.motion-3d main .hero3d * {
  pointer-events: none !important;
}

/* ── Building scenes (inserted by motion.js, desktop only) ─────────── */
/* The explore scene follows About directly: trim the gap between them. */
html.motion-3d #about {
  padding-bottom: 2rem;
}

.m3d-scene {
  position: relative;
  height: 330vh;
}

.m3d-scene-sticky {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 0.78fr) minmax(0, 1.22fr);
  align-items: start; /* top-aligned, so the scene starts right after About */
  gap: 2rem;
  max-width: calc(var(--max-width) + 2 * var(--content-padding));
  margin: 0 auto;
  padding: calc(72px + 2.5rem) var(--content-padding) 0;
}

.m3d-slot {
  height: min(72vh, 720px);
}

.m3d-scene-copy {
  max-width: 30rem;
}

.m3d-scene-copy .section-title {
  margin-bottom: 1rem;
}

.m3d-scene-meta {
  font-family: var(--font-mono);
  font-size: var(--text-overline);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin: 0 0 1.75rem;
}

.m3d-scene-stats {
  display: grid;
  grid-template-columns: repeat(3, auto);
  justify-content: start;
  gap: 0.25rem 2.25rem;
  margin: 0 0 2rem;
}

.m3d-scene-stats dt {
  order: 2;
  font-size: var(--text-caption);
  color: var(--text-tertiary);
}

.m3d-scene-stats div {
  display: flex;
  flex-direction: column;
}

.m3d-scene-stats dd {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 2.6vw, 2.25rem);
  font-weight: 700;
  line-height: 1.1;
  color: var(--text-primary);
}

.m3d-floors {
  list-style: none;
  margin: 0 0 1.75rem;
  padding: 0;
  border-top: 1px solid var(--surface-border);
}

.m3d-floors li {
  border-bottom: 1px solid var(--surface-border);
  border-left: 3px solid transparent;
  font-size: var(--text-small);
  color: var(--text-tertiary);
  transition: color 0.3s ease, border-color 0.3s ease, background-color 0.3s ease;
}

.m3d-floor {
  display: flex;
  gap: 1rem;
  align-items: baseline;
  width: 100%;
  padding: 0.55rem 0 0.55rem 0.75rem;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
}

button.m3d-floor {
  cursor: pointer;
}

button.m3d-floor:hover {
  color: var(--text-primary);
}

button.m3d-floor:focus-visible {
  outline: 2px solid var(--text-primary);
  outline-offset: -2px;
}

.m3d-floors li span {
  font-family: var(--font-mono);
  font-size: var(--text-overline);
  color: var(--text-muted);
  min-width: 1.75rem;
}

.m3d-floors li.is-on {
  color: var(--text-primary);
  border-left-color: var(--ai-accent);
  background: linear-gradient(90deg, rgba(224, 240, 125, 0.35), rgba(224, 240, 125, 0));
}

.m3d-scene-hint {
  font-family: var(--font-mono);
  font-size: var(--text-overline);
  letter-spacing: var(--tracking-wide);
  color: var(--text-tertiary);
  margin: 0;
}

/* Scene copy eases in as the scene pins */
.m3d-scene-copy > * {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.9s var(--ease-out-expo), transform 0.9s var(--ease-out-expo);
}

.m3d-scene.is-in .m3d-scene-copy > * {
  opacity: 1;
  transform: none;
}

.m3d-scene.is-in .m3d-scene-copy > :nth-child(2) { transition-delay: 0.06s; }
.m3d-scene.is-in .m3d-scene-copy > :nth-child(3) { transition-delay: 0.12s; }
.m3d-scene.is-in .m3d-scene-copy > :nth-child(4) { transition-delay: 0.18s; }
.m3d-scene.is-in .m3d-scene-copy > :nth-child(5) { transition-delay: 0.24s; }
.m3d-scene.is-in .m3d-scene-copy > :nth-child(6) { transition-delay: 0.3s; }

/* ── Floating cards ─────────────────────────────────────────────────── */
.m3d-deck {
  perspective: 1600px;
  perspective-origin: 50% 40%;
}

/* Transforms and opacity are written per frame; no CSS easing on top. */
html.motion-on .m3d-card {
  transform-style: preserve-3d;
  will-change: transform;
  backface-visibility: hidden;
  transition: border-color var(--transition), box-shadow var(--transition) !important;
}

html.motion-on .m3d-card.fade-in {
  opacity: 1;
}

html.motion-on .m3d-card:is(.service-card, .fixed-fee-card, .recommendation-card) {
  box-shadow: 0 18px 40px -22px rgba(26, 26, 26, 0.28);
}

html.motion-on .m3d-card:is(.service-card, .fixed-fee-card, .recommendation-card):hover {
  box-shadow: 0 28px 56px -24px rgba(26, 26, 26, 0.38);
}

/* On the dark band (Why Firms Engage) the cards keep a dark ground over the
   blueprint behind them. */
html.motion-on .section-dark .m3d-card.recommendation-card {
  background: rgba(26, 26, 26, 0.78);
  box-shadow: 0 18px 40px -22px rgba(0, 0, 0, 0.7);
}

html.motion-on .section-dark .m3d-card.recommendation-card:hover {
  box-shadow: 0 28px 56px -24px rgba(0, 0, 0, 0.8);
}

/* The brand mark GIF has a white ground; let the backdrop through. */
html.motion-on .image-section img {
  mix-blend-mode: multiply;
  will-change: transform;
}

/* Fixed-fee cylinder (motion.js setupCarousel, ≥700px wide) */
.m3d-cyl {
  position: relative;
}

.m3d-cyl-pin {
  position: sticky;
  top: 0;
  height: 100vh;
  width: 100vw;
  margin-left: calc(50% - 50vw);
  overflow: clip;
  display: flex;
  flex-direction: column;
  padding: calc(72px + 1.25rem) 0 0.75rem;
}

.m3d-cyl-pin .fixed-fee-heading {
  text-align: center;
  margin: 0;
}

.m3d-cyl-ring {
  position: relative;
  flex: 1;
  perspective: 1800px;
  perspective-origin: 50% 45%;
}

html.motion-on .m3d-cyl-grid {
  display: block;
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

.m3d-cyl-slot {
  position: absolute;
  left: 50%;
  top: 50%;
  backface-visibility: hidden;
  will-change: transform;
}

/* Width and zoom (the lens) are set by motion.js. */
html.motion-on .m3d-cyl-card {
  width: 340px;
  background: var(--bg-white);
  will-change: auto;
}

/* The fixed-fee closing line, under the cylinder in the pinned panel */
.m3d-cyl-pin .m3d-cyl-note {
  max-width: 62ch;
  margin: 0 auto;
  padding: 0 var(--content-padding);
  text-align: center;
}

/* Hero hint hides once the scroll starts (motion.js paintHeroText). */
.hero3d-ready.m3d-hint-out::after {
  opacity: 0;
}

/* About: paragraphs fly in from beyond the edges of the screen, stat tiles
   zoom in. The slide decelerates hard; the fade and the motion blur run on a
   gentler curve over most of the flight, so a paragraph sharpens and reaches
   full strength as it settles rather than long before. The section clips
   sideways (clip, not hidden, so nothing becomes a scroll container). */
html.motion-on #about {
  overflow-x: clip;
}

html.motion-on .m3d-slide {
  opacity: 0;
  filter: blur(8px);
  transition:
    transform 1.5s cubic-bezier(0.33, 1, 0.68, 1),
    opacity 1.1s cubic-bezier(0.37, 0, 0.63, 1),
    filter 1.1s cubic-bezier(0.37, 0, 0.63, 1);
}

html.motion-on .m3d-from-left { transform: translateX(-100vw) skewX(-8deg); }
html.motion-on .m3d-from-right { transform: translateX(100vw) skewX(8deg); }

html.motion-on .m3d-slide.is-in {
  opacity: 1;
  filter: none;
  transform: none;
}

.m3d-zoom-grid {
  perspective: 900px;
}

html.motion-on .m3d-zoom-grid .stat-item {
  opacity: 0;
  transform: translateZ(-260px) scale(0.7);
  filter: blur(6px);
  transition: opacity 0.9s var(--ease-out-expo), transform 1.1s var(--ease-out-expo), filter 0.9s var(--ease-out-expo);
}

html.motion-on .m3d-zoom-grid.is-in .stat-item {
  opacity: 1;
  transform: none;
  filter: none;
}

/* ── Key moments ────────────────────────────────────────────────────── */
html.motion-on .section-dark .case-study-metric-number {
  color: var(--ai-accent);
}

.m3d-reveal {
  opacity: 0;
  transform: translateY(28px);
  transition: opacity 1s var(--ease-out-expo), transform 1s var(--ease-out-expo);
}

.m3d-reveal.is-in {
  opacity: 1;
  transform: none;
}

/* ── Sound toggle (nav) ─────────────────────────────────────────────── */
.m3d-sound {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-right: 0.5rem;
  padding: 0;
  border: 1px solid var(--surface-border);
  border-radius: 50%;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition), background-color var(--transition);
}

.m3d-sound:hover {
  color: var(--text-primary);
  border-color: var(--surface-border-hover);
}

.m3d-sound[aria-pressed="true"] {
  color: var(--text-primary);
  background: var(--ai-accent);
  border-color: transparent;
}

.m3d-sound svg {
  width: 17px;
  height: 17px;
}

.m3d-sound .m3d-sound-waves { display: none; }
.m3d-sound[aria-pressed="true"] .m3d-sound-waves { display: inline; }
.m3d-sound[aria-pressed="true"] .m3d-sound-mute { display: none; }

.m3d-sound:focus-visible {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}
