/* ── Dark Theme (Cyberpunk, default) ── */
:root, [data-theme="dark"] {
  --bg-color: #0f1115;
  --panel-bg: #1a1d24;
  --surface: #1a1d24;
  --surface2: #242933;
  --bg-card: #1a1d24;
  --text-primary: #f0f0f0;
  --text-secondary: #9ca3af;
  --text: #f0f0f0;
  --text-muted: #9ca3af;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
  --danger: #ef4444;
  --border-color: #2d3139;
  --border: #2d3139;
  --radius: 16px;
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.3);
  --font-family: 'Inter', sans-serif;
  --cyber-glow: 0 0 20px rgba(59,130,246,0.3);
  --cyber-line: rgba(59,130,246,0.06);
}

/* ── Light Theme (Sunny Meadow) ── */
[data-theme="light"] {
  --bg-color: transparent;
  --panel-bg: rgba(255,255,255,0.82);
  --surface: #ffffff;
  --surface2: #f1f5f9;
  --bg-card: #ffffff;
  --text-primary: #1a2b1a;
  --text-secondary: #4a6741;
  --text: #1a2b1a;
  --text-muted: #4a6741;
  --accent: #2e7d32;
  --accent-hover: #1b5e20;
  --success: #2e7d32;
  --danger: #dc2626;
  --border-color: rgba(76,175,80,0.3);
  --border: rgba(76,175,80,0.3);
  --radius: 16px;
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.08);
  --font-family: 'Inter', sans-serif;
  --cyber-glow: 0 4px 16px rgba(76,175,80,0.2);
  --cyber-line: none;
}


* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  background-color: var(--bg-color);
  color: var(--text-primary);
  min-height: 100vh;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-primary);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  position: relative;
  transition: background 0.4s ease, color 0.3s ease;
}

/* ── Light Theme: Sunny Meadow Background ── */
[data-theme="light"] body {
  background: linear-gradient(160deg, #87ceeb 0%, #a8dea4 40%, #c0e8bc 70%, #e0f2e0 100%);
  background-attachment: fixed;
}
[data-theme="light"] body::before {
  content: '☀️';
  position: fixed;
  top: 24px; right: 48px;
  font-size: 52px;
  filter: drop-shadow(0 4px 16px rgba(255, 200, 0, 0.65));
  pointer-events: none;
  z-index: 0;
  animation: sunPulse 4s ease-in-out infinite;
}
[data-theme="light"] body::after {
  content: '🌿';
  position: fixed;
  bottom: 16px; left: 0;
  font-size: 64px;
  opacity: 0.25;
  pointer-events: none;
  z-index: 0;
}
@keyframes sunPulse {
  0%, 100% { transform: scale(1) rotate(-4deg); }
  50%       { transform: scale(1.07) rotate(4deg); }
}

/* ── Dark Theme: Cyberpunk Scanlines ── */
[data-theme="dark"] body::before {
  content: '';
  position: fixed; inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    var(--cyber-line) 2px,
    var(--cyber-line) 4px
  );
  pointer-events: none;
  z-index: 0;
}

/* ── Icon Buttons (theme toggle & support) ── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: 9px;
  border: 1px solid var(--border-color);
  background: transparent;
  font-size: 17px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text-primary);
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover {
  background: var(--border-color);
  border-color: var(--accent);
  transform: scale(1.08);
}
.icon-btn:active { transform: scale(0.95); }

/* Custom Theme Toggle Button */
.theme-btn {
  position: relative;
  width: 38px;
  min-width: 38px;
  height: 38px;
  min-height: 38px;
  border-radius: 12px;
  background: var(--panel-bg);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  outline: none;
  z-index: 10;
  padding: 0;
  flex-shrink: 0;
  box-sizing: border-box;
}

