/* Greybox multi-embed source UI — cinematic glass, token-driven.
 * No framework. Only Greybox tokens (css/tokens.css): glass surfaces,
 * low-opacity white borders, restrained amber accent. No foreign colors,
 * no giant spinners, no noisy chrome. */

.gx-src-select {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(10, 11, 14, 0.62);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  overflow-y: auto;
  animation: gx-src-fade 220ms ease;
}
.gx-src-select.hidden { display: none; }
@keyframes gx-src-fade { from { opacity: 0; } to { opacity: 1; } }

.gx-src-panel {
  width: 100%;
  max-width: 26rem;
  background: var(--gx-glass-strong);
  border: 1px solid var(--gx-border-strong);
  border-radius: var(--gx-radius-pop);
  box-shadow: var(--gx-shadow-pop), var(--gx-glass-highlight);
  padding: 1.25rem 1.25rem 1.1rem;
}

.gx-src-kicker {
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gx-accent);
  text-align: center;
}
.gx-src-title {
  margin-top: 0.2rem;
  font-size: 1.35rem;
  font-weight: 900;
  letter-spacing: -0.01em;
  color: var(--gx-text);
  text-align: center;
}
.gx-src-hint {
  margin-top: 0.35rem;
  min-height: 1.4rem;
  font-size: 0.82rem;
  color: var(--gx-text-dim);
  text-align: center;
}

.gx-src-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.9rem;
  max-height: 46vh;
  overflow-y: auto;
  padding: 0.1rem;
}

.gx-src-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  min-height: 44px;
  padding: 0.65rem 0.8rem;
  text-align: left;
  background: var(--gx-glass-wash);
  border: 1px solid var(--gx-border);
  border-radius: 0.8rem;
  color: var(--gx-text);
  cursor: pointer;
  transition: background var(--gx-transition), border-color var(--gx-transition), transform var(--gx-transition);
}
.gx-src-row:hover { background: rgba(255, 255, 255, 0.1); border-color: var(--gx-border-strong); }
.gx-src-row:active { transform: scale(0.99); }
.gx-src-row.is-selected { border-color: var(--gx-accent-border); background: var(--gx-accent-soft); }
.gx-src-row:disabled { opacity: 0.45; cursor: not-allowed; }
.gx-src-row:focus-visible { outline: 2px solid var(--gx-accent); outline-offset: 2px; }

