/* Motion for the marketing and account site. Loaded after saas-site.css / saas-app.css. Spec: css/MOTION.md.
   Same tokens as the panel (durations, easings, distances). Content is visible by default; entrances are CSS animations with
   fill-mode "both" so nothing depends on JS to appear, plus a failsafe for the scroll-reveal classes. */
:root {
  --mo-fast: 120ms; --mo-base: 220ms; --mo-slow: 360ms;
  --mo-out: cubic-bezier(.16, 1, .3, 1); --mo-in: cubic-bezier(.4, 0, 1, 1); --mo-inout: cubic-bezier(.65, 0, .35, 1);
  --mo-spring: cubic-bezier(.34, 1.56, .64, 1);
}
@keyframes sm-rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes sm-h1 { from { opacity: 0; transform: translateY(28px); } to { opacity: 1; transform: none; } }
@keyframes sm-dig { from { clip-path: inset(62% 0 0 0); transform: translateY(24%); } to { clip-path: inset(0 0 0 0); transform: none; } }
@keyframes sm-bubble { from { opacity: 0; transform: scale(.86) translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes sm-pop { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: none; } }
@keyframes sm-fail { to { opacity: 1; transform: none; } }
@keyframes sm-shake { 15% { transform: translateX(-4px); } 35% { transform: translateX(3px); } 55% { transform: translateX(-2px); } 75% { transform: translateX(1px); } }
@keyframes sm-slide { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@keyframes sm-ring { from { opacity: .5; transform: scale(.6); } to { opacity: 0; transform: scale(2.4); } }
@keyframes sm-low { 50% { opacity: .55; } }

/* ---------- scroll reveals (existing .rv system, retuned) ---------- */
html.rv-ok .rv { transform: translateY(14px); transition: opacity .55s var(--mo-out), transform .7s var(--mo-out); transition-delay: calc(var(--d, 0) * 70ms); }
html.rv-ok .rv.in { transform: none; }
/* If the reveal script never runs (module failed), everything still appears after 2.5 s. */
html.js:not(.rv-ok) :is(.rv, .dig, .pv, .parts) { animation: sm-fail .01s 2s forwards; }
html.js:not(.rv-ok) :is(.dig .layer .bar i, .dig .layer .bar u, .tl i, .parts u i, .pv :is(.pv-bar, .pv-verdict > *, .filters span, tbody tr, .pv-foot, .pv-cats > div, .tl-cap)) { animation: sm-fail .01s 2s forwards; }

/* ---------- landing hero opening: headline, search, preview panel, then the mole digs up ---------- */
html.js .hero .wrap > div:first-child > h1 { animation: sm-h1 .72s var(--mo-out) both; }
html.js .hero .hero-sub { animation: sm-rise .7s var(--mo-out) .12s both; }
html.js .hero .hero-form { animation: sm-rise .7s var(--mo-out) .22s both; }
html.js .hero .hero-meta { animation: sm-rise .7s var(--mo-out) .32s both; }
html.js .hero .dig { animation: sm-rise .8s var(--mo-out) .5s both; }
html.js .hero .dig .layer .bar :is(i, u) { transition-delay: calc(var(--k, 0) * 90ms + 850ms); }
html.js .hero .dig-top, html.js .hero .dig-verdict { animation: sm-rise .6s var(--mo-out) both; }
html.js .hero .dig-top { animation-delay: .75s; }
html.js .hero .dig-verdict { animation-delay: 1.45s; }
html.js .hero .dig-kosto .bubble { transform-origin: 100% 100%; animation: sm-bubble .42s var(--mo-spring) 2.2s both; }
/* After arriving, the mole breathes: a slow idle, hero only. */
@keyframes mo-breathe { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-3px) scale(1.025); } }

