:root {
  --primary: #6C3CE1;
  --primary-light: #8B5CF6;
  --primary-dark: #5228CC;
  --bg: #0F0F14;
  --bg-card: #1A1A24;
  --bg-input: #22222E;
  --bg-message-user: #6C3CE1;
  --bg-message-coach: #1E1E2A;
  --text: #F0F0F5;
  --text-muted: #8888A0;
  --border: #2A2A3A;
  --success: #34D399;
  --danger: #EF4444;
  --radius: 14px;
  --radius-sm: 10px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
}

/* ===== LANDING ===== */
.landing {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.landing-content {
  max-width: 680px;
  width: 100%;
}

.logo {
  text-align: center;
  margin-bottom: 32px;
}

.logo-icon {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 800;
  color: white;
  margin-bottom: 16px;
  box-shadow: 0 8px 32px rgba(108, 60, 225, 0.3);
}

.logo h1 {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -1px;
  background: linear-gradient(135deg, #fff, #c4b5fd);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  color: var(--text-muted);
  font-size: 16px;
  margin-top: 8px;
}

/* Interface toggle */
.interface-toggle {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-bottom: 32px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  max-width: 240px;
  margin-left: auto;
  margin-right: auto;
}

.toggle-btn {
  flex: 1;
  padding: 10px 20px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(108, 60, 225, 0.3);
}

.toggle-btn:hover:not(.active) {
  color: var(--text);
}

.mode-section h2 {
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* Free input on landing */
.free-input-area {
  margin-bottom: 20px;
}

.free-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 6px 6px 16px;
  transition: border-color 0.15s;
}

.free-input-wrapper:focus-within {
  border-color: var(--primary);
}

.free-input-wrapper textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  resize: none;
  outline: none;
  max-height: 120px;
  padding: 8px 0;
  line-height: 1.4;
}

.free-input-wrapper textarea::placeholder {
  color: var(--text-muted);
}

/* Free voice button on landing */
.free-voice-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px 24px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border: none;
  border-radius: var(--radius);
  color: white;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 20px rgba(108, 60, 225, 0.3);
}

.free-voice-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(108, 60, 225, 0.4);
}

.free-voice-btn:active {
  transform: translateY(0);
}

.or-divider {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
  opacity: 0.6;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.mode-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  text-align: left;
  color: var(--text);
  font-family: inherit;
}

.mode-card:hover {
  border-color: var(--primary);
  background: #1E1E30;
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(108, 60, 225, 0.15);
}

.mode-emoji {
  font-size: 28px;
  line-height: 1;
}

.mode-title {
  font-size: 15px;
  font-weight: 700;
}

.mode-desc {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ===== SHARED HEADER ===== */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.back-btn,
.reset-btn,
.header-action-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  font-family: inherit;
  flex-shrink: 0;
}

.back-btn:hover,
.reset-btn:hover,
.header-action-btn:hover {
  background: var(--bg-input);
  color: var(--text);
}

.reset-btn {
  margin-left: 0;
}

.header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.coach-avatar {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 800;
  color: white;
  flex-shrink: 0;
}

.header-info h2 {
  font-size: 15px;
  font-weight: 700;
}

.mode-label {
  font-size: 11.5px;
  color: var(--primary-light);
  font-weight: 500;
}

.voice-label {
  color: var(--success);
}

/* ===== CHAT (text) ===== */
.chat-container {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.55;
  font-size: 14px;
  animation: msgIn 0.25s ease;
  white-space: pre-wrap;
  word-break: break-word;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.coach {
  align-self: flex-start;
  background: var(--bg-message-coach);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message.user {
  align-self: flex-end;
  background: var(--bg-message-user);
  border-bottom-right-radius: 4px;
}

.message.coach strong,
.message.coach b {
  color: var(--primary-light);
}

.typing-indicator {
  align-self: flex-start;
  padding: 12px 20px;
  background: var(--bg-message-coach);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 5px;
  animation: msgIn 0.2s ease;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* Input */
.chat-input-area {
  padding: 12px 20px 16px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 6px 6px 16px;
  transition: border-color 0.15s;
}

.input-wrapper:focus-within {
  border-color: var(--primary);
}

textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  resize: none;
  outline: none;
  max-height: 120px;
  padding: 8px 0;
  line-height: 1.4;
}

textarea::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--primary-dark);
}

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

