:root {
  --gap: 2px;
}
html,
body {
  height: 100%;
  margin: 0;
  font-family: system-ui, Segoe UI, Roboto, Helvetica, Arial;
}
.popup-body {
  background: #0f1113; /* very dark grey */
  color: #e6eef8;
}
/* ensure positioning context for absolute children */
.popup-body {
  position: relative;
  height: 100%;
  overflow: hidden;
}
.controls {
  padding: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* hidden top bar: translate up when hidden */
.controls.hidden {
  transform: translateY(-100%);
  transition: transform 220ms ease-in-out;
  position: fixed; /* fix to viewport so it always overlays */
  left: 0;
  right: 0;
  top: 0;
  width: 100%;
  z-index: 9999; /* ensure it's above iframe overlays */
  background: rgba(0, 0, 0, 0.28); /* thin translucent background */
  backdrop-filter: blur(6px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}
.controls.visible {
  transform: translateY(0);
  transition: transform 220ms ease-in-out;
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  width: 100%;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

#grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: var(--gap);
  padding: 0;
  box-sizing: border-box;
}
#grid .cell {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
  border: 1px solid #2b2b2b;
}
#grid .cell .frame-controls {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: flex;
  gap: 6px;
  align-items: center;
  z-index: 30; /* above overlays */
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none; /* enabled on visible only */
}
#grid .cell .frame-left-controls {
  position: absolute;
  left: 8px;
  bottom: 8px;
  display: flex;
  gap: 6px;
  align-items: center;
  z-index: 30;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}
#grid .cell:not(.interaction-locked):hover .frame-controls,
#grid .cell.show-controls .frame-controls {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
#grid .cell:not(.interaction-locked):hover .frame-left-controls,
#grid .cell.show-controls .frame-left-controls {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.frame-btn {
  background: rgba(0, 0, 0, 0.5);
  color: #e6eef8;
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}
.frame-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

/* selected stream label shown next to the select button */
.selected-label {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  color: #e6eef8;
}
.selected-label .selected-tag {
  padding: 4px 6px;
  border-radius: 6px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}
.selected-label .selected-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0.9;
}

/* Fullscreen expanded state for a single cell. We animate with transforms to keep it smooth. */
.cell.expanded {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 8000; /* keep below topbar (9999) so topbar stays accessible */
  border-radius: 0;
  transition: transform 560ms ease-in-out, width 560ms ease-in-out,
    height 560ms ease-in-out, left 560ms ease-in-out, top 560ms ease-in-out;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}
/* ensure internal iframe fills the expanded cell */
.cell.expanded iframe {
  width: 100% !important;
  height: 100% !important;
}
#grid .cell iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  position: relative;
  z-index: 1;
}
/* placeholder used to reserve grid space while a cell is expanded */
.cell-placeholder {
  box-sizing: border-box;
  display: block;
  width: 100%;
  height: 100%;
  visibility: hidden;
}
#grid .mute-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* interaction overlay sits above iframe and can capture events when enabled */
.cell .interaction-overlay {
  position: absolute;
  inset: 0;
  background: transparent;
  z-index: 10;
  display: none;
}
.cell .interaction-overlay.enabled {
  display: block;
  pointer-events: all;
}
/* Stream selector styles */
.stream-select-btn {
  position: absolute;
  left: 8px;
  top: 8px;
  z-index: 20;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.5);
  color: #e6eef8;
  cursor: pointer;
  font-size: 12px;
}

/* subtle bottom gradient to improve contrast for controls placed at bottom-left/right */
.cell::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 72px; /* matches control area height */
  pointer-events: none;
  background: linear-gradient(
    180deg,
    rgba(15, 17, 19, 0) 0%,
    rgba(15, 17, 19, 0.48) 60%,
    rgba(15, 17, 19, 0.85) 100%
  );
  border-radius: 0 0 6px 6px;
  z-index: 12; /* above iframe but below control buttons (z-index 30) */
  opacity: 0;
  transition: opacity 180ms ease;
}

/* show gradient only when controls are visible (hover or .show-controls) */
.cell:not(.interaction-locked):hover::before,
.cell.show-controls::before {
  opacity: 1;
}

.stream-dropdown {
  /* positioned by JS to attach to the left controls and grow upward */
  z-index: 12000; /* above everything */
  display: inline-flex; /* size to content (widest child) and allow items to stretch */
  flex-direction: column;
  min-width: 220px;
  max-height: 320px;
  overflow: auto;
  background: #0b0c0d;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
  padding: 6px;
  transform-origin: bottom left;
}
.stream-item {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  border-radius: 6px;
  background: transparent;
  color: #e6eef8;
  border: 0;
  text-align: left;
  cursor: pointer;
  white-space: nowrap; /* keep items on one line */
  width: 100%; /* stretch to dropdown width */
  box-sizing: border-box;
}
.stream-item:hover {
  background: rgba(255, 255, 255, 0.03);
}
.stream-tag {
  display: inline-block;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.95);
}
.stream-title {
  flex: 1;
  font-size: 13px;
}
#audio-controls {
  display: flex;
  gap: 6px;
}
.audio-btn {
  padding: 6px 8px;
  border-radius: 4px;
  border: 1px solid #444;
  background: #151719;
  color: #e6eef8;
  cursor: pointer;
}
.audio-btn.active {
  background: #0366d6;
  color: white;
  border-color: #0366d6;
}

/* border highlight for active audio frame */
.cell.active-audio {
  border-color: rgba(255, 0, 0, 1);
}

/* overlay inset border that sits above the iframe */
.cell.active-audio::after {
  content: "";
  position: absolute;
  inset: 1px; /* inset so border doesn't get clipped by rounded corners */
  border: 1px solid rgba(255, 0, 0, 0.95);
  border-radius: 4px;
  pointer-events: none;
  z-index: 5; /* above iframe which has z-index:1 */
}

/* when expanded, hide the active-audio visual chrome so it doesn't overlay fullscreen */
.cell.expanded.active-audio {
  border-color: transparent !important;
}
.cell.expanded.active-audio::after {
  display: none !important;
}
