* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  /* Disable text selection globally */
  user-select: none;
  /* Disable highlighting on mobile */
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: black;
  color: #eee;
  /* Use dynamic viewport height for mobile browsers */
  /* Disable pinch-zoom and double-tap zoom, but allow single taps */
  touch-action: manipulation; /* Custom viewport height */
  height: 100dvh; /* Dynamic viewport height - newer browsers */
  min-height: 100dvh;
  overflow: hidden;
  /* iOS Safari full-screen optimizations */
  -webkit-overflow-scrolling: touch;
  /* Support iPhone X+ safe areas */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.invisible {
  visibility: hidden;
}

.hidden {
  display: none !important;
}

.initially-hidden {
  visibility: hidden !important;
  pointer-events: none !important;
}

.permission-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 1rem;
  background: #000;
  color: #fff;
}

.error-content {
  max-width: 400px;
  text-align: center;
  padding: 2rem;
  background: rgb(255 255 255 / 5%);
  border-radius: 12px;
  border: 1px solid rgb(255 255 255 / 10%);
}

.error-content h2 {
  margin: 0 0 1rem;
  font-size: 1.4rem;
  font-weight: 500;
  color: #fff;
}

.error-content p {
  margin: 0 0 1rem;
  font-size: 1rem;
  line-height: 1.4;
  color: rgb(255 255 255 / 80%);
}

.error-solutions {
  margin: 1rem 0;
  padding: 1rem;
  background: rgb(255 255 255 / 5%);
  border-radius: 8px;
  text-align: left;
  font-size: 0.9rem;
}

.error-solutions p {
  margin: 0.5rem 0;
}

.error-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.retry-button, .help-button {
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  min-width: 100px;
}

.retry-button {
  background: #007aff;
  color: white;
}

.help-button {
  background: rgb(255 255 255 / 10%);
  color: white;
  border: 1px solid rgb(255 255 255 / 20%);
}

.retry-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (width <= 480px) {
  .error-content {
    padding: 1.5rem;
    margin: 1rem;
  }
  
  .error-content h2 {
    font-size: 1.2rem;
  }
  
  .error-actions {
    flex-direction: column;
  }
  
  .retry-button, .help-button {
    width: 100%;
  }
}

.trove-logout {
  min-height: 16px;
  margin-top: 10px;
}


#ming {
  height: 100vh;
  height: calc(var(--vh, 1vh) * 100); /* Custom viewport height */
  height: 100dvh; /* Dynamic viewport height */
  min-height: 100vh;
  min-height: calc(var(--vh, 1vh) * 100);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  /* Ensure full coverage on iOS */
  width: 100vw;
  max-width: 100vw;
}

/* Trove topic header - displays the current trove topic */
.trove-topic-header {
  flex-shrink: 0;
  padding: 8px 16px;
  background: rgb(255 255 255 / 5%);
  border-bottom: 1px solid rgb(255 255 255 / 10%);
  text-align: center;
  z-index: 100;
}

.trove-topic-title {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: rgb(255 255 255 / 70%);
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

/* Mobile: slightly smaller topic header */
@media (width <= 640px) {
  .trove-topic-header {
    padding: 6px 12px;
  }

  .trove-topic-title {
    font-size: 12px;
  }
}

/* Main content wrapper for horizontal flex layout */
.main-content {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: row;
}

/* Gallery mode: change main-content to column layout for videos + thumbnails */
.main-content.gallery-mode {
  flex-direction: column;
  gap: 4px;
}

.videos-container {
  flex: 1;
  position: relative;
  background: #000;
  overflow: hidden;
  /* Ensure videos container doesn't overlap with button bar */
  padding-bottom: 88px; /* Add padding instead of changing height + 2px for floor border */
  /* Default to block (works before layout runs) - grid classes add flex */
  display: block;
  gap: 4px;
}

/* Gallery mode: videos-container stays as flex:1 child of main-content */
.main-content.gallery-mode .videos-container {
  padding-bottom: 0; /* Remove padding-bottom in gallery mode - thumbnails handle spacing */
}

.video-wrapper {
  position: relative; /* Default to relative for flexbox layouts */
  overflow: hidden;
  background: #1a1a1a;
  border: 1px solid #222;
  box-sizing: border-box;
  /* Don't enable container-type by default - causes collapse before layout runs */
  /* transition: border-color 0.2s ease, box-shadow 0.2s ease; */
}

/* Enable container queries only for multi-person grids (not solo) */
/* Solo video uses absolute positioning which doesn't work with container-type */
.videos-container.grid-2-1 .video-wrapper,
.videos-container.grid-1-2 .video-wrapper,
.videos-container.grid-3-1 .video-wrapper,
.videos-container.grid-1-3 .video-wrapper,
.videos-container.grid-2-2-3p .video-wrapper,
.videos-container.grid-2-2 .video-wrapper,
.videos-container.grid-4-1 .video-wrapper,
.videos-container.grid-1-4 .video-wrapper {
  container-type: size;
}

/* Animation class - applied separately from layout class */
.video-wrapper.animate-in {
  animation: tile-appear 750ms ease-out;
  animation-fill-mode: both;
  /* Make visible when animation starts */
  visibility: visible;
}

/* Focus container animation - same as video tiles for games and screenshare */
#focus-container.focus-appear {
  animation: tile-appear 750ms ease-out;
  animation-fill-mode: both;
}

/* Game container animation within focus area */
#focus-game-container.focus-appear {
  animation: tile-appear 750ms ease-out;
  animation-fill-mode: both;
}


/* Speaking indicators - gray stroke */
.video-wrapper.speaking {
  outline: 2px solid rgb(128 128 128 / 100%);
  outline-offset: -2px;
  box-shadow: 0 0 10px rgb(128 128 128 / 40%);
}

/* Floor control indicator - bright green stroke */
.video-wrapper.has-floor {
  outline: 1px solid rgb(0 255 0 / 100%);
  outline-offset: -1px;
  box-shadow: 0 0 20px rgb(0 255 0 / 70%);
}

/* When both speaking and floor are active - combine effects */
.video-wrapper.speaking.has-floor {
  outline: 1px solid rgb(0 255 0 / 100%);
  outline-offset: -1px;
  box-shadow:
    0 0 10px rgb(128 128 128 / 40%),
    0 0 20px rgb(0 255 0 / 70%);
}

/* 1 participant - full screen */
/* ============================================================================
   FLEXBOX GRID LAYOUTS (1-4 participants)
   ============================================================================ */

/* 1 person - solo fullscreen (keep absolute positioning) */
.videos-container.grid-1-1 {
  display: block;
}

.videos-container.grid-1-1 .video-wrapper {
  position: absolute;
  inset: 0 0 88px; /* Exclude bottom padding (desktop: 88px) */
}

/* Mobile: smaller bottom inset to match mobile padding */
@media (width <= 640px) {
  .videos-container.grid-1-1 .video-wrapper {
    inset: 0 0 76px; /* Match mobile padding-bottom */
  }
}

