/* ===================================================
   ANIMATIONS & KEYFRAMES
   =================================================== */

/* Rung lắc khi nhập sai mã PIN */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-10px); }
  40%, 80% { transform: translateX(10px); }
}

.shake {
  animation: shake 0.5s ease-in-out;
}

/* Hiệu ứng nhịp đập / thở nhẹ cho chữ hướng dẫn */
@keyframes pulseHint {
  0%, 100% {
    transform: scale(1);
    opacity: 0.85;
  }
  50% {
    transform: scale(1.08);
    opacity: 1;
    text-shadow: 0 0 12px rgba(255, 105, 180, 0.6);
  }
}

.pulse-hint {
  animation: pulseHint 2s infinite ease-in-out;
}

/* Nút xoay đĩa nhạc */
@keyframes spinRecord {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.music-spinning {
  animation: spinRecord 6s linear infinite;
}

/* Mở nắp phong bì 3D */
@keyframes openTopFlap {
  0% {
    transform: rotateX(0deg);
    z-index: 5;
  }
  50% {
    transform: rotateX(-90deg);
    z-index: 5;
  }
  100% {
    transform: rotateX(-180deg);
    z-index: 1;
  }
}

/* Lá thư trượt từ bên trong phong bì lên */
@keyframes slideLetterUp {
  0% {
    transform: translateY(0) scale(0.9);
    opacity: 0.8;
  }
  50% {
    transform: translateY(-55%) scale(0.95);
    opacity: 1;
  }
  100% {
    transform: translateY(-30%) scale(1.05);
    opacity: 1;
  }
}

/* Chuyển cảnh mượt mà */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(1.04);
  }
}

