/* Home hero: sprite-driven Momo. Shared tokens, header and buttons come from site.css.
   Performance rule for this file: anything that moves animates only transform and opacity, so the
   GPU compositor runs it without repainting. Blurs and shadows are baked into images up front. */

:root {
  /* --edge-top / --edge-bottom are overwritten at runtime with colours sampled from the frame edges */
  --edge-top: #3b1f0e;
  --edge-bottom: #1f0f07;
}

.hero {
  position: relative;
  height: 100svh;
  min-height: 560px;
  overflow: hidden;
  isolation: isolate;
  /* hero.js swaps this for one whose stops sit on the frame's own edges */
  background: linear-gradient(180deg, var(--edge-top), var(--edge-bottom));
  touch-action: pan-y;
}

/* ---------- stage ---------- */
.stage {
  position: absolute;
  inset: 0;
  z-index: 0;
  transform-origin: 50% 40%;
  will-change: transform; /* pages.js moves it on scroll */
}

/* Both sit exactly where the frame is drawn (hero.js sets left/top/width/height). The canvas holds
   frames at their native 848x464 and the GPU scales it up, which is free; scaling in JavaScript was
   the single most expensive thing on the page. */
.poster,
.sprite {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
}

/* A 64px-wide copy of the first frame, stretched: it is naturally blurry, so no live blur filter. */
.poster {
  object-fit: cover;
  transition: opacity 0.9s var(--ease-out);
}

.sprite {
  opacity: 0;
  transform: scale(1.025);
  transition: opacity 0.9s var(--ease-out), transform 1.6s var(--ease-out);
}

.hero.is-ready .sprite { opacity: 1; transform: none; }
.hero.is-ready .poster { opacity: 0; }

/* ---------- ambient 3D layer (hero-fx.js) ---------- */
.fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  perspective: 900px;
  opacity: 0;
  transition: opacity 1.6s var(--ease-out) 0.4s;
}
.hero.is-ready .fx { opacity: 1; }
.fx.is-paused * { animation-play-state: paused !important; }

/* Parallax wrappers: hero-fx.js nudges these with the cursor; children carry the CSS motion. */
.fx-par,
.bean,
.bean-bob {
  position: absolute;
  left: 0;
  top: 0;
  transform-style: preserve-3d;
  will-change: transform;
}
.fx-par { inset: 0; }

.bean-bob { animation: bean-bob var(--bob-dur) ease-in-out var(--delay) infinite alternate; }
.bean-spin {
  display: block;
  will-change: transform;
  animation: bean-spin var(--spin-dur) ease-in-out var(--delay) infinite alternate;
  animation-direction: var(--spin-dir, alternate);
}
@keyframes bean-bob {
  from { transform: translateY(calc(var(--bob) * -1)); }
  to { transform: translateY(var(--bob)); }
}
/* rocks within ±50°, so the flat artwork never turns edge-on and vanishes */
@keyframes bean-spin {
  from { transform: rotateZ(var(--rz0)) rotateX(-46deg) rotateY(-52deg); }
  50% { transform: rotateZ(calc(var(--rz0) + 18deg)) rotateX(12deg) rotateY(38deg); }
  to { transform: rotateZ(calc(var(--rz0) + 34deg)) rotateX(44deg) rotateY(-20deg); }
}

.speck {
  position: absolute;
  bottom: -12px;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 216, 165, 0.95), rgba(255, 180, 100, 0) 70%);
  opacity: 0;
  will-change: transform, opacity;
  animation: speck-rise var(--dur) linear var(--delay) infinite;
}
@keyframes speck-rise {
  0% { transform: translate(0, 0); opacity: 0; }
  15% { opacity: 0.85; }
  75% { opacity: 0.45; }
  100% { transform: translate(var(--drift), -95vh); opacity: 0; }
}

