/* ====================================================================
   YTCustomPlayer — Modern Professional CSS  v2.0
   Glassmorphism · Smooth Animations · Touch-Friendly · E-Learning Ready
   ==================================================================== */

/* Google Fonts — loaded once in <head>, reference only */
/* @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap'); */

:root {
  --ytp-accent: #f5365c;
  --ytp-accent-glow: rgba(245, 54, 92, 0.45);
  --ytp-bg: rgba(10, 10, 18, 0.92);
  --ytp-glass: rgba(255, 255, 255, 0.08);
  --ytp-glass-border: rgba(255, 255, 255, 0.12);
  --ytp-text: #f0f0f5;
  --ytp-text-dim: #a8a8b8;
  --ytp-radius: 10px;
  --ytp-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Wrapper ─────────────────────────────────────────── */
.yt-player-wrapper {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%;
  height: 0;
  background: #0a0a12;
  border-radius: var(--ytp-radius);
  overflow: hidden;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.55),
    0 1px 0 var(--ytp-glass-border) inset;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-family: 'Kanit', 'Inter', sans-serif;
}

.yt-player-iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border: 0;
  pointer-events: none;
}

/* ─── Watermark ───────────────────────────────────────── */
.yt-player-watermark {
  position: absolute;
  top: 14px; right: 18px;
  color: rgba(255, 255, 255, 0.5);
  font-size: 12px;
  font-weight: 500;
  pointer-events: none;
  z-index: 10;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
  line-height: 1.4;
  letter-spacing: 0.3px;
}

/* ─── Center Controls Overlay ───────────────────────── */
.yt-player-overlay {
  position: absolute;
  inset: 0;
  display: flex !important;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.4);
  cursor: pointer;
  z-index: 15;
  transition: background var(--ytp-transition);
  -webkit-tap-highlight-color: transparent;
}

.yt-player-wrapper:not(.paused):not(.user-active) .yt-player-overlay {
  background: transparent;
}

.yt-player-wrapper.paused:not(.user-active) .yt-player-overlay {
  background: rgba(0, 0, 0, 0.4);
}

.yt-center-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.yt-player-wrapper.user-active .yt-center-controls {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.yt-center-btn {
  background: rgba(12, 12, 20, 0.72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  line-height: 1;
}

.yt-center-spd-btn {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: -0.3px;
  font-family: inherit;
}

.yt-center-play-btn {
  width: 56px;
  height: 56px;
  background: var(--ytp-accent);
  border: none;
  box-shadow: 0 8px 28px var(--ytp-accent-glow);
}

.yt-center-btn:hover {
  transform: scale(1.12);
  background: rgba(255, 255, 255, 0.28);
}

.yt-center-play-btn:hover {
  transform: scale(1.12);
  background: #ff4b72;
}

.yt-center-btn:active {
  transform: scale(0.92);
}

/* ─── Subtitles Elevation Offset ────────────────────── */
.yt-player-wrapper.has-subtitles .yt-player-iframe {
  height: calc(100% - 52px) !important;
  top: 0 !important;
}

/* เต็มจอ: ยกเลิก subtitles offset ให้วิดีโอเต็มพื้นที่ */
.yt-player-wrapper.fullscreen-active.has-subtitles .yt-player-iframe {
  height: 100% !important;
}

/* ─── Controls Bar ────────────────────────────────────── */
.yt-player-controls {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.95) 0%,
    rgba(0, 0, 0, 0.65) 75%,
    transparent 100%
  );
  padding: 10px 14px calc(8px + env(safe-area-inset-bottom, 0px));
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 4px;
  opacity: 1;
  transition: opacity 0.35s ease;
  color: var(--ytp-text);
}

.yt-player-wrapper:not(.user-active) .yt-player-controls {
  opacity: 0;
  pointer-events: none;
}

/* ─── Mobile Fullscreen Fallback (WebView / LINE / FB) ── */
.yt-player-wrapper.yt-mobile-fullscreen {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  width: 100dvw !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-width: none !important;
  max-height: none !important;
  padding-bottom: 0 !important;
  margin: 0 !important;
  z-index: 999999 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: #000 !important;
}

/* เต็มจอต้องให้ iframe เต็มพื้นที่ ไม่ว่าจะเปิด subtitles หรือไม่ */
.yt-player-wrapper.yt-mobile-fullscreen .yt-player-iframe,
.yt-player-wrapper.yt-mobile-fullscreen.has-subtitles .yt-player-iframe {
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
}

/* ป้องกัน overlay ไม่ให้สร้างที่ว่างเกินเมื่อเต็มจอ */
.yt-player-wrapper.yt-mobile-fullscreen .yt-player-overlay {
  inset: 0 !important;
}

