/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:            #080812;
  --surface:       #0f0f1e;
  --card:          #14142a;
  --card-hover:    #1a1a34;
  --accent:        #6366f1;
  --accent-light:  #818cf8;
  --accent-dim:    rgba(99, 102, 241, 0.15);
  --accent-glow:   rgba(99, 102, 241, 0.35);
  --text-primary:  #f0f0ff;
  --text-secondary:#8b8baa;
  --text-muted:    #44446a;
  --border:        rgba(255, 255, 255, 0.06);
  --border-active: rgba(99, 102, 241, 0.4);
  --error:         #f87171;
  --success:       #34d399;
  --radius-sm:     8px;
  --radius-md:     14px;
  --radius-lg:     22px;
  --radius-full:   999px;
  --font:          'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --transition:    0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── App Shell ────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

/* ── Header ───────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  flex-shrink: 0;
  position: relative;
}

.header .pill-toggle {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  border-radius: 50%;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
}

.icon-btn:hover { color: var(--text-secondary); background: rgba(255,255,255,0.06); }

#soundBtn.sound-on { color: var(--accent-light); }

#clearBtn.icon-btn:hover { color: var(--error); }

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.logo svg {
  color: var(--accent-light);
}

/* Pill toggle (mode switcher) */
.pill-toggle {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 3px;
  gap: 0;
  position: relative;
}

.pill-btn {
  position: relative;
  z-index: 1;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: color var(--transition);
  white-space: nowrap;
}

.pill-btn.active {
  color: var(--text-primary);
  background: var(--card);
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

/* ── Direction Bar ────────────────────────────────────────── */
.direction-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 20px;
  gap: 10px;
  flex-shrink: 0;
}

.dir-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
}

.dir-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  cursor: pointer;
  transition: all var(--transition);
  flex: 1;
  justify-content: center;
}

.dir-btn:hover {
  border-color: var(--border-active);
  color: var(--text-primary);
}

.dir-btn.active {
  background: var(--accent-dim);
  border-color: var(--border-active);
  color: var(--accent-light);
}

.dir-btn .flag { font-size: 16px; }
.dir-btn .lang-code { font-size: 13px; font-weight: 600; letter-spacing: 0.5px; }
.dir-btn .arrow-icon { opacity: 0.5; flex-shrink: 0; }
.dir-btn.active .arrow-icon { opacity: 0.8; color: var(--accent-light); }

/* ── Two-Way Bar ──────────────────────────────────────────── */
.twoway-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 20px 4px;
  gap: 4px;
  flex-shrink: 0;
}

.twoway-info {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
}

.twoway-info svg { opacity: 0.5; }
.twoway-lang { color: var(--text-primary); }
.twoway-hint { font-size: 11px; color: var(--text-muted); letter-spacing: 0.3px; }

/* ── Status Area ──────────────────────────────────────────── */
.status-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 20px;
  gap: 6px;
  min-height: 52px;
  flex-shrink: 0;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 5px 12px;
  transition: all var(--transition);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition);
  flex-shrink: 0;
}

.status-pill.listening .status-dot {
  background: var(--accent-light);
  box-shadow: 0 0 8px var(--accent-glow);
  animation: dotPulse 1.5s ease-in-out infinite;
}

.status-pill.processing .status-dot { background: #fbbf24; box-shadow: 0 0 8px rgba(251,191,36,0.4); }
.status-pill.speaking .status-dot  { background: var(--success); box-shadow: 0 0 8px rgba(52,211,153,0.4); }
.status-pill.error .status-dot     { background: var(--error); }

.status-text {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.2px;
}

.status-pill.listening .status-text { color: var(--accent-light); }
.status-pill.processing .status-text { color: #fbbf24; }
.status-pill.speaking .status-text  { color: var(--success); }
.status-pill.error .status-text     { color: var(--error); }

.interim-text {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
  min-height: 18px;
  padding: 0 20px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  transition: opacity var(--transition);
}

/* ── Transcript ───────────────────────────────────────────── */
.transcript-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.transcript {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: 8px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: none;
  box-sizing: border-box;
}

.transcript::-webkit-scrollbar { display: none; }

.scroll-thumb {
  position: absolute;
  right: 3px;
  width: 3px;
  border-radius: 2px;
  background: rgba(255,255,255,0.22);
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
  z-index: 10;
}

/* Empty state */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.empty-title { font-size: 15px; font-weight: 500; color: var(--text-secondary); }
.empty-hint  { font-size: 13px; color: var(--text-muted); text-align: center; }

/* Chat Bubbles */
.bubble {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: bubbleIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.bubble-left  { align-self: flex-start; }
.bubble-right { align-self: flex-end;   }

.bubble-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bubble-left  .bubble-card { border-bottom-left-radius: 4px; }
.bubble-right .bubble-card { border-bottom-right-radius: 4px; background: var(--accent-dim); border-color: var(--border-active); }

.bubble-lang-tag {
  display: none;
}

.bubble-original {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-secondary);
  font-style: italic;
  line-height: 1.45;
}

.bubble-right .bubble-original { color: var(--accent-light); }

.bubble-divider {
  height: 1px;
  background: var(--border);
  margin: 2px 0;
}

.bubble-right .bubble-divider { background: rgba(99,102,241,0.2); }

.bubble-translated {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.45;
}

.bubble-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  padding: 0 2px;
  align-self: flex-end;
}

.bubble-left .bubble-time { align-self: flex-start; }

/* ── Bottom Controls ──────────────────────────────────────── */
.bottom-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 20px 28px;
  gap: 16px;
  flex-shrink: 0;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

/* Input mode switch row */
.input-mode-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.input-mode-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  transition: color var(--transition);
  user-select: none;
}