[data-theme="dark"] .theme-btn::before {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 14px;
  background: linear-gradient(45deg, #ff758c, #ff7eb3, #a1c4fd, #c2e9fb);
  z-index: -2;
  filter: blur(4px);
  opacity: 0.8;
  transition: opacity 0.3s;
  pointer-events: none;
}

[data-theme="dark"] .theme-btn::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 13px;
  background: linear-gradient(45deg, #ff758c, #ff7eb3, #a1c4fd, #c2e9fb);
  z-index: -1;
  pointer-events: none;
}

.theme-btn-content {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: var(--panel-bg);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  z-index: 2;
  pointer-events: none;
}

[data-theme="light"] .theme-btn-content {
  border: 1px solid var(--border-color);
  background: transparent;
}

[data-theme="light"] .theme-btn::before,
[data-theme="light"] .theme-btn::after {
  display: none;
}

.theme-btn svg {
  width: 22px;
  height: 22px;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s ease;
  position: absolute;
  pointer-events: none;
}

[data-theme="dark"] .moon-icon { opacity: 1; transform: scale(1) rotate(0deg); }
[data-theme="dark"] .sun-icon { opacity: 0; transform: scale(0.5) rotate(-90deg); }

[data-theme="light"] .moon-icon { opacity: 0; transform: scale(0.5) rotate(90deg); }
[data-theme="light"] .sun-icon { opacity: 1; transform: scale(1) rotate(0deg); }



.app-container {
  width: 100%;
  max-width: 600px;
  background: var(--panel-bg);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.app-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-header h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.5px;
  flex: 1;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Mode badge */
.mode-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  cursor: default;
  transition: background 0.3s, color 0.3s;
}
.mode-badge.online {
  background: rgba(59,130,246,0.15);
  color: #60a5fa;
  border: 1px solid rgba(59,130,246,0.3);
}
/* Mode toggle button */
.mode-toggle-btn {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.mode-toggle-btn:hover {
  background: var(--border-color);
  color: var(--text-primary);
}

/* Profile link button in header */
.profile-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: rgba(59,130,246,0.1);
  color: #60a5fa;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.profile-btn:hover {
  background: rgba(59,130,246,0.2);
  color: var(--text-primary);
}

.main-content {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.config-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: rgba(255, 255, 255, 0.03);
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

select, input[type="range"] {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-color);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

.slider-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

#speed-value {
  font-weight: 600;
  width: 24px;
  text-align: center;
}

.speed-labels {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.speed-label-desc {
  font-weight: 600;
  color: var(--accent);
  font-size: 12px;
}

/* CEFR Progress */
.progress-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

.level-badge {
  font-weight: 600;
  background: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
}

.level-badge.next {
  background: rgba(16, 185, 129, 0.1);
  color: #10b981;
}

.xp-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.progress-track {
  width: 100%;
  height: 12px;
  background: var(--border-color);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #10b981);
  width: 0%;
  transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Status Indicator */
.status-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-secondary);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #6b7280;
  transition: background 0.3s;
}

.status-dot.active {
  background: var(--success);
  box-shadow: 0 0 10px var(--success);
}

/* 20-min Banner */
.notification-banner {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid var(--success);
  color: var(--success);
  padding: 12px;
  border-radius: 8px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  animation: slideDown 0.5s ease-out;
}

.hidden {
  display: none !important;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Turn Indicator & Turn-Taking Controls */
.turn-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 6px 0 12px;
}

.turn-indicator {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  border-radius: 9999px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.2px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

.turn-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
  transition: transform 0.3s ease;
}

/* AI Speaking State */
.turn-indicator.turn-ai {
  background: rgba(139, 92, 246, 0.15);
  border-color: rgba(139, 92, 246, 0.5);
  color: #c4b5fd;
  box-shadow: 0 0 18px rgba(139, 92, 246, 0.25);
}

.turn-indicator.turn-ai .turn-dot {
  background: #a78bfa;
  animation: pulseDot 1.2s infinite ease-in-out;
}

/* User's Turn / Waiting for Speech */
.turn-indicator.turn-listening {
  background: rgba(16, 185, 129, 0.16);
  border-color: rgba(16, 185, 129, 0.6);
  color: #34d399;
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.3);
  transform: scale(1.02);
}

.turn-indicator.turn-listening .turn-dot {
  background: #10b981;
  animation: bounceDot 0.8s infinite alternate ease-in-out;
}

/* User Actively Speaking */
.turn-indicator.turn-user {
  background: rgba(59, 130, 246, 0.16);
  border-color: rgba(59, 130, 246, 0.6);
  color: #60a5fa;
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.3);
}

.turn-indicator.turn-user .turn-dot {
  background: #3b82f6;
  animation: pulseDot 0.8s infinite ease-in-out;
}

@keyframes pulseDot {
  0% { transform: scale(0.85); opacity: 0.6; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.85); opacity: 0.6; }
}

@keyframes bounceDot {
  0% { transform: scale(0.9); }
  100% { transform: scale(1.35); }
}

/* Controls below turn indicator */
.turn-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

.interrupt-btn {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.35);
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.interrupt-btn:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.25);
  border-color: #ef4444;
  color: #fff;
  transform: translateY(-1px);
}

