/* ==========================================================================
   PlanariaShop motion — ทำให้หน้าเว็บดูมีชีวิตชีวา (2026-11-24)
   - หน้าเว็บค่อยๆ fade เข้าเวลาเปิด/เปลี่ยนหน้า
   - การ์ด/รายการค่อยๆ ลอยขึ้นทีละใบ (assets/js/motion.js ใส่คลาส .pl-rv / .pl-in)
     ทั้งตอนเปิดหน้า (ส่วนบนสุด) และตอนเลื่อนลงมาเจอ — แทน AOS เดิมที่โผล่มาทั้งแถวพร้อมกัน
   - hover/แตะการ์ดมีลูกเล่น ปุ่มหลักมีแสงวิ่งผ่าน
   - ใช้ property `translate`/`scale` แยก ไม่ใช้ `transform` จึงไม่ทับ hover เดิม
   - ห้ามใช้ body::before / body::after — เป็นพื้นหลังธีม/เทศกาลของเว็บ
   - ผู้ใช้ที่ตั้ง "ลดการเคลื่อนไหว" จะไม่เห็นแอนิเมชันใดๆ
   ========================================================================== */

@keyframes pl-page-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pl-rise { from { opacity: 0; translate: 0 28px; scale: .97; } to { opacity: 1; translate: 0 0; scale: 1; } }
@keyframes pl-pop { from { opacity: 0; scale: .8; } 70% { opacity: 1; scale: 1.04; } to { opacity: 1; scale: 1; } }
@keyframes pl-shine { from { transform: translateX(-130%) skewX(-20deg); } to { transform: translateX(330%) skewX(-20deg); } }
@keyframes pl-shine-loop { 0%, 72% { transform: translateX(-130%) skewX(-20deg); } 100% { transform: translateX(330%) skewX(-20deg); } }
@keyframes pl-bob { 0%, 100% { translate: 0 0; } 50% { translate: 0 -4px; } }
@keyframes pl-press { 50% { scale: .96; } }
@keyframes pl-pan { from { background-position: 0% 50%; } to { background-position: 200% 50%; } }
@keyframes pl-scroll-progress { from { transform: scaleX(0); } to { transform: scaleX(1); } }

