/* ================================================
   modal-animation.css — Package Modal Animation
   ใช้คู่กับ modal-animation.js
   สถานะ:
     #PackageModal.ma-open    → เล่นอนิเมชั่นเปิด
     #PackageModal.ma-closing → เล่นอนิเมชั่นปิด
================================================ */

#PackageModal {
    --ma-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ma-ease-back: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── FIX: scrollbar โผล่ตอนเปิด ──
   ระหว่างอนิเมชั่น ชิ้นที่ถูก scale / translate จะล้นออกนอกจอชั่วคราว
   ทำให้ .modal (overflow-y: auto ของ Bootstrap) แสดง scrollbar
   → ซ่อน overflow เฉพาะช่วงที่อนิเมชั่นกำลังเล่น (JS ใส่/ถอดคลาสให้)
   หลังเล่นจบ จอเล็กยังเลื่อนดูเนื้อหาได้ตามปกติ */
#PackageModal.ma-animating {
    overflow: hidden;
}

/* ── สถานะเริ่มต้น: ซ่อนทุกชิ้นก่อนเปิด ── */
#PackageModal .modal-content,
#PackageModal .packageModalClose,
#PackageModal .packageModalTitle,
#PackageModal .packageModalNote,
#PackageModal .packageFrameContentMainLayout,
#PackageModal .packageItem,
#PackageModal .packageNpcLayout,
#PackageModal .packageCoin_1,
#PackageModal .packageCoin_2 {
    opacity: 0;
}

/* ─────────────────────
   OPEN SEQUENCE (timeline)
   0.00s พื้นหลัง modal
   0.15s กรอบทอง กางออก
   0.35s หัวข้อ ตกลงมา
   0.50s หมายเหตุ
   0.60s / 0.75s การ์ด Package
   0.70s กองเหรียญ / 0.80s NPC / 0.95s เหรียญเล็ก
   0.90s ปุ่มปิด
───────────────────── */

#PackageModal.ma-open .modal-content {
    animation: maBgIn 0.55s var(--ma-ease-out) both;
}

#PackageModal.ma-open .packageFrameContentMainLayout {
    animation: maFrameIn 0.65s var(--ma-ease-out) 0.15s both;
}

#PackageModal.ma-open .packageModalTitle {
    animation: maTitleDrop 0.75s var(--ma-ease-back) 0.35s both;
}

#PackageModal.ma-open .packageModalNote {
    animation: maRise 0.5s var(--ma-ease-out) 0.5s both;
}

#PackageModal.ma-open .packageItem {
    animation:
        maCardPop 0.8s var(--ma-ease-out) var(--ma-delay, 0.6s) both,
        maFlash 0.6s ease-out calc(var(--ma-delay, 0.6s) + 0.45s);
}

#PackageModal.ma-open .packageItem:nth-child(2) {
    --ma-delay: 0.75s;
}

#PackageModal.ma-open .packageCoin_1 {
    animation: maPileRise 0.7s var(--ma-ease-back) 0.7s both;
}

#PackageModal.ma-open .packageNpcLayout {
    animation:
        maSlideFromRight 0.8s var(--ma-ease-back) 0.8s both,
        maFloat 3.2s ease-in-out 1.6s infinite;
}

#PackageModal.ma-open .packageCoin_2 {
    animation:
        maCoinDrop 0.9s var(--ma-ease-out) 0.95s both,
        maCoinBob 2.6s ease-in-out 1.85s infinite;
}

#PackageModal.ma-open .packageModalClose {
    animation: maSpinIn 0.55s var(--ma-ease-back) 0.9s both;
}

/* ─────────────────────
   CLOSE
───────────────────── */
#PackageModal.ma-closing .modal-content {
    animation: maBgOut 0.38s cubic-bezier(0.4, 0, 1, 1) forwards;
}

/* ─────────────────────
   FIX: detail โดนเส้นกรอบ/เหรียญทับ
   อนิเมชั่น opacity/transform ทำให้ .packageItem กลายเป็น stacking context
   z-index: 3 ของ detail เลยถูกขังอยู่ข้างใน → ยก .packageItem ที่เปิด detail
   ขึ้นทั้งก้อนแทน (หน่วงตอนปิด 0.35s ให้ detail จางหายจบก่อนค่อยลดชั้น)
───────────────────── */
#PackageModal .packageItem {
    z-index: 0;
    transition: z-index 0s linear 0.35s;
}

