/* ===== THEME VARIABLES ===== */
:root {
  /* Surface scale (space-separated RGB for Tailwind alpha support) */
  --s-50: 248 250 252;
  --s-100: 241 245 249;
  --s-200: 226 232 240;
  --s-300: 203 213 225;
  --s-400: 148 163 184;
  --s-500: 100 116 139;
  --s-600: 71 85 105;
  --s-700: 51 65 85;
  --s-800: 30 41 59;
  --s-900: 15 23 42;
  --s-950: 2 6 23;

  --body-bg: #0f172a;
  --glass-bg: rgba(15, 23, 42, 0.85);
  --glass-border: rgba(148, 163, 184, 0.1);
  --avatar-bg-start: #1e3a5f;
  --avatar-bg-end: #0f172a;
  --avatar-border: rgba(148, 163, 184, 0.2);
  --avatar-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --status-label-bg: rgba(15, 23, 42, 0.75);
  --status-label-border: rgba(148, 163, 184, 0.1);
  --coach-bg: rgba(30, 41, 59, 0.7);
  --coach-border: rgba(148, 163, 184, 0.1);
  --coach-text: #e2e8f0;
  --feedback-bg: rgba(15, 23, 42, 0.5);
  --feedback-border: rgba(148, 163, 184, 0.08);
  --feedback-divider: rgba(148, 163, 184, 0.06);
  --feedback-text: #cbd5e1;
  --thinking-text: #64748b;
  --thinking-dot: #475569;
  --welcome-text: #94a3b8;
  --welcome-heading: #e2e8f0;
  --scrollbar-thumb: rgba(148, 163, 184, 0.2);
  --toggle-bg: #334155;
  --toggle-thumb: #94a3b8;
  --correction-arrow: #475569;
  --mic-text: #64748b;
  --play-btn-color: #93c5fd;
  --play-btn-hover: #bfdbfe;
  --status-base: #94a3b8;
}

[data-theme="light"] {
  --s-50: 15 23 42;
  --s-100: 30 41 59;
  --s-200: 51 65 85;
  --s-300: 71 85 105;
  --s-400: 100 116 139;
  --s-500: 148 163 184;
  --s-600: 203 213 225;
  --s-700: 226 232 240;
  --s-800: 241 245 249;
  --s-900: 248 250 252;
  --s-950: 255 255 255;

  --body-bg: #f8fafc;
  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(148, 163, 184, 0.25);
  --avatar-bg-start: #dbeafe;
  --avatar-bg-end: #eff6ff;
  --avatar-border: rgba(148, 163, 184, 0.3);
  --avatar-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  --status-label-bg: rgba(255, 255, 255, 0.85);
  --status-label-border: rgba(148, 163, 184, 0.2);
  --coach-bg: rgba(241, 245, 249, 0.85);
  --coach-border: rgba(148, 163, 184, 0.2);
  --coach-text: #334155;
  --feedback-bg: rgba(241, 245, 249, 0.7);
  --feedback-border: rgba(148, 163, 184, 0.15);
  --feedback-divider: rgba(148, 163, 184, 0.1);
  --feedback-text: #475569;
  --thinking-text: #94a3b8;
  --thinking-dot: #cbd5e1;
  --welcome-text: #64748b;
  --welcome-heading: #1e293b;
  --scrollbar-thumb: rgba(100, 116, 139, 0.3);
  --toggle-bg: #cbd5e1;
  --toggle-thumb: #64748b;
  --correction-arrow: #94a3b8;
  --mic-text: #94a3b8;
  --play-btn-color: #2563eb;
  --play-btn-hover: #1d4ed8;
  --status-base: #64748b;
}

/* Theme transition utility — applied temporarily during toggle */
html.theme-transition,
html.theme-transition *,
html.theme-transition *::before,
html.theme-transition *::after {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease !important;
}

/* ===== BASE ===== */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  background: var(--body-bg);
  /* Dynamic viewport height for mobile browsers */
  height: 100dvh;
  height: 100vh; /* fallback */
}

/* iOS safe area support */
@supports (padding: env(safe-area-inset-bottom)) {
  .input-area { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .glass-header { padding-top: env(safe-area-inset-top); }
}

/* ===== GLASS HEADER ===== */
.glass-header {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--glass-border);
}

