/* Qizil 0.4.0: motion layer, opt-in classes (docs/MOTION.md). Copied from src/motion.css by scripts/build.mjs; edit the source. */

/* Needs qizil.css (tokens). Load after components.css (and effects.css, in any order). docs/MOTION.md
   says when to use what.

   Everything here is opt-in: nothing moves until an element carries one of these classes, so a page
   that loads this file without using it looks and behaves exactly as before.

   Rules of the layer:
   - Only transform and opacity animate in keyframes (the drift moves a double-width layer). Nothing changes
     layout per frame.
   - Four durations (--q-duration-quick 160ms, -base 320ms, -slow 640ms, -long 1280ms) and one ease
     family: --q-ease-out to enter, --q-ease-in to leave, --q-ease-in-out for loops and state changes.
   - Content is always visible without JavaScript. Scroll reveals hide content only under html.q-js,
     which dist/motion.js sets once it can reveal it again.
   - Everything stops under prefers-reduced-motion and under data-motion="off" on the element or any
     ancestor. Ambient loops follow --q-motion-ambient (paused for data-product="admin") and pause off
     screen and in hidden tabs when motion.js runs. */

/* =========================================================================
   Keyframes (q- prefix; Tailwind's animate-q-* utilities use them too)
   ========================================================================= */

@keyframes q-fade-in {
  from {
    opacity: 0;
  }
}

@keyframes q-rise-in {
  from {
    opacity: 0;
    transform: translateY(var(--q-motion-rise, 16px));
  }
}

@keyframes q-scale-in {
  from {
    opacity: 0;
    transform: scale(var(--q-scale-enter));
  }
}

@keyframes q-sink-out {
  to {
    opacity: 0;
    transform: translateY(calc(var(--q-motion-rise, 16px) / 2));
  }
}

@keyframes q-fade-out {
  to {
    opacity: 0;
  }
}

@keyframes q-float {
  to {
    transform: translateY(calc(-1 * var(--q-distance-float)));
  }
}

@keyframes q-pulse {
  from {
    opacity: 0.5;
    transform: scale(1);
  }

  to {
    opacity: 0;
    transform: scale(2.75);
  }
}

@keyframes q-drift {
  to {
    transform: translateX(-50%);
  }
}

@keyframes q-sweep {
  from {
    transform: translateX(-100%);
  }

  to {
    transform: translateX(100%);
  }
}

@keyframes q-marquee {
  to {
    transform: translateX(-50%);
  }
}

@keyframes q-caret {
  50% {
    opacity: 0;
  }
}

/* =========================================================================
   M1 Entrance on load: .q-enter (rise), .q-enter--fade, .q-enter--scale.
   CSS only, no JavaScript needed; set --q-i: 0..8 (or use .q-stagger) to delay.
   ========================================================================= */

.q-enter {
  animation: q-rise-in var(--q-duration-slow) var(--q-ease-out) both;
  animation-delay: calc(var(--q-i, 0) * var(--q-stagger-step));
}

.q-enter--fade {
  animation-name: q-fade-in;
}

.q-enter--scale {
  animation-name: q-scale-in;
}

/* A group whose children enter one after the other on load (the hero text). CSS only. */
.q-enter-stagger > * {
  animation: q-rise-in var(--q-duration-slow) var(--q-ease-out) both;
  animation-delay: calc(var(--q-i, 0) * var(--q-stagger-step));
}

/* =========================================================================
   M2 Scroll reveal: .q-reveal on an element, .q-stagger on a group (its children rise one after the
   other, 60ms apart, at most 8 steps). Hidden only under html.q-js.
   - .q-reveal uses a CSS scroll-driven animation (animation-timeline: view()) where the browser has
     one; motion.js then leaves it alone. Elsewhere motion.js adds .q-in when it enters the viewport.
   - .q-stagger is always time-based: motion.js adds .q-in once and the children play in order.
   ========================================================================= */

.q-stagger > *,
.q-enter-stagger > * {
  --q-i: 0;
}

