:root {
  --bg: #0a0a0f;
  --bg2: #12121a;
  --bg3: #1a1a25;
  --bg4: #252535;
  --text: #f2f2f7;
  --text2: #a0a0b8;
  --accent: #7c5cff;
  --accent2: #00d2ff;
  --danger: #ff4d6d;
  --success: #42f2a2;
  --warn: #ffcc42;
  --glass: rgba(255,255,255,0.04);
  --glass2: rgba(255,255,255,0.08);
  --border: rgba(255,255,255,0.08);
  --radius: 18px;
  --shadow: 0 20px 50px rgba(0,0,0,0.45);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 15px; overflow: hidden; }
button, input { font-family: inherit; }
button { border: none; cursor: pointer; }
#app { display: flex; height: 100vh; width: 100vw; }

/* Auth */
#auth-screen { display: none; align-items: center; justify-content: center; width: 100%; height: 100%; background: radial-gradient(1200px 800px at 10% 0%, rgba(124,92,255,0.18) 0%, transparent 60%), radial-gradient(800px 600px at 90% 100%, rgba(0,210,255,0.14) 0%, transparent 60%), var(--bg); }
#auth-screen.active { display: flex; }
.auth-card { width: 380px; max-width: 90%; padding: 34px; border-radius: var(--radius); text-align: center; border: 1px solid var(--border); box-shadow: var(--shadow); background: var(--glass); backdrop-filter: blur(20px); }
.logo-wrap { display: flex; justify-content: center; margin-bottom: 18px; }
.logo { width: 210px; height: 70px; }
.auth-card h1 { margin: 0 0 6px; font-size: 24px; }
.auth-card .sub { color: var(--text2); margin: 0 0 22px; font-size: 13px; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; background: var(--bg3); padding: 5px; border-radius: 12px; }
.tab { flex: 1; padding: 10px; border-radius: 8px; background: transparent; color: var(--text2); font-size: 14px; font-weight: 600; transition: .2s; }
.tab.active, .tab:hover { background: var(--accent); color: #fff; }
.auth-form { display: none; flex-direction: column; gap: 12px; }
.auth-form.active { display: flex; }
.auth-form input { padding: 13px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg2); color: var(--text); font-size: 15px; }
.auth-form input:focus { outline: none; border-color: var(--accent); }
.btn-primary { padding: 13px 18px; border-radius: 12px; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; font-weight: 700; font-size: 15px; transition: .2s; }
.btn-primary:hover { transform: translateY(-1px); filter: brightness(1.1); }
.btn-secondary { padding: 12px 16px; border-radius: 12px; background: var(--bg4); color: var(--text); font-weight: 600; }
.btn-secondary.danger { background: var(--danger); color: #fff; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; }

/* Main */
#main-screen { display: none; flex: 1; height: 100%; }
#main-screen.active { display: flex; }
.server-sidebar { width: 72px; min-width: 72px; background: var(--bg2); display: flex; flex-direction: column; align-items: center; padding: 12px 0; gap: 12px; border-right: 1px solid var(--border); }
.server-icon { width: 48px; height: 48px; border-radius: 50%; background: var(--bg3); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 18px; cursor: pointer; transition: .2s; border: 1px solid var(--border); overflow: hidden; color: var(--text); }
.server-icon:hover, .server-icon.active { border-radius: 16px; background: var(--accent); color: #fff; }
.server-icon.home { font-size: 20px; }
.server-icon.add { font-size: 26px; color: var(--success); }
.server-icon.public { font-size: 22px; }
.server-list { display: flex; flex-direction: column; gap: 12px; width: 100%; align-items: center; }

.channel-panel { width: 240px; min-width: 240px; background: var(--bg3); display: flex; flex-direction: column; border-right: 1px solid var(--border); }
.channel-header { height: 52px; padding: 0 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); font-weight: 700; }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; background: transparent; color: var(--text2); font-size: 16px; display: flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: var(--bg4); color: var(--text); }
.header-actions { display: flex; gap: 6px; }
.channel-list { flex: 1; overflow-y: auto; padding: 12px; }
.channel-category { color: var(--text2); font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; margin: 14px 0 8px; padding: 0 4px; }
.channel-item { padding: 9px 12px; border-radius: 10px; cursor: pointer; color: var(--text2); display: flex; align-items: center; gap: 8px; font-size: 14px; transition: .15s; }
.channel-item:hover { background: var(--bg4); color: var(--text); }
.channel-item.active { background: var(--glass2); color: var(--text); }
.channel-item .badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 11px; border-radius: 10px; padding: 2px 6px; }
.user-bar { padding: 10px 12px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.user-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.user-info .avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex-shrink: 0; }
.user-info .meta { display: flex; flex-direction: column; min-width: 0; }
.user-info .name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info .status { font-size: 11px; color: var(--text2); }
.user-info .status.online { color: var(--success); }

