/* ============================================
   刘武大帅B的翻译器原型测试版本 - 样式
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.7);
  --bg-glass: rgba(255, 255, 255, 0.03);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(99, 102, 241, 0.3);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-indigo: #6366f1;
  --accent-violet: #8b5cf6;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-rose: #f43f5e;
  --accent-amber: #f59e0b;
  --gradient-primary: linear-gradient(135deg, #6366f1, #8b5cf6);
  --gradient-bg: linear-gradient(135deg, #0a0e1a 0%, #1a1040 50%, #0a0e1a 100%);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.15);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--gradient-bg);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
}

/* Animated background */
body::before {
  content: '';
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 30% 40%, rgba(99, 102, 241, 0.06) 0%, transparent 50%),
    radial-gradient(circle at 70% 60%, rgba(139, 92, 246, 0.05) 0%, transparent 50%),
    radial-gradient(circle at 50% 80%, rgba(6, 182, 212, 0.04) 0%, transparent 50%);
  animation: bgFloat 20s ease-in-out infinite;
  z-index: -1;
}

@keyframes bgFloat {

  0%,
  100% {
    transform: translate(0, 0) rotate(0deg);
  }

  33% {
    transform: translate(2%, -2%) rotate(1deg);
  }

  66% {
    transform: translate(-1%, 1%) rotate(-0.5deg);
  }
}

/* ============ LAYOUT ============ */

.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

/* ============ HEADER ============ */

.header {
  text-align: center;
  margin-bottom: 28px;
}

.header h1 {
  font-size: 2rem;
  font-weight: 700;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.header p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 400;
}

/* ============ CARDS ============ */

.card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

.card-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title .icon {
  font-size: 1rem;
}

/* ============ API KEY ============ */

.api-key-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.input-wrapper {
  flex: 1;
  position: relative;
}

.input-wrapper input {
  width: 100%;
  padding: 10px 42px 10px 14px;
  background: var(--bg-glass);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-wrapper input:focus {
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.input-wrapper input::placeholder {
  color: var(--text-muted);
  font-family: 'Inter', sans-serif;
}

.btn-toggle-vis {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px;
  transition: color var(--transition);
}

.btn-toggle-vis:hover {
  color: var(--text-secondary);
}

/* ============ BUTTONS ============ */

.btn {
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}

.btn-start {
  background: var(--gradient-primary);
  color: #fff;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

.btn-start:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(99, 102, 241, 0.4);
}

.btn-stop {
  background: rgba(244, 63, 94, 0.15);
  color: var(--accent-rose);
  border: 1px solid rgba(244, 63, 94, 0.3);
}

.btn-stop:not(:disabled):hover {
  background: rgba(244, 63, 94, 0.25);
  transform: translateY(-1px);
}

.btn-talk {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  cursor: grab;
  transition: all 0.15s ease;
}

.btn-talk:not(:disabled):hover {
  background: rgba(16, 185, 129, 0.25);
}

.btn-talk:not(:disabled).active {
  background: linear-gradient(135deg, #059669, #10b981);
  color: #fff;
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.5), 0 0 40px rgba(16, 185, 129, 0.2);
  transform: scale(1.05);
  cursor: grabbing;
  border-color: transparent;
}

/* ============ Floating Controls Overlay ============ */

.floating-controls {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.floating-controls.visible {
  opacity: 1;
  pointer-events: auto;
}

.btn-talk-float {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  border: 2px solid rgba(16, 185, 129, 0.3);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.05);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  cursor: grab;
  transition: all 0.2s ease;
}

.btn-talk-float span {
  font-size: 2rem;
  line-height: 1;
}

.btn-talk-float:not(:disabled):hover {
  background: rgba(16, 185, 129, 0.25);
  transform: scale(1.05);
}

.btn-talk-float:not(:disabled).active {
  background: linear-gradient(135deg, #059669, #10b981);
  color: #fff;
  box-shadow: 0 0 30px rgba(16, 185, 129, 0.6), 0 0 60px rgba(16, 185, 129, 0.3), 0 8px 32px rgba(0, 0, 0, 0.3);
  transform: scale(1.1);
  cursor: grabbing;
  border-color: transparent;
}

.btn-stop-float {
  padding: 10px 28px;
  font-size: 0.85rem;
  border-radius: var(--radius-lg);
  background: rgba(244, 63, 94, 0.15);
  color: var(--accent-rose);
  border: 1px solid rgba(244, 63, 94, 0.3);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.btn-stop-float:not(:disabled):hover {
  background: rgba(244, 63, 94, 0.25);
  transform: translateY(-1px);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.78rem;
}

.btn-ghost {
  background: var(--bg-glass);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

/* ============ CONTROLS ============ */

.controls-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  background: rgba(100, 116, 139, 0.15);
  color: var(--text-secondary);
  border: 1px solid rgba(100, 116, 139, 0.2);
  margin-left: auto;
  transition: all var(--transition);
}

.status-badge .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition);
}

.status-badge.connected {
  background: rgba(16, 185, 129, 0.12);
  color: var(--accent-emerald);
  border-color: rgba(16, 185, 129, 0.25);
}

.status-badge.connected .dot {
  background: var(--accent-emerald);
  animation: pulse 2s ease-in-out infinite;
}

.status-badge.error {
  background: rgba(244, 63, 94, 0.12);
  color: var(--accent-rose);
  border-color: rgba(244, 63, 94, 0.25);
}

.status-badge.error .dot {
  background: var(--accent-rose);
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.4;
  }
}

/* ============ TTS Auto-Play Toggle ============ */

.lang-select {
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  background: var(--bg-glass);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2394a3b8'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 22px;
}

.lang-select:focus {
  border-color: var(--accent-indigo);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.lang-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.btn-tts {
  margin-left: auto;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  background: var(--bg-glass);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-tts:hover {
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.06);
}

.btn-tts.active {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  border-color: rgba(16, 185, 129, 0.35);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.15);
}

/* ============ TRANSCRIPT PANELS (Chat Bubbles) ============ */

.lang-arrow {
  color: var(--text-muted);
  font-size: 1rem;
  padding: 0 4px;
  user-select: none;
}

.transcript-panel {
  min-height: 200px;
  max-height: 400px;
  display: flex;
  flex-direction: column;
}

.transcript-panel .card-title {
  flex-shrink: 0;
}

.transcript-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Paired bubble: source + divider + translation in one */
.paired-bubble {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  animation: bubbleIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.paired-bubble .chat-avatar {
  margin-top: 4px;
}

.paired-bubble .chat-body {
  max-width: 90%;
  flex: 1;
}

.paired-bubble .chat-msg-pair {
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.15);
}

.paired-bubble .source-text {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text-primary);
  word-break: break-word;
}