.q-stagger > :nth-child(2),
.q-enter-stagger > :nth-child(2) { --q-i: 1; }
.q-stagger > :nth-child(3),
.q-enter-stagger > :nth-child(3) { --q-i: 2; }
.q-stagger > :nth-child(4),
.q-enter-stagger > :nth-child(4) { --q-i: 3; }
.q-stagger > :nth-child(5),
.q-enter-stagger > :nth-child(5) { --q-i: 4; }
.q-stagger > :nth-child(6),
.q-enter-stagger > :nth-child(6) { --q-i: 5; }
.q-stagger > :nth-child(7),
.q-enter-stagger > :nth-child(7) { --q-i: 6; }
.q-stagger > :nth-child(8),
.q-enter-stagger > :nth-child(8) { --q-i: 7; }
.q-stagger > :nth-child(n + 9),
.q-enter-stagger > :nth-child(n + 9) { --q-i: 8; }

@supports (animation-timeline: view()) {
  html.q-js .q-reveal {
    animation: q-rise-in linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 80%;
  }
}

@supports not (animation-timeline: view()) {
  html.q-js .q-reveal:not(.q-in) {
    opacity: 0;
  }

  html.q-js .q-reveal.q-in {
    animation: q-rise-in var(--q-duration-slow) var(--q-ease-out) both;
  }
}

html.q-js .q-stagger:not(.q-in) > * {
  opacity: 0;
}

html.q-js .q-stagger.q-in > * {
  animation: q-rise-in var(--q-duration-slow) var(--q-ease-out) both;
  animation-delay: calc(var(--q-i) * var(--q-stagger-step));
}

/* =========================================================================
   M3 Hover and press feedback (one transition per interaction, --q-duration)
   ========================================================================= */

/* Lift: moves up --q-motion-lift (2px; 0 for admin). Pair it with .q-card--lift for the soft shadow. */
.q-lift {
  transition: transform var(--q-duration) var(--q-ease);
}

.q-lift:hover {
  transform: translateY(calc(-1 * var(--q-motion-lift, 2px)));
}

/* Press: a tile or card gives a little under the pointer. Buttons keep their 1px press (K4). */
.q-press {
  transition: transform var(--q-duration) var(--q-ease);
}

.q-press:active {
  transform: scale(var(--q-scale-press));
}

/* Card lift: .q-card (or any tile) rises and its soft shadow fades in. The shadow is a layer that
   covers the border box exactly (inset -hairline, the same radius), so only its opacity changes. It
   is the ::before layer, so it pairs with .q-card--glow (::after) on pricing and app cards. Not with
   .q-spotlight or .q-aurora: they own ::before and clip their box. */
.q-card--lift {
  position: relative;
  isolation: isolate;
  transition: transform var(--q-duration) var(--q-ease), border-color var(--q-duration) var(--q-ease);
}

.q-card--lift::before {
  content: "";
  position: absolute;
  inset: calc(-1 * var(--q-line-hairline));
  z-index: -1;
  border-radius: inherit;
  box-shadow: var(--q-shadow-soft-2);
  opacity: 0;
  transition: opacity var(--q-duration) var(--q-ease);
  pointer-events: none;
}

.q-card--lift:hover,
.q-card--lift:focus-within {
  transform: translateY(calc(-1 * var(--q-motion-lift, 2px)));
}

.q-card--lift:hover::before,
.q-card--lift:focus-within::before {
  opacity: 1;
}

/* Animated underline for links in running text: the border-coloured line slides to crimson. Uses
   background-position, so it follows the text across line breaks. */
.q-link-anim {
  background-image: linear-gradient(90deg, currentColor 50%, var(--q-border) 50%);
  background-position: 100% 100%;
  background-repeat: no-repeat;
  background-size: 200% var(--q-line-hairline);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  text-decoration: none;
  transition: color var(--q-duration) var(--q-ease), background-position var(--q-duration-base) var(--q-ease-out);
}

.q-link-anim:hover,
.q-link-anim:focus-visible {
  background-position: 0 100%;
}

/* Button shine: a light sweep crosses the button once on hover (primary and gradient buttons). */
.q-btn--shine {
  position: relative;
  isolation: isolate;
  overflow: hidden;
}

