/* Flexbox центрирует анимку внутри страницы. */
.flexbox-demo {
    display: flex;
    justify-content: center;
    align-items: center;
}

.scene {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 24px auto;
  border: 2px solid #222;
  box-sizing: border-box; /* Компонент вместе с рамкой занимает 200 x 200 px. */
  overflow: hidden;
  background: radial-gradient(circle at 60% 35%, #fff, #d761e0 75%);
  cursor: pointer;
  user-select: none;
  transition: filter 1.2s;
}

.prince {
  position: absolute;
  left: 10px;
  bottom: 9px;
  width: 75px;
  height: 163px;
}

.prince-full {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 75px;
}

.prince-parts {
  opacity: 0;
  pointer-events: none;
}

.prince-body {
  position: absolute;
  bottom: 0;
  left: -5px;
  width: 85px;
}

.prince-head {
  position: absolute;
  top: 7px;
  left: 26px;
  width: 30px;
  transform-origin: 50% 85%;
}

/* При наведении на принца меняем целое изображение на тело и голову. */
.prince:hover .prince-full {
  opacity: 0;
}

.prince:hover .prince-parts {
  opacity: 1;
}

.prince:hover .prince-head {
  animation: shake-head 0.6s infinite;
}

/* Лягушка появляется справа и плавно приближается к принцу. */
.frog {
    position: absolute;
    right: 22px;
    bottom: 9px;
    width: 50px;
    opacity: 0;
    transform: translate(82px, 0);
}

.frog img {
  display: block;
  width: 100%;
}

.scene:hover .frog {
  opacity: 1;
  animation: frog-appear 1.4s ease-out forwards;
}

.frog:hover img {
  animation: jump 0.6s infinite;
}

.princess {
  position: absolute;
  right: 4px;
  bottom: 9px;
  width: 88px;
  opacity: 0;
  transform: scale(0.15);
  transform-origin: 50% 100%;
  transition: transform 1s, opacity 1s;
  pointer-events: none;
}

.caption {
  position: absolute;
  top: 28px;
  right: 16px;
  font-size: 16px;
  transform: rotate(13deg);
  opacity: 0;
  pointer-events: none;
}

.scene:hover .caption {
  opacity: 1;
}

.answer {
  display: none;
}

/* Превращение работает, пока кнопка мыши зажата. */
.scene:active {
  filter: sepia(1);
}

.scene:active .frog {
  opacity: 0;
}

.scene:active .princess {
  opacity: 1;
  transform: scale(1);
}

.scene:active .caption {
  top: 14px;
  right: 6px;
  font-size: 14px;
}

.scene:active .question {
  display: none;
}

.scene:active .answer {
  display: block;
}

@keyframes shake-head {
  0%, 100% {
    transform: rotate(-9deg);
  }
  50% {
    transform: rotate(9deg);
  }
}

@keyframes jump {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-7px);
  }
}

@keyframes frog-appear {
    0% {
        transform: translate(82px, 0);
        opacity: 0;
    }

    50% {
        transform: translate(41px, -55px);
    }

    75% {
        opacity: 1;
    }


    100% {
        transform: translate(0, 0);
        opacity: 1;
    }
}
