/* ==========================================================================
   PLAYER.CSS — ADVANCED CUSTOM IPTV VIDEO PLAYER WITH GESTURE HUD
   ========================================================================== */

/* Fullscreen / Modal Player Overlay */
.player-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  background: #000000;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
  touch-action: none; /* Manage touch gestures customly */
}

.player-modal.active {
  display: flex;
}

/* Brightness Filter Overlay (Adjusted dynamically via JS style.filter) */
.player-brightness-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: transparent;
  z-index: 2;
  transition: opacity 0.15s ease;
}

/* Video Stage */
.player-stage {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000000;
}

.player-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000000;
}

/* Gesture Touch Areas (Left for Brightness, Right for Volume) */
.player-gesture-surface {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
}

.gesture-zone-left,
.gesture-zone-right {
  flex: 1;
  height: 100%;
}

/* Gesture Feedback HUD Overlays */
.gesture-hud {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 25;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  padding: 16px 14px;
  min-width: 60px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.gesture-hud.active {
  display: flex;
}

.gesture-hud-left {
  left: 24px;
}

.gesture-hud-right {
  right: 24px;
}

.gesture-hud-icon {
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}

.gesture-hud-icon svg {
  width: 24px;
  height: 24px;
}

.gesture-hud-bar-container {
  width: 6px;
  height: 100px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  position: relative;
  overflow: hidden;
}

.gesture-hud-bar-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, var(--primary), var(--accent));
  border-radius: 3px;
  height: 100%;
  transition: height 0.05s ease;
}

.gesture-hud-value {
  font-size: 0.75rem;
  font-weight: 800;
  color: #FFFFFF;
  font-family: var(--font-mono);
}

/* Loading Spinner */
.player-spinner-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(8, 11, 18, 0.65);
  backdrop-filter: blur(4px);
  pointer-events: none;
}

.player-spinner-overlay.active {
  display: flex;
}

.spinner {
  width: 52px;
  height: 52px;
  border: 4px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner-text {
  font-size: 0.875rem;
  font-weight: 700;
  color: #FFFFFF;
  letter-spacing: 0.04em;
}

/* Stream Error Overlay with Retry */
.player-error-overlay {
  position: absolute;
  inset: 0;
  z-index: 35;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 14px;
  padding: 24px;
  background: rgba(8, 11, 18, 0.92);
}

.player-error-overlay.active {
  display: flex;
}

.error-icon-box {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: rgba(239, 68, 68, 0.2);
  color: #EF4444;
  display: flex;
  align-items: center;
  justify-content: center;
}

.error-icon-box svg {
  width: 28px;
  height: 28px;
}

.error-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: #FFFFFF;
}

.error-message {
  font-size: 0.85rem;
  color: var(--muted);
  max-width: 380px;
  line-height: 1.45;
}

.retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  border-radius: 12px;
  background: var(--primary);
  color: #FFFFFF;
  font-size: 0.875rem;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
  transition: all 0.2s ease;
}

.retry-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

/* First-time Gesture Hints Toast / Overlay */
.gesture-hint-overlay {
  position: absolute;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: rgba(17, 24, 39, 0.88);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 9999px;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  animation: fadeInOut 4s forwards ease-in-out;
  pointer-events: none;
}

.gesture-hint-overlay.active {
  display: flex;
}

@keyframes fadeInOut {
  0% { opacity: 0; transform: translate(-50%, 10px); }
  15% { opacity: 1; transform: translate(-50%, 0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -8px); }
}

/* --------------------------------------------------------------------------
   PLAYER CONTROLS LAYER (Fades in/out)
   -------------------------------------------------------------------------- */
.player-controls {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.player-controls.hidden-controls {
  opacity: 0;
  pointer-events: none;
}

.player-controls > * {
  pointer-events: auto;
}

/* Top Bar Overlay */
.player-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0) 100%);
}

.player-channel-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.player-channel-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  object-fit: cover;
  flex-shrink: 0;
}

.player-channel-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.player-channel-title {
  font-size: 1rem;
  font-weight: 800;
  color: #FFFFFF;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-channel-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--muted);
}