.interrupt-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.turn-protection-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.turn-protection-toggle input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
  width: 14px;
  height: 14px;
}

/* Talk Button area */
.interaction-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 20px 0;
}

.talk-button {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  outline: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
}

.talk-button:active {
  transform: scale(0.95);
}

.button-surface {
  position: relative;
  z-index: 2;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: white;
  box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
}

.talk-button.state-recording .button-surface {
  background: linear-gradient(135deg, #10b981, #059669); /* Green for recording */
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
}


.call-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.stop-button {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.stop-button:hover {
  background: #ef4444;
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(239, 68, 68, 0.3);
}

.stop-icon {
  width: 14px;
  height: 14px;
}

.button-icon {
  width: 32px;
  height: 32px;
}

.button-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1px;
}

.button-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--accent);
  filter: blur(20px);
  opacity: 0;
  transition: opacity 0.3s;
}

.talk-button.state-recording .button-glow {
  background: #10b981;
  opacity: 0.5;
  animation: pulse 2s infinite alternate;
}


@keyframes pulse {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 0.3; }
  100% { transform: translate(-50%, -50%) scale(1.3); opacity: 0.6; }
}

/* Visualizer (stub) */
.visualizer-container {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  opacity: 0;
  transition: opacity 0.3s;
}

.talk-button.state-active ~ .visualizer-container,
.visualizer-container.active {
  opacity: 1;
}

.wave {
  width: 6px;
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  animation: waveAnim 1s ease-in-out infinite alternate;
}

.wave-2 { animation-delay: 0.2s; }
.wave-3 { animation-delay: 0.4s; }

@keyframes waveAnim {
  0% { transform: scaleY(0.2); }
  100% { transform: scaleY(1); }
}

.lesson-panel { display: flex; flex-direction: column; gap: 12px; background: rgba(255, 255, 255, 0.03); padding: 16px; border-radius: 12px; border: 1px solid var(--border-color); }
.lesson-header { display: flex; justify-content: space-between; align-items: center; }
.lesson-header h3 { font-size: 16px; font-weight: 600; }
.generate-btn { display: flex; align-items: center; gap: 6px; background: var(--accent); color: white; border: none; padding: 6px 12px; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer; transition: background 0.2s; }
.generate-btn:hover { background: var(--accent-hover); }
.generate-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-sparkle { width: 14px; height: 14px; }
.lesson-content { display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.lesson-field { display: flex; flex-direction: column; gap: 2px; }
.field-label { color: var(--text-secondary); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }

/* Interactive Word Chips */
.words-container { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.word-chip { 
  background: rgba(255, 255, 255, 0.05); 
  border: 1px solid rgba(255, 255, 255, 0.1); 
  border-radius: 16px; 
  padding: 4px 10px; 
  font-size: 13px; 
  transition: all 0.3s ease; 
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.word-chip.completed {
  background: rgba(46, 213, 115, 0.15);
  border-color: #2ed573;
  color: #2ed573;
  box-shadow: 0 0 8px rgba(46, 213, 115, 0.3);
}
.word-chip svg { width: 12px; height: 12px; opacity: 0; transform: scale(0); transition: all 0.3s ease; }
.word-chip.completed svg { opacity: 1; transform: scale(1); }
.placeholder-text { color: var(--text-secondary); font-style: italic; }

/* Taboo Badge Styles */
.taboo-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.28);
  border-radius: 8px;
  padding: 8px 12px;
  margin-top: 6px;
}
.taboo-label {
  color: #f87171 !important;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.5px;
}
.taboo-words-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.taboo-chip {
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.taboo-audit-section {
  background: rgba(239, 68, 68, 0.05);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 8px;
  padding: 12px;
}
.taboo-audit-section h3 {
  color: #f87171;
  font-size: 14px;
}
.taboo-audit-tips {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Modal Styles */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.7); display: flex; align-items: center; justify-content: center; z-index: 1000; backdrop-filter: blur(4px); }
.modal-overlay.hidden { display: none; }
.modal-content { background: var(--surface); border: 1px solid var(--border-color); border-radius: 16px; width: 90%; max-width: 500px; max-height: 80vh; overflow-y: auto; padding: 24px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3); }
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.admin-btn {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.admin-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; border-bottom: 1px solid var(--border-color); padding-bottom: 12px; }
.modal-header h2 { font-size: 20px; font-weight: 600; }
.close-btn { background: none; border: none; color: var(--text-secondary); font-size: 24px; cursor: pointer; }
.close-btn:hover { color: var(--text); }

