/* M&B motion layer (17 Nov 2026). One set of timings and effects for the public site, the sign-in pages and the
   three portal doors. Loaded last by layouts/public.php, layouts/auth.php and layouts/learn.php; the script half is
   the "Motion layer" block in assets/js/app.js.

   How it works
     html.mo            set in the page head (partials/head-meta.php) only when scripts run and the visitor has not
                        asked for reduced motion. Every hidden or moved starting state below sits under html.mo, so
                        without scripts, in print and with reduced motion the page is simply there.
     on load            blocks that are on screen rise and fade in once (CSS only, starts with the first paint).
     on scroll          blocks below the fold wait (.mo-wait, set by app.js before anyone sees them) and rise in
                        (.mo-rise) the first time they come into view, staggered within a group. Once only.
     opt in             add class "reveal" (or data-mo) to any block.
     opt out            add data-mo="off" to a block (covers everything inside it too).
     counters, bars     .stat numbers and [data-count] count up; .lprogress bars fill; once, when first seen.
     butterfly          .mo-flutter on a success block lets one butterfly lift off it, once. Success messages
                        (flash) get it automatically. The logo mark (partials/mark.php) is not touched here.
   Only transform and opacity are animated. */
:root {
  --m-fast: 180ms; --m-mid: 320ms; --m-slow: 600ms;
  --m-ease: cubic-bezier(.22, .8, .26, 1);
  --m-rise: 14px;
}

@keyframes m-rise { from { opacity: 0; transform: translateY(var(--m-rise)); } }
@keyframes m-rise-in { from { opacity: 0; transform: translateY(var(--m-rise)); } }
@keyframes m-fade { from { opacity: 0; } }
@keyframes m-pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes m-toast { from { opacity: 0; transform: translateX(24px); } }
@keyframes m-shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
@keyframes m-flutter {
  0% { opacity: 0; transform: translate(0, 6px) scale(.5) rotate(-8deg); }
  14% { opacity: 1; transform: translate(4px, -6px) scale(1, 1) rotate(6deg); }
  28% { transform: translate(-3px, -16px) scale(.72, 1) rotate(-7deg); }
  42% { transform: translate(6px, -27px) scale(1, 1) rotate(8deg); }
  56% { transform: translate(-2px, -38px) scale(.72, 1) rotate(-6deg); }
  70% { opacity: 1; transform: translate(7px, -49px) scale(1, 1) rotate(7deg); }
  100% { opacity: 0; transform: translate(14px, -70px) scale(.8, 1) rotate(12deg); }
}

/* ---- 1. the page eases in ---- */
html.mo :where(body:not(.learn) > main > *), html.mo :where(body.learn .main > .topbar ~ *), html.mo .auth-box, html.mo :where(.auth-side > *) { animation: m-fade var(--m-mid) ease-out backwards; }
html.mo .auth-box { animation-name: m-pop; animation-timing-function: var(--m-ease); }

/* ---- 2. blocks rise in: on load (here) and on scroll (.mo-wait / .mo-rise, set by app.js) ---- */
html.mo .reveal, html.mo [data-mo]:not([data-mo="off"]),
html.mo body.learn .main > .hero, html.mo body.learn .main > .panel, html.mo body.learn .main > .stats > *, html.mo body.learn .main > .stat-cards > *,
html.mo body.learn .main > .cols > *, html.mo body.learn .main > .dash-cols > * {
  animation: m-rise var(--m-mid) var(--m-ease) backwards;
}
html.mo body.learn .main > .stats > :nth-child(2), html.mo body.learn .main > .stat-cards > :nth-child(2), html.mo body.learn .main > .cols > :nth-child(2), html.mo body.learn .main > .dash-cols > :nth-child(2) { animation-delay: 60ms; }
html.mo body.learn .main > .stats > :nth-child(3), html.mo body.learn .main > .stat-cards > :nth-child(3) { animation-delay: 120ms; }
html.mo body.learn .main > .stats > :nth-child(4), html.mo body.learn .main > .stat-cards > :nth-child(4) { animation-delay: 180ms; }
html.mo body.learn .main > .stats > :nth-child(n+5), html.mo body.learn .main > .stat-cards > :nth-child(n+5) { animation-delay: 240ms; }
html.mo .mo-wait { opacity: 0; transform: translateY(var(--m-rise)); animation: none !important; }
html.mo .mo-rise { animation: m-rise-in var(--m-slow) var(--m-ease) backwards !important; }
html.mo [data-mo="off"], html.mo [data-mo="off"] * { animation: none !important; }
/* the older reveal rule left blocks at 72% until a script ran: a block is now fully there unless html.mo says otherwise */
.reveal, .reveal.in { opacity: 1; transform: none; transition: none; }
html.mo .reveal.mo-wait { opacity: 0; transform: translateY(var(--m-rise)); }