/* ===== FLOATING AVATAR ===== */
.avatar-float {
  position: fixed;
  bottom: 90px;
  left: 16px;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.avatar-float > * { pointer-events: auto; }

.avatar-circle {
  position: relative;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid var(--avatar-border);
  box-shadow: var(--avatar-shadow);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}
.avatar-circle svg {
  width: 130px;
  height: 130px;
}

/* State borders */
.avatar-circle.state-speaking {
  border-color: #3b82f6;
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.3), var(--avatar-shadow);
}
.avatar-circle.state-listening {
  border-color: #ef4444;
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.3), var(--avatar-shadow);
}
.avatar-circle.state-thinking {
  border-color: #f59e0b;
  box-shadow: 0 0 20px rgba(245, 158, 11, 0.3), var(--avatar-shadow);
}

/* Speaking ring animation */
.avatar-ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(59, 130, 246, 0.6);
  animation: ring-pulse 1.2s ease-in-out infinite;
  pointer-events: none;
}

@keyframes ring-pulse {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50% { transform: scale(1.1); opacity: 0; }
}

/* Listening ring animation */
.avatar-ring-listening {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(239, 68, 68, 0.6);
  animation: ring-pulse-red 1.5s ease-in-out infinite;
  pointer-events: none;
}

@keyframes ring-pulse-red {
  0%, 100% { transform: scale(1); opacity: 0.6; }
  50% { transform: scale(1.08); opacity: 0; }
}

/* Status label below avatar */
.avatar-status-label {
  font-size: 0.7rem;
  font-weight: 500;
  text-align: center;
  letter-spacing: 0.02em;
  background: var(--status-label-bg);
  backdrop-filter: blur(8px);
  padding: 2px 10px;
  border-radius: 10px;
  border: 1px solid var(--status-label-border);
  white-space: nowrap;
}

/* Eye blink */
.avatar-eye {
  transform-origin: center;
  transition: transform 100ms ease;
}
.avatar-eye.blink { transform: scaleY(0.08); }

/* Mouth animation */
#avatar-mouth, #avatar-mouth-fill {
  transition: d 60ms ease, opacity 60ms ease;
}

