:root {
  --bg-0: #1e1f22; --bg-1: #2b2d31; --bg-2: #313338; --bg-3: #383a40; --bg-hover: #35373c;
  --text: #dbdee1; --text-strong: #f2f3f5; --muted: #949ba4;
  --accent: #5865f2; --green: #23a55a; --red: #da373c; --yellow: #f0b232;
  --radius: 8px;
  font-family: "gg sans", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg-2); color: var(--text); }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .4; cursor: not-allowed; }
input, textarea { font: inherit; color: var(--text); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }

/* Login */
.login { display: grid; place-items: center; height: 100%; background: radial-gradient(circle at 30% 20%, #3c45a5 0, var(--bg-0) 60%); }
.login-card { background: var(--bg-2); padding: 32px; border-radius: 12px; width: min(380px, 92vw); display: grid; gap: 14px; box-shadow: 0 10px 40px #0008; }
.login-card label { display: grid; gap: 6px; font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--muted); }
.login-card input { background: var(--bg-0); border: 0; border-radius: 4px; padding: 10px; font-size: 15px; text-transform: none; }
.logo { font-size: 24px; font-weight: 800; color: var(--text-strong); }
.btn { border: 0; border-radius: 4px; padding: 10px 16px; font-weight: 600; }
.btn.primary { background: var(--accent); color: #fff; }
.error { color: #fa777c; font-size: 13px; min-height: 1em; }

/* Layout */
.app { display: grid; grid-template-columns: 250px 1fr 220px; height: 100%; }
.sidebar { background: var(--bg-1); display: flex; flex-direction: column; min-height: 0; }
.server-name { padding: 14px 16px; font-weight: 800; color: var(--text-strong); border-bottom: 1px solid var(--bg-0); }
.channels { flex: 1; overflow-y: auto; padding: 8px; }
.section-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 8px 4px; font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--muted); }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 4px; }
.icon-btn:hover { color: var(--text-strong); }
.icon-btn.danger:hover { color: var(--red); }
ul { list-style: none; margin: 0; padding: 0; }
.ch { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 4px; color: var(--muted); cursor: pointer; user-select: none; }
.ch:hover { background: var(--bg-hover); color: var(--text); }
.ch.active { background: var(--bg-3); color: var(--text-strong); }
.ch.unread { color: var(--text-strong); font-weight: 700; }
.ch .badge { margin-left: auto; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; border-radius: 8px; padding: 0 6px; }
.ch .ico { width: 18px; text-align: center; opacity: .8; }
.voice-users { padding-left: 30px; }
.voice-users li { display: flex; align-items: center; gap: 6px; padding: 3px 4px; font-size: 13px; color: var(--muted); }
.voice-users .flags { margin-left: auto; font-size: 11px; }

.voice-panel { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-top: 1px solid var(--bg-0); background: #232428; }
.vp-status { display: flex; gap: 8px; align-items: center; color: var(--green); font-size: 13px; }
.vp-status b { color: var(--green); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.live { background: var(--green); box-shadow: 0 0 6px var(--green); }

.user-panel { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: #232428; }
.me-name { flex: 1; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.controls { display: flex; gap: 2px; }
.ctl { background: none; border: 0; border-radius: 4px; width: 30px; height: 30px; font-size: 15px; position: relative; }
.ctl:hover:not(:disabled) { background: var(--bg-3); }
.ctl.off::after, .round.off::after { content: ""; position: absolute; left: 50%; top: 15%; height: 70%; width: 2px; background: var(--red); transform: rotate(45deg); }
.ctl.on, .round.on { background: var(--green) !important; }

.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; font-size: 14px; }
.avatar.sm { width: 22px; height: 22px; font-size: 11px; }
.avatar.speaking { box-shadow: 0 0 0 2px var(--bg-1), 0 0 0 4px var(--green); }

/* Main */
.main { display: flex; min-width: 0; min-height: 0; position: relative; }
.view { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--bg-0); color: var(--text-strong); box-shadow: 0 1px 2px #0003; }
.hash { color: var(--muted); font-size: 20px; }

.messages { flex: 1; overflow-y: auto; padding: 16px 0; }
.msg { display: grid; grid-template-columns: 56px 1fr; padding: 2px 16px 2px 0; position: relative; }
.msg:hover { background: #2e3035; }
.msg.head { margin-top: 14px; }
.msg .avatar { margin: 2px auto 0; width: 38px; height: 38px; }
.msg .meta { display: flex; gap: 8px; align-items: baseline; }
.msg .author { font-weight: 600; }
.msg .time { font-size: 11px; color: var(--muted); }
.msg .text { white-space: pre-wrap; word-wrap: break-word; line-height: 1.4; }
.msg .text code { background: var(--bg-0); padding: 1px 4px; border-radius: 3px; font-size: 90%; }
.msg .text a { color: #00a8fc; }
.msg .hovertime { font-size: 10px; color: var(--muted); text-align: center; visibility: hidden; padding-top: 3px; }
.msg:hover .hovertime { visibility: visible; }
.msg .del { position: absolute; right: 16px; top: -6px; display: none; background: var(--bg-2); border: 1px solid var(--bg-0); border-radius: 4px; color: var(--muted); font-size: 12px; padding: 2px 6px; }
.msg:hover .del { display: block; }
.msg .del:hover { color: var(--red); }
.load-more { text-align: center; color: var(--muted); font-size: 12px; padding: 8px; }
.day-sep { display: flex; align-items: center; gap: 8px; margin: 16px 16px 4px; color: var(--muted); font-size: 12px; font-weight: 600; }
.day-sep::before, .day-sep::after { content: ""; flex: 1; height: 1px; background: var(--bg-3); }
.typing { height: 20px; padding: 0 16px; font-size: 12px; color: var(--muted); }
.composer { padding: 0 16px 20px; }
.composer textarea { width: 100%; resize: none; background: var(--bg-3); border: 0; border-radius: var(--radius); padding: 12px 14px; max-height: 200px; outline: none; font-size: 15px; }

/* Voice stage */
.stage { flex: 1; display: grid; gap: 10px; padding: 16px; background: #000; overflow: auto; align-content: center; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.stage.focus { grid-template-columns: 1fr; grid-auto-rows: auto; align-content: stretch; }
.stage.focus .tile:not(.focused) { display: none; }
.tile { position: relative; background: var(--bg-1); border-radius: var(--radius); aspect-ratio: 16 / 9; overflow: hidden; display: grid; place-items: center; cursor: pointer; outline: 2px solid transparent; transition: outline-color .1s; }
.tile.speaking { outline-color: var(--green); }
.tile video { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; background: #000; }
.tile.screen video, .stage.focus .tile video { object-fit: contain; }
.tile.mirror video { transform: scaleX(-1); }
.tile .big-avatar { width: 80px; height: 80px; border-radius: 50%; display: grid; place-items: center; font-size: 32px; font-weight: 700; color: #fff; }
.tile .label { position: absolute; left: 8px; bottom: 8px; background: #000a; padding: 3px 8px; border-radius: 4px; font-size: 13px; display: flex; gap: 6px; align-items: center; }
.tile.novideo video { display: none; }
.stage-controls { display: flex; justify-content: center; gap: 14px; padding: 14px; background: #000; }
.round { width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--bg-3); font-size: 20px; position: relative; }
.round:hover { filter: brightness(1.2); }
.round.danger { background: var(--red); }

/* Members */
.members { background: var(--bg-1); padding: 8px; overflow-y: auto; }
.member { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 4px; }
.member:hover { background: var(--bg-hover); }
.member .sub { font-size: 11px; color: var(--muted); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--bg-0); color: var(--text-strong); padding: 10px 16px; border-radius: 6px; box-shadow: 0 4px 20px #0008; z-index: 10; font-size: 14px; }

@media (max-width: 900px) {
  .app { grid-template-columns: 220px 1fr; }
  .members { display: none; }
}
@media (max-width: 600px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 40vh; }
}
