/* --- เพิ่มตัวแปร :root ไว้บนสุดของไฟล์ --- */
:root {
  --bg-image: url('https://www.lcbp.co.th/wp-content/uploads/2026/03/galaxy.webp');
}
/* 1. ล้างค่าพื้นฐานเพื่อให้ชิดขอบหน้าจอ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  font-family: 'SF Thonburi', 'Sarabun', sans-serif;
  color: rgb(37, 34, 34);
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  background-color: #09080a;
  position: relative;
}

/* พื้นหลัง Galaxy แบบเคลื่อนไหว */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  background-image: var(--bg-image); /* <--- แก้ไขบรรทัดนี้ให้ดึงตัวแปรมาใช้ */
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  animation: galaxyPulse 30s ease-in-out infinite;
  transition: background-image 3s ease-in-out; /* <--- เพิ่มบรรทัดนี้ให้ภาพเปลี่ยนแบบนุ่มนวลขึ้น */
}

@keyframes galaxyPulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.07);
  }
}

/* 2. Header */
header {
  width: 100%;
  padding: 30px 20px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  text-align: center;
  flex-shrink: 0;
}

header img {
  height: 55px;
  margin-bottom: 10px;
}
header h1 {
  font-size: 2em;
  font-weight: 600;
  color: white;
  text-shadow: 0 2px 15px rgba(255, 255, 255, 0.3);
  margin: 0;
}
header h4 {
  font-size: 0.9em;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.8);
  margin-top: 5px;
}

/* 3. Main Content: Layout 2 คอลัมน์ (PC) */
.game-main-content {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
  padding: 40px 20px;
}

.game-container {
  display: flex;
  width: 100%;
  max-width: 1200px;
  gap: 50px;
  align-items: flex-start;
}

/* ฝั่งซ้าย: วงล้อ และ พลังบุญ */
.left-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ฝั่งขวา: รูปภาพ และ คำเฉลย */
.right-panel {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  padding: 30px;
  border-radius: 30px;
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255, 255, 255, 0.8);
}

/* 4. Wheel & Control */
.wheel-wrapper {
  position: relative;
  width: 380px;
  height: 380px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 20px;
}

.main-wheel {
  position: absolute;
  width: 100%;
  height: auto;
  border-radius: 50%;
  overflow: hidden;
  transition: transform 4s cubic-bezier(0.15, 0, 0.15, 1);
}

.wheel-img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
}

.spin-trigger {
  position: absolute;
  z-index: 100;
  width: 145px;
  height: 145px;
  cursor: pointer;
  background: url('https://www.lcbp.co.th/wp-content/uploads/2026/03/ปุ่มจุติ2.png')
    center/contain no-repeat;
  filter: drop-shadow(0 0 10px rgb(113, 46, 6));
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.spin-trigger:hover {
  transform: scale(1.09);
  filter: drop-shadow(0 0 40px rgb(255, 161, 9));
}
.spin-trigger:active {
  transform: scale(0.85);
}

/* 5. Result Components (ฝั่งขวา) */
#resImg {
  max-width: 100%;
  height: 160px;
  object-fit: contain;
  display: none;
  margin: 0 auto 0px auto;
  transition: opacity 0.5s ease-in-out;
}

.result-panel {
  width: 100%;
  text-align: center;
  display: none;
  opacity: 0;
}

.show-result {
  display: block !important;
  opacity: 1 !important;
}

h2 {
  font-size: 1.8em;
  color: #fbf9f9;
  text-align: center;
  text-shadow: 0 0px 5px rgb(38, 32, 64);
  margin-bottom: 0px;
  line-height: 44px;
}
h3 {
  text-align: center;
  font-size: 1.2em;
  color: rgb(250, 250, 250);
  text-shadow: 0 0px 5px rgb(38, 32, 64);
  line-height: 27px;
}

h4 {
  font-size: 2.7em;
  color: #fbf9f9;
  text-align: center;
  line-height: 44px;
  margin-bottom: 9px;
}

h2 small {
  display: inline-block;
  font-size: 0.6em;
  color: #fbf9f9;
  text-align: center;
  line-height: 1.4 !important; /* บรรทัดจะชิดกันมากขึ้น */
  margin: 5px 0; /* เว้นบนล่างนิดหน่อยให้ดูง่าย */
  font-weight: normal;
}

.cycle-container {
  display: flex;
  gap: 10px;
  margin: 20px 0;
}
.cycle-card {
  flex: 1;
  padding: 15px 5px;
  border-radius: 12px;
  font-size: 0.9em;
  text-align: center;
}
.label {
  font-size: 1.3em;
  display: block;
  font-weight: 700;
  margin-bottom: 5px;
  color: #000;
}

.kilesa {
  background: linear-gradient(
    rgba(255, 255, 255, 0.9),
    rgba(255, 255, 255, 0.3)
  );
  border-top: 3px solid #9856d6;
}
.kamma {
  background: linear-gradient(
    rgba(255, 255, 255, 0.9),
    rgba(255, 255, 255, 0.3)
  );
  border-top: 3px solid #27a8e3;
}
.vibaka {
  background: linear-gradient(
    rgba(255, 255, 255, 0.9),
    rgba(255, 255, 255, 0.3)
  );
  border-top: 3px solid #fbb71a;
}

