/* AI Edu LK · motion.css v3
   Optional motion layer applied on top of base.css.
   Adds: scroll-reveal, hover utilities, page transition, heraldic cursor.
   Pair with the IntersectionObserver snippet at the bottom of this file. */

/* ===========================================================
   A. SCROLL-REVEAL
   Default state hidden via .reveal; activated via .in (toggled by IO).
   =========================================================== */

.reveal {
  opacity: 0;
  transform: translateY(24px);
  transition:
    opacity     800ms var(--ease-enter),
    transform   800ms var(--ease-enter);
  will-change: opacity, transform;
}
.reveal.in {
  opacity: 1;
  transform: translateY(0) translateX(0);
}

/* directional variants — same timing, different axis */
.reveal-up {
  opacity: 0;
  transform: translateY(40px);
  transition:
    opacity     800ms var(--ease-enter),
    transform   800ms var(--ease-enter);
}
.reveal-up.in { opacity: 1; transform: translateY(0); }

.reveal-left {
  opacity: 0;
  transform: translateX(-32px);
  transition:
    opacity     800ms var(--ease-enter),
    transform   800ms var(--ease-enter);
}
.reveal-left.in { opacity: 1; transform: translateX(0); }

.reveal-right {
  opacity: 0;
  transform: translateX(32px);
  transition:
    opacity     800ms var(--ease-enter),
    transform   800ms var(--ease-enter);
}
.reveal-right.in { opacity: 1; transform: translateX(0); }

/* opacity-only — for hero blocks where transform would jitter typography */
.reveal-fade {
  opacity: 0;
  transition: opacity 800ms var(--ease-enter);
  transform: none;
}
.reveal-fade.in { opacity: 1; }

/* slower variant — for headline display + decorative ornaments */
.reveal-slow {
  transition-duration: 1200ms;
}

/* stagger group — children animate sequentially with 80ms delay
   activated by adding .in to PARENT; children inherit via :nth-child */
.reveal-stagger > * {
  opacity: 0;
  transform: translateY(20px);
  transition:
    opacity     700ms var(--ease-enter),
    transform   700ms var(--ease-enter);
}
.reveal-stagger.in > *               { opacity: 1; transform: translateY(0); }
.reveal-stagger.in > *:nth-child(1)  { transition-delay:   0ms; }
.reveal-stagger.in > *:nth-child(2)  { transition-delay:  80ms; }
.reveal-stagger.in > *:nth-child(3)  { transition-delay: 160ms; }
.reveal-stagger.in > *:nth-child(4)  { transition-delay: 240ms; }
.reveal-stagger.in > *:nth-child(5)  { transition-delay: 320ms; }
.reveal-stagger.in > *:nth-child(6)  { transition-delay: 400ms; }
.reveal-stagger.in > *:nth-child(7)  { transition-delay: 480ms; }
.reveal-stagger.in > *:nth-child(8)  { transition-delay: 560ms; }
.reveal-stagger.in > *:nth-child(9)  { transition-delay: 640ms; }
.reveal-stagger.in > *:nth-child(10) { transition-delay: 720ms; }
.reveal-stagger.in > *:nth-child(11) { transition-delay: 800ms; }
.reveal-stagger.in > *:nth-child(12) { transition-delay: 880ms; }

/* ===========================================================
   B. HOVER UTILITIES
   Pointer-fine devices only — touch screens skip the lift.
   =========================================================== */

@media (hover: hover) and (pointer: fine) {

  .hov-lift {
    transition:
      transform   var(--t-fast) var(--ease-ui),
      box-shadow  var(--t-fast) var(--ease-ui),
      border-color var(--t-fast) var(--ease-ui);
  }
  .hov-lift:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 0 0.5px var(--hair-strong), 0 4px 14px rgba(26, 20, 16, 0.05);
  }

  .hov-fade {
    transition: opacity var(--t-fast) var(--ease-ui);
  }
  .hov-fade:hover { opacity: 0.85; }

  /* growth — NOT for text nodes; reserved for image / svg / icon containers */
  .hov-grow {
    transition: transform var(--t-base) var(--ease-ui);
    transform-origin: center;
  }
  .hov-grow:hover { transform: scale(1.02); }

  /* underline grow — heraldic 1px accent from 0 → 100% over 300ms */
  .hov-underline {
    position: relative;
    display: inline-block;
    padding-bottom: 2px;
  }
  .hov-underline::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 1px;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform 300ms var(--ease-ui);
  }
  .hov-underline:hover::after { transform: scaleX(1); }

  /* dim siblings on hover — for list groups where the hovered row should pop */
  .hov-dim-siblings:hover ~ *,
  .hov-dim-siblings:has(~ :hover) {
    opacity: 0.55;
    transition: opacity var(--t-base) var(--ease-ui);
  }
}

/* ===========================================================
   C. PAGE TRANSITION
   Body starts at opacity 0; .page-enter triggers fade-in over 500ms.
   Apply on load via JS (see snippet at the bottom of this file).
   =========================================================== */

body {
  opacity: 1; /* default — JS overrides this to 0 before paint */
}

body.page-loading {
  opacity: 0;
}

body.page-enter {
  animation: page-enter-fade 500ms var(--ease-ui) forwards;
}

