:root {
  --bg: #0e0f12;
  --panel: #151823;
  --panel-elevated: #1a1b1e;
  --line: #23283b;
  --text: #e8eaf0;
  --text-sub: #9aa3b2;
  --text-muted: #6b7280;
  --brand: #8b5cf6;
  --brand-hover: #7c3aed;
  --accent: #4a9eff;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius-sm: 6px;
  --radius: 12px;
  --transition-fast: 120ms ease;
  --transition: 180ms ease;
  --header-height: 80px;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); overflow: hidden; }

#app { display: grid; grid-template-rows: var(--header-height) 1fr auto; height: 100vh; width: 100vw; }

.header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.header-title { font-size: 18px; font-weight: 600; margin: 0; white-space: nowrap; }
.header-left { display: flex; align-items: center; gap: 12px; }
.header-controls { display: flex; align-items: center; gap: 12px; flex: 1; flex-wrap: wrap; }
.header-right { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; }

.input-group { display: flex; flex-direction: column; gap: 4px; }
.input-group label { font-size: 12px; font-weight: 500; color: var(--text-sub); }
.input-group input, .input-group select {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  min-width: 120px;
}

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 6px;
}

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

.btn-primary:hover {
  background: var(--brand-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--panel-elevated);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--line);
}

.btn-icon {
  padding: 8px;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
}

.mode-switcher {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.mode-btn {
  padding: 6px 12px;
  background: transparent;
  border: none;
  color: var(--text-sub);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 4px;
  transition: all var(--transition-fast);
}

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

.mode-btn:hover:not(.active) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.grid-container {
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

.grid {
  display: grid;
  gap: 16px;
  padding: 16px;
  height: 100%;
  width: 100%;
  place-items: center;
  place-content: center;
}

.grid[data-count="1"] {
  grid-template-columns: 1fr;
  max-width: 800px;
  margin: 0 auto;
}

.grid[data-count="1"] .tile {
  width: 100%;
  max-width: 720px;
  height: 405px;
}

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

.grid[data-count="2"] .tile {
  width: 100%;
  height: 360px;
}

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

.grid[data-count="3"] .tile,
.grid[data-count="4"] .tile {
  width: 100%;
  height: 320px;
}

.grid[data-count="5"],
.grid[data-count="6"],
.grid[data-count="7"],
.grid[data-count="8"],
.grid[data-count="9"] {
  grid-template-columns: repeat(3, 1fr);
  max-width: 1800px;
  margin: 0 auto;
}

.grid[data-count="5"] .tile,
.grid[data-count="6"] .tile,
.grid[data-count="7"] .tile,
.grid[data-count="8"] .tile,
.grid[data-count="9"] .tile {
  width: 100%;
  height: 280px;
}

.grid:not([data-count]) {
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  max-width: 1800px;
  margin: 0 auto;
}

.grid:not([data-count]) .tile {
  width: 100%;
  height: 300px;
}

.tile {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: #1e1f22;
  border: 2px solid transparent;
  transition: border-color 0.15s ease;
  cursor: pointer;
}

.tile.speaking {
  border-color: #23a55a;
  box-shadow: 0 0 0 2px rgba(35, 165, 90, 0.3);
}

.tile:hover {
  border-color: rgba(255, 255, 255, 0.1);
}

.tile > .media {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--bg);
}

.tile.portrait > .media {
  object-fit: contain;
  background: #0b0d12;
}

.tile-label {
  position: absolute;
  bottom: 8px;
  left: 8px;
  right: 8px;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  color: white;
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 0.2s ease;
}

.tile:hover .tile-label {
  opacity: 0.7;
}

#app[data-mode="free"] .tile {
  position: absolute;
  cursor: move;
  max-width: none !important;
  max-height: none !important;
  width: auto;
  height: auto;
}

#app[data-mode="free"] .tile:hover {
  transform: none;
}

#app[data-mode="free"] .grid {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
}

