/* ===== Trình phát tuỳ biến kiểu YouTube (public/js/dieu-khien-phat.js) =====
   Mọi lớp bắt đầu bằng "dkp-"; chỉ có hiệu lực trong .khung-phat.co-dieu-khien.
   Trạng thái đặt trên .khung-phat: dkp-an (điều khiển ẩn), dkp-dung (tạm dừng), dkp-het (hết bài), dkp-dem (đang đệm),
   dkp-keo (đang kéo thanh tiến độ), dkp-cham (thiết bị cảm ứng), dkp-ios, dkp-truc-tiep, dkp-toan-man, dkp-menu-mo. */

.khung-phat.co-dieu-khien { position: relative; }
.khung-phat.co-dieu-khien.dkp-an { cursor: none; }
.khung-phat.co-dieu-khien > .nhan-truc-tiep { display: none; }      /* nhãn trực tiếp đã nằm trong hàng điều khiển */
.khung-phat.co-dieu-khien video::-webkit-media-controls { display: none !important; }
.khung-phat.co-dieu-khien video::-webkit-media-controls-enclosure { display: none !important; }
.khung-phat.co-dieu-khien video::cue { font-size: clamp(14px, 2.6vw, 24px); background: rgba(0, 0, 0, .75); }

.dkp {
  position: absolute; inset: 0; z-index: 2;
  color: #fff; font-size: 13px; line-height: 1.2;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  outline: none;
}
.dkp, .dkp * { box-sizing: border-box; }
.dkp .bt { width: 24px; height: 24px; stroke-width: 1.8; }

