/* Portrait TV guide bottom-sheet snaps — never cover all video */
.buffer-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.28);
  pointer-events: none;
}
.buffer-overlay.show {
  display: flex;
}
/* Soft chip: background HLS recovery while frames are already on screen */
.buffer-overlay.soft {
  inset: auto;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  flex-direction: row;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(12, 14, 18, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.buffer-overlay.soft .buffer-spinner {
  width: 16px;
  height: 16px;
  border-width: 2px;
  box-shadow: none;
}
.buffer-overlay.soft .buffer-status {
  font-size: 12px;
  font-weight: 600;
}
.buffer-spinner {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: #3b82f6;
  animation: sdBufferSpin 0.75s linear infinite;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}
.buffer-status {
  font: 600 13px/1.3 system-ui, -apple-system, sans-serif;
  color: rgba(255, 255, 255, 0.88);
  letter-spacing: 0.02em;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.55);
}
@keyframes sdBufferSpin {
  to { transform: rotate(360deg); }
}

/* Keep guide rows clear of fixed install / guest toasts on tall phones */
@media (orientation: portrait) and (max-width: 900px),
       (orientation: landscape) and (max-height: 560px) {
  body.sd-install-visible .tv-root:not(.guide-collapsed) .epg-panel,
  body.sd-guest-banner-visible .tv-root:not(.guide-collapsed) .epg-panel {
    scroll-padding-bottom: 88px;
  }
}

.guide-sheet-handle {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  height: 22px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  /* Above channel-row scroll; below modals / embed reclaim */
  position: relative;
  z-index: 3;
  pointer-events: auto;
}
.guide-sheet-handle:active { cursor: grabbing; }
.guide-sheet-grip {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.28);
}
.guide-sheet-handle:hover .guide-sheet-grip,
.guide-sheet-handle:focus-visible .guide-sheet-grip {
  background: rgba(255, 255, 255, 0.48);
}

/* Phone sheet: portrait phones + short landscape (S21/S23 landscape) */
@media (orientation: portrait) and (max-width: 900px),
       (orientation: landscape) and (max-height: 560px) {
  .tv-root {
    --guide-video-min: 32vh;
    --guide-sheet-h: 45vh;
    --guide-sheet-peek: 26vh;
    --guide-sheet-mid: 45vh;
    --guide-sheet-expanded: 62vh;
  }

  /* Landscape phones: keep a usable video strip while guide is open */
  @media (orientation: landscape) {
    .tv-root {
      --guide-video-min: 28vh;
      --guide-sheet-peek: 30vh;
      --guide-sheet-mid: 42vh;
      --guide-sheet-expanded: 55vh;
      --guide-sheet-h: 42vh;
    }
  }

  .tv-root:not(.guide-collapsed) .video-area {
    flex: 1 1 auto;
    min-height: var(--guide-video-min);
  }

  .tv-root:not(.guide-collapsed) .epg-panel {
    flex: 0 0 var(--guide-sheet-h);
    max-height: min(var(--guide-sheet-h), calc(100% - var(--guide-video-min)));
    min-height: 0;
  }

  .tv-root.guide-sheet-dragging:not(.guide-collapsed) .epg-panel {
    transition: none;
  }

  .tv-root:not(.guide-collapsed) .guide-sheet-handle {
    display: flex;
  }

  .tv-root[data-guide-snap="peek"] { --guide-sheet-h: var(--guide-sheet-peek); }
  .tv-root[data-guide-snap="mid"] { --guide-sheet-h: var(--guide-sheet-mid); }
  .tv-root[data-guide-snap="expanded"] { --guide-sheet-h: var(--guide-sheet-expanded); }
}

/* Desktop / tall landscape tablets: free --epg-h resize via same grabber */
@media (min-width: 901px) and (min-height: 561px) {
  .tv-root {
    --guide-video-min: 28vh;
  }
  .tv-root:not(.guide-collapsed) .guide-sheet-handle {
    display: flex !important;
    height: 14px;
    border-bottom: 1px solid rgba(255,255,255,.06);
    background: linear-gradient(180deg, rgba(255,255,255,.04), transparent);
  }
  .tv-root:not(.guide-collapsed) .guide-sheet-grip {
    width: 48px;
    height: 3px;
  }
  .tv-root:not(.guide-collapsed) .video-area {
    flex: 1 1 auto;
    min-height: var(--guide-video-min);
  }
  .tv-root.guide-epg-dragging:not(.guide-collapsed) .epg-panel {
    transition: none;
  }
}