/* ---- 3. hover, press and focus ---- */
.btn { transition: background-color var(--m-fast) ease-out, border-color var(--m-fast) ease-out, color var(--m-fast) ease-out, box-shadow var(--m-fast) ease-out, transform var(--m-fast) var(--m-ease); }
.btn:active:not([disabled]), body.learn .btn:active:not([disabled]) { transform: translateY(1px) scale(.98); transition-duration: 60ms; }
a.card, .card-link, .tile, body.learn .mod, body.learn .stat, body.learn a.panel { transition: transform var(--m-fast) var(--m-ease), box-shadow var(--m-fast) ease-out, border-color var(--m-fast) ease-out; }
@media (hover: hover) { a.card:hover, .card-link:hover { transform: translateY(-3px); } }
a.card:active, .card-link:active, body.learn .mod:active { transform: translateY(0) scale(.99); }
body.learn .sidebar nav a, body.learn .bottomnav a, .site-nav a, .drawer a { transition: background-color var(--m-fast) ease-out, color var(--m-fast) ease-out, transform var(--m-fast) var(--m-ease); }
body.learn .sidebar nav a .n-ic { transition: transform var(--m-fast) var(--m-ease); }
@media (hover: hover) { body.learn .sidebar nav a:hover .n-ic { transform: translateX(2px); } }
body.learn .bottomnav a:active { transform: scale(.94); }
body.learn .bottomnav a.on svg { animation: m-pop var(--m-mid) var(--m-ease) backwards; }
body.learn .icon-btn, body.learn .bell, body.learn .theme-toggle, body.learn .me-btn { transition: background-color var(--m-fast) ease-out, color var(--m-fast) ease-out, border-color var(--m-fast) ease-out, transform var(--m-fast) var(--m-ease); }
body.learn .icon-btn:active, body.learn .bell:active, body.learn .theme-toggle:active { transform: scale(.92); }
input, select, textarea { transition: border-color var(--m-fast) ease-out, box-shadow var(--m-fast) ease-out, background-color var(--m-fast) ease-out; }

/* ---- 4. bars and counters ---- */
body.learn .lprogress i, .progress > i, .gd-progress i { transform-origin: left center; transition: transform var(--m-slow) var(--m-ease); }
html.mo body.learn .lprogress:not(.mo-seen) i { transform: scaleX(0); }
html.mo .mo-counting { font-variant-numeric: tabular-nums; }

/* ---- 5. modals, drawers, toasts, tabs, details ---- */
body.learn dialog.modal[open] { animation: m-pop var(--m-fast) var(--m-ease); }
body.learn dialog.modal[open]::backdrop, dialog[open]::backdrop { animation: m-fade var(--m-fast) ease-out; }
body.learn dialog.modal.mo-closing { opacity: 0; transform: translateY(6px) scale(.985); transition: opacity 140ms ease-in, transform 140ms ease-in; }
body.learn .sidebar { transition-duration: var(--m-mid); transition-timing-function: var(--m-ease); }
/* the public menu drawer slides out as smoothly as it slides in (it used to vanish at once on close) */
@media (max-width: 1023.98px) {
  .site-nav { transition: transform var(--m-mid) var(--m-ease), visibility 0s linear var(--m-mid); }
  .site-nav.open { transition: transform var(--m-mid) var(--m-ease), visibility 0s; }
}
.flash-stack .alert { animation: m-toast var(--m-mid) var(--m-ease) backwards; }
.flash-stack .alert:nth-child(2) { animation-delay: 80ms; } .flash-stack .alert:nth-child(n+3) { animation-delay: 160ms; }
html.mo [data-tab-panel]:not([hidden]) { animation: m-fade var(--m-mid) ease-out; }
html.mo details[open] > summary ~ * { animation: m-fade var(--m-mid) ease-out; }
body.learn .tabs button { transition: color var(--m-fast) ease-out, border-color var(--m-fast) ease-out; }

/* ---- 6. shimmer for anything that arrives late ---- */
.mo-skel, .gsi-btn:empty { position: relative; overflow: hidden; background: rgba(120, 140, 160, .16); border-radius: 10px; }
.mo-skel::after, .gsi-btn:empty::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .38), transparent); animation: m-shimmer 1.3s linear infinite; }
:root[data-theme="dark"] .mo-skel::after, :root[data-theme="dark"] .gsi-btn:empty::after { background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .1), transparent); }
.mo-skel-text { display: inline-block; min-width: 3.5em; min-height: 1em; vertical-align: middle; }

/* photos that are still on their way (gallery, album covers): app.js adds .mo-loaded when the picture is in */
html.mo .gal-item, html.mo .album-cover { position: relative; }
html.mo .gal-item:not(.mo-loaded)::before, html.mo .album-cover:not(.mo-loaded):has(img)::before { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .45), transparent); animation: m-shimmer 1.3s linear infinite; }
html.mo .gal-item img, html.mo .album-cover img { transition: opacity var(--m-mid) ease-out; }
html.mo .gal-item:not(.mo-loaded) img, html.mo .album-cover:not(.mo-loaded) img { opacity: 0; }

/* ---- 7. the butterfly: one lifts off a success, once ---- */
.mo-flutter, .flash-stack .alert-success, .mb-alert-icon.success { position: relative; }
html.mo .mo-flutter::after, html.mo .flash-stack .alert-success::after, html.mo .mb-alert-backdrop.show .mb-alert-icon.success::after {
  content: ""; position: absolute; right: 14px; top: -4px; width: 26px; height: 20px; pointer-events: none; opacity: 0;
  background: url(../img/center_large_butterfly_clean.webp) center / contain no-repeat;
  animation: m-flutter 1.9s ease-out .35s 1 both;
}
html.mo .mo-flutter.mo-wait::after { animation: none; }

/* ---- off: reduced motion, print ---- */
@media (prefers-reduced-motion: reduce) {
  /* all of it off, on every layout (events such as animationend still fire, so no script waits for ever) */
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; transition-delay: 0s !important; scroll-behavior: auto !important; }
  .mo-skel::after, .gsi-btn:empty::after, .mo-flutter::after, .flash-stack .alert-success::after, .mb-alert-icon.success::after { display: none !important; }
  .btn:active:not([disabled]), body.learn .btn:active:not([disabled]), a.card:hover, .card-link:hover, body.learn .bottomnav a:active, body.learn .icon-btn:active { transform: none; }
}
@media print {
  .mo-wait, .reveal { opacity: 1 !important; transform: none !important; }
  html.mo body.learn .lprogress i { transform: none !important; }
  .mo-flutter::after, .flash-stack .alert-success::after { display: none !important; }
  * { animation: none !important; }
}