/* ----- Nút chung: nền trong suốt, vùng chạm 44px ----- */
.dkp button {
  background: transparent; color: #fff; border: 0; border-radius: 50%;
  width: 44px; height: 44px; min-width: 44px; min-height: 44px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; flex: none; position: relative; transition: background .15s ease;
}
.dkp button:hover { background: rgba(255, 255, 255, .14); }
.dkp button:active { background: rgba(255, 255, 255, .24); }
.dkp button:focus-visible { outline: 2px solid #fff; outline-offset: -3px; }
.dkp button[aria-pressed="true"] .bt { color: #fff; }
.dkp-nut-phu-de[aria-pressed="true"]::after {
  content: ""; position: absolute; left: 13px; right: 13px; bottom: 8px; height: 2px; border-radius: 1px; background: var(--nhan, #ff3d3d);
}

/* ----- Lớp dưới: gradient + thanh tiến độ + hàng nút ----- */
.dkp-duoi {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 36px 8px 2px;
  background: linear-gradient(to top, rgba(0, 0, 0, .78) 0%, rgba(0, 0, 0, .45) 45%, rgba(0, 0, 0, 0) 100%);
  transition: opacity .25s ease, transform .25s ease;
}
.dkp-an .dkp-duoi { opacity: 0; transform: translateY(6px); pointer-events: none; }

.dkp-hang { display: flex; align-items: center; justify-content: space-between; gap: 2px; min-height: 48px; }
.dkp-trai, .dkp-phai { display: flex; align-items: center; gap: 0; min-width: 0; }
.dkp-trai { flex: 1 1 auto; }
.dkp-phai { flex: none; }

.dkp-thoi-gian { font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; padding: 0 8px; color: #fff; text-shadow: 0 0 2px rgba(0,0,0,.5); }
.dkp-thoi-gian .dkp-tg-tong { color: rgba(255, 255, 255, .75); }
.dkp-truc-tiep .dkp-thoi-gian .dkp-tg-cach { display: none; }

/* Nhãn TRỰC TIẾP: đỏ khi ở mép live, xám khi đang xem lại trong vùng DVR */
.dkp .dkp-nut-truc-tiep {
  width: auto; min-width: 0; height: 44px; border-radius: 4px; padding: 0 8px; gap: 6px;
  font-size: 12px; font-weight: 700; letter-spacing: .5px; color: #fff; white-space: nowrap;
}
.dkp-nut-truc-tiep::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #8a8a8a; flex: none; transition: background .2s; }
.dkp-nut-truc-tiep[aria-pressed="true"]::before { background: var(--nhan, #ff3d3d); animation: dkp-nhap-nhay 1.2s infinite; }
@keyframes dkp-nhap-nhay { 50% { opacity: .35; } }

/* ----- Âm lượng: nút + thanh trượt trượt ra khi rê chuột ----- */
.dkp-am-luong { display: flex; align-items: center; }
.dkp-thanh-am {
  -webkit-appearance: none; appearance: none;
  width: 0; height: 44px; margin: 0; padding: 0; opacity: 0; background: transparent; cursor: pointer;
  transition: width .2s ease, opacity .2s ease; font-size: 13px;
  --muc: 100%;
}
.dkp-am-luong:hover .dkp-thanh-am, .dkp-am-luong:focus-within .dkp-thanh-am, .dkp-keo-am .dkp-thanh-am { width: 64px; opacity: 1; margin-right: 6px; }
@media (hover: none) { .dkp-thanh-am { width: 64px; opacity: 1; margin-right: 6px; } }
.dkp-ios .dkp-thanh-am { display: none; }                         /* iOS không cho đổi âm lượng bằng mã */
.dkp-thanh-am::-webkit-slider-runnable-track {
  height: 3px; border-radius: 2px;
  background: linear-gradient(to right, #fff 0 var(--muc), rgba(255, 255, 255, .3) var(--muc) 100%);
}
.dkp-thanh-am::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 0; margin-top: -4.5px;
}
.dkp-thanh-am::-moz-range-track { height: 3px; border-radius: 2px; background: rgba(255, 255, 255, .3); }
.dkp-thanh-am::-moz-range-progress { height: 3px; border-radius: 2px; background: #fff; }
.dkp-thanh-am::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 0; }
.dkp-thanh-am:focus-visible { outline: 2px solid #fff; outline-offset: 2px; border-radius: 4px; }

/* ----- Thanh tiến độ ----- */
.dkp-tien-do {
  position: relative; height: 20px; margin: 0 8px; cursor: pointer; outline: none;
  display: flex; align-items: center; touch-action: none;
}
/* Cảm ứng: vùng chạm cao 36px (vạch vẫn 5px, tâm giữ nguyên nhờ bù margin âm) + khe 4px tới hàng nút
   → ngón tay lệch xuống 12–20px vẫn tua, không bấm nhầm Phụ đề / Toàn màn hình */
.dkp-cham .dkp-tien-do { height: 36px; margin-top: -8px; }
.dkp-cham .dkp-hang { margin-top: 4px; }
.dkp-tien-do:focus-visible .dkp-td-nut { transform: translate(-50%, -50%) scale(1); box-shadow: 0 0 0 3px rgba(255,255,255,.5); }
.dkp-td-nen {
  position: relative; width: 100%; height: 3px; background: rgba(255, 255, 255, .25); border-radius: 2px;
  transition: height .12s ease;
}
.dkp-tien-do:hover .dkp-td-nen, .dkp-keo .dkp-td-nen, .dkp-cham .dkp-td-nen { height: 5px; }
.dkp-td-dem, .dkp-td-phat, .dkp-td-treo {
  position: absolute; left: 0; top: 0; bottom: 0; border-radius: 2px; width: 0; transform-origin: left center;
}
.dkp-td-dem { background: rgba(255, 255, 255, .4); }
.dkp-td-treo { background: rgba(255, 255, 255, .35); opacity: 0; }
.dkp-tien-do:hover .dkp-td-treo { opacity: 1; }
.dkp-td-phat { background: var(--nhan, #ff3d3d); }
.dkp-td-nut {
  position: absolute; top: 50%; left: 0; width: 13px; height: 13px; border-radius: 50%; background: var(--nhan, #ff3d3d);
  transform: translate(-50%, -50%) scale(0); transition: transform .12s ease; pointer-events: none;
}
.dkp-tien-do:hover .dkp-td-nut, .dkp-keo .dkp-td-nut, .dkp-cham .dkp-td-nut { transform: translate(-50%, -50%) scale(1); }
.dkp-td-goi-y {
  position: absolute; bottom: 100%; left: 0; transform: translate(-50%, -2px);
  background: rgba(28, 28, 28, .92); color: #fff; font-size: 12px; font-variant-numeric: tabular-nums;
  padding: 4px 7px; border-radius: 4px; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .1s;
}
.khung-phat:not(.dkp-cham) .dkp-tien-do:hover .dkp-td-goi-y, .dkp-keo .dkp-td-goi-y { opacity: 1; }   /* cảm ứng: :hover dính sau khi kéo → không dùng */
.dkp-truc-tiep:not(.dkp-co-dvr) .dkp-tien-do { visibility: hidden; }

/* ----- Giữa: nút phát lớn, vòng xoay, nhãn phản hồi ----- */
.dkp-giua { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.dkp .dkp-phat-lon {
  pointer-events: auto; width: 68px; height: 68px; min-width: 68px; min-height: 68px;
  background: rgba(0, 0, 0, .55); border-radius: 50%; display: none;
  transition: background .15s ease, opacity .25s ease, transform .25s ease;
}
.dkp .dkp-phat-lon:hover { background: rgba(0, 0, 0, .75); }
.dkp-phat-lon .bt { width: 36px; height: 36px; stroke-width: 1.6; }
.dkp-dung .dkp-phat-lon, .dkp-het .dkp-phat-lon, .dkp-cham .dkp-phat-lon { display: inline-flex; }
.dkp-dem .dkp-phat-lon, .dkp-an .dkp-phat-lon { display: none; }

.dkp-xoay {
  width: 56px; height: 56px; border-radius: 50%; border: 4px solid rgba(255, 255, 255, .25); border-top-color: #fff;
  animation: dkp-xoay .9s linear infinite; position: absolute;
}
@keyframes dkp-xoay { to { transform: rotate(360deg); } }

.dkp-phan-hoi {
  position: absolute; display: flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 56px; height: 56px; padding: 0 14px; border-radius: 28px;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums;
  pointer-events: none; opacity: 0;
}
.dkp-phan-hoi .bt { width: 28px; height: 28px; }
.dkp-phan-hoi.hien { animation: dkp-phan-hoi .6s ease-out forwards; }
@keyframes dkp-phan-hoi { 0% { opacity: 1; transform: scale(1); } 60% { opacity: 1; } 100% { opacity: 0; transform: scale(1.5); } }

/* ----- Chạm đúp tua 10 giây: vòng tròn lan + chữ ----- */
.dkp-tua {
  position: absolute; top: 0; bottom: 0; width: 38%; display: flex; align-items: center; justify-content: center;
  pointer-events: none; opacity: 0;
}
.dkp-tua-trai { left: 0; border-radius: 0 50% 50% 0 / 0 50% 50% 0; }
.dkp-tua-phai { right: 0; border-radius: 50% 0 0 50% / 50% 0 0 50%; }
.dkp-tua.hien { animation: dkp-tua-nen .7s ease-out forwards; }
@keyframes dkp-tua-nen { 0% { opacity: 0; background: rgba(255,255,255,.18); } 20% { opacity: 1; } 100% { opacity: 0; background: rgba(255,255,255,.08); } }
.dkp-tua-noi { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.dkp-tua-noi .bt { width: 30px; height: 30px; }
.dkp-tua.hien .dkp-tua-noi .bt { animation: dkp-tua-mui .6s ease-out; }
@keyframes dkp-tua-mui { 0% { transform: scale(.6); opacity: .4; } 50% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); } }

/* ----- Lỗi ngắn ----- */
.dkp-loi {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%);
  max-width: min(92%, 480px); padding: 12px 16px; border-radius: 10px;
  background: rgba(0, 0, 0, .8); color: #fff; font-size: 14px; text-align: center; pointer-events: none;
}

/* ----- Menu cài đặt ----- */
.dkp-menu {
  position: absolute; right: 12px; bottom: 60px; z-index: 3;
  width: min(300px, calc(100% - 24px)); max-height: calc(100% - 76px); overflow-y: auto;
  background: rgba(28, 28, 28, .92); border-radius: 12px; padding: 8px 0;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .45); font-size: 13px;
  transform-origin: bottom right; animation: dkp-menu-hien .14s ease-out;
}
@keyframes dkp-menu-hien { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
.dkp-menu button {
  width: 100%; min-width: 0; height: 44px; border-radius: 0; padding: 0 16px; justify-content: flex-start; gap: 12px;
  font-size: 13px; font-weight: 500; text-align: left; white-space: nowrap;
}
.dkp-menu button:hover { background: rgba(255, 255, 255, .1); }
.dkp-menu button .bt { width: 22px; height: 22px; color: rgba(255,255,255,.9); }
.dkp-menu .dkp-muc-ten { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.dkp-menu .dkp-muc-gia-tri { color: rgba(255, 255, 255, .72); font-weight: 400; display: inline-flex; align-items: center; gap: 2px; max-width: 55%; overflow: hidden; text-overflow: ellipsis; }
.dkp-menu .dkp-muc-gia-tri .bt { width: 18px; height: 18px; }
.dkp-menu .dkp-menu-dau { border-bottom: 1px solid rgba(255, 255, 255, .15); margin-bottom: 6px; font-weight: 600; }
.dkp-menu .dkp-menu-dau .bt { width: 20px; height: 20px; }
.dkp-menu [role="menuitemradio"] .dkp-muc-kiem { width: 22px; height: 22px; flex: none; visibility: hidden; }
.dkp-menu [role="menuitemradio"][aria-checked="true"] .dkp-muc-kiem { visibility: visible; }

/* ----- Toàn màn hình: khung phát phủ kín, video co giãn giữ tỉ lệ ----- */
.khung-phat.co-dieu-khien:fullscreen { width: 100%; height: 100%; margin: 0; border-radius: 0; background: #000; display: flex; align-items: center; justify-content: center; top: auto; }
.khung-phat.co-dieu-khien:fullscreen video { width: 100%; height: 100%; max-height: none; aspect-ratio: auto; object-fit: contain; border-radius: 0; }
.khung-phat.co-dieu-khien:-webkit-full-screen { width: 100%; height: 100%; margin: 0; border-radius: 0; background: #000; display: flex; align-items: center; justify-content: center; top: auto; }
.khung-phat.co-dieu-khien:-webkit-full-screen video { width: 100%; height: 100%; max-height: none; aspect-ratio: auto; object-fit: contain; border-radius: 0; }
.dkp-toan-man .dkp-duoi { padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); padding-bottom: max(2px, env(safe-area-inset-bottom)); }

/* ----- Màn hẹp: bỏ âm lượng và chế độ rạp để hàng nút không tràn ----- */
@media (max-width: 599px) {
  /* ".dkp .dkp-…" để thắng ".dkp button{display:inline-flex}" (đặc hiệu 0,1,1) — chế độ rạp vô nghĩa dưới 1024px */
  .dkp .dkp-am-luong, .dkp .dkp-nut-rap { display: none; }
  .dkp-duoi { padding: 28px 4px 0; }
  .dkp-tien-do { margin: 0 6px; }
  .dkp-hang { min-height: 44px; }
  .dkp-thoi-gian { font-size: 12px; padding: 0 6px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .dkp .dkp-phat-lon { width: 60px; height: 60px; min-width: 60px; min-height: 60px; }
  .dkp-menu { right: 8px; bottom: 52px; }
}
/* Màn rất hẹp (≤374px) có nút Bài sau (danh sách phát): bỏ " / tổng" để chữ thời gian không đè lên nhóm nút phải */
@media (max-width: 374px) {
  .dkp-trai:has(.dkp-nut-sau:not([hidden])) .dkp-tg-cach,
  .dkp-trai:has(.dkp-nut-sau:not([hidden])) .dkp-tg-tong { display: none; }
}
/* Điện thoại cầm ngang, màn thấp: điều khiển gọn hơn */
@media (max-height: 420px) {
  .dkp-duoi { padding-top: 20px; }
  .dkp-menu { max-height: calc(100% - 56px); bottom: 50px; }
  .dkp-menu button { height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  .dkp *, .dkp-duoi, .dkp-menu { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .dkp-xoay { animation-duration: .9s !important; }   /* vòng xoay vẫn phải quay để báo đang đệm */
  .dkp-phan-hoi.hien { animation: none; opacity: 1; }
  .dkp-tua.hien { animation: none; opacity: 1; background: rgba(255,255,255,.12); }
}