/* 2 people layouts */
.videos-container.grid-2-1 {
  display: flex;
  flex-direction: row;
}

.videos-container.grid-1-2 {
  display: flex;
  flex-direction: column;
}

.grid-2-1 .video-wrapper,
.grid-1-2 .video-wrapper {
  flex: 1;
  position: relative;
}

/* 3 people layouts */
.videos-container.grid-3-1 {
  display: flex;
  flex-direction: row;
}

.videos-container.grid-1-3 {
  display: flex;
  flex-direction: column;
}

.grid-3-1 .video-wrapper,
.grid-1-3 .video-wrapper {
  flex: 1;
  position: relative;
}

/* 3 people - 2x2 grid with 1 empty (2 on top, 1 on bottom centered) */
.videos-container.grid-2-2-3p {
  display: flex;
  flex-flow: row wrap;
  align-content: flex-start;
}

.grid-2-2-3p .video-wrapper {
  flex: 0 0 calc(50% - 2px);
  position: relative;
}

.grid-2-2-3p .video-wrapper:last-child {
  margin-left: calc(25% + 2px);
}

/* 4 people - 2x2 quad */
.videos-container.grid-2-2 {
  display: flex;
  flex-flow: row wrap;
}

.grid-2-2 .video-wrapper {
  flex: 0 0 calc(50% - 2px);
  position: relative;
}

/* 4 people - 4x1 horizontal line */
.videos-container.grid-4-1 {
  display: flex;
  flex-direction: row;
}

.grid-4-1 .video-wrapper {
  flex: 1;
  position: relative;
}

/* 4 people - 1x4 vertical stack */
.videos-container.grid-1-4 {
  display: flex;
  flex-direction: column;
}

.grid-1-4 .video-wrapper {
  flex: 1;
  position: relative;
}

/* Gallery mode styles - focus container is always visible in gallery mode */
.main-content.gallery-mode .videos-container #focus-container {
  position: relative; /* Flexbox child */
  display: flex !important; /* Override .hidden class */
  align-items: center;
  justify-content: center;
}

/* Focus tile video uses full available space efficiently */
.main-content.gallery-mode .videos-container .video-wrapper.gallery-focus video {
  width: 100%;
  height: 100%;
  object-fit: cover; /* Fill space, crop if needed for optimal use of screen real estate */
}

/* Gallery thumbnails styling - combined selectors */
.main-content.gallery-mode .videos-container .video-wrapper.gallery-thumb {
  /* Position is relative when inside #thumbnail-container (flexbox child) */
  /* Old absolute positioning removed - CSS flexbox handles layout */
  overflow: hidden;
}

/* Square gallery thumbnails with center cropping */
.main-content.gallery-mode .videos-container .video-wrapper.gallery-thumb video {
  width: 100%; /* Fill container width */
  height: 100%; /* Fill container height */
  object-fit: cover; /* Crop to fill container completely */
  object-position: center; /* Center the cropped video */
}

/* Smaller controls ONLY in thumbnail tiles - be more specific */
.main-content.gallery-mode .videos-container .video-wrapper.gallery-thumb .control-btn {
  width: 7px !important; /* 50% smaller buttons */
  height: 7px !important; /* 50% smaller buttons */
  min-width: 7px !important; /* Override mobile min-width */
  font-size: 3px !important; /* Smaller text */
  padding: 0 !important; /* Minimal internal padding */
  margin: 0 !important; /* No margins */
  border-radius: 2px !important; /* Smaller border radius */
}

/* Make sure focus tile buttons stay normal size */
.main-content.gallery-mode .videos-container .video-wrapper.gallery-focus .control-btn {
  width: 48px !important; /* Restore normal size */
  height: 48px !important; /* Restore normal size */
  min-width: 48px !important; /* Restore normal min-width */
  font-size: 18px !important; /* Restore normal font size */
  padding: inherit !important;
  margin: inherit !important;
  border-radius: 8px !important; /* Restore normal border radius */
}

/* Game container - overlays videos-container when active */
/* Height calculation: 100vh - button bar - thumbnail container height */
#focus-game-container {
  position: fixed;
  inset: 0 0 calc(88px + clamp(140px, 20vh, 164px));
  /* Desktop: avoid button bar (88px) + thumbnail height clamp(140px, 20vh, 164px) */
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 24px;
  pointer-events: none;
  z-index: 10;
}

#focus-game-container:not(.hidden) {
  pointer-events: auto;
}

/* Adjust bottom spacing based on peer count to match thumbnail container */
#focus-game-container.peer-count-3 {
  bottom: calc(88px + clamp(120px, 18vh, 164px));
}

#focus-game-container.peer-count-4,
#focus-game-container.peer-count-5 {
  bottom: calc(88px + clamp(110px, 15vh, 164px));
}

#focus-game-container.peer-count-6 {
  bottom: calc(88px + clamp(90px, 12vh, 164px));
}

/* Mobile: button bar is 76px instead of 88px */
@media (width <= 640px) {
  #focus-game-container {
    bottom: calc(76px + clamp(140px, 20vh, 164px));
  }

  #focus-game-container.peer-count-3 {
    bottom: calc(76px + clamp(120px, 18vh, 164px));
  }

  #focus-game-container.peer-count-4,
  #focus-game-container.peer-count-5 {
    bottom: calc(76px + clamp(110px, 15vh, 164px));
  }

  #focus-game-container.peer-count-6 {
    bottom: calc(76px + clamp(90px, 12vh, 164px));
  }
}

/* Gallery mode: game container uses same flex sizing as videos-container */
.main-content.gallery-mode #focus-game-container {
  position: relative; /* Flex child, not fixed */
  flex: 1; /* Same as videos-container - fills available space */
  min-height: 0; /* Allow flex shrinking */
  inset: auto;
}

/* Hide videos-container and show game container when game is active in gallery mode */
.main-content.gallery-mode .videos-container.game-active {
  display: none;
}

.main-content.gallery-mode #focus-game-container.game-active {
  display: block;
}

/* Specific positioning for different button types in thumbnails - keep in corners */
/* Removed legacy .video-controls container in thumbnails (not used) */

.main-content.gallery-mode .videos-container .video-wrapper.gallery-thumb .remote-mute-btn {
  bottom: 2px !important; /* Bottom left corner - closer to edge */
  left: 2px !important;
}

.main-content.gallery-mode .videos-container .video-wrapper.gallery-thumb .reaction-menu-btn {
  top: 2px !important; /* Top left corner - closer to edge */
  left: 2px !important;
  right: auto !important; /* Override right positioning */
}


/* Make icons much smaller in thumbnail tiles */
.main-content.gallery-mode .videos-container .video-wrapper.gallery-thumb .control-btn i,
.main-content.gallery-mode .videos-container .video-wrapper.gallery-thumb .control-btn svg {
  width: 4px !important; /* 50% smaller icons */
  height: 4px !important; /* 50% smaller icons */
}

