/* popconui: micro-interactions for icons. MIT licence. https://github.com/aeivrix/popconui

   Wrap an icon in <span class="popcon">. It plays when the closest link, button, label,
   summary, [role=button] or [data-popcon-trigger] is hovered or keyboard-focused.
     .popcon-play   on the wrapper or a parent: play once now (remove and re-add to replay)
     .popcon-loop   on the wrapper or a parent: repeat, with a pause between (e.g. unread alerts)
     --popcon-lift  scale the jump (1 = 1.75px, tuned for 16-48px icons)
     --popcon-speed length of one play (default 0.7s)
   Only transform and stroke-dashoffset animate, so nothing around the icon moves.
   With reduced motion turned on, nothing animates. */

.popcon { display: inline-flex; vertical-align: middle; transform-origin: 50% 100%; } /* lands on its base */
.popcon svg { overflow: visible; }
.popcon .pc { transform-box: fill-box; }

@media (prefers-reduced-motion: no-preference) {
  :where(a, button, label, summary, [role=button], [data-popcon-trigger]):is(:hover, :focus-visible) .popcon,
  .popcon:hover, .popcon-play .popcon, .popcon.popcon-play { animation: popcon-hop var(--popcon-speed, .7s); }

  :where(a, button, label, summary, [role=button], [data-popcon-trigger]):is(:hover, :focus-visible) .popcon .pc,
  .popcon:hover .pc, .popcon-play .popcon .pc, .popcon.popcon-play .pc { animation: var(--pc-anim, popcon-part) var(--popcon-speed, .7s); }

  /* loop: one play, then rest for twice as long */
  .popcon-loop .popcon, .popcon.popcon-loop { animation: popcon-hop-loop calc(var(--popcon-speed, .7s) * 3) infinite; }
  .popcon-loop .popcon .pc, .popcon.popcon-loop .pc { animation: var(--pc-loop, popcon-part-loop) calc(var(--popcon-speed, .7s) * 3) infinite; }
}

/* The hop: jump, land with a squash, ripple, settle. Width and height move against each other. */
@keyframes popcon-hop {
  0%   { transform: none;                                                         animation-timing-function: cubic-bezier(.2, .7, .4, 1); }
  24%  { transform: translateY(calc(-1.75px * var(--popcon-lift, 1))) scale(.96, 1.045); animation-timing-function: cubic-bezier(.6, 0, .9, .5); }
  40%  { transform: translateY(0) scale(1.1, .9);                                 animation-timing-function: ease-out; }
  54%  { transform: scale(.96, 1.04);                                             animation-timing-function: ease-in-out; }
  67%  { transform: scale(1.03, .97);                                             animation-timing-function: ease-in-out; }
  79%  { transform: scale(.985, 1.015);                                           animation-timing-function: ease-in-out; }
  90%  { transform: scale(1.005, .995); }
  100% { transform: none; }
}
@keyframes popcon-hop-loop { /* the same hop, squeezed into the first third */
  0%   { transform: none;                                                         animation-timing-function: cubic-bezier(.2, .7, .4, 1); }
  8%   { transform: translateY(calc(-1.75px * var(--popcon-lift, 1))) scale(.96, 1.045); animation-timing-function: cubic-bezier(.6, 0, .9, .5); }
  13.3% { transform: translateY(0) scale(1.1, .9);                                animation-timing-function: ease-out; }
  18%  { transform: scale(.96, 1.04);                                             animation-timing-function: ease-in-out; }
  22.3% { transform: scale(1.03, .97);                                            animation-timing-function: ease-in-out; }
  26.3% { transform: scale(.985, 1.015);                                          animation-timing-function: ease-in-out; }
  30%  { transform: scale(1.005, .995); }
  33.3%, 100% { transform: none; }
}

/* A part's own motion: it goes to --pc-a, swings back past rest to --pc-b, then --pc-c, then rests. */
@keyframes popcon-part {
  0%   { transform: none; animation-timing-function: cubic-bezier(.2, .7, .4, 1); }
  30%  { transform: var(--pc-a); animation-timing-function: ease-in-out; }
  55%  { transform: var(--pc-b); animation-timing-function: ease-in-out; }
  78%  { transform: var(--pc-c); animation-timing-function: ease-in-out; }
  100% { transform: none; }
}
@keyframes popcon-part-loop {
  0%   { transform: none; animation-timing-function: cubic-bezier(.2, .7, .4, 1); }
  10%  { transform: var(--pc-a); animation-timing-function: ease-in-out; }
  18.3% { transform: var(--pc-b); animation-timing-function: ease-in-out; }
  26%  { transform: var(--pc-c); animation-timing-function: ease-in-out; }
  33.3%, 100% { transform: none; }
}
@keyframes popcon-spin {
  0%   { transform: none; animation-timing-function: cubic-bezier(.3, 0, .2, 1); }
  70%  { transform: rotate(375deg); animation-timing-function: ease-in-out; }
  100% { transform: rotate(360deg); }
}
@keyframes popcon-spin-loop {
  0%   { transform: none; animation-timing-function: cubic-bezier(.3, 0, .2, 1); }
  23.3% { transform: rotate(375deg); animation-timing-function: ease-in-out; }
  33.3%, 100% { transform: rotate(360deg); }
}
@keyframes popcon-draw { 0% { stroke-dashoffset: 1; } 65%, 100% { stroke-dashoffset: 0; } }
@keyframes popcon-draw-loop { 0% { stroke-dashoffset: 1; } 21.7%, 100% { stroke-dashoffset: 0; } }

