:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --primary: #4f6ef7;
  --primary-dark: #3d55d6;
  --text: #1f2430;
  --muted: #8a90a3;
  --border: #e7e9f2;
  --danger: #e5484d;
  --radius: 16px;
  --shadow: 0 8px 24px rgba(31, 36, 48, 0.06);
  /* 刘海屏 / 底部手势条安全区域 */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

/* 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 16px 24px;
  padding-top: calc(16px + var(--safe-top));
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.nav { display: flex; gap: 8px; flex: 1; }
.nav-btn {
  border: none;
  background: transparent;
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 15px;
  color: var(--muted);
  cursor: pointer;
  transition: all .2s;
}
.nav-btn:hover { color: var(--text); background: var(--bg); }
.nav-btn:active { opacity: .75; }
.nav-btn.active { color: #fff; background: var(--primary); }
.lang-switch {
  flex: none;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  appearance: none;
}

/* 布局 */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  padding-bottom: calc(48px + var(--safe-bottom));
}
.view { display: none; }
.view.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* 语言栏 */
.lang-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.lang-select {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
  appearance: none;
}
.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  font-size: 18px;
  color: var(--primary);
  cursor: pointer;
  transition: all .2s;
}
.icon-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.icon-btn:active { transform: scale(.94); }

/* 输入 */
.text-input {
  width: 100%;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  font-family: inherit;
  resize: vertical;
  min-height: 140px;
  color: var(--text);
  background: var(--card);
}
.text-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,110,247,.12); }