/* ---------- product preview panels build in when scrolled to ---------- */
html.rv-ok .pv :is(.pv-bar, .pv-verdict > *, .filters span, tbody tr, .pv-foot, .pv-cats > div, .tl-cap) { opacity: 0; transform: translateY(8px); transition: opacity .4s var(--mo-out), transform .55s var(--mo-out); transition-delay: calc(var(--pi, 0) * 55ms); }
html.rv-ok .pv.in :is(.pv-bar, .pv-verdict > *, .filters span, tbody tr, .pv-foot, .pv-cats > div, .tl-cap) { opacity: 1; transform: none; }
html.rv-ok .pv :is(.pv-verdict > :nth-child(2), .filters span:nth-child(2), tbody tr:nth-child(2), .pv-cats > div:nth-child(2)) { --pi: 2; }
html.rv-ok .pv :is(.pv-verdict > :nth-child(3), .filters span:nth-child(3), tbody tr:nth-child(3), .pv-cats > div:nth-child(3)) { --pi: 3; }
html.rv-ok .pv :is(.filters span:nth-child(4), tbody tr:nth-child(4), .pv-cats > div:nth-child(4)) { --pi: 4; }
html.rv-ok .pv :is(.filters span:nth-child(5)) { --pi: 5; }
html.rv-ok .pv :is(.pv-verdict > :nth-child(1), .filters span:nth-child(1), tbody tr:nth-child(1), .pv-cats > div:nth-child(1)) { --pi: 1; }
html.rv-ok .pv :is(.pv-foot, .tl-cap) { --pi: 6; }
html.rv-ok .pv .pv-verdict .vchip { transition-timing-function: var(--mo-spring); }

/* ---------- pricing: the cycle switch glides, prices roll (JS), the card lifts on hover ---------- */
.seg.big::before { transition: transform .32s var(--mo-out), width .32s var(--mo-out), opacity .15s; }
.pc { transition: transform .25s var(--mo-out), border-color .2s; }
@media (hover: hover) { .pc:hover { transform: translateY(-3px); } }
.price b { display: inline-block; font-variant-numeric: tabular-nums; }

/* ---------- FAQ: the answer fades in with the height ---------- */
.faq-a > div { opacity: 0; transition: opacity .25s var(--mo-out); }
.faq-item.open .faq-a > div { opacity: 1; transition-delay: .06s; }
.faq-q .pm { transition: transform .3s var(--mo-out); }
.faq-q[aria-expanded="true"] .pm { transform: rotate(180deg); }

/* ---------- forms: subtle error shake, messages slide in, success pops ---------- */
.fld.err { animation: sm-shake .34s var(--mo-out); }
.fld .msg:not(:empty) { animation: sm-slide .22s var(--mo-out) both; }
.form-top:not(:empty) { animation: sm-slide .24s var(--mo-out) both; }
.form-top.good:not(:empty) { animation: sm-slide .24s var(--mo-out) both; }
.btn.spin { transition: opacity .15s; }
.strength i { transition: background .2s, transform .25s var(--mo-out); }
.strength[data-s] i { transform-origin: left; }
.auth-card { animation: sm-rise .45s var(--mo-out) both; }
.auth-card .kosto, .auth-side .kosto { animation: sm-rise .5s var(--mo-out) .2s both; }

/* ---------- checkout ---------- */
.countdown.low { animation: sm-low 1s ease-in-out infinite; }
.pstate.ok .pulse { position: relative; animation: sm-pop .45s var(--mo-spring) both; }
.pstate.ok .pulse::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--v-ok); animation: sm-ring .7s var(--mo-out) both; }
.pstate:not(.ok) { animation: sm-slide .24s var(--mo-out) both; }

/* ---------- account / admin: buttons, drawers, tabs ---------- */
.btn:not(:disabled):active { transform: scale(.97); }
.drawer { transition: transform .32s var(--mo-out); }
.snav a { transition: background .15s, color .15s; }
.copy-done svg { animation: sm-pop .28s var(--mo-spring) both; }

@media (prefers-reduced-motion: reduce) {
  html.js .hero * , html.js .hero, .fld.err, .fld .msg, .form-top, .auth-card, .auth-card .kosto, .auth-side .kosto, .pstate, .pstate.ok .pulse, .pstate.ok .pulse::after, .countdown.low { animation: none !important; }
  html.rv-ok .pv :is(.pv-bar, .pv-verdict > *, .filters span, tbody tr, .pv-foot, .pv-cats > div, .tl-cap), html.rv-ok .rv, .faq-a > div { opacity: 1; transform: none; transition: none; }
  .pc, .pc:hover { transform: none; transition: none; }
}

/* ---------- toast (copy confirmation): the tick draws itself ---------- */
.toast.on svg path { stroke-dasharray: 24; stroke-dashoffset: 24; animation: sm-draw .28s .07s var(--mo-inout) forwards; }
@keyframes sm-draw { to { stroke-dashoffset: 0; } }
.toast { transition: opacity .2s var(--mo-out), transform .3s var(--mo-out); }

