:root {
  --bg-deep:    #0b0d12;
  --bg:         #12151c;
  --bg-soft:    #171b24;
  --bg-raise:   #1d2230;
  --line:       #262c3a;
  --line-soft:  #1f2431;
  --text:       #e7eaf0;
  --text-dim:   #9aa3b5;
  --text-faint: #6b7488;
  --accent:     #6c7cff;
  --accent-2:   #9d6cff;
  --green:      #2ecc71;
  --red:        #ef4d54;
  --radius:     14px;
  --shadow:     0 18px 50px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: var(--bg-deep);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font: inherit; }
svg { width: 100%; height: 100%; display: block; }

/* ---------------- JOIN SCREEN ---------------- */
.join-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 700px at 15% -10%, #1a2036 0%, transparent 60%),
    radial-gradient(900px 600px at 110% 110%, #241a3a 0%, transparent 55%),
    var(--bg-deep);
  overflow: hidden;
}
.glow {
  position: absolute;
  width: 520px; height: 520px;
  border-radius: 50%;
  filter: blur(120px);
  opacity: .35;
  pointer-events: none;
  animation: drift 18s ease-in-out infinite alternate;
}
.glow-a { background: #4b57ff; top: -160px; left: -120px; }
.glow-b { background: #8b3dff; bottom: -180px; right: -140px; animation-delay: -9s; }
@keyframes drift {
  from { transform: translate3d(0,0,0) scale(1); }
  to   { transform: translate3d(60px,40px,0) scale(1.15); }
}

.join-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  padding: 32px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(29,34,48,.92), rgba(18,21,28,.95));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  animation: rise .5s cubic-bezier(.2,.8,.3,1) both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 26px; }
.brand-mark {
  width: 46px; height: 46px;
  padding: 11px;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 22px rgba(108,124,255,.35);
  flex: none;
}
.brand h1 { margin: 0; font-size: 21px; letter-spacing: -.3px; }
.brand-sub { margin: 2px 0 0; font-size: 13px; color: var(--text-dim); }

.field { display: block; margin-bottom: 16px; }
.field > span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 7px;
}
.field em { font-style: normal; text-transform: none; letter-spacing: 0; font-weight: 400; }
.field input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 11px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 15px;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.field input::placeholder { color: var(--text-faint); }
.field input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-soft);
  box-shadow: 0 0 0 4px rgba(108,124,255,.14);
}

.btn-primary {
  width: 100%;
  margin-top: 8px;
  padding: 14px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  font-size: 15px; font-weight: 650;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 26px rgba(108,124,255,.32);
  transition: transform .12s, box-shadow .2s, filter .2s;
}
.btn-primary svg { width: 18px; height: 18px; }
.btn-primary:hover { filter: brightness(1.08); box-shadow: 0 14px 34px rgba(108,124,255,.42); }
.btn-primary:active { transform: translateY(1px) scale(.995); }
.btn-primary[disabled] { opacity: .6; pointer-events: none; }

.join-error { min-height: 18px; margin: 12px 0 0; font-size: 13px; color: #ff8f94; text-align: center; }
.join-foot {
  margin-top: 18px; padding-top: 16px;
  border-top: 1px solid var(--line-soft);
  font-size: 12px; color: var(--text-faint);
  display: flex; align-items: center; gap: 8px; justify-content: center;
}
.dot-live {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(46,204,113,.6);
  animation: pulse 2.2s infinite;
  flex: none;
}
@keyframes pulse {
  70%  { box-shadow: 0 0 0 7px rgba(46,204,113,0); }
  100% { box-shadow: 0 0 0 0 rgba(46,204,113,0); }
}

/* ---------------- APP SHELL ---------------- */
.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: 268px 1fr;
  background: var(--bg-deep);
}

/* ---------------- SIDEBAR ---------------- */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
  border-right: 1px solid var(--line-soft);
}
.room-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 16px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.room-meta { display: flex; align-items: baseline; gap: 5px; min-width: 0; }
.room-hash { color: var(--text-faint); font-weight: 700; }
.room-name {
  font-weight: 650; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn-ghost {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 10px;
  border-radius: 9px;
  font-size: 12px; font-weight: 600;
  color: var(--text-dim);
  background: var(--bg-raise);
  border: 1px solid var(--line);
  transition: color .15s, background .15s, transform .12s;
  flex: none;
}
.btn-ghost svg { width: 14px; height: 14px; }
.btn-ghost:hover { color: var(--text); background: #232a3a; }
.btn-ghost:active { transform: scale(.96); }

.section-label {
  display: flex; align-items: center; gap: 7px;
  padding: 16px 16px 8px;
  font-size: 11px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-faint);
}
.section-label svg { width: 13px; height: 13px; }

.participants {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 8px 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.participant {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px;
  border-radius: 10px;
  transition: background .15s;
  animation: slide-in .25s ease both;
}
.participant:hover { background: var(--bg-soft); }
@keyframes slide-in {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: none; }
}
.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 14px; font-weight: 700;
  color: #fff;
  flex: none;
  position: relative;
  transition: box-shadow .12s, transform .12s;
}
.avatar.sm { width: 30px; height: 30px; font-size: 12px; }
.participant.speaking .avatar {
  box-shadow: 0 0 0 2.5px var(--green), 0 0 14px rgba(46,204,113,.45);
  transform: scale(1.04);
}
.participant.muted .avatar { opacity: .45; }
.p-name {
  font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text-dim);
  transition: color .15s;
}
.participant.speaking .p-name { color: var(--text); }
.p-you { font-size: 11px; color: var(--text-faint); margin-left: 4px; }
.p-mic { width: 15px; height: 15px; margin-left: auto; color: var(--red); flex: none; }