/* Status text colors */
.status-text { color: var(--status-base); transition: color 0.2s ease; }
.status-speaking { color: #60a5fa; }
.status-listening { color: #f87171; }
.status-thinking { color: #fbbf24; }
.status-processing { color: #fbbf24; }

/* ===== STOP SPEAKING BUTTON ===== */
.btn-stop-speaking {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #f87171;
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 0.75rem;
  min-height: 34px;
}
.btn-stop-speaking:hover {
  background: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
}

/* ===== CHAT MESSAGES ===== */
#chat-messages {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
  -webkit-overflow-scrolling: touch;
  padding-left: 160px; /* reserve space for floating avatar */
}
#chat-messages::-webkit-scrollbar { width: 5px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }

.msg-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.875rem;
  line-height: 1.55;
  animation: msg-appear 0.25s ease-out;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

@keyframes msg-appear {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-user {
  background: #2563eb;
  color: #ffffff;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}

.msg-coach {
  background: var(--coach-bg);
  border: 1px solid var(--coach-border);
  color: var(--coach-text);
  margin-right: auto;
  border-bottom-left-radius: 4px;
}

/* User audio message */
.msg-user-audio {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 85%;
  margin-left: auto;
  animation: msg-appear 0.25s ease-out;
}
.msg-user-audio .audio-text {
  background: #2563eb;
  color: #ffffff;
  padding: 10px 14px;
  border-radius: 16px;
  border-bottom-right-radius: 4px;
  font-size: 0.875rem;
  line-height: 1.55;
}
.msg-user-audio .audio-playback {
  display: flex;
  align-items: center;
  gap: 6px;
  align-self: flex-end;
}
.btn-play-audio {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 12px;
  background: rgba(37, 99, 235, 0.15);
  border: 1px solid rgba(37, 99, 235, 0.3);
  color: var(--play-btn-color);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 32px;
}
.btn-play-audio:hover {
  background: rgba(37, 99, 235, 0.25);
  color: var(--play-btn-hover);
}
.btn-play-audio svg {
  width: 14px;
  height: 14px;
}
.btn-play-audio.btn-audio-playing {
  background: rgba(37, 99, 235, 0.3);
  border-color: rgba(37, 99, 235, 0.5);
  color: var(--play-btn-hover);
}

/* Feedback card */
.feedback-card {
  background: var(--feedback-bg);
  border: 1px solid var(--feedback-border);
  border-radius: 12px;
  padding: 10px 12px;
  margin-top: 4px;
  margin-right: auto;
  max-width: 85%;
  font-size: 0.8125rem;
  animation: msg-appear 0.25s ease-out;
}

.feedback-section { padding: 5px 0; }
.feedback-section + .feedback-section {
  border-top: 1px solid var(--feedback-divider);
}

.feedback-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}
.feedback-label-correction { color: #fbbf24; }
.feedback-label-grammar { color: #a78bfa; }
.feedback-label-pronunciation { color: #38bdf8; }
.feedback-label-praise { color: #34d399; }

.feedback-text { color: var(--feedback-text); line-height: 1.45; }

.correction-diff {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.correction-original { color: #f87171; text-decoration: line-through; opacity: 0.8; }
.correction-arrow { color: var(--correction-arrow); }
.correction-fixed { color: #34d399; font-weight: 500; }

/* Portuguese word detection */
.feedback-label-portuguese { color: #fb923c; }

.portuguese-word-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  padding: 4px 0;
}
.portuguese-word-item + .portuguese-word-item {
  border-top: 1px solid var(--feedback-divider);
}
.pt-word {
  color: #fb923c;
  font-weight: 600;
  font-style: italic;
}
.en-word {
  color: #34d399;
  font-weight: 500;
}
.pt-example {
  width: 100%;
  font-size: 0.75rem;
  color: var(--feedback-text);
  opacity: 0.8;
  font-style: italic;
  padding-left: 4px;
}

/* Pronunciation notes (detailed per-word) */
.pronunciation-note-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 0;
}
.pronunciation-note-item + .pronunciation-note-item {
  border-top: 1px solid var(--feedback-divider);
}
.pron-word {
  color: #38bdf8;
  font-weight: 600;
  font-size: 0.875rem;
}
.pron-issue {
  color: #f87171;
  font-size: 0.75rem;
}
.pron-suggestion {
  color: var(--feedback-text);
  font-size: 0.8125rem;
}

/* Thinking indicator */
.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 16px;
  margin-right: auto;
  max-width: 85%;
}
.thinking-indicator span { font-size: 0.8125rem; color: var(--thinking-text); }
.thinking-dots { display: flex; gap: 3px; }
.thinking-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--thinking-dot);
  animation: dot-bounce 1.4s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.16s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes dot-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ===== MIC INDICATOR ===== */
.mic-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0 6px;
  max-width: 42rem;
  margin: 0 auto;
  color: var(--mic-text);
}

/* ===== INPUT AREA ===== */
.input-area {
  background: linear-gradient(to top, rgb(var(--s-950)) 70%, transparent);
  padding-left: 160px; /* match avatar reserved space */
}

textarea#text-input {
  line-height: 1.5;
  scrollbar-width: none;
  font-size: 16px; /* Prevents iOS zoom on focus */
}
textarea#text-input::-webkit-scrollbar { display: none; }

/* ===== AUDIO TOGGLE ===== */
.toggle-track {
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: var(--toggle-bg);
  transition: background 0.2s ease;
  cursor: pointer;
}
.toggle-track input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  z-index: 1;
}
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--toggle-thumb);
  transition: all 0.2s ease;
  pointer-events: none;
}
.toggle-track:has(input:checked) { background: #2563eb; }
.toggle-track:has(input:checked) .toggle-thumb { left: 18px; background: #fff; }

/* ===== RECORD BUTTON ===== */
.btn-recording {
  background: rgba(239, 68, 68, 0.15) !important;
  border-color: rgba(239, 68, 68, 0.4) !important;
  color: #ef4444 !important;
  animation: recording-pulse 1.5s ease-in-out infinite;
}

@keyframes recording-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.25); }
  50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

/* ===== WELCOME ===== */
.welcome-msg {
  text-align: center;
  padding: 40px 20px 20px;
  animation: msg-appear 0.4s ease-out;
}
.welcome-msg p { font-size: 0.875rem; color: var(--welcome-text); line-height: 1.6; }
.welcome-msg .greeting {
  font-size: 1.05rem;
  color: var(--welcome-heading);
  font-weight: 500;
  margin-bottom: 4px;
}

/* ===== OVERLAY SCREENS (onboarding + ending) ===== */
.overlay-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--body-bg);
  padding: 16px;
  overflow-y: auto;
}

/* --- Onboarding --- */
.onboarding-card {
  width: 100%;
  max-width: 400px;
  text-align: center;
  padding: 40px 32px;
  border-radius: 24px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px);
  animation: overlay-appear 0.4s ease-out;
}

