/*
  Motion: every keyframe of the mockup, the scroll reveals and the page transition.

  Vocabulary (docs/DESIGN.md, Motion):
    arrive   – rise-in, pop-in, dialog-in, sheet-up: content appears with a short rise and a soft landing
    leave    – shorter than arriving (users wait for what comes, not for what goes)
    confirm  – pop / bump on success (cart count, add to cart, order placed)
    travel   – indicators and the logo nozzle move with ease-in-out
  Durations come from tokens.css (--dur*), multiplied by --motion-scale (debug slow motion).
*/

/* ---------------------------------------------------------------- scroll reveal */
[data-reveal] { opacity: 0; transform: translateY(14px); }
[data-reveal].is-revealed {
  opacity: 1; transform: none;
  transition: opacity calc(600ms * var(--motion-scale)) var(--ease-enter) var(--reveal-delay, 0ms),
              transform calc(700ms * var(--motion-scale)) var(--ease-enter) var(--reveal-delay, 0ms);
}
@media (scripting: none) { [data-reveal] { opacity: 1; transform: none; } }
@media print { [data-reveal] { opacity: 1 !important; transform: none !important; } }

/* ---------------------------------------------------------------- page change
   The new page fades in and rises 8px (platform/motion.js playPageEnter). Plain CSS on <main>, so the page
   stays clickable during the animation – View Transitions block every click until they end. */
.site-main.is-entering { animation: page-in calc(340ms * var(--motion-scale)) var(--ease-enter); }
@keyframes page-in { from { opacity: 0; transform: translateY(8px); } }
/* the sign-in pages (form beside a large picture) only fade in: rising, the two columns read as a jolt */
.site-main.is-entering:has(> .auth) { animation-name: page-fade; }
@keyframes page-fade { from { opacity: 0; } }

/* Theme switch (ui/theme.js): the only View Transition left. The whole page is one snapshot: the old
   theme stays still, the new one grows over it as a circle from the pressed switch (centre and radius
   come from the script as --reveal-x / -y / -r). */
:root[data-theme-switch]::view-transition-old(root) { animation: none; mix-blend-mode: normal; }
:root[data-theme-switch]::view-transition-new(root) {
  animation: theme-reveal calc(560ms * var(--motion-scale)) cubic-bezier(.22, 1, .36, 1) both;
  mix-blend-mode: normal;
}
@keyframes theme-reveal {
  from { clip-path: circle(0 at var(--reveal-x) var(--reveal-y)); }
  to { clip-path: circle(var(--reveal-r) at var(--reveal-x) var(--reveal-y)); }
}
:root[data-theme-switch] *, :root[data-theme-switch] *::before, :root[data-theme-switch] *::after { transition: none !important; }
/* …except the sun and moon of the switch, which still turn inside the new snapshot */
:root[data-theme-switch] .theme-toggle__icons .icon { transition: opacity var(--dur-panel) var(--ease), transform calc(500ms * var(--motion-scale)) var(--ease-enter) !important; }
/* Browsers without View Transitions: every colour cross-fades instead of jumping. */
:root.is-theme-fading *, :root.is-theme-fading *::before, :root.is-theme-fading *::after {
  transition: background-color 300ms var(--ease), color 300ms var(--ease), border-color 300ms var(--ease), box-shadow 300ms var(--ease), fill 300ms var(--ease), stroke 300ms var(--ease) !important;
}

/* route loading: the Z prints itself in a loop in the middle of the page (main.js mountRouteLoader) while
   the old page steps back – layer by layer like the logo, then it fades and starts again. Both wait
   300 ms, so a quick load (most of them) does not flash; each load starts the print from the beginning. */
.route-loader {
  --logo-h: 44px; --loader-loop: calc(1500ms * var(--motion-scale));
  position: fixed; inset: var(--header-h) 0 0; z-index: 40; display: grid; place-items: center; pointer-events: none;
  opacity: 0; visibility: hidden; transition: opacity var(--dur) var(--ease), visibility 0s linear var(--dur);
}
html.is-route-loading .route-loader { opacity: 1; visibility: visible; transition: opacity var(--dur) var(--ease) 300ms, visibility 0s linear 300ms; }
#main { transition: opacity var(--dur) var(--ease); }
html.is-route-loading #main { opacity: .5; transition-delay: 300ms; }
html.is-route-loading .route-loader .logo-mark__layer { stroke-dasharray: 1; animation: loader-layer var(--loader-loop) var(--ease-io) 300ms infinite both; }
html.is-route-loading .route-loader .logo-mark__path { stroke-dasharray: 1; animation: loader-top var(--loader-loop) var(--ease-io) 300ms infinite both; }
html.is-route-loading .route-loader .logo-mark__nozzle--layer { animation: loader-nozzle-layer var(--loader-loop) var(--ease-io) 300ms infinite both; }
html.is-route-loading .route-loader .logo-mark__nozzle--top { animation: loader-nozzle-top var(--loader-loop) var(--ease-io) 300ms infinite both; }
@keyframes loader-layer { 0% { stroke-dashoffset: 1; opacity: 1; } 36%, 88% { stroke-dashoffset: 0; opacity: 1; } 100% { stroke-dashoffset: 0; opacity: 0; } }
@keyframes loader-top { 0%, 40% { stroke-dashoffset: 1; opacity: 1; } 80%, 88% { stroke-dashoffset: 0; opacity: 1; } 100% { stroke-dashoffset: 0; opacity: 0; } }
@keyframes loader-nozzle-layer { 0% { offset-distance: 0%; opacity: 1; } 36% { offset-distance: 100%; opacity: 1; } 40%, 100% { offset-distance: 100%; opacity: 0; } }
@keyframes loader-nozzle-top { 0%, 39% { offset-distance: 0%; opacity: 0; } 40% { offset-distance: 0%; opacity: 1; } 80% { offset-distance: 100%; opacity: 1; } 84%, 100% { offset-distance: 100%; opacity: 0; } }
/* boot: before the first page, the mark in index.html prints in the same loop from the very first
   paint – it only appears after a short moment, so a quick start shows nothing at all. It is the only
   loader then: the route loader and the dimming wait until the first page stands. */