/* 6. Merit Bar (ฝั่งซ้าย) */
.merit-status {
  width: 100%;
  margin: 20px 0;
}
.merit-status h1 {
  font-size: 1.8em;
  color: #ffffff;
  margin-bottom: 15px;
  text-align: center;
}
.merit-bar {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.bar {
  width: 25px;
  height: 25px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.3);
  transition: all 0.4s ease;

  /* --- เพิ่มบรรทัดนี้ครับ --- */
  animation: meritGlow 3s ease-in-out infinite;
}

/* สีสะสมบุญ (ขาวไปเหลืองทอง) พร้อมแสงเรืองที่ชัดขึ้น */
.fill-black {
  background: #ffffff !important;
  box-shadow: 0 0 10px #fff;
}
.fill-red {
  background: #ffffff !important;
  border: 1px solid #ffcc00;
  box-shadow: 0 0 12px #fff;
}
.fill-orange {
  background: #fad08e !important;
  border: 1px solid #f6a63d;
  box-shadow: 0 0 15px #ffae10;
}
.fill-lightblue {
  background: #fbc139 !important;
  border: 1px solid #f6a63d;
  box-shadow: 0 0 20px #ffbb00;
}
.fill-darkblue {
  background: #ffbb00 !important;
  border: 1px solid #f6a63d;
  box-shadow: 0 0 25px #ffbb00;
}

/* สร้าง Effect การเปล่งแสง (Glow) */
@keyframes meritGlow {
  0%,
  100% {
    transform: scale(1);
    filter: brightness(1);
  }
  50% {
    transform: scale(1.2); /* ขยายใหญ่ขึ้นเล็กน้อย */
    filter: brightness(1.3); /* สว่างขึ้น */
  }
}

/* 7. Footer & Buttons */
.nav-btn-group {
  display: flex;
  justify-content: center; /* จัดกึ่งกลางแนวนอน */
  gap: 15px; /* ระยะห่างระหว่างปุ่ม */
  margin: 10px auto; /* เว้นระยะบน-ล่างให้สมดุล */
  margin-left: -20;
  width: 80%;
  max-width: 350px;
  z-index: 10;
  position: relative;
}
.btn-nav {
  font-size: 13px;
  flex: 1;
  background: linear-gradient(60deg, #ff934b, #d4145a);
  color: white !important;
  text-decoration: none;
  padding: 6px 8px;
  border-radius: 50px;
  text-align: center;
  font-weight: 400;
  transition: all 0.3s ease;
  display: inline-block;
}

.btn-nav:hover {
  transform: translateY(-3px);
  box-shadow: 0 3px 8px rgba(131, 62, 87, 0.4);
  filter: brightness(1.1);
}

footer {
  width: 100%;
  background: #f5f5f5;
  color: #666;
  padding: 10px 10px;
  text-align: center;
  font-size: 13px;
  margin-top: auto;
}
footer img {
  height: 45px;
  margin-bottom: 0px;
}
footer a {
  text-decoration: none;
  color: #f6623d;
  font-weight: 600;
}

/* 8. Mobile Responsive */
@media (max-width: 992px) {
  .game-container {
    flex-direction: column;
    align-items: center;
    gap: 30px;
  }
  .left-panel,
  .right-panel {
    width: 100%;
  }
  .right-panel {
    background: transparent;
    border: none;
    padding: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.8);
  }
  .wheel-wrapper {
    width: 320px;
    height: 320px;
  }
  .spin-trigger {
    width: 120px;
    height: 120px;
  }
  .cycle-container {
    flex-direction: column;
  }
  .cycle-card {
    text-align: left;
    padding: 15px;
    display: flex;
    flex-direction: column;
  }
}

/* 9. Overlay & Countdown */
.game-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 9999;
  justify-content: center;
  align-items: center;
}

.overlay-content {
  background: white;
  color: #333;
  padding: 40px;
  border-radius: 30px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  max-width: 400px;
}

.retry-btn {
  background: linear-gradient(45deg, #ff934b, #d4145a);
  color: white;
  border: none;
  padding: 15px 40px;
  border-radius: 50px;
  cursor: pointer;
  font-weight: 400;
  margin-top: 20px;
}

/* เพิ่มเติมต่อจากของเดิมของเฮีย */

#countdown-wrapper {
  background: rgba(255, 255, 255, 0.8);
  padding: 20px;
  border-radius: 20px;
  border: 1px snow #fbb71a;
  margin-top: 20px;
  text-align: center;
  color: rgb(51, 45, 45); /* บังคับให้เป็นสีขาวจะได้เห็นชัดบนพื้นมืด */
}

#wait-msg {
  color: #bc1c1c; /* สีแดงสว่าง */
  font-weight: 600;
  margin-bottom: 10px;
  display: block;
}

#timer-count {
  font-size: 2.5em;
  font-weight: bold;
  color: #242320;
  display: inline-block;
  margin-left: 10px;
}

/* ป้องกันปัญหา result-panel ซ่อนถาวร */
.result-panel {
  width: 100%;
  text-align: center;
  display: none; /* ปิดไว้ก่อน */
  transition: opacity 0.5s ease-in-out;
  /* เอา opacity: 0 ออกเพื่อให้ JS คุม display อย่างเดียวพอ */
}
.pre-footer-credits {
  background-color: transparent; /* ให้เห็นพื้นหลัง Galaxy เดิม */
  color: white;
  padding: 10px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1); /* เส้นแบ่งจางๆ ด้านบน */
  backdrop-filter: blur(5px); /* เพิ่มเอฟเฟกต์เบลอให้เนื้อหาอ่านง่าย */
  position: relative;
  z-index: 5;
}
