:root {
  --bg-0: #1e1f22;
  --bg-1: #2b2d31;
  --bg-2: #313338;
  --bg-3: #383a40;
  --bg-hover: #35373c;
  --text: #dbdee1;
  --text-muted: #949ba4;
  --accent: #e8590c;
  --accent-hover: #d9480f;
  --green: #23a55a;
  --red: #da373c;
  --radius: 8px;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg-2);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: #00a8fc; text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.small { font-size: 12.5px; }
.error { color: #fa777c; min-height: 1em; margin: 0; }
.center { display: flex; align-items: center; justify-content: center; }

.screen { position: fixed; inset: 0; }
.screen.center { background: linear-gradient(135deg, #1b1c1f, #3a2418); }
.card { background: var(--bg-2); padding: 28px 32px; border-radius: var(--radius); width: 420px; max-width: calc(100vw - 32px); box-shadow: 0 8px 32px rgba(0,0,0,.35); }
.card h1, .card h2 { margin: 0 0 6px; text-align: center; }
.card > p { text-align: center; }
form.card { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; text-transform: uppercase; color: var(--text-muted); }
input, textarea, select { background: var(--bg-0); border: 1px solid transparent; border-radius: 4px; padding: 10px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
button { cursor: pointer; border: 0; border-radius: 4px; padding: 10px 14px; background: var(--bg-3); }
button:hover { filter: brightness(1.1); }
button.primary { background: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent-hover); filter: none; }
button.secondary { background: var(--bg-3); }
button.danger { background: var(--red); color: #fff; }
.small-btn { padding: 4px 10px; font-size: 12.5px; }
.divider { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 12px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--bg-3); }

/* ---------- App layout ---------- */
#screen-app { display: grid; grid-template-columns: 72px 240px 1fr 220px; }
#guild-rail { background: var(--bg-0); padding: 12px 0; display: flex; flex-direction: column; align-items: center; gap: 8px; overflow-y: auto; }
#guild-list { display: flex; flex-direction: column; gap: 8px; }
.guild-icon { width: 48px; height: 48px; border-radius: 50%; background: var(--bg-2); display: flex; align-items: center; justify-content: center; font-weight: 600; padding: 0; transition: border-radius .15s, background .15s; position: relative; }
.guild-icon:hover, .guild-icon.active { border-radius: 16px; background: var(--accent); color: #fff; }
.guild-icon.add { color: var(--green); font-size: 24px; }
.guild-icon.add:hover { background: var(--green); color: #fff; }
.guild-icon.unread::before { content: ""; position: absolute; left: -12px; width: 8px; height: 8px; border-radius: 4px; background: #fff; }

#sidebar { background: var(--bg-1); display: flex; flex-direction: column; min-width: 0; }
#guild-header { height: 48px; padding: 0 12px 0 16px; display: flex; align-items: center; justify-content: space-between; font-weight: 600; border-bottom: 1px solid var(--bg-0); }
#guild-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { background: transparent; padding: 6px; border-radius: 4px; color: var(--text-muted); font-size: 16px; line-height: 1; }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.off { color: var(--red); }
#channel-list { flex: 1; overflow-y: auto; padding: 8px; }
.channel-group { margin-top: 12px; display: flex; justify-content: space-between; align-items: center; padding: 0 4px 4px; font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-muted); }
.channel-group button { padding: 0 4px; background: transparent; color: var(--text-muted); font-size: 16px; }
.channel { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 4px; color: var(--text-muted); cursor: pointer; user-select: none; }
.channel:hover { background: var(--bg-hover); color: var(--text); }
.channel.active { background: var(--bg-3); color: #fff; }
.channel.unread { color: #fff; font-weight: 600; }
.channel .sym { width: 18px; text-align: center; opacity: .8; }
.channel .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel .del { visibility: hidden; padding: 0 4px; background: transparent; color: var(--text-muted); }
.channel:hover .del { visibility: visible; }
.voice-users { padding: 0 0 4px 30px; }
.voice-user { display: flex; align-items: center; gap: 6px; padding: 3px 4px; font-size: 13.5px; color: var(--text-muted); }
.voice-user .avatar { width: 22px; height: 22px; font-size: 11px; }
.voice-user.speaking .avatar { box-shadow: 0 0 0 2px var(--green); }
.voice-user .flags { margin-left: auto; color: var(--red); font-size: 12px; }

#voice-panel { border-top: 1px solid var(--bg-0); padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; background: #232428; }
.voice-status { display: flex; align-items: center; gap: 6px; color: var(--green); font-weight: 600; font-size: 13.5px; }
.voice-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.voice-status.connecting { color: #f0b232; }
.voice-status.connecting .dot { background: #f0b232; }
#voice-mode-hint.tx { color: var(--green); font-weight: 600; }
#voice-leave { align-self: flex-start; }

#user-panel { height: 56px; background: #232428; display: flex; align-items: center; gap: 6px; padding: 0 8px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; position: relative; font-size: 14px; }
.avatar.online::after { content: ""; position: absolute; right: -2px; bottom: -2px; width: 10px; height: 10px; border-radius: 50%; background: var(--green); border: 3px solid var(--bg-1); }
.me-info { flex: 1; min-width: 0; }
.me-info > div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#me-name { font-weight: 600; font-size: 14px; }

#chat { display: flex; flex-direction: column; min-width: 0; position: relative; }
#chat-header { height: 48px; padding: 0 16px; display: flex; align-items: center; gap: 6px; font-weight: 600; border-bottom: 1px solid var(--bg-0); flex-shrink: 0; }
#chat-header .hash { color: var(--text-muted); font-size: 22px; }
#messages { flex: 1; overflow-y: auto; padding: 16px 0 8px; }
.load-more { display: block; margin: 0 auto 12px; }
.msg { display: grid; grid-template-columns: 40px 1fr; column-gap: 14px; padding: 2px 16px; position: relative; }
.msg:hover { background: #2e3035; }
.msg.head { margin-top: 14px; }
.msg .avatar { width: 40px; height: 40px; grid-row: span 2; }
.msg:not(.head) .avatar { visibility: hidden; height: 0; }
.msg .meta { display: flex; align-items: baseline; gap: 8px; }
.msg:not(.head) .meta { display: none; }
.msg .author { font-weight: 600; color: #fff; }
.msg .time { font-size: 11.5px; color: var(--text-muted); }
.msg .content { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; line-height: 1.4; }
.msg .edited { font-size: 11px; color: var(--text-muted); margin-left: 4px; }
.msg .actions { position: absolute; right: 16px; top: -12px; display: none; background: var(--bg-2); border: 1px solid var(--bg-0); border-radius: 4px; }
.msg:hover .actions { display: flex; }
.msg .actions button { background: transparent; padding: 4px 8px; font-size: 12.5px; }
.msg .edit-box { width: 100%; resize: none; }
.msg.mention { background: rgba(240, 178, 50, .08); box-shadow: inset 2px 0 0 #f0b232; }
#typing { height: 20px; padding: 0 16px; }
#composer { padding: 0 16px 20px; }
#composer-input { width: 100%; resize: none; background: var(--bg-3); border-radius: var(--radius); padding: 12px 14px; max-height: 40vh; }
#chat-empty { position: absolute; inset: 0; background: var(--bg-2); }

#members { background: var(--bg-1); padding: 16px 8px; overflow-y: auto; }
.member-group { font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--text-muted); padding: 12px 8px 4px; }
.member { display: flex; align-items: center; gap: 10px; padding: 5px 8px; border-radius: 4px; }
.member.offline { opacity: .4; }
.member .crown { color: #f0b232; font-size: 12px; }

/* ---------- Modals ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; z-index: 10; }
.modal { background: var(--bg-2); border-radius: var(--radius); width: 480px; max-width: calc(100vw - 32px); max-height: calc(100vh - 32px); overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.modal h2 { margin: 0; }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; }
.modal .seg { display: flex; gap: 8px; }
.modal .seg label { flex-direction: row; align-items: center; gap: 6px; text-transform: none; font-size: 14px; color: var(--text); font-weight: 400; }
.invite-code { display: flex; gap: 8px; }
.invite-code input { flex: 1; font-family: Consolas, monospace; }
.meter { height: 8px; background: var(--bg-0); border-radius: 4px; overflow: hidden; position: relative; }
.meter .fill { height: 100%; background: var(--green); width: 0; transition: width .05s; }
.meter .threshold { position: absolute; top: -2px; bottom: -2px; width: 2px; background: #f0b232; }
.keycap { display: inline-block; padding: 6px 12px; background: var(--bg-0); border-radius: 4px; font-family: Consolas, monospace; min-width: 120px; text-align: center; }
.keycap.capturing { outline: 2px solid var(--accent); }
.host-info { background: var(--bg-0); padding: 10px; border-radius: 4px; font-family: Consolas, monospace; font-size: 13px; white-space: pre-wrap; }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--bg-0); padding: 10px 16px; border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,.4); z-index: 20; }
#toast.error { background: #6b1d20; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: var(--bg-0); border-radius: 4px; }

.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
details summary { cursor: pointer; }
.invite-banner { background: rgba(232, 89, 12, .15); border: 1px solid rgba(232, 89, 12, .5); border-radius: 4px; padding: 8px 10px; font-size: 14px; text-align: center; margin: 0; }
.member { cursor: default; }
.context-menu { position: fixed; z-index: 30; background: var(--bg-0); border-radius: 6px; padding: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.5); min-width: 180px; }
.context-menu button { display: block; width: 100%; text-align: left; background: transparent; padding: 8px 10px; }
.context-menu button:hover { background: var(--accent); color: #fff; filter: none; }
.context-menu button.danger-item { color: #fa777c; }
.context-menu button.danger-item:hover { background: var(--red); color: #fff; }
.context-menu .slider-row { padding: 6px 10px; display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-muted); }
