:root {
  --bg-darkest: #1e1f22;
  --bg-dark: #2b2d31;
  --bg-chat: #313338;
  --bg-hover: #35373c;
  --bg-active: #404249;
  --bg-input: #383a40;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --text: #dbdee1;
  --text-strong: #f2f3f5;
  --muted: #949ba4;
  --faint: #80848e;
  --danger: #fa777c;
  --ok: #23a55a;
  --divider: #3f4147;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg-darkest);
}
button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; }
[hidden] { display: none !important; }

/* ----- Auth ----- */
.auth-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1000px 500px at 15% -10%, rgba(88, 101, 242, 0.28), transparent 60%),
    radial-gradient(800px 500px at 110% 110%, rgba(88, 101, 242, 0.16), transparent 55%),
    var(--bg-darkest);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  background: var(--bg-dark);
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  text-align: center;
}
.auth-logo { margin-bottom: 12px; }
.auth-card h1 { margin: 0 0 6px; font-size: 24px; color: var(--text-strong); }
.auth-sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--bg-darkest);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 20px;
}
.auth-tabs button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 0;
  border-radius: 6px;
  font-weight: 600;
}
.auth-tabs button[aria-selected="true"] { background: var(--bg-active); color: var(--text-strong); }
.auth-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.field input, .field select, .composer textarea {
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-strong);
  padding: 10px 12px;
  outline: none;
}
.field input:focus, .field select:focus, .composer textarea:focus { border-color: var(--accent); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.nickname-preview { font-weight: 700; }
.field-hint { font-size: 12px; color: var(--faint); }
.password-wrap { display: flex; gap: 6px; align-items: center; }
.password-wrap input { flex: 1; min-width: 0; }
.ghost-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 13px;
  padding: 6px;
}
.ghost-btn:hover { color: var(--text-strong); }
.primary-btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: 11px 16px;
  font-weight: 600;
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:disabled { opacity: 0.55; cursor: default; }
.form-error { color: var(--danger); font-size: 13px; margin: 12px 0 0; text-align: left; }

/* ----- App layout ----- */
.app {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 230px;
  height: 100dvh;
}
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-dark);
  min-height: 0;
}
.sidebar-header {
  padding: 14px 16px;
  font-weight: 700;
  color: var(--text-strong);
  border-bottom: 1px solid var(--bg-darkest);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}
