:root {
  --brand: #4f7cff;
  --brand-dark: #3a63d9;
  --bg: #f2f4f8;
  --bubble-in: #ffffff;
  --bubble-out: #4f7cff;
  --text: #1f2430;
  --text-sub: #8a93a6;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ============ 登录页 ============ */
#loginScreen {
  align-items: center;
  justify-content: center;
  padding: 32px 28px;
  background: linear-gradient(160deg, #6c9bff 0%, #4f7cff 45%, #3a63d9 100%);
}

.login-box {
  width: 100%;
  max-width: 380px;
  text-align: center;
  color: #fff;
}

.logo {
  width: 96px;
  height: 96px;
  margin: 0 auto 24px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.18);
  border: 2px solid rgba(255, 255, 255, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 44px;
  font-weight: 700;
  backdrop-filter: blur(6px);
}

.login-box h1 { font-size: 30px; margin: 0 0 8px; font-weight: 700; }
.login-box .sub { font-size: 14px; opacity: 0.85; margin: 0 0 32px; }

.name-input {
  width: 100%;
  height: 50px;
  border: none;
  border-radius: 25px;
  padding: 0 20px;
  font-size: 16px;
  color: #1f2430;
  background: #fff;
  outline: none;
}

.primary-btn {
  width: 100%;
  height: 50px;
  margin-top: 14px;
  border: none;
  border-radius: 25px;
  background: #fff;
  color: var(--brand-dark);
  font-size: 17px;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
}

.primary-btn:active { transform: scale(0.985); }

#loginScreen .tip { font-size: 13px; opacity: 0.8; margin-top: 18px; min-height: 18px; }

/* ============ 聊天页 ============ */
.chat-header {
  flex-shrink: 0;
  padding: calc(var(--safe-t) + 12px) 16px 12px;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.h-info .room-name { font-size: 17px; font-weight: 600; }
.h-info .online { font-size: 12px; opacity: 0.85; margin-top: 3px; }

.ghost-btn {
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: transparent;
  color: #fff;
  border-radius: 16px;
  padding: 6px 14px;
  font-size: 13px;
}

/* ============ 消息列表 ============ */
.msg-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg { display: flex; flex-direction: column; max-width: 78%; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }

.sender { font-size: 11px; color: var(--text-sub); margin: 0 4px 5px; }

.bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
}

.msg.in .bubble {
  background: var(--bubble-in);
  color: var(--text);
  border-bottom-left-radius: 6px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.msg.out .bubble {
  background: var(--bubble-out);
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 1px 2px rgba(79, 124, 255, 0.25);
}

/* 语音气泡 */
.bubble.voice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 96px;
  cursor: pointer;
  user-select: none;
}

.bubble.voice .play-ico {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  border-style: solid;
  border-width: 6px 0 6px 11px;
  border-color: transparent transparent transparent currentColor;
}

.bubble.voice.playing .play-ico {
  width: 12px;
  height: 12px;
  border: none;
  background: currentColor;
  animation: blink 0.9s steps(2, start) infinite;
}

@keyframes blink { 0%, 50% { opacity: 1; } 51%, 100% { opacity: 0.25; } }

.bubble.voice .wave {
  flex: 1;
  height: 14px;
  display: flex;
  align-items: center;
  gap: 2px;
  opacity: 0.75;
}

.bubble.voice .wave i {
  display: block;
  flex: 1;
  background: currentColor;
  border-radius: 1px;
  min-height: 3px;
}

.bubble.voice .dur { font-size: 12px; opacity: 0.85; flex-shrink: 0; }

.msg-time { font-size: 10px; color: var(--text-sub); margin: 5px 4px 0; }

.sys-tip {
  align-self: center;
  font-size: 11px;
  color: var(--text-sub);
  background: rgba(0, 0, 0, 0.05);
  padding: 4px 12px;
  border-radius: 10px;
}

/* ============ 历史消息提示 ============ */
.history-tip {
  flex-shrink: 0;
  height: 20px;
  padding: 0 16px;
  font-size: 12px;
  color: var(--text-sub);
  text-align: center;
}

/* ============ 正在输入 ============ */
.typing-tip {
  flex-shrink: 0;
  height: 20px;
  padding: 0 18px;
  font-size: 12px;
  color: var(--text-sub);
}

/* ============ 输入栏 ============ */
.input-bar {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + var(--safe-b));
  background: #fff;
  border-top: 1px solid #e8ebf2;
}

.mic-btn {
  width: 58px;
  height: 44px;
  flex-shrink: 0;
  border: none;
  border-radius: 22px;
  background: #f0f2f7;
  color: var(--brand);
  font-size: 11px;
  line-height: 1.25;
  font-weight: 600;
  padding: 0;
}

.mic-btn.recording { background: #ff4d5e; color: #fff; }

.text-input {
  flex: 1;
  min-height: 44px;
  max-height: 110px;
  border: 1px solid #e2e6ef;
  border-radius: 22px;
  padding: 11px 16px;
  font-size: 15px;
  outline: none;
  background: #fafbfd;
  resize: none;
}

.send-btn {
  height: 44px;
  padding: 0 18px;
  flex-shrink: 0;
  border: none;
  border-radius: 22px;
  background: var(--brand);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}

.send-btn:disabled { background: #c3cfe8; }

/* ============ 录音遮罩 ============ */
.rec-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.rec-box {
  width: 220px;
  padding: 26px 20px 22px;
  border-radius: 20px;
  background: #fff;
  text-align: center;
}

.rec-wave {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 40px;
}

.rec-wave span {
  width: 5px;
  background: var(--brand);
  border-radius: 3px;
  animation: wave 0.9s ease-in-out infinite;
}

.rec-wave span:nth-child(1) { height: 14px; animation-delay: 0s; }
.rec-wave span:nth-child(2) { height: 26px; animation-delay: 0.12s; }
.rec-wave span:nth-child(3) { height: 36px; animation-delay: 0.24s; }
.rec-wave span:nth-child(4) { height: 24px; animation-delay: 0.36s; }
.rec-wave span:nth-child(5) { height: 16px; animation-delay: 0.48s; }

@keyframes wave {
  0%, 100% { transform: scaleY(0.45); }
  50% { transform: scaleY(1); }
}

.rec-time { font-size: 30px; font-weight: 700; color: var(--brand); margin-top: 10px; }
.rec-tip { font-size: 12px; color: var(--text-sub); margin: 8px 0 16px; }
.rec-box .ghost-btn { color: #ff4d5e; border-color: #ff4d5e; }
