/* ==========================================================================
   WooCommerce Product Video Autoplay — UI/UX
   ========================================================================== */

.youtube-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 16px;
  background: #0a0a0a;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.08);
  isolation: isolate;
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1),
              box-shadow 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.youtube-wrapper:hover {
  transform: translateY(-4px);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.22), 0 4px 10px rgba(0, 0, 0, 0.12);
}

/* Viền gradient tinh tế tạo điểm nhấn */
.youtube-wrapper::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  z-index: 4;
}

/* --------------------------------------------------------------------------
   Iframe
   -------------------------------------------------------------------------- */
.youtube-wrapper .yt-frame-holder,
.youtube-wrapper #yt-player {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  z-index: 2;
}

/* --------------------------------------------------------------------------
   Poster (hiển thị trước khi lazy-load)
   -------------------------------------------------------------------------- */
.youtube-wrapper .yt-poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
  transform: scale(1.02);
  transition: opacity 0.5s ease, transform 6s ease;
}

.youtube-wrapper:hover .yt-poster {
  transform: scale(1.08);
}

/* Lớp phủ gradient để text/nút nổi bật */
.youtube-wrapper::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.45) 0%,
    rgba(0, 0, 0, 0) 35%,
    rgba(0, 0, 0, 0) 70%,
    rgba(0, 0, 0, 0.25) 100%
  );
  opacity: 1;
  transition: opacity 0.4s ease;
}

.youtube-wrapper.is-ready::before {
  opacity: 0;
}

.youtube-wrapper.is-ready .yt-poster {
  opacity: 0;
}

/* Hiệu ứng loading shimmer khi đang chờ iframe */
.youtube-wrapper.is-loading .yt-frame-holder::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(
    100deg,
    rgba(255, 255, 255, 0) 30%,
    rgba(255, 255, 255, 0.12) 50%,
    rgba(255, 255, 255, 0) 70%
  );
  background-size: 200% 100%;
  animation: yt-shimmer 1.4s infinite;
}

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

/* --------------------------------------------------------------------------
   Badge "Video" góc trên
   -------------------------------------------------------------------------- */
.youtube-wrapper .yt-badge {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.youtube-wrapper .yt-badge svg {
  width: 13px;
  height: 13px;
  fill: #ff2d55;
}

.youtube-wrapper.is-ready .yt-badge {
  opacity: 0;
  transform: translateY(-6px);
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Nút Play lớn ở giữa
   -------------------------------------------------------------------------- */
.youtube-wrapper .yt-play-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 5;
  width: 74px;
  height: 74px;
  padding: 0;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #111;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1),
              background 0.3s ease, opacity 0.4s ease;
}

/* Vòng sóng pulse quanh nút play */
.youtube-wrapper .yt-play-badge::before {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  animation: yt-pulse 2.2s ease-out infinite;
}

@keyframes yt-pulse {
  0%   { transform: scale(0.85); opacity: 0.8; }
  100% { transform: scale(1.4); opacity: 0; }
}

.youtube-wrapper .yt-play-badge svg {
  width: 30px;
  height: 30px;
  fill: currentColor;
  margin-left: 3px;
}

.youtube-wrapper .yt-play-badge:hover {
  transform: translate(-50%, -50%) scale(1.08);
  background: #fff;
}

.youtube-wrapper .yt-play-badge:active {
  transform: translate(-50%, -50%) scale(0.96);
}

/* Ẩn nút play khi video đã chạy */
.youtube-wrapper.is-ready .yt-play-badge {
  opacity: 0;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Link ra YouTube (phủ toàn khung, dưới các nút)
   -------------------------------------------------------------------------- */
.youtube-wrapper .yt-external-link {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
}

/* --------------------------------------------------------------------------
   Nút bật/tắt tiếng
   -------------------------------------------------------------------------- */
.youtube-wrapper .mute-toggle {
  position: absolute;
  bottom: 16px;
  left: 16px;
  z-index: 6;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: rgba(20, 20, 20, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  transition: transform 0.25s ease, background 0.25s ease, color 0.25s ease;
}

.youtube-wrapper .mute-toggle:hover {
  transform: scale(1.08);
  background: rgba(20, 20, 20, 0.78);
}

.youtube-wrapper .mute-toggle:active {
  transform: scale(0.94);
}

.youtube-wrapper .mute-toggle svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.youtube-wrapper .mute-toggle.unmuted {
  color: #ff3b30;
  background: rgba(255, 255, 255, 0.92);
  border-color: transparent;
}

.youtube-wrapper .mute-toggle:focus-visible,
.youtube-wrapper .yt-play-badge:focus-visible {
  outline: 3px solid #4c9ffe;
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
  .youtube-wrapper { border-radius: 12px; }
  .youtube-wrapper .yt-play-badge { width: 60px; height: 60px; }
  .youtube-wrapper .yt-play-badge svg { width: 24px; height: 24px; }
  .youtube-wrapper .mute-toggle { width: 40px; height: 40px; bottom: 12px; left: 12px; }
  .youtube-wrapper .mute-toggle svg { width: 20px; height: 20px; }
}

/* Tôn trọng người dùng tắt hiệu ứng chuyển động */
@media (prefers-reduced-motion: reduce) {
  .youtube-wrapper,
  .youtube-wrapper .yt-poster,
  .youtube-wrapper .yt-play-badge,
  .youtube-wrapper .mute-toggle { transition: none; }
  .youtube-wrapper .yt-play-badge::before,
  .youtube-wrapper.is-loading .yt-frame-holder::before { animation: none; }
}
