/*
 * Ivenku shared motion layer: the base states every preset builds on.
 * Plan and rules: docs/plans/template-motion-plan.md.
 *
 * Contract (set by an engine adapter, never by hand in a design's stylesheet):
 *   html[data-motion]          full | soft | off, resolved by motion.js
 *   [data-m~="masuk"]          a container whose [data-m-item] children enter when it is seen
 *   [data-m-item="variant"]    one entering child; the preset styles each variant
 *   [data-m~="hidup"]          an ambient loop, running only while on screen (.m-run)
 *   [data-m~="sorot"]          a one-off highlight when first seen
 *
 * Shared variant names. Every preset gives each of these its own look, so an adapter only says
 * WHAT an element is and never needs to know which preset the design uses:
 *   items  (none)  text and blocks        card   a card or panel      photo  a photo or emblem
 *   hidup  frame   border or corner art   sway   foliage, hanging     float  free-floating art
 *   sorot  names   the couple's names     count  a countdown
 *
 * Every hidden state uses the individual `translate`, `scale` and `rotate` properties, never
 * `transform`, so it composes with whatever transform the design already gives the element (a
 * tilted stamp stays tilted). For the same reason no rule may set `transform-origin` on a marked
 * element: the design's transform shares it, and changing it moves the element. The entering transition only exists until the container is marked
 * .m-done, so it never replaces the design's own hover transitions for longer than the entrance.
 *
 * Specificity is deliberately high: some designs blanket-disable motion under
 * prefers-reduced-motion with `* { transition: none !important }`. The plan's decision is that
 * reduced motion means "soft", not "off", so the soft rules below must out-rank those.
 */

:root {
  --m-ease: cubic-bezier(.22, .61, .36, 1);
  --m-ease-out: cubic-bezier(.16, 1, .3, 1);
  --m-dur: 620ms;
  --m-step: 80ms;
  --m-rise: 16px;
  --m-paper: #f4efe6;
  --m-ink: #2b2b2b;
  --m-accent: #a8432f;
  --m-buka-reveal: 500;
}

/* ── Masuk: entering children ─────────────────────────────────────────── */

/* A container or item the design was hiding for its own scroll reveal. The adapter hands it to
   this layer (.m-owned) so the two reveals do not stack; ours then decides when it appears. */
html[data-motion] .m-owned {
  opacity: 1 !important;
  transform: none !important;
}

html[data-motion="full"] [data-m~="masuk"]:not(.m-in) [data-m-item] {
  opacity: 0 !important;
  translate: 0 var(--m-rise);
}

html[data-motion="full"] [data-m~="masuk"].m-in:not(.m-done) [data-m-item] {
  transition-property: opacity, translate, scale, rotate, clip-path, filter !important;
  transition-duration: var(--m-dur) !important;
  transition-timing-function: var(--m-ease-out) !important;
  transition-delay: calc(var(--m-i, 0) * var(--m-step) + var(--m-after, 0ms)) !important;
}

/* Soft: opacity and a short rise only. Same timing contract, half the travel, no variants. */
html[data-motion="soft"] [data-m~="masuk"]:not(.m-in) [data-m-item] {
  opacity: 0 !important;
  translate: 0 8px !important;
  clip-path: none !important;
  filter: none !important;
  scale: none !important;
}

html[data-motion="soft"] [data-m~="masuk"].m-in:not(.m-done) [data-m-item] {
  transition-property: opacity, translate !important;
  transition-duration: 420ms !important;
  transition-timing-function: ease-out !important;
  transition-delay: calc(var(--m-i, 0) * 60ms + var(--m-after, 0ms)) !important;
}

/* ── Hidup: ambient loops ─────────────────────────────────────────────── */

[data-m~="hidup"] {
  animation-play-state: paused !important;
}

html[data-motion="full"] [data-m~="hidup"].m-run {
  animation-play-state: running !important;
}

html:not([data-motion="full"]) [data-m~="hidup"] {
  animation: none !important;
}

/* ── Sorot: one-off highlights ────────────────────────────────────────── */

html[data-motion="full"] [data-m~="sorot"]:not(.m-in) {
  opacity: 0;
}

html[data-motion="soft"] [data-m~="sorot"]:not(.m-in) {
  opacity: 0 !important;
}

html[data-motion="soft"] [data-m~="sorot"].m-in {
  animation: m-fade 420ms ease-out both !important;
}

@keyframes m-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Buka: the opening layer motion.js adds for one moment ───────────── */

.m-buka-layer {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  pointer-events: none;
  overflow: hidden;
  contain: strict;
}

.m-buka-layer > i {
  position: absolute;
  display: block;
}

/* The once-only petal shower some presets scatter after opening (motion.js, --m-petals). */
.m-petals {
  position: fixed;
  inset: 0;
  z-index: 2147482000;
  pointer-events: none;
  overflow: hidden;
  contain: strict;
}

