/**
 * Intro "Đổi màu" (template-parts/intro-mascot.php). Timeline vào cảnh chạy bằng CSS khi có .is-playing;
 * intro-mascot.js thêm .is-leaving ở 3s (vòng tròn mở, Kè X bay về nút mascot) và lo nút bỏ qua.
 * Không có JS: tự tắt ở 4,3s.
 *
 *   0–0,75s    logo X lắp ráp (3 mảnh bay vào, nảy khi khớp)
 *   0,75–1,3s  X lùi thành phông, Kè X bật ra (co giãn), đang ngụy trang cùng màu xanh sân khấu
 *   1,35–1,9s  sóng xanh chanh quét qua người → màu thật + vòng sáng; chip "mình là Kè X" hiện ở 1,55s
 *   1,9–2,5s   "Soi. Đoán. Thử. Nhân." dập vào từng chữ; dòng giải nghĩa hiện ở 2,2s, đứng yên tới 3s
 *   3–3,65s    trang lộ ra qua vòng tròn mở rộng từ giữa, Kè X thu nhỏ bay về nút mascot góc phải dưới
 */
@property --sm-reveal {
    syntax: '<percentage>';
    inherits: false;
    initial-value: 0%;
}
@property --sm-hole {
    syntax: '<length>';
    inherits: false;
    initial-value: 0px;
}

.sm-intro { display: none; }
.sm-intro.is-playing {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    animation: sm-intro-autoclose 0.4s ease 4.1s forwards;
}
html.sm-intro-lock, html.sm-intro-lock body { overflow: hidden !important; }

/* Sân khấu xanh thương hiệu (cùng ngôn ngữ với ảnh bìa thẻ game) */
.sm-intro-bg {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 50% 42%, rgba(190, 255, 1, 0.16) 0, rgba(190, 255, 1, 0) 32%),
        radial-gradient(rgba(255, 255, 255, 0.12) 1.2px, transparent 1.4px) 0 0 / 22px 22px,
        linear-gradient(135deg, #00287a 0%, #0047c9 45%, #005eff 75%, #3d8cff 100%);
}

