/* ==========================================================
   StreamPulse Design System - 9:16 Immersive Vertical Live
   TikTok / Instagram Live / MeetMe Aesthetic
   ========================================================== */

:root {
  --bg-base: #07090e;
  --bg-surface: #0e111a;
  --bg-card: rgba(18, 22, 34, 0.7);
  --bg-glass: rgba(18, 22, 34, 0.55);
  
  --border-subtle: rgba(255, 255, 255, 0.1);
  --border-hover: rgba(168, 85, 247, 0.45);
  
  --accent-purple: #8b5cf6;
  --accent-purple-glow: rgba(139, 92, 246, 0.35);
  --accent-cyan: #06b6d4;
  --accent-cyan-glow: rgba(6, 182, 212, 0.35);
  --accent-red: #ef4444;
  --accent-red-glow: rgba(239, 68, 68, 0.4);
  --accent-green: #22c55e;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  line-height: 1.5;
}

/* Glassmorphism */
.glass-panel {
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}

.glass-nav {
  background: rgba(10, 12, 20, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 50;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  text-decoration: none;
  touch-action: manipulation;
}

.btn-primary {
  background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
  color: #fff;
  box-shadow: 0 4px 15px var(--accent-purple-glow);
}
.btn-primary:active {
  transform: scale(0.97);
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
  color: #fff;
  box-shadow: 0 4px 15px var(--accent-red-glow);
}
.btn-danger:active {
  transform: scale(0.97);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}
.btn-secondary:active {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(0.97);
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-icon:hover {
  background: rgba(0, 0, 0, 0.65);
  transform: scale(1.05);
}
.btn-icon:active {
  transform: scale(0.92);
}

/* Badges */
.badge-live {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.6);
  padding: 3px 8px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border-radius: 9999px;
}
.badge-live::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--accent-red);
  box-shadow: 0 0 8px var(--accent-red);
  animation: pulse-dot 1.4s infinite cubic-bezier(0.4, 0, 0.6, 1);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.75); }
}

.badge-offline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-muted);
  border: 1px solid rgba(148, 163, 184, 0.25);
  padding: 3px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  border-radius: 9999px;
}

/* Input Form Controls */
.input-control {
  width: 100%;
  background: rgba(15, 17, 24, 0.85);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 1rem;
  outline: none;
  transition: all 0.2s ease;
  min-height: 44px;
}
.input-control:focus {
  border-color: var(--accent-purple);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
}

/* Pills scroll wrapper */
.pills-scroll-wrapper {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.pills-scroll-wrapper::-webkit-scrollbar {
  display: none;
}
.pill {
  padding: 7px 16px;
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  white-space: nowrap;
  flex-shrink: 0;
  user-select: none;
}
.pill.active {
  background: rgba(139, 92, 246, 0.25);
  color: #c4b5fd;
  border-color: rgba(139, 92, 246, 0.45);
}

/* ==========================================================
   IMMERSIVE 9:16 VERTICAL STAGE & FULLSCREEN LOCK
   ========================================================== */

/* Main 9:16 Vertical Screen Container: Mathematically locked to strict 9:16 aspect ratio */
.vertical-stream-container {
  position: relative;
  aspect-ratio: 9 / 16;
  width: min(calc(100vw - 24px), calc((100vh - 100px) * 9 / 16), 460px);
  height: calc(min(calc(100vw - 24px), calc((100vh - 100px) * 9 / 16), 460px) * 16 / 9);
  margin: 0 auto;
  background: #000;
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.95), 0 0 35px rgba(139, 92, 246, 0.15);
  border: 1px solid var(--border-subtle);
  user-select: none;
}

/* Fullscreen on Desktop/Mobile: Locks 9:16 ratio in center with cinema pillarboxes */
.vertical-stream-container:fullscreen,
.vertical-stream-container:-webkit-full-screen {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  background: #000 !important;
  width: 100vw !important;
  height: 100vh !important;
  max-width: 100vw !important;
  max-height: 100vh !important;
  border: none !important;
  border-radius: 0 !important;
  overflow: hidden !important;
  box-shadow: none !important;
}

/* Inner Frame containing the 9:16 viewport */
.stream-inner-frame {
  position: relative;
  width: 100%;
  height: 100%;
  aspect-ratio: 9 / 16;
  overflow: hidden;
  border-radius: inherit;
  background: #000;
}