@keyframes page-enter-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* page-leave — for client-side navigation where we control unmount */
body.page-leave {
  animation: page-leave-fade 250ms var(--ease-ui) forwards;
}
@keyframes page-leave-fade {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* ===========================================================
   D. CUSTOM CURSOR (optional, heraldic — subtle inverted dot)
   Activates only on .cursor-host root and pointer-fine.
   =========================================================== */

@media (hover: hover) and (pointer: fine) {
  .cursor-host {
    cursor: default;
  }
  .cursor-host a,
  .cursor-host button,
  .cursor-host [role='button'],
  .cursor-host .card-interactive,
  .cursor-host .hov-lift,
  .cursor-host .hov-underline {
    cursor: none;
  }

  .cursor-glyph {
    position: fixed;
    top: 0;
    left: 0;
    width: 28px;
    height: 28px;
    margin: -14px 0 0 -14px;
    border: 1px solid var(--ink);
    border-radius: 50%;
    background: transparent;
    pointer-events: none;
    z-index: 9999;
    opacity: 0;
    transform: translate3d(0, 0, 0) scale(1);
    transition:
      opacity   var(--t-base) var(--ease-ui),
      transform var(--t-fast) var(--ease-ui),
      background-color var(--t-fast) var(--ease-ui),
      border-color var(--t-fast) var(--ease-ui);
    mix-blend-mode: difference;
  }
  .cursor-glyph.visible { opacity: 1; }
  .cursor-glyph.active {
    background: var(--accent);
    border-color: var(--accent);
    transform: translate3d(0, 0, 0) scale(1.35);
  }
  .cursor-glyph::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 3px;
    height: 3px;
    background: var(--ink);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: background-color var(--t-fast) var(--ease-ui);
  }
  .cursor-glyph.active::after { background: var(--bg-page); }
}

/* ===========================================================
   MICRO-MOTION HELPERS
   =========================================================== */

/* gentle pulse — for live-indicators (active session, new message dot) */
.pulse {
  animation: pulse 2400ms var(--ease-ui) infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1;   transform: scale(1); }
  50%      { opacity: 0.5; transform: scale(0.92); }
}

/* slow rotate — for heraldic spinner / decorative rosettes */
.spin {
  animation: spin 6s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ascend — soft floating for badges in hero */
.float {
  animation: float 5s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-6px); }
}

/* ===========================================================
   ACCESSIBILITY — reduced motion overrides
   =========================================================== */

@media (prefers-reduced-motion: reduce) {
  .reveal,
  .reveal-up,
  .reveal-left,
  .reveal-right,
  .reveal-fade,
  .reveal-slow,
  .reveal-stagger > *,
  .hov-lift,
  .hov-fade,
  .hov-grow,
  .hov-underline::after,
  body.page-enter,
  body.page-leave,
  .pulse,
  .spin,
  .float,
  .cursor-glyph {
    animation: none !important;
    transition: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
  .cursor-host,
  .cursor-host a,
  .cursor-host button {
    cursor: auto !important;
  }
  .cursor-glyph { display: none !important; }
}

/* ===========================================================
   ===  JS INTEGRATION  ======================================
   Paste the following block at the end of <body> on any page
   that loads motion.css.  Filename suggestion: motion.js.
   ===========================================================

<script>
(function () {
  'use strict';

  // ---- 1. page enter ----------------------------------------------------
  // Body begins hidden (set inline opacity:0 to avoid FOUC flash) then
  // fades in once the DOM is ready.
  document.body.classList.add('page-enter');

  // ---- 2. scroll-reveal -------------------------------------------------
  var reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  var revealSelector = '.reveal, .reveal-up, .reveal-left, .reveal-right, .reveal-fade, .reveal-stagger';

  if (reduced || !('IntersectionObserver' in window)) {
    document.querySelectorAll(revealSelector).forEach(function (el) {
      el.classList.add('in');
    });
  } else {
    var io = new IntersectionObserver(function (entries) {
      entries.forEach(function (e) {
        if (e.isIntersecting) {
          e.target.classList.add('in');
          io.unobserve(e.target);
        }
      });
    }, { rootMargin: '-10% 0px', threshold: 0.15 });
    document.querySelectorAll(revealSelector).forEach(function (el) { io.observe(el); });
  }

  // ---- 3. topbar shadow on scroll --------------------------------------
  var topbar = document.querySelector('.app-topbar');
  if (topbar) {
    var onScroll = function () {
      if (window.scrollY > 6) topbar.classList.add('scrolled');
      else topbar.classList.remove('scrolled');
    };
    window.addEventListener('scroll', onScroll, { passive: true });
    onScroll();
  }

  // ---- 4. custom cursor (optional; only when .cursor-host is present) --
  var host = document.querySelector('.cursor-host');
  if (host && !reduced && window.matchMedia('(hover: hover) and (pointer: fine)').matches) {
    var glyph = document.createElement('div');
    glyph.className = 'cursor-glyph';
    document.body.appendChild(glyph);

    var x = 0, y = 0, tx = 0, ty = 0, raf = null;
    var tick = function () {
      x += (tx - x) * 0.22;
      y += (ty - y) * 0.22;
      glyph.style.transform = 'translate3d(' + x + 'px,' + y + 'px,0)';
      raf = requestAnimationFrame(tick);
    };
    document.addEventListener('mousemove', function (ev) {
      tx = ev.clientX;
      ty = ev.clientY;
      if (!raf) raf = requestAnimationFrame(tick);
      glyph.classList.add('visible');
    });
    document.addEventListener('mouseleave', function () {
      glyph.classList.remove('visible');
    });
    var interactiveSel = 'a, button, [role="button"], .card-interactive, .hov-lift, .hov-underline';
    document.querySelectorAll(interactiveSel).forEach(function (el) {
      el.addEventListener('mouseenter', function () { glyph.classList.add('active'); });
      el.addEventListener('mouseleave', function () { glyph.classList.remove('active'); });
    });
  }
})();
</script>

   ===========================================================
   ===  END JS INTEGRATION  ==================================
   =========================================================== */
