/* BFT Motion Library
 * Dependency-free CSS animations for modal, page, and typing effects.
 * Reference: inspired by common motion patterns; no Animate.css source is bundled.
 */

.u-anim,
.u-anim-zoom-in-down,
.u-anim-zoom-out-right,
.u-anim-flip-out-y,
.u-anim-fade-in-up,
.u-anim-slide-in-right,
.u-anim-pop-in,
.u-anim-fade-out-down,
.u-anim-slide-out-left,
.u-anim-soft-pulse {
  --anim-duration: 620ms;
  --anim-delay: 0ms;
  --anim-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  animation-duration: var(--anim-duration);
  animation-delay: var(--anim-delay);
  animation-timing-function: var(--anim-ease);
  animation-fill-mode: both;
  transform-origin: center center;
  will-change: transform, opacity;
}

/* A single u-anim-* class is enough. Add u-anim only when you want to
 * override the timing variables through a class-based theme token. */

.u-anim--fast {
  --anim-duration: 360ms;
}

.u-anim--slow {
  --anim-duration: 900ms;
}

/* Modal opening: dramatic but readable */
.u-anim-zoom-in-down {
  animation-name: bft-zoom-in-down;
}

/* Modal closing: exits to the right */
.u-anim-zoom-out-right {
  animation-name: bft-zoom-out-right;
}

/* Modal closing: card-like flip */
.u-anim-flip-out-y {
  animation-name: bft-flip-out-y;
}

/* General entrances */
.u-anim-fade-in-up {
  animation-name: bft-fade-in-up;
}

.u-anim-slide-in-right {
  animation-name: bft-slide-in-right;
}

.u-anim-pop-in {
  animation-name: bft-pop-in;
}

/* General exits */
.u-anim-fade-out-down {
  animation-name: bft-fade-out-down;
}

.u-anim-slide-out-left {
  animation-name: bft-slide-out-left;
}

/* Attention / feedback */
.u-anim-soft-pulse {
  animation-name: bft-soft-pulse;
}

@keyframes bft-zoom-in-down {
  from {
    opacity: 0;
    transform: translate3d(0, -38vh, 0) scale3d(0.22, 0.22, 0.22);
    animation-timing-function: cubic-bezier(0.55, 0.055, 0.675, 0.19);
  }
  58% {
    opacity: 1;
    transform: translate3d(0, 12px, 0) scale3d(0.9, 0.9, 0.9);
    animation-timing-function: cubic-bezier(0.175, 0.885, 0.32, 1);
  }
  78% {
    transform: translate3d(0, -4px, 0) scale3d(1.025, 1.025, 1.025);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale3d(1, 1, 1);
  }
}

@keyframes bft-zoom-out-right {
  0% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale3d(1, 1, 1);
    animation-timing-function: cubic-bezier(0.55, 0.055, 0.675, 0.19);
  }
  38% {
    opacity: 1;
    transform: translate3d(-14px, 0, 0) scale3d(0.94, 0.94, 0.94);
    animation-timing-function: cubic-bezier(0.175, 0.885, 0.32, 1);
  }
  to {
    opacity: 0;
    transform: translate3d(58vw, 0, 0) scale3d(0.18, 0.18, 0.18);
  }
}

@keyframes bft-flip-out-y {
  from {
    opacity: 1;
    transform: perspective(900px) rotateY(0deg) scale(1);
  }
  42% {
    opacity: 1;
    transform: perspective(900px) rotateY(80deg) scale(0.96);
  }
  to {
    opacity: 0;
    transform: perspective(900px) rotateY(360deg) scale(0.72);
  }
}

@keyframes bft-fade-in-up {
  from {
    opacity: 0;
    transform: translate3d(0, 22px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

@keyframes bft-fade-out-down {
  from {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
  to {
    opacity: 0;
    transform: translate3d(0, 24px, 0);
  }
}

@keyframes bft-slide-in-right {
  from {
    opacity: 0;
    transform: translate3d(52px, 0, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

@keyframes bft-slide-out-left {
  from {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
  to {
    opacity: 0;
    transform: translate3d(-52px, 0, 0);
  }
}

@keyframes bft-pop-in {
  0% {
    opacity: 0;
    transform: scale3d(0.72, 0.72, 0.72);
  }
  68% {
    opacity: 1;
    transform: scale3d(1.035, 1.035, 1.035);
  }
  100% {
    opacity: 1;
    transform: scale3d(1, 1, 1);
  }
}

@keyframes bft-soft-pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.035);
  }
}

/* Typing animation */
.typewriter {
  min-height: 1.55em;
}

.typewriter__text {
  white-space: pre-wrap;
}

.typewriter__caret {
  display: inline-block;
  width: 0.08em;
  min-width: 2px;
  height: 1.12em;
  margin-left: 0.12em;
  border-radius: 2px;
  background: currentColor;
  vertical-align: -0.12em;
  animation: bft-caret-blink 0.85s steps(1, end) infinite;
}

@keyframes bft-caret-blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

/* Reusable modal shell */
.anim-modal-shell {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 24px;
}

.anim-modal-shell[hidden] {
  display: none;
}

.anim-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 10, 20, 0.72);
  backdrop-filter: blur(7px);
  animation: bft-backdrop-in 220ms ease both;
}

.anim-modal-panel {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
}

.anim-modal-panel:focus {
  outline: none;
}

.anim-modal-panel:focus-visible {
  outline: 3px solid rgba(127, 156, 255, 0.5);
  outline-offset: 4px;
}

@keyframes bft-backdrop-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

html.anim-scroll-lock {
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .u-anim,
  .anim-modal-backdrop {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
  }

  .typewriter__caret {
    animation: none;
  }
}
