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

:root {
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #0f3460;
  --accent: #e94560;
  --accent-glow: rgba(233, 69, 96, 0.4);
  --green: #00c853;
  --blue: #448aff;
  --yellow: #ffd600;
  --text: #eaeaea;
  --text-dim: #8892a4;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 20px;
}

.container {
  max-width: 480px;
  width: 100%;
}

/* === Header === */
header {
  text-align: center;
  padding: 24px 0 16px;
}
header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.subtitle {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-top: 4px;
}

/* === Status === */
.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 20px;
  background: var(--bg-card);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}
.status.idle .status-dot { background: var(--text-dim); }
.status.listening .status-dot { background: var(--accent); animation: pulse 1s infinite; }
.status.processing .status-dot { background: var(--yellow); animation: pulse 0.5s infinite; }
.status.speaking .status-dot { background: var(--green); animation: pulse 0.8s infinite; }

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

/* === Visualizer === */
.visualizer-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
#visualizer {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 400px;
  height: 80px;
}

/* === Record Button === */
.record-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.record-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.record-btn:hover {
  background: rgba(233, 69, 96, 0.15);
}
.record-btn.recording {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 8px var(--accent-glow);
  animation: recording-pulse 1.5s infinite;
}
.mic-icon {
  width: 36px;
  height: 36px;
}

@keyframes recording-pulse {
  0%, 100% { box-shadow: 0 0 0 6px var(--accent-glow); }
  50% { box-shadow: 0 0 0 14px rgba(233, 69, 96, 0.15); }
}

/* === Toggle === */
.record-controls { display: flex; gap: 12px; }
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-dim);
}
.toggle input { display: none; }
.toggle-slider {
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: #333;
  position: relative;
  transition: background 0.2s;
}
.toggle-slider::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #888;
  top: 2px;
  left: 2px;
  transition: all 0.2s;
}
.toggle input:checked + .toggle-slider {
  background: var(--accent);
}
.toggle input:checked + .toggle-slider::after {
  left: 18px;
  background: #fff;
}

/* === Result Box === */
.result-section, .tts-section {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.result-section h2, .tts-section h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.result-box {
  background: var(--bg-input);
  border-radius: 8px;
  padding: 14px;
  min-height: 48px;
  font-size: 1rem;
  line-height: 1.5;
  word-break: break-all;
}
.result-box .placeholder {
  color: var(--text-dim);
  font-style: italic;
}

/* === TTS === */
.tts-input-wrap textarea {
  width: 100%;
  background: var(--bg-input);
  border: none;
  border-radius: 8px;
  color: var(--text);
  padding: 12px;
  font-size: 0.95rem;
  resize: vertical;
  font-family: inherit;
  outline: none;
}
.tts-input-wrap textarea:focus {
  box-shadow: 0 0 0 2px var(--blue);
}
.tts-controls {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}
.tts-controls select {
  flex: 1;
  background: var(--bg-input);
  border: none;
  border-radius: 8px;
  color: var(--text);
  padding: 10px;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}
.tts-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}
.tts-btn:hover { background: #5c9cff; }
.tts-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.tts-btn svg { width: 18px; height: 18px; }

/* === Error Toast === */
.error-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #c62828;
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.85rem;
  max-width: 90%;
  text-align: center;
  z-index: 100;
  transition: opacity 0.3s;
}
.error-toast.hidden { opacity: 0; pointer-events: none; }

/* === Responsive === */
@media (max-width: 480px) {
  body { padding: 12px; }
  header h1 { font-size: 1.3rem; }
  .record-btn { width: 70px; height: 70px; }
  .mic-icon { width: 30px; height: 30px; }
}