.q-btn--shine::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(105deg, transparent 30%, var(--q-shine) 50%, transparent 70%);
  transform: translateX(-100%);
  pointer-events: none;
}

.q-btn--shine:hover::after {
  transform: translateX(100%);
  transition: transform var(--q-duration-slow) var(--q-ease-out);
}

/* Icon nudge: the trailing icon moves 2px toward where the link goes. --diag for external links. */
.q-nudge .q-icon:last-child {
  transition: transform var(--q-duration) var(--q-ease);
}

.q-nudge:hover .q-icon:last-child,
.q-nudge:focus-visible .q-icon:last-child {
  transform: translateX(var(--q-distance-nudge));
}

.q-nudge--diag:hover .q-icon:last-child,
.q-nudge--diag:focus-visible .q-icon:last-child {
  transform: translate(var(--q-distance-nudge), calc(-1 * var(--q-distance-nudge)));
}

/* =========================================================================
   M4 Ambient loops. Slow, few, and never behind text people are reading. One per view is plenty.
   ========================================================================= */

/* Float: an illustration or a badge drifts up and down by 6px. */
.q-float {
  animation: q-float var(--q-loop-float) var(--q-ease-in-out) infinite alternate;
  animation-play-state: var(--q-motion-ambient, running);
}

/* Pulse: a live dot (status, recording, presence). Put text next to it: the pulse is not the signal. */
.q-pulse {
  position: relative;
  display: inline-block;
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: var(--q-radius-full);
  background: currentColor;
  vertical-align: middle;
}

.q-pulse::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: currentColor;
  animation: q-pulse var(--q-loop-pulse) var(--q-ease-out) infinite;
  animation-play-state: var(--q-motion-ambient, running);
}

/* Gradient drift: a gradient surface (its own background-image, for example the product gradient)
   slides slowly through its stops. The ::before layer inherits the background at twice the width
   and moves by transform, so nothing repaints. Surfaces only: gradient text stays still. */
.q-drift {
  position: relative;
  isolation: isolate;
  overflow: hidden;
}

.q-drift::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  z-index: -1;
  width: 200%;
  background: inherit;
  background-size: 100% 100%;
  animation: q-drift var(--q-loop-drift) var(--q-ease-in-out) infinite alternate;
  animation-play-state: var(--q-motion-ambient, running);
  pointer-events: none;
}

/* Shimmer: a light sweep crosses a surface twice and rests (a "new" badge; under WCAG 2.2.2 nothing
   moves on its own for more than 5s). --loop keeps it going, for a label that says it is loading. */
.q-shimmer {
  position: relative;
  isolation: isolate;
  overflow: hidden;
}

.q-shimmer::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(100deg, transparent 30%, var(--q-shine) 50%, transparent 70%);
  transform: translateX(-100%);
  animation: q-sweep var(--q-loop-shimmer) var(--q-ease-in-out) 2;
  animation-play-state: var(--q-motion-ambient, running);
  pointer-events: none;
}

.q-shimmer--loop::after {
  animation-iteration-count: infinite;
}

/* Marquee: logos or quotes scroll sideways. Repeat the items once inside the track and mark the copy
   aria-hidden="true". Hover and focus pause it (give the .q-marquee tabindex="0", role="region" and
   an aria-label so keyboards can reach it), and a .q-marquee__pause checkbox label right before it
   pauses it for touch (WCAG 2.2.2, no JavaScript needed). Without motion it is a scrollable row. */
.q-marquee {
  overflow: hidden;
  -webkit-mask-image: linear-gradient(90deg, transparent, black 8%, black 92%, transparent);
  mask-image: linear-gradient(90deg, transparent, black 8%, black 92%, transparent);
}

.q-marquee__track {
  display: flex;
  gap: var(--q-space-32);
  width: max-content;
  padding-right: var(--q-space-32);
  animation: q-marquee var(--q-loop-marquee) linear infinite;
  animation-play-state: var(--q-motion-ambient, running);
}

.q-marquee__pause {
  margin-bottom: var(--q-space-8);
}

.q-marquee:hover .q-marquee__track,
.q-marquee:focus-within .q-marquee__track,
.q-marquee__pause:has(:checked) + .q-marquee .q-marquee__track {
  animation-play-state: paused;
}