.tile-resize-handle {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  cursor: nwse-resize;
  opacity: 0;
  transition: opacity var(--transition-fast);
  z-index: 30;
}

.tile-resize-handle::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 30%, var(--brand) 30%, var(--brand) 40%, transparent 40%, transparent 60%, var(--brand) 60%, var(--brand) 70%, transparent 70%);
  border-radius: 0 0 var(--radius) 0;
}

.tile:hover .tile-resize-handle {
  opacity: 1;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 12px 20px;
  background: var(--panel-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 10000;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.log-footer {
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 12px;
  max-height: 150px;
  overflow-y: auto;
}

#log {
  margin: 0;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  color: var(--text-sub);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.account-dropdown {
  position: absolute;
  top: 72px;
  right: 16px;
  background: var(--panel-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.5);
  min-width: 300px;
  z-index: 1000;
  animation: slideDown 0.2s ease;
}

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

.account-dropdown-content {
  padding: 16px;
}

.account-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.account-status {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.account-hint {
  font-size: 13px;
  color: var(--text-sub);
  margin: 0;
  line-height: 1.5;
}

.account-info {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
}

.account-avatar {
  background: var(--brand);
  border-radius: 50%;
  padding: 8px;
  flex-shrink: 0;
}

.account-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.account-username {
  font-weight: 600;
  color: var(--text);
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-email {
  font-size: 13px;
  color: var(--text-sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 12px 0;
}

.account-menu-item {
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background var(--transition-fast);
  text-align: left;
}

.account-menu-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.account-menu-item svg {
  flex-shrink: 0;
}

.btn-block {
  width: 100%;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  justify-content: center;
}

/* Danger button */
.btn-danger {
  background: #ef4444;
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

/* Participant Sidebar */
.participant-sidebar {
  position: fixed;
  right: 0;
  top: 80px;
  bottom: 160px;
  width: 280px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transform: translateX(100%);
  transition: transform var(--transition-normal);
}

.participant-sidebar:not([hidden]) {
  transform: translateX(0);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-header h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.participant-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.participant-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 4px;
  transition: background var(--transition-fast);
}

.participant-item:hover {
  background: var(--bg-tertiary);
}

.participant-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

.participant-info {
  flex: 1;
  min-width: 0;
}

.participant-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.participant-status {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.participant-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
}

.participant-indicator.speaking {
  background: var(--speaking-indicator);
  animation: pulse 1s infinite;
}

.participant-indicator.muted {
  background: #ef4444;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Chat Sidebar */
.chat-sidebar {
  position: fixed;
  right: 0;
  top: 80px;
  bottom: 160px;
  width: 320px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transform: translateX(100%);
  transition: transform var(--transition-normal);
}

.chat-sidebar:not([hidden]) {
  transform: translateX(0);
}

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

.chat-message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: slideIn 0.2s ease-out;
}

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

.chat-message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.chat-message-sender {
  font-weight: 600;
  color: var(--brand);
}

.chat-message-sender.self {
  color: var(--success);
}

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

.chat-message-text {
  background: var(--bg-tertiary);
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  max-width: 100%;
}

.chat-message.self .chat-message-text {
  background: var(--brand);
  color: white;
}

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

#chat-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition-fast);
}

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

#chat-send {
  padding: 8px 16px;
  white-space: nowrap;
}

.grid-container.sidebar-open {
  margin-right: 280px;
}

.obs-link-btn {
  padding: 6px 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  margin-left: 8px;
}

.obs-link-btn:hover {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
  transform: translateY(-1px);
}

.obs-link-btn:active {
  transform: translateY(0);
}

.obs-link-btn svg {
  opacity: 0.8;
}

.participant-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 1;
  min-width: 0;
}

.participant-name {
  flex: 1;
  min-width: 0;
}

.position-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: var(--brand);
  color: white;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  margin-right: 8px;
  flex-shrink: 0;
}

.position-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: var(--brand);
  color: white;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  margin-right: 8px;
  flex-shrink: 0;
}

.participant-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.volume-slider {
  width: 80px;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--brand);
  border-radius: 50%;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.volume-slider::-webkit-slider-thumb:hover {
  background: var(--brand-hover);
  transform: scale(1.15);
}

.volume-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--brand);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.volume-slider::-moz-range-thumb:hover {
  background: var(--brand-hover);
  transform: scale(1.15);
}

