/* ============================================
   مشروع العمر — Video Player Styles
   (Plyr + HLS + watermark + states)
   ============================================ */

/* تحميل Plyr من CDN — يستخدم مع CSS الأساسي */
@import url('https://cdn.jsdelivr.net/npm/plyr@3.7.8/dist/plyr.css');

/* ─── حاوية المشغّل ─── */
.player-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius-lg, 16px);
  overflow: hidden;
  isolation: isolate;
}

.player-stage video,
.player-stage .plyr {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-lg, 16px);
}

/* ─── حالة التحميل ─── */
.player-stage.is-loading::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at center, rgba(0,204,102,0.08), transparent 60%),
    linear-gradient(135deg, #0a0a0a, #1a1a1a);
  z-index: 2;
}
.player-stage.is-loading::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 56px; height: 56px;
  border: 3px solid rgba(0,204,102,0.2);
  border-top-color: var(--accent, #00cc66);
  border-radius: 50%;
  animation: mau-spin 0.8s linear infinite;
  z-index: 3;
}
@keyframes mau-spin { to { transform: translate(-50%, -50%) rotate(360deg); } }

/* ─── حالة الخطأ ─── */
.player-stage.is-error {
  display: flex;
  align-items: center;
  justify-content: center;
}
.player-error {
  text-align: center;
  color: var(--text-secondary);
  padding: var(--sp-6, 24px);
  max-width: 420px;
}
.player-error svg {
  color: var(--danger, #ef4444);
  margin-bottom: var(--sp-3, 12px);
}
.player-error h3 {
  font-size: var(--fs-lg, 1.25rem);
  margin-bottom: var(--sp-2, 8px);
  color: var(--text-primary);
}
.player-error p {
  font-size: var(--fs-sm, 0.875rem);
  margin-bottom: var(--sp-4, 16px);
  opacity: 0.85;
}

/* ─── علامة مائية مضادة للتسريب ─── */
.player-watermark {
  position: absolute;
  top: 12px;
  inset-inline-end: 16px;
  z-index: 3;
  padding: 4px 10px;
  background: rgba(0, 0, 0, 0.35);
  color: rgba(255, 255, 255, 0.6);
  font-size: 11px;
  font-family: var(--font-arabic, system-ui), sans-serif;
  border-radius: 999px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  pointer-events: none;
  user-select: none;
  letter-spacing: 0.02em;
  /* يطفو فوق Plyr بدون تعطيل التحكّم */
  mix-blend-mode: overlay;
}

/* ─── تخصيص ألوان Plyr لتطابق هوية الموقع ─── */
.plyr {
  --plyr-color-main: var(--accent, #00cc66);
  --plyr-video-control-color: #fff;
  --plyr-video-control-color-hover: var(--accent, #00cc66);
  --plyr-video-control-background-hover: rgba(255,255,255,0.1);
  --plyr-range-fill-background: var(--accent, #00cc66);
  --plyr-menu-background: rgba(20, 20, 20, 0.95);
  --plyr-menu-color: #fff;
  --plyr-tooltip-background: rgba(20, 20, 20, 0.92);
  --plyr-tooltip-color: #fff;
  --plyr-font-family: var(--font-arabic, "Tajawal"), system-ui, sans-serif;
  font-family: var(--plyr-font-family) !important;
  direction: ltr; /* أزرار التحكّم LTR حتى في الصفحات RTL */
}

/* في الصفحات RTL، نُبقي الـcontrols بترتيبها الطبيعي */
[dir="rtl"] .plyr__controls {
  direction: ltr;
}

/* قائمة الإعدادات تأخذ اتجاه الصفحة */
[dir="rtl"] .plyr__menu__container {
  direction: rtl;
  text-align: right;
}

/* تحسين ظهور الترجمات */
.plyr__captions {
  font-size: 1.05em;
  line-height: 1.5;
  background: rgba(0, 0, 0, 0.7);
  padding: 4px 10px;
  border-radius: 4px;
  backdrop-filter: blur(2px);
}

/* تحسين زر التشغيل المركزي على الجوال */
.plyr--video .plyr__control--overlaid {
  background: rgba(0, 204, 102, 0.85);
  padding: 18px;
}
.plyr--video .plyr__control--overlaid:hover,
.plyr--video .plyr__control--overlaid:focus {
  background: var(--accent, #00cc66);
}

/* ─── حالة "مكتمل" في قائمة الحلقات ─── */
.episode-item.is-completed .ep-num {
  background: rgba(0, 204, 102, 0.18);
  border-color: var(--accent, #00cc66);
  color: var(--accent, #00cc66);
}
.episode-item.is-completed .ep-num span {
  display: none;
}
.episode-item.is-completed .ep-num::before {
  content: "✓";
  font-weight: 700;
  font-size: 1.1em;
  line-height: 1;
}
.episode-item.is-completed h4 {
  text-decoration: line-through;
  text-decoration-color: rgba(0, 204, 102, 0.4);
  text-decoration-thickness: 1.5px;
  opacity: 0.7;
}

/* ─── حماية بسيطة من تنزيل الفيديو ─── */
.plyr__video-wrapper video::-webkit-media-controls-enclosure {
  /* إخفاء Download menu في Chrome */
}
video::-internal-media-controls-download-button {
  display: none !important;
}

/* ─── responsive ─── */
@media (max-width: 700px) {
  .player-watermark {
    font-size: 9px;
    padding: 3px 8px;
    top: 8px;
    inset-inline-end: 8px;
  }
  .plyr__controls {
    padding: 6px 8px !important;
  }
}

/* ─── منع تحديد النصّ على الفيديو (anti-screenshot helper) ─── */
.player-stage,
.player-stage * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