/* Typing caret after a line of text (the hero of the profile site, a command line). It blinks four
   times (4.8s) and then stays lit: WCAG 2.2.2 allows no blinking past 5s without a pause control. */
.q-caret::after {
  content: "";
  display: inline-block;
  width: 0.08em;
  height: 1em;
  margin-left: 0.08em;
  background: var(--q-accent);
  vertical-align: -0.12em;
  animation: q-caret var(--q-loop-caret) steps(1) 4;
  animation-play-state: var(--q-motion-ambient, running);
}

/* Count-up hook: [data-q-count] holds the final number, also as its text; motion.js counts to it
   when it scrolls into view and reserves the width first. */
[data-q-count] {
  display: inline-block;
  font-variant-numeric: tabular-nums;
}

/* Skeleton upgrade: a softer wave in the product tint (the v0.1 skeleton stays as it is). */
.q-skeleton--soft {
  background: color-mix(in srgb, var(--q-product-tint) 45%, var(--q-surface));
}

.q-skeleton--soft::after {
  background: linear-gradient(90deg, transparent, var(--q-shine), transparent);
  animation-duration: var(--q-loop-shimmer);
  animation-timing-function: var(--q-ease-in-out);
}

/* =========================================================================
   M5 Toasts and dialogs: enter and exit
   ========================================================================= */

/* A toast that leaves: set data-leaving (motion.js dismiss() does it), remove it on animationend. */
.q-toast[data-leaving] {
  animation: q-sink-out var(--q-duration-quick) var(--q-ease-in) both;
  pointer-events: none;
}

/* Native <dialog class="q-dialog q-dialog--motion">: fades and rises in, sinks out on close. Browsers
   without @starting-style simply show and hide it. */
dialog.q-dialog--motion {
  opacity: 0;
  transform: translateY(calc(var(--q-motion-rise, 16px) / 2)) scale(var(--q-scale-enter));
  transition:
    opacity var(--q-duration-quick) var(--q-ease-in),
    transform var(--q-duration-quick) var(--q-ease-in),
    overlay var(--q-duration-quick) allow-discrete,
    display var(--q-duration-quick) allow-discrete;
}

dialog.q-dialog--motion[open] {
  opacity: 1;
  transform: none;
  animation: none;
  transition-duration: var(--q-duration-base);
  transition-timing-function: var(--q-ease-out);
}

@starting-style {
  dialog.q-dialog--motion[open] {
    opacity: 0;
    transform: translateY(calc(var(--q-motion-rise, 16px) / 2)) scale(var(--q-scale-enter));
  }
}

dialog.q-dialog--motion::backdrop {
  opacity: 0;
  transition:
    opacity var(--q-duration-base) var(--q-ease-in-out),
    overlay var(--q-duration-base) allow-discrete,
    display var(--q-duration-base) allow-discrete;
}

dialog.q-dialog--motion[open]::backdrop {
  opacity: 1;
}

@starting-style {
  dialog.q-dialog--motion[open]::backdrop {
    opacity: 0;
  }
}

/* =========================================================================
   M6 Scroll-aware nav: the .q-nav-bar backdrop fades in over the first 96px of scroll. Without
   scroll-driven animations the backdrop is simply always there.
   ========================================================================= */

@supports (animation-timeline: scroll()) {
  .q-nav-bar--scroll::before {
    animation: q-fade-in linear both;
    animation-timeline: scroll(root block);
    animation-range: 0px 96px;
  }
}

/* =========================================================================
   M7 Page and section transitions (View Transitions API), opt-in with html.q-vt.
   Same-document: motion.js transition(update). Multi-page sites also add
   @view-transition { navigation: auto; } to their own stylesheet. Unsupported browsers just swap.
   ========================================================================= */

html.q-vt::view-transition-old(root) {
  animation: q-fade-out var(--q-duration-quick) var(--q-ease-in) both;
}

html.q-vt::view-transition-new(root) {
  animation: q-rise-in var(--q-duration-base) var(--q-ease-out) both;
}

