/* ============================================
   同声传译 Web - 响应式样式
   支持电脑和手机浏览器，Material Design 3 风格
   ============================================ */

/* ---- CSS 变量 ---- */
:root {
  --bg: #0f1019;
  --surface: #1a1b2e;
  --surface-variant: #242540;
  --primary: #a8c7fa;
  --primary-container: #004a77;
  --on-surface: #e2e2e5;
  --on-surface-variant: #9899ab;
  --outline: #44465e;
  --error: #ffb4ab;
  --error-container: #93000a;
  --success: #7dd3a6;
  --shadow: rgba(0, 0, 0, 0.4);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 28px;
}

/* ---- 全局重置 ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans SC', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--on-surface);
  line-height: 1.5;
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---- 工具类 ---- */
.hidden { display: none !important; }

/* ---- 主布局 ---- */
.app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 16px 24px;
}

/* ---- 顶部栏 ---- */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.top-bar h1 {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--on-surface);
  letter-spacing: 0.02em;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--on-surface-variant);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.icon-btn:hover {
  background: var(--surface-variant);
}

/* ---- 语言选择 ---- */
.lang-section {
  padding: 8px 0 16px;
}

.lang-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.lang-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lang-group label {
  font-size: 0.75rem;
  color: var(--on-surface-variant);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
}

.lang-group select {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--outline);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--on-surface);
  font-size: 0.95rem;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%239899ab' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  transition: border-color 0.2s;
}

.lang-group select:focus {
  outline: none;
  border-color: var(--primary);
}

.lang-group select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.swap-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--outline);
  border-radius: 50%;
  background: var(--surface);
  color: var(--on-surface-variant);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-bottom: 1px;
  transition: all 0.2s;
}

.swap-btn:hover {
  background: var(--surface-variant);
  color: var(--primary);
  border-color: var(--primary);
}

/* ---- 控制区域 ---- */
.control-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0 20px;
  gap: 12px;
}

.status-text {
  font-size: 0.875rem;
  color: var(--on-surface-variant);
  text-align: center;
  min-height: 1.4em;
  transition: color 0.3s;
}

.status-text.active {
  color: var(--primary);
}

.status-text.error {
  color: var(--error);
}

/* ---- 录音按钮 ---- */
.record-btn {
  width: 72px;
  height: 72px;
  border: none;
  border-radius: 50%;
  background: var(--primary-container);
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.record-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--primary);
  opacity: 0;
  transition: opacity 0.3s;
}

.record-btn:hover:not(:disabled) {
  background: #005a8c;
}

.record-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.record-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.record-btn.recording {
  background: var(--error-container);
  color: var(--error);
  animation: pulse 2s ease-in-out infinite;
}

.record-btn.recording::before {
  opacity: 1;
  animation: ring-pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@keyframes ring-pulse {
  0%, 100% { transform: scale(1); opacity: 0.3; }
  50% { transform: scale(1.15); opacity: 0; }
}

/* ---- 音频电平指示器 ---- */
.audio-level {
  width: 200px;
  height: 4px;
  background: var(--surface-variant);
  border-radius: 2px;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.3s;
}

.audio-level.visible {
  opacity: 1;
}

.audio-level-bar {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 2px;
  transition: width 0.05s;
}

/* ---- 实时识别区域 ---- */
.partial-section {
  padding: 0 0 8px;
}

.section-label {
  font-size: 0.75rem;
  color: var(--on-surface-variant);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  margin-bottom: 8px;
}

.partial-text {
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  color: var(--primary);
  line-height: 1.6;
  min-height: 2em;
  border: 1px solid var(--surface-variant);
}

/* ---- 翻译记录 ---- */
.transcript-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 200px;
}

.transcript-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px 0 16px;
  scroll-behavior: smooth;
}

.empty-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 16px;
  color: var(--on-surface-variant);
  text-align: center;
  flex: 1;
}

.empty-hint p {
  font-size: 0.875rem;
  opacity: 0.6;
}

/* 翻译条目 */
.transcript-entry {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  border: 1px solid var(--surface-variant);
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.entry-source {
  font-size: 0.875rem;
  color: var(--on-surface-variant);
  margin-bottom: 8px;
  line-height: 1.5;
  word-break: break-word;
}

.entry-divider {
  height: 1px;
  background: var(--surface-variant);
  margin: 8px 0;
}

.entry-translated {
  font-size: 0.95rem;
  color: var(--on-surface);
  line-height: 1.5;
  word-break: break-word;
}

.entry-lang-tags {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.lang-tag {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--surface-variant);
  color: var(--on-surface-variant);
  letter-spacing: 0.04em;
}

/* ---- 对话框 ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  backdrop-filter: blur(4px);
}

.dialog {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 400px;
  border: 1px solid var(--surface-variant);
}

.dialog h2 {
  font-size: 1.2rem;
  font-weight: 500;
  margin-bottom: 8px;
}

.dialog-desc {
  font-size: 0.875rem;
  color: var(--on-surface-variant);
  margin-bottom: 16px;
}

.dialog input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--outline);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--on-surface);
  font-size: 0.95rem;
  margin-bottom: 8px;
  transition: border-color 0.2s;
}

.dialog input:focus {
  outline: none;
  border-color: var(--primary);
}

.dialog-hint {
  font-size: 0.8rem;
  color: var(--on-surface-variant);
  margin-bottom: 20px;
}

.dialog-hint a {
  color: var(--primary);
  text-decoration: none;
}

.dialog-hint a:hover {
  text-decoration: underline;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.btn {
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius-xl);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: var(--bg);
}

.btn-primary:hover {
  filter: brightness(1.1);
}

/* ---- 滚动条 ---- */
.transcript-list::-webkit-scrollbar {
  width: 4px;
}

.transcript-list::-webkit-scrollbar-track {
  background: transparent;
}

.transcript-list::-webkit-scrollbar-thumb {
  background: var(--outline);
  border-radius: 2px;
}

/* ---- 响应式：桌面端 (>640px) ---- */
@media (min-width: 641px) {
  .app {
    padding: 0 24px 32px;
  }

  .top-bar {
    padding: 20px 0;
  }

  .top-bar h1 {
    font-size: 1.4rem;
  }

  .record-btn {
    width: 80px;
    height: 80px;
  }

  .transcript-section {
    min-height: 300px;
  }
}

/* ---- 响应式：小屏手机 (<380px) ---- */
@media (max-width: 380px) {
  .app {
    padding: 0 12px 16px;
  }

  .lang-row {
    gap: 8px;
  }

  .lang-group select {
    padding: 10px 12px;
    font-size: 0.875rem;
  }

  .record-btn {
    width: 64px;
    height: 64px;
  }

  .record-btn .mic-icon {
    width: 26px;
    height: 26px;
  }
}

/* ---- 安全区域适配（刘海屏等） ---- */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .app {
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
}

/* ---- 横屏适配 ---- */
@media (max-height: 500px) and (orientation: landscape) {
  .control-section {
    padding: 4px 0 12px;
  }

  .record-btn {
    width: 56px;
    height: 56px;
  }

  .audio-level {
    display: none;
  }
}
