:root {
  /* Color Palette - Consistent with Conductor */
  --bg-page: #101014;
  --bg-sidebar: #18181c;
  --bg-header: #1c1c22;
  --bg-surface: #25252b;
  --bg-input: #2f2f36;
  --bg-card: #1e1e24;

  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;

  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --border: #3f3f46;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -2px rgb(0 0 0 / 0.05);

  --font-family: 'Inter', system-ui, -apple-system, sans-serif;
  --radius: 8px;
}

/* Global */
html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg-page);
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

* {
  box-sizing: border-box;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-page);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #52525b;
}

/* Header */
header {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 15px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 1.2rem;
  color: #ffffff;
  /* Explicit white */
}

.logo {
  height: 40px;
  width: auto;
}

/* Status Dot */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--text-muted);
  /* Default: offline/connecting */
  display: inline-block;
}

.status-dot.connected {
  background-color: var(--success);
  box-shadow: 0 0 5px var(--success);
}

.status-dot.disconnected {
  background-color: var(--danger);
}

/* Modal / Popup */
.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
}

.modal-content {
  background-color: var(--bg-surface);
  margin: 15% auto;
  padding: 20px;
  border: 1px solid var(--border);
  width: 90%;
  max-width: 400px;
  border-radius: 8px;
  text-align: center;
  position: relative;
}

.close-modal {
  color: #aaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  position: absolute;
  right: 15px;
  top: 10px;
}

.close-modal:hover,
.close-modal:focus {
  color: #fff;
  text-decoration: none;
  cursor: pointer;
}

.qr-container {
  margin: 20px 0;
  background: white;
  padding: 10px;
  border-radius: 8px;
  display: inline-block;
}

.qr-container img {
  width: 150px;
  height: 150px;
}

.link-container {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

#share-link-input {
  flex: 1;
  padding: 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-main);
  font-family: monospace;
}

/* Start Overlay */
#start-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(5px);
}

.overlay-content {
  text-align: center;
}

.overlay-content h1 {
  margin-bottom: 10px;
  font-size: 2rem;
}

.btn-large {
  font-size: 1.2rem;
  padding: 12px 24px;
  margin-top: 20px;
}

.host-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.peer-id-display {
  font-family: monospace;
  background: var(--bg-input);
  padding: 6px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  color: var(--success);
  cursor: pointer;
  transition: all 0.2s;
}

.peer-id-display:hover {
  border-color: var(--success);
  background: rgba(34, 197, 94, 0.1);
}

/* Main Layout */
.main-container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.name-input-large {
  font-size: 1.2rem;
  padding: 10px;
  border-radius: 4px;
  border: 1px solid #ccc;
  margin: 15px 0;
  width: 80%;
  max-width: 300px;
  text-align: center;
}

/* Grid Area - Horizontal Layout */
#grid-container {
  flex: 1;
  padding: 10px;
  overflow-y: auto;
  display: flex;
  flex-flow: row wrap;
  /* Horizontal wrapping */
  align-content: center;
  justify-content: center;
  /* Center items */
  gap: 15px;
}

/* User Card */
.user-card {
  background: var(--bg-surface);
  border-radius: 8px;
  padding: 8px;
  /* Compact padding */
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: relative;
  transition: box-shadow 0.2s;
  /* Removed transform */
  min-height: auto;
  /* Allow auto height */
  flex: 1 1 300px;
  /* Responsive width */
  max-width: 400px;
  /* limit width */
}

.user-card:hover {
  /* transform removed */
  box-shadow: var(--shadow-md);
  border-color: #52525b;
}

.user-card.local {
  background: var(--bg-surface);
  /* Reset background */
  border: 2px solid #6366f1;
  /* Purple outline */
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.25);
  /* Subtle glow */
}

/* ... */

/* VU Meter */
.vu-meter-container {
  flex: 1;
  background: #000;
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  border: none;
  /* No border as requested "black rectangle" */
  min-height: 24px;
  /* Drastically reduced */
  max-height: 40px;
}

canvas.vu-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Device Controls */
.device-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
}

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

.control-group label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Buttons */
.btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.2s;
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-secondary {
  background: #4b5563;
  /* Lighter gray for visibility */
  color: #fff;
  border: 1px solid #6b7280;
}

.btn-secondary:hover {
  background: #6b7280;
}

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

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

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

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

/* User Card - More Compact */
.user-card {
  background: var(--bg-surface);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: relative;
  transition: transform 0.2s, box-shadow 0.2s;
  flex: 1 1 240px;
  /* Smaller basis for better row fitting */
  max-width: 320px;
  min-width: 220px;
}

/* Prettier Selects */
select {
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  width: 100%;
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 32px;
}

select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

/* Chat Sidebar */
#chat-sidebar {
  width: 300px;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.chat-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  color: var(--text-muted);
}

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

.message {
  font-size: 0.9rem;
  line-height: 1.4;
}

.message .author {
  font-weight: 700;
  color: var(--primary);
  margin-right: 6px;
}

.message.system {
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  font-size: 0.8rem;
}

.chat-input-area {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

#chat-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 8px;
  border-radius: 4px;
  color: var(--text-main);
  resize: none;
  height: 40px;
}

#chat-input:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {

  /* Header Adjustments */
  .brand span {
    display: none;
    /* Hide text on small screens */
  }

  .header-controls {
    gap: 8px;
  }

  #toggle-chat-btn {
    display: inline-flex !important;
    margin-left: 8px;
    /* Visual balance */
    /* Show chat button */
  }

  /* Chat Sidebar as Drawer */
  #chat-sidebar {
    position: fixed;
    top: 60px;
    /* Below header */
    right: -100%;
    /* Hidden by default */
    bottom: 0;
    width: 85%;
    /* Take most of screen */
    max-width: 350px;
    z-index: 1000;
    transition: right 0.3s ease-in-out;
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.5);
  }

  #chat-sidebar.open {
    right: 0;
    /* Slide in */
  }

  /* Grid Adjustments */
  #grid-container {
    padding-top: 80px !important;
    /* FORCE CLEARANCE of header */
    padding-bottom: 80px;
    /* Space for bottom content if needed */
  }

  .user-card {
    min-width: 100%;
    /* Full width cards on mobile */
  }
}