.vertical-stream-container:fullscreen .stream-inner-frame,
.vertical-stream-container:-webkit-full-screen .stream-inner-frame {
  position: relative !important;
  height: 100vh !important;
  width: calc(100vh * 9 / 16) !important;
  max-width: 100vw !important;
  aspect-ratio: 9 / 16 !important;
  margin: 0 auto !important;
  overflow: hidden !important;
  background: #000 !important;
}

/* If video element is made fullscreen directly, enforce 9:16 letterboxing */
video:fullscreen,
video:-webkit-full-screen {
  object-fit: cover !important;
  background: #000 !important;
}

/* Fullscreen Backdrop on Widescreen Monitors */
::backdrop {
  background-color: #030407;
}

/* Video Canvas: ALWAYS fills entire 9:16 frame top-to-bottom, edge-to-edge */
.vertical-video-element {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  background: #000;
  display: block;
  z-index: 1;
}

/* Scrim Gradient Overlays */
.scrim-top {
  position: absolute;
  top: 0;
  inset-inline: 0;
  height: 130px;
  background: linear-gradient(180deg, rgba(0,0,0,0.75) 0%, rgba(0,0,0,0.3) 60%, transparent 100%);
  pointer-events: none;
  z-index: 10;
}

.scrim-bottom {
  position: absolute;
  bottom: 0;
  inset-inline: 0;
  height: 240px;
  background: linear-gradient(0deg, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.45) 50%, transparent 100%);
  pointer-events: none;
  z-index: 10;
}

/* Top Floating Header (Streamer Profile & Controls) */
.stream-overlay-top {
  position: absolute;
  top: 14px;
  inset-inline: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 20;
}

.broadcaster-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 4px 12px 4px 4px;
  border-radius: 9999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.broadcaster-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #8b5cf6, #06b6d4);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.95rem;
  color: #fff;
  overflow: hidden;
  flex-shrink: 0;
}
.broadcaster-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.broadcaster-info {
  display: flex;
  flex-direction: column;
}

.broadcaster-name {
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
  line-height: 1.2;
}

.broadcaster-topic {
  font-size: 0.68rem;
  color: #cbd5e1;
}

.top-stats-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
}

.viewer-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 5px 10px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

/* ==========================================================
   FLOATING OVERLAY CHAT (TikTok / Instagram Live Style)
   ========================================================== */
.stream-overlay-chat {
  position: absolute;
  bottom: 74px;
  left: 12px;
  right: 68px;
  max-height: 250px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 20;
  pointer-events: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  mask-image: linear-gradient(to top, black 85%, transparent 100%);
  -webkit-mask-image: linear-gradient(to top, black 85%, transparent 100%);
}
.stream-overlay-chat::-webkit-scrollbar {
  display: none;
}

.chat-bubble {
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 6px 12px;
  font-size: 0.82rem;
  color: #fff;
  width: fit-content;
  max-width: 90%;
  line-height: 1.35;
  word-break: break-word;
  animation: chatSlideIn 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

@keyframes chatSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-bubble-user {
  font-weight: 700;
  color: #c4b5fd;
  margin-right: 6px;
}
.chat-bubble-broadcaster {
  background: #8b5cf6;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 4px;
  margin-right: 6px;
  text-transform: uppercase;
}

/* Bottom Floating Input Bar */
.stream-overlay-bottom {
  position: absolute;
  bottom: 14px;
  inset-inline: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 20;
  padding-bottom: env(safe-area-inset-bottom);
}

.chat-floating-form {
  flex: 1;
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 9999px;
  padding: 4px 6px 4px 14px;
  transition: all 0.2s ease;
}
.chat-floating-form:focus-within {
  border-color: var(--accent-purple);
  box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.35);
}

.chat-floating-input {
  flex: 1;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 0.875rem;
  outline: none;
  font-family: inherit;
}
.chat-floating-input::placeholder {
  color: rgba(255, 255, 255, 0.55);
}

.chat-send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-purple);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}
.chat-send-btn:active {
  transform: scale(0.9);
}

/* Side Action Button Cluster (Right Rail) */
.stream-action-rail {
  position: absolute;
  right: 12px;
  bottom: 74px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 25;
}

.rail-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.rail-icon-wrapper {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, background 0.15s ease;
}
.rail-btn:hover .rail-icon-wrapper {
  transform: scale(1.1);
  background: rgba(0, 0, 0, 0.7);
}
.rail-btn:active .rail-icon-wrapper {
  transform: scale(0.88);
}
.rail-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