.feedback-loading { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 0; gap: 16px; color: var(--text-secondary); }
.spinner { width: 30px; height: 30px; border: 3px solid rgba(255, 255, 255, 0.1); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.feedback-section { margin-bottom: 20px; }
.feedback-section h3 { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; margin-bottom: 8px; color: var(--text); }
.feedback-section h3 svg { width: 16px; height: 16px; color: #f1c40f; }
.feedback-section p { font-size: 14px; color: var(--text-secondary); line-height: 1.5; }
.feedback-section ul { padding-left: 20px; font-size: 14px; color: var(--text-secondary); line-height: 1.5; }
.feedback-section ul li { margin-bottom: 6px; }
.feedback-section ul li span.err { text-decoration: line-through; color: #e74c3c; margin-right: 6px; }
.feedback-section ul li span.corr { color: #2ecc71; font-weight: 500; }
.mistakes-section h3 { color: #e74c3c; }

/* Turn Indicator */
.turn-indicator {
  text-align: center;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.3px;
  transition: all 0.3s ease;
  animation: fadeInSlide 0.3s ease-out;
}

.turn-indicator.hidden { display: none !important; }

.turn-indicator.turn-ai {
  background: rgba(59, 130, 246, 0.12);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.25);
  animation: fadeInSlide 0.3s ease-out, subtlePulse 2s ease-in-out infinite;
}

.turn-indicator.turn-listening {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
  animation: fadeInSlide 0.3s ease-out, listenPulse 1.2s ease-in-out infinite;
}

.turn-indicator.turn-user {
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.25);
}

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

@keyframes subtlePulse {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 1; }
}

@keyframes listenPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.3); }
  50% { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
}

/* --- PTT Button Styles --- */
.session-actions {
  text-align: center;
}
.ptt-button {
  position: relative;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  border: none;
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}
.ptt-button.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(100%);
}
.ptt-button:not(.disabled):active, .ptt-button.state-recording {
  transform: scale(0.95);
  box-shadow: 0 0 40px rgba(239, 68, 68, 0.6);
  background: rgba(239, 68, 68, 0.1);
}
.ptt-button.state-recording .button-icon {
  color: var(--danger);
}
.ptt-button.state-processing {
  box-shadow: 0 0 30px rgba(234, 179, 8, 0.6);
  background: rgba(234, 179, 8, 0.1);
}
.ptt-button.state-processing .button-icon {
  color: var(--warning);
}
.interrupt-btn {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}
.interrupt-btn:hover {
  background: var(--danger);
  color: white;
}
.interrupt-btn.hidden {
  display: none;
}

/* --- Connect Buttons --- */
.connect-btn-large, .end-btn-large {
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  color: #fff;
}
.connect-btn-large {
  background-color: #22c55e; /* Салатовый (emerald green) */
}
.connect-btn-large:hover {
  background-color: #16a34a;
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(34, 197, 94, 0.3);
}
.end-btn-large {
  background-color: #ef4444; /* Красный */
}
.end-btn-large:hover {
  background-color: #dc2626;
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(239, 68, 68, 0.3);
}

/* ============================================================
   Auto-mic row (always visible, above PTT)
   ============================================================ */
.auto-mic-row {
  display: flex;
  justify-content: center;
  padding: 6px 0 2px;
}

/* ============================================================
   Noise Gate Panel  (Discord/Skype style mic level meter)
   ============================================================ */
.noise-gate-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 12px;
  width: 100%;
  max-width: 440px;
}

.noise-gate-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.noise-gate-toggle-btn:hover,
.noise-gate-toggle-btn.active {
  background: rgba(139, 92, 246, 0.15);
  border-color: rgba(139, 92, 246, 0.4);
  color: #c4b5fd;
}

.noise-gate-panel {
  width: 100%;
  background: rgba(15, 15, 30, 0.85);
  border: 1px solid rgba(139, 92, 246, 0.25);
  border-radius: 12px;
  padding: 14px 16px 12px;
  margin-top: 8px;
  backdrop-filter: blur(12px);
  animation: fadeSlideDown 0.2s ease;
}

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

