:root {
  --bg: #0e1116;
  --panel: #151a21;
  --border: #242c36;
  --text: #e6ebf2;
  --muted: #8b96a5;
  --accent: #5b8def;
  --live: #ff4d5e;
  --mine: #2b4a6f;
  --theirs: #1e2530;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#app { display: grid; grid-template-columns: 280px 1fr; height: 100vh; }

/* ---------- sidebar ---------- */
#sidebar {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
}
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px; border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; }
.logo { font-weight: 800; font-size: 18px; letter-spacing: 0.5px; }
.live-btn {
  background: var(--live); color: #fff; border: none; border-radius: 20px;
  padding: 7px 14px; font-weight: 700; cursor: pointer; font-size: 13px;
}
.live-btn.live { animation: pulse 1.4s infinite; }
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(255,77,94,.5); }
  50% { box-shadow: 0 0 0 8px rgba(255,77,94,0); }
}

.live-list { border-bottom: 1px solid var(--border); }
.live-item { display: flex; align-items: center; gap: 10px; padding: 9px 14px; cursor: pointer; }
.live-item:hover { background: var(--theirs); }
.live-item .live-dot { color: var(--live); font-size: 12px; }
.live-item .live-name { font-weight: 600; font-size: 14px; }
.live-item .live-title { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.friends-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px 6px; color: var(--muted); font-size: 12px;
  text-transform: uppercase; letter-spacing: 1px;
}
.friends-head button {
  background: none; border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; width: 24px; height: 24px; cursor: pointer; line-height: 1;
}
#friendName, #groupName {
  margin: 0 14px 6px; padding: 7px 10px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text); display: none;
}
.show { display: block !important; }
#friendName, #groupName:focus { outline: none; border-color: var(--accent); }

#dmList, #groupList { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
#dmList { flex: 1; }
#groupList { max-height: 40vh; border-bottom: 1px solid var(--border); }

