/* Motion: press feedback, page and sheet transitions, and the log pop. Loaded last.
   Everything that moves sits behind prefers-reduced-motion: no-preference; Reduce Motion keeps color fades only. */
:root{
  --ease:cubic-bezier(.2,.8,.2,1);      /* quick start, soft landing */
  --spring:cubic-bezier(.3,1.5,.5,1);   /* slight overshoot */
}

/* Color and border changes ease instead of snapping */
button,.btn,summary,.toggle input,input,select{transition:background-color .2s var(--ease),border-color .2s var(--ease),color .2s var(--ease),opacity .2s var(--ease),box-shadow .2s var(--ease),transform .14s var(--ease)}
input:focus,select:focus{border-color:var(--ink2)}

/* Status lines fade out instead of vanishing */
.saved.out,#gym-status.out{opacity:0;transition:opacity .2s}

/* The check on a logged button sits beside the label */
.btn.hero>span{display:inline-flex;align-items:center;gap:8px}
.btn.hero .ck{flex:none;margin-top:-2px}

@media (prefers-reduced-motion:no-preference){
  /* ---------- press ---------- */
  button:not(:disabled):active,.btn:active,summary:active{transform:scale(.96)}
  .btn.hero:active,details.card>summary:active,.lr-o:active,.lhead[data-act]:active,.moremenu button:active,.moremenu a:active{transform:scale(.985)}
  .strip .c:not(:disabled):active,.cal .d:not(.blank):active{transform:scale(.9)}
  button:not(:disabled):active{opacity:.85}
  /* Bottom bar: the icon squeezes on press */
  .tabbar button:active{transform:none}
  .tabbar button svg,.tabbar .tb-av{transition:transform .14s var(--ease)}
  .tabbar button:active svg,.tabbar button:active .tb-av{transform:scale(.86)}
  /* the workout done card, the moment the last exercise goes in */
  .wo-done.just{animation:hero-pop .55s var(--d,0s) var(--spring) both}
  .wo-done.just .wo-dc path{stroke-dasharray:24;stroke-dashoffset:24;animation:ck-draw .35s calc(var(--d,0s) + .12s) var(--ease) forwards}
  /* and the tab you land on pops */
  .tabbar button[aria-current=page] svg,.tabbar button[aria-current=page] .tb-av{animation:tab-pop .4s var(--spring)}
  @keyframes tab-pop{0%{transform:scale(.86)}55%{transform:scale(1.12)}100%{transform:scale(1)}}

  /* ---------- log pop ---------- */
  /* --d is how long ago the tap was (negative), set by js/ui/motion.js, so a re-render mid-pop carries on */
  .btn.hero.just{animation:hero-pop .55s var(--d,0s) var(--spring) both}
  .btn.hero.just .ck path{stroke-dasharray:24;stroke-dashoffset:24;animation:ck-draw .35s calc(var(--d,0s) + .12s) var(--ease) forwards}
  .strip .c.just{animation:cell-pop .5s var(--d,0s) var(--spring) both}
  @keyframes hero-pop{0%{transform:scale(.94)}45%{transform:scale(1.03)}100%{transform:scale(1)}}
  @keyframes ck-draw{to{stroke-dashoffset:0}}
  @keyframes cell-pop{0%{transform:scale(.8)}50%{transform:scale(1.12)}100%{transform:scale(1)}}

  /* ---------- page change: cards rise in one after another ---------- */
  main.enter>[data-page]:not([hidden]){animation:card-in .38s var(--ease) both;animation-delay:calc(min(var(--i,0),6) * 45ms)}
  main.enter .meter i{animation:bar-grow .7s .15s var(--ease) both;transform-origin:left}
  @keyframes card-in{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:none}}
  @keyframes bar-grow{from{transform:scaleX(0)}to{transform:scaleX(1)}}

  /* ---------- pagers: month and running day slide the way you went ---------- */
  .cal.slide-fwd,#running.slide-fwd>:not(.card-head),#workout.slide-fwd>:not(.card-head){animation:from-right .3s var(--ease) both}
  .cal.slide-back,#running.slide-back>:not(.card-head),#workout.slide-back>:not(.card-head){animation:from-left .3s var(--ease) both}
  /* a swipe to another page slides its cards in the same way */
  main.slide-fwd>[data-page]:not([hidden]){animation:from-right .3s var(--ease) both}
  main.slide-back>[data-page]:not([hidden]){animation:from-left .3s var(--ease) both}
  main.stay>[data-also]{animation:none!important}
  /* while a page follows the finger (js/ui/swipe.js) it can't widen the page past the screen, and a pager's slides stay in their card */
  /* on <html> as well: alone, the body's clip is handed up to the viewport, where a phone still widens the page to fit what sticks out */
  html:has(body.swiping),body.swiping{overflow-x:clip}
  .paging{position:relative}
  .card.paging{overflow:clip}
  /* A drag owns movement: tap feedback and entry animations must not scale or override it. */
  body.swiping button:active,body.swiping .btn:active,body.swiping summary:active{transform:none;opacity:1}
  .card.paging,.card.paging *{animation:none!important}
  /* the next page, beside the one being swiped (js/ui/swipe.js peek): laid out like the body, so it looks as it will once it's open */
  .peek{position:fixed;inset:0;z-index:14;overflow:hidden;background:var(--bg);pointer-events:none;padding:12px 0 0;padding-left:inherit;padding-right:inherit}
  /* between the Profile tabs the real header stays on screen, so the layer is see-through */
  .peek.tabpeek{background:transparent}
  /* a pager's next slide, beside the one being dragged inside its card (js/ui/swipe.js pagerPeek) */
  .pgpeek{position:absolute;pointer-events:none}
  @keyframes from-right{from{opacity:0;transform:translateX(24px)}to{opacity:1;transform:none}}
  @keyframes from-left{from{opacity:0;transform:translateX(-24px)}to{opacity:1;transform:none}}

  /* ---------- sheets: rise in, drop out ---------- */
  #checkin[open],#dayview[open],.sheet[open]{animation:sheet-in .32s var(--spring) both}
  #checkin[open]::backdrop,#dayview[open]::backdrop,.sheet[open]::backdrop{animation:fade-in .25s ease both}
  #checkin.closing,#dayview.closing,.sheet.closing{animation:sheet-out .17s ease-in both}
  #checkin.closing::backdrop,#dayview.closing::backdrop,.sheet.closing::backdrop{animation:fade-in .17s ease-in reverse both}
  @keyframes sheet-in{from{opacity:0;transform:translateY(28px) scale(.97)}to{opacity:1;transform:none}}
  @keyframes sheet-out{to{opacity:0;transform:translateY(20px) scale(.98)}}
  /* a friend's profile grows out of the photo you tapped (--ox, --oy: js/ui/motion.js growFrom) */
  dialog.grow[open]:not(.closing){animation:grow-in .36s var(--ease) both;transform-origin:var(--ox) var(--oy)}
  @keyframes grow-in{from{opacity:0;transform:scale(.2)}50%{opacity:1}to{opacity:1;transform:none}}
  /* pulled by the finger (js/ui/sheet-drag.js): the spring moves it from here on, and the backdrop fades as it goes down */
  dialog.held:not(.closing){animation:none!important}
  dialog.held:not(.closing)::backdrop{animation:none!important;opacity:var(--bd,1)}
  @keyframes fade-in{from{opacity:0}to{opacity:1}}

  /* ---------- menus and expanding rows ---------- */
  .moremenu:not([hidden]){animation:menu-in .2s var(--ease) both;transform-origin:bottom right}
  @keyframes menu-in{from{opacity:0;transform:scale(.92) translateY(6px)}to{opacity:1;transform:none}}
  details[open]>summary~*{animation:reveal .25s var(--ease) both}
  @keyframes reveal{from{opacity:0;transform:translateY(-6px)}to{opacity:1;transform:none}}

  /* ---------- status and confirm ---------- */
  .saved.flash,#gym-status.flash{animation:msg-in .25s var(--ease) both}
  @keyframes msg-in{from{opacity:0;transform:translateY(4px)}to{opacity:1;transform:none}}
  .btn.sure{animation:nudge .3s var(--ease)}
  @keyframes nudge{20%{transform:translateX(-3px)}50%{transform:translateX(3px)}80%{transform:translateX(-1px)}}

  /* Session and cardio pickers: the picked one settles in */
  .splitpick button[aria-pressed=true]{transition:background-color .2s var(--ease),border-color .2s var(--ease),color .2s var(--ease),transform .2s var(--spring)}
}

/* The upload bar slides up, and steps with no known amount (getting ready, finishing, processing) run a sliding segment */
@media (prefers-reduced-motion:no-preference){
  html:not(.still) .vidbar:not([hidden]){animation:vb-in .28s var(--ease) both}
  html:not(.still) .vb-bar.busy i{width:35%;opacity:1;animation:vb-slide 1.1s ease-in-out infinite}
  @keyframes vb-in{from{opacity:0;transform:translate(-50%,16px)}to{opacity:1;transform:translate(-50%,0)}}
  @keyframes vb-slide{from{left:-35%}to{left:100%}}
}
