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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  height: 100vh;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  text-align: center;
  padding: 16px;
  border-bottom: 1px solid #1e293b;
}

header h1 {
  font-size: 1.25rem;
  color: #60a5fa;
}

.subtitle {
  font-size: 0.8rem;
  color: #64748b;
  margin-top: 2px;
}

/* Avatar */
#avatar-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0 8px;
  border-bottom: 1px solid #1e293b;
}

#avatar-container {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  overflow: hidden;
  background: #1e293b;
}

#heygen-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

#avatar-state-label {
  font-size: 0.7rem;
  color: #64748b;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Chat */
#chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.message.user {
  align-self: flex-end;
  background: #1d4ed8;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: #1e293b;
  color: #e2e8f0;
  border-bottom-left-radius: 4px;
}

.message .audio-play {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 8px;
  color: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.message .audio-play:hover {
  background: rgba(255, 255, 255, 0.25);
}

.message .audio-play.playing {
  background: #2563eb;
}

/* Controls */
#controls {
  padding: 12px 16px 24px;
  border-top: 1px solid #1e293b;
}

#status-bar {
  text-align: center;
  padding: 8px;
  font-size: 0.8rem;
  color: #94a3b8;
}

#mic-area {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 8px 0;
}

.control-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid #334155;
  background: #1e293b;
  color: #64748b;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.control-btn:hover {
  border-color: #60a5fa;
  color: #60a5fa;
}

.control-btn.active {
  border-color: #f59e0b;
  color: #f59e0b;
}

#session-controls {
  display: flex;
  justify-content: center;
  padding: 4px 0;
}

.session-btn {
  background: none;
  border: none;
  color: #64748b;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 4px 12px;
  border-radius: 4px;
  transition: color 0.2s;
}

.session-btn:hover {
  color: #94a3b8;
}

#mic-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid #334155;
  background: #1e293b;
  color: #94a3b8;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all 0.2s;
}

#mic-btn:hover {
  border-color: #60a5fa;
  color: #60a5fa;
}

#mic-btn.recording {
  border-color: #ef4444;
  color: #ef4444;
  background: #1e293b;
}

#mic-btn.processing {
  border-color: #f59e0b;
  color: #f59e0b;
  opacity: 0.7;
  pointer-events: none;
}

/* Recording indicator */
#recording-indicator {
  position: absolute;
  top: -4px;
  right: -4px;
}

#recording-indicator.hidden {
  display: none;
}

.pulse {
  display: block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ef4444;
  animation: pulse 1s ease-in-out infinite;
}

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

/* Loading dots */
.typing-dots span {
  animation: blink 1.4s infinite both;
  font-size: 1.5rem;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

/* Grammar Corrections */
.message.corrections {
  align-self: flex-start;
  max-width: 90%;
  background: #1a1a2e;
  border: 1px solid #2d3748;
  border-left: 3px solid #f59e0b;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.85rem;
}

.corrections-header {
  font-size: 0.75rem;
  font-weight: 600;
  color: #f59e0b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.corrected-text {
  color: #a3e635;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #2d3748;
  line-height: 1.4;
}

.corrected-text .label {
  color: #64748b;
  font-size: 0.75rem;
}

.correction-item {
  padding: 6px 0;
}

.correction-item + .correction-item {
  border-top: 1px solid #1e293b;
}

.correction-item.severity-major {
  border-left: 2px solid #ef4444;
  padding-left: 8px;
  margin-left: -4px;
}

.correction-error {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.original-word {
  color: #ef4444;
  text-decoration: line-through;
}

.arrow {
  color: #64748b;
  font-size: 0.8rem;
}

.corrected-word {
  color: #34d399;
  font-weight: 500;
}

.error-type {
  font-size: 0.7rem;
  color: #94a3b8;
  background: #1e293b;
  padding: 1px 6px;
  border-radius: 4px;
}

.correction-explanation {
  color: #94a3b8;
  font-size: 0.8rem;
  margin-top: 3px;
  line-height: 1.4;
}

.correction-tamil {
  color: #a78bfa;
  font-size: 0.82rem;
  margin-top: 2px;
  line-height: 1.5;
  font-style: italic;
}

/* Responsive — Tablet (768px+) */
@media (min-width: 768px) {
  #app {
    max-width: 600px;
  }

  header h1 {
    font-size: 1.5rem;
  }

  #avatar-container {
    width: 200px;
    height: 220px;
  }

  .message {
    font-size: 1rem;
    padding: 12px 16px;
  }

  #mic-btn {
    width: 72px;
    height: 72px;
  }

  #mic-btn svg {
    width: 36px;
    height: 36px;
  }

  .control-btn {
    width: 44px;
    height: 44px;
  }
}

/* Responsive — Desktop (1024px+) */
@media (min-width: 1024px) {
  #app {
    max-width: 720px;
    border-left: 1px solid #1e293b;
    border-right: 1px solid #1e293b;
  }

  header {
    padding: 20px;
  }

  #chat-container {
    padding: 20px 24px;
  }

  .message {
    max-width: 75%;
  }

  .message.corrections {
    max-width: 80%;
  }
}