#PackageModal .packageItem:has(.packageDetailMainLayout.is-open) {
    z-index: 10;
    transition-delay: 0s;
}

/* ─────────────────────
   DETAIL (เมื่อกดการ์ด) : ไอเทมเด้งทีละชิ้น
───────────────────── */
.packageDetailMainLayout.is-open>* {
    animation: maItemPop 0.45s var(--ma-ease-back) both;
    animation-delay: calc(var(--i, 0) * 60ms + 80ms);
}

/* ─────────────────────
   SPARKLES (สร้างจาก JS)
───────────────────── */
.ma-sparkles {
    position: absolute;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.ma-sparkles i {
    position: absolute;
    left: var(--x);
    top: var(--y);
    width: var(--s);
    height: var(--s);
    border-radius: 50%;
    background: radial-gradient(circle,
            #fffbe3 0%,
            #f2d97c 35%,
            rgba(242, 217, 124, 0) 70%);
    opacity: 0;
}

#PackageModal.ma-open .ma-sparkles i {
    animation: maTwinkle var(--dur) ease-in-out var(--d) infinite;
}

/* ─────────────────────
   KEYFRAMES
───────────────────── */
@keyframes maBgIn {
    from {
        opacity: 0;
        transform: scale(1.06);
        filter: brightness(1.6) blur(8px);
    }

    to {
        opacity: 1;
        transform: none;
        filter: none;
    }
}

@keyframes maBgOut {
    from {
        opacity: 1;
        transform: none;
        filter: none;
    }

    to {
        opacity: 0;
        transform: scale(0.96);
        filter: brightness(1.4) blur(6px);
    }
}

/* กรอบกางออกจากเส้นแนวนอน → เต็มกรอบ */
@keyframes maFrameIn {
    0% {
        opacity: 0;
        transform: scaleX(0.3) scaleY(0.02);
    }

    45% {
        opacity: 1;
        transform: scaleX(1) scaleY(0.02);
    }

    100% {
        opacity: 1;
        transform: none;
    }
}

@keyframes maTitleDrop {
    0% {
        opacity: 0;
        transform: translateY(-70px) scale(1.25);
    }

    60% {
        opacity: 1;
    }

    100% {
        opacity: 1;
        transform: none;
    }
}

@keyframes maRise {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes maCardPop {
    0% {
        opacity: 0;
        transform: perspective(900px) translateY(70px) rotateX(55deg) scale(0.7);
    }

    65% {
        opacity: 1;
        transform: perspective(900px) translateY(-12px) rotateX(-6deg) scale(1.04);
    }

    100% {
        opacity: 1;
        transform: none;
    }
}

/* แฟลชทองครั้งเดียวหลังการ์ดลงจอด */
@keyframes maFlash {
    0% {
        filter: brightness(1) drop-shadow(0 0 0 rgba(255, 215, 90, 0));
    }

    40% {
        filter: brightness(1.35) drop-shadow(0 0 22px rgba(255, 215, 90, 0.9));
    }

    100% {
        filter: brightness(1) drop-shadow(0 0 0 rgba(255, 215, 90, 0));
    }
}

@keyframes maPileRise {
    from {
        opacity: 0;
        transform: translateY(80px) scale(0.8);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes maSlideFromRight {
    from {
        opacity: 0;
        transform: translateX(140px) rotate(6deg);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes maFloat {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

@keyframes maCoinDrop {
    0% {
        opacity: 0;
        transform: translateY(-160px) rotate(-200deg);
    }

    60% {
        opacity: 1;
        transform: translateY(10px) rotate(10deg);
    }

    80% {
        transform: translateY(-6px) rotate(-4deg);
    }

    100% {
        opacity: 1;
        transform: none;
    }
}

@keyframes maCoinBob {

    0%,
    100% {
        transform: translateY(0) rotate(0deg);
    }

    50% {
        transform: translateY(-8px) rotate(8deg);
    }
}

@keyframes maSpinIn {
    from {
        opacity: 0;
        transform: scale(0) rotate(-180deg);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes maItemPop {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.6);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes maTwinkle {

    0%,
    100% {
        opacity: 0;
        transform: translateY(0) scale(0.4);
    }

    50% {
        opacity: 0.9;
        transform: translateY(-24px) scale(1);
    }
}