/* falling coffee: each piece falls (outer) while swaying and turning (inner) */
.fall {
  position: absolute;
  top: 0;
  will-change: transform, opacity;
  animation: dust-fall var(--dur) linear var(--delay) infinite;
}
.fall i {
  display: block;
  width: var(--size);
  height: var(--size);
  will-change: transform;
  animation: dust-sway var(--sway-dur) ease-in-out var(--delay) infinite alternate;
}
.fall .powder { border-radius: 50%; background: var(--c); }
.fall .grain { background: var(--img) center / contain no-repeat; }
@keyframes dust-fall {
  0% { transform: translateY(-6vh); opacity: 0; }
  10% { opacity: var(--a); }
  70% { opacity: var(--a); }
  100% { transform: translateY(var(--fall)); opacity: 0; }
}
@keyframes dust-sway {
  from { transform: translateX(calc(var(--sway) * -1)) rotate(0deg); }
  to { transform: translateX(var(--sway)) rotate(var(--turn)); }
}

/* steam wisps curling up the right-hand side (pre-blurred image, so only transform/opacity move) */
.steam-wisp {
  position: absolute;
  bottom: 4%;
  width: calc(130px * var(--s));
  height: calc(440px * var(--s));
  margin-left: calc(-65px * var(--s));
  background: var(--img) center / 100% 100% no-repeat;
  opacity: 0;
  will-change: transform, opacity;
  animation: wisp-rise var(--dur) ease-in-out var(--delay) infinite;
}
@keyframes wisp-rise {
  0% { transform: translate(0, 12%) scaleX(0.8); opacity: 0; }
  25% { opacity: 0.75; }
  60% { transform: translate(14px, -10%) scaleX(1.1); opacity: 0.55; }
  100% { transform: translate(-10px, -32%) scaleX(1.35); opacity: 0; }
}
/* phones have no empty side to rise through; it would drift over Momo and the headline */
@media (max-width: 720px) { .steam-wisp { display: none; } }

/* warm light that trails the cursor: a fixed gradient circle that moves, never repainted */
.glow {
  position: absolute;
  left: 0;
  top: 0;
  width: 80vmax;
  height: 80vmax;
  margin: -40vmax 0 0 -40vmax;
  pointer-events: none;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 190, 120, 0.16), rgba(255, 190, 120, 0.06) 35%, rgba(255, 190, 120, 0) 62%);
  opacity: 0;
  will-change: transform, opacity;
}

.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 75% 70% at 50% 45%, transparent 55%, rgba(10, 4, 1, 0.55)),
    linear-gradient(180deg, rgba(10, 4, 1, 0.45), transparent 22%, transparent 58%, rgba(10, 4, 1, 0.7));
}

/* ---------- copy ---------- */
.hero .copy {
  position: absolute;
  left: var(--gutter);
  bottom: clamp(28px, 7vh, 72px);
  z-index: 2;
  max-width: 520px;
  will-change: transform, opacity; /* pages.js fades it on scroll */
}

.hero h1 {
  margin: 0 0 26px;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(36px, 5.2vw, 72px);
  line-height: 1.02;
  letter-spacing: -0.025em;
  text-wrap: balance;
}
.hero h1 em { color: var(--accent); }
.hero .actions { display: flex; flex-wrap: wrap; gap: 12px; }

.hint {
  position: absolute;
  right: var(--gutter);
  bottom: clamp(28px, 7vh, 72px);
  z-index: 2;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--ink-soft);
  transition: opacity 0.8s var(--ease-out);
}
.hero.has-interacted .hint { opacity: 0; }

/* pulsing dot: the ring is a scaled pseudo-element, not an animated box-shadow (which repaints) */
.dot {
  position: relative;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
.dot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  animation: pulse 2.2s var(--ease-out) infinite;
}
@keyframes pulse {
  from { transform: scale(1); opacity: 0.7; }
  to { transform: scale(3.4); opacity: 0; }
}

/* load progress hairline */
.loader {
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  z-index: 3;
  transition: opacity 0.6s var(--ease-out) 0.3s;
}
.loader span {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform-origin: left;
  transform: scaleX(var(--progress, 0));
  transition: transform 0.25s linear;
}
.hero.is-ready .loader { opacity: 0; }

@media (max-width: 720px) {
  .hero .copy { right: var(--gutter); }
  .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sprite, .poster { transition-duration: 0.01s; }
  .dot::after, .bean-bob, .bean-spin, .fall, .fall i, .speck, .steam-wisp { animation: none; }
  .speck, .steam-wisp, .fall { display: none; }
}