.boot { --logo-h: 44px; --loader-loop: calc(1500ms * var(--motion-scale)); }
.boot .logo-mark { animation: fade-in var(--dur) var(--ease) 200ms both; }
.boot .logo-mark__layer { stroke-dasharray: 1; animation: loader-layer var(--loader-loop) var(--ease-io) infinite both; }
.boot .logo-mark__path { stroke-dasharray: 1; animation: loader-top var(--loader-loop) var(--ease-io) infinite both; }
.boot .logo-mark__nozzle--layer { animation: loader-nozzle-layer var(--loader-loop) var(--ease-io) infinite both; }
.boot .logo-mark__nozzle--top { animation: loader-nozzle-top var(--loader-loop) var(--ease-io) infinite both; }
html.is-route-loading:has(.boot) .route-loader { display: none; }
html.is-route-loading #main:has(.boot) { opacity: 1; }
/* reduced motion: the finished mark stands still while loading */
@media (prefers-reduced-motion: reduce) {
  html.is-route-loading .route-loader .logo-mark *, .boot .logo-mark * { animation: none; }
  :is(.route-loader, .boot) .logo-mark__nozzle { opacity: 0; }
}

/* Arrows lean the way they lead (3 px) while their link, button or clickable row is hovered or focused –
   the only movement on hover besides photos (DESIGN.md "Motion"). Not under reduced motion. */
@media (prefers-reduced-motion: no-preference) {
  .icon:is(.icon--arrow-right, .icon--chevron-right, .icon--arrow-left, .icon--chevron-left, .icon--arrow-up-right) { transition: transform var(--dur) var(--ease); }
  :is(a, button, [data-row-link]):is(:hover, :focus-visible) .icon:is(.icon--arrow-right, .icon--chevron-right) { transform: translateX(3px); }
  :is(a, button, [data-row-link]):is(:hover, :focus-visible) .icon:is(.icon--arrow-left, .icon--chevron-left) { transform: translateX(-3px); }
  :is(a, button, [data-row-link]):is(:hover, :focus-visible) .icon--arrow-up-right { transform: translate(2px, -2px); }
}

/* ---------------------------------------------------------------- one-shot accents */
.is-bumping { animation: bump calc(420ms * var(--motion-scale)) var(--ease-enter); }
@keyframes bump { 0% { transform: scale(1); } 35% { transform: scale(1.35); } 100% { transform: scale(1); } }
@keyframes confirm-pop { 0% { transform: scale(1); } 40% { transform: scale(.96); } 100% { transform: scale(1); } }
@keyframes price-flip { from { opacity: 0; transform: translateY(6px); } }

/* ---------------------------------------------------------------- keyframes */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(12px); } }
@keyframes pop-in { 0% { opacity: 0; transform: scale(.6); } 70% { transform: scale(1.06); } 100% { opacity: 1; transform: scale(1); } }
@keyframes check-draw { to { stroke-dashoffset: 0; } }
@keyframes error-in { from { opacity: 0; transform: translateY(-4px); } }
@keyframes line-in { from { opacity: 0; transform: translateX(10px); } }
@keyframes hero-settle { from { transform: scale(1.06); } }
@keyframes pulse-dot { 0% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--accent) 70%, transparent); } 70%, 100% { box-shadow: 0 0 0 8px transparent; } }

@keyframes dialog-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes dialog-out { to { opacity: 0; transform: translateY(6px) scale(.985); } }
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes sheet-down { to { transform: translateY(100%); } }
@keyframes slide-from-right { from { transform: translateX(100%); } }
@keyframes slide-to-right { to { transform: translateX(100%); } }
@keyframes slide-from-left { from { transform: translateX(-100%); } }
@keyframes slide-to-left { to { transform: translateX(-100%); } }
@keyframes menu-in { from { opacity: 0; transform: translateY(-6px) scale(.97); } }
@keyframes menu-out { to { opacity: 0; transform: translateY(-4px) scale(.98); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(16px) scale(.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---------------------------------------------------------------- reduced motion: show, don't move */
@media (prefers-reduced-motion: reduce) {
  [data-reveal] { opacity: 1; transform: none; }
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
