:root {
  --bg: #0c120f;
  --rail: #09100c;
  --side: #121a15;
  --panel: #151f18;
  --panel2: #1a251e;
  --hover: #1d2a22;
  --line: #27352c;
  --text: #e8f0e9;
  --muted: #94a197;
  --soft: #b8c4bb;
  --accent: #20ad78;
  --accent2: #63d4a5;
  --accent-dim: #163d2c;
  --red: #e56770;
  --yellow: #e8c15a;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 "Segoe UI", system-ui, sans-serif;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
a { color: var(--accent2); }

/* Buttons */
.primary, .secondary, .danger, .ghost {
  border: 0; border-radius: 8px; padding: 9px 16px; font-weight: 600;
}
.primary { background: var(--accent); color: #04140d; }
.primary:hover { background: #27c189; }
.primary:disabled { opacity: .5; cursor: default; }
.secondary { background: var(--panel2); border: 1px solid var(--line); }
.secondary:hover { background: var(--hover); }
.danger { background: #4a1f24; color: #ffb3b9; }
.danger:hover { background: #5c252b; }
.ghost { background: none; color: var(--soft); padding: 6px 8px; }
.ghost:hover { background: var(--hover); color: var(--text); }
.wide { width: 100%; }
.link { border: 0; background: none; color: var(--muted); text-decoration: underline; padding: 4px; font-size: 12px; }
.icon-btn {
  border: 0; background: none; color: var(--muted); width: 32px; height: 32px;
  border-radius: 8px; display: inline-grid; place-items: center; font-size: 16px; flex: none;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.on { color: var(--red); }
.icon-btn.active { color: var(--accent2); background: var(--accent-dim); }

input, textarea, select {
  background: #0d1510; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%;
}
input::placeholder, textarea::placeholder { color: #6c7a70; }

/* Auth */
.auth {
  height: 100%; display: grid; place-items: center;
  background: radial-gradient(ellipse at 50% -10%, #143b2a99, transparent 55%), var(--bg);
}
.auth-card {
  width: min(380px, calc(100vw - 32px)); background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 20px 60px #0008;
}
.auth-logo { width: 72px; align-self: center; }
.auth-card h1 { margin: 0; text-align: center; font-size: 22px; }
.auth-card > p { margin: 0 0 4px; text-align: center; }
.auth-card label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--soft); }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; background: #0d1510; border-radius: 9px; padding: 3px; }
.auth-tabs button { border: 0; background: none; padding: 7px; border-radius: 7px; color: var(--muted); }
.auth-tabs button.active { background: var(--panel2); color: var(--text); }
.form-error { color: var(--red); margin: 0; min-height: 1em; font-size: 13px; }
.auth-card .code-input { text-align: center; font-size: 22px; letter-spacing: 8px; font-variant-numeric: tabular-nums; }
.auth-card .stack, dialog .stack { display: flex; flex-direction: column; gap: 8px; }
.auth-card .row.split { display: flex; justify-content: space-between; align-items: center; }

/* Layout */
.app {
  height: 100%; display: grid; grid-template-columns: 72px 248px minmax(0, 1fr) auto;
  background: radial-gradient(ellipse at 73% -20%, #143b2a66, transparent 42%), var(--bg);
}

/* Rail */
.rail {
  background: var(--rail); border-right: 1px solid #1a271f; display: flex; flex-direction: column;
  align-items: center; padding: 12px 0; gap: 8px; min-height: 0;
}
.rail-guilds { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; scrollbar-width: none; align-items: center; }
.rail-btn {
  position: relative; width: 48px; height: 48px; border-radius: 16px; border: 0; background: var(--panel2);
  color: var(--soft); font-weight: 700; font-size: 15px; display: grid; place-items: center; flex: none;
  transition: border-radius .15s, background .15s;
}
.rail-btn:hover, .rail-btn.active { border-radius: 14px; background: var(--accent-dim); color: var(--accent2); }
.rail-btn.active::before {
  content: ""; position: absolute; left: -12px; top: 10px; bottom: 10px; width: 4px; border-radius: 0 4px 4px 0; background: var(--accent2);
}
.rail-btn.home img { width: 34px; }
.rail-btn.add { color: var(--accent); font-size: 22px; }
.rail-btn.unread::after {
  content: ""; position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--red); border: 3px solid var(--rail);
}
.rail-sep { width: 28px; border-top: 1px solid var(--line); }
.rail-spacer { flex: 1; }

/* Sidebar */
.sidebar { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.side-head {
  height: 52px; padding: 0 12px 0 16px; display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--line);
  font-weight: 700; font-size: 15px;
}
.side-head .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-body { flex: 1; overflow-y: auto; padding: 10px 8px; min-height: 0; }
.section {
  display: flex; align-items: center; justify-content: space-between; padding: 14px 8px 4px;
  font-size: 11px; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); font-weight: 700;
}
.section .icon-btn { width: 22px; height: 22px; font-size: 15px; }
.item {
  width: 100%; border: 0; background: none; color: var(--soft); display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 7px; text-align: left; min-height: 34px;
}
.item:hover { background: var(--hover); color: var(--text); }
.item.active { background: var(--accent-dim); color: #c6f0da; }
.item.unread { color: var(--text); font-weight: 700; }
.item .glyph { width: 20px; text-align: center; color: var(--muted); flex: none; }
.item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .badge { background: var(--red); color: white; border-radius: 9px; font-size: 11px; padding: 0 6px; font-weight: 700; }
.item .ring { color: var(--accent2); font-size: 12px; }
.item .limit { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.voice-users { padding: 2px 0 6px 34px; display: flex; flex-direction: column; gap: 2px; }
.voice-user { display: flex; align-items: center; gap: 7px; color: var(--soft); font-size: 13px; padding: 2px 4px; }
.voice-user .flags { margin-left: auto; color: var(--muted); font-size: 12px; display: flex; gap: 3px; }
.voice-user .live { background: var(--red); color: white; border-radius: 4px; padding: 0 4px; font-size: 10px; font-weight: 700; }

/* Avatars */
.avatar {
  --size: 32px; position: relative; width: var(--size); height: var(--size); border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: calc(var(--size) * .42); color: white; background: #2b3a31;
}
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.avatar.sm { --size: 22px; }
.avatar.lg { --size: 80px; }
.avatar.xl { --size: 96px; }
.avatar .status {
  position: absolute; right: -2px; bottom: -2px; width: 11px; height: 11px; border-radius: 50%;
  background: #5d6b62; border: 2.5px solid var(--side);
}
.avatar .status.online { background: var(--accent); }
.avatar.speaking { box-shadow: 0 0 0 2px var(--side), 0 0 0 4px var(--accent2); }

/* Voice bar + me bar */
.voice-bar { border-top: 1px solid var(--line); padding: 10px 10px 8px; background: #101813; }
.voice-bar .status-line { display: flex; align-items: center; gap: 8px; }
.voice-bar .status-text { flex: 1; min-width: 0; }
.voice-bar b { color: var(--accent2); font-size: 13px; display: block; }
.voice-bar small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-bar .controls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.voice-bar .controls button { border: 0; border-radius: 7px; background: var(--panel2); padding: 6px 0; font-size: 15px; }
.voice-bar .controls button:hover { background: var(--hover); }
.voice-bar .controls button.on { background: #4a1f24; }
.voice-bar .controls button.sharing { background: var(--accent-dim); }
.voice-bar .controls button.leave { background: #4a1f24; }
.me-bar { border-top: 1px solid var(--line); padding: 8px; display: flex; align-items: center; gap: 8px; background: #0f1612; }
.me-bar .who { flex: 1; min-width: 0; }
.me-bar b, .me-bar small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-bar small { color: var(--muted); font-size: 12px; }
.net-indicator { display: flex; flex-direction: column; align-items: center; gap: 2px; flex: none; min-width: 44px; cursor: default; color: var(--muted); }
.net-indicator .bars { display: flex; align-items: flex-end; gap: 2px; height: 12px; }
.net-indicator .bars i { width: 4px; border-radius: 1px; background: var(--line); }
.net-indicator .bars i:nth-child(1) { height: 5px; }
.net-indicator .bars i:nth-child(2) { height: 8px; }
.net-indicator .bars i:nth-child(3) { height: 12px; }
.net-indicator .ms { font-size: 10px; line-height: 1; white-space: nowrap; font-variant-numeric: tabular-nums; }
.net-indicator.good .bars i.lit { background: var(--accent2); }
.net-indicator.mid .bars i.lit { background: var(--yellow); }
.net-indicator.bad .bars i.lit { background: var(--red); }
.net-indicator.off .ms { color: var(--red); }

/* Main */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); }
.main-head {
  height: 52px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 16px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.main-head .title { font-weight: 700; font-size: 15px; }
.main-head .sub { color: var(--muted); font-size: 13px; }
.main-head .spacer { flex: 1; }
.empty { flex: 1; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 24px; }
.empty h2 { color: var(--text); margin: 0 0 6px; }

/* Messages */
.messages { flex: 1; overflow-y: auto; padding: 16px 0 8px; min-height: 0; }
.day { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 14px 16px 6px; }
.day::before, .day::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.msg { position: relative; display: grid; grid-template-columns: 40px 1fr; gap: 0 12px; padding: 3px 48px 3px 16px; }
.msg:hover { background: #ffffff06; }
.msg.first { margin-top: 12px; }
.msg .avatar { --size: 40px; grid-row: span 2; }
.msg .head { display: flex; align-items: baseline; gap: 8px; }
.msg .head b { font-weight: 650; }
.msg .head time, .msg .side-time { color: var(--muted); font-size: 11px; }
.msg .side-time { visibility: hidden; text-align: right; padding-top: 3px; }
.msg:hover .side-time { visibility: visible; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; color: #dce6de; }
.msg .text.pending { opacity: .55; }
.msg .delete {
  position: absolute; right: 12px; top: 2px; visibility: hidden; border: 1px solid var(--line); background: var(--panel2);
  color: var(--muted); border-radius: 6px; padding: 1px 7px;
}
.msg:hover .delete { visibility: visible; }
.msg .delete:hover { color: var(--red); }
.load-more { display: block; margin: 0 auto 8px; }

.composer { padding: 0 16px 16px; flex: none; }
.composer-box { display: flex; align-items: flex-end; gap: 8px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 6px 6px 6px 14px; }
.composer textarea { border: 0; background: none; resize: none; padding: 7px 0; max-height: 200px; min-height: 22px; line-height: 1.4; }
.composer textarea:focus-visible { outline: none; }
.composer .counter { color: var(--muted); font-size: 11px; padding: 0 0 9px; }

/* Friends */
.friends { flex: 1; overflow-y: auto; padding: 16px 20px; }
.add-friend { display: flex; gap: 8px; margin-bottom: 6px; }
.friend-row { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-top: 1px solid var(--line); }
.friend-row .who { flex: 1; min-width: 0; }
.friend-row small { color: var(--muted); display: block; }
.friend-row .actions { display: flex; gap: 6px; }

/* Voice stage */
.stage { flex: 1; display: flex; flex-direction: column; min-height: 0; background: #0a0f0c; }
.stage.compact { flex: none; height: 46%; border-bottom: 1px solid var(--line); }
.stage-grid { flex: 1; display: grid; gap: 10px; padding: 14px; min-height: 0; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); grid-auto-rows: minmax(140px, 1fr); overflow: auto; }
.stage-grid.has-screen { grid-template-columns: 1fr; grid-auto-rows: auto; }
.screens { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.screen-tile { position: relative; background: #000; border-radius: 12px; overflow: hidden; aspect-ratio: 16 / 9; }
.screen-tile video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.screen-tile .label { position: absolute; left: 10px; bottom: 10px; background: #000a; padding: 3px 9px; border-radius: 6px; font-size: 12px; }
.screen-tile .fs { position: absolute; right: 8px; top: 8px; background: #000a; }
.tiles { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.has-screen .tiles { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.tile {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; padding: 16px; min-height: 140px; position: relative;
}
.has-screen .tile { min-height: 90px; padding: 10px; }
.has-screen .tile .avatar { --size: 44px; }
.tile .name { font-weight: 600; display: flex; gap: 6px; align-items: center; }
.tile .flags { color: var(--red); font-size: 13px; }
.stage-controls { flex: none; display: flex; justify-content: center; gap: 10px; padding: 12px; }
.stage-controls button { border: 0; border-radius: 24px; background: var(--panel2); padding: 10px 18px; font-weight: 600; }
.stage-controls button:hover { background: var(--hover); }
.stage-controls button.on { background: #4a1f24; }
.stage-controls button.sharing { background: var(--accent-dim); color: var(--accent2); }
.stage-controls button.leave { background: #b8333e; color: white; }
.stage-join { flex: 1; display: grid; place-items: center; text-align: center; gap: 12px; }

/* Members */
.members { width: 232px; background: var(--side); border-left: 1px solid var(--line); overflow-y: auto; padding: 8px; }
.member { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 7px; }
.member:hover { background: var(--hover); }
.member.offline { opacity: .45; }
.member .crown { color: var(--yellow); font-size: 12px; }
.member .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Incoming call */
.call-strip {
  flex: none; display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--accent-dim); border-bottom: 1px solid var(--line);
}
.call-strip .spacer { flex: 1; }

/* Modal */
.modal {
  border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); padding: 0;
  width: min(460px, calc(100vw - 32px)); box-shadow: 0 24px 70px #000a;
}
.modal::backdrop { background: #000a; }
.modal form { display: flex; flex-direction: column; gap: 12px; padding: 22px; }
.modal h2 { margin: 0; font-size: 19px; }
.modal p { margin: 0; }
.modal label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--soft); }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.modal .row.split { justify-content: space-between; }
.modal .choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal .choice button { padding: 18px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); text-align: center; }
.modal .choice button:hover { border-color: var(--accent); }
.modal .choice b { display: block; margin-bottom: 4px; }
.modal .choice small { color: var(--muted); }
.modal .switch { flex-direction: row; align-items: center; gap: 10px; font-size: 14px; color: var(--text); }
.modal .switch input { width: auto; }
.modal input[type=range] { padding: 0; border: 0; background: none; accent-color: var(--accent); }
.modal input[type=range]:disabled { opacity: .4; }
.modal .limit-head { display: flex; justify-content: space-between; }
.modal .limit-value { color: var(--text); font-size: 14px; font-variant-numeric: tabular-nums; }
.modal .small { font-size: 12px; min-height: 1em; }
.modal .tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.modal .tabs button { border: 0; background: none; color: var(--muted); padding: 6px 10px; border-radius: 7px; }
.modal .tabs button.active { background: var(--panel2); color: var(--text); }
.invite-code { display: flex; gap: 8px; }
.invite-code input { font-family: Consolas, monospace; font-size: 16px; letter-spacing: 1px; }
.profile-edit { display: flex; align-items: center; gap: 16px; }
.meter { height: 8px; background: #0d1510; border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .08s; }

/* Toast + connection */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; box-shadow: 0 10px 30px #0008;
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: #7a2d35; }
.connection-banner {
  position: fixed; top: 0; left: 0; right: 0; text-align: center; background: #6b4a12; color: #ffe6b3; padding: 4px; font-size: 13px; z-index: 30;
}

@media (max-width: 900px) {
  .app { grid-template-columns: 64px 220px minmax(0, 1fr); }
  .members { display: none; }
}
