:root {
  --bg-primary: #313338;
  --bg-secondary: #2b2d31;
  --bg-tertiary: #1e1f22;
  --bg-card: #18191c;
  --bg-card-overlay: rgba(0, 0, 0, 0.6);
  --bg-input: #1e1f22;
  --bg-hover: #35373c;
  --bg-active: #404249;

  --text-normal: #dbdee1;
  --text-muted: #949ba4;
  --text-header: #f2f3f5;
  --text-link: #00a8fc;

  --brand-color: #5865f2;
  --brand-hover: #4752c4;
  --brand-active: #3c45a5;

  --status-green: #23a55a;
  --status-green-glow: rgba(35, 165, 90, 0.45);
  --status-red: #da373c;
  --status-red-hover: #a12828;
  --status-yellow: #f0b232;
  --status-live: #eb459e;

  --border-subtle: rgba(255, 255, 255, 0.08);
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-tertiary);
  color: var(--text-normal);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  user-select: none;
}

input, button, textarea {
  font-family: inherit;
}

/* ========================================================== */
/* MODAL OVERLAY & JOIN CARD                                  */
/* ========================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.join-card {
  background-color: var(--bg-secondary);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  padding: 32px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  border: 1px solid var(--border-subtle);
  animation: modalIn 0.25s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.join-header {
  text-align: center;
  margin-bottom: 24px;
}

.discord-logo-icon {
  color: var(--brand-color);
  margin-bottom: 12px;
  display: inline-block;
}

.join-header h2 {
  color: var(--text-header);
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 6px;
}

.join-header .subtitle {
  color: var(--text-muted);
  font-size: 14px;
}

.join-form .form-group {
  margin-bottom: 18px;
}

.join-form label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.join-form input[type="text"],
.join-form input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  background-color: var(--bg-input);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-header);
  font-size: 15px;
  outline: none;
  transition: var(--transition);
}

.join-form input:focus {
  border-color: var(--brand-color);
}

.form-preview-toggles {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
  padding: 12px;
  background-color: var(--bg-input);
  border-radius: var(--radius-sm);
}

.toggle-control {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-normal);
}

.toggle-control input[type="checkbox"] {
  accent-color: var(--brand-color);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.alert-error {
  background-color: rgba(218, 55, 60, 0.15);
  border: 1px solid var(--status-red);
  color: #ff7b7f;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  line-height: 1.4;
}

.join-footer {
  margin-top: 20px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

/* ========================================================== */
/* BUTTONS & CONTROLS                                         */
/* ========================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  color: #fff;
}

.btn-primary {
  background-color: var(--brand-color);
}

.btn-primary:hover {
  background-color: var(--brand-hover);
}

.btn-primary:active {
  background-color: var(--brand-active);
}

.btn-danger {
  background-color: var(--status-red);
}

.btn-danger:hover {
  background-color: var(--status-red-hover);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.icon-button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.icon-button:hover {
  background-color: var(--bg-hover);
  color: var(--text-header);
}

.icon-button.active {
  background-color: var(--bg-active);
  color: var(--brand-color);
}

.has-badge-container {
  position: relative;
}

.badge-count {
  position: absolute;
  top: 2px;
  right: 2px;
  background-color: var(--status-red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  border-radius: var(--radius-full);
  padding: 0 4px;
}

/* ========================================================== */
/* MAIN APP LAYOUT                                            */
/* ========================================================== */
.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  background-color: var(--bg-primary);
}

/* HEADER */
.app-header {
  height: 52px;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.channel-icon {
  font-size: 18px;
}

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

.room-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-header);
  line-height: 1.2;
}

.room-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.connection-status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  display: inline-block;
}

.connection-status-dot.online {
  background-color: var(--status-green);
  box-shadow: 0 0 6px var(--status-green);
}

.separator {
  color: var(--text-muted);
  opacity: 0.5;
}