.sm-intro-stage {
    --size: min(46vh, 400px, 78vw);
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.sm-intro-hero {
    position: relative;
    width: var(--size);
    height: var(--size);
}

/* 1. Logo X lắp ráp */
.sm-intro-x {
    position: absolute;
    left: 50%;
    top: 50%;
    width: calc(var(--size) * 0.62);
    height: auto;
    aspect-ratio: 418 / 482;
    transform: translate(-50%, -50%);
    overflow: visible;
    filter: drop-shadow(0 12px 30px rgba(0, 20, 80, 0.35));
    animation: sm-intro-x-back 0.5s cubic-bezier(.4, 0, .2, 1) 0.75s forwards;
}
.sm-intro-x polygon {
    fill: url(#sm-intro-x-fill);
    stroke: url(#sm-intro-x-fill);
    stroke-width: 10;
    stroke-linejoin: round;
    transform-box: fill-box;
    opacity: 0;
    animation: sm-intro-piece 0.55s cubic-bezier(.25, 1.45, .45, 1) forwards;
}
.sm-intro-x .sm-x-a { --from: translateX(-70%); }
.sm-intro-x .sm-x-b { --from: translate(80%, -80%) rotate(12deg); animation-delay: 0.1s; }
.sm-intro-x .sm-x-c { --from: translate(80%, 80%) rotate(-12deg); animation-delay: 0.18s; }

/* Lớp bọc để bay về nút mascot khi thoát (JS đặt --fx/--fy/--fs theo vị trí nút); tách khỏi animation của mascot */
.sm-intro-fly { position: absolute; inset: 0; }

/* 2. Mascot bật ra, ngụy trang cùng màu sân khấu */
.sm-intro-mascot {
    position: absolute;
    inset: 0;
    opacity: 0;
    transform-origin: 50% 95%;
    animation: sm-intro-pop 0.55s cubic-bezier(.3, 0, .3, 1) 0.75s forwards,
               sm-intro-bounce 0.35s cubic-bezier(.3, 1.6, .5, 1) 1.88s;
}
.sm-intro-mascot img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    clip-path: inset(0 0 2.5% 0); /* ảnh gốc có 1 hàng pixel mờ ở mép dưới */
}
.sm-intro-camo { filter: grayscale(1) sepia(1) hue-rotate(178deg) saturate(3.2) brightness(0.95) contrast(1.05); }

/* 3. Sóng đổi màu: lớp màu thật lộ dần theo đường chéo, viền sóng xanh chanh chạy theo dáng mascot */
.sm-intro-color {
    -webkit-mask-image: linear-gradient(115deg, #000 calc(var(--sm-reveal) - 12%), transparent var(--sm-reveal));
    mask-image: linear-gradient(115deg, #000 calc(var(--sm-reveal) - 12%), transparent var(--sm-reveal));
    animation: sm-intro-reveal 0.55s cubic-bezier(.5, 0, .4, 1) 1.35s forwards;
}
.sm-intro-wave {
    position: absolute;
    inset: 0;
    background: linear-gradient(115deg, transparent 42%, rgba(220, 255, 120, 0.95) 49%, #beff01 50%, transparent 58%) 120% 0 / 300% 100% no-repeat;
    -webkit-mask: var(--mascot) center / 100% 100% no-repeat;
    mask: var(--mascot) center / 100% 100% no-repeat;
    opacity: 0;
    animation: sm-intro-wave 0.55s cubic-bezier(.5, 0, .4, 1) 1.35s;
}
.sm-intro-burst {
    position: absolute;
    left: 50%;
    top: 46%;
    width: 70%;
    aspect-ratio: 1;
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0.3);
    background: radial-gradient(circle, rgba(190, 255, 1, 0) 40%, rgba(190, 255, 1, 0.55) 62%, rgba(190, 255, 1, 0) 72%);
    opacity: 0;
    animation: sm-intro-burst 0.6s cubic-bezier(.2, .8, .3, 1) 1.6s;
}

/* 4. Bốn bước DMAIC Lite, font như wordmark logo */
.sm-intro-words {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0 0.45em;
    margin: 12px 16px 0;
    font-family: var(--font-display);
    font-size: clamp(30px, 3.4vw + 10px, 64px);
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -0.02em;
}
/* Theme ép color + -webkit-text-fill-color cho chữ trong nội dung: đặt lại cho intro */
.sm-intro-words,
.sm-intro-words span { color: #ffffff !important; -webkit-text-fill-color: #ffffff !important; }
.sm-intro-words span {
    opacity: 0;
    transform: scale(1.7);
    filter: blur(6px);
    animation: sm-intro-slam 0.3s cubic-bezier(.2, .9, .3, 1.2) forwards;
    animation-delay: calc(1.9s + var(--i) * 0.1s);
}
.sm-intro-words b { color: #beff01 !important; -webkit-text-fill-color: #beff01 !important; }

/* Chip tên nhân vật: hiện đúng lúc Kè X bừng màu */
.sm-intro-chip {
    position: absolute;
    left: 66%;
    top: 6%;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 16px 16px 16px 4px;
    background: #ffffff;
    box-shadow: 0 12px 30px -10px rgba(0, 20, 80, 0.55);
    font-family: var(--font-display);
    font-size: clamp(13px, 0.6vw + 9px, 16px);
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    color: #0b1a3a !important;
    -webkit-text-fill-color: #0b1a3a !important;
    opacity: 0;
    transform: translateY(10px) scale(0.8);
    transform-origin: 0% 100%;
    animation: sm-intro-chip 0.4s cubic-bezier(.3, 1.5, .5, 1) 1.55s forwards;
}
.sm-intro-chip-wave { display: inline-block; transform-origin: 70% 80%; animation: sm-intro-hand 0.9s ease-in-out 1.85s 1; }
/* Màn hẹp: chip đặt trên đầu mascot cho khỏi tràn mép phải */
@media (max-width: 640px) {
    .sm-intro-chip { left: 50%; top: -4%; transform: translate(-50%, 10px) scale(0.8); transform-origin: 50% 100%; animation-name: sm-intro-chip-center; border-radius: 16px; }
}

/* Dòng giải nghĩa 4 bước */
.sm-intro-tagline {
    max-width: min(560px, 86vw);
    margin: 10px 16px 0;
    text-align: center;
    font-size: clamp(14px, 0.5vw + 11px, 18px);
    font-weight: 500;
    line-height: 1.45;
    color: rgba(255, 255, 255, 0.88) !important;
    -webkit-text-fill-color: rgba(255, 255, 255, 0.88) !important;
    opacity: 0;
    transform: translateY(8px);
    animation: sm-intro-rise 0.4s ease-out 2.2s forwards;
}

.sm-intro-skip {
    position: absolute;
    right: 24px;
    bottom: 24px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border: 1px solid rgba(255, 255, 255, 0.45);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.85);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.sm-intro-skip:hover { color: #fff; border-color: #fff; }

/* 5. Thoát: lỗ hình chữ X ở giữa phóng to, trang lộ ra bên trong (không chớp sáng cả màn hình) */
.sm-intro.is-leaving { pointer-events: none; }
/* Phần tử không có animation: chuyển tiếp thường. Phần tử đang giữ animation (forwards): thay bằng animation rút ra có điểm đầu rõ ràng */
.sm-intro.is-leaving .sm-intro-words,
.sm-intro.is-leaving .sm-intro-skip {
    transition: opacity 0.22s ease, transform 0.45s cubic-bezier(.6, 0, .3, 1);
    opacity: 0;
    transform: scale(1.08);
}
.sm-intro.is-leaving .sm-intro-tagline,
.sm-intro.is-leaving .sm-intro-chip { animation: sm-intro-out 0.22s ease forwards; }
.sm-intro.is-leaving .sm-intro-x { animation: sm-intro-x-out 0.3s ease forwards; }
/* Vòng tròn mở rộng từ giữa sân khấu: trang lộ ra gọn, không còn vạch chéo của lỗ hình chữ X */
.sm-intro.is-leaving .sm-intro-bg {
    -webkit-mask: radial-gradient(circle at 50% 46%, transparent var(--sm-hole), #000 calc(var(--sm-hole) + 1px));
    mask: radial-gradient(circle at 50% 46%, transparent var(--sm-hole), #000 calc(var(--sm-hole) + 1px));
    animation: sm-intro-hole 0.62s cubic-bezier(.6, 0, .3, 1) forwards, sm-intro-fade-out 0.18s ease 0.5s forwards;
}
/* Kè X thu nhỏ, bay về nút mascot; mờ dần ở chặng cuối để nút "nhận" lấy */
.sm-intro.is-leaving .sm-intro-fly {
    transition: transform 0.62s cubic-bezier(.55, 0, .25, 1), opacity 0.16s ease 0.48s;
    transform: translate(var(--fx, 0px), var(--fy, 40vh)) scale(var(--fs, 0.2));
    opacity: 0;
}
.sm-intro.is-skipped { transition: opacity 0.3s ease; opacity: 0; }

@keyframes sm-intro-piece {
    from { opacity: 0; transform: var(--from); }
    40% { opacity: 1; }
    to { opacity: 1; transform: none; }
}
@keyframes sm-intro-x-back { to { transform: translate(-50%, -50%) scale(2.4); opacity: 0.08; filter: none; } }
@keyframes sm-intro-pop {
    0% { opacity: 0; transform: translateY(30%) scale(0.5, 0.35); }
    45% { opacity: 1; transform: translateY(-7%) scale(0.92, 1.1); }
    72% { transform: translateY(0) scale(1.06, 0.94); }
    100% { opacity: 1; transform: none; }
}
@keyframes sm-intro-bounce { 50% { transform: translateY(-3%) scale(1.03); } }
@keyframes sm-intro-reveal { to { --sm-reveal: 125%; } }
@keyframes sm-intro-wave {
    0% { opacity: 1; background-position: 120% 0; }
    85% { opacity: 1; }
    100% { opacity: 0; background-position: -20% 0; }
}
@keyframes sm-intro-burst {
    0% { opacity: 1; transform: translate(-50%, -50%) scale(0.3); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.7); }
}
@keyframes sm-intro-slam { to { opacity: 1; transform: none; filter: none; } }
@keyframes sm-intro-hole {
    0% { --sm-hole: 0px; }
    100% { --sm-hole: 120vmax; }
}
@keyframes sm-intro-chip { to { opacity: 1; transform: none; } }
@keyframes sm-intro-chip-center { to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes sm-intro-rise { to { opacity: 1; transform: none; } }
@keyframes sm-intro-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes sm-intro-x-out {
    from { opacity: 0.08; transform: translate(-50%, -50%) scale(2.4); }
    to { opacity: 0; transform: translate(-50%, -50%) scale(2.7); }
}
@keyframes sm-intro-hand { 0%, 100% { transform: rotate(0); } 20%, 60% { transform: rotate(18deg); } 40%, 80% { transform: rotate(-10deg); } }
@keyframes sm-intro-fade-out { to { opacity: 0; } }
@keyframes sm-intro-autoclose { to { opacity: 0; visibility: hidden; } }
