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

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --text: #e8e8f0;
  --text-muted: #8888a0;
  --primary: #7c3aed;
  --primary-glow: rgba(124, 58, 237, 0.4);
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.4);
  --success: #22c55e;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100%;
  padding: env(safe-area-inset-top, 20px) 20px env(safe-area-inset-bottom, 20px);
}

header {
  text-align: center;
  padding-top: 12vh;
  margin-bottom: 6vh;
}

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 0.25rem;
}

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  width: 100%;
  max-width: 400px;
}

/* Microphone button */

.mic-btn {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
  box-shadow: 0 0 0 0 var(--primary-glow);
  position: relative;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.mic-btn:active {
  transform: scale(0.95);
}

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

.mic-btn .hidden {
  display: none;
}

/* Listening state */

.mic-btn.listening {
  background: var(--danger);
  box-shadow: 0 0 0 0 var(--danger-glow);
  animation: pulse-ring 1.5s ease-out infinite;
}

.mic-btn.listening .mic-icon {
  display: none;
}

.mic-btn.listening .stop-icon {
  display: block;
}

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 var(--danger-glow); }
  70% { box-shadow: 0 0 0 20px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Waveform */

.waveform {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 60px;
  margin-bottom: 24px;
  transition: opacity 0.3s;
}

.waveform.hidden {
  opacity: 0;
  pointer-events: none;
}

.waveform span {
  width: 4px;
  height: 8px;
  border-radius: 2px;
  background: var(--primary);
  transition: height 0.1s;
}

.waveform.active span {
  animation: wave 0.6s ease-in-out infinite alternate;
}

.waveform.active span:nth-child(1)  { animation-delay: 0s; }
.waveform.active span:nth-child(2)  { animation-delay: 0.05s; }
.waveform.active span:nth-child(3)  { animation-delay: 0.1s; }
.waveform.active span:nth-child(4)  { animation-delay: 0.15s; }
.waveform.active span:nth-child(5)  { animation-delay: 0.2s; }
.waveform.active span:nth-child(6)  { animation-delay: 0.25s; }
.waveform.active span:nth-child(7)  { animation-delay: 0.3s; }
.waveform.active span:nth-child(8)  { animation-delay: 0.35s; }
.waveform.active span:nth-child(9)  { animation-delay: 0.3s; }
.waveform.active span:nth-child(10) { animation-delay: 0.25s; }
.waveform.active span:nth-child(11) { animation-delay: 0.2s; }
.waveform.active span:nth-child(12) { animation-delay: 0.15s; }
.waveform.active span:nth-child(13) { animation-delay: 0.1s; }
.waveform.active span:nth-child(14) { animation-delay: 0.05s; }
.waveform.active span:nth-child(15) { animation-delay: 0s; }

@keyframes wave {
  from { height: 8px; }
  to { height: 48px; }
}

/* Status text */

.status {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 20px;
  text-align: center;
  transition: color 0.3s;
}

.status.listening {
  color: var(--danger);
}

.status.thinking {
  color: var(--primary);
}

.status.speaking {
  color: var(--success);
}

.status.error {
  color: var(--danger);
}

/* Transcript */

.transcript {
  margin-top: 32px;
  width: 100%;
  max-height: 40vh;
  overflow-y: auto;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  text-align: center;
  padding: 0 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--surface) transparent;
}

.transcript:empty {
  display: none;
}

.transcript p {
  padding: 12px 16px;
  background: var(--surface);
  border-radius: 12px;
  margin-bottom: 8px;
  text-align: left;
  animation: fade-in 0.3s ease;
}

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

/* iOS safe areas */
@supports (padding: env(safe-area-inset-bottom)) {
  #app {
    padding-bottom: calc(env(safe-area-inset-bottom) + 20px);
  }
}

/* Landscape adjustment */
@media (max-height: 500px) {
  header {
    padding-top: 4vh;
    margin-bottom: 2vh;
  }
  .mic-btn {
    width: 72px;
    height: 72px;
  }
  .mic-btn svg {
    width: 28px;
    height: 28px;
  }
}
