:root {
  --bg-rail: #17181c;
  --bg-sidebar: #1f2026;
  --bg-main: #2a2c33;
  --bg-elevated: #33363e;
  --bg-input: #383b44;
  --bg-hover: rgba(255, 255, 255, 0.06);
  --bg-active: rgba(255, 255, 255, 0.11);
  --text: #e6e8ee;
  --text-muted: #9a9fab;
  --text-faint: #6c717d;
  --accent: #6a5cff;
  --accent-hover: #5a4bf0;
  --ok: #2fbf71;
  --danger: #ec4f5b;
  --warn: #f0b232;
  --radius: 8px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg-rail);
  color: var(--text);
  font: 15px/1.4 'Segoe UI', system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: 13px;
}

.pad {
  padding: 8px 12px;
}

.ok {
  color: var(--ok);
}

.form-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 1em;
  margin: 4px 0;
}

.icon {
  flex: none;
}

/* ---------- buttons & inputs ---------- */

.btn {
  border: 0;
  border-radius: 6px;
  padding: 9px 16px;
  background: var(--bg-input);
  font-weight: 600;
  transition: background 0.15s;
}

.btn:hover {
  background: #444852;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.primary:hover {
  background: var(--accent-hover);
}

.btn.danger {
  background: var(--danger);
  color: #fff;
}

.btn.wide {
  width: 100%;
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.link {
  background: none;
  border: 0;
  padding: 0;
  color: #8f86ff;
}

.link:hover {
  text-decoration: underline;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.icon-btn.tiny {
  width: 20px;
  height: 20px;
}

.icon-btn.round {
  border-radius: 50%;
  background: var(--bg-sidebar);
  width: 36px;
  height: 36px;
}

.icon-btn.on {
  color: var(--ok);
}

.icon-btn.off {
  color: var(--danger);
}

.icon-btn.danger:hover {
  color: var(--danger);
}

.icon-btn.ok:hover {
  color: var(--ok);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--bg-rail);
  padding: 10px 12px;
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
}

label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

/* ---------- login ---------- */

.login {
  height: 100%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 20% 20%, #3a2f8f 0, transparent 45%), radial-gradient(circle at 80% 80%, #1d5f6b 0, transparent 40%), var(--bg-rail);
}

.login-card {
  width: min(440px, calc(100% - 32px));
  display: grid;
  gap: 14px;
  padding: 32px;
  border-radius: 12px;
  background: var(--bg-main);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.login-card h1 {
  margin: 0;
  text-align: center;
  font-size: 28px;
}

.login-card .login-hint {
  margin: -8px 0 0;
}

.login-card > p:last-of-type {
  margin: 0;
  text-align: center;
}

.login-card .login-custom {
  justify-self: center;
  margin-top: -6px;
  font-size: 12px;
  color: var(--text-faint);
}

#login-subtitle {
  margin: -8px 0 4px;
  text-align: center;
}

/* ---------- app layout ---------- */

.app {
  height: 100%;
  display: grid;
  grid-template-columns: 72px 248px 1fr auto;
}

.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  overflow-y: auto;
  scrollbar-width: none;
}

.rail-item {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
}

.rail-pill {
  position: absolute;
  left: 0;
  top: 50%;
  width: 4px;
  height: 0;
  border-radius: 0 4px 4px 0;
  background: #fff;
  transform: translateY(-50%);
  transition: height 0.15s;
}

.rail-item.unread .rail-pill {
  height: 8px;
}

.rail-item:hover .rail-pill {
  height: 20px;
}

.rail-item.active .rail-pill {
  height: 40px;
}

.rail-btn {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--bg-elevated);
  font-weight: 700;
  font-size: 15px;
  transition:
    border-radius 0.15s,
    background 0.15s;
}

.rail-item:hover .rail-btn,
.rail-item.active .rail-btn {
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
}

.rail-btn.action {
  color: var(--ok);
}

.rail-item:hover .rail-btn.action {
  background: var(--ok);
  color: #fff;
}

.rail-separator {
  width: 32px;
  height: 2px;
  border-radius: 1px;
  background: var(--bg-elevated);
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-sidebar);
  border-radius: 12px 0 0 0;
}