.disclaimer {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
  opacity: 0.6;
}

/* ===== LOGIN OVERLAY ===== */
.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.login-box {
  text-align: center;
  width: 90%;
  max-width: 340px;
}

.login-box h2 {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 6px;
}

.login-box > p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-form input[type="password"] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}

.login-form input[type="password"]:focus {
  border-color: var(--primary);
}

.login-submit {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}

.login-submit:hover {
  background: var(--primary-dark);
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
}

/* ===== VOICE INTERFACE ===== */
.voice-container {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.voice-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 20px;
  overflow: hidden;
}

/* Orb */
.voice-orb-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.voice-orb {
  width: 160px;
  height: 160px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.orb-core {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 800;
  color: white;
  z-index: 2;
  transition: all 0.3s;
}

.orb-ring {
  position: absolute;
  border-radius: 50%;
  border: 2px solid var(--primary);
  opacity: 0;
  transition: all 0.3s;
}

.ring-1 { width: 100px; height: 100px; }
.ring-2 { width: 125px; height: 125px; }
.ring-3 { width: 155px; height: 155px; }

/* Orb states */
.voice-orb.idle .orb-core {
  box-shadow: 0 0 30px rgba(108, 60, 225, 0.2);
}

.voice-orb.connected .orb-core {
  box-shadow: 0 0 40px rgba(108, 60, 225, 0.3);
}

.voice-orb.connected .ring-1 {
  opacity: 0.3;
  animation: pulse 2s ease-in-out infinite;
}

.voice-orb.listening .orb-core {
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  box-shadow: 0 0 50px rgba(108, 60, 225, 0.4);
}

.voice-orb.listening .ring-1 {
  opacity: 0.5;
  border-color: var(--primary-light);
  animation: pulse 1.5s ease-in-out infinite;
}

.voice-orb.listening .ring-2 {
  opacity: 0.3;
  border-color: var(--primary-light);
  animation: pulse 1.5s ease-in-out infinite 0.3s;
}

.voice-orb.speaking .orb-core {
  background: linear-gradient(135deg, #34D399, #6ee7b7);
  box-shadow: 0 0 60px rgba(52, 211, 153, 0.4);
}

.voice-orb.speaking .ring-1 {
  opacity: 0.6;
  border-color: var(--success);
  animation: pulse 0.8s ease-in-out infinite;
}

.voice-orb.speaking .ring-2 {
  opacity: 0.4;
  border-color: var(--success);
  animation: pulse 0.8s ease-in-out infinite 0.15s;
}

.voice-orb.speaking .ring-3 {
  opacity: 0.2;
  border-color: var(--success);
  animation: pulse 0.8s ease-in-out infinite 0.3s;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.2; }
  50% { transform: scale(1.08); opacity: 0.5; }
}

.voice-status {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
  text-align: center;
  min-height: 20px;
}

/* Transcript */
.voice-transcript {
  width: 100%;
  max-width: 600px;
  max-height: 200px;
  overflow-y: auto;
  padding: 0 16px;
}

.transcript-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.transcript-msg {
  font-size: 13px;
  line-height: 1.5;
  padding: 8px 12px;
  border-radius: 10px;
  animation: msgIn 0.2s ease;
  max-width: 90%;
}

.transcript-msg.user {
  align-self: flex-end;
  background: rgba(108, 60, 225, 0.2);
  color: #c4b5fd;
  border: 1px solid rgba(108, 60, 225, 0.3);
}

.transcript-msg.coach {
  align-self: flex-start;
  background: rgba(52, 211, 153, 0.1);
  color: #a7f3d0;
  border: 1px solid rgba(52, 211, 153, 0.2);
}

.transcript-msg.partial {
  opacity: 0.5;
  font-style: italic;
}

/* Voice controls */
.voice-controls {
  padding: 16px 20px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.voice-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 32px;
  border: none;
  border-radius: 50px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  color: white;
}

.voice-btn.connect {
  background: var(--primary);
  box-shadow: 0 4px 20px rgba(108, 60, 225, 0.3);
}

.voice-btn.connect:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(108, 60, 225, 0.4);
}

