/* แอนิเมชันของ progress bar (โหลดหลัง style.css เพื่อเขียนทับค่าเดิม) */

#myProgress {
  position: relative;
  height: 22px;
  margin-block: 10px;
  border-radius: 999px;
  background-color: rgba(255, 255, 255, 0.2);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.35);
}

#myBar {
  --bar-color: #ffffff;
  --bar-glow: rgba(255, 255, 255, 0.8);
  --stripe-speed: 1s;

  position: relative;
  height: 100%;
  border-radius: inherit;
  background-color: var(--bar-color);
  /* ลายทางเฉียงที่เลื่อนไปเรื่อย ๆ */
  background-image: linear-gradient(
    45deg,
    rgba(0, 0, 0, 0.12) 25%,
    transparent 25%,
    transparent 50%,
    rgba(0, 0, 0, 0.12) 50%,
    rgba(0, 0, 0, 0.12) 75%,
    transparent 75%
  );
  background-size: 40px 40px;
  box-shadow: 0 0 12px var(--bar-glow);
  animation: bar-stripes var(--stripe-speed) linear infinite;
  transition: width 0.5s ease, background-color 0.8s ease, box-shadow 0.8s ease;
}

/* แสงวิ่งผ่านแถบ */
#myBar::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.75) 50%,
    transparent 100%
  );
  background-size: 50% 100%;
  background-repeat: no-repeat;
  animation: bar-shimmer 2.5s ease-in-out infinite;
}

/* จุดเรืองแสงที่ปลายแถบ */
#myBar::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -13px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 35%, var(--bar-color) 70%);
  box-shadow: 0 0 10px 4px var(--bar-glow);
  transform: translateY(-50%);
  animation: bar-pulse 1.4s ease-in-out infinite;
}

/* เหลือเวลาไม่เกิน 5 นาที: สีส้ม */
#myBar.is-ending {
  --bar-color: #ffb347;
  --bar-glow: rgba(255, 179, 71, 0.9);
  --stripe-speed: 0.6s;
}

/* เหลือเวลาไม่เกิน 1 นาที: สีแดง กะพริบเร็วขึ้น */
#myBar.is-last {
  --bar-color: #ff5252;
  --bar-glow: rgba(255, 82, 82, 1);
  --stripe-speed: 0.3s;
}
#myBar.is-last::after {
  animation-duration: 0.5s;
}

@keyframes bar-stripes {
  from { background-position: 0 0; }
  to   { background-position: 40px 0; }
}

@keyframes bar-shimmer {
  0%   { background-position: -100% 0; }
  100% { background-position: 200% 0; }
}

@keyframes bar-pulse {
  0%, 100% { transform: translateY(-50%) scale(1); }
  50%      { transform: translateY(-50%) scale(1.35); }
}

@media (prefers-reduced-motion: reduce) {
  #myBar,
  #myBar::before,
  #myBar::after {
    animation: none;
  }
}