/* Floating Hearts FX (TikTok/Instagram style) */
.heart-particle {
  position: absolute;
  right: 22px;
  bottom: 80px;
  font-size: 26px;
  pointer-events: none;
  z-index: 30;
  animation: floatUp 1.8s ease-out forwards;
}

@keyframes floatUp {
  0% {
    opacity: 1;
    transform: translateY(0) scale(0.8) rotate(0deg);
  }
  50% {
    opacity: 0.9;
    transform: translateY(-120px) scale(1.2) rotate(15deg);
  }
  100% {
    opacity: 0;
    transform: translateY(-240px) scale(0.9) rotate(-15deg);
  }
}

/* Avatar Selection & Upload Styles */
.avatar-upload-box {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  margin-bottom: 16px;
}
.avatar-preview-lg {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #8b5cf6, #06b6d4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 800;
  color: #fff;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
}
.avatar-preview-lg img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-presets-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.avatar-preset-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.avatar-preset-btn:hover {
  transform: scale(1.15);
  border-color: #fff;
}

/* Discovery Grid Cards (9:16 Vertical) */
.streams-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 36px;
}

.stream-card {
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
  display: flex;
  flex-direction: column;
  position: relative;
}
.stream-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-hover);
  box-shadow: 0 14px 28px -8px rgba(139, 92, 246, 0.35);
}

.thumb-wrapper {
  position: relative;
  aspect-ratio: 9 / 16;
  width: 100%;
  background: #0f121d;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.thumb-gradient {
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, #1e1b4b 0%, #090a10 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}
.modal-dialog {
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  background: #121522;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-xl);
  padding: 24px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
}

/* Video Loading Overlay */
.video-loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(7, 9, 14, 0.88);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 15;
  color: var(--text-primary);
  text-align: center;
  padding: 20px;
}
.spinner-ring {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(139, 92, 246, 0.2);
  border-top-color: var(--accent-purple);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .vertical-stream-container {
    max-width: 100% !important;
    height: calc(100dvh - 65px) !important;
    max-height: calc(100dvh - 65px) !important;
    aspect-ratio: 9 / 16 !important;
    border-radius: 0 !important;
    border-left: none !important;
    border-right: none !important;
  }

  .streams-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px !important;
  }

  .stream-overlay-chat {
    max-height: 180px !important;
  }
}

/* User Profile Nav Button */
.user-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  padding: 4px 12px 4px 6px;
  border-radius: 9999px;
  cursor: pointer;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.2s ease;
  text-decoration: none;
}
.user-nav-btn:hover {
  background: rgba(139, 92, 246, 0.22);
  border-color: rgba(139, 92, 246, 0.45);
  transform: translateY(-1px);
}
.user-nav-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.72rem;
  color: #fff;
  flex-shrink: 0;
}
.user-nav-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ==========================================================
   IMMERSIVE FULL-SCREEN BROADCASTING MODE
   ========================================================== */

/* Circular End Stream 'X' Button on top-right of stream overlay */
.btn-close-stream {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}
.btn-close-stream:hover {
  background: rgba(239, 68, 68, 0.9);
  border-color: #ef4444;
  transform: scale(1.1);
  box-shadow: 0 4px 16px rgba(239, 68, 68, 0.5);
}

/* When the broadcaster goes live: remove top bar, whole screen is the stream */
body.is-broadcasting #studio-top-nav {
  display: none !important;
}

body.is-broadcasting main {
  padding: 0 !important;
  margin: 0 !important;
  height: 100vh !important;
  height: 100dvh !important;
  width: 100vw !important;
  max-width: 100vw !important;
}

body.is-broadcasting .vertical-stream-container {
  height: 100vh !important;
  height: 100dvh !important;
  max-height: 100vh !important;
  max-height: 100dvh !important;
  width: calc(100vh * 9 / 16) !important;
  width: calc(100dvh * 9 / 16) !important;
  max-width: 100vw !important;
  border-radius: 0 !important;
  border: none !important;
  box-shadow: none !important;
}

@media (max-width: 768px) {
  body.is-broadcasting .vertical-stream-container {
    width: 100% !important;
    height: 100vh !important;
    height: 100dvh !important;
  }
}

body.is-broadcasting #btn-go-live {
  display: none !important;
}

body.is-broadcasting #btn-end-stream-x {
  display: flex !important;
}