/* Removed legacy .control-btn-small icon overrides (not used) */

/* Hide captions completely in gallery thumbnails */
.main-content.gallery-mode .videos-container .video-wrapper.gallery-thumb .caption-container {
  display: none !important;
}


/* Ultra-compact resolution display in thumbnail tiles */
/* Hide resolution stats in gallery mode */
.main-content.gallery-mode .videos-container .resolution-debug {
  display: none !important; /* Hide completely in gallery mode */
}

/* More specific selector for gallery thumbnails */
.main-content.gallery-mode .videos-container .video-wrapper .resolution-debug {
  display: none !important;
}

/* Even more specific for thumbnail containers */
.main-content.gallery-mode .videos-container .gallery-thumb .resolution-debug {
  display: none !important;
}

/* Hide age-gender indicators in gallery mode */
.main-content.gallery-mode .videos-container .age-gender-info {
  display: none !important;
}

/* Gallery thumbnail positioning is calculated dynamically in JS */

/* Thumbnail container with responsive height based on peer count */
.main-content.gallery-mode #thumbnail-container {
  position: relative; /* Flexbox child of main-content */
  flex: 0 0 auto; /* Don't grow/shrink, use content height from clamp() */
  width: 100%;
  overflow: auto hidden;
  z-index: 2; /* Lower z-index - should not overlap focus */
  margin-bottom: 88px; /* Space for button bar */

  /* Flexbox layout for thumbnails */
  display: flex !important;
  flex-flow: row nowrap;
  gap: 4px;
  align-items: center;
  justify-content: center;
}

/* Responsive heights based on peer count using clamp() */
#thumbnail-container.peer-count-1,
#thumbnail-container.peer-count-2 {
  height: clamp(140px, 20vh, 164px); /* 2 peers side by side at max */
}

#thumbnail-container.peer-count-3 {
  height: clamp(120px, 18vh, 164px);
}

#thumbnail-container.peer-count-4,
#thumbnail-container.peer-count-5 {
  height: clamp(110px, 15vh, 164px);
}

#thumbnail-container.peer-count-6 {
  height: clamp(90px, 12vh, 164px); /* Smallest for 6 peers */
}

/* Thumbnail wrappers use flexbox for equal distribution */
#thumbnail-container .gallery-thumb {
  position: relative !important; /* Override absolute positioning */
  flex: 1 1 0; /* Equal width distribution, can grow/shrink */
  min-width: 60px; /* Minimum touch target */
  max-width: 164px; /* Max size (allows 2 peers side by side at 160px + gaps) */
  height: 100%; /* Fill container height */
  aspect-ratio: 1/1; /* Keep thumbnails square */
}

/* ============================================================================
   NATIVE HYBRID CROPPING WITH CONTAINER QUERIES
   ============================================================================ */

/* Default: close to square tiles use full cover */
.video-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Hybrid cropping: when tile aspect ratio differs from 1:1 by >10% */
/* Blends 50% between contain (no crop) and cover (full crop) */
@container (aspect-ratio < 0.9) or (aspect-ratio > 1.1) {
  .video-wrapper video {
    --min-dimension: min(100cqw, 100cqh);
    --max-dimension: max(100cqw, 100cqh);
    --hybrid-size: calc((var(--min-dimension) + var(--max-dimension)) / 2);

    width: var(--hybrid-size);
    height: var(--hybrid-size);
    object-fit: cover;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
  }
}

/* Mirror local video (but not when screen sharing) */
.video-wrapper[data-participant="local"]:not(.is-screensharing) video {
  transform: scaleX(-1);
}

/* Combine mirroring with hybrid cropping centering */
@container (aspect-ratio < 0.9) or (aspect-ratio > 1.1) {
  .video-wrapper[data-participant="local"]:not(.is-screensharing) video {
    transform: translate(-50%, -50%) scaleX(-1);
  }
}

/* ============================================================================
   SOLO VIDEO HYBRID CROPPING (viewport-based, no container queries)
   ============================================================================ */

/* Solo video: calculate hybrid crop from viewport dimensions */
.videos-container.grid-1-1 .video-wrapper video {
  --viewport-width: 100vw;
  --viewport-height: calc(100vh - 88px); /* Desktop button bar + padding */
  --viewport-aspect: calc(var(--viewport-width) / var(--viewport-height));

  /* Only apply hybrid if viewport is not square (aspect < 0.9 or > 1.1) */
  /* We'll use a trick: calculate the hybrid size always, but only position absolutely when needed */
  --min-dimension: min(var(--viewport-width), var(--viewport-height));
  --max-dimension: max(var(--viewport-width), var(--viewport-height));
  --hybrid-size: calc((var(--min-dimension) + var(--max-dimension)) / 2);
}

/* Apply hybrid positioning for non-square viewports */
/* Rough approximation: if viewport is < 0.9 or > 1.1 aspect ratio */
@media (aspect-ratio < 9/10) or (aspect-ratio > 11/10) {
  .videos-container.grid-1-1 .video-wrapper video {
    width: var(--hybrid-size);
    height: var(--hybrid-size);
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    object-fit: cover;
  }

  /* Combine with mirroring for local video */
  .videos-container.grid-1-1 .video-wrapper[data-participant="local"]:not(.is-screensharing) video {
    transform: translate(-50%, -50%) scaleX(-1);
  }
}

/* Mobile: adjust for smaller button bar (48px + 28px buffer = 76px) */
@media (width <= 640px) {
  .videos-container.grid-1-1 .video-wrapper video {
    --viewport-height: calc(100vh - 76px);
  }
}

/* Video orientation correction classes for mobile devices */
.video-rotate-0 {
  transform: rotate(0deg);
}

.video-rotate-90 {
  transform: rotate(90deg);
}

.video-rotate-180 {
  transform: rotate(180deg);
}

.video-rotate-270 {
  transform: rotate(270deg);
}

/* Special handling for local video which is already mirrored */
#local-video.video-rotate-0 {
  transform: scaleX(-1) rotate(0deg);
}

#local-video.video-rotate-90 {
  transform: scaleX(-1) rotate(90deg);
}

#local-video.video-rotate-180 {
  transform: scaleX(-1) rotate(180deg);
}

#local-video.video-rotate-270 {
  transform: scaleX(-1) rotate(270deg);
}

/* Override mirroring when screen sharing and rotating */
#local-video.screen-sharing.video-rotate-0 {
  transform: rotate(0deg);
}

#local-video.screen-sharing.video-rotate-90 {
  transform: rotate(90deg);
}

#local-video.screen-sharing.video-rotate-180 {
  transform: rotate(180deg);
}

#local-video.screen-sharing.video-rotate-270 {
  transform: rotate(270deg);
}

