:root {
  --bg: #0b0d13;
  --panel: #14171f;
  --panel-2: #1b1f2a;
  --border: #262b38;
  --text: #e9ecf3;
  --muted: #8b93a7;
  --accent: #6d5efc;
  --accent-2: #3ba3ff;
  --green: #22c55e;
  --amber: #f0b429;
  --red: #ef4444;
  --shadow: 0 20px 60px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background:
    radial-gradient(900px 600px at 15% -10%, rgba(109, 94, 252, .18), transparent 60%),
    radial-gradient(800px 600px at 110% 110%, rgba(59, 163, 255, .14), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.screen { height: 100%; }

/* ---------------- 加入房间 ---------------- */
#joinScreen { display: flex; align-items: center; justify-content: center; padding: 24px; }

.join-card {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .04), rgba(255, 255, 255, .01)), var(--panel);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 34px 30px 26px;
  box-shadow: var(--shadow);
  animation: rise .45s cubic-bezier(.2, .8, .2, 1);
}

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }

.brand-icon {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  font-size: 22px; border-radius: 13px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 24px rgba(109, 94, 252, .4);
}

.brand h1 { font-size: 21px; margin: 0; letter-spacing: .5px; }

.sub { color: var(--muted); font-size: 13px; line-height: 1.7; margin: 0 0 24px; }
.sub b { color: var(--text); }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 7px; letter-spacing: .3px; }

.field input {
  width: 100%; padding: 13px 15px; font-size: 15px; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px;
  outline: none; transition: border-color .18s, box-shadow .18s;
}

.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(109, 94, 252, .18); }

.primary-btn {
  width: 100%; padding: 14px; margin-top: 8px;
  font-size: 15px; font-weight: 600; color: #fff;
  border: 0; border-radius: 12px; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 26px rgba(109, 94, 252, .35);
  transition: transform .12s, filter .18s;
}

.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:active { transform: scale(.985); }
.primary-btn:disabled { opacity: .6; cursor: default; }
.primary-btn.small { width: auto; padding: 11px 22px; margin: 0; }

.error { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 10px; text-align: center; }

.tips { margin-top: 22px; padding-top: 18px; border-top: 1px dashed var(--border); display: grid; gap: 9px; }
.tip { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--muted); }

.tip span {
  width: 19px; height: 19px; flex: none;
  display: grid; place-items: center; font-size: 11px;
  color: var(--accent-2); border: 1px solid rgba(59, 163, 255, .35); border-radius: 50%;
}

/* ---------------- 聊天界面 ---------------- */
#chatScreen {
  display: flex; flex-direction: column;
  height: 100%; max-width: 1080px; margin: 0 auto;
  background: rgba(20, 23, 31, .72);
  border-left: 1px solid var(--border); border-right: 1px solid var(--border);
  backdrop-filter: blur(8px);
  position: relative;
}

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  background: rgba(20, 23, 31, .9); flex: none;
}

.status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); min-width: 96px; }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); transition: background .2s; }

