/* Unified responsive video player v4 — Canva mockup layout, NajirEXE theme.
 * Mobile-first: stacked layout on phones, 3-column grid on desktop (1024px+).
 * One player code for both — no more desktop/mobile split.
 *
 * Mobile order (top to bottom):
 * - Video (full-bleed)
 * - Back + title, episode info, controls, server/language, volume
 * - Up Next + seasons + episode list
 * - Recommendations (horizontal scroll)
 * - Settings gear opens a bottom sheet
 *
 * Desktop (1024px+): 3-column grid
 * - Left: back+title, video, episode info, controls, server/lang, volume
 * - Middle: seasons pills, Up Next episodes
 * - Right: recommendation cards
 */

/* ============ MOBILE BASE (stacked) ============ */
.bp4-topnav { display: none; } /* desktop-only; JS doesn't build it on mobile */

.st-player.st-yt.bp4 {
  display: flex;
  flex-direction: column;
  padding: 0 0 48px;
  background: #0a0a0c;
  max-width: none;
  margin: 0;
  align-items: stretch;
  overflow-y: auto;
}
/* v4: video stays in normal document flow (not floating) so title/controls
 * don't overlap. The base stream.css fixed-position rule is overridden. */
.st-player.st-yt.bp4:not(.mini-mode) .st-yt-video-wrap {
  position: relative;
  top: auto;
  left: auto;
  right: auto;
  z-index: auto;
}
.st-player.st-yt.bp4 .st-yt-main {
  max-width: none;
  flex: none;
  width: 100%;
}

/* Back + title */
.bp4-backrow {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px 0;
}
.bp4-back {
  background: none; border: 0; color: #fff; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 18px; font-weight: 700; padding: 0;
}
.bp4-back .material-symbols-outlined { font-size: 24px; }

/* Video: full-bleed on mobile */
.st-yt-video-wrap {
  border-radius: 0;
  border: 0;
  overflow: hidden;
}
/* Mobile keeps native touch controls (see JS); do NOT hide them here. */

/* The base player pins the video fixed on mobile with 12px gaps — give it
 * an opaque background so scrolled content doesn't show through the gaps. */
.st-player.st-yt.bp4:not(.mini-mode) .st-yt-video-wrap {
  background: #0a0a0c;
}

/* Episode info */
.bp4-epinfo {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 0;
}
.bp4-epinfo .bp4-ep-title {
  font-size: 14px; font-weight: 600; color: #c9c9d4; margin: 0;
}
.bp4-ep-pill {
  font-size: 12px; font-weight: 700; color: #fff;
  background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.14);
  border-radius: 999px; padding: 5px 14px;
}

/* Controls */
.bp4-controls {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px 0; flex-wrap: wrap;
}
/* Mobile: hide v4 playback buttons (native video controls are used instead).
 * Settings gear and Server/Language stay visible. */
.bp4-cbtn[data-bp4="play"],
.bp4-cbtn[data-bp4="mute"],
.bp4-cbtn[data-bp4="prev"],
.bp4-cbtn[data-bp4="next"],
.bp4-cbtn[data-bp4="pip"],
.bp4-volbar {
  display: none;
}
.bp4-cbtn {
  width: 44px; height: 44px; border-radius: 10px;
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.1);
  color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.bp4-cbtn:active { background: rgba(255,255,255,0.15); }
.bp4-cbtn .material-symbols-outlined { font-size: 24px; }
.bp4-cbtn.bp4-play { background: rgba(255,255,255,0.12); }
.bp4-cbtn.bp4-play .material-symbols-outlined { font-size: 28px; }

