/**
 * Floating Header — style.css v1.0.5
 *
 * Changelog 1.0.5:
 *   - Fix: .fh-logo เพิ่ม transform: translate(-50%, -50%) เป็น base style
 *     แก้ปัญหาโลโก้ shift/กระตุกตอนโหลดหน้าครั้งแรก
 *     (เดิม transform มีอยู่แค่ใน @keyframes ทำให้ระหว่าง animation-delay
 *      โลโก้ไม่มี transform เลย พอ animation เริ่มทำงานจะ "เด้ง" ไปตำแหน่งที่ถูกต้อง)
 *   - เพิ่ม @keyframes fh-fade-in + รวมเข้ากับ .fh-float-up/.fh-float-down
 *     ทำให้โลโก้ fade in ทีละตัวตอนโหลดหน้า (ลำดับสุ่มจาก --fh-fade-delay
 *     ที่ PHP shuffle มาให้ในแต่ละ request)
 */

:root {
    --fh-float-y: 20px;
}

.fh-wrapper {
    position: relative;
    min-height: 400px;
    overflow: visible;
    width: 100%;
}

.fh-logo-layer {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
}

/**
 * --fh-x / --fh-y มาจาก PHP (shortcode.php)
 * translate(-50%,-50%) รวมอยู่ใน keyframes เพื่อไม่ให้ animation override centering
 */
.fh-logo {
    position: absolute;
    left: var(--fh-x, 50%);
    top: var(--fh-y, 50%);
    transform: translate(-50%, -50%);
    /* หมายเหตุ: ไม่ตั้ง opacity ที่นี่ (default = 1)
       ความ "invisible ก่อน fade-in" ควบคุมผ่าน @keyframes fh-fade-in
       + animation-fill-mode: both เท่านั้น — ถ้า animation ถูกปิด
       (เช่น prefers-reduced-motion) โลโก้จะ fallback กลับมาเห็นได้ทันที
       ไม่ค้างที่ opacity: 0 */
}

.fh-logo img {
    display: block;
    width: auto;
    height: auto;
    max-width: 120px;
    max-height: 80px;
    object-fit: contain;
}

@keyframes fh-float-up {
    0%,
    100% {
        transform: translate(-50%, -50%) translateY(0);
    }
    50% {
        transform: translate(-50%, -50%) translateY(calc(-1 * var(--fh-float-y)));
    }
}

@keyframes fh-float-down {
    0%,
    100% {
        transform: translate(-50%, -50%) translateY(0);
    }
    50% {
        transform: translate(-50%, -50%) translateY(var(--fh-float-y));
    }
}

/**
 * fh-fade-in — เล่นครั้งเดียวตอนโหลดหน้า (ไม่ infinite)
 * คุมแค่ opacity เท่านั้น ไม่ชนกับ transform ของ float animation
 * --fh-fade-delay: ค่าที่ PHP สุ่ม (shuffle) แจกให้แต่ละโลโก้ต่างกัน
 *                  ทำให้ลำดับการ fade in ของแต่ละตัวสลับกันทุกครั้งที่โหลดหน้า
 */
@keyframes fh-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.fh-float-up {
    animation:
        fh-fade-in 0.6s ease-out var(--fh-fade-delay, 0s) both,
        fh-float-up var(--fh-duration, 3s) ease-in-out var(--fh-delay, 0s) infinite;
}

.fh-float-down {
    animation:
        fh-fade-in 0.6s ease-out var(--fh-fade-delay, 0s) both,
        fh-float-down var(--fh-duration, 3s) ease-in-out var(--fh-delay, 0s) infinite;
}

@media (prefers-reduced-motion: reduce) {
    .fh-float-up,
    .fh-float-down {
        animation: none;               /* ปิดทั้ง float และ fade-in */
        transform: translate(-50%, -50%);
        opacity: 1;                    /* แสดงผลทันที ไม่มี stagger/fade */
    }
}

.fh-title-layer {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 10;
    width: 80%;
    pointer-events: none;
}

.fh-title {
    margin: 0 0 0.4em;
    line-height: 1.2;
}

.fh-subtitle {
    line-height: 1.6;
}

.fh-tier-3 .fh-logo:nth-child(even) {
    opacity: 0.75;
}

.fh-tier-4 .fh-logo:nth-child(n + 7) {
    opacity: 0.5;
}

@media (max-width: 768px) {
    :root {
        --fh-float-y: 12px;
    }

    .fh-wrapper {
        min-height: 280px;
    }

    .fh-logo img {
        max-width: 80px;
        max-height: 56px;
    }

    .fh-title-layer {
        width: 90%;
    }
}

@media (max-width: 480px) {
    :root {
        --fh-float-y: 8px;
    }

    .fh-wrapper {
        min-height: 220px;
    }

    .fh-logo img {
        max-width: 56px;
        max-height: 40px;
    }

    .fh-title-layer {
        width: 95%;
    }
}
