/* =====================================================================
   motion.css — extra animations + phone smoothness layer.
   Load it LAST (after polish.css). Delete its <link> to switch it off.
   Rules: only transform/opacity are animated (GPU-cheap), nothing here
   adds blur, and everything respects prefers-reduced-motion.
   ===================================================================== */

:root {
    --m-ease: cubic-bezier(.22, 1, .36, 1);
    --m-spring: cubic-bezier(.34, 1.56, .64, 1);
}

/* ---------- Scroll progress bar (top of screen) ---------- */
#m-progress {
    position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 100001;
    transform: scaleX(0); transform-origin: 0 50%; pointer-events: none;
    background: linear-gradient(90deg, #6366f1, #a855f7, #06b6d4);
    box-shadow: 0 0 10px rgba(129, 140, 248, .7);
    will-change: transform;
}

/* ---------- Scroll-reveal (tagged by motion.js) ---------- */
.m-reveal { opacity: 0; transform: translate3d(0, 22px, 0) scale(.98); }
.m-reveal.m-in {
    opacity: 1; transform: none;
    transition: opacity .6s var(--m-ease), transform .6s var(--m-ease);
    transition-delay: calc(min(var(--m-i, 0), 8) * 60ms);
}
/* alternate left/right entrances for list rows so it feels alive */
.m-reveal.m-left  { transform: translate3d(-26px, 0, 0); }
.m-reveal.m-right { transform: translate3d(26px, 0, 0); }

/* ---------- Page enter: children of the newly opened tab cascade in ---------- */
@keyframes mRise { from { opacity: 0; transform: translate3d(0, 18px, 0); } to { opacity: 1; transform: none; } }
.m-enter > * { animation: mRise .55s var(--m-ease) both; }
.m-enter > *:nth-child(1) { animation-delay: .02s; }
.m-enter > *:nth-child(2) { animation-delay: .08s; }
.m-enter > *:nth-child(3) { animation-delay: .14s; }
.m-enter > *:nth-child(4) { animation-delay: .20s; }
.m-enter > *:nth-child(n+5) { animation-delay: .26s; }

/* ---------- Press feedback (finger down = squish, release = spring back) ---------- */
button, .nav-btn, .glass-card, [onclick], label[class*="cursor-pointer"] {
    touch-action: manipulation;            /* kills the 300ms tap delay */
    -webkit-tap-highlight-color: transparent;
}
.m-pressed { transform: scale(.955) !important; transition: transform .12s ease-out !important; }
.glass-card.m-pressed, .glass-panel.m-pressed { transform: scale(.985) !important; }

/* ---------- Idle micro-motion on key elements ---------- */
@keyframes mBreath { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }
@keyframes mPing  { 0% { transform: scale(1); opacity: .55; } 100% { transform: scale(1.9); opacity: 0; } }
@keyframes mWiggle { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-8deg); } 40% { transform: rotate(7deg); } 60% { transform: rotate(-4deg); } 80% { transform: rotate(3deg); } }
@keyframes mShimmerLine { 0% { transform: translateX(-120%); } 100% { transform: translateX(220%); } }
@keyframes mPop { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); } }
@keyframes mFloatIn { from { opacity: 0; transform: translate3d(0, 30px, 0) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes mSlideDown { from { opacity: 0; transform: translate3d(0, -14px, 0); } to { opacity: 1; transform: none; } }
@keyframes mBounceUp { 0% { transform: translateY(0); } 40% { transform: translateY(-6px); } 70% { transform: translateY(1px); } 100% { transform: translateY(0); } }

#welcome-message { animation: mSlideDown .7s var(--m-ease) both; }
#dashboard-rank-badge { animation: mPop .6s var(--m-spring) .15s both; }
#dashboard-progress-percent { animation: mPop .7s var(--m-spring) .25s both; }
.m-count-pop { animation: mBounceUp .45s var(--m-spring); }
.m-tap-wiggle { animation: mWiggle .5s ease; }

/* Live-ping dot, locker rings and the little status dots breathe */
.animate-ping { animation-duration: 2.4s !important; }

/* Milestone badges pop when unlocked */
#badge-milestone-1:not(.grayscale), #badge-milestone-2:not(.grayscale),
#badge-milestone-3:not(.grayscale), #badge-milestone-4:not(.grayscale) {
    animation: mPop .6s var(--m-spring) both;
}

/* (v2) leaderboard glint removed: three infinite sweeps repainted that grid forever */

/* Chat bubbles: mine slide from the right, theirs from the left */
#chat-messages-list > div.justify-end  > div { animation: mFloatIn .32s var(--m-ease) both; transform-origin: 100% 100%; }
#chat-messages-list > div.justify-start > div { animation: mFloatIn .32s var(--m-ease) both; transform-origin: 0 100%; }

/* AI chat: bubbles + typing dots */
#ai-chat-board > div { animation: mFloatIn .38s var(--m-ease) both; }

/* Toasts spring in harder */
#toast-container > * { transform-origin: 100% 100%; }

/* Modals: backdrop fades, sheet springs up */
@keyframes mBackdrop { from { opacity: 0; } to { opacity: 1; } }
.modal-root:not(.hidden) { animation: mBackdrop .22s ease both; }

/* Section headings underline-draw on first view */
.m-reveal h3::after, .m-reveal h4::after { transform-origin: 0 50%; }

/* Buttons that submit: soft pulse ring on primary CTA while idle (desktop+phone, cheap) */
button.bg-indigo-600:not(:disabled) { position: relative; }

/* Nav pills: active tab glides its icon */
.nav-btn.bg-indigo-600\/15 i, .nav-btn.bg-indigo-600\/15 svg { animation: mBounceUp .5s var(--m-ease); }

/* Smooth momentum scrolling everywhere */
#workspace-view-scroll, .overflow-y-auto, .overflow-x-auto {
    overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
html { overscroll-behavior-y: none; }

/* Skip rendering work for off-screen cards until they scroll near */
@supports (content-visibility: auto) {
    #feed-stream > div, #materials-grid > div, #video-sessions-list > div,
    #feedback-list > div, #admin-students-list > div {
        content-visibility: auto; contain-intrinsic-size: auto 160px;
    }
}