.sidebar-header {
  height: 48px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.3);
  flex: none;
}

.sidebar-title {
  font-weight: 700;
}

.server-menu-btn {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 0;
  background: none;
  padding: 6px 4px;
  border-radius: 6px;
}

.server-menu-btn:hover {
  background: var(--bg-hover);
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.section-title {
  margin: 16px 4px 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.section-title.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.side-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  margin: 1px 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text-muted);
  text-align: left;
}

.side-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.side-item.active {
  background: var(--bg-active);
  color: var(--text);
}

.side-item.unread {
  color: var(--text);
  font-weight: 700;
}

.side-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hash {
  width: 20px;
  text-align: center;
  font-size: 20px;
  color: var(--text-faint);
}

.hash.big,
.at {
  font-size: 22px;
  color: var(--text-faint);
}

.badge {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

.voice-participants {
  padding: 2px 0 6px 28px;
}

.voice-participant {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 6px;
  color: var(--text-muted);
  font-size: 14px;
}

.live {
  padding: 0 5px;
  border-radius: 4px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
}

.voice-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.3);
}

.voice-info {
  flex: 1;
  min-width: 0;
  display: grid;
  border: 0;
  background: none;
  text-align: left;
  padding: 2px 4px;
  border-radius: 6px;
}

.voice-info:hover {
  background: var(--bg-hover);
}

.voice-info span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice-actions {
  display: flex;
}

.user-panel {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 8px;
  background: #1a1b20;
}

.user-chip {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

/* ---------- avatars ---------- */

.avatar {
  position: relative;
  flex: none;
  width: var(--avatar-size, 32px);
  height: var(--avatar-size, 32px);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: hsl(var(--avatar-hue, 250) 55% 45%);
  color: #fff;
  font-weight: 700;
  font-size: calc(var(--avatar-size, 32px) * 0.42);
  transition: box-shadow 0.1s;
}

.status {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 3px solid var(--bg-sidebar);
}

.status.online {
  background: var(--ok);
}

.status.offline {
  background: var(--text-faint);
}

.speaking .avatar,
.speaking.avatar {
  box-shadow:
    0 0 0 2px var(--bg-sidebar),
    0 0 0 4px var(--ok);
}

/* ---------- main ---------- */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-main);
}

.main-header {
  height: 48px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.25);
  font-weight: 700;
}

.main-header .divider {
  width: 1px;
  height: 24px;
  margin: 0 8px;
  background: var(--bg-input);
}

.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0 8px;
}

.channel-intro {
  padding: 16px;
}

.channel-intro h2 {
  margin: 0;
  font-size: 22px;
}

.load-more {
  display: block;
  margin: 8px auto 16px;
}

.message {
  display: flex;
  gap: 16px;
  padding: 2px 16px;
  margin-top: 14px;
}

.message.grouped {
  margin-top: 0;
  padding-left: 72px;
}

.message:hover {
  background: rgba(0, 0, 0, 0.08);
}

.message-body {
  min-width: 0;
}

.message-meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.message-author {
  font-weight: 600;
}

.message-time {
  font-size: 12px;
  color: var(--text-faint);
}

.message-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.composer {
  flex: none;
  padding: 0 16px 20px;
}

.composer textarea {
  resize: none;
  background: var(--bg-input);
  border-radius: 8px;
  max-height: 200px;
  padding: 12px 14px;
}

.empty {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--text-muted);
}

/* ---------- friends ---------- */

.friends {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.tab {
  border: 0;
  border-radius: 6px;
  padding: 4px 10px;
  background: none;
  color: var(--text-muted);
  font-weight: 600;
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.tab:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.tab.active {
  background: var(--bg-active);
  color: var(--text);
}

.tab.add {
  background: var(--ok);
  color: #fff;
}

.tab.add.active {
  background: transparent;
  color: var(--ok);
}

.friends-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 24px;
}

.friend-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px;
  border-top: 1px solid var(--bg-elevated);
  border-radius: 8px;
}

.friend-row:hover {
  background: var(--bg-hover);
}

.friend-text {
  flex: 1;
  display: grid;
}

.friend-actions {
  display: flex;
  gap: 8px;
}