/* Enhanced tooltips for control buttons */
.control-btn {
  position: relative;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  
  /* True glass effect - more transparent */
  background: rgb(255 255 255 / 15%) !important;
  backdrop-filter: blur(20px) saturate(180%) !important;
  border: 1px solid rgb(255 255 255 / 40%) !important;
  box-shadow: 0 8px 32px rgb(0 0 0 / 30%), inset 0 1px 0 rgb(255 255 255 / 20%), inset 0 0 20px rgb(0 0 0 / 30%) !important;
  color: #fff !important;
  cursor: pointer;
}

/* Active button states - clean and subtle to let diagonal line icons show */
.control-btn.active {
  background: rgb(100 100 100 / 30%);
  backdrop-filter: blur(14px);
  border-color: rgb(255 255 255 / 40%);
  box-shadow: 0 2px 8px rgb(0 0 0 / 40%);
}

/* Active state hover enhancement - subtle */
.control-btn.active:hover {
  background: rgb(120 120 120 / 40%);
  box-shadow: 0 4px 12px rgb(0 0 0 / 50%);
}

/* Consistent hover effect for all control buttons */
.control-btn:hover {
  background: rgb(255 255 255 / 20%) !important;
  backdrop-filter: blur(20px) saturate(180%) !important;
  border-color: rgb(255 255 255 / 50%) !important;
  box-shadow: 0 6px 24px rgb(255 255 255 / 30%), inset 0 1px 0 rgb(255 255 255 / 30%) !important;
}

.control-btn:active {
  /* Pressed glass effect */
  background: rgb(62 62 62 / 90%);
  backdrop-filter: blur(6px);
  border-color: rgb(255 255 255 / 40%);
  box-shadow: 0 1px 4px rgb(0 0 0 / 20%);
}

.control-btn i,
.control-btn svg {
  width: 20px;
  height: 20px;
  transition: color 0.2s ease, stroke 0.2s ease;
  position: relative;
  z-index: 2;
  filter: drop-shadow(0 1px 2px rgb(0 0 0 / 40%)); /* Subtle dark glow */
}


/* Button-specific active states with colors */
/* Target both <i> and <svg> since Lucide replaces <i> with <svg> */
/* Muted microphone - white diagonal line icon */
#mute-btn.active i,
#mute-btn.active svg {
  color: #fff !important;
  stroke: #fff !important;
}

/* Disabled video - white diagonal line icon */
#video-btn.active i,
#video-btn.active svg {
  color: #fff !important;
  stroke: #fff !important;
}

#menu-btn.active i,
#menu-btn.active svg,
.reaction-menu-btn.active i,
.reaction-menu-btn.active svg {
  color: #fa0 !important; /* Yellow when an effect is active */
  stroke: #fa0 !important;
}

/* Popup portal container - holds menus that need to escape stacking contexts */
.popup-portal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none; /* Allow clicks through to underlying content */
  z-index: 10000; /* Very high z-index to appear above everything */
}

/* Portal-based menus can receive pointer events */
.popup-portal .reaction-menu {
  pointer-events: auto;
}

/* Position reaction menu buttons within video containers */
.reaction-menu-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  z-index: 60;
}

.remote-mute-btn {  
  position: absolute;
  bottom: 8px;
  left: 8px;
  z-index: 60;
}

.remote-mute-btn i, 
.remote-mute-btn svg, 
.reaction-menu-btn i,
.reaction-menu-btn svg {
  color: #fff !important;
  stroke: #fff !important;
  width: 20px;
  height: 20px;
  transition: color 0.2s ease, stroke 0.2s ease;
  position: relative;
  z-index: 2;
  filter: drop-shadow(0 1px 2px rgb(0 0 0 / 40%)); /* Subtle dark glow */
} 

/* Reaction menu button - matches remote-mute button size and styling */
.reaction-menu-btn, 
.remote-mute-btn {
  width: 32px !important;
  height: 32px !important;
  min-width: 32px !important;
  max-width: 32px !important;
  font-size: 14px;
  padding: 0 !important;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 2px;
}

.remote-mute-btn.active {
  /* Muted state - no background, just red icon */
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

.remote-mute-btn.active i,
.remote-mute-btn.active svg {
  color: #f44 !important;
  stroke: #f44 !important;
}

.reaction-menu-btn:hover,
.reaction-menu-btn:active {
  background: transparent !important;
  backdrop-filter: none !important;
  border: none !important;
  box-shadow: none !important;
  transform: none !important;
}


/* Reaction menu dropdown - container-based portal positioning */
.reaction-menu-portal {
  /* Container will be positioned via JavaScript as flex container */
  position: fixed;
  /* Will have top/left/right/bottom and align-items/justify-content set dynamically */

  /* The menu content itself */
  background: rgb(255 255 255 / 15%);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgb(255 255 255 / 40%);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgb(0 0 0 / 30%), inset 0 1px 0 rgb(255 255 255 / 20%), inset 0 0 20px rgb(0 0 0 / 30%);
  padding: 8px;

  /* Internal layout for menu options */
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 120px;
  width: fit-content;
  height: fit-content;
}

.reaction-menu.hidden {
  display: none;
}

/* Reaction menu options inherit menu-option styles but with consistent spacing */
.reaction-option {
  /* Uses existing .menu-option styles */
}

/* Warning labels */
.warning-label {
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: bold;
  color: #fff;
  background: rgb(0 0 0 / 70%);
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgb(0 0 0 / 80%);
  pointer-events: none;
}


/* Mobile responsive styles for new layout */
@media (width <= 768px) {
  /* Mobile styles for shuffle button now covered by .reaction-menu-btn */

  /* Removed legacy .video-controls mobile styles (container not used) */

  /* On narrow screens, reduce side margins for captions to account for smaller buttons */
  .caption-container {
    width: calc(100% - 72px) !important; /* Reserve 36px on each side for 28px buttons + margin */
  }

  #local-video .caption-container {
    width: calc(100% - 72px) !important;
  }
  
}

.waveform {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 180px; /* Increased height for better visibility */
  pointer-events: none;
  opacity: 0.8;
  display: none; /* Hidden by default, show when video is off */
}

.waveform.show-when-video-off {
  display: block;
}


/* Caption display styles - centered between buttons with proper spacing */
.caption-container {
  position: absolute;
  bottom: 50px; /* Position above button area with spacing */
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 88px); /* Reserve 44px on each side for buttons (32px + 12px margin) */
  max-width: 420px;
  height: 60px;
  /* No background - transparent */
  background: none;
  backdrop-filter: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  justify-content: center;
  z-index: 70; /* Above buttons (z-index: 60) to prevent collision on small screens */
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none; /* Disable by default to avoid blocking buttons */
  cursor: pointer;
}

/* Local caption container - same positioning as remote */
#local-video .caption-container {
  position: absolute;
  bottom: 50px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 88px);
  max-width: 420px;
  height: 60px;
  text-align: center;
}

.caption-container.visible {
  opacity: 1;
  pointer-events: auto; /* Enable touch events only when caption is visible */
}

