:root {
  /* 디스코드 다크 테마 팔레트 */
  --bg-rail: #1e1f22;
  --bg-side: #2b2d31;
  --bg-main: #313338;
  --bg-raised: #383a40;
  --bg-hover: #35373c;
  --bg-active: #404249;
  --bg-panel: #232428;
  --bg-pop: #111214;
  --line: #3f4147;
  --text: #dbdee1;
  --text-2: #b5bac1;
  --text-3: #949ba4;
  --accent: #5865f2;
  --accent-2: #4752c4;
  --accent-ink: #ffffff;
  --green: #23a559;
  --yellow: #f0b232;
  --red: #f23f43;
  --offline: #80848e;
  --radius: 4px;
  --radius-lg: 8px;
  --font: "Pretendard Variable", Pretendard, "Noto Sans KR", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
* { scrollbar-width: thin; scrollbar-color: var(--bg-rail) transparent; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.45; color: var(--text); background: var(--bg-main); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; padding: 0; }
a { color: var(--accent); }
img, video { max-width: 100%; }
[hidden] { display: none !important; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── 로그인 ── */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(900px 500px at 15% -10%, rgba(63, 209, 192, .18), transparent 60%), var(--bg-rail); }
.auth-card { width: min(420px, 100%); background: var(--bg-side); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 32px; display: flex; flex-direction: column; gap: 14px; }
.auth-card h1 { margin: 0; font-size: 28px; letter-spacing: -.02em; }
.auth-sub { margin: -8px 0 8px; color: var(--text-2); }
.auth-card label, .field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-2); }
input:not([type=checkbox]):not([type=color]):not([type=file]), textarea, select { background: var(--bg-rail); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; color: var(--text); font-size: 15px; width: 100%; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
input[type=color] { width: 48px; height: 36px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg-rail); cursor: pointer; }
.auth-error { color: var(--red); font-size: 13px; min-height: 1em; }
.auth-hint { margin: 0; color: var(--text-3); font-size: 12px; }

