/* Homepage hero: the Falmera mountain sunrise (docs/homepage-hero.md).
 * One photograph moves as a single plate. The layers on top of it (letter light, mist, petals,
 * shade) are drawn separately, so no part of the picture is cut out or shifted against itself.
 * Every moving property is translate, scale or opacity. --fm-hero-p (0 at the top, 1 when the hero has
 * scrolled away) comes from js/falmera-scroll-motion.js; --mx/--my (pointer, -0.5..0.5) from
 * js/falmera-hero-scene.js. Without JavaScript, or with reduced motion, both stay 0: a still picture. */
.fm-home .hero {
  position: relative; overflow: hidden; background: #10162a; min-height: 100svh;
  align-items: flex-end;
  padding-block: calc(var(--fm-header-h) + 1.5rem) clamp(3rem, 1.5rem + 6svh, 6.5rem);
}
.fm-home .hero::before { background: none; }   /* the old cream veil */
.fm-home .hero-content { position: relative; z-index: 1; }

.fm-hero__scene {
  position: absolute; inset: 0; z-index: -1; overflow: hidden; pointer-events: none;
  container-type: size;
}
/* The picture's box: covers the hero (like object-fit: cover). It is shifted so the lettering (its centre
   is 60.75% across the picture) sits in the middle of the screen, as far as the picture's edges allow. */
.fm-hero__frame {
  --w: max(100cqw, 177.7cqh);
  --h: calc(var(--w) * 941 / 1672);
  position: absolute; width: var(--w); height: var(--h);
  left: clamp(100cqw - var(--w), 50cqw - var(--w) * 0.6075, 0px);
  top: calc((100cqh - var(--h)) * 0.5);
}
.fm-hero__img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; max-width: none; border-radius: 0; }

/* Ambient light over the lettering, and a slow light that crosses the letters only (masked to them). */
.fm-hero__aura {
  position: absolute; left: 27%; top: 25%; width: 68%; height: 36%;
  background: radial-gradient(closest-side, rgb(146 92 255 / 0.42), rgb(103 39 232 / 0.16) 58%, transparent);
  mix-blend-mode: screen; opacity: 0.55;
}
.fm-hero__letters {
  position: absolute; left: 30.98%; top: 33.9%; width: 59.51%; height: 16.05%; overflow: hidden;
  -webkit-mask: url("../assets/img/hero/falmera-letters-mask.png") 0 0 / 100% 100% no-repeat;
  mask: url("../assets/img/hero/falmera-letters-mask.png") 0 0 / 100% 100% no-repeat;
  mix-blend-mode: screen;
}
.fm-hero__letters::before {
  content: ""; position: absolute; top: -10%; bottom: -10%; left: 0; width: 26%;
  background: linear-gradient(100deg, transparent 10%, rgb(214 226 255 / 0.85) 50%, transparent 90%);
  translate: -110% 0;
}

/* Soft valley mist, in front of the picture. */
.fm-hero__mist i {
  position: absolute; border-radius: 50%;
  background: radial-gradient(closest-side, rgb(255 226 238 / 0.5), rgb(255 226 238 / 0.18) 55%, transparent);
}
.fm-hero__mist i:nth-child(1) { left: -8%; top: 54%; width: 62%; height: 20%; }
.fm-hero__mist i:nth-child(2) { left: 46%; top: 60%; width: 70%; height: 22%; opacity: 0.8; }
.fm-hero__mist i:nth-child(3) { left: 14%; top: 74%; width: 64%; height: 22%; opacity: 0.65; }

.fm-hero__petals { position: absolute; inset: 0; width: 100%; height: 100%; }

