/* =========================================
   VoiceLink — 移动端优先语音通话 UI
   UX 二次迭代版
   ========================================= */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-dark: #0a0e1a;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-glass: rgba(255, 255, 255, 0.06);
  --accent: #6C63FF;
  --accent-light: #8B83FF;
  --accent-glow: rgba(108, 99, 255, 0.3);
  --blue: #3B82F6;
  --green: #10B981;
  --red: #EF4444;
  --amber: #F59E0B;
  --text-primary: #F1F5F9;
  --text-secondary: #94A3B8;
  --text-dim: #64748B;
  --radius: 16px;
  --radius-sm: 10px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-dark);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ---- 视图系统 ---- */
.view {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1;
}

.view.active {
  display: flex;
  align-items: center;
  justify-content: center;
  animation: viewIn 0.35s ease-out;
}

@keyframes viewIn {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

/* =========================================
   首页
   ========================================= */
.home-container {
  width: 100%;
  max-width: 400px;
  padding: 40px 24px;
  text-align: center;
}

.logo-area { margin-bottom: 48px; }

.logo-icon {
  width: 88px; height: 88px;
  margin: 0 auto 20px;
  animation: float 3s ease-in-out infinite;
}

.logo-icon svg {
  width: 100%; height: 100%;
  filter: drop-shadow(0 0 24px var(--accent-glow));
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-10px) rotate(2deg); }
}

.home-container h1 {
  font-size: 34px; font-weight: 700; letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text; margin-bottom: 8px;
}

.tagline { font-size: 15px; color: var(--text-secondary); }

/* 主按钮 */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 18px 32px; font-size: 17px; font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  border: none; border-radius: var(--radius); cursor: pointer;
  position: relative; overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 24px var(--accent-glow);
  font-family: var(--font);
}

.btn-primary:active { transform: scale(0.96); }
.btn-primary:disabled { opacity: 0.6; pointer-events: none; }

.btn-primary::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.18), transparent 60%);
  pointer-events: none;
}

.btn-icon { font-size: 20px; }

/* R1: 连接进度步骤 */
.progress-section { margin-top: 24px; animation: slideUp 0.4s ease-out; }

.progress-steps {
  display: flex; flex-direction: column; gap: 0;
  text-align: left; padding: 0 8px;
}

.step {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; color: var(--text-dim);
  transition: color 0.3s;
  position: relative;
}

.step::before {
  content: '';
  position: absolute; left: 7px; top: 32px;
  width: 2px; height: calc(100% - 12px);
  background: rgba(255,255,255,0.06);
}

.step:last-child::before { display: none; }

.step-dot {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.15);
  flex-shrink: 0; position: relative; z-index: 1;
  transition: all 0.3s;
  background: var(--bg-dark);
}

.step-text { font-size: 14px; transition: color 0.3s; }

.step.active { color: var(--accent-light); }
.step.active .step-dot {
  border-color: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
  animation: stepPulse 1.5s ease-in-out infinite;
}

.step.active::before { background: var(--accent); opacity: 0.3; }

.step.done { color: var(--green); }
.step.done .step-dot {
  border-color: var(--green);
  background: var(--green);
}

.step.done::before { background: var(--green); opacity: 0.3; }

@keyframes stepPulse {
  0%, 100% { box-shadow: 0 0 4px var(--accent-glow); }
  50% { box-shadow: 0 0 12px var(--accent-glow); }
}