.caption-line {
  font-size: 18px; /* Bigger text */
  font-weight: 600; /* Bolder weight */
  color: #fff;
  text-align: center;
  line-height: 1.1; /* Tighter line spacing */
  padding: 0 12px;
  max-height: 20px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Hard drop shadow */
  text-shadow: 
    2px 2px 4px rgb(0 0 0 / 90%),
    1px 1px 2px rgb(0 0 0 / 100%),
    0 0 6px rgb(0 0 0 / 80%);
}

.caption-top {
  /* Remove visible line separator and adjust vertical alignment */
  padding-bottom: 0;
  margin-bottom: 2px;
}

.caption-bottom {
  padding-top: 0;
}

/* Remote video caption positioning - avoid remote-mute button */
.video-wrapper:not([data-participant="local"]) .caption-container {
  /* Position in bottom right area, away from remote-mute button */
  bottom: 8px;
  left: 60px; /* Start after remote-mute button (32px + margin) */
  right: 8px; /* Align to right edge */
  transform: none; /* Remove center transform */
  width: auto;
  max-width: none;
  height: 50px; /* Slightly smaller for remote videos */
  text-align: right; /* Right-align text to avoid button overlap */
}

/* Local video caption centered, avoiding control buttons */
.video-wrapper[data-participant="local"] .caption-container {
  bottom: 8px;
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  width: calc(100% - 200px); /* Reserve space for control buttons (160px) + margin */
  max-width: 420px;
  height: 50px;
  text-align: center;
  padding-right: 0;
}

/* When video is off but audio is on - caption moves above waveform */
.video-wrapper .waveform.show-when-video-off ~ .caption-container {
  bottom: 220px; /* Position above the waveform (which is 180px + gap) */
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  width: calc(100% - 16px);
  max-width: 520px; /* Use more width when video is off */
  height: 60px;
}

/* Mobile caption adjustments */
@media (width <= 768px) {
  /* Mobile local video captions */
  .video-wrapper[data-participant="local"] .caption-container {
    bottom: 6px;
    left: 120px; /* Start after mobile control buttons */
    right: 0; /* Right against tile edge */
    height: 45px;
    max-width: none; /* Use full available space */
    text-align: right;
    padding-right: 6px; /* Internal padding instead of margin */
  }
  
  /* Mobile remote video captions */
  .video-wrapper:not([data-participant="local"]) .caption-container {
    bottom: 6px;
    left: 50px; /* Start after mobile remote-mute button (28px + margin) */
    right: 6px; /* Align to right edge */
    height: 45px;
    text-align: right; /* Right-align text on mobile too */
  }
  
  /* Mobile: When video is off but audio is on */
  .video-wrapper .waveform.show-when-video-off ~ .caption-container {
    bottom: 200px; /* Position above the waveform on mobile */
    max-width: 420px;
  }
  
  .caption-line {
    font-size: 12px;
    max-height: 16px;
  }
}

/* Small to large iPhone screens - center captions to avoid button collision */
@media (width <= 640px) {
  .video-wrapper[data-participant="local"] .caption-container,
  .video-wrapper:not([data-participant="local"]) .caption-container {
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    width: calc(100% - 40px) !important;
    max-width: 280px !important;
    text-align: center !important;
  }
}

.controls {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  z-index: 100;
  background: rgb(0 0 0 / 80%);
  padding: 10px;
  border-radius: 8px;
  backdrop-filter: blur(10px);
}

/* Duplicate .control-btn definition removed - using glassmorphism version above */

#menu-btn {
  position: relative;
  overflow: visible; /* Allow tooltip to show outside button bounds */
}

/* Menu button uses consistent hover pattern */
#menu-btn:hover {
  background: rgb(255 255 255 / 20%) !important;
  backdrop-filter: blur(20px) saturate(180%) !important;
  border-color: rgb(255 255 255 / 50%) !important;
  box-shadow: 0 6px 24px rgb(255 255 255 / 30%), inset 0 1px 0 rgb(255 255 255 / 30%) !important;
}

/* Menu container for proper positioning */
.menu-container {
  position: relative;
  display: inline-block;
}

/* Video effects menu dropdown */
.video-menu {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 8px;
  background: rgb(255 255 255 / 15%);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgb(255 255 255 / 40%);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgb(0 0 0 / 30%), inset 0 1px 0 rgb(255 255 255 / 20%), inset 0 0 20px rgb(0 0 0 / 30%);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 120px;
  z-index: 1000;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.video-menu.hidden {
  display: none;
}

/* Menu sections for organizing effects */
.menu-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.menu-section:not(:last-child) {
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgb(255 255 255 / 20%);
}

.menu-section-header {
  font-size: 10px;
  font-weight: 600;
  color: rgb(255 255 255 / 70%);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 4px 4px;
  margin-bottom: 2px;
}

.menu-option {
  background: rgb(255 255 255 / 10%);
  border: 1px solid rgb(255 255 255 / 20%);
  border-radius: 8px;
  color: white;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
  text-align: left;
  white-space: nowrap;
}

.menu-option.subtle {
  background: rgb(255 255 255 / 5%);
  border-style: dashed;
  color: rgb(255 255 255 / 70%);
}

.menu-option:hover {
  background: rgb(255 255 255 / 20%);
  border-color: rgb(255 255 255 / 40%);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 10%), 0 0 0 1px rgb(255 255 255 / 10%);
}

.menu-option.subtle:hover {
  background: rgb(255 255 255 / 12%);
  border-color: rgb(255 255 255 / 32%);
}

.menu-option.active {
  background: rgb(255 170 0 / 30%);
  border-color: rgb(255 170 0 / 50%);
  color: #fa0;
}

.menu-option i,
.menu-option svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.menu-option span {
  flex-grow: 1;
}

@keyframes pulse {
  0%, 100% {
    opacity: 0.8;
  }

  50% {
    opacity: 1;
  }
}