@keyframes overlay-appear {
  from { opacity: 0; transform: scale(0.95) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.onboarding-avatar {
  width: 88px;
  height: 88px;
  margin: 0 auto 16px;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(37, 99, 235, 0.3);
  border: 3px solid rgba(37, 99, 235, 0.4);
}
.onboarding-avatar svg {
  width: 100%;
  height: 100%;
  display: block;
}

.onboarding-title {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--welcome-heading);
  margin-bottom: 4px;
}

.onboarding-subtitle {
  font-size: 0.875rem;
  color: var(--welcome-text);
  margin-bottom: 28px;
}

.onboarding-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.onboarding-input {
  width: 100%;
  padding: 14px 18px;
  border-radius: 16px;
  border: 1px solid var(--glass-border);
  background: var(--feedback-bg);
  color: var(--coach-text);
  font-size: 1rem;
  text-align: center;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.onboarding-input::placeholder { color: var(--thinking-text); }
.onboarding-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.level-selector {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.level-label {
  font-size: 0.8125rem;
  color: var(--welcome-text);
  font-weight: 500;
}

.level-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.level-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 14px 10px;
  border-radius: 14px;
  border: 2px solid var(--glass-border);
  background: transparent;
  color: var(--feedback-text);
  cursor: pointer;
  transition: all 0.2s ease;
}
.level-btn:hover {
  border-color: rgba(59, 130, 246, 0.4);
  background: rgba(59, 130, 246, 0.05);
}
.level-btn.selected {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.12);
  color: var(--welcome-heading);
}

.level-btn-title {
  font-size: 0.9375rem;
  font-weight: 600;
}
.level-btn-desc {
  font-size: 0.7rem;
  opacity: 0.7;
}

.btn-start {
  width: 100%;
  padding: 14px;
  border-radius: 16px;
  border: none;
  background: #2563eb;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-start:hover:not(:disabled) {
  background: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.3);
}
.btn-start:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* --- Session Timer --- */
.session-timer {
  font-size: 0.75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--status-base);
  background: var(--feedback-bg);
  padding: 2px 10px;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  letter-spacing: 0.04em;
  transition: color 0.3s ease, border-color 0.3s ease;
}
.session-timer.timer-warning {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.3);
  animation: timer-blink 1s ease-in-out infinite;
}

@keyframes timer-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* --- Ending Screen --- */
.ending-card {
  width: 100%;
  max-width: 420px;
  text-align: center;
  padding: 36px 28px;
  border-radius: 24px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px);
  animation: overlay-appear 0.4s ease-out;
  max-height: 90vh;
  overflow-y: auto;
}

.ending-title {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--welcome-heading);
  margin-bottom: 20px;
}

