/*
 * Yomochi's idle motions on the write tab and the calendar faces' glance. public/js/mascot-idle.js
 * adds one m-<id> class for as long as its duration (mascot-idle-model.js), so each animation
 * runs once. DiaryKit's MascotIdle draws the same keyframes in the iPhone app.
 */
.mascot-whole {
  transform-origin: 60px 108px;
}

/* The stem's root, where it meets the body, is the leaf's hinge. */
.mascot-sprout {
  transform-origin: 61px 48px;
}

/* Each cheek swells about its own center; scaling the pair's box would push them onto the outline. */
.mascot-eyes,
.mascot-cheek {
  transform-box: fill-box;
  transform-origin: center;
}

.mascot-closed,
.mascot-happy,
.mascot-z {
  opacity: 0;
}

.mascot-z {
  fill: var(--color-leaf-dark);
}

.day-whole {
  transform-origin: 18px 34px;
}

@media (prefers-reduced-motion: no-preference) {
  .mascot.m-blink .mascot-eyes {
    animation: idle-blink 0.36s ease-in-out;
  }

  .mascot.m-blink2 .mascot-eyes {
    animation: idle-blink 0.32s ease-in-out 2;
  }

  .mascot.m-look .mascot-face {
    animation: idle-look 2.2s ease-in-out;
  }

  .mascot.m-look .mascot-whole {
    animation: idle-look-tilt 2.2s ease-in-out;
  }

  .mascot.m-leaf .mascot-sprout {
    animation: idle-leaf 1.4s ease-in-out;
  }

  .mascot.m-smile .mascot-eyes {
    animation: idle-smile-open 1.8s steps(1, end);
  }

  .mascot.m-smile .mascot-happy {
    animation: idle-smile-happy 1.8s steps(1, end);
  }

  .mascot.m-smile .mascot-cheek {
    animation: idle-smile-cheeks 1.8s ease-in-out;
  }

  .mascot.m-hop .mascot-whole,
  .mascot-photo.m-hop {
    animation: idle-hop 0.9s cubic-bezier(0.3, 0.7, 0.4, 1);
  }

  .mascot.m-jiggle .mascot-whole,
  .mascot-photo.m-jiggle {
    animation: idle-jiggle 0.8s ease-out;
  }

  /* A picture squashes from its bottom edge, as the drawing does from her feet, and hops as high
     for its size: 16 of the drawing's 120 units. */
  .mascot-photo {
    transform-origin: 50% 100%;
    --idle-hop-y: -13.333%;
  }

  .mascot.m-doze .mascot-whole {
    animation: idle-doze-tilt 3.6s ease-in-out;
  }

  .mascot.m-doze .mascot-eyes {
    animation: idle-doze-open 3.6s steps(1, end);
  }

  .mascot.m-doze .mascot-closed {
    animation: idle-doze-closed 3.6s steps(1, end);
  }

  .mascot.m-doze .mascot-z {
    animation: idle-doze-z 3.6s ease-out;
  }

  .day-face.m-look .day-face-parts {
    animation: idle-day-look 2s ease-in-out;
  }

  .day-face.m-look .day-whole {
    animation: idle-day-tilt 2s ease-in-out;
  }

  @keyframes idle-blink {
    45%,
    55% {
      transform: scaleY(0.1);
    }
  }

  @keyframes idle-look {
    14%,
    40% {
      transform: translateX(-7px);
    }

    56%,
    82% {
      transform: translateX(7px);
    }
  }

  @keyframes idle-look-tilt {
    14%,
    40% {
      transform: rotate(-3deg);
    }

    56%,
    82% {
      transform: rotate(3deg);
    }
  }

  @keyframes idle-leaf {
    20% {
      transform: rotate(20deg);
    }

    40% {
      transform: rotate(-14deg);
    }

    60% {
      transform: rotate(10deg);
    }

    80% {
      transform: rotate(-5deg);
    }
  }

  @keyframes idle-smile-open {
    8% {
      opacity: 0;
    }

    88% {
      opacity: 1;
    }
  }

  @keyframes idle-smile-happy {
    8% {
      opacity: 1;
    }

    88% {
      opacity: 0;
    }
  }

  @keyframes idle-smile-cheeks {
    20%,
    80% {
      transform: scale(1.3);
    }
  }

  @keyframes idle-hop {
    18% {
      transform: scale(1.1, 0.88);
    }

    45% {
      transform: translateY(var(--idle-hop-y, -16px)) scale(0.94, 1.07);
    }

    70% {
      transform: translateY(0) scale(1.12, 0.86);
    }

    85% {
      transform: scale(0.97, 1.03);
    }
  }

  @keyframes idle-jiggle {
    20% {
      transform: scale(1.1, 0.9);
    }

    40% {
      transform: scale(0.93, 1.07);
    }

    60% {
      transform: scale(1.05, 0.95);
    }

    80% {
      transform: scale(0.98, 1.02);
    }
  }

  /* She nods off to one side, then jolts awake. */
  @keyframes idle-doze-tilt {
    8% {
      transform: rotate(0deg);
    }

    70% {
      transform: rotate(-7deg) translateY(1px);
    }

    76% {
      transform: rotate(0deg) translateY(-6px);
    }

    84% {
      transform: none;
    }
  }

  @keyframes idle-doze-open {
    10% {
      opacity: 0;
    }

    74% {
      opacity: 1;
    }
  }

  @keyframes idle-doze-closed {
    10% {
      opacity: 1;
    }

    74% {
      opacity: 0;
    }
  }

  @keyframes idle-doze-z {
    18% {
      opacity: 0;
      transform: none;
    }

    30% {
      opacity: 1;
    }

    66% {
      opacity: 1;
      transform: translate(6px, -14px);
    }

    74%,
    100% {
      opacity: 0;
      transform: translate(8px, -18px);
    }
  }

  @keyframes idle-day-look {
    15%,
    42% {
      transform: translateX(-2.4px);
    }

    58%,
    85% {
      transform: translateX(2.4px);
    }
  }

  @keyframes idle-day-tilt {
    15%,
    42% {
      transform: rotate(-6deg);
    }

    58%,
    85% {
      transform: rotate(6deg);
    }
  }
}
