:root {
  --bg-primary: #0f1117;
  --bg-secondary: #151920;
  --bg-tertiary: #1c2130;
  --bg-card: #1e2535;
  --bg-hover: #252d3d;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --accent-rgb: 88, 101, 242;
  --green: #3ba55c;
  --red: #ed4245;
  --yellow: #faa61a;
  --text-primary: #e3e5e8;
  --text-secondary: #96a0b0;
  --text-muted: #5c6578;
  --border: #2a3347;
  --border-light: #323d52;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --sidebar-w: 240px;
  --font: 'Inter', system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── OVERLAY ──────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn .15s ease;
}

@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 100%;
  max-width: 400px;
  animation: slideUp .2s ease;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-modal {
  max-width: 520px;
  padding: 0;
  gap: 0;
  overflow: hidden;
}

.glass {
  box-shadow: var(--shadow);
}

.modal-icon {
  font-size: 36px;
  text-align: center;
}

.modal h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
}

.modal p {
  color: var(--text-secondary);
  text-align: center;
  font-size: 13px;
}

/* ── INPUTS ───────────────────────────────────────────────────── */
.input {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  width: 100%;
  transition: border-color .15s;
  outline: none;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-muted); }

.input-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 4px;
  display: block;
}

.select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  cursor: pointer;
}

.range {
  appearance: none;
  width: 120px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.range::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
}

.color-picker {
  width: 48px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  cursor: pointer;
  padding: 2px;
}

/* ── BUTTONS ──────────────────────────────────────────────────── */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); }

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn.active { color: var(--accent); }

.mt16 { margin-top: 16px; }

.form-error {
  color: var(--red);
  font-size: 12px;
  text-align: center;
  min-height: 18px;
}

/* ── TOGGLE ───────────────────────────────────────────────────── */
.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  background: var(--bg-hover);
  border-radius: 24px;
  cursor: pointer;
  transition: .2s;
}
.slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: .2s;
}
.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(20px); background: #fff; }

/* ── AVATAR UPLOAD ────────────────────────────────────────────── */
.avatar-upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.avatar-preview {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 2px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  overflow: hidden;
  transition: border-color .15s;
  position: relative;
}
.avatar-preview.large { width: 96px; height: 96px; }
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.avatar-upload-area:hover .avatar-preview { border-color: var(--accent); }

.avatar-hint {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── COLOR PRESETS ────────────────────────────────────────────── */
.color-presets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  border: 2px solid transparent;
}
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.selected { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }

/* ── BANNER OPTIONS ───────────────────────────────────────────── */
.banner-options {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.banner-opt {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  text-align: center;
  font-size: 12px;
  cursor: pointer;
  transition: all .15s;
  color: var(--text-secondary);
}
.banner-opt:hover, .banner-opt.selected {
  border-color: var(--accent);
  color: var(--text-primary);
  background: rgba(var(--accent-rgb), .15);
}

/* ── SETTINGS MODAL INNER ─────────────────────────────────────── */
.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}
.settings-header h2 { font-size: 18px; }

.settings-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
}
.tab {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font);
  transition: all .15s;
}
.tab:hover { color: var(--text-primary); background: var(--bg-hover); }
.tab.active { color: var(--text-primary); background: var(--bg-tertiary); }

.tab-content {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: 60vh;
  overflow-y: auto;
}
.tab-content.hidden { display: none; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0;
}
.setting-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}
.setting-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.mic-meter-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.mic-meter-wrap {
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.mic-meter-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), #57cc82);
  border-radius: 4px;
  transition: width .05s;
}

.threshold-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.threshold-wrap span {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 24px;
  text-align: right;
}

/* ── LAYOUT ───────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
}

/* ── SIDEBAR ──────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-top {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}
.logo-icon { font-size: 20px; }

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

.channel-section-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 8px 4px;
}
.channel-add { float:right; border:0; background:none; color:var(--text-muted); font-size:18px; cursor:pointer; line-height:12px; }
.channel-add:hover { color:var(--text-primary); }
.invite-btn { border:1px solid var(--border); background:var(--bg-hover); color:var(--text-primary); border-radius:6px; padding:6px 10px; cursor:pointer; font-weight:600; }

.channel-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .1s;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
}
.channel-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.channel-item.active { background: var(--bg-tertiary); color: var(--text-primary); }
.channel-hash { font-size: 16px; }
.channel-name { flex: 1; }
.channel-count {
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}
.channel-count:empty, .channel-count[data-count="0"] { display: none; }

/* Self area */
.self-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border);
}
.self-avatar-wrap { position: relative; flex-shrink: 0; }
.self-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  overflow: hidden;
  position: relative;
}
.self-avatar img { width: 100%; height: 100%; object-fit: cover; }
.self-avatar-speaking {
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: border-color .1s;
  pointer-events: none;
}
.self-avatar-speaking.active { border-color: var(--green); }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--bg-tertiary);
  position: absolute;
  bottom: -1px;
  right: -1px;
}
.status-dot.online { background: var(--green); }
.status-dot.offline { background: var(--text-muted); }