.score-display {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.score-circle {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  border: 4px solid #3b82f6;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  animation: score-pop 0.5s ease-out 0.2s both;
}
.score-circle.score-low { border-color: #f87171; }
.score-circle.score-mid { border-color: #fbbf24; }
.score-circle.score-high { border-color: #34d399; }

@keyframes score-pop {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.score-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--welcome-heading);
  line-height: 1;
}
.score-max {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--thinking-text);
  align-self: flex-end;
  margin-bottom: 4px;
}

.level-badge {
  display: inline-block;
  padding: 4px 16px;
  border-radius: 20px;
  font-size: 0.8125rem;
  font-weight: 600;
  background: rgba(59, 130, 246, 0.12);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.25);
  margin-bottom: 20px;
}

.end-section {
  text-align: left;
  margin-bottom: 16px;
}

.end-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.end-strengths-title { color: #34d399; }
.end-improvements-title { color: #fbbf24; }

.end-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.end-list li {
  font-size: 0.8125rem;
  color: var(--feedback-text);
  padding: 6px 10px;
  border-radius: 8px;
  line-height: 1.4;
}
.end-list-strengths li {
  background: rgba(52, 211, 153, 0.08);
  border-left: 3px solid #34d399;
}
.end-list-improvements li {
  background: rgba(251, 191, 36, 0.08);
  border-left: 3px solid #fbbf24;
}

.end-feedback {
  font-size: 0.875rem;
  color: var(--coach-text);
  line-height: 1.5;
  margin-bottom: 8px;
  padding: 12px;
  background: var(--feedback-bg);
  border-radius: 12px;
  border: 1px solid var(--feedback-border);
}

.end-encouragement {
  font-size: 0.8125rem;
  color: var(--welcome-text);
  font-style: italic;
  margin-bottom: 24px;
}

.funifier-mention {
  font-size: 0.6875rem;
  color: var(--thinking-text);
  margin-top: 16px;
}

/* ===== UTILITIES ===== */
.hidden { display: none !important; }

/* ============================================================
   RESPONSIVE — Mobile first adjustments
   ============================================================ */

/* Small phones (< 380px) */
@media (max-width: 379px) {
  .avatar-circle { width: 80px; height: 80px; }
  .avatar-circle svg { width: 80px; height: 80px; }
  .avatar-float { bottom: 80px; left: 8px; gap: 4px; }
  .avatar-status-label { font-size: 0.6rem; padding: 1px 6px; }

  .msg-bubble, .msg-user-audio, .feedback-card { max-width: 90%; }
  .msg-bubble { font-size: 0.8125rem; padding: 8px 12px; }
  .feedback-card { font-size: 0.75rem; padding: 8px 10px; }

  #chat-messages { padding-left: 98px; padding-right: 8px; }
  .input-area { padding-left: 98px; padding-right: 8px; }
}

/* Phones (380px – 639px) */
@media (min-width: 380px) and (max-width: 639px) {
  .avatar-circle { width: 96px; height: 96px; }
  .avatar-circle svg { width: 96px; height: 96px; }
  .avatar-float { bottom: 82px; left: 10px; gap: 4px; }
  .avatar-status-label { font-size: 0.625rem; padding: 2px 8px; }

  .msg-bubble, .msg-user-audio, .feedback-card { max-width: 88%; }

  #chat-messages { padding-left: 118px; }
  .input-area { padding-left: 118px; }
}

/* Tablets (640px – 1023px) */
@media (min-width: 640px) and (max-width: 1023px) {
  .avatar-circle { width: 110px; height: 110px; }
  .avatar-circle svg { width: 110px; height: 110px; }
  .avatar-float { bottom: 88px; left: 14px; }

  #chat-messages { padding-left: 140px; }
  .input-area { padding-left: 140px; }
}

/* Desktop (1024px+) — defaults already set (130px avatar) */

/* ===== Landscape phones — move avatar to not block content ===== */
@media (max-height: 500px) and (orientation: landscape) {
  .avatar-float { bottom: auto; top: 50px; left: 10px; }
  .avatar-circle { width: 72px; height: 72px; }
  .avatar-circle svg { width: 72px; height: 72px; }
  .avatar-status-label { font-size: 0.6rem; }

  .welcome-msg { padding: 16px 16px 8px; }
  .glass-header { padding-top: 4px; padding-bottom: 4px; }
  .input-area { padding-bottom: 8px; padding-top: 4px; padding-left: 92px; }

  #chat-messages { padding-left: 92px; }
}

/* ===== TRANSLATION TOOLTIP ===== */
.translatable {
  cursor: help;
  background: rgba(59, 130, 246, 0.06);
  border-bottom: 1px dashed rgba(59, 130, 246, 0.3);
  padding: 0 1px;
  border-radius: 2px;
  transition: background 0.15s, border-color 0.15s;
}
.translatable:hover {
  background: rgba(59, 130, 246, 0.18);
  border-bottom-color: rgba(59, 130, 246, 0.6);
}
.translation-tooltip {
  position: fixed;
  z-index: 100;
  background: #1e293b;
  color: #f1f5f9;
  border: 1px solid rgba(148, 163, 184, 0.2);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.15s, visibility 0.15s;
}
.translation-tooltip.visible {
  visibility: visible;
  opacity: 1;
}
[data-theme="light"] .translatable {
  background: rgba(59, 130, 246, 0.08);
  border-bottom-color: rgba(37, 99, 235, 0.3);
}
[data-theme="light"] .translatable:hover {
  background: rgba(59, 130, 246, 0.2);
  border-bottom-color: rgba(37, 99, 235, 0.6);
}
[data-theme="light"] .translation-tooltip {
  background: #1e293b;
  color: #f1f5f9;
}

/* ===== Touch-friendly: ensure all interactive elements are >= 44px ===== */
@media (pointer: coarse) {
  #btn-record { min-width: 48px; min-height: 48px; }
  #btn-send { min-width: 36px; min-height: 36px; }
  #btn-reset { min-width: 40px; min-height: 40px; padding: 8px; }
  .btn-stop-speaking { min-height: 40px; padding: 8px 14px; }
  .btn-play-audio { min-height: 36px; padding: 8px 14px; }
  .toggle-track { width: 40px; height: 24px; }
  .toggle-thumb { width: 20px; height: 20px; }
  .toggle-track:has(input:checked) .toggle-thumb { left: 18px; }
}