.user-panel {
  border-top: 1px solid var(--line-soft);
  background: var(--bg-deep);
  padding: 10px;
}
.me { display: flex; align-items: center; gap: 9px; padding: 4px 4px 10px; }
.me-text { min-width: 0; }
.me-name { font-size: 13px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-status { font-size: 11px; color: var(--text-faint); display: flex; align-items: center; gap: 5px; }
.ctrl-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.ctrl {
  height: 38px;
  padding: 10px;
  border-radius: 10px;
  color: var(--text-dim);
  background: var(--bg-raise);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  transition: color .15s, background .15s, transform .1s;
}
.ctrl svg { width: 18px; height: 18px; }
.ctrl .ico-off { display: none; }
.ctrl:hover { color: var(--text); background: #232a3a; }
.ctrl:active { transform: scale(.94); }
.ctrl.active { color: #fff; background: var(--red); border-color: transparent; }
.ctrl.active .ico-on  { display: none; }
.ctrl.active .ico-off { display: block; }
.ctrl.danger:hover { color: #fff; background: var(--red); border-color: transparent; }

/* ---------------- CHAT ---------------- */
.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-soft);
}
.chat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg-soft);
}
.chat-title { font-weight: 650; font-size: 15px; }
.chat-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11px; font-weight: 600;
  color: var(--text-faint);
  background: var(--bg);
  border: 1px solid var(--line);
}
.chat-badge svg { width: 13px; height: 13px; }
.chat-badge.warn { color: #ffc46b; border-color: #4a3a1e; background: #241d10; }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 20px 8px;
  scroll-behavior: smooth;
}
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-faint); }
.empty-mark {
  width: 54px; height: 54px; padding: 13px;
  margin: 0 auto 14px;
  border-radius: 16px;
  color: var(--accent);
  background: var(--bg-raise);
  border: 1px solid var(--line);
}
.empty-state h3 { margin: 0 0 6px; font-size: 16px; color: var(--text-dim); }
.empty-state p { margin: 0; font-size: 13px; line-height: 1.8; }
.empty-state code {
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--accent);
  background: var(--bg-raise);
  border: 1px solid var(--line);
}

.msg {
  display: flex; gap: 12px;
  padding: 4px 8px 4px 4px;
  border-radius: 8px;
  animation: msg-in .22s ease both;
}
.msg:hover { background: rgba(255,255,255,.022); }
.msg + .msg { margin-top: 2px; }
.msg.grouped { margin-top: 0; }
.msg.leaving { animation: msg-out .32s ease both; }
@keyframes msg-in  { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes msg-out { to { opacity: 0; transform: translateX(-14px); max-height: 0; padding: 0; margin: 0; } }

.msg-gutter { width: 38px; flex: none; display: flex; justify-content: center; }
.msg-time-hover {
  font-size: 10px; color: var(--text-faint);
  opacity: 0; align-self: center;
  transition: opacity .12s;
}
.msg:hover .msg-time-hover { opacity: 1; }
.msg-body { min-width: 0; flex: 1; }
.msg-head { display: flex; align-items: baseline; gap: 9px; margin-bottom: 2px; }
.msg-author { font-size: 14px; font-weight: 650; }
.msg-time { font-size: 11px; color: var(--text-faint); }
.msg-text {
  font-size: 14.5px; line-height: 1.5;
  color: #cfd5e2;
  word-wrap: break-word; overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.msg-text a { color: #7aa2ff; }

.sys-msg {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 6px 6px 46px;
  font-size: 12.5px; color: var(--text-faint);
  animation: msg-in .22s ease both;
}
.sys-dot { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.sys-msg.join .sys-dot  { background: var(--green); }
.sys-msg.leave .sys-dot { background: var(--red); }
.sys-msg.clear .sys-dot { background: var(--accent); }
.sys-msg b { color: var(--text-dim); font-weight: 600; }

.typing-row {
  height: 20px;
  padding: 0 20px;
  font-size: 12px;
  color: var(--text-faint);
  display: flex; align-items: center;
}

.chat-form {
  display: flex; gap: 10px;
  padding: 8px 20px 20px;
}
.chat-input {
  flex: 1;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14.5px;
  transition: border-color .15s, box-shadow .15s;
}
.chat-input::placeholder { color: var(--text-faint); }
.chat-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(108,124,255,.13);
}
.send-btn {
  width: 48px; flex: none;
  padding: 14px;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 20px rgba(108,124,255,.28);
  transition: filter .15s, transform .1s;
}
.send-btn:hover { filter: brightness(1.1); }
.send-btn:active { transform: scale(.94); }

/* ---------------- TOAST ---------------- */
.toast {
  position: fixed;
  left: 50%; bottom: 30px;
  transform: translate(-50%, 20px);
  padding: 11px 18px;
  border-radius: 11px;
  font-size: 13.5px; font-weight: 550;
  color: var(--text);
  background: var(--bg-raise);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- SCROLLBARS ---------------- */
::-webkit-scrollbar { width: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a3142; border-radius: 99px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #38415a; background-clip: content-box; }

/* ---------------- MOBILE ---------------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--line-soft); }
  .participants {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 10px 10px;
    gap: 6px;
  }
  .participant { flex-direction: column; gap: 6px; padding: 8px 10px; min-width: 74px; }
  .p-name { font-size: 11px; max-width: 62px; text-align: center; }
  .p-you, .p-mic { display: none; }
  .user-panel { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  .me { padding: 0; flex: 1; min-width: 0; }
  .ctrl-row { grid-template-columns: repeat(3, 44px); }
  .messages { padding: 14px 14px 6px; }
  .chat-form { padding: 6px 14px 14px; }
  .sys-msg { padding-left: 12px; }
}