/* Shade only where the text sits: a little under the header, more behind the copy at the bottom left. */
.fm-hero__shade {
  position: absolute; inset: 0;
  background:
    linear-gradient(180deg, rgb(16 22 42 / 0.5) 0, rgb(16 22 42 / 0) calc(var(--fm-header-h) + 4rem)),
    radial-gradient(75% 62% at 0% 100%, rgb(16 22 42 / 0.62), rgb(16 22 42 / 0) 72%),
    linear-gradient(0deg, rgb(16 22 42 / 0.7) 0, rgb(16 22 42 / 0.32) 24%, rgb(16 22 42 / 0) 46%);
}
/* Deepens to navy as the hero scrolls away, so the scene hands over to the page below. */
.fm-hero__dim { position: absolute; inset: 0; background: #10162a; opacity: 0; }

/* Portrait and near-square screens: the whole lettering across the top, the copy underneath. */
@media (max-aspect-ratio: 23/20) {
  .fm-hero__frame { --w: 150cqw; top: 0; }   /* the lettering spans 89% of the width */
  .fm-hero__plate {
    -webkit-mask-image: linear-gradient(180deg, #000 66%, transparent 98%);
    mask-image: linear-gradient(180deg, #000 66%, transparent 98%);
  }
  .fm-hero__mist i:nth-child(3) { display: none; }
  .fm-hero__shade {
    background: linear-gradient(180deg, rgb(16 22 42 / 0.5) 0, rgb(16 22 42 / 0) calc(var(--fm-header-h) + 2rem));
  }
  .fm-home .hero { min-height: 0; align-items: flex-start; padding-block: calc(150vw * 941 / 1672 * 0.8) 4.5rem; }
  .fm-home .hero .fm-hero__copy { width: auto; max-width: 34rem; }
  /* The valley below the lettering fills the rest of a tall screen, as the whole painting does on desktop: the lower
     half of the same picture (river, mist and blossoms), drawn closer, melting up into the plate. */
  .fm-hero__scene::before {
    content: ""; position: absolute; left: 0; right: 0; bottom: 0; top: calc(150cqw * 941 / 1672 * 0.5);
    background: url("../assets/img/hero/falmera-mountain-1672.webp") 46% 100% / auto 205% no-repeat;
    -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 26%); mask-image: linear-gradient(180deg, transparent 0, #000 26%);
  }
}
/* Touch screens have no pointer to follow, so the plate drifts on its own, a slow look across the range. */
@media (prefers-reduced-motion: no-preference) and (hover: none) {
  .fm-hero__plate { animation: fm-hero-look 16s ease-in-out infinite alternate; }
  .fm-hero__scene::before { animation: fm-hero-look-near 16s ease-in-out infinite alternate; }
  .hero.is-paused .fm-hero__plate, .hero.is-paused .fm-hero__scene::before { animation-play-state: paused; }
  @keyframes fm-hero-look { from { transform: translate(-1.6%, 0); } to { transform: translate(1.6%, -0.8%); } }
  @keyframes fm-hero-look-near { from { transform: translate(-2.4%, 0) scale(1.02); } to { transform: translate(2.4%, -1.2%) scale(1.04); } }
}

/* Motion: only with JavaScript running and motion allowed. */
@media (prefers-reduced-motion: no-preference) {
  .fm-home .hero { --p: var(--fm-hero-p, 0); }
  .fm-hero__plate {
    transform-origin: 61% 42%;
    translate: calc(var(--mx, 0) * -14px) calc(var(--p) * 10cqh + var(--my, 0) * -8px);
    scale: calc(1 + var(--p) * 0.08);
  }
  .fm-hero__mist { translate: calc(var(--mx, 0) * -26px) calc(var(--p) * -5cqh + var(--my, 0) * -12px); }
  .fm-hero__petals { translate: calc(var(--mx, 0) * -40px) calc(var(--p) * -18cqh); }
  .fm-hero__dim { opacity: calc(var(--p) * 0.75); }
  .fm-home .hero .fm-hero__copy { translate: 0 calc(var(--p) * -10svh); opacity: calc(1 - var(--p) * 1.4); }

  /* The camera settles into the scene on arrival. */
  .hero-wait .fm-hero__img { scale: 1.08; }
  .hero-go .fm-hero__img { scale: 1; transition: scale 1.8s cubic-bezier(0.22, 1, 0.36, 1); }

  .fm-hero__aura { animation: fm-hero-aura 6s ease-in-out infinite alternate; }
  .fm-hero__letters::before { animation: fm-hero-sweep 8s cubic-bezier(0.45, 0, 0.3, 1) 1.4s infinite; }
  .fm-hero__mist i:nth-child(1) { animation: fm-hero-mist 34s ease-in-out infinite alternate; }
  .fm-hero__mist i:nth-child(2) { animation: fm-hero-mist 42s ease-in-out -12s infinite alternate-reverse; }
  .fm-hero__mist i:nth-child(3) { animation: fm-hero-mist 50s ease-in-out -20s infinite alternate; }
  .hero.is-paused :is(.fm-hero__aura, .fm-hero__mist i) { animation-play-state: paused; }
  .hero.is-paused .fm-hero__letters::before { animation-play-state: paused; }

  @keyframes fm-hero-aura { from { opacity: 0.45; } to { opacity: 0.95; } }
  @keyframes fm-hero-sweep { 0% { translate: -110% 0; } 42%, 100% { translate: 400% 0; } }
  @keyframes fm-hero-mist { from { translate: -6% 0; } to { translate: 9% -4%; } }
}

/* entrance: only hidden when the script is running, so the text can never get stuck invisible */
.hero-wait [data-hero-in] { opacity: 0; transform: translateY(18px); }
.hero-go [data-hero-in] {
  opacity: 1; transform: none;
  transition: opacity 0.7s cubic-bezier(0.22, 1, 0.36, 1), transform 0.8s cubic-bezier(0.22, 1, 0.36, 1);
  transition-delay: calc(0.25s + var(--i, 0) * 0.15s);
}
@media (prefers-reduced-motion: reduce) {
  .hero-wait [data-hero-in] { opacity: 1; transform: none; }
  .hero-go [data-hero-in] { transition: none; }
}

/* Light copy over the scene. Type, sizes and buttons are unchanged. */
.fm-home .hero { --fm-focus: #FFF1E4; --fm-text: #FFF1E4; --fm-border-strong: rgb(255 241 228 / 0.32); }
.fm-home .hero :is(.fm-hero__title, .fm-hero__accent, .fm-hero__lead, .fm-hero__work-link) { color: #FFF1E4; }
.fm-home .hero :is(.fm-hero__title, .fm-hero__lead) { text-shadow: 0 1px 18px rgb(16 22 42 / 0.45); }
.fm-home .hero .fm-hero__work-link:hover { color: var(--fm-sand); }
.fm-home .hero :is(a, button):focus-visible { outline-color: #FFF1E4; }
