:root {
  --bg-rail: #1b1d23;
  --bg-sidebar: #23262e;
  --bg-chat: #2c2f37;
  --bg-input: #393c45;
  --bg-hover: #353841;
  --bg-active: #41444e;
  --bg-mention: rgba(250, 166, 26, 0.1);
  --border: #1f2128;
  --text: #e3e5ea;
  --text-muted: #9a9ea8;
  --text-strong: #ffffff;
  --accent: #5b6cf0;
  --accent-hover: #4a5ad8;
  --danger: #ed4245;
  --online: #3ba55d;
  --link: #3fa9f5;
  --radius: 8px;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg-rail); color: var(--text); display: flex; flex-direction: column; overflow: hidden; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--link); }
.muted { color: var(--text-muted); }
.small { font-size: 12.5px; }
.strong { color: var(--text-strong); font-weight: 600; }
.error { color: var(--danger); font-size: 13px; min-height: 1em; margin: 4px 0; }

button.primary { background: var(--accent); border: 0; border-radius: 4px; padding: 10px 16px; color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent-hover); }
.icon-button { background: none; border: 0; color: var(--text-muted); font-size: 18px; padding: 6px; border-radius: 4px; }
.icon-button:hover { background: var(--bg-hover); color: var(--text); }

/* --- custom titlebar (desktop shell only; the window is frameless like Discord's) --- */
#titlebar { height: 28px; display: flex; align-items: stretch; background: var(--bg-rail); flex: none; }
.titlebar-drag { flex: 1; -webkit-app-region: drag; display: flex; align-items: center; padding-left: 12px; font-size: 12px; font-weight: 700; color: var(--text-muted); }
.titlebar-controls { display: flex; -webkit-app-region: no-drag; }
.titlebar-controls button { width: 46px; background: none; border: 0; color: var(--text-muted); }
.titlebar-controls button:hover { background: var(--bg-hover); color: var(--text); }
.titlebar-controls button.close:hover { background: var(--danger); color: #fff; }

/* --- auth --- */
.auth { flex: 1; display: grid; place-items: center; background: radial-gradient(circle at 30% 20%, #3a3f8f, #1b1d23 60%); }
.auth-card { background: var(--bg-sidebar); padding: 32px; border-radius: var(--radius); width: min(440px, 92vw); display: flex; flex-direction: column; gap: 12px; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4); }
.auth-card h1 { margin: 0; text-align: center; color: var(--text-strong); font-size: 24px; }
.auth-card > p { margin: 0; text-align: center; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-muted); }
input, textarea { font: inherit; color: var(--text); background: var(--bg-rail); border: 0; border-radius: 4px; padding: 10px; outline: none; }
input:focus, textarea:focus { box-shadow: 0 0 0 2px var(--accent); }

/* --- app layout --- */
.app { flex: 1; display: grid; grid-template-columns: 72px 240px 1fr 240px; min-height: 0; }

.guild-rail { background: var(--bg-rail); display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 0; overflow-y: auto; }
.guild-icon { position: relative; width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--bg-chat); color: var(--text); font-weight: 600; font-size: 16px; display: grid; place-items: center; transition: border-radius 0.15s, background 0.15s; flex: none; }
.guild-icon:hover, .guild-icon.active { border-radius: 16px; background: var(--accent); color: #fff; }
.guild-icon.action { color: var(--online); font-size: 24px; }
.guild-icon.action:hover { background: var(--online); color: #fff; }
.guild-icon::before { content: ''; position: absolute; left: -16px; width: 8px; border-radius: 0 4px 4px 0; background: var(--text-strong); height: 0; transition: height 0.15s; }
.guild-icon.unread::before { height: 8px; }
.guild-icon:hover::before { height: 20px; }
.guild-icon.active::before { height: 40px; }
.rail-separator { width: 32px; height: 2px; background: var(--bg-active); border-radius: 1px; flex: none; }

.sidebar { background: var(--bg-sidebar); display: flex; flex-direction: column; min-height: 0; }
.sidebar-header { height: 48px; padding: 0 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); font-weight: 700; color: var(--text-strong); flex: none; }
.sidebar-header .icon-button { font-size: 14px; }
.channel-list { flex: 1; overflow-y: auto; padding: 12px 8px; }
.channel-category { display: flex; justify-content: space-between; align-items: center; padding: 4px 8px; font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-muted); }
.channel { display: flex; align-items: center; gap: 6px; width: 100%; text-align: left; padding: 6px 8px; margin: 1px 0; border: 0; border-radius: 4px; background: none; color: var(--text-muted); }
.channel .icon { opacity: 0.7; flex: none; }
.channel:hover { background: var(--bg-hover); color: var(--text); }
.channel.active { background: var(--bg-active); color: var(--text-strong); }
.channel.unread { color: var(--text-strong); font-weight: 600; }
.empty-state { padding: 24px; text-align: center; }