/* Server/language button: prominent, outside the gear menu */
.bp4-server {
  display: flex; align-items: center; gap: 8px;
  margin-left: 8px; padding: 10px 16px;
  background: transparent; border: 0; cursor: pointer;
  color: #8a8a93; font-size: 13px; font-weight: 600;
}
.bp4-server:active { color: #fff; }
.bp4-server .material-symbols-outlined { font-size: 20px; }

/* Volume */
.bp4-volbar {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 12px 16px 0;
}
.bp4-volbar .material-symbols-outlined { color: #8a8a93; font-size: 24px; flex-shrink: 0; }
.bp4-volbar input[type="range"] {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 8px; border-radius: 999px;
  background: linear-gradient(to right, rgba(255,255,255,0.5) var(--bp4-vol, 100%), rgba(255,255,255,0.15) var(--bp4-vol, 100%));
  cursor: pointer;
}
.bp4-volbar input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: 50%; background: #8a8a93;
}
.bp4-volbar input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%; background: #8a8a93; border: 0;
}

/* Seasons + Up Next + Episodes (stacked) */
.bp4-mid {
  display: flex; flex-direction: column; gap: 14px;
  padding: 16px 16px 0;
}
.bp4-mid h3 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 18px; font-weight: 600; color: #c9c9d4; margin: 0;
}
.bp4-seasons {
  display: flex; gap: 10px;
  overflow-x: auto; flex-wrap: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.bp4-seasons::-webkit-scrollbar { display: none; }
.bp4-season-pill {
  flex-shrink: 0;
  padding: 10px 20px; border-radius: 999px;
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.1);
  color: #c9c9d4; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all 0.2s;
}
.bp4-season-pill.active { background: #fff; color: #0a0a0a; border-color: #fff; }

/* Up Next */
.bp4-upnext {
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  padding: 16px;
}
.bp4-upnext-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.bp4-upnext-head h4 {
  font-size: 16px; font-weight: 700; color: #fff; margin: 0;
}
.bp4-upnext-head span { font-size: 13px; color: #8a8a93; }
.bp4-eplist { display: flex; flex-direction: column; gap: 10px; }
.bp4-ep {
  display: flex; gap: 12px; align-items: center;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px; padding: 12px;
  cursor: pointer; transition: background 0.2s; width: 100%; text-align: left; color: inherit;
}
.bp4-ep:active { background: rgba(255,255,255,0.07); }
.bp4-ep.cur { background: rgba(255,255,255,0.09); border-color: rgba(255,255,255,0.2); }
.bp4-ep-n {
  flex: 0 0 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,0.08);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; color: #fff;
}
.bp4-ep.cur .bp4-ep-n { background: #fff; color: #0a0a0a; }
.bp4-ep-tx { flex: 1; min-width: 0; }
.bp4-ep-tx b { display: block; font-size: 14px; color: #fff; margin-bottom: 2px; }
.bp4-ep-tx span { font-size: 12px; color: #c9c9d4; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bp4-ep-tx em { font-size: 11px; color: #8a8a93; font-style: normal; }

/* Recommendations: horizontal scroll on mobile */
.bp4-recs {
  display: flex; flex-direction: row; gap: 12px;
  overflow-x: auto;
  padding: 16px 16px 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.bp4-recs::-webkit-scrollbar { display: none; }
.bp4-rec-card {
  flex: 0 0 120px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  aspect-ratio: 3/4;
  display: flex; align-items: center; justify-content: center;
  color: #8a8a93; font-size: 13px; font-weight: 600; text-align: center;
  cursor: pointer; overflow: hidden; padding: 8px;
}
.bp4-rec-card img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }

/* Settings as bottom sheet on mobile */
.st-player.st-yt.bp4 .st-p-menu {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  top: auto;
  max-width: none;
  max-height: 70vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  background: rgba(18,18,22,0.98);
  border: 1px solid rgba(255,255,255,0.1);
  border-bottom: 0;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 100;
  backdrop-filter: blur(20px);
}

/* Dedicated watch page */
body.bp4-watchpage .st-player.st-yt.bp4 {
  position: static;
  inset: auto;
  z-index: auto;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-y: visible;
}

/* ============ DESKTOP (1024px+): 3-column grid ============ */
@media (min-width: 1024px) {

  /* Custom playback controls (desktop only; mobile uses native) */
  .bp4-cbtn[data-bp4="play"],
  .bp4-cbtn[data-bp4="mute"],
  .bp4-cbtn[data-bp4="prev"],
  .bp4-cbtn[data-bp4="next"],
  .bp4-cbtn[data-bp4="pip"],
  .bp4-volbar {
    display: flex;
  }
  .bp4-volbar { align-items: center; }

  /* Top nav (desktop only) */
  .bp4-topnav {
    grid-column: 1 / -1;
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 32px;
    background: rgba(10,10,12,0.95);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    backdrop-filter: blur(16px);
  }
  .bp4-topnav-left { display: flex; align-items: center; gap: 28px; }
  .bp4-logo { font-family: 'Space Grotesk', sans-serif; font-size: 20px; font-weight: 700; color: #fff; }
  .bp4-logo span { color: #d4e4fa; }
  .bp4-nav { display: flex; gap: 4px; }
  .bp4-nav button {
    padding: 8px 16px; border-radius: 9999px; background: transparent; border: 0;
    color: #8a8a93; font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.2s;
  }
  .bp4-nav button:hover { color: #fff; background: rgba(255,255,255,0.06); }
  .bp4-nav button.active { color: #fff; background: rgba(255,255,255,0.1); }
  .bp4-topnav-right { display: flex; gap: 12px; align-items: center; }
  .bp4-icon-btn, .bp4-profile-btn {
    width: 40px; height: 40px; border-radius: 50%;
    background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
    color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px; overflow: hidden;
  }
  .bp4-icon-btn:hover { background: rgba(255,255,255,0.12); }
  .bp4-profile-btn img { width: 100%; height: 100%; object-fit: cover; }

  /* 3-column grid */
  .st-player.st-yt.bp4 {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px 200px;
    gap: 24px;
    padding: 20px 32px 40px;
    max-width: 1700px;
    margin: 0 auto;
    align-items: start;
  }
  .st-player.st-yt.bp4 .st-yt-main {
    max-width: none;
    flex: none;
  }

  /* Back + title */
  .bp4-backrow {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 14px;
    padding: 0;
  }
  .bp4-back { font-size: 22px; }
  .bp4-back .material-symbols-outlined { font-size: 28px; }
  .bp4-back:hover { opacity: 0.8; }

  /* Video */
  .st-yt-video-wrap {
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,0.08);
  }

  /* Episode info */
  .bp4-epinfo { padding: 0; margin: 14px 0 12px; }

  /* Controls */
  .bp4-controls { padding: 0; margin-bottom: 14px; }
  .bp4-cbtn:hover { background: rgba(255,255,255,0.15); }
  .bp4-server { margin-left: 12px; }
  .bp4-server:hover { color: #fff; }

  /* Volume */
  .bp4-volbar { margin: 0; }

  /* Middle column */
  .bp4-mid {
    padding: 0;
    max-height: calc(100vh - 140px);
    overflow-y: auto;
    scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.15) transparent;
  }
  .bp4-mid h3 { font-size: 20px; }
  .bp4-seasons { flex-wrap: wrap; overflow: visible; }
  .bp4-upnext-head h4 { font-size: 17px; }
  .bp4-ep:hover { background: rgba(255,255,255,0.07); }

  /* Right column: vertical recommendations */
  .bp4-recs {
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    max-height: calc(100vh - 140px);
    scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.15) transparent;
  }
  .bp4-rec-card {
    flex: none;
    width: 100%;
    font-size: 14px;
    padding: 12px;
  }
  .bp4-rec-card:hover { border-color: rgba(255,255,255,0.2); }

  /* Settings: anchored panel on desktop (not bottom sheet) */
  .st-player.st-yt.bp4 .st-p-menu {
    position: absolute;
    left: auto; right: 12px; bottom: auto;
    max-width: calc(100vw - 24px);
    max-height: none;
    border-radius: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding: 8px;
  }

  /* Grid wins over older player rules */
  body.beta-watch-page .st-player.st-yt.bp4 {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px 200px;
    gap: 24px;
    padding: 20px 32px 40px;
    max-width: 1700px;
    margin: 0 auto;
    align-items: start;
  }
  body.beta-watch-page .st-player.st-yt.bp4 .st-yt-main {
    max-width: none;
    flex: none;
  }
}