/* 分享区域 */
.share-section {
  margin-top: 24px;
  animation: slideUp 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.share-label { font-size: 14px; color: var(--text-secondary); margin-bottom: 12px; }

/* R4: 短链显示 */
.share-link-box {
  display: flex;
  background: var(--bg-glass);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.share-url-display {
  flex: 1; padding: 14px 16px;
  font-size: 14px; font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--text-dim);
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 0;
}

.share-domain { color: var(--text-dim); }

.share-room-id {
  color: var(--accent-light);
  font-weight: 600;
  background: rgba(108, 99, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 2px;
}

.btn-copy {
  padding: 14px 20px; font-size: 14px; font-weight: 600;
  color: var(--accent-light);
  background: rgba(108, 99, 255, 0.1);
  border: none; border-left: 1px solid rgba(255,255,255,0.06);
  cursor: pointer; transition: background 0.2s;
  font-family: var(--font); white-space: nowrap;
}

.btn-copy:active { background: rgba(108, 99, 255, 0.25); }

.copy-toast {
  margin-top: 8px; font-size: 13px; color: var(--green);
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.btn-share {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 16px; padding: 12px 24px; font-size: 15px; font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-glass);
  border: 1px solid rgba(255,255,255,0.1); border-radius: var(--radius);
  cursor: pointer; transition: all 0.2s; font-family: var(--font);
}

.btn-share:active { transform: scale(0.96); background: rgba(255,255,255,0.1); }

/* 平台快捷分享 */
.share-platforms {
  display: flex; justify-content: center; gap: 12px;
  margin-top: 16px;
}

.platform-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 16px; min-width: 72px;
  background: var(--bg-glass);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px; cursor: pointer;
  color: var(--text-secondary); font-size: 11px; font-weight: 500;
  text-decoration: none; font-family: var(--font);
  transition: all 0.15s;
}

.platform-btn:active { transform: scale(0.93); }
.platform-btn svg { opacity: 0.9; }

.platform-btn.tg { border-color: rgba(0,136,204,0.2); }
.platform-btn.tg svg { color: #0088CC; }
.platform-btn.tg:active { background: rgba(0,136,204,0.1); }

.platform-btn.wa { border-color: rgba(37,211,102,0.2); }
.platform-btn.wa svg { color: #25D366; }
.platform-btn.wa:active { background: rgba(37,211,102,0.1); }

.platform-btn.wx { border-color: rgba(7,193,96,0.2); }
.platform-btn.wx svg { color: #07C160; }
.platform-btn.wx:active { background: rgba(7,193,96,0.1); }

.platform-btn.sms { border-color: rgba(255,255,255,0.1); }
.platform-btn.sms svg { color: var(--accent-light); }

/* QR 码 */
.qr-section {
  margin-top: 16px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}

.btn-qr-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; font-size: 13px;
  color: var(--text-dim); background: transparent;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 20px; cursor: pointer;
  font-family: var(--font); transition: all 0.15s;
}

.btn-qr-toggle:active { background: var(--bg-glass); }
.btn-qr-toggle svg { opacity: 0.5; }

.qr-canvas {
  background: #fff; border-radius: 12px;
  padding: 0; /* padding handled by QR drawing */
  animation: fadeIn 0.3s ease-out;
}

.waiting-indicator {
  margin-top: 24px; display: flex; flex-direction: column;
  align-items: center; gap: 12px;
}

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

.waiting-dots span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); opacity: 0.3;
  animation: dotPulse 1.4s ease-in-out infinite;
}

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

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1.2); }
}

.share-hint { font-size: 14px; color: var(--text-dim); }

/* =========================================
   通话房间
   ========================================= */
.room-container {
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: space-between;
  padding: 48px 24px 48px;
  background: radial-gradient(ellipse at 50% 0%, rgba(108,99,255,0.08) 0%, transparent 60%),
              var(--bg-dark);
  transition: background 0.5s;
}

/* R6: 通话中背景 */
.room-container.in-call {
  background: radial-gradient(ellipse at 50% 0%, rgba(16,185,129,0.06) 0%, transparent 60%),
              var(--bg-dark);
}

.room-container.call-ended {
  background: radial-gradient(ellipse at 50% 0%, rgba(239,68,68,0.06) 0%, transparent 60%),
              var(--bg-dark);
}

.conn-badge {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 14px;
  background: var(--bg-glass);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 20px; font-size: 12px;
  color: var(--text-secondary);
  backdrop-filter: blur(8px);
  animation: fadeIn 0.3s ease-out;
}

.conn-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green);
}

.conn-dot.relay { background: var(--amber); }

.call-status-area {
  display: flex; flex-direction: column;
  align-items: center; gap: 14px;
}

.call-avatar { position: relative; width: 120px; height: 120px; }

.avatar-ring {
  position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid var(--accent); opacity: 0.3;
  animation: pulse-ring 2s ease-out infinite;
}

@keyframes pulse-ring {
  0% { transform: scale(1); opacity: 0.3; }
  50% { transform: scale(1.18); opacity: 0; }
  100% { transform: scale(1); opacity: 0; }
}

.avatar-inner {
  width: 100%; height: 100%; border-radius: 50%;
  background: linear-gradient(135deg, rgba(108,99,255,0.2), rgba(59,130,246,0.2));
  border: 2px solid rgba(108,99,255,0.3);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent-light); transition: all 0.5s ease;
}

.call-avatar.connected .avatar-ring {
  border-color: var(--green);
  animation: pulse-ring-green 2.5s ease-out infinite;
}

.call-avatar.connected .avatar-inner {
  background: linear-gradient(135deg, rgba(16,185,129,0.2), rgba(59,130,246,0.12));
  border-color: rgba(16,185,129,0.35); color: var(--green);
}

@keyframes pulse-ring-green {
  0% { transform: scale(1); opacity: 0.3; }
  50% { transform: scale(1.18); opacity: 0; }
  100% { transform: scale(1); opacity: 0; }
}

.call-status { font-size: 18px; font-weight: 600; transition: color 0.3s; }

.call-timer {
  font-size: 42px; font-weight: 300;
  color: var(--text-secondary); letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
}

/* R2: 结束摘要 */
.call-summary {
  display: flex; flex-direction: column;
  align-items: center; gap: 8px;
  animation: fadeIn 0.5s ease-out;
}

.summary-duration {
  font-size: 52px; font-weight: 300;
  color: var(--text-secondary); letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
}

.summary-label { font-size: 14px; color: var(--text-dim); }

