/* values.io motion: the motion language (durations and curves), keyframes and classes. Link after tokens.css and
   ui.css. The script side (count-up, stagger, pop, shake, ring, burst, FLIP, slide-in, the result bar, the tab line,
   press) is app/motion.js; a page change swaps in one frame (app/motion.js transition: no cross-fade). Colours only
   from tokens.css. Moves use the `translate` / `scale` / `rotate` properties, so they add to a part's own transform
   (the buttons' translateZ(0)) instead of replacing it. Only transform and opacity move.
   Under prefers-reduced-motion every duration below drops to 1ms, so everything built on them just appears. */

:root {
  /* The motion language: every transition and animation in the app uses these (app/motion.js mirrors them in DUR and
     EASE). Quick and springy like Duolingo, never floaty. */
  --m-fast: 120ms;                                 /* presses, hovers, colour changes, anything leaving */
  --m-base: 200ms;                                 /* things arriving: a page, a window, a list row, a result bar */
  --m-slow: 320ms;                                 /* bigger moves: toasts, rows gliding, pops, shakes, progress */
  --m-step: 30ms;                                  /* between the rows of a list coming in */
  --m-glow: 900ms;                                 /* a "just changed" highlight fading away (a new row, a changed card) */
  --m-ease-out: cubic-bezier(.22, 1, .36, 1);      /* arriving and moving: quick start, soft landing */
  --m-ease-in: cubic-bezier(.4, 0, 1, 1);          /* leaving: picks up speed and is gone */
  --m-ease-in-out: cubic-bezier(.45, 0, .55, 1);   /* back and forth: shakes, wiggles, loops */
  --m-spring: cubic-bezier(.35, 1.4, .5, 1);       /* a small overshoot: windows, toasts, switches */
  --m-bounce: cubic-bezier(.35, 1.8, .35, .83);    /* Duolingo's result bar: a bigger overshoot */

  --m-skel-base: var(--color-swan);
  --m-skel-shine: var(--color-polar);              /* lighter than swan: the sweep of light */
}

/* ================================================================ skeletons: swan blocks with a soft sweep of light */
.m-skel {
  display: block; height: 16px; border-radius: 8px;
  background: var(--m-skel-base) linear-gradient(100deg, var(--m-skel-base) 40%, var(--m-skel-shine) 50%, var(--m-skel-base) 60%);
  background-size: 300% 100%;
  animation: m-shimmer 1.5s linear infinite;
}
.m-skel--text { height: 14px; border-radius: 7px; width: var(--w, 100%); }          /* a line of text; style="--w: 60%" */
.m-skel--text + .m-skel--text { margin-top: 10px; }
.m-skel--circle { width: var(--s, 48px); height: var(--s, 48px); border-radius: 50%; flex-shrink: 0; }   /* avatar / item */
.m-skel--card { height: var(--h, 160px); border-radius: 16px; }                     /* a whole card, their 16px radius */
@keyframes m-shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
/* the library's skeleton rows (UI.skeletonRows, ui.css .u-skel) get the same sweep, so every loading list looks alike */
.u-skel {
  background: var(--m-skel-base) linear-gradient(100deg, var(--m-skel-base) 40%, var(--m-skel-shine) 50%, var(--m-skel-base) 60%);
  background-size: 300% 100%;
  animation: m-shimmer 1.5s linear infinite;
}

/* ================================================================ one-shot animations */
/* enter: fade + 8px rise; set --i (0, 1, 2 ...) on each item of a list for a --m-step between them */
.m-in { animation: m-in var(--m-base) var(--m-ease-out) both; animation-delay: calc(var(--i, 0) * var(--m-step)); }
@keyframes m-in { from { opacity: 0; translate: 0 8px; } }

/* content taking a skeleton's place: a plain fade, nothing moves */
.m-fade-in { animation: m-fade-in var(--m-base) var(--m-ease-out) both; }
@keyframes m-fade-in { from { opacity: 0; } }
@keyframes m-fade-out { to { opacity: 0; } }

/* a quick bounce (add the class again to replay it, or use pop() from app/motion.js) */
.m-pop { animation: m-pop var(--m-slow) var(--m-ease-out); }
@keyframes m-pop { 35% { scale: 1.15; } 70% { scale: .96; } }

/* the wrong-answer shake */
.m-shake { animation: m-shake var(--m-slow) var(--m-ease-in-out); }
@keyframes m-shake { 20% { translate: -8px 0; } 40% { translate: 7px 0; } 60% { translate: -5px 0; } 80% { translate: 3px 0; } }

/* a bell ringing: alerts turned on (ring() in app/motion.js) */
.m-ring { transform-origin: 50% 10%; animation: m-ring calc(var(--m-slow) * 2) var(--m-ease-in-out); }
@keyframes m-ring { 15% { rotate: 16deg; } 30% { rotate: -13deg; } 45% { rotate: 9deg; } 60% { rotate: -6deg; } 75% { rotate: 3deg; } }

/* ================================================================ loops */
/* loading spinner for buttons and inline use: a faint 3px ring with a turning arc, both in the text colour.
   <button class="u-btn u-btn--green" disabled><span class="m-spin"></span>Posting</button> */
.m-spin { position: relative; display: inline-block; flex-shrink: 0; width: 20px; height: 20px; vertical-align: middle; }
.m-spin::before, .m-spin::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 3px solid currentColor; }
.m-spin::before { opacity: .3; }
.m-spin::after { border-color: currentColor transparent transparent; animation: m-spin .7s linear infinite; }
@keyframes m-spin { to { rotate: 1turn; } }

/* a soft ring that keeps growing out of a "new" dot or count (.u-dot, .u-count); red by default, any token through
   --m-pulse-rgb, e.g. style="--m-pulse-rgb: var(--color-macaw-rgb)" */

@keyframes m-pulse {
  from { box-shadow: 0 0 0 0 rgba(var(--m-pulse-rgb), .45); }
  70%, to { box-shadow: 0 0 0 8px rgba(var(--m-pulse-rgb), 0); }
}

/* ================================================================ tabs: the blue line slides to the picked tab
   (app/motion.js draws .m-tabline in any .u-tabs while it moves; the picked tab's own line waits under it) */
.m-tabline {
  position: absolute; left: 0; bottom: -2px; width: 1px; height: 2px; z-index: 1;
  background: var(--color-macaw); transform-origin: 0 0; pointer-events: none;
}
.u-tabs.m-tabs-moving .u-tab.is-active { border-bottom-color: var(--color-swan); }

/* ================================================================ reduced motion: every duration ~0, loops off */
@media (prefers-reduced-motion: reduce) {
  :root { --m-fast: 1ms; --m-base: 1ms; --m-slow: 1ms; --m-step: 0ms; --m-glow: 1ms; }
  .m-skel, .u-skel, .m-in, .m-fade-in, .m-pop, .m-shake, .m-ring { animation: none; }
  .m-spin::after { animation: m-blink 1s ease-in-out infinite; }   /* still shows it is busy, without turning */
  .m-tabline { display: none; }
}
@keyframes m-blink { 50% { opacity: .35; } }