.noise-gate-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 10px;
}
.noise-gate-header span {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}
.noise-gate-header small {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.noise-gate-meter-wrap {
  position: relative;
  width: 100%;
  background: rgba(255,255,255,0.05);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 10px;
}
.noise-gate-canvas {
  display: block;
  width: 100%;
  height: 28px;
  border-radius: 6px;
}

.noise-gate-slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.noise-gate-label {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}
.noise-gate-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: rgba(255,255,255,0.15);
  outline: none;
  cursor: pointer;
}
.noise-gate-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #8b5cf6;
  cursor: pointer;
  box-shadow: 0 0 6px rgba(139, 92, 246, 0.6);
  transition: transform 0.1s ease;
}
.noise-gate-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}
.noise-gate-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #8b5cf6;
  cursor: pointer;
  border: none;
}

.noise-gate-status {
  text-align: center;
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 6px;
  letter-spacing: 0.3px;
}
/* --- Interrupt Radio Logic --- */
body.interrupt-bottom #turn-controls { display: none !important; }
body.interrupt-top .interrupt-container { display: none !important; }

/* --- Settings Button --- */
.settings-btn { background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2); color: white; padding: 6px 12px; border-radius: 6px; cursor: pointer; transition: 0.2s; font-size: 13px; }
.settings-btn:hover { background: rgba(255,255,255,0.2); }

.radio-group { display: flex; gap: 15px; margin-top: 5px; }
.radio-group label { display: flex; align-items: center; gap: 5px; cursor: pointer; color: var(--text-primary); font-size: 14px; }

/* ── Voice Grid ── */
.voice-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 8px;
}
.voice-card {
  background: rgba(255,255,255,0.04);
  border: 1.5px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 12px 10px;
  cursor: pointer;
  text-align: center;
  transition: all 0.22s;
  user-select: none;
}
.voice-card:hover {
  background: rgba(59,130,246,0.12);
  border-color: rgba(59,130,246,0.4);
  transform: translateY(-1px);
}
.voice-card.selected {
  background: rgba(59,130,246,0.18);
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59,130,246,0.25);
}
.voice-gender {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.voice-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 3px;
}
.voice-desc {
  font-size: 11px;
  color: var(--text-secondary);
}
.voice-card.selected .voice-name { color: #60a5fa; }

/* =========================================
   Auth Modal 
   ========================================= */
.auth-modal {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.3s ease;
}
.auth-modal.hidden {
  opacity: 0;
  pointer-events: none;
}
.auth-modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 16px 32px rgba(0,0,0,0.4);
  transform: scale(1);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.auth-modal.hidden .auth-modal-content {
  transform: scale(0.95);
}
.auth-header {
  text-align: center;
  margin-bottom: 24px;
}
.auth-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}
.auth-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
}
.auth-error {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  padding: 12px;
  border-radius: 8px;
  border: 1px solid rgba(239, 68, 68, 0.3);
  font-size: 0.9rem;
  margin-bottom: 16px;
  text-align: center;
}
.auth-form .form-group {
  margin-bottom: 16px;
}
.auth-form label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.auth-form input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.2s;
}
.auth-form input:focus {
  outline: none;
  border-color: var(--accent);
}
.auth-submit-btn {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  margin-top: 8px;
}
.auth-separator {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 24px 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.auth-separator::before, .auth-separator::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border);
}
.auth-separator span {
  padding: 0 10px;
}
.oauth-buttons {
  display: flex;
  gap: 12px;
}
.oauth-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.2s;
}
.oauth-btn:hover {
  background: rgba(255,255,255,0.05);
}
.auth-footer {
  text-align: center;
  margin-top: 24px;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.auth-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
.auth-footer a:hover {
  text-decoration: underline;
}



/* ═══════════════════════════════════════════════════════════════
   Mobile & Tablet Responsive Styles
   Supports: iOS Safari 16+, Android Chrome, small tablets (≤ 768px)
   ═══════════════════════════════════════════════════════════════ */

/* Fix iOS Safari 100vh bug — use dvh (dynamic viewport height) where supported */
@supports (height: 100dvh) {
  html, body {
    min-height: 100dvh;
  }
  body {
    min-height: 100dvh;
  }
}

@media (max-width: 768px) {
  /* Full-screen layout on mobile — no centering padding */
  body {
    align-items: flex-start;
    padding: 0;
  }

  .app-container {
    max-width: 100%;
    width: 100%;
    min-height: 100dvh;
    min-height: 100vh; /* fallback */
    border-radius: 0;
    border-left: none;
    border-right: none;
    padding-bottom: env(safe-area-inset-bottom, 16px); /* iPhone notch/home bar */
  }

  /* Header: stack to single line, prevent overflow */
  .app-header {
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .app-header h1 {
    font-size: 1.1rem;
  }
  .header-controls {
    gap: 6px;
  }

  /* Larger touch targets for icon buttons (min 44×44px per Apple HIG) */
  .icon-btn,
  .settings-btn,
  .profile-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 12px;
    font-size: 0.85rem;
  }

  /* Main content: tighter padding on small screens */
  .main-content {
    padding: 10px 12px;
    gap: 10px;
  }

  /* Lesson panel: more compact */
  .lesson-panel {
    padding: 12px;
  }

  /* Connect / End buttons — large touch targets */
  .connect-btn-large,
  .end-btn-large,
  .exam-btn-large {
    min-height: 56px;
    font-size: 1rem;
    padding: 14px 20px;
    border-radius: 14px;
    width: 100%;
  }

  /* Pause / Mute buttons */
  .pause-btn, .mute-btn {
    min-height: 48px;
    min-width: 48px;
    font-size: 1.1rem;
  }

  /* Voice selector — full width dropdown */
  .voice-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .voice-btn {
    min-height: 44px;
    font-size: 0.82rem;
  }

  /* Speed slider — wider for touch */
  .speed-slider-wrap {
    flex-direction: column;
    gap: 6px;
  }
  input[type="range"] {
    width: 100%;
    height: 28px; /* larger touch area */
  }

  /* Transcript / visualizer */
  .visualizer-container {
    height: 56px;
  }
  #transcript-display {
    font-size: 0.82rem;
    max-height: 90px;
  }

  /* Modals: full-width on mobile */
  .modal-content {
    width: 95vw;
    max-width: 95vw;
    margin: 12px auto;
    padding: 16px;
    max-height: 88dvh;
    max-height: 88vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Feedback modal panels */
  .feedback-panel, .exam-panel {
    padding: 10px;
    font-size: 0.88rem;
  }

  /* Noise gate panel */
  .noise-gate-panel {
    padding: 10px;
  }
  #noise-gate-canvas {
    height: 48px;
  }

  /* Settings panel */
  .settings-panel {
    padding: 12px;
  }

  /* Profile link in header — icon only on very small screens */
  @media (max-width: 380px) {
    .profile-btn span {
      display: none;
    }
    .app-header h1 {
      font-size: 0.95rem;
    }
  }
}