.self-info { flex: 1; min-width: 0; }
.self-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.self-status { font-size: 11px; color: var(--text-muted); }

.self-controls { display: flex; gap: 2px; }

/* ── MAIN ─────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-primary);
}

.channel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}
.channel-header-icon { font-size: 18px; }
.channel-header-name { font-size: 16px; font-weight: 700; }
.header-actions { margin-left: auto; }

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

/* ── PARTICIPANTS ─────────────────────────────────────────────── */
.participants-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  align-items: flex-start;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  min-height: 200px;
}
.empty-icon { font-size: 48px; opacity: .5; }
.empty-title { font-size: 18px; font-weight: 600; color: var(--text-secondary); }
.empty-sub { font-size: 13px; }

.participants {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  width: 100%;
}

.participant {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transition: all .15s;
  position: relative;
  animation: slideUp .2s ease;
}
.participant:hover { border-color: var(--border-light); background: var(--bg-hover); }
.participant.speaking {
  border-color: var(--green);
  box-shadow: 0 0 0 2px rgba(59, 165, 92, .3);
}

.participant-avatar-wrap { position: relative; }
.participant-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  overflow: hidden;
  transition: box-shadow .1s;
}
.participant-avatar img { width: 100%; height: 100%; object-fit: cover; }
.participant.speaking .participant-avatar {
  box-shadow: 0 0 0 3px var(--green);
}

.participant-muted-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 20px;
  height: 20px;
  background: var(--red);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-card);
  font-size: 10px;
}

.participant-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
  max-width: 120px;
}
.participant-status {
  font-size: 11px;
  color: var(--text-muted);
}
.participant-status.speaking-label { color: var(--green); }

/* ── CONTROLS BAR ─────────────────────────────────────────────── */
.controls-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  gap: 12px;
  flex-shrink: 0;
  position: relative;
}

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

.controls-right {
  position: absolute;
  right: 24px;
}

.ctrl-btn {
  border: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all .15s;
  padding: 10px 16px;
}
.ctrl-btn:disabled { opacity: .5; cursor: not-allowed; }

.join-ctrl {
  background: var(--green);
  color: #fff;
  padding: 10px 24px;
  border-radius: 24px;
  font-size: 15px;
}
.join-ctrl:hover:not(:disabled) { background: #2d9249; transform: translateY(-1px); }

.leave-ctrl {
  background: var(--red);
  color: #fff;
  border-radius: 24px;
  font-size: 15px;
}
.leave-ctrl:hover:not(:disabled) { background: #c93537; }

.mute-ctrl {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  padding: 0;
  justify-content: center;
}
.mute-ctrl:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--border-light); }
.mute-ctrl.muted { background: var(--red); border-color: var(--red); color: #fff; }

.latency-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--green);
  display: flex;
  align-items: center;
  gap: 4px;
}
.latency-badge.lag { color: var(--yellow); }
.latency-badge.bad { color: var(--red); }

/* ── TOASTS ───────────────────────────────────────────────────── */
#toasts {
  position: fixed;
  bottom: 80px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  box-shadow: var(--shadow);
  animation: slideToast .25s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 280px;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--accent); }

@keyframes slideToast {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ── SCROLL ───────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ── RESPONSIVE ───────────────────────────────────────────────── */
@media (max-width: 600px) {
  .sidebar { width: 180px; }
  .participants { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}

/* ── THEME VARIANTS ───────────────────────────────────────────── */
body.theme-darker {
  --bg-primary: #090c10;
  --bg-secondary: #0e1117;
  --bg-tertiary: #131921;
  --bg-card: #161e2a;
}
body.theme-midnight {
  --bg-primary: #080e1a;
  --bg-secondary: #0d1529;
  --bg-tertiary: #131e35;
  --bg-card: #172040;
  --border: #1f2f4a;
}
body.theme-forest {
  --bg-primary: #0a0f0a;
  --bg-secondary: #0f1510;
  --bg-tertiary: #141c14;
  --bg-card: #182018;
  --accent: #3ba55c;
  --accent-hover: #2d9249;
}

/* compact mode */
body.compact .participant { padding: 10px 8px; gap: 6px; }
body.compact .participant-avatar { width: 44px; height: 44px; font-size: 18px; }
body.compact .participants { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