/* 加入按钮 */
.btn-join {
  max-width: 240px; padding: 16px 40px; font-size: 18px;
  animation: pulse-join 2s ease-in-out infinite;
}

@keyframes pulse-join {
  0%, 100% { box-shadow: 0 4px 24px var(--accent-glow); }
  50% { box-shadow: 0 4px 40px var(--accent-glow), 0 0 60px rgba(108,99,255,0.15); }
}

/* 音频区 */
.audio-section {
  display: flex; flex-direction: column;
  align-items: center; gap: 12px;
  width: 100%; max-width: 300px;
}

.visualizer {
  display: flex; align-items: center; justify-content: center;
  gap: 5px; height: 56px;
}

.viz-bar {
  width: 4px; height: 6px; border-radius: 4px;
  background: linear-gradient(to top, var(--accent), var(--blue));
  transition: height 0.08s ease;
  animation: viz-idle 1.2s ease-in-out infinite;
}

.viz-bar:nth-child(1) { animation-delay: 0s; }
.viz-bar:nth-child(2) { animation-delay: 0.08s; }
.viz-bar:nth-child(3) { animation-delay: 0.16s; }
.viz-bar:nth-child(4) { animation-delay: 0.24s; }
.viz-bar:nth-child(5) { animation-delay: 0.32s; }
.viz-bar:nth-child(6) { animation-delay: 0.24s; }
.viz-bar:nth-child(7) { animation-delay: 0.16s; }
.viz-bar:nth-child(8) { animation-delay: 0.08s; }
.viz-bar:nth-child(9) { animation-delay: 0s; }

@keyframes viz-idle {
  0%, 100% { height: 6px; }
  50% { height: 28px; }
}

.mic-level-wrap {
  display: flex; align-items: center; gap: 8px;
  width: 100%; max-width: 160px; opacity: 0.6;
}

.mic-level-icon { color: var(--text-dim); flex-shrink: 0; }

.mic-level-track {
  flex: 1; height: 3px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px; overflow: hidden;
}

.mic-level-bar {
  height: 100%; width: 0%;
  background: linear-gradient(to right, var(--green), var(--accent));
  border-radius: 2px; transition: width 0.1s ease;
}

/* 控制按钮 */
.call-controls {
  display: flex; align-items: center; justify-content: center;
  gap: 20px;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.ctrl-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--bg-glass);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px; padding: 16px 22px;
  color: var(--text-primary); cursor: pointer;
  transition: all 0.15s; min-width: 76px;
  font-family: var(--font); backdrop-filter: blur(4px);
  position: relative;
}

.ctrl-btn svg:not(.hangup-progress) { width: 26px; height: 26px; }
.ctrl-btn span { font-size: 11px; color: var(--text-secondary); }
.ctrl-btn:active { transform: scale(0.92); background: rgba(255,255,255,0.12); }
.ctrl-btn.active { background: rgba(108,99,255,0.15); border-color: rgba(108,99,255,0.3); }
.ctrl-btn.active svg:not(.hangup-progress) { color: var(--accent-light); }

/* R5: 挂断按钮 + 长按进度环 */
.hangup-btn {
  background: rgba(239,68,68,0.15);
  border-color: rgba(239,68,68,0.2);
}

.hangup-btn svg:not(.hangup-progress) { color: var(--red); }
.hangup-btn span { color: var(--red); }
.hangup-btn:active { background: rgba(239,68,68,0.35); }

.hangup-progress {
  position: absolute;
  top: -3px; left: -3px;
  width: calc(100% + 6px); height: calc(100% + 6px);
  pointer-events: none; opacity: 0;
  transition: opacity 0.15s;
}

.hangup-btn.pressing .hangup-progress { opacity: 1; }

.hidden { display: none !important; }

/* iOS safe area */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .call-controls { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .room-container { padding-bottom: calc(48px + env(safe-area-inset-bottom)); }
}

/* 横屏 */
@media (orientation: landscape) and (max-height: 500px) {
  .room-container { padding: 16px 24px; flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 16px; }
  .call-status-area { padding-top: 0; }
  .call-avatar { width: 72px; height: 72px; }
  .call-timer { font-size: 24px; }
  .conn-badge { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); }
}

/* 小屏 */
@media (max-height: 640px) and (orientation: portrait) {
  .call-avatar { width: 96px; height: 96px; }
  .call-timer { font-size: 34px; }
  .room-container { padding-top: 32px; }
}

/* 诊断面板 */
.diag-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  z-index: 100; text-align: center;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.diag-bar button {
  padding: 6px 16px; font-size: 11px;
  color: var(--text-dim); background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px 12px 0 0; border-bottom: none;
  cursor: pointer; font-family: var(--font);
  backdrop-filter: blur(8px);
}

.diag-panel {
  background: rgba(0,0,0,0.85);
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: 12px 16px;
  max-height: 200px; overflow-y: auto;
  backdrop-filter: blur(12px);
}

.diag-panel pre {
  font-size: 11px; font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--green); white-space: pre-wrap;
  word-break: break-all; line-height: 1.5; margin: 0;
}