/* ===================================================================== */
/* 📱 PHONE / TABLET SMOOTHNESS — turns off the expensive always-on stuff  */
/* ===================================================================== */
@media (max-width: 1023px), (pointer: coarse) {
    /* Huge rotating aurora + animated film grain + 5 drifting blobs were
       repainting the whole screen every frame. Static versions look the same. */
    body::before, body::after { animation: none !important; display: none !important; }
    .bg-blob-indigo, .bg-blob-cyan, .bg-blob-purple, .bg-blob-rose, .bg-blob-teal {
        animation: none !important; will-change: auto;
    }
    /* Conic spinning borders, sheen sweeps, avatar float: all repaint-heavy */
    .glass-card::before, .glass-card, #profile-avatar, #login-logo,
    .xp-shine, #dashboard-xp-progress-bar::after { animation: none !important; }
    .nav-btn.bg-indigo-600\/15::before { animation: none !important; }
    button.bg-indigo-600::after { display: none !important; }
    .gentle-float, .empty-state-float { animation-duration: 5s !important; }

    /* Hover-only effects never help a finger and cause sticky-hover jank */
    .glass-card:hover, .glass-panel:hover { transform: none !important; }
    .nav-btn:hover { transform: none !important; }

    /* Keep only cheap, compositor-only transitions */
    .glass-card, .glass-panel, .nav-btn, button { transition-property: transform, opacity, background-color, border-color !important; }

    /* Promote only what actually moves */
    /* (v2) no permanent will-change: a GPU layer per element is what made phones stutter */

    /* Sticky nav bar glides instead of snapping */
    .glass-sidebar nav { scroll-behavior: smooth; scroll-snap-type: x proximity; }
    .glass-sidebar nav .nav-btn { scroll-snap-align: center; }

    /* Slightly shorter, snappier entrances on small screens */
    .m-reveal.m-in { transition-duration: .45s; }
    .m-enter > * { animation-duration: .42s; }

    /* Tab switch: gentle horizontal slide feels native */
    .view-panel { animation-name: mRise !important; animation-duration: .38s !important; }
}

@media (max-width: 767px) {
    /* Modals as bottom sheets spring up */
    @keyframes mSheet { from { transform: translate3d(0, 100%, 0); } to { transform: none; } }
    .modal-root:not(.hidden) > div { animation: mSheet .38s var(--m-ease) both !important; }
    /* Toast slides in from the bottom edge */
    @keyframes mToastUp { from { opacity: 0; transform: translate3d(0, 24px, 0) scale(.96); } to { opacity: 1; transform: none; } }
    #toast-container > * { animation: mToastUp .35s var(--m-spring) both !important; }
}

/* ---------- Reduced motion: everything off, content visible ---------- */
@media (prefers-reduced-motion: reduce) {
    .m-reveal { opacity: 1 !important; transform: none !important; }
    .m-enter > *, #welcome-message, #dashboard-rank-badge, #dashboard-progress-percent,
    #chat-messages-list > div > div, #ai-chat-board > div,
    #dashboard-leaderboard-grid > div::after { animation: none !important; }
    #m-progress { display: none; }
}
/* ---------- Hidden tab: pause every animation ---------- */
/* (removed: universal html.tab-hidden rule — hidden tabs are frozen by the browser anyway, and it forced a full restyle) */