.volume-slider::-webkit-slider-runnable-track {
  background: var(--bg-tertiary);
  height: 4px;
  border-radius: 2px;
}

.volume-slider::-moz-range-track {
  background: var(--bg-tertiary);
  height: 4px;
  border-radius: 2px;
}

/* Modal Styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal[hidden] {
  display: none;
}

.modal-content {
  background: #1a1a2e;
  border-radius: 12px;
  padding: 24px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h2 {
  margin: 0;
  color: #fff;
  font-size: 1.5rem;
}

.modal-close {
  background: none;
  border: none;
  color: #888;
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: #fff;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  color: #ddd;
  font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group textarea,
.form-control {
  width: 100%;
  padding: 10px;
  background: #0f0f1e;
  border: 1px solid #333;
  border-radius: 6px;
  color: #fff;
  font-size: 14px;
  box-sizing: border-box;
}

.form-control {
  cursor: pointer;
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #4a90e2;
}

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.radio-group label {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  transition: background 0.2s;
}

.radio-group label:hover {
  background: rgba(255, 255, 255, 0.05);
}

.radio-group input[type="radio"] {
  margin-right: 8px;
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* Moderator Panel */
.moderator-panel {
  position: fixed;
  top: 80px;
  right: 20px;
  width: 300px;
  background: #1a1a2e;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  z-index: 900;
}

.moderator-panel[hidden] {
  display: none;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #333;
}

.panel-header h3 {
  margin: 0;
  color: #fff;
  font-size: 1.1rem;
}

.panel-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-actions .btn {
  width: 100%;
  justify-content: flex-start;
}

.hint-text {
  color: #888;
  font-size: 0.85rem;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #333;
}

/* Banned Users Modal */
.banned-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: #0f0f1e;
  border-radius: 6px;
  margin-bottom: 8px;
}

.banned-item:last-child {
  margin-bottom: 0;
}

.banned-item strong {
  color: #fff;
}

.banned-item small {
  color: #888;
}

/* Button variants */
.btn-xs {
  padding: 4px 8px;
  font-size: 11px;
  border-radius: 4px;
}

.btn-warning {
  background: #f59e0b;
  color: #000;
}

.btn-warning:hover {
  background: #d97706;
}

.participant-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

#moderator-toggle {
  background: #7c3aed;
}

#moderator-toggle:hover {
  background: #6d28d9;
}

#moderator-toggle svg {
  margin-right: 6px;
}

/* Room Selection Page */
.page {
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f0f1e 0%, #1a1a2e 100%);
}

.page[hidden] {
  display: none !important;
}

.room-selection-container {
  width: 90%;
  max-width: 1200px;
  background: #1a1a2e;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.selection-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 32px;
  background: #0f0f1e;
  border-bottom: 1px solid #333;
}

.selection-header h1 {
  margin: 0;
  color: #fff;
  font-size: 1.8rem;
}

.room-selection-content {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1.5fr;
  gap: 32px;
  padding: 32px;
}

/* Device Preview Section */
.preview-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.preview-section h3 {
  margin: 0;
  color: #ddd;
  font-size: 1.1rem;
}

.preview-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 16px;
  border: 1px solid var(--border-color);
}

.video-preview-wrapper {
  position: relative;
  width: 100%;
  padding-top: 75%; /* 4:3 aspect ratio */
  background: #000;
  border-radius: 8px;
  overflow: hidden;
}

#preview-video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #666;
}

.preview-placeholder svg {
  opacity: 0.5;
}

.preview-placeholder p {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
}