.player-live-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--badge-live);
  color: #FFFFFF;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.player-top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.player-icon-btn:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.08);
}

.player-icon-btn:active {
  transform: scale(0.95);
}

.player-icon-btn.is-fav {
  color: #EF4444;
}

.player-icon-btn svg {
  width: 20px;
  height: 20px;
}

/* Center Play/Pause Large Action (for touch tap feedback) */
.player-center-action {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: auto;
}

.player-center-action.visible {
  opacity: 1;
}

.player-center-action:hover {
  transform: translate(-50%, -50%) scale(1.1);
  background: rgba(0, 212, 255, 0.4);
}

.player-center-action svg {
  width: 32px;
  height: 32px;
}

/* Bottom Controls Bar */
.player-bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0) 100%);
  gap: 16px;
}

.player-bottom-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.player-bottom-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Volume Slider in bottom bar */
.player-volume-group {
  display: none;
  align-items: center;
  gap: 8px;
}

@media (min-width: 640px) {
  .player-volume-group {
    display: flex;
  }
}

.player-volume-slider {
  width: 90px;
  height: 5px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 3px;
  outline: none;
}

.player-volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   PICTURE-IN-PICTURE (PiP) FLOATING MINI-PLAYER
   -------------------------------------------------------------------------- */
.player-modal.pip-mode {
  position: fixed;
  bottom: 24px;
  right: 24px;
  top: auto;
  left: auto;
  width: 350px;
  height: 200px;
  border-radius: 16px;
  border: 2px solid var(--accent);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.75), 0 0 24px rgba(0, 212, 255, 0.3);
  z-index: 50;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
  background: #0B0F19;
  touch-action: auto;
}

@media (max-width: 640px) {
  .player-modal.pip-mode {
    bottom: 74px; /* Float above mobile bottom navigation (64px) */
    right: 12px;
    width: min(290px, calc(100vw - 24px));
    height: 165px;
    border-radius: 14px;
  }
}

/* In PiP mode, hide full-size overlays and touch gestures */
.player-modal.pip-mode .player-controls,
.player-modal.pip-mode .player-gesture-surface,
.player-modal.pip-mode .gesture-hud,
.player-modal.pip-mode .gesture-hint-overlay,
.player-modal.pip-mode .player-center-action {
  display: none !important;
}

/* Make video fit nicely in mini frame */
.player-modal.pip-mode .player-stage {
  cursor: pointer;
}

/* Mini Player Controls Overlay Bar */
.player-pip-bar {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 8px 10px;
  background: linear-gradient(to bottom, rgba(8, 11, 18, 0.94) 0%, rgba(8, 11, 18, 0.65) 75%, transparent 100%);
  z-index: 25;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: opacity 0.2s ease;
  user-select: none;
}

.player-modal.pip-mode .player-pip-bar {
  display: flex;
}

.pip-channel-info {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.pip-live-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--badge-live);
  color: #FFFFFF;
  font-size: 0.55rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.pip-live-badge .live-dot {
  width: 4px;
  height: 4px;
}

.pip-channel-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: #FFFFFF;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}

.pip-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.pip-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(8px);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.18s ease;
}

.pip-btn:hover {
  background: rgba(255, 255, 255, 0.35);
  transform: scale(1.12);
  color: var(--accent);
}

.pip-btn-close:hover {
  background: rgba(239, 68, 68, 0.85);
  color: #FFFFFF;
}

.pip-btn svg {
  width: 14px;
  height: 14px;
}

/* Picture-in-Picture Floating Toast Notification */
.pip-toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(17, 24, 39, 0.94);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-active);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 0 16px rgba(0, 212, 255, 0.2);
  color: #FFFFFF;
  padding: 8px 18px;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 48;
  animation: pipToastAnim 3.5s forwards cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

@keyframes pipToastAnim {
  0% { opacity: 0; transform: translate(-50%, 15px); }
  15% { opacity: 1; transform: translate(-50%, 0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -10px); }
}