.paired-bubble .bubble-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15), transparent);
  margin: 8px 0;
}

.paired-bubble .translation-text {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--accent-cyan);
  word-break: break-word;
  font-style: italic;
}

.paired-bubble .translation-text.pending {
  opacity: 0.5;
}

/* Play button on each bubble */
.bubble-play-btn {
  align-self: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.bubble-play-btn:hover {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--accent-indigo);
  color: var(--accent-indigo);
  transform: scale(1.1);
}

.bubble-play-btn.hidden {
  opacity: 0;
  pointer-events: none;
}

.transcript-content::-webkit-scrollbar {
  width: 5px;
}

.transcript-content::-webkit-scrollbar-track {
  background: transparent;
}

.transcript-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}

/* Chat bubble base */
.chat-bubble {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: bubbleIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes bubbleIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.95);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.chat-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  flex-shrink: 0;
  font-weight: 600;
}

.chat-body {
  max-width: 85%;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-msg {
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.6;
  word-break: break-word;
  position: relative;
}

.chat-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px;
}

.chat-time {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.chat-speaker {
  font-size: 0.6rem;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-indigo);
}

.chat-tag {
  font-size: 0.6rem;
  font-weight: 500;
  padding: 1px 5px;
  border-radius: 4px;
}

/* Source message - left aligned, indigo tones */
.chat-bubble.source {
  align-self: flex-start;
}

.chat-bubble.source .chat-avatar {
  background: rgba(99, 102, 241, 0.2);
  color: var(--accent-indigo);
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.chat-bubble.source .chat-msg {
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.15);
  border-bottom-left-radius: 4px;
  color: var(--text-primary);
}

.chat-bubble.source .chat-tag {
  background: rgba(99, 102, 241, 0.12);
  color: var(--accent-indigo);
}

