/* ========== 全局 ========== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #0a0a0a;
  color: #fff;
  min-height: 100vh;
  min-height: 100dvh;
}

body.room-page {
  overflow: hidden;
}

/* ========== 首页 ========== */
.home {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px;
  overflow-y: auto;
}

.home-card {
  background: #1a1a1a;
  border-radius: 20px;
  padding: 40px 32px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 0 40px rgba(37, 211, 102, 0.3), 0 0 80px rgba(37, 211, 102, 0.15);
  animation: glowPulse 4s ease-in-out infinite;
}

@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 40px rgba(37, 211, 102, 0.3), 0 0 80px rgba(37, 211, 102, 0.15); }
  50% { box-shadow: 0 0 60px rgba(37, 211, 102, 0.45), 0 0 100px rgba(37, 211, 102, 0.2); }
}

.room-lang-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  background: #1a1a1a;
}

.room-lang-label {
  font-size: 13px;
  color: #999;
}

.room-lang-bar select {
  background: transparent;
  color: #25D366;
  border: none;
  font-size: 15px;
  font-weight: 600;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  padding: 4px 20px 4px 12px;
  text-align: center;
  text-align-last: center;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2325D366' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 2px center;
}

.room-info {
  font-size: 14px;
  color: #ccc;
}

.version {
  font-size: 10px;
  color: #555;
  position: absolute;
  right: 16px;
  top: 18px;
}

.brand {
  font-size: 13px;
  color: #25D366;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.footer-links {
  margin-top: 20px;
  text-align: center;
}

.footer-links a {
  color: #666;
  font-size: 12px;
  text-decoration: none;
}

.footer-links a:hover {
  color: #25D366;
}

.logo { margin-bottom: 16px; }

.logo img {
  border-radius: 16px;
  border: 2px solid #333;
  box-shadow: 0 0 15px rgba(37, 211, 102, 0.2), 0 0 30px rgba(37, 211, 102, 0.1);
}

.home-card h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.subtitle {
  color: #888;
  font-size: 14px;
  margin-bottom: 28px;
  line-height: 1.5;
}