.contact {
  display: flex; align-items: center; gap: 10px; padding: 9px 14px; cursor: pointer;
  border-left: 3px solid transparent;
}
.contact:hover { background: var(--theirs); }
.contact.active { border-left-color: var(--accent); background: var(--theirs); }
.contact .names { display: flex; flex-direction: column; min-width: 0; }
.contact .c-handle { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact .c-user { color: var(--muted); font-size: 12px; }
.contact.offline .status { background: #5a6470; }
.contact .live-tag { color: var(--live); font-size: 11px; font-weight: 700; margin-left: auto; }
.group-ico { background: var(--theirs); color: var(--accent); }

.empty { color: var(--muted); font-size: 13px; padding: 16px 14px; }

/* avatars */
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
  text-transform: uppercase; position: relative; flex: none; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar .status { position: absolute; bottom: 0; right: 0; width: 11px; height: 11px; border-radius: 50%; background: #3ddc7a; border: 2px solid var(--panel); }
.small-avatar { width: 34px; height: 34px; font-size: 14px; }
.big-avatar { width: 84px; height: 84px; font-size: 34px; }

.side-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 14px; border-top: 1px solid var(--border);
}
.me { display: flex; align-items: center; gap: 10px; min-width: 0; cursor: pointer; }
.me-names { min-width: 0; }
.me-handle { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.me-user { color: var(--muted); font-size: 12px; }
.ghost-btn {
  background: none; border: 1px solid var(--border); color: var(--muted);
  border-radius: 6px; padding: 5px 10px; cursor: pointer; font-size: 12px; flex: none;
}
.ghost-btn:hover { color: var(--text); border-color: var(--muted); }

/* ---------- main ---------- */
#main { display: flex; flex-direction: column; min-width: 0; }
#chatHead { padding: 18px 22px 14px; border-bottom: 1px solid var(--border); }
.chat-title { font-size: 20px; font-weight: 700; }
.chat-sub { color: var(--muted); font-size: 13px; margin-top: 2px; height: 16px; }

#messages { flex: 1; overflow-y: auto; padding: 18px 22px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 68%; padding: 9px 12px; border-radius: 14px; font-size: 14px; line-height: 1.4; word-wrap: break-word; }
.msg .m-head { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.msg.mine { align-self: flex-end; background: var(--mine); border-bottom-right-radius: 4px; }
.msg.theirs { align-self: flex-start; background: var(--theirs); border-bottom-left-radius: 4px; }
.msg .time { font-size: 10px; color: var(--muted); margin-top: 4px; text-align: right; opacity: .8; }
.msg.temp { opacity: .6; font-style: italic; }
.msg.image { padding: 6px; background: none; }
.msg.image.mine { background: none; }
.msg.image .imgwrap { border-radius: 12px; overflow: hidden; background: var(--theirs); }
.msg.image img { display: block; max-width: 300px; max-height: 320px; border-radius: 12px; object-fit: cover; }
.msg .cap { font-size: 13px; padding: 6px 6px 0; }
.msg .cap + .m-head { margin-top: 6px; }

.picker { align-self: center; text-align: center; color: var(--muted); padding: 40px 20px; }
.picker .big { font-size: 22px; margin-bottom: 8px; }

#composer { display: flex; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); align-items: center; }
.attach {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border);
  display: grid; place-items: center; cursor: pointer; color: var(--muted);
  font-size: 20px; flex: none; position: relative; background: var(--panel);
}
.attach:hover { color: var(--accent); border-color: var(--accent); }
.attach.uploading { pointer-events: none; opacity: .5; }
#input, #streamInput {
  flex: 1; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 20px; padding: 11px 16px; font-size: 14px;
}
#input:focus, #streamInput:focus, .modal input:focus, textarea:focus { outline: none; border-color: var(--accent); }
#send {
  background: var(--accent); color: #fff; border: none; border-radius: 20px;
  padding: 0 20px; font-weight: 700; cursor: pointer;
}
#send:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- stream ---------- */
#streamPane { display: flex; flex-direction: column; border-left: 1px solid var(--border); height: 100vh; }
#streamPane.hidden { display: none !important; }
.stream-head { display: flex; align-items: center; gap: 10px; padding: 14px; border-bottom: 1px solid var(--border); }
#streamLiveBadge { color: var(--live); font-weight: 800; font-size: 13px; animation: pulse 1.4s infinite; }
#streamTitle { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#closeStream { background: none; border: none; color: var(--muted); font-size: 22px; cursor: pointer; }
.stream-stage { flex: 1; min-height: 200px; background: linear-gradient(180deg, #16202b, #10151b); display: grid; place-items: center; position: relative; }
.stream-avatar { border-radius: 50%; overflow: hidden; }
.stream-plane { text-align: center; color: var(--muted); padding: 14px; }
.stream-plane .now { font-size: 24px; color: var(--text); font-weight: 700; }
.stream-plane .hosted { margin-top: 6px; font-size: 13px; }
.stream-play { font-size: 40px; margin-bottom: 10px; animation: pulse 1.4s infinite; }
#streamMsg { padding: 10px 14px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--border); overflow-y: auto; max-height: 140px; min-height: 36px; }
.lchat { color: var(--text); margin-bottom: 6px; font-size: 14px; }
.lchat b { color: var(--accent); }
#streamComposer { display: flex; padding: 12px 14px; border-top: 1px solid var(--border); gap: 10px; }

/* ---------- modals ---------- */
.modal-cover { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; backdrop-filter: blur(3px); z-index: 10; }
.modal-cover.hidden { display: none; }
#groupModal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 11; }
#groupModal.hidden { display: none; }
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 22px;
  width: 360px; max-width: 94vw;
}
.modal.wide { width: 640px; }
.modal h2 { margin: 0 0 14px; font-size: 18px; }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.modal input[type=text], .modal input:not([type=color]):not([type=file]), .modal textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 11px; font-size: 14px;
}
.modal textarea { resize: vertical; min-height: 56px; }
.theme-row { display: flex; align-items: center; justify-content: space-between; font-size: 14px; margin-bottom: 12px; color: var(--muted); }
.theme-row input[type=color] { width: 48px; height: 30px; border: none; background: none; cursor: pointer; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.primary { background: var(--accent); color: #fff; border: none; border-radius: 8px; padding: 9px 18px; font-weight: 700; cursor: pointer; }
.prof-left { display: flex; flex-direction: column; gap: 6px; }
#pMsg, #gMsg { margin-top: 8px; font-size: 12px; color: var(--live); min-height: 14px; }
.prof-card {
  border: 1px solid var(--border); border-radius: 12px; padding: 18px; text-align: center;
  align-self: start; color: var(--muted);
}
.prof-card .pc-avatar { margin: 0 auto 10px; }
.pc-avatar {
  width: 84px; height: 84px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 34px;
  text-transform: uppercase; overflow: hidden;
}
.pc-avatar img { width: 100%; height: 100%; object-fit: cover; }
.pc-bio { margin-top: 8px; font-size: 13px; color: var(--text); }
#gMembers { margin: 8px 0; }
.member-chip { display: inline-block; background: var(--theirs); border-radius: 12px; padding: 4px 10px; margin: 3px; font-size: 13px; }

.hidden { display: none !important; }

/* ---------- auth screen ---------- */
#authScreen {
  position: fixed; inset: 0; background: var(--bg);
  display: grid; place-items: center; z-index: 20; padding: 20px;
}
.auth-box {
  width: 340px; max-width: 94vw; padding: 26px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
}
.auth-brand { font-size: 28px; font-weight: 800; text-align: center; margin-bottom: 18px; letter-spacing: 0.5px; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tab {
  flex: 1; background: none; border: 1px solid var(--border); color: var(--muted);
  border-radius: 10px; padding: 9px; cursor: pointer; font-weight: 600; font-size: 14px;
}
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.auth-form .field { margin-bottom: 14px; }
.auth-form .field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.auth-form input {
  width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 11px 12px; font-size: 14px;
}
.auth-form input:focus { outline: none; border-color: var(--accent); }
.full { width: 100%; }
.primary.auth { width: 100%; padding: 11px; font-size: 15px; }
#authMsg { margin-top: 12px; font-size: 13px; color: var(--live); min-height: 16px; text-align: center; }

/* ---------- language ---------- */
.lang-wrap { padding: 8px 14px 0; }
.lang-wrap > button { width: 100%; }

.foot-btns { display: flex; gap: 6px; }
#logoutBtn { color: var(--live); border-color: var(--border); }
#logoutBtn:hover { color: #fff; border-color: var(--live); }

/* select styling */
select {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 6px 8px; font-size: 14px;
}

@media (max-width: 720px) {
  #app { grid-template-columns: 1fr; }
  #sidebar { display: none; }
}