/* avatar.css: a model wearing a coat and a bag, in the waiting queue (js/components/avatar.js).
   Inside an avatar, 1cqh = 1% of the model's height. Each model brings her own --shoulders,
   --shoulder-line, --body, --bag-hand-x, --bag-top and --eyes (js/data/models.js). */

.avatar {
  --bag-width: 13cqh; /* width of a bag with scale 1, as on the Archives page */
  position: relative;
  flex: none;
  width: calc(
    var(--avatar-height) * 0.4
  ); /* the space each person takes in the queue */
  /* --avatar-height is from the eyes to the feet: the picture is taller by what is above her eyes. */
  /* --stature: how tall she is next to the others (js/data/models.js); her feet stay on the floor. */
  height: calc(
    var(--avatar-height) * var(--stature, 1) * 100 / (100 - var(--eyes))
  );
  container-type: size;
}

.avatar > * {
  position: absolute;
  left: 50%;
}

/* The pictures never catch a tap: their transparent edges overlap the neighbours, whose like
   buttons must stay reachable (js/interactions/queue-like.js). */
.avatar img,
.avatar canvas {
  pointer-events: none;
}

.avatar-model {
  top: 0;
  width: auto;
  max-width: none;
  height: 100%;
  transform: translateX(-50%);
}

/* The coat's shoulders on her shoulder line. Its size (--px) is set in css/components/coat-fit.css. */
.avatar-coat {
  top: calc(var(--shoulder-line) - var(--px) * var(--shoulder-top));
  transform: translateX(-50%);
}

/* The handle in her hand. --scale comes from each bag in js/data/bags.js. */
.avatar-bag {
  top: var(--bag-top);
  width: calc(var(--bag-width) * var(--scale, 1));
  transform: translateX(calc(var(--bag-hand-x) - 50%));
}

.avatar-coat > *,
.avatar-bag > * {
  width: 100%;
}

/* Entering the store (js/render.js): she no longer has a place in the queue. */
.avatar[data-leaving] .avatar-number {
  visibility: hidden;
}

/* Her place in the queue, centred under her feet. */
.avatar-number {
  top: calc(100% + var(--space-3));
  /* The letter spacing also follows the last digit: the same space before the first keeps it centred. */
  padding-left: var(--tracking-wide);
  font-size: var(--text-note);
  letter-spacing: var(--tracking-wide);
  transform: translateX(-50%);
}

/* The hand-drawn crown over the first in the queue (assets/doodles/crown.svg), placed on the top of
   her head, its rays to the upper right. In % of her height (cqh), measured on the mockup. */
.avatar-crown {
  top: calc(
    2.7cqh - 10.4cqh
  ); /* its base 2.7 below the top of her head; it is 10.4 tall */
  left: calc(50% - 4.6cqh);
  width: 17.3cqh;
  max-width: none;
}

/* -- liking an outfit: tap a person (js/interactions/queue-like.js) -- */
.avatar-like {
  inset: 0;
  left: 0;
  border: 0;
  background: none;
  /* No dark box flashing over her on a phone when she is tapped: the doodle is the feedback.
     The keyboard focus ring (css/base.css) stays. */
  -webkit-tap-highlight-color: transparent;
}

/* The doodle, around her head. --like-left, --like-top and --like-width come from queue-like.js. */
.avatar-liked {
  top: var(--like-top);
  left: calc(50% + var(--like-left));
  width: var(--like-width);
  max-width: none;
}

@keyframes avatar-liked {
  0% {
    opacity: 0;
    transform: scale(0.85) rotate(-4deg);
  }
  15% {
    opacity: 1;
    transform: scale(1.04);
  }
  25% {
    transform: none;
  }
  75% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-1.5cqh);
  }
}

/* A little pulse when she is liked: she grows, shrinks back past her size, and settles. */
@keyframes avatar-bounce {
  0% {
    transform: none;
  }
  30% {
    transform: scale(1.06);
  }
  55% {
    transform: scale(0.97);
  }
  75% {
    transform: scale(1.02);
  }
  100% {
    transform: none;
  }
}

/* Pops in, then floats away; with reduced motion the doodle only appears, then goes, and she does not pulse. */
@media (prefers-reduced-motion: no-preference) {
  .avatar-liked {
    animation: avatar-liked 1400ms ease-out forwards;
  }

  .avatar-bounce {
    transform-origin: 50% 50%;
    animation: avatar-bounce 500ms ease-out;
  }
}

/* -- a like for you while you are on screen: a doodle wraps around you (js/interactions/queue-votes.js) -- */
.avatar-wrapped {
  top: calc(var(--wrap-top) * 1cqh);
  left: calc(50% + var(--wrap-left) * 1cqh);
  width: calc(var(--wrap-width) * 1cqh);
  max-width: none;
}

/* The line draws itself from top to bottom, stays a moment, then fades. */
@keyframes avatar-wrapped {
  0% {
    clip-path: inset(0 0 100% 0);
  }
  45% {
    clip-path: inset(0 0 0 0);
  }
  80% {
    opacity: 1;
  }
  100% {
    clip-path: inset(0 0 0 0);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .avatar-wrapped {
    animation: avatar-wrapped 2200ms ease-out forwards;
  }
}