/* Tablet breakpoint: wider panel, still touch-friendly */
@media (min-width: 769px) and (max-width: 1024px) {
  .app-container {
    max-width: 680px;
  }
  .connect-btn-large,
  .end-btn-large,
  .exam-btn-large {
    min-height: 52px;
    font-size: 1rem;
  }
}

/* ── Onboarding Modal ──────────────────────────────────────────────────────── */
.onboarding-levels-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.onboarding-level-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  padding: 10px 12px;
  background: var(--surface-alt, rgba(255, 255, 255, 0.04));
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
  border-radius: 10px;
  color: var(--text, #e2e8f0);
  cursor: pointer;
  transition: all 0.15s ease;
}
.onboarding-level-btn strong {
  font-size: 0.85rem;
  margin-bottom: 2px;
}
.onboarding-level-btn span {
  font-size: 0.72rem;
  color: var(--text-muted, #94a3b8);
}
.onboarding-level-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}
.onboarding-level-btn.active {
  background: rgba(79, 70, 229, 0.15);
  border-color: #6366f1;
  color: #fff;
}
.onboarding-level-btn.active span {
  color: #c7d2fe;
}
.onboarding-topics-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
  padding: 2px;
}
.topic-chip {
  padding: 7px 12px;
  font-size: 0.8rem;
  background: var(--surface-alt, rgba(255, 255, 255, 0.04));
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
  border-radius: 20px;
  color: var(--text, #cbd5e1);
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
}
.topic-chip:hover {
  background: rgba(255, 255, 255, 0.08);
}
.topic-chip.active {
  background: rgba(16, 185, 129, 0.15);
  border-color: #10b981;
  color: #6ee7b7;
  font-weight: 500;
}
@media (max-width: 480px) {
  .onboarding-levels-grid {
    grid-template-columns: 1fr;
  }
}

.https-warning-banner {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fbbf24;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.84rem;
  line-height: 1.45;
  text-align: center;
}
[data-theme="light"] .https-warning-banner {
  background: rgba(245, 158, 11, 0.14);
  color: #92400e;
  border-color: rgba(217, 119, 6, 0.4);
}