.preview-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.device-select-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.device-select-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.device-select {
  padding: 8px 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: #ffffff;
  font-size: 14px;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition-fast);
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

.device-select option {
  background: #1a1a2e;
  color: #ffffff;
  padding: 8px;
}

.device-select:hover {
  border-color: var(--brand);
}

.device-select:focus {
  border-color: var(--brand);
}

.preview-buttons {
  display: flex;
  gap: 8px;
}

.preview-buttons .btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
}

.preview-buttons .btn.off {
  background: #ef4444;
  border-color: #ef4444;
}

.preview-buttons .btn.off:hover {
  background: #dc2626;
}

/* Audio Level Indicator */
.audio-level-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 8px;
}

.audio-level-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.audio-level-header label {
  font-weight: 500;
  color: var(--text-secondary);
}

.audio-level-db {
  font-family: 'Courier New', monospace;
  font-weight: 600;
  color: var(--brand);
  min-width: 60px;
  text-align: right;
}

.audio-level-bar {
  height: 12px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border-color);
}

.audio-level-fill {
  height: 100%;
  background: linear-gradient(90deg, #10b981 0%, #22c55e 40%, #fbbf24 70%, #f59e0b 85%, #ef4444 100%);
  width: 0%;
  transition: width 0.05s ease-out;
  border-radius: 4px;
}

/* Audio Controls */
.audio-controls-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
  margin-top: 8px;
}

.audio-control-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.audio-control-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.audio-control-group label span {
  color: var(--brand);
  font-family: 'Courier New', monospace;
  font-weight: 600;
}

.audio-slider {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-tertiary);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.audio-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--brand);
  cursor: pointer;
  border: 2px solid var(--bg-secondary);
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.audio-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--brand);
  cursor: pointer;
  border: 2px solid var(--bg-secondary);
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.audio-slider::-webkit-slider-thumb:hover {
  background: var(--brand-hover);
  transform: scale(1.1);
}

.audio-slider::-moz-range-thumb:hover {
  background: var(--brand-hover);
  transform: scale(1.1);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

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

.ptt-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: #ef4444;
  color: white;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  animation: pulse-ptt 1s infinite;
  margin-top: 4px;
}

.ptt-indicator svg {
  animation: pulse-dot 1s infinite;
}

@keyframes pulse-ptt {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.8; }
}

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

.room-actions {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.btn-large {
  padding: 16px 24px;
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-radius: 8px;
  transition: all 0.2s;
}

.btn-large:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(74, 144, 226, 0.3);
}

.divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: #666;
  margin: 8px 0;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid #333;
}

.divider span {
  padding: 0 16px;
  font-weight: 600;
}

.join-room-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.join-room-form h3 {
  margin: 0 0 8px 0;
  color: #ddd;
  font-size: 1.1rem;
}

.room-input {
  width: 100%;
  padding: 12px 16px;
  background: #0f0f1e;
  border: 2px solid #333;
  border-radius: 8px;
  color: #fff;
  font-size: 1rem;
  transition: border-color 0.2s;
}

.room-input:focus {
  outline: none;
  border-color: #4a90e2;
}

.available-rooms {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.available-rooms h3 {
  margin: 0;
  color: #ddd;
  font-size: 1.2rem;
}

.rooms-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 500px;
  overflow-y: auto;
  padding-right: 8px;
}

.rooms-list::-webkit-scrollbar {
  width: 8px;
}

.rooms-list::-webkit-scrollbar-track {
  background: #0f0f1e;
  border-radius: 4px;
}

.rooms-list::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 4px;
}

.rooms-list::-webkit-scrollbar-thumb:hover {
  background: #444;
}

.room-card {
  background: #0f0f1e;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.room-card:hover {
  border-color: #4a90e2;
  transform: translateX(4px);
}

.room-card-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 8px;
}

.room-card-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: #fff;
  margin: 0;
}

.room-card-participants {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #4a90e2;
  font-size: 0.9rem;
}