.user-panel { height: 56px; display: flex; align-items: center; gap: 8px; padding: 0 8px; background: #1f2128; flex: none; }
.user-panel-names { flex: 1; min-width: 0; }
.user-panel-names div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; position: relative; }
.avatar.large { width: 40px; height: 40px; }
.avatar .status { position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%; border: 3px solid var(--bg-sidebar); background: #80848e; }
.avatar .status.online { background: var(--online); }

/* --- chat --- */
.chat { background: var(--bg-chat); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-header { height: 48px; display: flex; align-items: center; gap: 8px; padding: 0 16px; border-bottom: 1px solid var(--border); flex: none; min-width: 0; }
.chat-header .channel-title { font-weight: 700; color: var(--text-strong); white-space: nowrap; }
.chat-header .channel-title::before { content: '# '; color: var(--text-muted); }
.chat-header .topic { border-left: 1px solid var(--bg-active); padding-left: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.messages { flex: 1; overflow-y: auto; padding: 16px 0 8px; outline: none; }
.channel-start { padding: 16px; margin-bottom: 8px; }
.channel-start h2 { color: var(--text-strong); margin: 0 0 4px; font-size: 28px; }
.message { position: relative; display: grid; grid-template-columns: 56px 1fr; padding: 2px 48px 2px 16px; }
.message.group-start { margin-top: 16px; }
.message:hover { background: rgba(0, 0, 0, 0.08); }
.message.mentioned { background: var(--bg-mention); box-shadow: inset 2px 0 0 #faa61a; }
.message .gutter { display: flex; justify-content: flex-start; }
.message .gutter time { visibility: hidden; font-size: 11px; color: var(--text-muted); padding-top: 4px; }
.message:hover .gutter time { visibility: visible; }
.message .meta { display: flex; align-items: baseline; gap: 8px; }
.message .author { font-weight: 600; color: var(--text-strong); }
.message .meta time { font-size: 12px; color: var(--text-muted); }
.message .content { white-space: pre-wrap; word-wrap: break-word; line-height: 1.375; }
.message .edited { font-size: 11px; color: var(--text-muted); margin-left: 4px; }
.message .actions { position: absolute; right: 16px; top: -12px; display: none; background: var(--bg-sidebar); border: 1px solid var(--border); border-radius: 4px; }
.message:hover .actions { display: flex; }
.message .actions button { background: none; border: 0; padding: 4px 8px; color: var(--text-muted); font-size: 13px; }
.message .actions button:hover { color: var(--text); background: var(--bg-hover); }
.message .actions button.danger:hover { color: var(--danger); }
.message textarea.edit { width: 100%; resize: none; background: var(--bg-input); }
.message .edit-hint { font-size: 12px; }
.content code { background: var(--bg-rail); border-radius: 3px; padding: 1px 4px; font-family: Consolas, monospace; font-size: 85%; }
.content pre { background: var(--bg-rail); border: 1px solid var(--border); border-radius: 4px; padding: 8px; margin: 4px 0; overflow-x: auto; }
.content pre code { background: none; padding: 0; }
.content .mention { background: rgba(91, 108, 240, 0.3); color: #c9cdfb; border-radius: 3px; padding: 0 2px; font-weight: 500; }

.composer-wrap { padding: 0 16px 4px; flex: none; }
.composer { display: flex; align-items: flex-start; background: var(--bg-input); border-radius: var(--radius); }
.composer textarea { flex: 1; resize: none; max-height: 40vh; background: transparent; padding: 12px 16px 12px 4px; line-height: 1.375; }
.composer textarea:focus { box-shadow: none; }
.attach-button { background: none; border: 0; color: var(--text-muted); padding: 10px 12px; display: grid; place-items: center; }
.attach-button:hover { color: var(--text); }
.typing { height: 20px; padding: 2px 4px; }
.typing strong { color: var(--text); }

/* --- members --- */
.member-list { background: var(--bg-sidebar); overflow-y: auto; padding: 16px 8px; }
.member-group { padding: 16px 8px 4px; font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-muted); }
.member-group:first-child { padding-top: 0; }
.member { display: flex; align-items: center; gap: 12px; padding: 6px 8px; border-radius: 4px; }
.member:hover { background: var(--bg-hover); }
.member.offline { opacity: 0.4; }
.member .crown { color: #faa61a; font-size: 12px; }

/* --- misc --- */
.connection-banner { position: fixed; top: 36px; left: 50%; transform: translateX(-50%); background: var(--danger); color: #fff; padding: 6px 14px; border-radius: 4px; font-size: 13px; font-weight: 600; z-index: 10; }
.modal { background: var(--bg-sidebar); color: var(--text); border: 0; border-radius: var(--radius); padding: 24px; width: min(440px, 92vw); }
.modal::backdrop { background: rgba(0, 0, 0, 0.7); }
.modal h2 { margin-top: 0; color: var(--text-strong); }
.modal input { width: 100%; }
.modal input[readonly] { user-select: all; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-actions button:not(.primary) { background: none; border: 0; padding: 10px 16px; }

@media (max-width: 1000px) {
  .app { grid-template-columns: 72px 220px 1fr; }
  .member-list { display: none; }
}

/* --- shared --- */
.icon { display: block; }
.toasts { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 20; }
.toast { background: var(--bg-rail); border: 1px solid var(--bg-active); border-left: 4px solid var(--danger); padding: 10px 14px; border-radius: 6px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4); max-width: 480px; }
.toast.info { border-left-color: var(--accent); }

/* --- uploads in the composer --- */
.pending-uploads { display: flex; gap: 8px; overflow-x: auto; background: var(--bg-input); border-radius: var(--radius) var(--radius) 0 0; padding: 12px 12px 4px; border-bottom: 1px solid var(--bg-active); }
.pending-uploads:not([hidden]) + .composer { border-radius: 0 0 var(--radius) var(--radius); }
.pending { position: relative; width: 160px; flex: none; background: var(--bg-sidebar); border-radius: 6px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.pending .preview { height: 96px; border-radius: 4px; background: var(--bg-rail); display: grid; place-items: center; overflow: hidden; color: var(--text-muted); }
.pending .preview img, .pending .preview video { width: 100%; height: 100%; object-fit: cover; }
.pending .name { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pending progress { width: 100%; height: 4px; appearance: none; border: 0; background: var(--bg-active); border-radius: 2px; }
.pending progress::-webkit-progress-bar { background: var(--bg-active); border-radius: 2px; }
.pending progress::-webkit-progress-value { background: var(--accent); border-radius: 2px; }
.pending.failed progress::-webkit-progress-value { background: var(--danger); }
.pending .remove { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--danger); color: #fff; display: grid; place-items: center; padding: 0; }

.drop-overlay { position: absolute; inset: 0; background: rgba(91, 108, 240, 0.85); display: grid; place-items: center; z-index: 5; pointer-events: none; }
.drop-card { border: 2px dashed rgba(255, 255, 255, 0.7); border-radius: 12px; padding: 32px 48px; display: flex; flex-direction: column; align-items: center; gap: 6px; color: #fff; font-size: 18px; }
.drop-card .muted { color: rgba(255, 255, 255, 0.85); font-size: 14px; }
.chat { position: relative; }

/* --- attachments and embeds in messages --- */
.attachments { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; align-items: flex-start; }
.attachment-image { max-width: min(400px, 100%); max-height: 300px; border-radius: 6px; cursor: zoom-in; display: block; background: var(--bg-rail); }
.attachment-video { max-width: min(480px, 100%); max-height: 360px; border-radius: 6px; background: #000; display: block; }
.file-card { display: flex; align-items: center; gap: 12px; background: var(--bg-sidebar); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; width: min(420px, 100%); }
.file-card .icon { color: var(--link); flex: none; }
.file-card .meta-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-card .file-name { color: var(--link); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: none; }
.file-card .file-name:hover { text-decoration: underline; }
.file-card audio { width: 100%; margin-top: 8px; height: 36px; }
.file-card.audio { flex-wrap: wrap; }
.file-card .download { color: var(--text-muted); }
.file-card .download:hover { color: var(--text); }

.embed { margin-top: 6px; background: var(--bg-sidebar); border-left: 4px solid var(--bg-active); border-radius: 4px; padding: 10px 14px 14px; max-width: 432px; display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; }
.embed > * { grid-column: 1; min-width: 0; }
.embed .provider { font-size: 12px; color: var(--text-muted); }
.embed .author { font-size: 13.5px; font-weight: 600; color: var(--text-strong); }
.embed .title { font-weight: 600; color: var(--link); text-decoration: none; }
.embed .title:hover { text-decoration: underline; }
.embed .description { font-size: 13.5px; color: var(--text); white-space: pre-line; }
.embed .thumb { grid-column: 2; grid-row: 1 / span 4; width: 80px; height: 80px; object-fit: cover; border-radius: 4px; }
.embed .media { grid-column: 1 / -1; max-width: 400px; max-height: 300px; border-radius: 4px; display: block; }
.embed.bare { padding: 0; background: none; border: 0; display: block; }
.embed-player { grid-column: 1 / -1; position: relative; width: 400px; max-width: 100%; aspect-ratio: 16 / 9; border-radius: 4px; overflow: hidden; background: #000; }
.embed-player img { width: 100%; height: 100%; object-fit: cover; display: block; }
.embed-player iframe { width: 100%; height: 100%; border: 0; display: block; }
.embed-player .play { position: absolute; inset: 0; margin: auto; width: 56px; height: 56px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, 0.7); color: #fff; display: grid; place-items: center; }
.embed-player .play:hover { background: rgba(0, 0, 0, 0.85); transform: scale(1.05); }

.lightbox { background: none; border: 0; padding: 0; max-width: 92vw; max-height: 92vh; overflow: visible; }
.lightbox::backdrop { background: rgba(0, 0, 0, 0.85); }
.lightbox img { max-width: 92vw; max-height: 86vh; display: block; border-radius: 4px; }
.lightbox-bar { padding-top: 8px; }
.lightbox-bar a { color: var(--text-muted); font-size: 14px; }

/* --- voice channels in the sidebar --- */
.voice-users { display: flex; flex-direction: column; gap: 2px; margin: 0 0 6px 28px; }
.voice-user { display: flex; align-items: center; gap: 8px; padding: 3px 6px; border-radius: 4px; color: var(--text-muted); font-size: 14px; }
.voice-user .avatar { width: 24px; height: 24px; font-size: 12px; }
.voice-user .name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.voice-user .flags { display: flex; gap: 4px; align-items: center; color: var(--text-muted); }
.voice-user .flags .off { color: var(--danger); }
.speaking .avatar, .tile.speaking { box-shadow: 0 0 0 2px var(--online); }
.live-badge { background: var(--danger); color: #fff; font-size: 10px; font-weight: 800; padding: 1px 5px; border-radius: 8px; letter-spacing: 0.04em; }

.voice-panel { border-top: 1px solid var(--border); background: #1f2128; padding: 8px 10px; display: flex; flex-direction: column; gap: 8px; flex: none; }
.voice-panel .status { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.voice-panel .status-text { min-width: 0; }
.voice-panel .connected { color: var(--online); font-weight: 700; font-size: 13.5px; }
.voice-panel .connected.connecting { color: #faa61a; }
.voice-panel .where { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.voice-panel .controls { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.voice-panel .controls button { background: var(--bg-sidebar); border: 0; border-radius: 4px; padding: 6px; display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 13px; color: var(--text); }
.voice-panel .controls button:hover { background: var(--bg-hover); }
.voice-panel .controls button.on { color: var(--online); }
.user-panel-controls { display: flex; }
.icon-button .off { color: var(--danger); }

/* --- call view --- */
.call-view { flex: 1; min-height: 0; background: #000; display: flex; flex-direction: column; }
.call-grid { flex: 1; min-height: 0; display: grid; gap: 8px; padding: 16px; align-content: center; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); grid-auto-rows: minmax(160px, 1fr); }
.tile { position: relative; background: var(--bg-sidebar); border-radius: 8px; overflow: hidden; display: grid; place-items: center; min-height: 160px; }
.tile video { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; background: #000; }
.tile.screen video { object-fit: contain; }
.tile.mirror video { transform: scaleX(-1); }
.tile .avatar { width: 80px; height: 80px; font-size: 32px; }
.tile .label { position: absolute; left: 8px; bottom: 8px; background: rgba(0, 0, 0, 0.6); color: #fff; padding: 3px 8px; border-radius: 4px; font-size: 13px; display: flex; gap: 6px; align-items: center; }
.tile .label .off { color: var(--danger); }
.tile .state { position: absolute; right: 8px; top: 8px; font-size: 11px; color: #faa61a; background: rgba(0, 0, 0, 0.6); padding: 2px 6px; border-radius: 4px; }
.tile .fullscreen-btn { position: absolute; right: 8px; bottom: 8px; background: rgba(0, 0, 0, 0.6); color: #fff; border: 0; border-radius: 4px; padding: 4px; display: none; }
.tile:hover .fullscreen-btn { display: block; }
.call-bar { display: flex; justify-content: center; gap: 12px; padding: 12px 0 20px; }
.call-bar button { width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--bg-active); color: var(--text-strong); display: grid; place-items: center; }
.call-bar button:hover { filter: brightness(1.2); }
.call-bar button.on { background: #fff; color: #000; }
.call-bar button.active-off { background: var(--danger); color: #fff; }
.call-bar button.hangup { background: var(--danger); color: #fff; }
.call-join { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 48px; color: var(--text); margin: auto; }
.call-join h2 { margin: 0; color: var(--text-strong); }
.call-join button.primary { background: var(--online); }

.voice-panel button.where { background: none; border: 0; padding: 0; cursor: pointer; text-align: left; max-width: 100%; display: block; }
.voice-panel button.where:hover { color: var(--text); text-decoration: underline; }
.chat-header .channel-title.voice::before { content: none; }
.chat-header .icon { color: var(--text-muted); }
.empty-state.welcome { margin: auto; max-width: 420px; padding-top: 12vh; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.empty-state.welcome h2 { color: var(--text-strong); margin: 0; }
.welcome-actions { display: flex; gap: 12px; margin-top: 12px; flex-wrap: wrap; justify-content: center; }
button.secondary { background: var(--bg-active); border: 0; border-radius: 4px; padding: 10px 16px; color: var(--text-strong); font-weight: 600; }
button.secondary:hover { background: var(--bg-hover); }
.member .member-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member .mod-actions { display: none; gap: 4px; }
.member:hover .mod-actions { display: flex; }
.member .mod-actions button { background: var(--bg-active); border: 0; border-radius: 3px; padding: 2px 6px; font-size: 11.5px; color: var(--text); }
.member .mod-actions button.danger:hover { background: var(--danger); color: #fff; }