.m-petals > i {
  position: absolute;
  top: -6vh;
  display: block;
}

/* ── Engine hooks ── */

/* Ragam's vanilla.js measures each slide (title fitting, contrast) under .vanilla-measuring with
   every transition off. Items must be at rest for that, or a line is judged against what sits
   16px below it. The class is added and removed in one task, so this never paints. */
html[data-motion] :is(.vanilla-measuring[data-m~="masuk"], .vanilla-measuring [data-m~="masuk"]):not(.m-in) [data-m-item] {
  opacity: 1 !important;
  translate: none !important;
  scale: none !important;
  rotate: none !important;
  clip-path: none !important;
  filter: none !important;
}

/* Print and no-JS: everything in its final place. */
@media print {
  [data-m-item], [data-m~="sorot"] {
    opacity: 1 !important;
    translate: none !important;
    clip-path: none !important;
    filter: none !important;
  }
  .m-buka-layer { display: none !important; }
}

/* ── Sambut: the cover as the page appears, the hero as it opens (motion.js stage()) ──
   Each part enters in role order (--m-r); at full it then keeps a slow loop while its stage is on
   screen (.m-run). Entrances fill backwards only, so once a part has landed none of these values
   stay on it. A preset may restyle a role through the same custom properties. */
html:not([data-motion="off"]) [data-m-s]:not(.m-in) [data-m-r] {
  opacity: 0 !important;
}

html[data-motion="full"] [data-m-s].m-in [data-m-r] {
  --m-s-at: calc(var(--m-r, 0) * 110ms + var(--m-after, 0ms));
  animation-name: var(--m-s-a, m-s-up), var(--m-s-l, none) !important;
  animation-duration: var(--m-s-d, 800ms), var(--m-s-ld, 8s) !important;
  animation-timing-function: var(--m-ease-out), ease-in-out !important;
  animation-delay: var(--m-s-at), calc(var(--m-s-at) + var(--m-s-d, 800ms)) !important;
  animation-iteration-count: 1, infinite !important;
  animation-direction: normal, alternate !important;
  animation-fill-mode: backwards, none !important;
  animation-play-state: running, paused !important;
}

html[data-motion="full"] .m-clip { overflow-x: clip; }

html[data-motion="full"] [data-m-s].m-in.m-run [data-m-r] {
  animation-play-state: running, running !important;
}

/* A stage that holds the RSVP form, gift details or wishes enters but never loops (plan §1). */
html[data-motion="full"] [data-m-s][data-m-calm].m-in [data-m-r] {
  animation-name: var(--m-s-a, m-s-up), none !important;
}

html[data-motion="soft"] [data-m-s].m-in [data-m-r] {
  animation: m-fade 420ms ease-out calc(var(--m-r, 0) * 60ms + var(--m-after, 0ms)) backwards !important;
}

[data-m-r="orn"]        { --m-s-a: m-s-orn; --m-s-d: 1000ms; --m-s-l: m-s-drift; }
[data-m-r="orn-big"]    { --m-s-a: m-s-big; --m-s-d: 1100ms; --m-s-l: m-s-breathe; --m-s-ld: 11s; }
[data-m-r="photo"]      { --m-s-a: m-s-iris; --m-s-d: 1200ms; --m-s-l: m-s-breathe; --m-s-ld: 10s; }
[data-m-r="photo-soft"] { --m-s-a: m-s-big; --m-s-d: 1100ms; --m-s-l: m-s-breathe; --m-s-ld: 10s; }
[data-m-r="names"]      { --m-s-a: m-s-name; --m-s-d: 1000ms; }
/* The open button grows in place: a rising entrance pushed it below the fold at 360×640 (CODEX-297). */
[data-m-r="btn"]        { --m-s-a: m-s-pop; --m-s-l: m-s-nudge; --m-s-ld: 1.4s; }

@keyframes m-s-up    { from { opacity: 0; translate: 0 12px; } }
@keyframes m-s-pop   { from { opacity: 0; scale: .92; } }
@keyframes m-s-orn   { from { opacity: 0; scale: .8; rotate: -7deg; translate: 0 14px; } }
@keyframes m-s-big   { from { opacity: 0; scale: 1.06; } }
@keyframes m-s-iris  { from { opacity: 0; scale: 1.08; clip-path: circle(0% at 50% 50%); } 45% { opacity: 1; } to { clip-path: circle(75% at 50% 50%); } }
@keyframes m-s-name  { from { opacity: 0; translate: 0 .45em; filter: blur(6px); clip-path: inset(-40% -20% 100% -20%); } to { clip-path: inset(-40% -20% -40% -20%); } }
@keyframes m-s-drift { to { rotate: 1.5deg; translate: 0 -5px; } }
@keyframes m-s-breathe { to { scale: 1.035; } }
@keyframes m-s-nudge { to { scale: 1.045; } }

@media print {
  [data-m-r] { opacity: 1 !important; animation: none !important; }
}
