:root {
  --bg: #313338;
  --sidebar: #2b2d31;
  --servers: #1e1f22;
  --hover: #35373c;
  --active: #404249;
  --text: #dbdee1;
  --muted: #949ba4;
  --accent: #5865f2;
  --green: #23a559;
  --danger: #f23f43;
  --input: #383a40;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: "gg sans", "Noto Sans", "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }

#login {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e1f22, #313338 50%, #5865f2);
}
.login-card {
  background: #2b2d31;
  padding: 40px 36px;
  border-radius: 8px;
  width: 420px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.logo { font-size: 32px; font-weight: 800; letter-spacing: 4px; color: #fff; margin-bottom: 8px; }
.login-card p { color: var(--muted); margin-bottom: 24px; }
.login-card input, .settings-card select, .settings-card input[type="range"] {
  width: 100%; padding: 12px; border: none; border-radius: 4px;
  background: #1e1f22; color: #fff; font-size: 16px; margin-bottom: 16px;
}
.login-card button, .settings-card button {
  width: 100%; padding: 12px; border: none; border-radius: 4px;
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 600; cursor: pointer;
}
.login-card button:hover, .settings-card button:hover { filter: brightness(1.1); }
.login-error { color: #f23f43; margin-top: 14px; font-size: 14px; line-height: 1.4; }

#app { display: flex; height: 100%; }

.servers {
  width: 72px; background: var(--servers); display: flex; flex-direction: column;
  align-items: center; padding: 12px 0; gap: 8px;
}
.server-icon {
  width: 48px; height: 48px; border-radius: 50%; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; cursor: pointer; transition: border-radius .15s;
  position: relative;
}
.badge {
  position: absolute; top: -4px; right: -4px;
  background: #f23f43; color: #fff; font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}
.ch.unread { color: #fff; font-weight: 700; }
.server-icon.active, .server-icon:hover { border-radius: 16px; background: var(--accent); }
.server-icon.add { background: #232428; color: var(--green); font-size: 22px; }
.server-sep { width: 32px; height: 2px; background: #3f4147; margin: 4px 0; }
.server-title { display: flex; align-items: center; justify-content: space-between; }
.server-title button, .add-ch {
  background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 16px;
}
.add-ch { float: right; }
.section { overflow: hidden; }
#userMenuDm {
  margin-top: 10px; width: 100%; background: var(--accent); color: #fff; border: none;
  border-radius: 4px; padding: 8px; cursor: pointer;
}
#replyBar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 16px; background: #2b2d31; color: var(--muted); font-size: 13px;
}
.msg-actions { margin-top: 4px; display: none; gap: 8px; }
.msg:hover .msg-actions { display: flex; }
.msg-actions button {
  background: transparent; border: none; color: var(--muted); cursor: pointer; font-size: 12px;
}
.reply-quote { font-size: 12px; color: var(--muted); border-left: 2px solid var(--accent); padding-left: 6px; margin-bottom: 4px; }
.edited { font-size: 11px; color: var(--muted); margin-left: 6px; }
.prompt-actions { display: flex; gap: 8px; }
.prompt-actions .ghost { background: #4e5058; }
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: #111214; border: 1px solid #3f4147; padding: 10px 16px; border-radius: 8px; z-index: 40;
}

.channels {
  width: 240px; background: var(--sidebar); display: flex; flex-direction: column; position: relative; overflow: hidden;
}
#serverPanel, #homePanel { flex: 1; overflow-y: auto; padding-bottom: 60px; }
.server-title { padding: 16px; font-weight: 700; border-bottom: 1px solid rgba(0,0,0,.2); }
.section { padding: 18px 16px 6px; font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .4px; }
.ch {
  margin: 1px 8px; padding: 6px 8px; border-radius: 4px; cursor: pointer;
  color: var(--muted); display: flex; align-items: center; gap: 6px;
  position: relative;
}
.ch:hover { background: var(--hover); color: var(--text); }
.ch.active { background: var(--active); color: #fff; }
.ch .hash { color: var(--muted); font-weight: 700; }
.voice-users { padding-left: 16px; font-size: 13px; }
.voice-user { display: flex; align-items: center; gap: 6px; padding: 3px 8px; color: var(--text); flex-wrap: wrap; cursor: context-menu; }
.voice-user.speaking { color: var(--green); }
.voice-user img { width: 20px; height: 20px; border-radius: 50%; }
.live-tag { color: #f23f43; font-size: 11px; font-weight: 700; }
.watch-btn {
  margin-left: auto; border: none; border-radius: 4px; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 11px; padding: 2px 6px;
}
.watch-btn.off { background: #4e5058; }
.member { cursor: context-menu; }

#userMenu {
  position: fixed; z-index: 30; background: #111214; border: 1px solid #3f4147;
  border-radius: 8px; padding: 12px; width: 220px; box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
#userMenu.hidden { display: none !important; }
.user-menu-name { font-weight: 700; margin-bottom: 10px; }
#userMenu label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 6px; }
#userMenu input { width: 100%; accent-color: var(--accent); }

.user-bar {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: #232428; padding: 8px; display: flex; align-items: center; gap: 8px;
}
.user-bar img { width: 32px; height: 32px; border-radius: 50%; }
.user-bar .uname { font-size: 14px; font-weight: 600; }

main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#channelHeader {
  height: 48px; display: flex; align-items: center; padding: 0 16px;
  border-bottom: 1px solid rgba(0,0,0,.2); font-weight: 700;
}
#messages { flex: 1; overflow-y: auto; padding: 16px; }
.msg { display: flex; gap: 12px; padding: 4px 8px; border-radius: 4px; }
.msg:hover { background: rgba(0,0,0,.06); }
.msg img { width: 40px; height: 40px; border-radius: 50%; }
.msg .meta { font-size: 16px; font-weight: 600; }
.msg .time { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 8px; }
.msg .body { color: #dbdee1; margin-top: 2px; white-space: pre-wrap; word-break: break-word; }
.sys { text-align: center; color: var(--muted); font-size: 13px; padding: 8px; }

#msgForm { padding: 0 16px 24px; display: flex; gap: 8px; align-items: center; }
#msgInput {
  flex: 1; padding: 12px 16px; border: none; border-radius: 8px;
  background: var(--input); color: #fff; font-size: 15px;
}
.attach-btn {
  flex: 0 0 40px; height: 40px; border-radius: 8px; background: var(--input);
  color: #fff; display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 22px; user-select: none;
}
.attach-btn:hover { background: var(--hover); }
#typingLine { padding: 0 20px 8px; font-size: 12px; color: var(--muted); min-height: 18px; }
.msg-img { margin-top: 8px; }
.msg-img img { max-width: min(420px, 100%); border-radius: 8px; display: block; }

.members { width: 240px; background: var(--sidebar); padding: 8px 0; overflow-y: auto; }
.member { display: flex; align-items: center; gap: 8px; padding: 6px 16px; }
.member img { width: 32px; height: 32px; border-radius: 50%; }
.member.voice { color: var(--green); }

#voiceBar {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: #111214; border: 1px solid #3f4147; border-radius: 8px;
  padding: 10px 16px; display: flex; align-items: center; gap: 24px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5); z-index: 10;
}
.green-dot { width: 8px; height: 8px; background: var(--green); border-radius: 50%; display: inline-block; margin-right: 6px; }
.voice-controls button {
  background: #2b2d31; border: none; color: #fff; width: 36px; height: 36px;
  border-radius: 50%; cursor: pointer; font-size: 16px;
}
.voice-controls button.muted, .voice-controls button.danger { background: var(--danger); }
.voice-controls button:hover { filter: brightness(1.15); }
.voice-controls button.sharing { background: var(--green); }
.voice-controls button.share-text {
  width: auto; padding: 0 12px; border-radius: 18px; font-size: 13px; font-weight: 600;
}

#screenStage {
  margin: 12px 16px 0;
  background: #111214;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #3f4147;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 240px;
}
#screenStage.hidden { display: none !important; }
.screen-bar {
  padding: 8px 12px;
  font-size: 13px;
  color: var(--muted);
  background: #1e1f22;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#fsBtn {
  background: var(--accent); color: #fff; border: none; border-radius: 4px;
  padding: 6px 10px; cursor: pointer; font-size: 12px;
}
#screenVideo, #screenImg {
  width: 100%;
  flex: 1;
  min-height: 200px;
  background: #000;
  object-fit: contain;
}
#screenImg { display: none; }
#screenImg.show { display: block; }
#screenVideo.hide { display: none; }
#screenStage:fullscreen, #screenStage:-webkit-full-screen {
  width: 100%; height: 100%; margin: 0; border: none; border-radius: 0;
}
#screenStage:fullscreen #screenVideo,
#screenStage:fullscreen #screenImg,
#screenStage:-webkit-full-screen #screenVideo,
#screenStage:-webkit-full-screen #screenImg {
  height: calc(100% - 40px);
}

#settingsModal, #promptModal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 40;
}
#promptInput {
  width: 100%; padding: 12px; border: none; border-radius: 4px;
  background: #1e1f22; color: #fff; font-size: 16px; margin-bottom: 16px;
}
.settings-card {
  background: #2b2d31; padding: 24px; border-radius: 8px; width: 400px;
}
.settings-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.settings-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.settings-card .hint { font-size: 12px; color: var(--muted); margin: -8px 0 16px; }
.settings-card input[type="range"] { padding: 0; height: 8px; width: 100%; accent-color: var(--accent); }
.meter {
  height: 10px; background: #1e1f22; border-radius: 5px; overflow: hidden; margin-bottom: 10px;
}
#micMeter { height: 100%; width: 0; background: #23a559; }
#micTestBtn.on { background: #23a559 !important; }

@media (max-width: 800px) {
  .members { display: none; }
  .channels { width: 200px; }
}

#attachPreview {
  margin: 0 16px 8px; padding: 8px; background: #2b2d31; border-radius: 8px;
  display: flex; align-items: flex-start; gap: 8px; width: fit-content;
}
#attachPreview.hidden { display: none; }
#attachPreviewImg { max-height: 120px; max-width: 220px; border-radius: 6px; display: block; }
#attachClear {
  border: none; background: #1e1f22; color: #fff; width: 24px; height: 24px;
  border-radius: 4px; cursor: pointer;
}
main.drop-on { outline: 2px dashed #5865f2; outline-offset: -8px; }
.msg-img img {
  max-width: min(520px, 100%);
  max-height: 360px;
  width: auto;
  height: auto;
  object-fit: contain;
  cursor: zoom-in;
  border-radius: 8px;
}
#lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.82);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000; cursor: zoom-out;
}
#lightbox.hidden { display: none; }
#lightbox img {
  max-width: 92vw; max-height: 92vh; border-radius: 8px;
  object-fit: contain;
}