@media (prefers-reduced-motion: no-preference) {
    /* เปิดหน้า: fade ทั้งหน้า (backwards = ไม่ค้างค่า opacity หลังจบ จึงไม่กระทบ modal/blur) */
    body:not(.pl-admin) { animation: pl-page-in .42s ease-out backwards; }

    /* การ์ดที่ยังไม่ถึงจอ */
    html.pl-motion .pl-rv { opacity: 0; }
    html.pl-motion .pl-rv.pl-in {
        opacity: 1;
        animation: pl-rise .7s cubic-bezier(.2, .75, .25, 1) var(--pl-d, 0ms) backwards;
    }
    html.pl-motion .pl-rv.pl-pop.pl-in { animation-name: pl-pop; animation-duration: .6s; }

    /* ไอคอนหัวข้อ section ลอยขึ้นลงเบาๆ */
    .ui-section-head .ui-icon-tile, .hp-stat .ui-icon-tile { animation: pl-bob 4.5s ease-in-out infinite; }
    .ui-section:nth-of-type(2n) .ui-section-head .ui-icon-tile, .col-6:nth-child(2n) .hp-stat .ui-icon-tile { animation-delay: -1.5s; }
    .col-6:nth-child(3n) .hp-stat .ui-icon-tile { animation-delay: -3s; }

    /* ข้อความไล่สีในหัวเว็บ: สีไหลช้าๆ */
    .ui-gradient-text {
        background-image: linear-gradient(100deg, var(--ui-accent) 0%, color-mix(in srgb, var(--ui-accent) 45%, #ffffff) 25%, var(--ui-accent) 50%, color-mix(in srgb, var(--ui-accent) 45%, #ffffff) 75%, var(--ui-accent) 100%);
        background-size: 200% 100%;
        animation: pl-pan 6s linear infinite;
    }

    /* ปุ่มหลักบนหัวเว็บ: แสงวิ่งผ่านเองทุกไม่กี่วินาที (ดึงสายตา) */
    .hp-hero .ui-btn-accent, .hp-promo .ui-btn-accent { position: relative; overflow: hidden; isolation: isolate; }
    .hp-hero .ui-btn-accent::after, .hp-promo .ui-btn-accent::after {
        content: ''; position: absolute; top: 0; left: 0; width: 35%; height: 100%; z-index: -1; pointer-events: none;
        background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .45), transparent);
        animation: pl-shine-loop 4.2s ease-in-out infinite;
    }

    /* แตะบนมือถือ: การ์ด/ปุ่มยุบลงนิดนึง ให้รู้สึกตอบสนอง */
    .ui-card-hover:active, .hp-tile:active, .hp-app:active, .ui-btn:active, .ui-link-more:active,
    .product-item:active, .wxs-item:active { animation: pl-press .22s ease; }

    /* แถบบอกระยะเลื่อนหน้าด้านบน (div ที่ motion.js ใส่ให้) */
    @supports (animation-timeline: scroll()) {
        .pl-scroll-bar {
            content: ''; position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 1040; pointer-events: none;
            background: linear-gradient(90deg, transparent, var(--ui-accent, #ffa66b) 30%, #fff 70%, var(--ui-accent, #ffa66b));
            transform-origin: 0 50%; transform: scaleX(0);
            animation: pl-scroll-progress linear both; animation-timeline: scroll(root);
        }
    }
}

/* เส้นสีหลักไล่เฉดบนหัวการ์ด section */
.ui-section {
    background-image: linear-gradient(90deg, transparent, var(--ui-accent-line, rgba(255,166,107,.4)) 25%, var(--ui-accent, #ffa66b) 50%, var(--ui-accent-line, rgba(255,166,107,.4)) 75%, transparent);
    background-size: 100% 2px;
    background-repeat: no-repeat;
    background-position: top center;
}

@media (hover: hover) and (prefers-reduced-motion: no-preference) {
    .ui-card-hover { transition: transform .25s ease, border-color .25s ease, box-shadow .25s ease; }
    .ui-card-hover:hover {
        box-shadow: 0 18px 40px rgba(0, 0, 0, .42), 0 10px 32px -10px var(--ui-accent-glow, rgba(255,166,107,.35));
    }

    /* รูปในการ์ดหมวดหมู่ซูมเข้านิดๆ ตอนชี้ */
    .hp-tile img, .ui-product img { transition: scale .5s cubic-bezier(.2, .75, .25, 1); }
    .hp-tile:hover img, .ui-product:hover img { scale: 1.05; }

    /* ปุ่มหลัก: แสงวิ่งผ่านตอนชี้ */
    .ui-btn-accent { position: relative; overflow: hidden; isolation: isolate; }
    .ui-btn-accent::after {
        content: ''; position: absolute; top: 0; left: 0; width: 35%; height: 100%; z-index: -1; pointer-events: none;
        background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .45), transparent);
        transform: translateX(-130%) skewX(-20deg);
    }
    .ui-btn-accent:hover::after { animation: pl-shine .75s ease; }
}

/* หัวข้อหน้าแรกพิมพ์ทีละตัว (motion.js) */
@keyframes pl-caret { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
#home-hero-title.pl-typing .pl-tw { visibility: hidden; }
#home-hero-title.pl-typing .pl-tw.pl-tw-on { visibility: visible; }
#home-hero-title .pl-tw-cur { position: relative; }
#home-hero-title .pl-tw-cur::after {
    content: ''; position: absolute; right: -4px; top: .12em; bottom: .08em; width: 3px; border-radius: 2px;
    background: var(--ui-accent, #ffa66b); box-shadow: 0 0 10px var(--ui-accent-glow, rgba(255,166,107,.5)); visibility: visible;
}
#home-hero-title .pl-tw-end::after { animation: pl-caret .9s step-end infinite; }
.hp-hero .hp-apps { transition: translate .35s cubic-bezier(.2, .75, .25, 1); }

@media print {
    html.pl-motion .pl-rv { opacity: 1 !important; animation: none !important; }
}