/* Translation message - right aligned, cyan/emerald tones */
.chat-bubble.translation {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-bubble.translation .chat-body {
  align-items: flex-end;
}

.chat-bubble.translation .chat-avatar {
  background: rgba(6, 182, 212, 0.2);
  color: var(--accent-cyan);
  border: 1px solid rgba(6, 182, 212, 0.3);
}

.chat-bubble.translation .chat-msg {
  background: rgba(6, 182, 212, 0.1);
  border: 1px solid rgba(6, 182, 212, 0.15);
  border-bottom-right-radius: 4px;
  color: var(--text-primary);
}

.chat-bubble.translation .chat-meta {
  flex-direction: row-reverse;
}

.chat-bubble.translation .chat-tag {
  background: rgba(6, 182, 212, 0.12);
  color: var(--accent-cyan);
}

/* Partial / typing bubble */
.chat-bubble.partial .chat-msg {
  opacity: 0.6;
  font-style: italic;
  border-style: dashed;
}

.chat-bubble.partial .chat-msg::after {
  content: '';
  display: inline-block;
  width: 4px;
  height: 14px;
  background: var(--text-muted);
  margin-left: 3px;
  vertical-align: middle;
  border-radius: 2px;
  animation: cursorBlink 1s step-end infinite;
}

@keyframes cursorBlink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}

/* ============ LOG PANEL ============ */

.log-section {
  margin-top: 8px;
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  padding: 4px 0;
}

.log-header:hover .card-title {
  color: var(--text-secondary);
}

.log-toggle-icon {
  color: var(--text-muted);
  transition: transform var(--transition);
  font-size: 0.9rem;
}

.log-toggle-icon.open {
  transform: rotate(180deg);
}

.log-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 500;
  background: var(--bg-glass);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: all var(--transition);
}

.filter-btn:hover,
.filter-btn.active {
  color: var(--text-primary);
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(99, 102, 241, 0.3);
}

.log-container {
  max-height: 350px;
  overflow-y: auto;
  overflow-x: hidden;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  line-height: 1.7;
}

.log-container::-webkit-scrollbar {
  width: 5px;
}

.log-container::-webkit-scrollbar-track {
  background: transparent;
}

.log-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
}

.log-entry {
  padding: 5px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  display: flex;
  gap: 8px;
  align-items: flex-start;
  transition: background var(--transition);
}

.log-entry:hover {
  background: rgba(255, 255, 255, 0.02);
}

.log-time {
  color: var(--text-muted);
  flex-shrink: 0;
  font-size: 0.7rem;
  min-width: 75px;
}

.log-dir {
  flex-shrink: 0;
  font-weight: 600;
  width: 18px;
  text-align: center;
}

.log-dir.send {
  color: var(--accent-cyan);
}

.log-dir.recv {
  color: var(--accent-emerald);
}

.log-dir.sys {
  color: var(--accent-amber);
}

.log-dir.err {
  color: var(--accent-rose);
}

.log-type {
  flex-shrink: 0;
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 500;
  min-width: 56px;
  text-align: center;
}

.log-type.ws {
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-indigo);
}

.log-type.audio {
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-cyan);
}

.log-type.data {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
}

.log-type.error {
  background: rgba(244, 63, 94, 0.15);
  color: var(--accent-rose);
}

.log-type.info {
  background: rgba(100, 116, 139, 0.15);
  color: var(--text-secondary);
}

.log-msg {
  flex: 1;
  color: var(--text-secondary);
  word-break: break-all;
}

.log-detail-toggle {
  color: var(--accent-indigo);
  cursor: pointer;
  text-decoration: underline;
  margin-left: 4px;
}

.log-detail-toggle:hover {
  color: var(--accent-violet);
}

.log-detail {
  display: none;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 6px;
  padding: 8px 10px;
  margin: 4px 0 4px 100px;
  white-space: pre-wrap;
  color: var(--text-muted);
  font-size: 0.7rem;
  border: 1px solid rgba(255, 255, 255, 0.04);
  max-height: 200px;
  overflow-y: auto;
}

.log-detail.open {
  display: block;
}

.log-counter {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-left: auto;
  flex-shrink: 0;
}

/* ============ RESPONSIVE ============ */

@media (max-width: 768px) {
  .transcript-grid {
    grid-template-columns: 1fr;
  }

  .api-key-row {
    flex-direction: column;
  }

  .controls-row {
    flex-direction: column;
    align-items: stretch;
  }

  .status-badge {
    margin-left: 0;
    justify-content: center;
  }

  .header h1 {
    font-size: 1.5rem;
  }

  .log-detail {
    margin-left: 0;
  }
}