.room-card-description {
  color: #aaa;
  font-size: 0.9rem;
  margin: 8px 0;
}

.room-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #222;
  font-size: 0.85rem;
  color: #888;
}

.loading-text {
  text-align: center;
  color: #888;
  padding: 40px;
}

.empty-state {
  text-align: center;
  color: #888;
  padding: 40px;
}

.empty-state svg {
  margin-bottom: 16px;
  opacity: 0.5;
}

@media (max-width: 1400px) {
  .header {
    gap: 8px;
  }
  
  .header-controls {
    gap: 8px;
  }
  
  .header-right {
    gap: 6px;
  }
  
  .btn {
    padding: 6px 10px;
    font-size: 13px;
  }
}

@media (max-width: 1200px) {
  .room-selection-content {
    grid-template-columns: 1fr;
  }
  
  .preview-section {
    order: -1; /* Show preview first on mobile */
  }
  
  .header-title {
    font-size: 16px;
  }
  
  .input-group label {
    font-size: 11px;
  }
  
  .input-group select {
    font-size: 13px;
    min-width: 100px;
    padding: 6px 8px;
  }
}

@media (max-width: 768px) {
  .preview-buttons {
    flex-direction: column;
  }
  
  .preview-buttons .btn {
    width: 100%;
  }
  
  .header {
    padding: 8px 12px;
    gap: 8px;
  }
  
  .header-controls {
    gap: 6px;
  }
  
  .header-right {
    gap: 6px;
  }
  
  .btn {
    padding: 6px 12px;
    font-size: 13px;
  }
  
  .btn-icon {
    width: 36px;
    height: 36px;
  }
  
  .mode-switcher {
    display: none;
  }
}

/* Account Dropdown */
.account-dropdown {
  position: fixed;
  top: 70px;
  right: 20px;
  background: var(--panel-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  min-width: 220px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  z-index: 1000;
}

.account-user-info {
  padding: 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}

.account-divider {
  height: 1px;
  background: var(--line);
  margin: 8px 0;
}

.account-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition-fast);
  text-align: left;
}

.account-menu-item:hover {
  background: var(--panel);
}

.account-menu-item svg {
  opacity: 0.7;
}

.account-menu-item:hover svg {
  opacity: 1;
}

/* Moderator Badge */
.mod-badge {
  display: inline-block;
  background: #8b5cf6;
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: bold;
  margin-right: 4px;
}

.participant-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.participant-controls .btn-xs {
  padding: 4px 6px;
  font-size: 11px;
  min-width: 24px;
}

.btn-primary {
  background: #3b82f6;
  color: white;
}

.btn-primary:hover {
  background: #2563eb;
}

.btn-success {
  background: #10b981;
  color: white;
}

.btn-success:hover {
  background: #059669;
}

/* ================================
   MOBILE RESPONSIVE STYLES
   ================================ */

/* Tablet and below */
@media (max-width: 1024px) {
  .room-selection-container {
    padding: 20px;
  }

  .room-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
  }

  .stage-container {
    padding: 16px;
  }

  .sidebar {
    width: 280px;
  }
}

/* Mobile landscape and below */
@media (max-width: 768px) {
  body {
    font-size: 14px;
  }

  /* Header adjustments */
  .selection-header h1,
  .stage-header h1 {
    font-size: 24px;
  }

  .header-right {
    gap: 8px;
  }

  .btn {
    padding: 8px 16px;
    font-size: 14px;
  }

  .btn-icon {
    width: 36px;
    height: 36px;
  }

  /* Room grid - 2 columns on tablet */
  .room-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .room-card {
    padding: 16px;
  }

  .room-card h3 {
    font-size: 16px;
  }

  /* Stage layout */
  .stage-main {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    max-width: none;
    height: 300px;
    border-right: none;
    border-bottom: 2px solid var(--border-color);
  }

  .content-area {
    width: 100%;
  }

  /* Video grid adjustments */
  .video-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .video-tile video {
    height: 150px;
  }

  /* Controls */
  .controls {
    padding: 12px;
    gap: 8px;
  }

  .control-btn {
    width: 48px;
    height: 48px;
  }

  /* Modals */
  .modal-content {
    width: 90%;
    max-width: none;
    margin: 20px;
  }

  /* Chat */
  .chat-container {
    height: 250px;
  }

  .chat-input input {
    font-size: 14px;
  }

  /* Settings modal */
  .av-settings-content {
    padding: 20px;
  }
}

