/* ==========================================================================
   motion.css — เอฟเฟกต์เคลื่อนไหวทั้งเว็บ (ใช้ร่วมกับ assets/js/main.js)
   - ซ่อนองค์ประกอบก่อนแสดงเฉพาะเมื่อ JS ทำงาน (html.js) เนื้อหาจึงไม่หายถ้า JS ไม่โหลด
   - ปิดทั้งหมดอัตโนมัติเมื่อผู้ใช้ตั้งค่า "ลดการเคลื่อนไหว" (prefers-reduced-motion)
   ========================================================================== */

@media (prefers-reduced-motion: no-preference) {

  /* 1. Scroll reveal: ค่อยๆ ลอยขึ้นตอนเลื่อนมาถึง (เรียงทีละชิ้นด้วย --d)
     ใช้ animation แบบ fill "backwards" — จบแล้วกลับเป็นสไตล์ปกติ hover จึงยังทำงาน */
  .js [data-reveal] { opacity: 0; }
  .js [data-reveal].is-in { opacity: 1; animation: rise .8s var(--ease) var(--d, 0s) backwards; }
  .js [data-reveal="zoom"].is-in { animation-name: rise-zoom; }

  /* รูปในการ์ด: ค่อยๆ ชัดขึ้นพร้อมซูมออกเล็กน้อย */
  .js [data-reveal].is-in .cat-card__media img,
  .js [data-reveal].is-in > img,
  .js [data-reveal].is-in .work-card__img {
    animation: soft-in 1.2s var(--ease) calc(var(--d, 0s) + .1s) backwards;
  }

  @keyframes rise-zoom { from { opacity: 0; transform: translateY(20px) scale(.96); } to { opacity: 1; transform: none; } }

  /* 2. Hero: ข้อความลอยขึ้นตอนโหลด + รูปซูมช้าๆ ---------------- */
  .js .hero__title .phrase,
  .js .hero__lead,
  .js .hero__actions,
  .js .hotspot {
    opacity: 0;
    animation: rise .9s var(--ease) forwards;
  }
  .js .hero__title .phrase:nth-child(1) { animation-delay: .15s; }
  .js .hero__title .phrase:nth-child(2) { animation-delay: .27s; }
  .js .hero__title .phrase:nth-child(3) { animation-delay: .39s; }
  .js .hero__lead { animation-delay: .5s; }
  .js .hero__actions { animation-delay: .62s; }
  .js .hero .hotspot { animation-delay: 1.1s; }
  .js .hero__bg { animation: kenburns 18s ease-out both; will-change: transform; }

  /* แบนเนอร์หน้าย่อย */
  .js .page-banner h1 { opacity: 0; animation: rise .9s var(--ease) .1s forwards; }
  .js .page-banner__bg { animation: kenburns 18s ease-out both; }
  .js .page-banner__intro { opacity: 0; animation: rise .9s var(--ease) .3s forwards; }

  @keyframes rise { from { opacity: 0; transform: translateY(26px); } to { opacity: 1; transform: none; } }
  @keyframes soft-in { from { opacity: 0; filter: blur(8px); transform: scale(1.08); } to { opacity: 1; filter: none; transform: none; } }
  @keyframes kenburns { from { transform: scale(1.1); } to { transform: scale(1); } }

  /* 3. Hover เล็กๆ น้อยๆ ------------------------------------------------- */
  .btn .icon { transition: transform .25s var(--ease); }
  .btn:hover .icon:last-child { transform: translateX(3px); }
  .work-card__img { transition: transform .6s var(--ease); }
  .work-card { overflow: hidden; }
  .work-card:hover .work-card__img { transform: scale(1.03); }
  .contact-card { transition: transform .3s var(--ease), box-shadow .3s var(--ease); }
  .contact-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }

}

/* 4. แถบความคืบหน้าการอ่าน ---------------------------------------------- */
.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 200;
  width: 100%;
  height: 3px;
  background: var(--black);
  transform: scaleX(var(--progress, 0));
  transform-origin: left;
  pointer-events: none;
}

/* 5. เปลี่ยนหมวดสินค้าแบบไม่โหลดทั้งหน้า (main.js) ----------------------- */
#main { transition: opacity .2s ease; }
#main.is-loading { opacity: .55; cursor: progress; }
@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(root), ::view-transition-new(root) { animation-duration: .35s; }
}