/* Scale-up animation for video tiles - prevents FOUC and adds fun entrance effect */
@keyframes tile-appear {
  from {
    transform: scale(0.01);
    opacity: 0;
  }

  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* Delayed animation for peers joining existing troves */
.video-wrapper.delayed-animation {
  animation: tile-appear-delayed 750ms ease-out;
  animation-fill-mode: both;
  animation-delay: 500ms;
}

@keyframes tile-appear-delayed {
  from {
    transform: scale(0.01);
    opacity: 0;
  }

  to {
    transform: scale(1);
    opacity: 1;
  }
}

@media (width <= 768px) {
  .controls {
    bottom: 10px;
    padding: 8px;
    gap: 5px;
  }

  .waveform {
    height: 40px;
  }
}

/* Mobile button bar - shorter height for small touch devices only
   IMPORTANT: This 640px breakpoint must match the JavaScript breakpoint
   in utils.js (window.innerWidth <= 640) for consistent layout calculations */
@media (width <= 640px) {
  .button-bar {
    height: 48px;
  }

  .videos-container {
    padding-bottom: 76px; /* Increased to prevent grid cutoff (48px button bar + 28px clearance) */
  }

  /* Remove the upward transform on mobile for better centering */
  .button-bar-btn {
    transform: translateY(0); /* Remove the -3px upward nudge on mobile */
  }
}

/* ====================================================================
   JOIN TROVE BUTTON STYLES
   ==================================================================== */

/* Join Trove button - centered and large */
.join-trove-button {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: auto;
  padding: 16px 32px;
  border-radius: 12px;
  background: rgb(255 255 255 / 10%);
  backdrop-filter: blur(12px);
  border: 1px solid rgb(255 255 255 / 20%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 18px;
  font-weight: 500;
  z-index: 2000;
  box-shadow: 0 8px 32px rgb(0 0 0 / 30%);
}

.join-trove-button:hover {
  background: rgb(255 255 255 / 20%);
  border-color: rgb(255 255 255 / 40%);
  box-shadow:
    0 0 20px rgb(255 255 255 / 20%),
    0 12px 40px rgb(0 0 0 / 40%);
  transform: translate(-50%, -50%) scale(1.05);
}

.join-trove-button.active {
  background: rgb(255 255 255 / 30%);
  transform: translate(-50%, -50%) scale(0.95);
}

.join-trove-button i {
  font-size: 20px;
}

/* ====================================================================
   BUTTON BAR STYLES
   ==================================================================== */

/* Fixed button bar at bottom of screen */
.button-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 74px;
  background: #000;
  display: flex;
  align-items: center;
  z-index: 10000; /* Very high z-index to ensure it's always on top, above all other elements */
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  box-shadow: 0 -2px 8px rgb(0 0 0 / 30%);
  /* Ensure button bar doesn't cover video content */
  pointer-events: auto;
}

/* Button bar layout sections */
.button-bar-left {
  flex: 0 0 auto;
  padding-left: 12px;  /* Reduced from 16px to save space on mobile */
  display: flex;
  gap: 6px;  /* Reduced from 8px */
  align-items: center;
}

.button-bar-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;  /* Reduced from 16px */
}

.button-bar-right {
  flex: 0 0 auto;
  padding-right: 12px;  /* Reduced from 16px to save space on mobile */
  display: flex;
  gap: 6px;  /* Reduced from 8px */
  align-items: center;
}

/* Button bar buttons - no transparency since background is solid black */
.button-bar-btn {
  position: relative;
  width: 44px;  /* Meets Apple's 44px minimum for touch targets */
  height: 44px;
  min-width: 44px;  /* Prevent shrinking */
  min-height: 44px;
  border-radius: 6px;
  background: rgb(255 255 255 / 10%);
  color: #fff;
  display: flex;
  align-items: center;
  transform: translateY(-3px); /* Nudge buttons up by 3px */
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
  border: 1px solid rgb(255 255 255 / 20%);

  /* Touch optimization */
  touch-action: manipulation; /* Prevents double-tap zoom delay on mobile */
  -webkit-tap-highlight-color: transparent; /* Remove iOS tap highlight flash */
  user-select: none; /* Prevent text selection on long press */
}

/* Button bar button hover - white glow */
.button-bar-btn:hover {
  background: rgb(255 255 255 / 20%);
  border-color: rgb(255 255 255 / 40%);
  box-shadow: 0 0 12px rgb(255 255 255 / 30%);
}

/* Button bar button active press state */
.button-bar-btn:active {
  background: rgb(255 255 255 / 30%);
  transform: scale(0.95);
}

/* Button bar button focus state for keyboard navigation */
.button-bar-btn:focus-visible {
  background: rgb(255 255 255 / 20%);
  outline: 2px solid rgb(255 255 255 / 60%);
  outline-offset: 2px;
}

/* Toggle button active states - RED background when activated */
.button-bar-btn.toggle-btn.active {
  background: rgb(255 68 68 / 80%) !important;
  border-color: rgb(255 100 100 / 90%) !important;
  box-shadow: 0 0 16px rgb(255 68 68 / 40%) !important;
}

.button-bar-btn.toggle-btn.active:hover {
  background: rgb(255 68 68 / 90%) !important;
  box-shadow: 0 0 20px rgb(255 68 68 / 60%) !important;
}

/* Local gallery button active state - BLUE background when activated */
#local-gallery-btn.active {
  background: rgb(68 150 255 / 80%) !important;
  border-color: rgb(100 170 255 / 90%) !important;
  box-shadow: 0 0 16px rgb(68 150 255 / 40%) !important;
}

#local-gallery-btn.active:hover {
  background: rgb(68 150 255 / 90%) !important;
  box-shadow: 0 0 20px rgb(68 150 255 / 60%) !important;
}

/* Button bar button icons */
.button-bar-btn i,
.button-bar-btn svg {
  width: 16px;
  height: 16px;
  position: relative;
  z-index: 2;
}

/* Videos container padding merged with main rule above */

/* Menu container positioning in button bar */
.button-bar .menu-container {
  position: relative;
}

/* ====================================================================
   ENHANCED REMOTE BUTTON STYLES
   ==================================================================== */

/* Remote buttons - no hover/active effects, transparent backgrounds */
.reaction-menu-btn:hover,
.remote-mute-btn:hover,
.reaction-menu-btn:active,
.remote-mute-btn:active {
  background: transparent !important;
  backdrop-filter: none !important;
  border: none !important;
  box-shadow: none !important;
  transform: none !important;
}

/* Reconnection status indicator */
.reconnect-status {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgb(255 255 255 / 10%);
  backdrop-filter: blur(10px);
  border: 1px solid rgb(255 255 255 / 20%);
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  z-index: 1000;
  text-align: center;
  box-shadow: 0 8px 32px rgb(0 0 0 / 30%);
  display: none;
  max-width: 90vw;
  overflow-wrap: break-word;
}

.reconnect-status.connecting {
  color: #ffd700;
  border-color: rgb(255 215 0 / 30%);
  background: rgb(255 215 0 / 10%);
}

.reconnect-status.failed {
  color: #ff6b6b;
  border-color: rgb(255 107 107 / 30%);
  background: rgb(255 107 107 / 10%);
}

@media (width <= 768px) {
  .reconnect-status {
    top: 10px;
    font-size: 12px;
    padding: 8px 16px;
  }
}

/* Age and Gender info display - hidden, shown in stats dialog instead */
.age-gender-info {
  display: none !important;
}

/* Gallery view adjustments */
/* Removed legacy .gallery-view adjustments (class not used) */

/* Resolution debug display */
.resolution-debug {
  position: absolute;
  top: 10px;
  right: 10px;
  color: white;
  font-size: 8px;
  font-weight: 400;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  z-index: 15;
  user-select: none;
  text-shadow: 1px 1px 2px rgb(0 0 0 / 80%);
  cursor: default;
}

/* Hidden by default, controlled by debug mode */
.resolution-debug.debug-hidden {
  display: none;
}