.fade-in {
  animation: fadeIn 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.fade-out {
  animation: fadeOut 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Hiệu ứng rơi từ TRÊN XUỐNG DƯỚI của cả khung hình Polaroid & Trái tim */
@keyframes fallDownwards {
  0% {
    transform: translateY(-50px) translateX(0) rotate(var(--rot-start, -6deg)) scale(var(--scale, 1));
    opacity: 0;
  }
  12% {
    opacity: var(--max-opacity, 0.92);
  }
  85% {
    opacity: var(--max-opacity, 0.92);
  }
  100% {
    transform: translateY(115vh) translateX(var(--drift-x, 35px)) rotate(var(--rot-end, 12deg)) scale(var(--scale, 1));
    opacity: 0;
  }
}

/* Hiệu ứng trôi nổi ngược (dự phòng) */
@keyframes floatUpwards {
  0% {
    transform: translateY(110vh) translateX(0) rotate(var(--rot-start, -5deg)) scale(var(--scale, 1));
    opacity: 0;
  }
  10% {
    opacity: var(--max-opacity, 0.85);
  }
  85% {
    opacity: var(--max-opacity, 0.85);
  }
  100% {
    transform: translateY(-20vh) translateX(var(--drift-x, 40px)) rotate(var(--rot-end, 15deg)) scale(var(--scale, 1));
    opacity: 0;
  }
}

/* Hiệu ứng lật thẻ thư (Card Flip / Fly Out) */
@keyframes cardFlyNext {
  0% {
    transform: translateX(0) rotate(0deg) scale(1);
    opacity: 1;
  }
  100% {
    transform: translateX(-120%) rotate(-12deg) scale(0.9);
    opacity: 0;
  }
}

/* Hiệu ứng lật về thẻ trước: bay từ bên trái vào vị trí bức thư */
@keyframes cardFlyPrev {
  0% {
    transform: translateX(-120%) rotate(-10deg) scale(0.92);
    opacity: 0;
  }
  100% {
    transform: translateX(0) rotate(0deg) scale(1);
    opacity: 1;
  }
}

.card-fly-next {
  animation: cardFlyNext 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

.card-fly-prev {
  animation: cardFlyPrev 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

/* Nổ pháo hoa trái tim khi bấm Đồng ý */
@keyframes heartBurst {
  0% {
    transform: translate(0, 0) scale(0.5);
    opacity: 1;
  }
  100% {
    transform: translate(var(--tx), var(--ty)) scale(1.5);
    opacity: 0;
  }
}

.heart-particle {
  position: absolute;
  pointer-events: none;
  animation: heartBurst 1.2s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

/* Toast thông báo */
@keyframes toastIn {
  from {
    transform: translate(-50%, 20px) scale(0.9);
    opacity: 0;
  }
  to {
    transform: translate(-50%, 0) scale(1);
    opacity: 1;
  }
}

@keyframes toastOut {
  from {
    transform: translate(-50%, 0) scale(1);
    opacity: 1;
  }
  to {
    transform: translate(-50%, -15px) scale(0.9);
    opacity: 0;
  }
}

.toast-in {
  animation: toastIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.toast-out {
  animation: toastOut 0.35s ease-in forwards;
}

/* Khung thoại Mascot Chibi (pop in/out không dịch chuyển toạ độ cha) */
@keyframes bubblePopIn {
  0% {
    opacity: 0;
    transform: scale(0.85) translateY(8px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes bubblePopOut {
  0% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
  100% {
    opacity: 0;
    transform: scale(0.85) translateY(6px);
  }
}

.bubble-in {
  animation: bubblePopIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.bubble-out {
  animation: bubblePopOut 0.25s ease-in forwards;
}

/* Rung nhẹ thẻ bị khóa */
@keyframes lockWobble {
  0%, 100% { transform: scale(0.98) translateX(0); }
  25% { transform: scale(0.98) translateX(-6px); }
  75% { transform: scale(0.98) translateX(6px); }
}

.lock-wobble {
  animation: lockWobble 0.4s ease-in-out;
}

/* ===================================================
   CHIBI CHARACTER ANIMATIONS
   =================================================== */

/* Chớp mắt tự nhiên */
@keyframes chibiBlink {
  0%, 90%, 100% {
    transform: scaleY(1);
  }
  95% {
    transform: scaleY(0.1);
  }
}

.chibi-anim-blink {
  transform-origin: 60px 55px;
  animation: chibiBlink 3.8s infinite ease-in-out;
}

/* Đu đưa thở nhẹ (Idle Breath/Float) */
@keyframes chibiFloat {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

.chibi-anim-float {
  animation: chibiFloat 2.6s infinite ease-in-out;
}

.chibi-head-group {
  transform-origin: 60px 80px;
  animation: chibiFloat 3.2s infinite ease-in-out;
}

/* Vẫy tay chào */
@keyframes chibiWave {
  0%, 100% {
    transform: rotate(0deg);
  }
  50% {
    transform: rotate(-14deg);
  }
}

.chibi-anim-wave {
  transform-origin: 82px 90px;
  animation: chibiWave 1.2s infinite ease-in-out;
}

/* Vệt sáng lóa kính */
@keyframes chibiGlint {
  0%, 75%, 100% {
    opacity: 0.2;
    transform: scale(0.9);
  }
  85% {
    opacity: 1;
    transform: scale(1.15);
  }
}

.chibi-anim-glint {
  transform-origin: center;
  animation: chibiGlint 4s infinite ease-in-out;
}

/* Đập rộn ràng (trái tim/má hồng) */
@keyframes chibiPulse {
  0%, 100% {
    transform: scale(1);
    opacity: 0.85;
  }
  50% {
    transform: scale(1.12);
    opacity: 1;
  }
}

.chibi-anim-pulse {
  transform-origin: center;
  animation: chibiPulse 1.8s infinite ease-in-out;
}

/* Nhún nhảy vui nhộn */
@keyframes chibiBounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-4px);
  }
}

.chibi-anim-bounce {
  animation: chibiBounce 1.5s infinite ease-in-out;
}

/* Lấp lánh ngôi sao */
@keyframes chibiShine {
  0%, 100% {
    transform: scale(0.85) rotate(0deg);
    opacity: 0.6;
  }
  50% {
    transform: scale(1.2) rotate(15deg);
    opacity: 1;
  }
}

.chibi-anim-shine {
  display: inline-block;
  transform-origin: center;
  animation: chibiShine 2s infinite ease-in-out;
}