/* Safe area padding สำหรับ controls ตอนเต็มจอ */
.yt-player-wrapper.yt-mobile-fullscreen .yt-player-controls {
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
  padding-left: calc(14px + env(safe-area-inset-left, 0px)) !important;
  padding-right: calc(14px + env(safe-area-inset-right, 0px)) !important;
}

/* ─── Progress Bar ────────────────────────────────────── */
.yt-progress-area {
  position: relative;
  width: 100%;
  height: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  touch-action: none;
  -webkit-touch-callout: none;
}

.yt-progress-bg {
  position: relative;
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 4px;
  overflow: visible;
  transition: height 0.15s ease;
}

.yt-progress-area:hover .yt-progress-bg {
  height: 6px;
}

.yt-progress-buffer {
  position: absolute;
  top: 0; left: 0;
  height: 100%; width: 0%;
  background: rgba(255, 255, 255, 0.28);
  border-radius: 4px;
}

.yt-progress-bar {
  position: absolute;
  top: 0; left: 0;
  height: 100%; width: 0%;
  background: var(--ytp-accent);
  border-radius: 4px;
  box-shadow: 0 0 8px var(--ytp-accent-glow);
  transition: box-shadow 0.2s ease;
}

/* Progress Thumb — visible on hover */
.yt-progress-bar::after {
  content: '';
  position: absolute;
  right: -6px; top: 50%;
  transform: translateY(-50%) scale(0);
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--ytp-accent);
  box-shadow: 0 0 6px var(--ytp-accent-glow);
  transition: transform 0.15s ease;
}

.yt-progress-area:hover .yt-progress-bar::after {
  transform: translateY(-50%) scale(1);
}

/* ─── Controls Row ────────────────────────────────────── */
.yt-controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  width: 100%;
}

.yt-controls-left,
.yt-controls-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ─── Control Buttons ─────────────────────────────────── */
.yt-ctrl-btn {
  background: transparent;
  border: none;
  color: var(--ytp-text);
  font-size: 16px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    background var(--ytp-transition),
    color var(--ytp-transition),
    transform 0.1s ease;
  line-height: 1;
  min-width: 32px;
  min-height: 32px;
  position: relative;
}

.yt-ctrl-btn:hover {
  background: var(--ytp-glass);
  color: #fff;
}

.yt-ctrl-btn:active {
  transform: scale(0.9);
}

/* Active State (CC, etc.) */
.yt-ctrl-btn.active {
  color: var(--ytp-accent) !important;
}

.yt-ctrl-btn.active span {
  border-color: var(--ytp-accent) !important;
  background: rgba(245, 54, 92, 0.15);
}

/* ─── Time Display ────────────────────────────────────── */
.yt-time-display {
  font-size: 12px;
  color: var(--ytp-text-dim);
  min-width: 85px;
  margin-left: 4px;
  letter-spacing: 0.5px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* ─── Dropdown Selectors (Speed / Quality) ────────────── */
.yt-select-group {
  position: relative;
  display: inline-block;
}

.yt-select-btn {
  background: var(--ytp-glass);
  border: 1px solid var(--ytp-glass-border);
  color: var(--ytp-text);
  font-size: 12px;
  font-family: 'Kanit', 'Inter', sans-serif;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all var(--ytp-transition);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.yt-select-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: var(--ytp-accent);
}

/* ─── Dropdown Menu (Glassmorphism) ───────────────────── */
.yt-dropdown-menu {
  display: none;
  position: absolute;
  bottom: 100%;
  right: 0;
  margin-bottom: 8px;
  background: rgba(16, 16, 24, 0.96);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid var(--ytp-glass-border);
  border-radius: 10px;
  padding: 6px 0;
  min-width: 110px;
  max-height: 220px;
  overflow-y: auto;
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.05) inset;
  z-index: 30;
  animation: ytMenuIn 0.18s ease-out;
}

@keyframes ytMenuIn {
  from { opacity: 0; transform: translateY(6px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.yt-dropdown-menu.show {
  display: block;
}

/* Scrollbar Styling */
.yt-dropdown-menu::-webkit-scrollbar {
  width: 4px;
}

.yt-dropdown-menu::-webkit-scrollbar-track {
  background: transparent;
}

.yt-dropdown-menu::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.yt-dropdown-item {
  padding: 8px 14px;
  font-size: 13px;
  color: var(--ytp-text-dim);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
  font-weight: 500;
  border-radius: 4px;
  margin: 0 4px;
}

.yt-dropdown-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.yt-dropdown-item.active {
  background: var(--ytp-accent);
  color: #fff;
}

/* ─── Desktop vs Mobile Visibility ────────────────────── */
.yt-desktop-only { display: inline-flex !important; }
.yt-mobile-only  { display: none !important; }
.yt-lbl-10s      { display: inline !important; }

/* ─── Volume Control ──────────────────────────────────── */
.yt-volume-group {
  display: flex !important;
  align-items: center;
  gap: 6px;
}

.yt-volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 60px;
  height: 4px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
  transition: width 0.2s ease;
}

.yt-volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--ytp-accent);
  cursor: pointer;
  box-shadow: 0 0 4px var(--ytp-accent-glow);
}