/* 按钮 */
.btn-primary {
  width: 100%;
  margin-top: 16px;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { background: var(--primary-dark); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.translate-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}
.translate-actions .btn-primary {
  flex: 2;
  margin-top: 0;
}
.voice-btn {
  flex: 1;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: all .2s;
}
.voice-btn.active {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

/* 结果 */
.result-box {
  margin-top: 20px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.result-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.result-title { font-weight: 600; font-size: 14px; color: var(--muted); }
.text-btn {
  border: none;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
}
.text-btn:disabled { color: var(--muted); cursor: not-allowed; }
.result-text { font-size: 16px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
.result-text.placeholder { color: var(--muted); }

/* 会议录音 */
.record-card {
  text-align: center;
  background: var(--card);
  border-radius: var(--radius);
  padding: 40px 20px;
  box-shadow: var(--shadow);
}
.record-btn {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .25s;
}
.record-btn:hover { transform: scale(1.05); }
.record-btn:active { transform: scale(.96); }
.record-btn.recording { background: var(--danger); animation: pulse 1.6s infinite; }
.record-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #fff;
  display: inline-block;
}
.record-btn.recording .record-icon { border-radius: 6px; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(229,72,77,.4); }
  70% { box-shadow: 0 0 0 22px rgba(229,72,77,0); }
  100% { box-shadow: 0 0 0 0 rgba(229,72,77,0); }
}
.record-state { margin-top: 18px; font-size: 16px; font-weight: 600; }
.record-time { margin-top: 6px; font-size: 32px; font-weight: 700; font-variant-numeric: tabular-nums; }
.record-tip { margin-top: 12px; font-size: 12px; color: var(--muted); }

/* 识别结果 */
.asr-result {
  margin-top: 20px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1;
  padding: 14px;
  border: none;
  background: transparent;
  font-size: 15px;
  color: var(--muted);
  cursor: pointer;
}
.tab:active { background: var(--bg); }
.tab.active { color: var(--primary); font-weight: 600; border-bottom: 2px solid var(--primary); }
.tab-panel { display: none; padding: 20px; font-size: 15px; line-height: 1.8; white-space: pre-wrap; word-break: break-word; }
.tab-panel.active { display: block; }

.asr-progress {
  margin-top: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  color: var(--muted);
}
.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 历史 */
.history-filter { display: flex; gap: 8px; margin-bottom: 16px; }
.filter-btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
}
.filter-btn:active { opacity: .75; }
.filter-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.history-list { display: flex; flex-direction: column; gap: 12px; }
.history-item {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.history-item .meta { font-size: 12px; color: var(--muted); margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.history-item .body { font-size: 15px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.history-item .del {
  border: none;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-size: 13px;
  padding: 6px 8px;
}
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* 听译 */
.lang-arrow {
  flex: none;
  color: var(--muted);
  font-size: 18px;
  padding: 0 4px;
}
.interpret-controls { text-align: center; margin-bottom: 20px; }
.interpret-btn {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}
.interpret-btn:active { opacity: .85; }
.interpret-btn.active {
  background: var(--danger);
  animation: pulse 1.6s infinite;
}
.interpret-state {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}
.interpret-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 4px 2px;
  -webkit-overflow-scrolling: touch;
}
.interpret-item {
  background: var(--card);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.interpret-src {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 6px;
  word-break: break-word;
}
.interpret-tgt {
  font-size: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 32px;
  bottom: calc(32px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: all .25s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.hidden { display: none !important; }

/* ===== 移动端自适应 ===== */
@media (max-width: 640px) {
  .topbar {
    gap: 8px;
    row-gap: 8px;
    padding: 10px 12px;
    padding-top: calc(10px + var(--safe-top));
    flex-wrap: wrap;
  }
  .brand { font-size: 18px; flex: none; }
  .lang-switch { margin-left: auto; }

  /* 导航换行到第二行，均分为 tab bar */
  .nav {
    flex: 1;
    flex-basis: 100%;
    order: 3;
    gap: 6px;
  }
  .nav-btn {
    flex: 1;
    padding: 11px 0;
    font-size: 14px;
    text-align: center;
    min-height: 40px;
  }

  .container {
    padding: 16px 12px 32px;
    padding-bottom: calc(32px + var(--safe-bottom));
  }

  .lang-bar { gap: 8px; margin-bottom: 12px; }
  .lang-select { padding: 12px 12px; font-size: 15px; }
  .icon-btn { width: 44px; height: 44px; }

  .text-input { min-height: 120px; padding: 14px; }

  .btn-primary { padding: 15px; }

  .result-box { padding: 16px; }

  .record-card { padding: 32px 16px; }
  .record-btn { width: 88px; height: 88px; }
  .record-time { font-size: 30px; }

  .tab { padding: 14px 8px; }
  .tab-panel { padding: 16px; }

  .history-filter { gap: 6px; }
  .filter-btn { flex: 1; padding: 12px 0; text-align: center; }

  .toast { bottom: calc(24px + var(--safe-bottom)); }
}

@media (max-width: 380px) {
  .brand { font-size: 16px; }
  .nav-btn { font-size: 13px; }
  .lang-select { font-size: 14px; padding: 11px 10px; }
  .record-btn { width: 80px; height: 80px; }
  .record-time { font-size: 28px; }
}

/* ===== 用户区 ===== */
.user-box {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
}
.user-phone {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--muted);
}
.user-box .text-btn { font-size: 14px; white-space: nowrap; }

/* ===== 登录 / 注册弹窗 ===== */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(31, 36, 48, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
  padding-top: calc(16px + var(--safe-top));
  padding-bottom: calc(16px + var(--safe-bottom));
}
.auth-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 24px 24px;
  box-shadow: 0 16px 48px rgba(31, 36, 48, 0.18);
  animation: fade .25s ease;
}
.auth-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.auth-close:hover { background: var(--border); color: var(--text); }
.auth-title { font-size: 20px; font-weight: 700; margin-bottom: 18px; text-align: center; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.auth-tab {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}
.auth-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.auth-input {
  min-height: 0;
  margin-bottom: 12px;
  padding: 13px 14px;
  font-size: 15px;
}
.auth-error {
  margin-top: 12px;
  min-height: 18px;
  font-size: 13px;
  color: var(--danger);
  text-align: center;
}
