/* ── Video Player Page ── */
.player-page {
  padding: 0;
  padding-top: env(safe-area-inset-top, 0px);
  background: #000;
  min-height: 100vh;
  touch-action: manipulation; /* Prevent pinch zoom & double-tap zoom */
}

.player-container {
  position: relative;
  width: 100%;
}

/* ── Vidstack Player ── */
.player-container media-player {
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 75vh;
  background: #000;
  --media-brand: #e50914;
  --media-focus-ring-color: #e50914;
  --media-tooltip-bg-color: rgba(0,0,0,0.85);
}

/* Desktop - more space */
@media (min-width: 1024px) {
  .player-container media-player {
    max-height: 80vh;
  }
}

.player-back {
  position: absolute;
  top: 12px;
  left: calc(12px + env(safe-area-inset-left, 0px));
  z-index: 10;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

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

/* ── Buffering Overlay ── */
.player-buffering {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.8);
  z-index: 5;
  pointer-events: none;
}

/* ── Vidstack Fullscreen ── */
media-player[data-fullscreen] {
  max-height: none !important;
  aspect-ratio: auto !important;
}

media-player:fullscreen {
  max-height: none !important;
  aspect-ratio: auto !important;
}

/* iOS CSS fullscreen fallback (Vidstack applies this when Fullscreen API unavailable) */
media-player[data-fullscreen] {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  max-height: none !important;
  z-index: 99999 !important;
  background: #000 !important;
  aspect-ratio: auto !important;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  box-sizing: border-box !important;
}

/* Hide back button in fullscreen */
media-player[data-fullscreen] ~ .player-back,
media-player:fullscreen ~ .player-back {
  display: none;
}

/* Captions styling */
media-player [data-part="cue"] {
  font-size: 16px;
}

media-player[data-fullscreen] [data-part="cue"],
media-player:fullscreen [data-part="cue"] {
  font-size: 20px !important;
}

/* Prevent touch zoom on fullscreen player */
media-player[data-fullscreen],
media-player[data-fullscreen] * {
  touch-action: manipulation !important;
}

/* ── Player Info Panel ── */
.player-info {
  padding: 16px;
  background: var(--bg-primary);
}

.player-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 12px;
}

.player-controls-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* ── Download Progress Overlay ── */
.player-progress {
  padding: 12px 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.player-progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.player-progress-title {
  font-size: 13px;
  font-weight: 500;
}

.player-progress-percent {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
}

.player-progress-stats {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.player-progress-stat {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Subtitle Track List ── */
.subtitle-tracks {
  margin-top: 12px;
}

.subtitle-track {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 4px;
  font-size: 13px;
}

.subtitle-track.active {
  border-left: 3px solid var(--accent);
}

/* ── Landscape fullscreen ── */
@media (orientation: landscape) and (max-height: 500px) {
  .player-page {
    padding-top: 0;
  }

  .player-page .bottom-nav {
    display: none;
  }

  .player-container media-player {
    max-height: 100vh;
    aspect-ratio: auto;
    height: 100vh;
  }

  .player-info {
    display: none;
  }

  body {
    padding-bottom: 0;
  }
}

/* ── File Selector ── */
.file-list {
  margin-top: 12px;
}

.file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.file-item:active { background: var(--bg-elevated); }
.file-item.active { border-left: 3px solid var(--accent); }

.file-name {
  font-size: 13px;
  flex: 1;
  margin-right: 8px;
  word-break: break-all;
}

.file-size {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}