.rtc-badge {
  background-color: rgba(88, 101, 242, 0.15);
  color: #8591ff;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.layout-toggle-group {
  display: flex;
  background-color: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 2px;
}

/* BODY: STAGE + CHAT SIDEBAR */
.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.stage-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 14px;
  overflow: hidden;
  position: relative;
  gap: 12px;
}

/* ========================================================== */
/* VIDEO GRID                                                 */
/* ========================================================== */
.video-grid {
  flex: 1;
  display: grid;
  gap: 12px;
  width: 100%;
  height: 100%;
  align-content: center;
  justify-content: center;
}

/* Responsive grid layout depending on count */
.video-grid[data-count="1"] {
  grid-template-columns: 1fr;
  max-width: 860px;
  max-height: 520px;
  margin: auto;
}

.video-grid[data-count="2"] {
  grid-template-columns: repeat(2, 1fr);
  max-width: 1100px;
  margin: auto;
}

.video-grid[data-count="3"],
.video-grid[data-count="4"] {
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

.video-grid[data-count="5"],
.video-grid[data-count="6"] {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

.video-grid[data-count="7"],
.video-grid[data-count="8"],
.video-grid[data-count="9"] {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
}

.video-grid[data-count="10"] {
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

/* Fallback auto grid */
.video-grid.layout-auto {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

/* USER / STREAM CARD */
.user-card {
  position: relative;
  background-color: var(--bg-card);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  border: 2px solid transparent;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  aspect-ratio: 16 / 9;
  cursor: pointer;
}

.user-card:hover {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
}

/* Speaking pulse ring */
.user-card.is-speaking {
  border-color: var(--status-green) !important;
  box-shadow: 0 0 16px var(--status-green-glow) !important;
}

.card-video-container {
  flex: 1;
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #0b0e14;
}

.card-video-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  inset: 0;
  display: none; /* hidden until active video stream */
}

.card-video-container video.active {
  display: block;
}

/* Fallback avatar when cam is off */
.avatar-fallback {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, #5865f2, #eb459e);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s ease;
}

.user-card.is-speaking .avatar-fallback {
  transform: scale(1.06);
  border: 3px solid var(--status-green);
}

.avatar-letter {
  font-size: 32px;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
}

/* Card bottom overlay info */
.card-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 12px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 2;
}

.user-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  max-width: 70%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-tag {
  color: var(--text-muted);
  font-size: 11px;
}

.status-badges {
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  background-color: rgba(0, 0, 0, 0.6);
  color: #fff;
}

.badge-muted {
  background-color: var(--status-red);
}

.badge-streaming {
  background-color: var(--status-live);
  font-size: 10px;
  font-weight: 700;
  padding: 0 6px;
  width: auto;
  letter-spacing: 0.05em;
}

/* Dedicated Screen Share Tile */
.stream-card {
  border: 2px solid rgba(235, 69, 158, 0.4);
}

.stream-card:hover {
  border-color: var(--status-live);
}

.stream-card .card-video-container video {
  object-fit: contain !important;
  background-color: #000;
}

/* ========================================================== */
/* SPOTLIGHT / THEATER MODE                                   */
/* ========================================================== */
.spotlight-container {
  flex: 3;
  background-color: #000;
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.spotlight-header {
  height: 42px;
  background-color: rgba(20, 20, 20, 0.85);
  backdrop-filter: blur(6px);
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 5;
}

.spotlight-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-header);
}

.live-pill {
  background-color: var(--status-live);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.spotlight-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.spotlight-media-wrapper {
  flex: 1;
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #050608;
}

.spotlight-media-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* In theater mode, video grid becomes a horizontal strip below or side */
.stage-section.theater-active .video-grid {
  flex: 1;
  max-height: 160px;
  display: flex;
  flex-direction: row;
  overflow-x: auto;
  overflow-y: hidden;
  align-items: center;
  justify-content: flex-start;
  padding-bottom: 6px;
}

.stage-section.theater-active .user-card {
  width: 220px;
  height: 130px;
  flex-shrink: 0;
}

/* ========================================================== */
/* SIDEBAR: CHAT & USERS                                      */
/* ========================================================== */
.chat-sidebar {
  width: 320px;
  background-color: var(--bg-secondary);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.25s ease;
}

.chat-sidebar.collapsed {
  display: none;
}

.sidebar-tabs {
  height: 48px;
  display: flex;
  border-bottom: 1px solid var(--border-subtle);
  padding: 6px 10px 0 10px;
  gap: 6px;
}

.tab-button {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  padding: 8px 0;
}

.tab-button:hover {
  color: var(--text-header);
}

.tab-button.active {
  color: var(--text-header);
  border-bottom-color: var(--brand-color);
}

.sidebar-panel {
  flex: 1;
  display: none;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.sidebar-panel.active {
  display: flex;
}

/* CHAT MESSAGES */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}
.chat-messages::-webkit-scrollbar-thumb {
  background-color: var(--bg-tertiary);
  border-radius: 4px;
}

.chat-system-message {
  padding: 10px;
  background-color: rgba(88, 101, 242, 0.1);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  line-height: 1.4;
}

.chat-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: fadeInMsg 0.15s ease-out;
}

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

.chat-item-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.chat-author {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
}

.chat-time {
  font-size: 11px;
  color: var(--text-muted);
}

.chat-text {
  font-size: 14px;
  color: var(--text-normal);
  word-break: break-word;
  line-height: 1.35;
}

.chat-input-bar {
  padding: 12px;
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-input-bar input {
  flex: 1;
  background-color: var(--bg-input);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-header);
  font-size: 14px;
  outline: none;
}

.chat-input-bar input:focus {
  border-color: var(--brand-color);
}

.chat-send-btn {
  background-color: var(--brand-color);
  border: none;
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.chat-send-btn:hover {
  background-color: var(--brand-hover);
}

/* PARTICIPANTS LIST */
.users-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.user-row:hover {
  background-color: var(--bg-hover);
}

.user-row-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-row-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, #5865f2, #99aab5);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  position: relative;
}

.user-row-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-header);
}