.sidebar-body { flex: 1; overflow-y: auto; padding: 10px 8px; min-height: 0; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}
.icon-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  width: 26px;
  height: 26px;
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  line-height: 1;
  padding: 0;
}
.icon-btn:hover { color: var(--text-strong); background: var(--bg-hover); }
.nav-list, .member-list, .pick-list { list-style: none; margin: 0; padding: 0; }
.nav-list button, .member-list button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 7px 8px;
  border-radius: 6px;
  text-align: left;
}
.nav-list button:hover, .member-list button:hover { background: var(--bg-hover); color: var(--text); }
.nav-list button.active { background: var(--bg-active); color: var(--text-strong); }
.channel-hash { font-size: 18px; font-weight: 600; color: var(--faint); width: 20px; text-align: center; flex: none; }
.nav-list button.active .channel-hash { color: var(--text); }
.nav-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-hint { font-size: 12px; color: var(--faint); padding: 4px 10px; margin: 0; }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 0;
  padding: 0;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  text-transform: uppercase;
}
.avatar.small { width: 24px; height: 24px; font-size: 11px; }
.avatar.has-photo { background-size: cover; background-position: center; background-repeat: no-repeat; }
.avatar:disabled { opacity: 0.6; cursor: progress; }
.avatar-lg { width: 88px; height: 88px; font-size: 32px; border-radius: 50%; }
#me-avatar:hover, #profile-avatar:hover { outline: 2px solid var(--accent); outline-offset: 2px; }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-darkest);
}
.me-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.me-name { font-size: 13px; font-weight: 600; color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.me-name:hover { text-decoration: underline; }
.me-status { font-size: 11px; color: var(--ok); }

/* ----- Chat ----- */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg-chat); }
.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--divider);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
}
.chat-header h2 { flex: 1; min-width: 0; margin: 0; font-size: 16px; color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view-icon { color: var(--faint); font-size: 20px; font-weight: 600; }
.menu-toggle { display: none; }

.voice-join {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--divider);
  border-radius: 999px;
  padding: 5px 12px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.voice-join:hover { color: var(--text-strong); background: var(--bg-hover); }
.voice-join:disabled { opacity: 0.6; cursor: progress; }

.messages { flex: 1; overflow-y: auto; padding: 16px 16px 8px; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.day-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0 8px;
  color: var(--faint);
  font-size: 12px;
  font-weight: 600;
}
.day-divider::before, .day-divider::after { content: ""; flex: 1; height: 1px; background: var(--divider); }
.msg { display: flex; gap: 12px; padding: 3px 8px; border-radius: 6px; }
.msg:hover { background: rgba(0, 0, 0, 0.06); }
.msg .avatar { margin-top: 2px; }
.msg-body { min-width: 0; flex: 1; }
.msg-head { display: flex; align-items: baseline; gap: 8px; }
.msg-author {
  font-weight: 600;
  color: var(--text-strong);
  background: transparent;
  border: 0;
  padding: 0;
}
.msg-author:hover { text-decoration: underline; }
.msg-time { font-size: 11px; color: var(--faint); }
.msg-text { white-space: pre-wrap; word-break: break-word; }
.msg.compact { padding-left: 52px; padding-top: 1px; padding-bottom: 1px; }
.empty-state { margin: auto; text-align: center; color: var(--muted); padding: 24px; }
.empty-state .big { font-size: 34px; margin-bottom: 8px; color: var(--faint); }

.voice-note {
  flex: none;
  margin: 0;
  padding: 8px 16px;
  font-size: 12px;
  color: #f0b357;
  background: rgba(240, 179, 87, 0.08);
  border-bottom: 1px solid var(--divider);
}
.voice-note a { color: var(--text-strong); text-decoration: underline; }

.voice-panel {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 16px;
  background: rgba(63, 185, 80, 0.07);
  border-bottom: 1px solid var(--divider);
}
.voice-panel[hidden] { display: none; }
.voice-panel-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.voice-live { flex: none; width: 8px; height: 8px; border-radius: 50%; background: #3fb950; box-shadow: 0 0 0 3px rgba(63, 185, 80, 0.18); }
.voice-panel-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 6px; }
.voice-panel-title strong { color: var(--text-strong); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-panel-count { flex: none; font-size: 12px; color: var(--muted); }
.voice-panel-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.voice-panel-actions .small-btn { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.voice-panel-actions .small-btn:hover { background: rgba(255, 255, 255, 0.12); }
#voice-mute[aria-pressed="true"] { color: #f0b357; }
.voice-peers { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.voice-peer { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px 3px 3px; border-radius: 999px; background: rgba(0, 0, 0, 0.22); font-size: 12px; color: var(--text); }
.voice-peer.self { outline: 1px solid rgba(63, 185, 80, 0.35); }
.voice-peer .avatar { width: 20px; height: 20px; font-size: 10px; }
.voice-peer-off { color: #f0b357; }

.send-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 16px;
  padding: 8px 12px;
  border-radius: 8px 8px 0 0;
  background: #4a3f35;
  color: #f0b357;
  font-size: 13px;
}
.send-bar-actions { display: flex; gap: 6px; flex: none; }
.small-btn {
  border: 0;
  border-radius: 5px;
  padding: 5px 10px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}
.small-btn.ghost { background: transparent; color: inherit; }
.small-btn.ghost:hover { text-decoration: underline; }

.composer { display: flex; gap: 10px; align-items: flex-end; padding: 0 16px 20px; }
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  border-radius: 8px;
  padding: 11px 14px;
}
.send-btn {
  flex: none;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.5; cursor: default; }

/* ----- Members ----- */
.members { background: var(--bg-dark); padding: 8px; overflow-y: auto; min-height: 0; }
.member-list button { gap: 10px; }
.member-text { display: flex; flex-direction: column; min-width: 0; }
.member-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-class { font-size: 11px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-self { font-size: 11px; color: var(--faint); margin-left: auto; flex: none; }

/* ----- Modals ----- */
.modal {
  border: 0;
  border-radius: 12px;
  background: var(--bg-dark);
  color: var(--text);
  padding: 0;
  width: min(420px, calc(100vw - 32px));
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.6); }
.modal-body { padding: 24px; display: flex; flex-direction: column; gap: 14px; max-height: calc(100dvh - 80px); overflow-y: auto; }
.modal-body h3 { margin: 0; color: var(--text-strong); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.profile-head { display: flex; align-items: center; gap: 14px; }
.profile-id { display: flex; flex-direction: column; min-width: 0; }
.profile-nick { font-size: 18px; font-weight: 700; color: var(--text-strong); overflow: hidden; text-overflow: ellipsis; }
.profile-class { font-size: 13px; color: var(--muted); }
.profile-real { display: flex; flex-direction: column; gap: 4px; }
.profile-real span:last-child { color: var(--text-strong); }
.pick-list { display: flex; flex-direction: column; gap: 2px; max-height: 300px; overflow-y: auto; }
.pick-list button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 8px;
  border-radius: 6px;
  text-align: left;
}
.pick-list button:hover { background: var(--bg-hover); }

.sidebar-backdrop { display: none; }

/* ----- Responsive ----- */
@media (max-width: 1100px) {
  .app { grid-template-columns: 240px minmax(0, 1fr); }
  .members { display: none; }
}
@media (max-width: 460px) {
  .field-row { grid-template-columns: 1fr; }
  .auth-card { padding: 24px 20px; }
}
@media (max-width: 720px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .menu-toggle { display: inline-flex; }
  .voice-note { padding: 8px 12px; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 280px;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.35);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(0, 0, 0, 0.5);
  }
}