.yt-volume-slider::-moz-range-thumb {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--ytp-accent);
  border: none;
  cursor: pointer;
}

/* ─── Mobile Settings Dropdown ────────────────────────── */
.yt-mobile-settings-menu {
  min-width: 200px;
  max-height: 300px;
}

.yt-dropdown-header {
  font-size: 10px;
  color: var(--ytp-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 8px 14px 4px;
  font-weight: 600;
}

.yt-dropdown-divider {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  margin: 4px 8px;
}

.yt-setting-row {
  display: flex !important;
  justify-content: space-between;
  align-items: center;
}

.yt-setting-val {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--ytp-glass);
  color: var(--ytp-text);
  font-weight: 500;
}

/* CC Badge in Button */
.yt-cc-badge {
  border: 1.5px solid currentColor;
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  transition: all var(--ytp-transition);
}

/* ─── Fullscreen Button ───────────────────────────────── */
.yt-fs-icon {
  font-size: 18px;
  line-height: 1;
}

/* ====================================================================
   RESPONSIVE — Mobile & Tablet (max-width: 768px)
   ==================================================================== */
@media (max-width: 768px) {
  .yt-player-wrapper.has-subtitles .yt-player-iframe {
    height: calc(100% - 68px) !important;
  }

  .yt-desktop-only { display: none !important; }
  .yt-mobile-only  { display: inline-flex !important; }
  .yt-lbl-10s      { display: none !important; }
  .yt-volume-group { display: none !important; }

  .yt-player-wrapper {
    border-radius: 6px;
  }

  .yt-player-controls {
    padding: 16px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    gap: 6px;
  }

  .yt-controls-row {
    gap: 4px;
  }

  .yt-controls-left,
  .yt-controls-right {
    gap: 4px;
  }

  .yt-ctrl-btn {
    padding: 8px 10px;
    font-size: 18px;
    min-width: 42px;
    min-height: 42px;
    border-radius: 8px;
  }

  .yt-ctrl-btn:active {
    background: rgba(255, 255, 255, 0.2);
  }

  .yt-select-btn {
    font-size: 14px;
    padding: 6px 12px;
    min-height: 42px;
    border-radius: 8px;
  }

  .yt-time-display {
    font-size: 11px;
    min-width: 60px;
    margin-left: 2px;
  }

  .yt-player-watermark {
    font-size: 10px;
    top: 6px; right: 8px;
  }

  /* Bigger touch area for progress */
  .yt-progress-area {
    height: 24px;
  }

  .yt-progress-bg {
    height: 5px;
  }

  .yt-progress-bar::after {
    width: 18px; height: 18px;
    right: -9px;
    transform: translateY(-50%) scale(1);
  }

  /* Mobile Dropdown Item Touch Targets */
  .yt-dropdown-item {
    padding: 12px 16px;
    font-size: 14px;
  }

  .yt-dropdown-header {
    font-size: 11px;
    padding: 10px 14px 4px;
  }

  .yt-mobile-settings-menu {
    min-width: 230px;
    max-height: 50vh;
  }

  /* Center Controls on Mobile */
  .yt-center-controls {
    gap: 6px;
  }

  .yt-center-btn {
    width: 36px;
    height: 36px;
  }

  .yt-center-spd-btn {
    font-size: 10px;
  }

  .yt-center-play-btn {
    width: 46px;
    height: 46px;
  }

  /* Big Play Button slightly smaller on Mobile */
  .yt-big-play-btn {
    width: 50px; height: 50px;
    font-size: 20px;
  }
}

/* ====================================================================
   RESPONSIVE — Very Small Phones (max-width: 380px)
   ==================================================================== */
@media (max-width: 380px) {
  .yt-center-controls {
    gap: 3px;
  }

  .yt-center-btn {
    width: 30px;
    height: 30px;
  }

  .yt-center-spd-btn {
    font-size: 9px;
  }

  .yt-center-play-btn {
    width: 38px;
    height: 38px;
  }

  .yt-time-display {
    font-size: 10px;
    min-width: 50px;
  }

  .yt-ctrl-btn {
    padding: 6px 8px;
    min-width: 36px;
    min-height: 36px;
    font-size: 16px;
  }

  .yt-select-btn {
    font-size: 13px;
    padding: 6px 10px;
    min-height: 36px;
  }
}