.content { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

/* Views */
.home-view, .text-channel-view, .voice-channel-view, .dm-view { display: none; flex: 1; flex-direction: column; min-height: 0; }
.home-view.active, .text-channel-view.active, .voice-channel-view.active, .dm-view.active { display: flex; }
.hero { padding: 34px; border-bottom: 1px solid var(--border); }
.hero h2 { margin: 0 0 8px; font-size: 28px; }
.hero p { margin: 0 0 18px; color: var(--text2); max-width: 640px; }
.hero-actions { display: flex; gap: 12px; }
.friends-section { flex: 1; overflow-y: auto; padding: 20px 34px; }
.friends-section h3 { margin: 0 0 16px; font-size: 18px; }
.friends-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.friends-list { display: flex; flex-direction: column; gap: 8px; }
.friend-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; background: var(--bg2); cursor: pointer; }
.friend-item:hover { background: var(--bg3); }
.friend-item .avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; }
.friend-item .meta { flex: 1; }
.friend-item .name { font-weight: 700; }
.friend-item .status { font-size: 12px; color: var(--text2); }
.friend-item .status.online { color: var(--success); }
.friend-item .actions { display: flex; gap: 6px; }
.add-friend { margin-top: 20px; }
.add-friend input { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg2); color: var(--text); }
.search-results { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.search-result { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; background: var(--bg2); }
.search-result button { margin-left: auto; padding: 6px 12px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 13px; }

/* Chat */
.chat-header { height: 52px; padding: 0 18px; display: flex; align-items: center; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 16px; }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.message { display: flex; gap: 12px; }
.message .avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--accent); flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
.message .body { display: flex; flex-direction: column; }
.message .meta { display: flex; gap: 10px; align-items: baseline; margin-bottom: 3px; }
.message .name { font-weight: 700; font-size: 14px; }
.message .time { font-size: 11px; color: var(--text2); }
.message .content { color: var(--text); line-height: 1.4; word-break: break-word; }
.chat-input { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 10px; }
.chat-input input { flex: 1; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg2); color: var(--text); }
.chat-input input:focus { outline: none; border-color: var(--accent); }

/* Voice */
.voice-grid { flex: 1; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; padding: 24px; align-content: start; overflow-y: auto; }
.voice-user { aspect-ratio: 16/10; border-radius: 18px; background: var(--bg2); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; border: 2px solid transparent; transition: .2s; position: relative; }
.voice-user.speaking { border-color: var(--success); box-shadow: 0 0 20px rgba(66,242,162,0.25); }
.voice-user .avatar { width: 72px; height: 72px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 700; }
.voice-user .name { font-weight: 700; }
.voice-user .indicators { position: absolute; top: 10px; right: 10px; display: flex; gap: 6px; }
.voice-user .ind { font-size: 14px; opacity: .6; }
.voice-user .ind.active { opacity: 1; color: var(--danger); }
.voice-controls { padding: 14px 24px; border-top: 1px solid var(--border); display: flex; justify-content: center; gap: 14px; }
.vc-btn { padding: 10px 18px; border-radius: 12px; background: var(--bg3); color: var(--text); font-weight: 600; }
.vc-btn.active { background: var(--danger); color: #fff; }
.vc-btn.danger { background: var(--danger); color: #fff; }

/* Modal */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); align-items: center; justify-content: center; z-index: 100; }
.modal-overlay.active { display: flex; }
.modal { width: 420px; max-width: 92%; max-height: 90vh; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg2); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.modal-header { padding: 16px 20px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); }
.modal-header h3 { margin: 0; font-size: 18px; }
.modal-close { width: 30px; height: 30px; border-radius: 8px; background: transparent; color: var(--text2); font-size: 22px; }
.modal-close:hover { background: var(--bg4); color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-body input, .modal-body select, .modal-body textarea { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); margin-bottom: 12px; }
.modal-body button { width: 100%; }
.modal-body .row { display: flex; gap: 10px; }
.modal-body .row input { flex: 1; }

/* Call popup */
.call-popup { display: none; position: fixed; bottom: 24px; right: 24px; width: 300px; padding: 20px; border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); z-index: 110; flex-direction: column; align-items: center; gap: 14px; }
.call-popup.active { display: flex; }
.call-popup .avatar { width: 64px; height: 64px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 700; }
.call-popup .name { font-weight: 700; font-size: 18px; }
.call-popup .sub { color: var(--text2); font-size: 13px; }
.call-popup .call-actions { display: flex; gap: 10px; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* Mobile */
@media (max-width: 900px) {
  .server-sidebar { width: 60px; min-width: 60px; }
  .server-icon { width: 42px; height: 42px; }
  .channel-panel { width: 200px; min-width: 200px; }
  .voice-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); padding: 14px; gap: 10px; }
  .hero { padding: 20px; }
  .friends-section { padding: 16px 20px; }
}
@media (max-width: 640px) {
  #main-screen { flex-direction: column; }
  .server-sidebar { flex-direction: row; width: 100%; height: 60px; min-height: 60px; padding: 0 10px; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .server-list { flex-direction: row; }
  .channel-panel { width: 100%; height: 240px; min-height: 240px; border-right: none; border-bottom: 1px solid var(--border); }
  .content { min-height: 0; }
}