/* 通话模式 */
.mode-select {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.mode-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #2a2a2a;
  color: #888;
  border: 1px solid #333;
  border-radius: 10px;
  padding: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-btn.active {
  background: #1a3a2a;
  color: #25D366;
  border-color: #25D366;
}

/* 语言选择 */
.lang-select {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 28px;
}

.lang-item { text-align: center; }

.lang-item label {
  display: block;
  font-size: 12px;
  color: #888;
  margin-bottom: 6px;
}

.lang-item select {
  background: #2a2a2a;
  color: #fff;
  border: 1px solid #333;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 15px;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  min-width: 120px;
  text-align: center;
  text-align-last: center;
}

.lang-arrow {
  font-size: 20px;
  color: #25D366;
  margin-top: 18px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.3s;
}

.lang-arrow:active { transform: rotate(180deg); }

/* Turnstile 验证框居中 */
.cf-turnstile {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

/* 按钮 */
.btn-primary {
  background: #25D366;
  color: #000;
  border: none;
  border-radius: 14px;
  padding: 16px 48px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: background 0.2s;
}

.btn-primary:hover { background: #1ebe5a; }
.btn-primary:disabled { background: #333; cursor: not-allowed; }

/* 创建房间结果 */
.created-box {
  margin-top: 20px;
  padding: 20px;
  background: #222;
  border-radius: 12px;
  text-align: center;
}

.created-box p { font-size: 13px; color: #888; }

.room-code {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: 8px;
  color: #25D366;
  margin: 12px 0;
  font-variant-numeric: tabular-nums;
}

.room-tip { margin-bottom: 12px !important; }

.created-actions { display: flex; gap: 10px; }

.btn-share {
  flex: 1;
  background: #2a2a2a;
  color: #25D366;
  border: 1px solid #25D366;
  border-radius: 10px;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn-share:hover { background: #1a3a2a; }

.btn-enter {
  flex: 1;
  background: #25D366;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn-enter:hover { background: #1ebe5a; }

@keyframes pulse-btn {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.tip {
  color: #25D366 !important;
  font-size: 12px !important;
  margin-top: 6px !important;
}

/* 分割线 */
.divider {
  display: flex;
  align-items: center;
  margin: 24px 0;
  color: #555;
  font-size: 13px;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #333;
}

.divider span { padding: 0 12px; }

/* 加入房间 */
.join-section { text-align: center; }
.join-label { font-size: 14px; color: #888; margin-bottom: 12px; }

.join-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.join-row input {
  width: 100%;
  background: #2a2a2a;
  border: 1px solid #333;
  border-radius: 10px;
  color: #fff;
  padding: 14px 16px;
  font-size: 22px;
  text-align: center;
  letter-spacing: 8px;
  font-variant-numeric: tabular-nums;
}

.join-row input::placeholder {
  font-size: 14px;
  letter-spacing: 0;
  color: #555;
}

.btn-join {
  width: 100%;
  background: #25D366;
  color: #000;
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.btn-join:hover { background: #1ebe5a; }

/* ========== 通话房间 ========== */

/*
 * 标准做法：flexbox + dvh + env(safe-area-inset-*)
 * 参考: https://www.w3tutorials.net/blog/ios-mobile-safari-the-bottom-bar-covers-my-footer/
 */
.room {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  background: #000;
  overflow: hidden;
}

/* 顶部状态栏 */
.top-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: #111;
  border-bottom: 1px solid #222;
  position: relative;
}

.status { font-size: 13px; color: #aaa; }

.status .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #25D366;
  margin-right: 6px;
  vertical-align: middle;
}

.timer {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: #ccc;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

/* 视频 */
.videos { position: relative; }
.video-remote { width: 100%; height: 100%; object-fit: cover; background: #111; }
.video-local {
  position: absolute;
  top: 16px; right: 16px;
  width: 120px; height: 160px;
  border-radius: 12px;
  object-fit: cover;
  background: #222;
  border: 2px solid #333;
  z-index: 10;
}

/* 等待覆盖层 */
.waiting-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000;
  z-index: 50;
}

.waiting-overlay h2 { font-size: 20px; font-weight: 600; margin-bottom: 8px; }
.waiting-overlay p { color: #888; font-size: 14px; margin-bottom: 24px; }

.waiting-room-code {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: 8px;
  color: #25D366;
  margin: 12px 0;
}

.btn-copy-room {
  background: #2a2a2a;
  color: #25D366;
  border: 1px solid #25D366;
  border-radius: 10px;
  padding: 10px 28px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 8px;
}

.btn-copy-room:hover { background: #1a3a2a; }

.waiting-dots { display: flex; gap: 8px; margin-top: 20px; }

.waiting-dots span {
  width: 10px;
  height: 10px;
  background: #25D366;
  border-radius: 50%;
  animation: dot-pulse 1.4s infinite ease-in-out;
}

.waiting-dots span:nth-child(2) { animation-delay: 0.2s; }
.waiting-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* 说话光晕 */
.voice-glow {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  width: 300px;
  height: 300px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(37,211,102,0.25) 0%, rgba(37,211,102,0.04) 50%, transparent 70%);
  opacity: 0;
  transition: opacity 0.15s, transform 0.2s;
  pointer-events: none;
  z-index: 0;
}

/* 对话记录（flex:1 填满中间） */
.transcript {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  word-break: break-word;
  line-height: 1.5;
}

.msg.them {
  align-self: flex-start;
  background: rgba(37, 211, 102, 0.15);
  border: 1px solid rgba(37, 211, 102, 0.3);
}

.msg.me {
  align-self: flex-end;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.msg.pending { opacity: 0.5; border-style: dashed; }
.msg-translation { font-size: 16px; color: #fff; }
.msg-original { font-size: 12px; color: #999; margin-top: 4px; }

/* 底部控制栏 */
.controls {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background: #111;
  border-top: 1px solid #222;
}

/* 音量条 */
.volume-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 280px;
}

.vol-label { font-size: 12px; color: #666; white-space: nowrap; }
.vol-val { font-size: 12px; color: #666; min-width: 36px; text-align: right; }

.volume-bar input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 3px;
  background: #333;
  border-radius: 2px;
  outline: none;
}

.volume-bar input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: #25D366;
  border-radius: 50%;
  cursor: pointer;
}

/* 按钮行 */
.ctrl-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.ctrl-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}

.ctrl-btn svg { width: 22px; height: 22px; }

.ctrl-btn.mute,
.ctrl-btn.mic,
.ctrl-btn.cam { background: #2a2a2a; }

.ctrl-btn.mute:hover,
.ctrl-btn.mic:hover,
.ctrl-btn.cam:hover { background: #3a3a3a; }

.ctrl-btn.mute.off,
.ctrl-btn.mic.off,
.ctrl-btn.cam.off { background: #ff4444; }

.ctrl-btn.hangup { background: #ff4444; }
.ctrl-btn.hangup:hover { background: #cc0000; }

/* ========== 响应式 ========== */
@media (max-width: 480px) {
  .home-card { padding: 28px 20px; }
  .home-card h1 { font-size: 20px; }
  .lang-item select { min-width: 100px; font-size: 14px; padding: 8px 12px; }
  .btn-primary { padding: 14px 32px; font-size: 16px; }
  .video-local { width: 90px; height: 120px; top: 70px; }
}