.input-mode-label.active-label { color: var(--text-secondary); }

/* Toggle switch */
.switch { position: relative; display: inline-flex; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }

.switch-track {
  width: 44px;
  height: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  padding: 2px;
  transition: all var(--transition);
}

.switch input:checked + .switch-track {
  background: var(--accent-dim);
  border-color: var(--border-active);
}

.switch-thumb {
  width: 18px;
  height: 18px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: all var(--transition);
  flex-shrink: 0;
}

.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(20px);
  background: var(--accent-light);
  box-shadow: 0 0 8px var(--accent-glow);
}

/* Mic button area */
.mic-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.mic-btn {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  outline: none;
}

.mic-btn:hover { background: var(--accent-light); transform: scale(1.03); }
.mic-btn:active { transform: scale(0.96); }

.mic-btn.listening {
  background: var(--accent-light);
  box-shadow: 0 0 0 0 var(--accent-glow);
  animation: btnPulse 1.6s ease-out infinite;
}

.mic-btn.processing {
  background: #ca8a04;
  animation: none;
}

.mic-btn.speaking {
  background: #059669;
  animation: speakingPulse 1.2s ease-in-out infinite;
}

.mic-btn.always-on-active {
  background: var(--accent);
}

/* Ripple rings */
.mic-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  pointer-events: none;
}

.mic-btn.listening .ring-1 {
  animation: ringExpand 1.6s ease-out 0s infinite;
}
.mic-btn.listening .ring-2 {
  animation: ringExpand 1.6s ease-out 0.5s infinite;
}

.mic-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
}

/* Live wave indicator */
.live-indicator {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 28px;
  position: relative;
  z-index: 1;
}

.wave-bar {
  width: 3px;
  height: 100%;
  background: rgba(255,255,255,0.9);
  border-radius: 2px;
  transform-origin: center;
  animation: waveDance 1.2s ease-in-out infinite;
}

.wave-bar:nth-child(1) { animation-delay: 0.0s; }
.wave-bar:nth-child(2) { animation-delay: 0.15s; }
.wave-bar:nth-child(3) { animation-delay: 0.3s;  }
.wave-bar:nth-child(4) { animation-delay: 0.15s; }
.wave-bar:nth-child(5) { animation-delay: 0.0s;  }

.mic-label {
  display: none;
}

/* ── Voice / Text toggle ──────────────────────────────────── */
.input-type-row {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 3px;
  gap: 2px;
}

.input-type-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 16px;
  border: none;
  border-radius: var(--radius-full);
  background: none;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.input-type-btn.active {
  background: var(--card);
  color: var(--text-primary);
}

/* ── Text input ───────────────────────────────────────────── */
#voiceControls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: inherit;
  width: 100%;
}

#textControls {
  width: 100%;
}

.text-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.text-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  padding: 13px 20px;
  outline: none;
  transition: border-color var(--transition);
}

.text-input:focus { border-color: var(--border-active); }
.text-input::placeholder { color: var(--text-muted); }

.send-btn {
  width: 50px;
  height: 50px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.send-btn:hover { background: var(--accent-light); }
.send-btn:active { transform: scale(0.93); }

/* ── Toast ────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  pointer-events: none;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 100;
  max-width: calc(100vw - 40px);
  text-align: center;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error { color: var(--error); border-color: rgba(248,113,113,0.3); }

/* ── Animations ───────────────────────────────────────────── */
@keyframes dotPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

@keyframes btnPulse {
  0%   { box-shadow: 0 0 0 0 rgba(99,102,241,0.5); }
  70%  { box-shadow: 0 0 0 18px rgba(99,102,241,0); }
  100% { box-shadow: 0 0 0 0   rgba(99,102,241,0); }
}

@keyframes speakingPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(5,150,105,0.4); }
  50%      { box-shadow: 0 0 0 14px rgba(5,150,105,0); }
}

@keyframes ringExpand {
  0%   { transform: scale(1);   opacity: 0.6; }
  100% { transform: scale(1.9); opacity: 0;   }
}

@keyframes waveDance {
  0%, 100% { transform: scaleY(0.25); opacity: 0.6; }
  50%      { transform: scaleY(1);    opacity: 1;   }
}

@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

/* ── STT provider toggle ──────────────────────────────────── */
.stt-provider-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.stt-provider-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.03em;
  margin-right: 2px;
}

.stt-provider-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--font);
  cursor: pointer;
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  transition: color var(--transition);
  user-select: none;
}

.stt-provider-btn.active {
  color: var(--accent-light);
  font-weight: 600;
}

.stt-provider-btn:not(.active):hover { color: var(--text-secondary); }

.stt-provider-sep {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.4;
  pointer-events: none;
}

/* ── Media Queries ────────────────────────────────────────── */
@media (min-height: 800px) {
  .mic-btn { width: 88px; height: 88px; }
  .bottom-controls { padding-bottom: 36px; gap: 20px; }
}

@media (max-height: 600px) {
  .mic-btn { width: 68px; height: 68px; }
  .bottom-controls { padding-bottom: 16px; gap: 10px; }
  .header { padding: 10px 16px 8px; }
}
