/* ==========================================================================
   Kachanan Tarot — Animations
   ใช้ animation อย่างพอดี: fade up, fade in, floating card, gold glow,
   card flip (ประกาศไว้ใน style.css), accordion, slider, mobile menu
   ทุก animation ปิดการทำงานเมื่อผู้ใช้เปิด prefers-reduced-motion
   ========================================================================== */

/* ==========================================================================
   01. KEYFRAMES
   ========================================================================== */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(26px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeInScale {
  from {
    opacity: 0;
    transform: scale(0.94);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* ไพ่ลอยเบาๆ — ช้าและนุ่มนวล */
@keyframes floatSoft {
  0%, 100% { transform: translateY(0) rotate(var(--float-rotate, 0deg)); }
  50%      { transform: translateY(-14px) rotate(var(--float-rotate, 0deg)); }
}

/* วงกลมเวทมนตร์หมุนช้ามาก */
@keyframes spinSlow {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

@keyframes spinSlowReverse {
  from { transform: rotate(360deg); }
  to   { transform: rotate(0deg); }
}

/* แสงทองเต้นเบาๆ */
@keyframes glowPulse {
  0%, 100% { opacity: 0.42; transform: scale(1); }
  50%      { opacity: 0.78; transform: scale(1.05); }
}

@keyframes twinkle {
  0%, 100% { opacity: 0.28; }
  50%      { opacity: 0.85; }
}

/* สนามดาวพื้นหลัง 2 ชั้น — คนละช่วงความทึบเพื่อให้เห็นเป็นระยะใกล้/ไกล
   ต้องแยก keyframe เพราะ keyframe ที่สั่ง opacity จะทับค่า opacity ของ rule เอง */
@keyframes starNear {
  0%, 100% { opacity: 0.46; }
  50%      { opacity: 0.82; }
}

@keyframes starFar {
  0%, 100% { opacity: 0.20; }
  50%      { opacity: 0.46; }
}

@keyframes shimmer {
  from { background-position: -180% 0; }
  to   { background-position: 180% 0; }
}

/* เลื่อนขึ้นอย่างเดียว ไม่แตะ opacity
   ใช้กับ element ที่เป็น LCP เพราะ Chrome ไม่นับ element ที่ opacity เป็น 0
   ถ้า fade ตัวนั้นจะทำให้ LCP เพี้ยนหรือหายไปเลย */
@keyframes riseUp {
  from { transform: translateY(20px); }
  to   { transform: translateY(0); }
}

/* วงแหวนทองกระเพื่อมออกจากจุดสี */
@keyframes dotRing {
  0%   { box-shadow: 0 0 0 0 rgba(218, 188, 153, 0.55); }
  70%  { box-shadow: 0 0 0 8px rgba(218, 188, 153, 0); }
  100% { box-shadow: 0 0 0 0 rgba(218, 188, 153, 0); }
}

@keyframes popIn {
  0%   { opacity: 0; transform: translateY(12px) scale(0.96); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* ==========================================================================
   02. SCROLL REVEAL (ใช้ร่วมกับ IntersectionObserver ใน main.js)
   ========================================================================== */
.reveal {
  opacity: 0;
  transform: translateY(26px);
  transition: opacity 0.7s cubic-bezier(0.22, 0.61, 0.36, 1),
    transform 0.7s cubic-bezier(0.22, 0.61, 0.36, 1);
  will-change: opacity, transform;
}

.reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Fade in อย่างเดียว ไม่มีการเลื่อน */
.reveal--scale {
  transform: scale(0.96);
}

.reveal--scale.is-visible {
  transform: scale(1);
}

/* Stagger — ใส่ style="--delay: 1" ..n ที่ตัวลูก */
.reveal[style*="--delay"] {
  transition-delay: calc(var(--delay, 0) * 90ms);
}

/* ==========================================================================
   03. HERO VISUAL ANIMATION
   ========================================================================== */
.mystic-circle .ring-outer {
  transform-origin: center;
  animation: spinSlow 90s linear infinite;
}

.mystic-circle .ring-mid {
  transform-origin: center;
  animation: spinSlowReverse 70s linear infinite;
}

.mystic-circle .ring-inner {
  transform-origin: center;
  animation: spinSlow 50s linear infinite;
}

.mystic-circle .ring-star {
  transform-origin: center;
  animation: twinkle 4.5s ease-in-out infinite;
}

.hero-visual .glow {
  animation: glowPulse 7s ease-in-out infinite;
}

.float-card {
  animation: floatSoft 7s ease-in-out infinite;
}

.float-card--left {
  --float-rotate: -14deg;
  animation-duration: 8s;
  animation-delay: -1.2s;
}

.float-card--center {
  --float-rotate: 0deg;
  animation-duration: 6.5s;
}

.float-card--right {
  --float-rotate: 14deg;
  animation-duration: 7.6s;
  animation-delay: -2.4s;
}

.hero-moon {
  animation: glowPulse 9s ease-in-out infinite;
}

/* --- Hero entrance — เล่นครั้งเดียวตอนโหลด ไม่ผูกกับ IntersectionObserver
       เพราะ hero อยู่บนสุดของหน้าอยู่แล้ว รอ scroll ไม่ได้

       หมายเหตุเรื่องความเร็ว: LCP ของหน้าแรกคือข้อความใน .hero-title
       จึงตั้ง delay ของหัวเรื่องไว้ต่ำสุด (0.05s) เพื่อไม่ให้ LCP ขยับ
       ตัวอื่นค่อยไล่ตามหลังได้เพราะไม่ใช่ตัวที่ถูกวัด --- */
.hero-copy > * {
  animation: fadeUp 0.6s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

/* หัวเรื่องคือ LCP ของหน้าแรก จึงเลื่อนขึ้นอย่างเดียว ห้าม fade
   ไม่งั้น Chrome จะไม่นับเป็น LCP เพราะเริ่มที่ opacity 0 */
.hero-title {
  animation: riseUp 0.6s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

.hero-copy .eyebrow { animation-delay: 0s; }
.hero-text          { animation-delay: 0.15s; }
.hero-actions       { animation-delay: 0.25s; }
.hero-meta          { animation-delay: 0.35s; }

/* การ์ด 3 ใบใน hero-meta ทยอยขึ้นต่อจากบล็อกแม่ */
.hero-meta .hero-meta-item {
  animation: fadeUp 0.5s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

.hero-meta .hero-meta-item:nth-child(1) { animation-delay: 0.4s; }
.hero-meta .hero-meta-item:nth-child(2) { animation-delay: 0.5s; }
.hero-meta .hero-meta-item:nth-child(3) { animation-delay: 0.6s; }

/* ภาพฝั่งขวาค่อยๆ ขยายเข้ามา ไพ่ที่ลอยอยู่ข้างในยังลอยต่อได้ปกติ */
.hero-visual {
  animation: fadeInScale 0.85s cubic-bezier(0.22, 0.61, 0.36, 1) 0.15s both;
}

/* ==========================================================================
   04. GOLD GLOW / HOVER SHEEN
   ========================================================================== */
/* ==========================================================================
   05. TAROT CARD ANIMATION
   ========================================================================== */
/* การ์ดถูกเปิด — ให้ผลลัพธ์ค่อยๆ ปรากฏ */
.tarot-card.is-flipped .tarot-face--reveal {
  animation: fadeIn 0.5s ease 0.35s both;
}

/* กองไพ่ปรากฏขึ้นแบบไล่ลำดับ
   ใช้เฉพาะ opacity เพื่อไม่ให้ animation-fill-mode ทับ transform ของ :hover */
.tarot-deck .tarot-card,
/* ผลการทำนายปรากฏ */
.reading-result:not([hidden]) {
  animation: fadeUp 0.65s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

.reading-list .reading-item {
  animation: fadeUp 0.6s cubic-bezier(0.22, 0.61, 0.36, 1) both;
  animation-delay: calc(var(--item-index, 0) * 110ms);
}

/* ==========================================================================
   06. HOROSCOPE DASHBOARD
   ========================================================================== */
.horo-dashboard:not([hidden]) {
  animation: fadeUp 0.6s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

.horo-grid .horo-item,
.lucky-row .lucky-box {
  animation: fadeUp 0.55s cubic-bezier(0.22, 0.61, 0.36, 1) both;
  animation-delay: calc(var(--item-index, 0) * 90ms);
}

/* ปุ่มเลือกวันเกิดทยอยขึ้นทีละใบตอนเลื่อนมาถึง
   ผูกกับ .is-visible ที่ IntersectionObserver ใน main.js ใส่ให้ */
.selector-grid.is-visible .selector-item {
  animation: fadeUp 0.5s cubic-bezier(0.22, 0.61, 0.36, 1) both;
  animation-delay: calc(var(--item-index, 0) * 70ms);
}

/* หัวการ์ดผลทำนายถูกสร้างใหม่ทุกครั้งที่เปลี่ยนวัน จึงเล่นซ้ำได้
   ต่างจาก .horo-dashboard ที่เล่นครั้งเดียวตอนเลิก hidden */
.horo-dashboard .horo-header {
  animation: fadeUp 0.5s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

/* สถานะยังไม่ได้เลือก — ไอคอนหายใจเบาๆ ให้รู้ว่ารออยู่ */
.horo-empty svg {
  animation: glowPulse 3.2s ease-in-out infinite;
}

/* จุดสีของวันที่เลือก กระเพื่อมเป็นวงเบาๆ ยืนยันการเลือก */
.selector-item[aria-pressed="true"] .selector-dot {
  animation: dotRing 2.6s ease-out infinite;
}

/* ==========================================================================
   07. MODAL
   ========================================================================== */
.modal.is-open .modal-dialog {
  animation: popIn 0.42s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

.modal.is-open .modal-icon {
  animation: fadeInScale 0.55s cubic-bezier(0.22, 0.61, 0.36, 1) 0.1s both;
}

/* ==========================================================================
   08. MISC MICRO-INTERACTION
   ========================================================================== */
.chip,
.selector-item,
.btn {
  will-change: transform;
}

/* ==========================================================================
   09. REDUCED MOTION — ปิด animation ทั้งหมด
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  .reveal {
    opacity: 1 !important;
    transform: none !important;
  }

  .float-card,
  .hero-moon,
  .hero-visual .glow,
  .mystic-circle .ring-outer,
  .mystic-circle .ring-mid,
  .mystic-circle .ring-inner,
  .mystic-circle .ring-star,
  .tarot-deck .tarot-card,
  /* ยังคงพลิกไพ่ให้เห็นผล แต่ไม่หมุน 3D */
  .tarot-card-inner {
    transition: none !important;
  }

  .card:hover,
  .btn:hover,
  .chip:hover,
  .selector-item:hover,
  .social-link:hover,
  .contact-item:hover {
    transform: none !important;
  }
}