/* Mobile portrait */
@media (max-width: 480px) {
  /* Typography */
  .selection-header h1,
  .stage-header h1 {
    font-size: 20px;
  }

  /* Room grid - single column on mobile */
  .room-grid {
    grid-template-columns: 1fr;
  }

  /* Header */
  .header-right {
    gap: 4px;
  }

  .btn {
    padding: 6px 12px;
    font-size: 13px;
  }

  .btn-icon {
    width: 32px;
    height: 32px;
  }

  /* Hide text on small buttons, keep icons */
  .btn-icon svg {
    margin: 0;
  }

  /* Stage adjustments */
  .sidebar {
    height: 250px;
  }

  /* Video grid - single column on small mobile */
  .video-grid {
    grid-template-columns: 1fr;
  }

  .video-tile video {
    height: 200px;
  }

  /* Controls - smaller on mobile */
  .controls {
    padding: 10px;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .control-btn {
    width: 44px;
    height: 44px;
  }

  .control-btn svg {
    width: 20px;
    height: 20px;
  }

  /* Modals - full screen on mobile */
  .modal {
    padding: 0;
  }

  .modal-content {
    width: 100%;
    height: 100%;
    margin: 0;
    border-radius: 0;
    max-height: 100vh;
  }

  .modal-header {
    padding: 16px;
  }

  .modal-body {
    padding: 16px;
  }

  /* Forms */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  select,
  textarea {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 12px;
  }

  /* Chat */
  .chat-container {
    height: 200px;
  }

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

  .chat-input {
    padding: 10px;
  }

  /* Account modal */
  .account-info {
    padding: 12px;
  }

  .stat-label,
  .info-label {
    font-size: 12px;
  }

  /* Audio level bar */
  .audio-level-container {
    height: 6px;
  }

  /* Participant list */
  .participant-item {
    padding: 10px;
    font-size: 14px;
  }

  /* Room info */
  .room-info p {
    font-size: 13px;
  }

  /* Settings */
  .setting-group label {
    font-size: 14px;
  }

  .slider {
    height: 6px;
  }

  /* Toast notifications */
  .toast {
    bottom: 80px; /* Above mobile controls */
    left: 10px;
    right: 10px;
    width: auto;
    font-size: 14px;
  }
}

/* Very small screens */
@media (max-width: 360px) {
  .selection-header h1,
  .stage-header h1 {
    font-size: 18px;
  }

  .control-btn {
    width: 40px;
    height: 40px;
  }

  .control-btn svg {
    width: 18px;
    height: 18px;
  }

  .btn {
    padding: 6px 10px;
    font-size: 12px;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  /* Larger touch targets */
  .btn,
  .control-btn,
  .room-card,
  .participant-item {
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(99, 102, 241, 0.1);
  }

  /* Hover states become active states */
  .btn:active,
  .control-btn:active {
    transform: scale(0.95);
  }

  .room-card:active {
    transform: translateY(0);
  }

  /* Remove hover effects that don't work on touch */
  .video-tile:hover .video-overlay {
    opacity: 0;
  }

  .video-tile:active .video-overlay {
    opacity: 1;
  }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
  .sidebar {
    width: 300px;
    height: 100%;
    border-right: 2px solid var(--border-color);
    border-bottom: none;
  }

  .stage-main {
    flex-direction: row;
  }

  .video-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .video-tile video {
    height: 120px;
  }
}

/* PWA viewport adjustments for notches */
@supports (padding: max(0px)) {
  body {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .controls {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}