.user-row-icons {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
}

/* Volume Slider in Context/Hover */
.user-volume-control {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.volume-slider {
  accent-color: var(--brand-color);
  width: 70px;
  height: 4px;
  cursor: pointer;
}

/* ========================================================== */
/* FOOTER: DISCORD VOICE CONTROLS BAR                        */
/* ========================================================== */
.app-footer {
  height: 64px;
  background-color: var(--bg-tertiary);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  flex-shrink: 0;
  z-index: 10;
}

.footer-user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
}

.footer-avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--brand-color), #23a55a);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
}

.footer-user-details {
  display: flex;
  flex-direction: column;
}

.footer-username {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-header);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.footer-status-text {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.status-indicator-green {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background-color: var(--status-green);
}

/* CENTER VOICE CONTROLS */
.footer-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.control-btn {
  background-color: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-normal);
  width: 48px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.control-btn:hover {
  background-color: var(--bg-hover);
  color: var(--text-header);
}

.control-btn.active-danger {
  background-color: var(--status-red);
  color: #fff;
}

.control-btn.active-live {
  background-color: var(--status-live);
  color: #fff;
}

.control-btn.active-success {
  background-color: var(--status-green);
  color: #fff;
}

.btn-tooltip {
  font-size: 9px;
  margin-top: 2px;
  font-weight: 600;
  opacity: 0.8;
}

.footer-room-status {
  min-width: 180px;
  display: flex;
  justify-content: flex-end;
}

.pill-badge {
  background-color: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .chat-sidebar {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.7);
  }

  .footer-user-profile {
    min-width: auto;
  }
  .footer-room-status {
    display: none;
  }
}