/* ── 버튼 ── */
.btn { border-radius: var(--radius); padding: 10px 16px; font-weight: 600; transition: background .12s, filter .12s; white-space: nowrap; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: var(--bg-raised); color: var(--text); }
.btn.ghost:hover { background: var(--bg-hover); }
.btn.danger { background: var(--red); color: #fff; }
.btn.danger:hover { filter: brightness(1.1); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.big { padding: 14px 28px; font-size: 16px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 6px; color: var(--text-2); flex: none; }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.on { color: var(--accent); }
.icon-btn.off { color: var(--red); }
.icon-btn.danger:hover { color: var(--red); }
.icon-btn.round { background: var(--bg-raised); border-radius: 50%; width: 36px; height: 36px; }
.icon-btn svg, .mi svg { width: 20px; height: 20px; }

/* ── 전체 레이아웃 ── */
.app { display: grid; grid-template-columns: 72px 240px minmax(0, 1fr) auto; height: 100vh; height: 100dvh; overflow: hidden; }

/* 서버 레일 */
.rail { background: var(--bg-rail); display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px 0; overflow-y: auto; }
.rail-item { position: relative; width: 48px; height: 48px; border-radius: 50%; background: var(--bg-raised); display: grid; place-items: center; font-weight: 700; font-size: 15px; color: var(--text); transition: border-radius .15s, background .15s; flex: none; }
.rail-item:hover, .rail-item.active { border-radius: 16px; background: var(--accent); color: var(--accent-ink); }
.rail-item.add { color: var(--accent); font-size: 26px; font-weight: 400; }
.rail-item.add:hover { background: var(--accent); color: var(--accent-ink); }
.rail-item::before { content: ""; position: absolute; left: -12px; top: 50%; width: 4px; height: 0; background: var(--text); border-radius: 0 4px 4px 0; transform: translateY(-50%); transition: height .15s; }
.rail-item:hover::before { height: 20px; }
.rail-item.unread::before { height: 8px; }
.rail-item.active::before { height: 36px; }
.rail-sep { width: 32px; height: 2px; background: var(--line); border-radius: 1px; flex: none; }
.rail-icon { display: grid; place-items: center; }
.rail-icon svg { width: 24px; height: 24px; }
.badge { min-width: 16px; height: 16px; padding: 0 5px; border-radius: 8px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; line-height: 1; }
.rail-item .badge { position: absolute; right: -4px; bottom: -4px; border: 3px solid var(--bg-rail); height: 22px; min-width: 22px; border-radius: 11px; }

/* 사이드바 */
.sidebar { background: var(--bg-side); display: flex; flex-direction: column; min-height: 0; }
.sidebar-header { height: 48px; flex: none; border-bottom: 1px solid var(--line); display: flex; align-items: center; padding: 0 8px; box-shadow: 0 1px 0 rgba(0, 0, 0, .2); }
.side-title-btn { flex: 1; display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 8px; border-radius: 6px; font-weight: 700; font-size: 15px; text-align: left; min-width: 0; }
.side-title-btn:hover, .side-title-btn.active { background: var(--bg-hover); }
.side-title-btn .chev { margin-left: auto; color: var(--text-2); display: inline-flex; }
.side-title-btn .chev svg { width: 18px; height: 18px; }
.sidebar-body { flex: 1; overflow-y: auto; padding: 8px; }
.cat { display: flex; align-items: center; justify-content: space-between; padding: 14px 6px 4px; font-size: 12px; font-weight: 700; color: var(--text-3); }
.cat-btn { color: var(--text-3); line-height: 1; padding: 2px; border-radius: 4px; display: inline-flex; }
.cat-btn:hover { color: var(--text); }
.cat-btn svg { width: 16px; height: 16px; }
.chan { position: relative; width: 100%; display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 8px; border-radius: 6px; color: var(--text-3); text-align: left; }
.chan:hover { background: var(--bg-hover); color: var(--text-2); }
.chan.active { background: var(--bg-active); color: var(--text); }
.chan.unread { color: var(--text); font-weight: 600; }
.chan.unread::before { content: ""; position: absolute; left: -8px; top: 50%; width: 4px; height: 8px; border-radius: 0 4px 4px 0; background: var(--text); transform: translateY(-50%); }
.chan-icon { width: 20px; display: inline-flex; justify-content: center; color: var(--text-3); flex: none; }
.chan-icon svg { width: 20px; height: 20px; }
.chan-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chan-gear { display: none; color: var(--text-3); }
.chan:hover .chan-gear { display: inline-flex; }
.chan-gear svg { width: 16px; height: 16px; }
.chan.dm { height: 42px; }
.side-empty { padding: 12px 8px; color: var(--text-3); font-size: 13px; }
.voice-members { padding: 2px 0 4px 26px; display: flex; flex-direction: column; gap: 2px; }
.voice-member { display: flex; align-items: center; gap: 8px; height: 28px; padding: 0 6px; border-radius: 4px; color: var(--text-2); font-size: 14px; }
.voice-member:hover { background: var(--bg-hover); }
.vm-icons { margin-left: auto; display: inline-flex; gap: 4px; color: var(--text-3); }
.vm-icons svg { width: 16px; height: 16px; }

/* 음성 연결 상태 + 내 패널 */
.voice-status { flex: none; background: var(--bg-rail); border-top: 1px solid var(--line); padding: 8px 10px; display: flex; align-items: center; gap: 8px; }
.vs-text { flex: 1; min-width: 0; }
.vs-title { color: var(--green); font-weight: 700; font-size: 13px; }
.vs-sub { display: block; width: 100%; text-align: left; font-size: 12px; color: var(--text-2); }
.vs-sub:hover { text-decoration: underline; }
.user-panel { flex: none; height: 56px; background: var(--bg-rail); display: flex; align-items: center; padding: 0 8px; gap: 2px; }
.me { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; padding: 4px; border-radius: 6px; text-align: left; }
.me:hover { background: var(--bg-hover); }
.me-text { min-width: 0; }
.me-name { font-weight: 600; font-size: 14px; }
.me-status { font-size: 12px; color: var(--text-2); }
.me-controls { display: flex; }
.user-panel .status-dot { border-color: var(--bg-rail); }

/* 아바타 */
.avatar { position: relative; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #0d1117; user-select: none; box-shadow: 0 0 0 0 transparent; transition: box-shadow .1s; }
.avatar.speaking { box-shadow: 0 0 0 3px var(--green); }
.status-dot { position: absolute; right: -2px; bottom: -2px; width: 34%; height: 34%; min-width: 10px; min-height: 10px; border-radius: 50%; border: 2.5px solid var(--bg-side); background: var(--offline); }
.status-dot.online { background: var(--green); }
.status-dot.idle { background: var(--yellow); }
.status-dot.dnd { background: var(--red); }

/* 메인 */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg-main); }
.main-header { height: 48px; flex: none; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; padding: 0 12px; box-shadow: 0 1px 0 rgba(0, 0, 0, .2); }
.main .status-dot { border-color: var(--bg-main); }
.head-title { display: flex; align-items: center; gap: 8px; font-weight: 700; min-width: 0; }
.head-title .hash { color: var(--text-3); display: inline-flex; }
.head-title .hash svg { width: 22px; height: 22px; }
.head-topic { font-weight: 400; color: var(--text-2); font-size: 13px; margin-left: 8px; border-left: 1px solid var(--line); padding-left: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-tools { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.search { width: 150px; padding: 6px 10px !important; font-size: 13px !important; border-radius: 6px !important; transition: width .15s; }
.search:focus { width: 220px; }
.nav-toggle { display: none; }
.tab { padding: 4px 10px; border-radius: 6px; color: var(--text-2); font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.tab:hover { background: var(--bg-hover); color: var(--text); }
.tab.active { background: var(--bg-active); color: var(--text); }
.tab.add { background: var(--accent); color: var(--accent-ink); }
.tab.add:hover { background: var(--accent-2); }

/* 채팅 */
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 16px 0 8px; }
.empty { padding: 40px 24px; text-align: center; color: var(--text-3); }
.date-divider { display: flex; align-items: center; gap: 12px; margin: 12px 16px; color: var(--text-3); font-size: 12px; font-weight: 600; }
.date-divider::before, .date-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.msg { position: relative; display: grid; grid-template-columns: 56px minmax(0, 1fr); padding: 2px 48px 2px 16px; margin-top: 16px; }
.msg.grouped { margin-top: 0; }
.msg:hover { background: rgba(0, 0, 0, .14); }
.msg.mentioned { background: rgba(245, 196, 81, .08); box-shadow: inset 2px 0 0 var(--yellow); }
.msg.pinned .msg-head::after { content: "고정됨"; font-size: 11px; color: var(--accent); margin-left: 4px; }
.msg.flash { animation: flash 1.2s; }
@keyframes flash { 0%, 60% { background: rgba(63, 209, 192, .18); } 100% { background: transparent; } }
.msg-gutter { display: flex; justify-content: center; align-items: flex-start; padding-top: 2px; }
.msg-hover-time { font-size: 11px; color: var(--text-3); visibility: hidden; padding-top: 4px; }
.msg:hover .msg-hover-time { visibility: visible; }
.msg-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg-author { font-weight: 600; }
.msg-author:hover { text-decoration: underline; }
.msg-time { font-size: 12px; color: var(--text-3); }
.msg-content { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; }
.msg-content code { background: var(--bg-rail); border-radius: 4px; padding: 1px 5px; font-family: var(--mono); font-size: 13px; }
.msg-content pre.code { background: var(--bg-rail); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; overflow-x: auto; margin: 4px 0; }
.msg-content pre.code code { background: none; padding: 0; }
.msg-content blockquote { margin: 2px 0; padding: 2px 10px; border-left: 3px solid var(--text-3); color: var(--text-2); }
.mention { background: rgba(63, 209, 192, .2); color: var(--accent); border-radius: 4px; padding: 0 3px; font-weight: 600; }
.mention.me { background: rgba(245, 196, 81, .25); color: var(--yellow); }
.edited { font-size: 11px; color: var(--text-3); margin-left: 4px; }
.reply-ref { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; margin: 0 0 2px 36px; font-size: 13px; color: var(--text-2); cursor: pointer; min-width: 0; }
.reply-ref::before { content: ""; width: 24px; height: 9px; border: 2px solid var(--line); border-right: 0; border-bottom: 0; border-radius: 6px 0 0 0; margin-right: 2px; align-self: flex-end; flex: none; }
.reply-ref span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-ref:hover b { text-decoration: underline; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.attachments img { max-width: 400px; max-height: 300px; border-radius: 8px; display: block; }
.file-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--bg-raised); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; color: var(--text); text-decoration: none; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction { background: var(--bg-raised); border: 1px solid transparent; border-radius: 8px; padding: 2px 8px; font-size: 14px; color: var(--text-2); }
.reaction:hover { border-color: var(--text-3); }
.reaction.mine { background: rgba(63, 209, 192, .15); border-color: var(--accent); color: var(--text); }
.reaction.add { opacity: 0; transition: opacity .1s; }
.msg:hover .reaction.add { opacity: 1; }
.msg-actions { position: absolute; right: 16px; top: -14px; display: none; background: var(--bg-raised); border: 1px solid var(--line); border-radius: 6px; padding: 2px; gap: 2px; box-shadow: 0 4px 12px rgba(0, 0, 0, .3); }
.msg:hover .msg-actions { display: flex; }
.msg-actions button { width: 28px; height: 28px; border-radius: 4px; color: var(--text-2); display: grid; place-items: center; }
.msg-actions button:hover { background: var(--bg-hover); color: var(--text); }
.msg-actions button.danger:hover { color: var(--red); }
.msg-actions svg { width: 16px; height: 16px; }
.msg.system { color: var(--text-2); font-size: 14px; align-items: center; margin-top: 8px; }
.msg.system .sys-arrow { text-align: center; color: var(--green); font-size: 18px; }
.msg.system .msg-time { margin-left: 8px; }

/* 입력창 */
.typing { height: 20px; padding: 0 16px; font-size: 12px; color: var(--text-2); }
.typing b { font-weight: 600; color: var(--text); }
.composer { padding: 0 16px 20px; }
.composer-context { display: flex; align-items: center; justify-content: space-between; background: var(--bg-raised); border-radius: 8px 8px 0 0; padding: 6px 12px; font-size: 13px; color: var(--text-2); border-bottom: 1px solid var(--line); }
.attach-preview { display: flex; gap: 8px; flex-wrap: wrap; background: var(--bg-raised); padding: 10px 12px; border-bottom: 1px solid var(--line); }
.attach-chip { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; width: 120px; padding: 8px; background: var(--bg-rail); border-radius: 8px; font-size: 12px; }
.attach-chip img { width: 100px; height: 70px; object-fit: cover; border-radius: 4px; }
.attach-chip .file-icon { font-size: 36px; }
.attach-chip .attach-name { width: 100%; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip .icon-btn { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; background: var(--red); color: #fff; border-radius: 50%; font-size: 11px; }
.composer-row { display: flex; align-items: flex-end; gap: 4px; background: var(--bg-raised); border-radius: 8px; padding: 4px 6px; }
.composer-context:not([hidden]) ~ .composer-row, .attach-preview:not([hidden]) ~ .composer-row { border-top-left-radius: 0; border-top-right-radius: 0; }
.composer-context:not([hidden]) + .attach-preview { border-radius: 0; }
.composer-row textarea { flex: 1; background: none; border: 0; resize: none; padding: 10px 4px; max-height: 200px; line-height: 1.4; }
.composer-row textarea:focus { outline: none; }
.composer-row .icon-btn { margin-bottom: 6px; font-size: 18px; }

/* 멤버 목록 */
.members { width: 240px; background: var(--bg-side); overflow-y: auto; padding: 8px; }
.member { width: 100%; display: flex; align-items: center; gap: 10px; height: 42px; padding: 0 8px; border-radius: 6px; text-align: left; color: var(--text-2); }
.member:hover { background: var(--bg-hover); color: var(--text); }
.member.offline { opacity: .45; }
.member-name { flex: 1; min-width: 0; font-weight: 500; }
.crown { color: var(--yellow); display: inline-flex; }
.crown svg { width: 16px; height: 16px; }

/* 친구 */
.friends { flex: 1; overflow-y: auto; padding: 16px 24px; max-width: 860px; width: 100%; }
.friends h3 { margin: 0 0 4px; }
.friends .cat { padding-left: 0; }
.friend-row { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-top: 1px solid var(--line); }
.friend-row:hover { background: var(--bg-hover); border-radius: 8px; }
.friend-text { flex: 1; min-width: 0; }
.friend-name { font-weight: 600; }
.friend-sub { font-size: 13px; color: var(--text-2); }
.friend-btns { display: flex; gap: 8px; }
.add-row { display: flex; gap: 8px; }
.add-row input { flex: 1; }
.muted { color: var(--text-2); font-size: 13px; margin: 0; }

/* 음성 채널 화면 */
.main > .voice { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--bg-rail); }   /* 사이드바의 .chan.voice 와 겹치지 않게 범위 한정 */
.voice-tiles { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; padding: 16px; align-content: center; }
.voice-tiles .empty { grid-column: 1 / -1; }
.tile { position: relative; aspect-ratio: 16 / 9; background: var(--bg-side); border-radius: 12px; display: grid; place-items: center; overflow: hidden; min-height: 140px; }
.tile.has-video { grid-column: 1 / -1; background: #000; aspect-ratio: auto; min-height: 320px; max-height: 70vh; }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.tile video.mirror { transform: scaleX(-1); }
.tile.has-video .tile-center { position: absolute; left: 10px; top: 10px; }
.tile-name { position: absolute; left: 10px; bottom: 10px; display: flex; align-items: center; gap: 6px; background: rgba(0, 0, 0, .55); padding: 3px 10px; border-radius: 6px; font-size: 13px; font-weight: 600; max-width: calc(100% - 20px); }
.tile-ic { display: inline-flex; color: var(--red); }
.tile-ic.ok { color: var(--accent); }
.tile-ic svg { width: 14px; height: 14px; }
.voice-controls { flex: none; display: flex; justify-content: center; align-items: center; gap: 12px; padding: 16px; }
.vc-btn { width: 52px; height: 52px; border-radius: 50%; background: var(--bg-raised); color: var(--text); display: grid; place-items: center; transition: background .12s; }
.vc-btn:hover { background: var(--bg-hover); }
.vc-btn.on { background: var(--accent); color: var(--accent-ink); }
.vc-btn.off { background: #fff; color: var(--red); }
.vc-btn.danger { background: var(--red); color: #fff; }
.vc-btn svg { width: 24px; height: 24px; }

/* 모달 · 팝오버 · 토스트 */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { width: min(480px, 100%); max-height: 90vh; display: flex; flex-direction: column; background: var(--bg-side); border-radius: var(--radius-lg); box-shadow: 0 20px 60px rgba(0, 0, 0, .5); animation: pop .15s ease-out; }
.modal.wide { width: min(680px, 100%); }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 8px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 8px 20px 16px; overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; background: var(--bg-rail); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack section { display: flex; flex-direction: column; gap: 10px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.stack section:last-child { border: 0; padding-bottom: 0; }
.stack h3 { margin: 0; font-size: 14px; }
.row { display: flex; gap: 8px; align-items: center; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.radio-row { display: flex; gap: 16px; }
.role-box { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.role-head { display: flex; align-items: center; gap: 8px; }
.role-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.perm-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.code-box { display: flex; gap: 8px; }
.code-box input { flex: 1; font-family: var(--mono); font-size: 18px; letter-spacing: .12em; text-align: center; }
.pin-item { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.pin-head { display: flex; gap: 8px; align-items: baseline; }
.pin-body { white-space: pre-wrap; }
.popover { position: fixed; z-index: 60; background: var(--bg-raised); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .4); padding: 6px; min-width: 180px; max-width: calc(100vw - 16px); }
.menu { display: flex; flex-direction: column; min-width: 210px; }
.menu-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; text-align: left; font-size: 14px; }
.menu-item:hover { background: var(--bg-hover); }
.menu-item.danger { color: var(--red); }
.menu-item.danger:hover { background: var(--red); color: #fff; }
.mi { display: inline-flex; }
.mi svg { width: 18px; height: 18px; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 32px); gap: 2px; }
.emoji-grid button { width: 32px; height: 32px; font-size: 20px; border-radius: 6px; }
.emoji-grid button:hover { background: var(--bg-hover); }
.user-card { width: 280px; padding: 6px; }
.uc-head { display: flex; align-items: center; gap: 12px; }
.uc-name { font-weight: 700; font-size: 16px; }
.uc-status { font-size: 13px; color: var(--text-2); }
.uc-about { margin: 10px 0 0; font-size: 13px; color: var(--text-2); white-space: pre-wrap; }
.uc-roles { margin-top: 12px; }
.uc-label { font-size: 12px; font-weight: 700; color: var(--text-3); margin-bottom: 6px; }
.role-chip { display: inline-flex; align-items: center; gap: 6px; margin: 2px 4px 2px 0; padding: 3px 8px; border-radius: 6px; background: var(--bg-rail); font-size: 12px; color: var(--text-2); cursor: pointer; }
.role-chip::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--role); opacity: .4; }
.role-chip.on { color: var(--text); }
.role-chip.on::before { opacity: 1; }
.role-chip input { display: none; }
.uc-actions { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.status-item .status-dot { position: static; width: 12px; height: 12px; border: 0; flex: none; }
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 70; pointer-events: none; }
.toast { background: var(--bg-raised); border: 1px solid var(--line); color: var(--text); padding: 10px 16px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .4); font-size: 14px; transition: opacity .3s, transform .3s; }
.toast.error { border-color: var(--red); }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ── 반응형 공통 요소 (기본은 숨김) ── */
.send-btn { display: none; }
.backdrop { position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, .55); opacity: 0; pointer-events: none; transition: opacity .2s; }
.head-tabs { display: flex; gap: 4px; margin-left: 8px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.head-tabs::-webkit-scrollbar { display: none; }
.head-tabs .tab { flex: none; }
.drawer-head { display: none; }
.sheet-back { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-end; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(24px); opacity: 0; } }

/* ── 태블릿 이하: 멤버 목록이 오른쪽 서랍 ── */
@media (max-width: 1100px) {
  .members { position: fixed; top: 0; right: 0; bottom: 0; z-index: 40; width: min(300px, 85vw); transform: translateX(110%); transition: transform .22s; box-shadow: -8px 0 24px rgba(0, 0, 0, .4); padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .app.members-open .members { transform: none; }
  .app.members-open .backdrop { opacity: 1; pointer-events: auto; }
  .drawer-head { display: flex; align-items: center; justify-content: space-between; height: 48px; padding: 0 4px 0 12px; margin: -8px -8px 4px; border-bottom: 1px solid var(--line); font-weight: 700; }
}

/* ── 모바일 ── */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); height: var(--app-h, 100dvh); }
  body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }

  /* 서버 레일 + 채널 목록은 왼쪽 서랍 */
  .rail, .sidebar { position: fixed; top: 0; bottom: 0; z-index: 40; transition: transform .22s; }
  .rail { left: 0; width: 72px; padding-top: calc(12px + env(safe-area-inset-top)); transform: translateX(-110%); }
  .sidebar { left: 72px; width: min(260px, calc(100vw - 72px - 44px)); box-shadow: 8px 0 24px rgba(0, 0, 0, .4); transform: translateX(calc(-100% - 90px)); }   /* left:72px 만큼 더 밀어야 완전히 숨음 */
  .sidebar-header { padding-top: env(safe-area-inset-top); height: calc(48px + env(safe-area-inset-top)); }
  .user-panel { height: calc(56px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); }
  .app.nav-open .rail, .app.nav-open .sidebar { transform: none; }
  .app.nav-open .backdrop { opacity: 1; pointer-events: auto; }
  .nav-toggle { display: inline-flex; }
  .chan { height: 40px; }        /* 터치 타깃 확대 */
  .chan-gear { display: inline-flex; }
  .cat-btns { display: inline-flex; }

  /* 헤더 */
  .main-header { padding: 0 6px 0 4px; gap: 4px; padding-top: env(safe-area-inset-top); height: calc(48px + env(safe-area-inset-top)); }
  .head-title { flex: 1; min-width: 0; font-size: 15px; }
  .head-topic { display: none; }
  .head-tools { gap: 0; }
  .icon-btn { width: 40px; height: 40px; }
  .search { flex: 1; width: auto !important; font-size: 16px !important; padding: 8px 12px !important; }
  .head-tabs { margin-left: 0; flex: 1; justify-content: flex-end; }
  .head-tabs .tab { padding: 6px 10px; font-size: 13px; }

  /* 메시지 */
  .messages { padding: 8px 0; }
  .msg { grid-template-columns: 48px minmax(0, 1fr); padding: 3px 12px 3px 8px; margin-top: 12px; }
  .msg:hover { background: none; }
  .msg.held { background: var(--bg-raised); }
  .msg-content { font-size: 15px; }
  .msg-hover-time { display: none; }
  .reply-ref { margin-left: 30px; }
  .attachments img { max-width: 100%; max-height: 260px; }
  .date-divider { margin: 10px 12px; }
  .reaction { padding: 4px 10px; }

  /* 입력창 */
  .composer { padding: 0 8px calc(8px + env(safe-area-inset-bottom)); }
  .composer-row { align-items: flex-end; padding: 4px; }
  .composer-row textarea { font-size: 16px; padding: 9px 4px; max-height: 120px; }   /* 16px 미만이면 iOS가 화면을 확대함 */
  .composer-row .icon-btn { width: 38px; height: 38px; margin-bottom: 2px; }
  .send-btn { display: inline-flex; color: var(--accent); }
  .typing { height: 18px; padding: 0 12px; }

  /* 친구 · 음성 */
  .friends { padding: 12px; }
  .friend-row { padding: 10px 6px; }
  .voice-tiles { padding: 12px; gap: 8px; align-content: start; }
  .tile { min-height: 120px; }
  .tile.has-video { min-height: 200px; max-height: 50vh; }
  .voice-controls { padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); gap: 10px; }
  .vc-btn { width: 56px; height: 56px; }

  /* 모달은 바텀시트 */
  .modal-back { place-items: end center; padding: 0; }
  .modal { width: 100%; max-height: min(92dvh, var(--app-h, 92dvh)); border-radius: 16px 16px 0 0; animation: slide-up .2s ease-out; }
  .modal.wide { width: 100%; }
  .modal::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 10px auto -6px; }
  .modal-actions { border-radius: 0; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .modal-actions .btn { flex: 1; text-align: center; padding: 12px 16px; }
  .perm-grid { grid-template-columns: 1fr; }
  .radio-row { flex-wrap: wrap; gap: 10px 16px; }

  /* 팝오버(메뉴·이모지·유저 카드)도 바텀시트 */
  .popover.sheet { position: static; width: 100%; max-width: none; border-radius: 16px 16px 0 0; border-width: 1px 0 0; padding: 8px 12px calc(12px + env(safe-area-inset-bottom)); animation: slide-up .2s ease-out; max-height: 80dvh; overflow-y: auto; }
  .popover.sheet::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 10px; }
  .popover.sheet .menu { min-width: 0; }
  .popover.sheet .menu-item { padding: 14px 12px; font-size: 15px; }
  .popover.sheet .mi svg { width: 20px; height: 20px; }
  .popover.sheet .emoji-grid { grid-template-columns: repeat(auto-fill, 44px); justify-content: center; gap: 4px; }
  .popover.sheet .emoji-grid button { width: 44px; height: 44px; font-size: 26px; }
  .popover.sheet .user-card { width: auto; }
  .popover.sheet .uc-actions .btn { flex: 1; text-align: center; }

  .toasts { bottom: calc(80px + env(safe-area-inset-bottom)); width: calc(100% - 32px); }
  .toast { text-align: center; }
}