/* A section that morphs in place keeps its own name; the nav stays still. */
.q-vt-section {
  view-transition-name: var(--q-vt-name, none);
}

.q-vt-nav {
  view-transition-name: q-nav;
}

html.q-vt::view-transition-old(q-nav),
html.q-vt::view-transition-new(q-nav) {
  animation: none;
}

/* =========================================================================
   M8 Pausing: motion.js sets data-q-paused on an ambient element while it is off screen or the tab
   is hidden (only on those elements, never on the whole page); the admin product is calm through
   --q-motion-ambient.
   ========================================================================= */

[data-q-paused],
[data-q-paused]::before,
[data-q-paused]::after,
[data-q-paused] .q-marquee__track {
  animation-play-state: paused !important;
}

/* =========================================================================
   M9 Motion off: prefers-reduced-motion, or data-motion="off" on the element or an ancestor.
   Everything stops and every revealed thing shows; the spinner keeps turning slowly (K13).
   ========================================================================= */

:is([data-motion="off"], [data-motion="off"] *),
:is([data-motion="off"], [data-motion="off"] *)::before,
:is([data-motion="off"], [data-motion="off"] *)::after {
  animation: none !important;
  transition: none !important;
}

:is([data-motion="off"], [data-motion="off"] *):is(.q-reveal, .q-stagger > *, .q-enter, .q-enter-stagger > *) {
  opacity: 1 !important;
  transform: none !important;
}

/* The same result as reduced motion (M5): hover and press move nothing. */
:is([data-motion="off"], [data-motion="off"] *):is(.q-lift:hover, .q-press:active, .q-card--lift:hover, .q-card--lift:focus-within),
:is([data-motion="off"], [data-motion="off"] *):is(.q-nudge:hover, .q-nudge:focus-visible) .q-icon:last-child {
  transform: none;
}

:is([data-motion="off"], [data-motion="off"] *).q-btn--shine:hover::after {
  transform: translateX(-100%);
}

/* View transitions (same-document and cross-document @view-transition) do not run either. */
html[data-motion="off"]::view-transition-group(*),
html[data-motion="off"]::view-transition-image-pair(*),
html[data-motion="off"]::view-transition-old(*),
html[data-motion="off"]::view-transition-new(*) {
  animation: none !important;
}

[data-motion="off"] .q-spinner,
.q-spinner[data-motion="off"] {
  animation: q-spin 1.6s linear infinite !important;
}

@media (prefers-reduced-motion: reduce) {
  .q-enter,
  .q-enter-stagger > *,
  html.q-js .q-reveal,
  html.q-js .q-stagger > *,
  .q-float,
  .q-pulse::after,
  .q-drift::before,
  .q-shimmer::after,
  .q-marquee__track,
  .q-caret::after,
  .q-skeleton--soft::after,
  .q-toast[data-leaving],
  .q-nav-bar--scroll::before,
  [class*="animate-q-"] {
    animation: none !important;
  }

  html.q-js .q-reveal,
  html.q-js .q-stagger > * {
    opacity: 1 !important;
    transform: none !important;
  }

  .q-lift,
  .q-press,
  .q-card--lift,
  .q-card--lift::before,
  .q-link-anim,
  .q-btn--shine::after,
  .q-nudge .q-icon:last-child,
  dialog.q-dialog--motion,
  dialog.q-dialog--motion::backdrop {
    transition: none !important;
  }

  .q-lift:hover,
  .q-press:active,
  .q-card--lift:hover,
  .q-card--lift:focus-within,
  .q-nudge:hover .q-icon:last-child,
  .q-nudge:focus-visible .q-icon:last-child {
    transform: none;
  }

  .q-btn--shine:hover::after {
    transform: translateX(-100%);
  }

  .q-marquee {
    overflow-x: auto;
  }

  html.q-vt::view-transition-group(*),
  html.q-vt::view-transition-old(*),
  html.q-vt::view-transition-new(*) {
    animation: none !important;
  }
}

/* Without motion the marquee is a row people scroll themselves (the mask stays as a hint). */
:is([data-motion="off"], [data-motion="off"] *).q-marquee {
  overflow-x: auto;
}