.room-label {
  flex: 1; text-align: center; font-size: 13px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.room-label b { color: var(--text); font-weight: 600; }

.actions { display: flex; gap: 8px; }

.icon-btn {
  padding: 8px 13px; font-size: 13px; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  cursor: pointer; transition: background .16s, border-color .16s, transform .12s, color .16s;
  white-space: nowrap;
}
.icon-btn:hover { background: #232838; border-color: #333a4d; }
.icon-btn:active { transform: scale(.96); }

.icon-btn.active {
  color: #fff; border-color: transparent;
  background: linear-gradient(135deg, #16a34a, #22c55e);
  box-shadow: 0 6px 18px rgba(34, 197, 94, .3);
}

.icon-btn.muted {
  color: #fff; border-color: transparent;
  background: linear-gradient(135deg, #b45309, #f59e0b);
  box-shadow: 0 6px 18px rgba(245, 158, 11, .3);
}

/* 主体：成员列表 + 消息区 */
.body { flex: 1; display: flex; min-height: 0; }

.members {
  width: 210px; flex: none;
  border-right: 1px solid var(--border);
  background: rgba(15, 18, 25, .5);
  display: flex; flex-direction: column;
}

.members-head {
  padding: 13px 16px; font-size: 12px; color: var(--muted);
  letter-spacing: .5px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between;
}
.members-head span { color: var(--accent-2); font-weight: 600; }

.member-list { flex: 1; overflow-y: auto; padding: 8px; }

.member {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; border-radius: 10px; margin-bottom: 2px;
  transition: background .15s;
}
.member:hover { background: rgba(255, 255, 255, .035); }

.member .avatar {
  width: 30px; height: 30px; flex: none;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 600; color: #fff;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.member.offline .avatar { background: #3a4050; color: #9aa2b5; }

.member .info { min-width: 0; flex: 1; }

.member .name {
  font-size: 13px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: flex; align-items: center; gap: 5px;
}
.member.offline .name { color: var(--muted); font-weight: 400; }

.member .meta { font-size: 11px; color: #5f6679; margin-top: 1px; }
.member .meta .on { color: var(--green); }

.badge-voice {
  font-size: 11px; padding: 1px 6px; border-radius: 999px;
  background: rgba(34, 197, 94, .16); color: #4ade80;
  border: 1px solid rgba(34, 197, 94, .3);
}

.badge-mute {
  font-size: 11px; padding: 1px 6px; border-radius: 999px;
  background: rgba(245, 158, 11, .16); color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, .3);
}

/* 说话高亮 */
.member.speaking { background: rgba(34, 197, 94, .09); }
.member.speaking .name { color: #eafff2; }
.member.speaking .avatar { animation: speakPulse 1s ease-in-out infinite; }

@keyframes speakPulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(34, 197, 94, .85), 0 0 10px rgba(34, 197, 94, .35); }
  50% { box-shadow: 0 0 0 3px rgba(34, 197, 94, 1), 0 0 18px rgba(34, 197, 94, .6); }
}

.me-tag { font-size: 10px; color: var(--accent-2); border: 1px solid rgba(59, 163, 255, .35); padding: 0 4px; border-radius: 4px; }

/* 消息区 */
.messages {
  flex: 1; overflow-y: auto; padding: 20px 18px 8px;
  display: flex; flex-direction: column; gap: 12px; min-height: 0;
}

.messages::-webkit-scrollbar, .member-list::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb, .member-list::-webkit-scrollbar-thumb { background: #2c3142; border-radius: 8px; }
.messages::-webkit-scrollbar-track, .member-list::-webkit-scrollbar-track { background: transparent; }

.row { display: flex; flex-direction: column; max-width: 76%; animation: pop .22s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.row.me { align-self: flex-end; align-items: flex-end; }
.row.peer { align-self: flex-start; align-items: flex-start; }

.sender { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; padding: 0 4px; }

.bubble {
  padding: 10px 14px; border-radius: 15px;
  font-size: 14.5px; line-height: 1.55;
  word-break: break-word; white-space: pre-wrap;
}

.row.me .bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-bottom-right-radius: 5px;
}
.row.peer .bubble {
  background: var(--panel-2); border: 1px solid var(--border); border-bottom-left-radius: 5px;
}

.bubble .text { white-space: pre-wrap; }

.row .foot {
  display: flex; align-items: center; gap: 7px;
  font-size: 11px; color: #5f6679; margin-top: 5px; padding: 0 3px;
}

.read-status { color: #5f6679; }
.read-status.read { color: #4ade80; }

.divider {
  align-self: center; width: 100%;
  display: flex; align-items: center; gap: 12px;
  font-size: 11.5px; color: var(--amber); margin: 6px 0;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: rgba(240, 180, 41, .25); }

.system {
  align-self: center; max-width: 88%; text-align: center;
  font-size: 12px; color: var(--muted);
  background: rgba(255, 255, 255, .035); border: 1px solid var(--border);
  padding: 5px 13px; border-radius: 999px; animation: pop .22s ease;
}

/* 文件卡片 */
.file-card { display: flex; align-items: center; gap: 12px; min-width: 210px; max-width: 320px; }

.file-thumb {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center; font-size: 20px;
  background: rgba(0, 0, 0, .22); border-radius: 11px;
}

.file-img { width: 96px; height: 96px; object-fit: cover; border-radius: 11px; cursor: zoom-in; display: block; }

.file-info { flex: 1; min-width: 0; }

.file-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { font-size: 11.5px; opacity: .72; margin-top: 2px; }

.progress { height: 4px; margin-top: 8px; border-radius: 4px; background: rgba(0, 0, 0, .28); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; border-radius: 4px; transition: width .12s linear; }

.row.me .progress i { background: #fff; }
.row.peer .progress i { background: var(--accent-2); }

.file-dl {
  display: inline-block; margin-top: 7px; font-size: 12px;
  color: var(--accent-2); text-decoration: none;
  border-bottom: 1px dashed rgba(59, 163, 255, .5);
}
.row.me .file-dl { color: #fff; border-bottom-color: rgba(255, 255, 255, .5); }

/* 等待层 */
.waiting {
  position: absolute; inset: 60px 0 72px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; font-size: 13.5px; color: var(--muted);
  pointer-events: none;
  background: linear-gradient(180deg, rgba(11, 13, 19, .3), rgba(11, 13, 19, .72));
}

.spinner {
  width: 26px; height: 26px;
  border: 2.5px solid var(--border); border-top-color: var(--accent-2);
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 输入区 */
.composer {
  flex: none; display: flex; align-items: flex-end; gap: 10px;
  padding: 12px 16px 16px; border-top: 1px solid var(--border);
  background: rgba(20, 23, 31, .9);
}

.composer textarea {
  flex: 1; resize: none; max-height: 130px;
  padding: 12px 15px; font-size: 14.5px; font-family: inherit; line-height: 1.5;
  color: var(--text); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 13px;
  outline: none; transition: border-color .18s, box-shadow .18s;
}

.composer textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(109, 94, 252, .16); }
.composer .icon-btn { padding: 11px 14px; font-size: 16px; }

@media (max-width: 760px) {
  #chatScreen { border: 0; }
  .room-label { display: none; }
  .row { max-width: 88%; }
  .status { min-width: auto; }
  .members { width: 148px; }
  .member .meta { display: none; }
  .icon-btn { padding: 8px 10px; font-size: 12px; }
}