/* ---------- 404: the mole digs up, then breathes ---------- */
main figure > img.mk[src*="kosto-error"] + figcaption { animation: sm-rise .5s var(--mo-out) .55s both; }
.auth-side .kosto .mk { transform-origin: 50% 92%; }
@media (prefers-reduced-motion: reduce) { main figure > img.mk, main figure > figcaption, .toast.on svg path { animation: none !important; stroke-dashoffset: 0; } }

/* ---------- auth pages (saas-auth.css): the stage assembles once, the mole comes up, its lamp switches on ----------
   Everything is visible by default: entrances use fill-mode "both" and are gated on JS + no reduced-motion. */
@keyframes au-stage { from { opacity: 0; clip-path: inset(0 0 0 8% round 16px); } to { opacity: 1; clip-path: inset(0 0 0 0 round 16px); } }
@keyframes au-in { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes au-grow { from { transform: scaleY(0); } to { transform: none; } }
@keyframes au-growx { from { transform: scaleX(0); } to { transform: none; } }
@keyframes au-arc { from { stroke-dasharray: 0 300; } }
@keyframes au-needle { from { transform: rotate(0deg); } }
@keyframes au-lamp { 0% { opacity: 0; } 30% { opacity: .9; } 42% { opacity: .25; } 58% { opacity: 1; } 100% { opacity: 1; } }
@keyframes au-breathe { 0%, 100% { transform: none; } 50% { transform: scale(1.018) translateY(-1px); } }
@keyframes au-bar { from { transform: scaleX(0); } to { transform: none; } }
@keyframes au-out { to { opacity: .55; filter: saturate(.6); } }
@media (prefers-reduced-motion: no-preference) {
  html.js .au-split .au-card > * { animation: au-in .5s var(--mo-out) both; }
  html.js .au-split .au-card > :nth-child(2) { animation-delay: .05s; }
  html.js .au-split .au-card > :nth-child(n+3) { animation-delay: .1s; }
  html.js .au-split .au-card > .au-alt { animation-delay: .18s; }
  html.js .au-stage { animation: au-stage .7s var(--mo-out) .05s both; }
  html.js .au-pitch { animation: au-in .6s var(--mo-out) .2s both; }
  html.js .vg-card { animation: au-in .62s var(--mo-out) both; animation-delay: calc(.32s + var(--i, 0) * .11s); }
  html.js .vg-gauge .val { animation: au-arc 1s var(--mo-out) .7s both; }
  html.js .vg-gauge .ndl { animation: au-needle 1s var(--mo-out) .7s both; }
  html.js .vg-tl u { animation: au-grow .6s var(--mo-out) both; animation-delay: calc(.6s + var(--d, 0) * .05s); }
  html.js .vg-tl > div:nth-child(2) u { --d: 1; } html.js .vg-tl > div:nth-child(3) u { --d: 2; } html.js .vg-tl > div:nth-child(4) u { --d: 3; }
  html.js .vg-tl > div:nth-child(5) u { --d: 4; } html.js .vg-tl > div:nth-child(6) u { --d: 5; } html.js .vg-tl > div:nth-child(7) u { --d: 6; } html.js .vg-tl > div:nth-child(8) u { --d: 7; }
  html.js .vg-sc i::after, html.js .vg-meter u i, html.js .vg-mix i { animation: au-growx .7s var(--mo-out) .85s both; }
  html.js .vg-row:not(.th) { animation: au-in .45s var(--mo-out) both; animation-delay: calc(.7s + var(--r, 0) * .06s); }
  html.js .vg-row:nth-child(2) { --r: 1; } html.js .vg-row:nth-child(3) { --r: 2; } html.js .vg-row:nth-child(4) { --r: 3; } html.js .vg-row:nth-child(5) { --r: 4; }
  html.js .vg-beam { animation: au-lamp .9s linear 1.6s both; }
  html.js .vg-say-k { transform-origin: 100% 100%; animation: sm-bubble .42s var(--mo-spring) 1.75s both; }
  /* single-card pages: the card rises, the mole comes up over its edge */
  html.js .au-box { animation: au-in .5s var(--mo-out) both; }
  /* micro-interactions */
  .au-fld.err { animation: sm-shake .34s var(--mo-out); }
  .au-msg:not(:empty), .au-note:not(:empty), .au-caps:not([hidden]) { animation: sm-slide .22s var(--mo-out) both; }
  .au-rules li.ok i { animation: sm-pop .3s var(--mo-spring); }
  .au-steps li.now i { animation: sm-pop .4s var(--mo-spring) .3s both; }
  .au-bar i { animation: au-bar .9s linear both; }
  /* leaving after a successful login: the page settles while the button confirms */
  .au-out .au-stage, .au-out .au-card > :not(form) { animation: au-out .5s var(--mo-out) forwards; }
}
.au-bar { height: 4px; border-radius: 2px; background: var(--grid); overflow: hidden; margin-top: 6px; }
.au-bar i { display: block; height: 100%; background: var(--v-ok); transform-origin: left; }

/* ---------- landing: the first screen answers the pointer ---------- */
/* Hover a year in the hero timeline: its bars re-fill and the flagged share lights up. */
@keyframes sm-refill { from { transform: scaleX(0); } to { transform: none; } }
.hero .dig .layer { cursor: default; }
.hero .dig .layer em, .hero .dig .layer b { transition: transform .2s var(--mo-out), color .2s; transform-origin: right center; }
.hero .dig .layer b { transform-origin: left center; }
@media (hover: hover) {
  html.js .hero .dig.in .layer:hover .bar i { animation: sm-refill .5s var(--mo-out) both; transform-origin: left; }
  html.js .hero .dig.in .layer:hover .bar u { animation: sm-refill .5s var(--mo-out) .12s both; transform-origin: left; }
  .hero .dig .layer:hover em { transform: scale(1.18); color: #fff; }
  .hero .dig .layer:hover b { transform: translateX(2px); color: #fff; }
}
/* Product previews: only the data mark under the pointer lifts, never the card. */
@media (hover: hover) {
  .pv .tl > div i, .pv .pv-cats > div u, .pv .pv-cats > div b, .pv tbody tr .vchip { transition-property: translate, scale, transform, opacity; transition-duration: .2s; transition-timing-function: var(--mo-out); }
  html.js .tl i { transition: transform .7s var(--mo-out), translate .2s var(--mo-out); transition-delay: calc(var(--k, 0) * 60ms + 200ms), 0s; }
  .pv .tl > div:hover i { translate: 0 -4px; }
  .pv .pv-cats > div:hover u { scale: 1 1.7; }
  .pv .pv-cats > div:hover b { translate: 0 -2px; }
  .pv tbody tr:hover .vchip { translate: 0 -2px; }
}
@media (prefers-reduced-motion: reduce) {
  .hero .dig .layer:hover em, .hero .dig .layer:hover b, .pv .tl > div:hover i, .pv .pv-cats > div:hover u, .pv .pv-cats > div:hover b, .pv tbody tr:hover .vchip { translate: none; scale: none; transform: none; }
  html.js .hero .dig.in .layer:hover .bar :is(i, u) { animation: none; }
}

/* ---------- mascot entrance (every mole image on the site) ----------
   The mole is the largest paint of the home page (LCP), so it is NEVER hidden: no opacity 0, no clip, no visibility wait. It is painted at once
   (preloaded, explicit size) and only settles: a small rise + scale to rest once the image has decoded (js/saas/motion.js adds .mk-in), then the
   idle bob. Reduced motion and no-JS get the plain image. The idle bob uses the independent translate/scale properties so it never fights the
   entrance and only starts after it. */
@keyframes mo-emerge { 0% { transform: translateY(7%) scale(.95); } 100% { transform: none; } }
@keyframes mo-bob { 0%, 100% { translate: 0 0; scale: 1; } 50% { translate: 0 -3px; scale: 1.025; } }
@media (prefers-reduced-motion: no-preference) {
  html.js img[src*="/brand/web/kosto-"].mk-in { transform-origin: 50% 92%; animation: mo-emerge .6s cubic-bezier(.33, 1, .68, 1) var(--mk-d, .05s) backwards, mo-bob 3.8s ease-in-out calc(var(--mk-d, .05s) + .9s) infinite; }
  .hero .dig-kosto img { --mk-d: 0s; }
  .vg-kosto { --mk-d: 1.05s; }
  .au-box > img { --mk-d: .25s; }
  main figure > img.mk { --mk-d: .15s; }
}