.add-friend h2 {
  margin: 12px 0 4px;
}

.add-friend-form {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  padding: 8px;
  border-radius: 8px;
  background: var(--bg-rail);
}

.add-friend-form input {
  background: transparent;
  border: 0;
}

.add-friend-form .btn {
  white-space: nowrap;
}

/* ---------- members ---------- */

.members {
  width: 232px;
  overflow-y: auto;
  padding: 8px;
  background: var(--bg-sidebar);
}

.member {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
}

.member:hover {
  background: var(--bg-hover);
}

.member.faded {
  opacity: 0.5;
}

.crown {
  color: var(--warn);
}

/* ---------- voice stage ---------- */

.stage {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #121317;
}

.stage .main-header {
  background: var(--bg-main);
}

.stage-empty {
  flex: 1;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  text-align: center;
}

.stage-empty h2 {
  margin: 0;
}

.stage-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  grid-auto-rows: minmax(160px, 1fr);
  gap: 12px;
  padding: 16px;
  overflow-y: auto;
}

.stage-grid.has-screens {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.tile {
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--bg-elevated);
  overflow: hidden;
  border: 2px solid transparent;
}

.tile.person.speaking {
  border-color: var(--ok);
}

.tile.screen {
  grid-column: 1 / -1;
  grid-row: span 3;
  background: #000;
  cursor: zoom-in;
}

.tile video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.tile-name {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.6);
  font-size: 13px;
  font-weight: 600;
}

.stage-controls {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 16px;
}

.round-btn {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--bg-elevated);
}

.round-btn:hover {
  background: var(--bg-input);
}

.round-btn.on {
  background: var(--ok);
}

.round-btn.off {
  color: var(--danger);
}

.round-btn.danger {
  background: var(--danger);
}

/* ---------- modals & toasts ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 10;
}

.modal {
  width: min(460px, calc(100% - 32px));
  max-height: calc(100% - 64px);
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  background: var(--bg-main);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.modal.wide {
  width: min(820px, calc(100% - 32px));
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 16px 0 20px;
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.modal-body {
  display: grid;
  gap: 14px;
  padding: 16px 20px 20px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-footer.spread {
  justify-content: space-between;
}

.invite-row {
  display: flex;
  gap: 8px;
}

.source-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.source {
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: var(--bg-elevated);
  text-align: left;
}

.source:hover {
  border-color: var(--accent);
}

.source img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: #000;
  border-radius: 4px;
}

.source span {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast-root {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 8px;
  z-index: 20;
}

.toast {
  max-width: 360px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--bg-elevated);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  border-left: 4px solid var(--accent);
}

.toast.error {
  border-left-color: var(--danger);
}

/* ---------- voice settings ---------- */

.noise-tag {
  color: var(--text-faint);
}

.noise-tag.on {
  color: #8f86ff;
}

.settings .section-title {
  margin: 8px 0 0;
}

.mode-list {
  display: grid;
  gap: 8px;
}

.mode-card,
.toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg-sidebar);
  text-transform: none;
  letter-spacing: normal;
  font-size: 15px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
}

.mode-card:has(input:checked) {
  outline: 2px solid var(--accent);
}

.mode-card input,
.toggle-row input {
  width: auto;
  flex: none;
  accent-color: var(--accent);
}

.toggle-row {
  justify-content: space-between;
}

.toggle-row input {
  width: 18px;
  height: 18px;
}

.mode-text {
  display: grid;
  gap: 2px;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.slider-row input {
  padding: 0;
  accent-color: var(--accent);
}

.slider-row span {
  min-width: 52px;
  text-align: right;
}

.meter {
  position: relative;
  height: 10px;
  border-radius: 5px;
  background: var(--bg-rail);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--ok), var(--warn) 80%, var(--danger));
  transition: width 0.06s linear;
}

.meter-gate {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #fff;
}

.test-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

label.inline {
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
  font-size: 14px;
}

label.inline input {
  width: auto;
}

@media (max-width: 1100px) {
  .members {
    display: none !important;
  }
}

@media (max-width: 760px) {
  .app {
    grid-template-columns: 72px 200px 1fr;
  }
}

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-thumb {
  border-radius: 4px;
  background: #15161a;
}
