/* Opening animation: intentionally kept separate from the page styles. */

.opening-animation {
  /* Change this value to compare expansion easing. */
  --opening-photo-easing: cubic-bezier(0.45, 0, 0.55, 1);

  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
  overflow: hidden;
  background: var(--color-panel, #f0e1b5);
  opacity: 1;
  pointer-events: auto;
  transition: opacity 0.9s ease-out;
}

html {
  overflow-y: scroll;
}

.opening-is-active {
  overflow-y: scroll;
}

.opening-is-active body {
  position: fixed;
  inset: 0;
  width: 100%;
  overflow: hidden;
}

.opening-is-active .opening-animation {
  display: block;
}

.opening-animation__title {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  width: min(72vw, 650px);
  aspect-ratio: 1521 / 473;
  opacity: 0;
  transform: translate3d(-50%, -50%, 0);
  will-change: opacity;
  backface-visibility: hidden;
  transition: opacity 0.7s ease-out;
}

.opening-animation__text {
  position: absolute;
  inset: 0;
  background: var(--color-primary, #a1506f);
  -webkit-mask: url("img/mv-txt-opening-text.svg") center / contain no-repeat;
  mask: url("img/mv-txt-opening-text.svg") center / contain no-repeat;
}

.opening-animation__leaf {
  position: absolute;
  inset: 0;
  background: var(--color-primary, #a1506f);
  opacity: 0;
  -webkit-mask: url("img/mv-txt-opening-leaf.svg") center / contain no-repeat;
  mask: url("img/mv-txt-opening-leaf.svg") center / contain no-repeat;
  filter: blur(3px);
  transform: translate3d(0, 6px, 0) scale(0.96);
  transform-origin: 26% 14%;
  transition:
    opacity 1s ease-out,
    filter 1s ease-out,
    transform 1.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.opening-animation__line {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.opening-animation__line path {
  fill: none;
  stroke: var(--color-primary, #a1506f);
  stroke-width: 2px;
  stroke-miterlimit: 10;
  stroke-dasharray: 1 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 0.9s cubic-bezier(0.45, 0, 0.25, 1);
}

.opening-animation.is-title-visible .opening-animation__title {
  opacity: 1;
}

.opening-animation.is-line-drawing .opening-animation__line path {
  stroke-dashoffset: 0;
}

.opening-animation.is-leaf-visible .opening-animation__leaf {
  opacity: 1;
  filter: blur(0);
  transform: translate3d(0, 0, 0) scale(1);
}

.opening-animation__photo {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  overflow: hidden;
  opacity: 0;
  clip-path: inset(45% 45% round 12px);
  will-change: clip-path, opacity;
  transition:
    opacity 0.35s ease-out,
    clip-path 0.75s var(--opening-photo-easing);
}

/* Remove opening-animation--bottle from the markup to restore the rectangle reveal. */
.opening-animation--bottle .opening-animation__photo {
  border-radius: 12px;
  clip-path: none;
  -webkit-mask-image: url("img/teapot_silhouette.svg");
  mask-image: url("img/teapot_silhouette.svg");
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: clamp(64px, 8vw, 104px) clamp(48px, 6vw, 78px);
  mask-size: clamp(64px, 8vw, 104px) clamp(48px, 6vw, 78px);
  will-change: mask-size, opacity;
  transition:
    opacity 0.35s ease-out,
    -webkit-mask-size 0.75s var(--opening-photo-easing),
    mask-size 0.75s var(--opening-photo-easing);
}

.opening-animation__photo::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--color-hero-tint, rgb(161 80 111 / 15%));
  mix-blend-mode: multiply;
  pointer-events: none;
}

.opening-animation__photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.opening-animation.is-photo-visible .opening-animation__photo {
  opacity: 1;
}

.opening-animation.is-photo-expanded .opening-animation__photo {
  clip-path: inset(0 round 12px);
}

.opening-animation--bottle.is-photo-expanded .opening-animation__photo {
  clip-path: none;
  -webkit-mask-size: 600vw 450vw;
  mask-size: 600vw 450vw;
}

.opening-animation.is-photo-square .opening-animation__photo {
  clip-path: inset(0 round 0);
  transition:
    opacity 0.35s ease-out,
    clip-path 0s;
}

.opening-animation--bottle.is-photo-square .opening-animation__photo {
  border-radius: 0;
  clip-path: none;
  -webkit-mask-image: none;
  mask-image: none;
  transition:
    opacity 0.35s ease-out,
    border-radius 0s,
    -webkit-mask-size 0s,
    mask-size 0s;
}

.opening-animation.is-leaving {
  opacity: 0;
  pointer-events: none;
}

.opening-is-active .hero__badge,
.opening-is-active .hero__heading,
.opening-is-active .hero__place-text {
  opacity: 0;
  animation: none;
  transition: opacity 1.1s ease-out;
}

.opening-is-active .hero__place::before {
  opacity: 0.01;
  animation: none;
  transition: opacity 1.1s ease-out;
}

.opening-is-active.opening-hero-visible .hero__badge,
.opening-is-active.opening-hero-visible .hero__heading,
.opening-is-active.opening-hero-visible .hero__place-text,
.opening-is-active.opening-hero-visible .hero__place::before {
  opacity: 1;
}

.opening-is-complete .hero__badge,
.opening-is-complete .hero__heading,
.opening-is-complete .hero__place-text,
.opening-is-complete .hero__place::before {
  opacity: 1;
  animation: none;
}

@media (max-width: 640px) {
  .opening-animation__title {
    top: 300px;
    width: min(88vw, 380px);
  }

  .opening-animation__photo {
    bottom: auto;
    height: 600px;
  }

  .opening-animation__photo::after {
    background: rgb(0 0 0 / 25%);
  }

  .opening-animation__photo img {
    object-position: center top;
  }
}

@media (prefers-reduced-motion: reduce) {
  .opening-animation {
    display: none !important;
  }
}
