/* =========================================================
   MOONCAKE 2026 — SPARKLE ORDER BUTTON  (v1.3)
   Hiệu ứng nút "Order Now" ở hero banner: glow vàng, tia sáng
   chạy quanh viền, particle bay, chớp nhẹ ở trạng thái mặc định.
   Dùng chung biến màu :root của trang (--mc-gold, --mc-yellow).
   Kích hoạt bằng order-sparkle.js.

   Kích thước nút chỉnh nhanh qua --tm-btn-size ở dưới.
========================================================= */

/* =========================================================
   WRAPPER
========================================================= */
.tm-sparkle-button-wrap {
    position: absolute;
    left: 50%;
    bottom: 40px;
    transform: translateX(-50%);
    z-index: 9999;

    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    /* Cho phép toàn bộ ánh sáng / particle tràn ra ngoài vùng button */
    overflow: visible !important;
    width: max-content;
    height: max-content;
    --active: 0;
}

/* =====================================================
   BUTTON CONTAINER
===================================================== */
.tm-sparkle-button-wrap .sparkle-button {
    position: relative;
    pointer-events: auto;
    overflow: visible !important;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* =====================================================
   MAIN BUTTON
===================================================== */
    .tm-sparkle-button-wrap button {
        --cut: 0.08em;
        --active: 0;
        /* Kích thước nút — tăng số này để nút to hơn/nhỏ hơn */
        --tm-btn-size: 38px;
        margin-bottom:42%;


        text-transform: uppercase;
        background-color: rgba(74, 12, 12, .55);
        background: rgba(74, 12, 12, .55);
        font-family: Futura, Arial, sans-serif;
        font-weight: 400;
        font-size: var(--tm-btn-size);
        letter-spacing: 4px;
        color: #ffe9a8;
        border: 1px solid var(--mc-gold, #f0da89);
        cursor: pointer;
        padding: 0.45em 1.7em;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.12em;
        white-space: nowrap;
        border-radius: 10px;
        position: relative;
        /* GOLD GLOW */
        box-shadow: 0 0 calc(var(--active) * 3em) calc(var(--active) * 1.8em) rgba(255, 211, 76, 0.55), 0 0.03em 0 0 rgba(255, 211, 76, 0.35) inset, 0 -0.03em 0 0 rgba(255, 211, 76, 0.18) inset;
        transition: box-shadow 0.25s, transform 0.25s, background 0.25s;
        transform: scale(calc(1 + (var(--active) * 0.05)));
        /* Không cắt glow */
        overflow: visible !important;
        /* Chớp nhẹ khi ở trạng thái mặc định */
        animation: tm-default-blink 1.2s ease-in-out infinite;
    }

/* =====================================================
   DEFAULT BLINK
===================================================== */
@keyframes tm-default-blink {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.785; }
}

/* =====================================================
   ACTIVE / CLICK
===================================================== */
.tm-sparkle-button-wrap button:active {
    transform: scale(0.96);
}

/* =====================================================
   SVG
===================================================== */
.tm-sparkle-button-wrap svg {
    overflow: visible !important;
}

/* =====================================================
   SPARKLE ICON
===================================================== */
.tm-sparkle-button-wrap .sparkle {
    display: none !important;
    position: relative;
    z-index: 3;
    overflow: visible !important;
    flex-shrink: 0;
}

.tm-sparkle-button-wrap .sparkle path {
    color: #FFD34C;
    transform-box: fill-box;
    transform-origin: center;
    fill: currentColor;
    stroke: currentColor;
    animation-delay: calc((0.25s * 1.5) + (var(--delay) * 1s));
    animation-duration: 0.6s;
    transition: color 0.25s;
    filter: drop-shadow(0 0 3px rgba(255, 211, 76, 0.85));
}

.tm-sparkle-button-wrap button:is(:hover, :focus-visible) path {
    animation-name: tm-bounce;
}

@keyframes tm-bounce {
    35%, 65% { scale: var(--scale); }
}

.tm-sparkle-button-wrap .sparkle path:nth-of-type(1) { --scale: 0.5; --delay: 0.1; }
.tm-sparkle-button-wrap .sparkle path:nth-of-type(2) { --scale: 1.5; --delay: 0.2; }
.tm-sparkle-button-wrap .sparkle path:nth-of-type(3) { --scale: 2.5; --delay: 0.35; }

/* =====================================================
   OUTER GOLD GLOW
===================================================== */
.tm-sparkle-button-wrap button::before {
    content: "";
    position: absolute;
    inset: -0.35em;
    z-index: -1;
    border: 0.12em solid rgba(255, 211, 76, 0.22);
    border-radius: 999px;
    opacity: var(--active, 0);
    transition: opacity 0.25s;
    pointer-events: none;
    filter: blur(5px);
    box-shadow:
        0 0 10px rgba(255, 211, 76, 0.28),
        0 0 22px rgba(255, 211, 76, 0.16),
        0 0 40px rgba(255, 211, 76, 0.08);
}

/* =====================================================
   ROTATING SPARK
===================================================== */
.tm-sparkle-button-wrap .spark {
    position: absolute;
    inset: -4px;
    border-radius: 14px;
    rotate: 0deg;
    overflow: visible !important;
    pointer-events: none;
    animation: tm-flip calc(1.8s * 2) infinite steps(2, end);
    -webkit-mask: linear-gradient(white, white);
    mask: linear-gradient(white, white);
}

.tm-sparkle-button-wrap .spark::before {
    content: "";
    position: absolute;
    width: 200%;
    aspect-ratio: 1;
    top: 0;
    left: 50%;
    z-index: -1;
    translate: -50% -15%;
    rotate: 0;
    transform: rotate(-90deg);
    opacity: calc(var(--active) + 0.25);
    background: conic-gradient(
        from 0deg,
        transparent 0 330deg,
        rgba(255, 211, 76, 0.9) 350deg,
        rgba(255, 211, 76, 0.05) 360deg
    );
    filter: blur(2px);
    transition: opacity 0.25s;
    animation: tm-rotate 1.8s linear infinite both;
    pointer-events: none;
}

.tm-sparkle-button-wrap .spark::after {
    content: "";
    position: absolute;
    inset: var(--cut);
    border-radius: 999px;
    pointer-events: none;
}

/* =====================================================
   BACKDROP
===================================================== */
.tm-sparkle-button-wrap .backdrop {
    position: absolute;
    inset: var(--cut);
    background: rgba(74, 12, 12, .55);
    border-radius: 10px;
    transition: background 0.25s;
    pointer-events: none;
    box-shadow: inset 0 0 8px rgba(255, 211, 76, 0.12);
}

@keyframes tm-rotate {
    to { transform: rotate(90deg); }
}

/* =====================================================
   TEXT
===================================================== */
.tm-sparkle-button-wrap .text {
    translate: 2% -6%;
    letter-spacing: 4px;
    color: #ffe9a8;
    font-family: Futura, Arial, sans-serif;
    font-weight: 400;
    font-style: italic;
    background: none;
    -webkit-background-clip: initial;
    background-clip: initial;
    transition: color 0.25s, text-shadow 0.25s;
    text-shadow:
        0 0 3px rgba(255, 211, 76, 0.45),
        0 0 7px rgba(255, 211, 76, 0.20);
}

/* =====================================================
   BUTTON ICON SIZE
===================================================== */
.tm-sparkle-button-wrap button svg {
    inline-size: 0.8em;
    translate: -15% -5%;
}

/* =====================================================
   PARTICLE PEN
===================================================== */
.tm-sparkle-button-wrap .particle-pen {
    position: absolute;
    width: 200%;
    aspect-ratio: 1;
    top: 50%;
    left: 50%;
    translate: -50% -50%;
    -webkit-mask: radial-gradient(white, transparent 65%);
    mask: radial-gradient(white, transparent 65%);
    z-index: -1;
    opacity: var(--active, 0);
    transition: opacity 0.25s;
    pointer-events: none;
    overflow: visible !important;
}

/* =====================================================
   PARTICLE
===================================================== */
.tm-sparkle-button-wrap .particle {
    fill: #FFD34C;
    width: calc(var(--size, 0.25) * 1rem);
    aspect-ratio: 1;
    position: absolute;
    top: calc(var(--y) * 1%);
    left: calc(var(--x) * 1%);
    opacity: var(--alpha, 1);
    animation: tm-float-out calc(var(--duration, 1) * 1s) calc(var(--delay) * -1s) infinite linear;
    transform-origin: var(--origin-x, 1000%) var(--origin-y, 1000%);
    z-index: -1;
    animation-play-state: var(--play-state, paused);
    filter: drop-shadow(0 0 3px rgba(255, 211, 76, 0.85));
}

.tm-sparkle-button-wrap .particle path {
    fill: #FFD34C;
    stroke: none;
}

.tm-sparkle-button-wrap .particle:nth-of-type(even) {
    animation-direction: reverse;
}

@keyframes tm-float-out {
    to { rotate: 360deg; }
}

/* =====================================================
   HOVER
===================================================== */
.tm-sparkle-button-wrap:hover {
    --active: 1;
}

.tm-sparkle-button-wrap:hover button {
    --active: 1;
    /* Tắt chớp khi hover để giữ hiệu ứng hover */
    animation: none;
    box-shadow:
        0 0 15px rgba(255, 211, 76, 0.55),
        0 0 30px rgba(255, 211, 76, 0.32),
        0 0 50px rgba(255, 211, 76, 0.16),
        0 0 0 1px rgba(255, 211, 76, 0.35);
}

.tm-sparkle-button-wrap:hover .particle-pen {
    --active: 1;
    --play-state: running;
}

/* =====================================================
   REDUCED MOTION
===================================================== */
@media (prefers-reduced-motion: reduce) {
    .tm-sparkle-button-wrap button,
    .tm-sparkle-button-wrap .spark,
    .tm-sparkle-button-wrap .spark::before,
    .tm-sparkle-button-wrap .particle {
        animation: none !important;
    }
}

/* =====================================================
   MOBILE / TABLET  (<= 1199px)
   Không có hover thật -> bật sẵn trạng thái HOVER làm mặc định.
===================================================== */
@media (max-width: 1199px) {
    .tm-sparkle-button-wrap {
        bottom: 25px;
        overflow: visible !important;
        --active: 1;
    }

    .tm-sparkle-button-wrap button {
        --active: 1;
        /* Tắt chớp mặc định */
        animation: none;
        /* Glow giống HOVER */
        box-shadow:
            0 0 15px rgba(255, 211, 76, 0.55),
            0 0 30px rgba(255, 211, 76, 0.32),
            0 0 50px rgba(255, 211, 76, 0.16),
            0 0 0 1px rgba(255, 211, 76, 0.35);
    }

    .tm-sparkle-button-wrap .particle-pen {
        --active: 1;
        --play-state: running;
    }

    /* Giữ hiệu ứng xoay ánh sáng */
    .tm-sparkle-button-wrap .spark::before {
        opacity: 1;
    }

    .tm-sparkle-button-wrap .sparkle-button {
        overflow: visible !important;
    }
}

/* =====================================================
   MOBILE  (<= 800px)  — thu nhỏ font cho vừa màn hình
===================================================== */
@media (max-width: 800px) {
    .tm-sparkle-button-wrap {
        bottom: 25px;
        overflow: visible !important;
    }

    .tm-sparkle-button-wrap button {
        --tm-btn-size: 21px;
        padding: 0.45em 1.2em;
    }

    .tm-sparkle-button-wrap .sparkle-button {
        overflow: visible !important;
    }
}