.gx-src-name { font-size: 0.92rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gx-src-status { font-size: 0.72rem; color: var(--gx-text-dim); white-space: nowrap; }
.gx-src-row.is-selected .gx-src-status { color: var(--gx-accent-strong); }
.gx-src-check { color: var(--gx-accent-strong); font-weight: 800; }

.gx-src-dot { width: 0.55rem; height: 0.55rem; border-radius: 999px; background: #71717a; flex: none; }
.gx-src-dot-ready { background: #34d399; }
.gx-src-dot-selected { background: var(--gx-accent); }
.gx-src-dot-failed { background: #f87171; }
.gx-src-dot-unavailable { background: #52525b; }
.gx-src-dot-checking, .gx-src-dot-loading { background: var(--gx-accent); animation: gx-src-pulse 1.2s ease-in-out infinite; }
@keyframes gx-src-pulse { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }

.gx-src-empty { padding: 1rem 0.5rem; font-size: 0.85rem; color: var(--gx-text-dim); text-align: center; }

.gx-src-play {
  width: 100%;
  min-height: 44px;
  margin-top: 0.9rem;
  padding: 0.7rem 1rem;
  border: 0;
  border-radius: 0.8rem;
  background: linear-gradient(180deg, var(--gx-accent-strong), var(--gx-accent));
  color: #1b1e23;
  font-size: 0.92rem;
  font-weight: 800;
  cursor: pointer;
  transition: filter var(--gx-transition), transform var(--gx-transition);
}
.gx-src-play:hover:not(:disabled) { filter: brightness(1.07); }
.gx-src-play:active:not(:disabled) { transform: scale(0.99); }
.gx-src-play:disabled { opacity: 0.45; cursor: not-allowed; }
.gx-src-play:focus-visible { outline: 2px solid var(--gx-accent-strong); outline-offset: 2px; }

/* ---- in-player compact source selector (header) ---- */
.gx-srcbar { position: relative; flex: none; }
.gx-srcbar.hidden { display: none; }
#source-current {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0.45rem 0.8rem;
  background: var(--gx-glass);
  border: 1px solid var(--gx-border-strong);
  border-radius: var(--gx-radius-pill);
  color: var(--gx-text);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background var(--gx-transition), border-color var(--gx-transition);
  max-width: 12rem;
}
#source-current:hover { background: rgba(255, 255, 255, 0.1); }
#source-current:focus-visible { outline: 2px solid var(--gx-accent); outline-offset: 2px; }
.gx-srcbar-label { font-size: 0.66rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gx-text-faint); }
.gx-srcbar-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gx-srcbar-caret { color: var(--gx-text-dim); font-size: 0.7rem; }
#source-current[aria-expanded="true"] .gx-srcbar-caret { transform: rotate(180deg); }

.gx-src-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 40;
  min-width: 15rem;
  max-width: min(19rem, calc(100vw - 2rem));
  max-height: 50vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.45rem;
  background: var(--gx-glass-strong);
  border: 1px solid var(--gx-border-strong);
  border-radius: var(--gx-radius-pop);
  box-shadow: var(--gx-shadow-pop);
  animation: gx-src-fade 160ms ease;
}
.gx-src-menu.hidden { display: none; }
.gx-src-menu-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.65rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 0.65rem;
  color: var(--gx-text);
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
  transition: background var(--gx-transition), border-color var(--gx-transition);
}
.gx-src-menu-row:hover:not(:disabled) { background: rgba(255, 255, 255, 0.07); border-color: var(--gx-border); }
.gx-src-menu-row.is-selected { background: var(--gx-accent-soft); border-color: var(--gx-accent-border); }
.gx-src-menu-row:disabled { opacity: 0.45; cursor: not-allowed; }
.gx-src-menu-row:focus-visible { outline: 2px solid var(--gx-accent); outline-offset: 1px; }

/* ---- restrained loading pulse (no giant spinner) ---- */
.gx-loading-pulse {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  margin-right: 0.6rem;
  border-radius: 999px;
  background: var(--gx-accent);
  animation: gx-src-pulse 1.2s ease-in-out infinite;
  flex: none;
}

/* ---- mobile: bottom sheet / compact full-width, never overflowing ---- */
@media (max-width: 640px) {
  .gx-src-select { align-items: flex-end; padding: 0; }
  .gx-src-panel {
    max-width: none;
    border-radius: 1rem 1rem 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    padding-bottom: calc(1.1rem + env(safe-area-inset-bottom, 0px));
  }
  .gx-src-list { max-height: 38vh; }
  .gx-src-menu {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    min-width: 0;
    max-width: none;
    max-height: 52vh;
    border-radius: 1rem 1rem 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    padding-bottom: calc(0.6rem + env(safe-area-inset-bottom, 0px));
  }
  #source-current { max-width: 9rem; }
}

@media (prefers-reduced-motion: reduce) {
  .gx-src-select, .gx-src-menu { animation: none; }
  .gx-src-dot-checking, .gx-src-dot-loading, .gx-loading-pulse { animation: none; opacity: 0.85; }
  .gx-src-row, .gx-src-play, #source-current { transition: none; }
}

/* ---- player modal layout fix: viewport-level flex column + stable stage ----
 * Root cause: the video stage (<div class="relative"> wrapping #embed-frame)
 * sized itself solely from the in-flow iframe. When the pre-playback picker
 * hid the iframe (display:none), the stage collapsed to 0 height, so the
 * absolutely-positioned picker (inset:0) collapsed with it — only a thin
 * sliver remained visible at the top. The header also had no positioning
 * context, so the compact source menu competed with the iframe paint order.
 * Fix: #player becomes a viewport flex column; the stage is flex:1 with
 * overflow:hidden (iframe stays clipped, picker lives INSIDE stage bounds);
 * the header is a positioned context above the stage so the menu always
 * paints above the iframe/loading/error layers. */
#player.gx-player {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  overscroll-behavior: contain;
}
#player.gx-player.hidden { display: none; }
.gx-player-head {
  position: relative;
  z-index: 50;
  flex: none;
  overflow: visible;
  background: #000;
}
.gx-player-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #000;
  isolation: isolate;
}
.gx-player-epbar {
  flex: none;
  position: relative;
  z-index: 40;
  background: #000;
}
/* Iframe fills the stable stage (overrides the Tailwind vh calc so the
 * stage — not a fixed viewport subtraction — owns the height). */
#player-stage #embed-frame {
  position: relative;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  background: #000;
}
#player-stage #embed-frame.hidden { display: none; }
/* Stacking inside the stage: iframe < picker < loading < error.
 * The header (z-50) + menu (z-60) sit above all of them. */
#player-stage .gx-src-select { z-index: 20; overscroll-behavior: contain; }
#player-stage #player-loading { z-index: 30; }
#player-stage #player-error { z-index: 35; }
.gx-player-head .gx-srcbar { position: relative; z-index: 1; overflow: visible; }
.gx-player-head .gx-src-menu {
  z-index: 60;
  overflow-y: auto;
  overscroll-behavior: contain;
}
/* Dropdown flip: when there is not enough room below, open upward. */
.gx-src-menu.open-up {
  top: auto;
  bottom: calc(100% + 8px);
}
/* Internal scrolling only — the page itself never becomes the list scroller. */
.gx-src-list, .gx-src-menu { overscroll-behavior: contain; }
#player-stage .gx-src-panel { max-height: 100%; overflow-y: auto; overscroll-behavior: contain; }
/* Viewport-unit hardening (dvh where supported) so laptop/mobile chrome
 * never pushes the menu or list beyond the visible viewport. */
.gx-src-list { max-height: 46vh; max-height: 46dvh; }
.gx-src-menu { max-height: 50vh; max-height: 50dvh; }
@media (max-width: 640px) {
  .gx-src-menu.open-up {
    top: auto;
    bottom: 0;
  }
  .gx-src-list { max-height: 38vh; max-height: 38dvh; }
  .gx-src-menu { max-height: 52vh; max-height: 52dvh; }
}