.voice-btn.disconnect {
  background: var(--danger);
  box-shadow: 0 4px 20px rgba(239, 68, 68, 0.3);
}

.voice-btn.disconnect:hover {
  background: #DC2626;
}

.voice-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ===== Debug Overlay ===== */
.debug-overlay {
  position: absolute;
  top: 60px;
  right: 12px;
  z-index: 100;
  animation: debugIn 0.15s ease;
}

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

.debug-panel {
  width: 360px;
  padding: 14px 16px;
  background: rgba(20, 20, 30, 0.96);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.debug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.debug-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.debug-close {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.15s;
}

.debug-close:hover {
  background: var(--bg-input);
  color: var(--text);
}

.debug-log-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.debug-log {
  height: 80px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 10px;
  line-height: 1.5;
  color: var(--text-muted);
}

.debug-log::-webkit-scrollbar { width: 4px; }
.debug-log::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* VU meter */
.vu-meter-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.vu-label,
.vad-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  width: 80px;
  flex-shrink: 0;
}

.vu-meter {
  flex: 1;
  height: 18px;
  background: var(--bg-input);
  border-radius: 9px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border);
}

.vu-meter-bar {
  height: 100%;
  width: 0%;
  border-radius: 9px;
  background: linear-gradient(90deg, #34D399 0%, #FBBF24 60%, #EF4444 90%);
  transition: width 0.08s linear;
}

.vu-threshold-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: white;
  opacity: 0.9;
  left: 50%;
  transition: left 0.15s;
  box-shadow: 0 0 4px rgba(255,255,255,0.5);
}

.vu-value,
.vad-value {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  width: 36px;
  text-align: right;
  flex-shrink: 0;
}

/* Sliders */
.vad-slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.vad-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  outline: none;
  border: 1px solid var(--border);
}

.vad-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid var(--primary-light);
  box-shadow: 0 2px 6px rgba(108, 60, 225, 0.3);
}

.vad-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid var(--primary-light);
  box-shadow: 0 2px 6px rgba(108, 60, 225, 0.3);
}

.hidden {
  display: none !important;
}

/* Markdown-like formatting in messages */
.message h3 {
  margin: 4px 0;
  font-size: 14px;
}

.message ul, .message ol {
  padding-left: 18px;
  margin: 4px 0;
}

.message li {
  margin: 2px 0;
}

.message code {
  background: rgba(255,255,255,0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
}

/* Scrollbar */
.messages::-webkit-scrollbar,
.voice-transcript::-webkit-scrollbar {
  width: 6px;
}
.messages::-webkit-scrollbar-track,
.voice-transcript::-webkit-scrollbar-track {
  background: transparent;
}
.messages::-webkit-scrollbar-thumb,
.voice-transcript::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* Mobile */
@media (max-width: 600px) {
  .landing {
    padding: 16px;
    align-items: flex-start;
    padding-top: 40px;
  }

  .logo h1 {
    font-size: 32px;
  }

  .mode-grid {
    grid-template-columns: 1fr;
  }

  .message {
    max-width: 90%;
  }

  .chat-header {
    padding: 10px 14px;
  }

  .messages {
    padding: 14px;
  }

  .chat-input-area {
    padding: 10px 14px 14px;
  }

  .voice-orb {
    width: 140px;
    height: 140px;
  }

  .orb-core {
    width: 70px;
    height: 70px;
    font-size: 24px;
  }

  .ring-1 { width: 90px; height: 90px; }
  .ring-2 { width: 112px; height: 112px; }
  .ring-3 { width: 136px; height: 136px; }

  .debug-overlay {
    right: 8px;
    left: 8px;
  }

  .debug-panel {
    width: 100%;
  }
}