/* ── 터치 기기: hover에 기대는 UI 교체 ── */
@media (pointer: coarse) {
  .msg-actions { display: none !important; }
  .msg-content, .reply-ref { -webkit-touch-callout: none; user-select: none; }   /* 길게 누르면 메뉴 (복사는 메뉴에서) */
  .reaction.add { opacity: 1; }
  .chan-gear { display: inline-flex; }
  .cat-btns { display: inline-flex; }
  .rail-item:hover:not(.active) { border-radius: 50%; background: var(--bg-raised); color: var(--text); }
  .rail-item:hover::before { height: 0; }
  .rail-item.unread::before { height: 8px; }
  .rail-item.active::before { height: 36px; }
  .btn, .menu-item, .member, .friend-row, .tab { min-height: 40px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* ── v2: 카테고리 · 페이지네이션 · 봇 ── */
.cat.category { padding-left: 0; }
.cat-toggle { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; color: inherit; font: inherit; text-align: left; padding: 0 2px; border-radius: 4px; }
.cat-toggle:hover { color: var(--text); }
.cat-chev { display: inline-flex; transition: transform .15s; }
.cat-chev svg { width: 14px; height: 14px; }
.cat.folded .cat-chev { transform: rotate(-90deg); }
.cat-btns { display: none; gap: 2px; }
.cat:hover .cat-btns { display: inline-flex; }
.load-more { display: block; margin: 0 auto 12px; padding: 6px 14px; border-radius: 6px; background: var(--bg-raised); color: var(--text-2); font-size: 13px; }
.load-more:hover { background: var(--bg-hover); color: var(--text); }
.chat-start { padding: 12px 16px 4px; color: var(--text-3); font-size: 13px; }
.search-note { padding: 4px 16px 8px; color: var(--text-2); font-size: 13px; }
.bot-tag { display: inline-block; vertical-align: middle; margin-left: 6px; padding: 1px 5px; border-radius: 4px; background: var(--accent); color: var(--accent-ink); font-size: 10px; font-weight: 700; line-height: 1.4; letter-spacing: .02em; }
.bot-row { padding: 6px 0; border-bottom: 1px solid var(--line); }
.snippet { background: var(--bg-rail); border: 1px solid var(--line); border-radius: 8px; padding: 12px; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; color: var(--text-2); }
.row code { font-family: var(--mono); background: var(--bg-rail); padding: 2px 6px; border-radius: 4px; }

/* ── v3: 디스코드 룩 · 아바타 이미지 · 그라데이션 역할 · 프로필 카드 · DM 전화 ── */
.auth { background: radial-gradient(900px 500px at 15% -10%, rgba(255, 255, 255, .16), transparent 60%), linear-gradient(160deg, #5865f2, #3b47d6 60%, #2b3399); }
.auth-card { background: var(--bg-main); border: 0; box-shadow: 0 8px 32px rgba(0, 0, 0, .35); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn .mi svg { width: 16px; height: 16px; }
.rail-item { background: var(--bg-main); color: var(--text); }
.rail-item:hover, .rail-item.active { background: var(--accent); color: #fff; }
.rail-item.add { background: var(--bg-main); color: var(--green); }
.rail-item.add:hover { background: var(--green); color: #fff; }
.tab.add { background: var(--green); color: #fff; }
.tab.add:hover { background: #1a6334; }
.sidebar-header, .main-header { border-bottom: 0; box-shadow: 0 1px 0 rgba(0, 0, 0, .2), 0 2px 0 rgba(0, 0, 0, .06); }
.chan.active { background: var(--bg-active); color: #fff; }
.user-panel, .voice-status { background: var(--bg-panel); }
.msg:hover { background: rgba(0, 0, 0, .08); }
.msg.mentioned { background: rgba(240, 178, 50, .1); box-shadow: inset 2px 0 0 var(--yellow); }
.mention, .mention.me { background: rgba(88, 101, 242, .3); color: #c9cdfb; }
.mention:hover { background: var(--accent); color: #fff; cursor: pointer; }
.reaction.mine { background: rgba(88, 101, 242, .15); border-color: var(--accent); }
.modal { background: var(--bg-main); }
.modal-actions { background: var(--bg-side); }
.popover { background: var(--bg-pop); border-color: #2a2b30; }
.menu-item:hover { background: var(--accent); color: #fff; }
.menu-item:hover .mi { color: #fff; }

/* 상태 점: 자리 비움은 초승달, 방해 금지는 가로줄, 오프라인은 속 빈 원 (디스코드와 동일) */
.status-dot { --dot-bg: var(--bg-side); border: 2.5px solid var(--dot-bg); }
.user-panel .status-dot, .voice-status .status-dot { --dot-bg: var(--bg-panel); border-color: var(--dot-bg); }
.main .status-dot { --dot-bg: var(--bg-main); border-color: var(--dot-bg); }
.status-item .status-dot { --dot-bg: var(--bg-pop); }
.status-dot.idle { background: radial-gradient(circle at 28% 28%, var(--dot-bg) 0 30%, transparent 33%), var(--yellow); }
.status-dot.dnd { background: linear-gradient(var(--dot-bg), var(--dot-bg)) center / 62% 22% no-repeat, var(--red); }
.status-dot.offline { background: radial-gradient(circle, var(--dot-bg) 0 33%, var(--offline) 37%); }

/* 아바타 이미지 */
.avatar { background: var(--bg-raised); }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.avatar.clickable { cursor: pointer; }
.avatar.clickable:hover img { filter: brightness(.82); }

/* 그라데이션 역할 이름 */
.grad { background-image: linear-gradient(90deg, var(--c1), var(--c2)); -webkit-background-clip: text; background-clip: text; color: transparent !important; text-decoration-color: var(--c2); }
.role-opts { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; }
.role-opts .check input[type=color] { width: 36px; height: 28px; margin-left: 2px; }
.role-preview { margin-left: auto; font-weight: 700; white-space: nowrap; padding: 2px 10px; border-radius: 4px; background-color: var(--bg-rail); }   /* 축약형(background:)을 쓰면 .grad의 그라데이션이 지워짐 */

/* 프로필 카드 (팝아웃) */
.card-pop { padding: 0; overflow: hidden; width: 300px; }
.user-card { width: 100%; padding: 0; }
.uc-banner { height: 60px; }
.uc-avatar { display: flex; padding: 0 16px; margin-top: -40px; }
.uc-avatar .avatar { border: 6px solid var(--bg-pop); box-sizing: content-box; --dot-bg: var(--bg-pop); }
.uc-avatar .status-dot { right: 1px; bottom: 1px; width: 22px; height: 22px; border-width: 4px; border-color: var(--bg-pop); }
.uc-body { padding: 10px 16px 16px; }
.uc-name { font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 6px; min-width: 0; }
.uc-name > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uc-status { font-size: 13px; color: var(--text-2); }
.uc-info { background: var(--bg-rail); border-radius: 8px; padding: 12px; margin-top: 12px; display: flex; flex-direction: column; gap: 4px; }
.uc-info .uc-label { margin: 8px 0 2px; }
.uc-info .uc-label:first-child { margin-top: 0; }
.uc-about { margin: 0; color: var(--text); }
.uc-since { font-size: 13px; color: var(--text); }
.uc-roles { margin-top: 0; }
.uc-actions { margin-top: 12px; }
.uc-actions .btn { flex: 1; }
.popover.sheet.card-pop { width: 100%; padding: 0 0 env(safe-area-inset-bottom); }
.popover.sheet.card-pop::before { position: absolute; left: 50%; top: 8px; transform: translateX(-50%); margin: 0; background: rgba(255, 255, 255, .5); z-index: 1; }
.popover.sheet.card-pop { position: relative; }

/* 설정: 프로필 사진 */
.av-row { align-items: flex-start; gap: 16px; }
.av-preview .avatar { border: 3px solid var(--line); box-sizing: content-box; }
.av-defaults { display: flex; gap: 8px; flex-wrap: wrap; }
.av-pick { width: 44px; height: 44px; border-radius: 50%; overflow: hidden; border: 2px solid transparent; transition: border-color .1s, transform .1s; }
.av-pick:hover { border-color: var(--accent); transform: scale(1.06); }
.av-pick img { width: 100%; height: 100%; display: block; }

/* DM 통화 패널 (채팅 위) */
.call-panel { flex: none; background: var(--bg-rail); display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 14px 16px; box-shadow: 0 1px 0 rgba(0, 0, 0, .3); }
.call-tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; width: 100%; }
.call-tiles .tile { width: 240px; min-height: 135px; aspect-ratio: 16 / 9; }
.call-tiles.has-video .tile.has-video { width: 100%; min-height: 220px; max-height: 45vh; }
.call-note { color: var(--text-2); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.ring-dots { width: 8px; height: 8px; border-radius: 50%; background: var(--green); animation: ringpulse 1s infinite; }
@keyframes ringpulse { 50% { opacity: .15; } }
.call-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }
.call-controls .vc-btn { width: 44px; height: 44px; }
.call-controls .vc-btn svg { width: 20px; height: 20px; }
.call-dot { display: inline-flex; color: var(--green); flex: none; }
.call-dot svg { width: 14px; height: 14px; }

/* 전화 받기 화면 */
.call-back { z-index: 80; }
.incoming { background: var(--bg-side); border-radius: 16px; padding: 32px 36px 28px; display: flex; flex-direction: column; align-items: center; gap: 6px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); animation: pop .15s ease-out; min-width: min(320px, 100%); }
.incoming .avatar { animation: callpulse 1.6s infinite; margin-bottom: 8px; }
@keyframes callpulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(35, 165, 89, .6); } 70% { box-shadow: 0 0 0 18px rgba(35, 165, 89, 0); } }
.in-name { font-size: 22px; font-weight: 700; }
.in-sub { color: var(--text-2); }
.in-actions { display: flex; gap: 24px; margin-top: 20px; }
.in-act { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.vc-btn.accept { background: var(--green); color: #fff; }
.vc-btn.accept:hover { background: #1a8f4a; }
@media (max-width: 760px) {
  .call-tiles .tile { width: calc(50% - 5px); min-height: 110px; }
  .call-panel { padding: 10px 12px; }
}