.pc-up    { --pc-a: translateY(-2.5px); --pc-b: translateY(.8px);  --pc-c: translateY(-.3px); }
.pc-down  { --pc-a: translateY(2.5px);  --pc-b: translateY(-.8px); --pc-c: translateY(.3px); }
.pc-left  { --pc-a: translateX(-2px);   --pc-b: translateX(.7px);  --pc-c: translateX(-.3px); }
.pc-right { --pc-a: translateX(2.5px);  --pc-b: translateX(-.8px); --pc-c: translateX(.3px); }
.pc-fly   { --pc-a: translate(2.5px, -2.5px);  --pc-b: translate(-.8px, .8px);  --pc-c: translate(.3px, -.3px); }
.pc-back  { --pc-a: translate(-1.5px, -1.5px); --pc-b: translate(.5px, .5px);   --pc-c: translate(-.2px, -.2px); }
.pc-sw    { --pc-a: translate(-2px, 2px);      --pc-b: translate(.7px, -.7px);  --pc-c: translate(-.3px, .3px); }
.pc-look  { --pc-a: translate(-1.5px, -1px);   --pc-b: translate(1.2px, .4px);  --pc-c: translate(-.4px, 0); }
.pc-slide { --pc-a: translateX(9px);    --pc-b: translateX(7.5px); --pc-c: translateX(8.2px); }
.pc-shake { --pc-a: translateX(-1.5px); --pc-b: translateX(1.5px); --pc-c: translateX(-.6px); }
.pc-swing { transform-origin: 50% 0;    --pc-a: rotate(16deg);  --pc-b: rotate(-10deg); --pc-c: rotate(4deg); }
.pc-sway  { transform-origin: 50% 100%; --pc-a: rotate(-10deg); --pc-b: rotate(6deg);   --pc-c: rotate(-2deg); }
.pc-lift  { transform-origin: 0 100%;   --pc-a: rotate(-20deg) translateY(-1px); --pc-b: rotate(3deg); --pc-c: rotate(-3deg); }
.pc-open  { transform-origin: 50% 100%; --pc-a: skewX(-14deg) scaleY(.8); --pc-b: skewX(4deg) scaleY(1.03); --pc-c: skewX(-2deg); }
.pc-flap  { transform-origin: 50% 0;    --pc-a: scaleY(-.7);   --pc-b: scaleY(-.5);   --pc-c: scaleY(-.6); }
.pc-beat  { transform-origin: 50% 50%;  --pc-a: scale(1.2);    --pc-b: scale(.92);    --pc-c: scale(1.04); }
.pc-blink { transform-origin: 50% 50%;  --pc-a: scaleY(.1);    --pc-b: scaleY(1.05);  --pc-c: scaleY(.98); }
.pc-tilt  { transform-origin: 50% 50%;  --pc-a: rotate(-22deg); --pc-b: rotate(9deg);  --pc-c: rotate(-3deg); }
.pc-tick  { transform-origin: 50% 100%; --pc-a: rotate(60deg);  --pc-b: rotate(40deg); --pc-c: rotate(48deg); }
.pc-wave  { transform-origin: 0 50%;    --pc-a: skewY(-9deg) scaleX(.9); --pc-b: skewY(6deg); --pc-c: skewY(-2deg); }
.pc-roll  { transform-origin: 50% 50%;  --pc-a: scaleX(.15);   --pc-b: scaleX(1.15);  --pc-c: scaleX(.95); }
.pc-flip  { transform-origin: 0 50%;    --pc-a: scaleX(.25);   --pc-b: scaleX(1.06);  --pc-c: scaleX(.97); }
.pc-spin  { transform-origin: 50% 50%;  --pc-anim: popcon-spin; --pc-loop: popcon-spin-loop; }
.pc-draw  { stroke-dasharray: 1;        --pc-anim: popcon-draw; --pc-loop: popcon-draw-loop; } /* give the path pathLength="1" */
