/**
 * @file The way from one place to another (public/js/solo/passage.js): the dark, the way's door seen from the front,
 * opening with its sound while the camera moves toward it, then the place of arrival. On the solo's page, and on
 * the TV when the GM moves the whole crew (public/js/tv/effects.js). The cold room's door sticks in its frost.
 */

/* --- The way from place to place (passage.js): darkness, the way's door from the front, opening, the place --- */
#passage {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  overflow: hidden;
  background: #000;
  opacity: 0;
  transition: opacity 0.2s;
}
#passage.shown {
  display: block;
  opacity: 1;
}
#passage.arrived {
  opacity: 0;
  transition: opacity 0.45s;
}
#passage .door {
  position: absolute;
  left: 50%;
  top: 50%;
  /* The picture covers the screen, whatever its shape (3 : 2). */
  width: max(100vw, 150dvh);
  aspect-ratio: 3 / 2;
  transform: translate(-50%, -50%) scale(1);
  opacity: 0;
  transition:
    opacity 0.35s,
    transform 1.2s ease-out;
}
/* A slow step toward the closed door, then on through it as it opens (transitions: no jump between the two). */
#passage.door-shown .door {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1.05);
}
#passage.opening .door {
  transform: translate(-50%, -50%) scale(1.9);
  transition:
    opacity 0.35s,
    transform var(--open-ms, 2000ms) cubic-bezier(0.5, 0, 0.75, 1);
}
#passage .frame,
#passage .leaf {
  position: absolute;
  background-repeat: no-repeat;
}
#passage .frame {
  inset: 0;
  background-size: 100% 100%;
}
#passage .leaf {
  transition: transform var(--open-ms, 2000ms) cubic-bezier(0.55, 0, 0.35, 1);
}
#passage.opening .leaf.left {
  transform: translateX(-100%);
}
#passage.opening .leaf.right {
  transform: translateX(100%);
}
#passage .leaf.hatch {
  border-radius: 50%;
  transition:
    transform var(--open-ms, 2000ms) cubic-bezier(0.6, 0, 0.4, 1),
    filter var(--open-ms, 2000ms);
}
/* The hatch: its wheel turns it a little, then it swings away into the dark. */
#passage.opening .leaf.hatch {
  animation: passage-hatch var(--open-ms, 2000ms) forwards;
}
@keyframes passage-hatch {
  0% {
    transform: rotate(0);
    filter: brightness(1);
  }
  35% {
    transform: rotate(-28deg);
    filter: brightness(1);
  }
  100% {
    transform: perspective(900px) rotate(-28deg) rotateY(-75deg) translateX(-30%);
    filter: brightness(0.15);
  }
}
/* The cold room's door: frozen in its seal, it gives a little, sticks, then slides open. */
#passage.opening .door.stuck .leaf.left {
  animation: passage-stuck-left var(--open-ms, 2000ms) forwards;
}
#passage.opening .door.stuck .leaf.right {
  animation: passage-stuck-right var(--open-ms, 2000ms) forwards;
}
@keyframes passage-stuck-left {
  0% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-9%);
  }
  40% {
    transform: translateX(-7%);
  }
  55% {
    transform: translateX(-12%);
  }
  100% {
    transform: translateX(-100%);
  }
}
@keyframes passage-stuck-right {
  0% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(9%);
  }
  40% {
    transform: translateX(7%);
  }
  55% {
    transform: translateX(12%);
  }
  100% {
    transform: translateX(100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  #passage .door,
  #passage .leaf {
    animation: none !important;
    transition: none !important;
  }
}
/* The mess's forced door (passage.js `through`): no leaf moves; the camera squeezes on into its gap, into the dark. */
#passage.opening .door.through {
  transform: translate(-50%, -50%) scale(3.4);
  filter: brightness(0.15);
  transition:
    opacity 0.35s,
    filter var(--open-ms, 2000ms) ease-in,
    transform var(--open-ms, 2000ms) cubic-bezier(0.45, 0, 0.8, 1);
}