/* Quality limitation indicator */
.resolution-debug[data-quality-limitation]:not([data-quality-limitation="none"]) {
  color: #fc0;
  background: rgb(255 204 0 / 10%);
  border-radius: 3px;
  padding: 2px 4px;
}

/* Age/gender positioning merged with main rule above */

/* Mobile adjustments for resolution display */
@media (width <= 768px) {
  .resolution-debug {
    top: 8px;
    right: 8px;
  }
  
  .age-gender-info {
    top: 24px !important;
  }
}

/* Stats Dialog Styles */
.stats-dialog {
  border: none;
  border-radius: 12px;
  background: rgb(0 0 0 / 90%);
  backdrop-filter: blur(20px) saturate(180%);
  color: white;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 12px;
  max-width: 90vw;
  max-height: 80vh;
  padding: 0;
  box-shadow: 0 8px 32px rgb(0 0 0 / 60%);
  
  /* Center the dialog */
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
}

.stats-dialog::backdrop {
  background: rgb(0 0 0 / 50%);
  backdrop-filter: blur(4px);
}

.stats-dialog-content {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stats-dialog pre {
  white-space: pre-wrap;
  overflow-wrap: break-word;
  margin: 0;
  font-family: inherit;
  font-size: inherit;
  line-height: 1.4;
  max-height: 60vh;
  overflow-y: auto;
  /* Enable text selection in dialog */
  user-select: text;
}

.stats-dialog-close {
  padding: 10px 20px;
  background: rgb(255 255 255 / 10%);
  border: 1px solid rgb(255 255 255 / 20%);
  border-radius: 8px;
  color: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  align-self: flex-end;
}

.stats-dialog-close:hover {
  background: rgb(255 255 255 / 20%);
  border-color: rgb(255 255 255 / 30%);
  transform: translateY(-1px);
}

@media (width <= 768px) {
  .stats-dialog {
    max-width: 95vw;
    max-height: 85vh;
    font-size: 11px;
  }

  .stats-dialog-content {
    padding: 16px;
  }

  .stats-dialog-close {
    padding: 12px 16px;
    font-size: 16px;
    align-self: stretch;
  }
}

/* Debug Dialog Styles */
.debug-dialog {
  border: none;
  border-radius: 12px;
  background: rgb(0 0 0 / 90%);
  backdrop-filter: blur(20px) saturate(180%);
  color: white;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  max-width: 600px;
  width: 90vw;
  max-height: 90vh;
  padding: 0;
  box-shadow: 0 8px 32px rgb(0 0 0 / 60%);
  z-index: 10001; /* Higher than button bar (10000) */

  /* Center the dialog */
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
}

.debug-dialog::backdrop {
  background: rgb(0 0 0 / 50%);
  backdrop-filter: blur(4px);
}

.debug-dialog-content {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.debug-dialog-header {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: rgb(255 255 255 / 90%);
  border-bottom: 1px solid rgb(255 255 255 / 20%);
  padding-bottom: 12px;
}

.debug-controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.debug-checkbox-label {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 12px;
  border-radius: 8px;
  background: rgb(255 255 255 / 5%);
  border: 1px solid rgb(255 255 255 / 10%);
  transition: all 0.2s ease;
}

.debug-checkbox-label:hover {
  background: rgb(255 255 255 / 10%);
  border-color: rgb(255 255 255 / 20%);
}

.debug-checkbox {
  width: 20px;
  height: 20px;
  cursor: pointer;
  appearance: none;
  background: rgb(255 255 255 / 10%);
  border: 2px solid rgb(255 255 255 / 30%);
  border-radius: 4px;
  position: relative;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.debug-checkbox:checked {
  background: rgb(59 130 246 / 80%);
  border-color: rgb(59 130 246 / 100%);
}

.debug-checkbox:checked::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 14px;
  font-weight: bold;
}

.debug-checkbox-text {
  font-size: 14px;
  font-weight: 500;
  color: rgb(255 255 255 / 85%);
  user-select: none;
}

.debug-message-log {
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: rgb(255 255 255 / 5%);
  border: 1px solid rgb(255 255 255 / 15%);
  border-radius: 8px;
  padding: 16px;
  max-height: 300px;
}

.debug-message-log-header {
  font-size: 14px;
  font-weight: 600;
  color: rgb(255 255 255 / 70%);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.debug-message-log-content {
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 11px;
  line-height: 1.5;
  color: rgb(255 255 255 / 80%);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  margin: 0;
  max-height: 200px;
  overflow-y: auto;
  padding: 8px;
  background: rgb(0 0 0 / 30%);
  border-radius: 4px;
  /* Enable text selection in log */
  user-select: text;
}

.debug-message-log-content::-webkit-scrollbar {
  width: 6px;
}

.debug-message-log-content::-webkit-scrollbar-track {
  background: rgb(255 255 255 / 5%);
  border-radius: 3px;
}

.debug-message-log-content::-webkit-scrollbar-thumb {
  background: rgb(255 255 255 / 20%);
  border-radius: 3px;
}

.debug-message-log-content::-webkit-scrollbar-thumb:hover {
  background: rgb(255 255 255 / 30%);
}

.debug-clear-log-btn {
  padding: 8px 16px;
  background: rgb(255 255 255 / 10%);
  border: 1px solid rgb(255 255 255 / 20%);
  border-radius: 6px;
  color: white;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  align-self: flex-start;
}

.debug-clear-log-btn:hover {
  background: rgb(255 255 255 / 20%);
  border-color: rgb(255 255 255 / 30%);
}

.debug-dialog-close {
  padding: 12px 24px;
  background: rgb(255 255 255 / 10%);
  border: 1px solid rgb(255 255 255 / 20%);
  border-radius: 8px;
  color: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  align-self: flex-end;
}

.debug-dialog-close:hover {
  background: rgb(255 255 255 / 20%);
  border-color: rgb(255 255 255 / 30%);
  transform: translateY(-1px);
}

@media (width <= 768px) {
  .debug-dialog {
    max-width: 95vw;
    max-height: 90vh;
    font-size: 13px;
  }

  .debug-dialog-content {
    padding: 20px;
  }

  .debug-dialog-close {
    padding: 14px 20px;
    font-size: 16px;
    align-self: stretch;
  }
}

/* Peer Recovery Indicator */
.recovery-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 72px;
  z-index: 9999;
  pointer-events: none;
  background: rgb(255 255 255 / 90%);
  border-radius: 50%;
  width: 100px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: hourglass-rotate 4s ease-in-out infinite;
  text-shadow: 0 0 10px rgb(0 0 0 / 80%);
  box-shadow: 0 4px 16px rgb(0 0 0 / 30%);
}

.recovery-indicator::before {
  content: '⏳';
  animation: hourglass-flip 2s steps(1) infinite;
}

@keyframes hourglass-rotate {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  50% { transform: translate(-50%, -50%) rotate(180deg); }
  100% { transform: translate(-50%, -50%) rotate(180deg); }
}

@keyframes hourglass-flip {
  0%, 49% { content: '⏳'; }
  50%, 100% { content: '⌛'; }
}

/* Video Pause Indicator */
.video-pause-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  background: rgb(0 0 0 / 80%);
  border-radius: 50%;
  border: 2px solid rgb(255 255 255 / 30%);
  z-index: 100;
  pointer-events: none;
}

.video-pause-indicator i,
.video-pause-indicator svg {
  width: 36px;
  height: 36px;
  color: rgb(255 255 255 / 90%);
}

/* ====================================================================
   CHAT SIDEBAR STYLES
   ==================================================================== */

.chat-sidebar {
  flex: 0 0 0;
  min-width: 0;
  max-width: 0;
  height: calc(100% - 74px);
  overflow: hidden;
  transition: all 0.3s ease;
  background: rgb(0 0 0 / 85%);
  backdrop-filter: blur(20px);
  border-left: 1px solid rgb(255 255 255 / 20%);
}

.chat-sidebar.open {
  flex: 0 0 20%;
  min-width: 300px;
  max-width: 400px;
}

/* Chat resize handle */
.chat-resize-handle {
  position: absolute;
  left: 0;
  top: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  background: transparent;
  z-index: 20;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.chat-resize-handle:hover {
  opacity: 1;
  background: rgb(255 255 255 / 20%);
}

.chat-resize-handle:active {
  opacity: 1;
  background: rgb(255 255 255 / 30%);
}

/* Only show resize handle on desktop when chat is open */
@media (width >= 769px) {
  .chat-sidebar.open .chat-resize-handle {
    display: block;
  }

  .chat-sidebar:not(.open) .chat-resize-handle {
    display: none;
  }
}

/* Hide resize handle on mobile */
@media (width <= 768px) {
  .chat-resize-handle {
    display: none;
  }
}

/* Mobile overlay for closing chat (only on mobile) */
.chat-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgb(0 0 0 / 50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 10;
}

/* Only enable overlay on mobile devices */
@media (width <= 768px) {
  .chat-sidebar.open .chat-overlay {
    opacity: 1;
    pointer-events: auto;
  }
}

/* Chat content container */
.chat-content {
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Mobile adjustments */
@media (width <= 768px) {
  .chat-sidebar.open {
    flex: 0 0 100%;
    position: fixed;
    top: 0;
    right: 0;
    z-index: 1000;
  }
}

/* Chat header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgb(255 255 255 / 15%);
  flex-shrink: 0;
}

.chat-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: rgb(255 255 255 / 90%);
}

.chat-close-btn {
  background: rgb(255 255 255 / 10%);
  border: 1px solid rgb(255 255 255 / 20%);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chat-close-btn:hover {
  background: rgb(255 255 255 / 20%);
  border-color: rgb(255 255 255 / 30%);
}

.chat-close-btn i,
.chat-close-btn svg {
  width: 18px;
  height: 18px;
  color: rgb(255 255 255 / 80%);
}

/* Messages container */
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow: hidden auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Custom scrollbar for chat messages */
.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
  background: rgb(255 255 255 / 5%);
  border-radius: 2px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgb(255 255 255 / 20%);
  border-radius: 2px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgb(255 255 255 / 30%);
}

/* Chat message styling */
.chat-message {
  display: flex;
  width: 100%;
}

.chat-message.local {
  justify-content: flex-end;
}

.chat-message.remote {
  justify-content: flex-start;
}

/* Chat bubble */
.chat-bubble {
  max-width: 85%;
  background: rgb(255 255 255 / 10%);
  backdrop-filter: blur(10px);
  border: 1px solid rgb(255 255 255 / 15%);
  border-radius: 16px;
  padding: 12px 16px;
  overflow-wrap: break-word;
}

.chat-message.local .chat-bubble {
  background: rgb(59 130 246 / 20%);
  border-color: rgb(59 130 246 / 30%);
}

.chat-message.remote .chat-bubble {
  background: rgb(255 255 255 / 8%);
  border-color: rgb(255 255 255 / 12%);
}

/* Bubble header */
.chat-bubble-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  gap: 12px;
}

.chat-peer-label {
  font-size: 12px;
  font-weight: 600;
  color: rgb(255 255 255 / 70%);
}

.chat-message.local .chat-peer-label {
  color: rgb(147 197 253 / 80%);
}

.chat-timestamp {
  font-size: 11px;
  color: rgb(255 255 255 / 50%);
  font-variant-numeric: tabular-nums;
}

/* Message text */
.chat-message-text {
  font-size: 14px;
  line-height: 1.4;
  color: rgb(255 255 255 / 85%);
  white-space: pre-wrap;
}

/* Chat links */
.chat-link {
  color: #4a9eff;
  text-decoration: underline;
  cursor: pointer;
  transition: color 0.2s ease;
}

.chat-link:hover {
  color: #68b4ff;
  text-decoration: underline;
}

.chat-link:visited {
  color: #9d7fff;
}

.chat-link:active {
  color: #2d8cff;
}

/* Chat footer and input styling */
.chat-footer {
  flex-shrink: 0;
  padding: 16px;
  border-top: 1px solid rgb(255 255 255 / 15%);
  background: rgb(0 0 0 / 20%);
}

.chat-input-container {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-input {
  flex: 1;
  padding: 10px 16px;
  background: rgb(255 255 255 / 10%);
  border: 1px solid rgb(255 255 255 / 20%);
  border-radius: 20px;
  color: rgb(255 255 255 / 90%);
  font-size: 14px;
  font-family: inherit;
  backdrop-filter: blur(10px);
  transition: all 0.2s ease;
}

.chat-input:focus {
  outline: none;
  border-color: rgb(255 255 255 / 40%);
  background: rgb(255 255 255 / 15%);
}

.chat-input::placeholder {
  color: rgb(255 255 255 / 50%);
}

.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgb(255 255 255 / 10%);
  border: 1px solid rgb(255 255 255 / 20%);
  color: rgb(255 255 255 / 90%);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(10px);
}

.chat-send-btn:hover {
  background: rgb(255 255 255 / 20%);
  border-color: rgb(255 255 255 / 30%);
}

.chat-send-btn:active {
  transform: scale(0.95);
}

.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-send-btn i {
  width: 16px;
  height: 16px;
}

/* Message type icons */
.message-type-icon {
  margin-right: 6px;
  opacity: 0.7;
  font-size: 12px;
}


/* Mobile adjustments */
@media (width <= 768px) {
  .chat-header {
    padding: 14px 16px;
  }

  .chat-messages {
    padding: 12px;
  }

  .chat-bubble {
    max-width: 90%;
    padding: 10px 14px;
  }

  .chat-message-text {
    font-size: 13px;
  }

  .chat-footer {
    padding: 12px;
  }

  .chat-input {
    padding: 8px 14px;
    font-size: 16px; /* Prevents zoom on iOS */
  }

  .chat-send-btn {
    width: 36px;
    height: 36px;
  }
}
