/* Движение. Только html.js[data-motion="full"]; в лёгком режиме и без JS всё статично.
   Путь 1 — animation-timeline; путь 2 — scroll.js перематывает анимации на паузе (currentTime). */

html.js[data-motion="full"] .cube { animation: spin 22s linear infinite; }
html.js[data-motion="full"] .stage { transform: rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)); transition: transform .3s ease-out; }

/* Сцена раскрытия: закреплена на 150vh, плитки раскладываются из сложенного куба. */
html.js[data-motion="full"] .reveal { display: block; height: 150vh; position: relative; }
html.js[data-motion="full"] .reveal__stage {
  position: sticky; top: 0; height: 100vh; height: 100svh; display: grid; place-items: center;
  padding: calc(var(--bar-h) + 16px) var(--gutter-r) 16px var(--gutter); perspective: 900px;
}
.unfold { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; width: min(100%, 720px); }
.tile { position: relative; border-radius: 14px; overflow: hidden; aspect-ratio: 16 / 9; border: 1px solid rgba(62, 240, 255, .6); box-shadow: 0 0 26px rgba(62, 240, 255, .25); }
.tile img { width: 100%; height: 100%; object-fit: cover; }
.tile span { position: absolute; left: 10px; bottom: 8px; font: 800 13px/1 var(--f-display); text-shadow: 0 1px 8px #000; }
.tile:nth-child(1) { --i: 0; --dx: 1; --dy: 1; }
.tile:nth-child(2) { --i: 1; --dx: -1; --dy: 1; }
.tile:nth-child(3) { --i: 2; --dx: 1; --dy: -1; }
.tile:nth-child(4) { --i: 3; --dx: -1; --dy: -1; }

html.js[data-motion="full"] .tile { animation: unfold 1s linear both paused; }
html.js[data-motion="full"] .card { opacity: 0; transform: translateY(48px); transition: opacity .6s ease-out, transform .6s cubic-bezier(.2, .7, .2, 1); }
html.js[data-motion="full"] .card.is-in { opacity: 1; transform: none; }

@supports (animation-timeline: view()) {
  html.js[data-motion="full"] .reveal { view-timeline-name: --reveal; }
  html.js[data-motion="full"] .tile {
    animation: unfold linear both; animation-play-state: running;
    animation-timeline: --reveal; animation-range: contain 0% contain 80%;
  }
  html.js[data-motion="full"] .portal__in {
    animation: lift linear both; animation-timeline: view(); animation-range: exit 20% exit 100%;
  }
  html.js[data-motion="full"] .card {
    opacity: 1; transform: none; transition: none;
    animation: rise linear both; animation-timeline: view(); animation-range: entry 0% entry 70%;
  }
  html.js[data-motion="full"] .card::after {
    animation: glow linear both; animation-timeline: view(); animation-range: entry 40% cover 50%;
  }
  html.js[data-motion="full"] .card__media img {
    animation: drift linear both; animation-timeline: view();
  }
}

@keyframes spin { from { transform: rotateX(-18deg) rotateY(32deg); } to { transform: rotateX(-18deg) rotateY(392deg); } }
@keyframes unfold {
  from { transform: translate(calc(var(--dx) * 52%), calc(var(--dy) * 52%)) rotateY(calc(var(--i) * 90deg)) scale(.42); opacity: .5; }
  60% { opacity: 1; }
  to { transform: none; opacity: 1; }
}
@keyframes lift { to { transform: translateY(-8vh) scale(.94); opacity: .25; } }
@keyframes rise { from { transform: translateY(56px) scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes glow { from { opacity: 0; } to { opacity: 1; } }
@keyframes drift { from { transform: translateY(-5%) scale(1.12); } to { transform: translateY(5%) scale(1.12); } }

/* Лёгкий режим и «уменьшить анимацию»: ничего не двигается. */
html[data-motion="lite"] .cube, html[data-motion="lite"] .card { animation: none; transition: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .reveal { display: none !important; }
  .card { opacity: 1 !important; transform: none !important; }
}
