:root {
  color-scheme: dark;
  --bg: #111318;
  --panel: #1a1d24;
  --border: #2a2e38;
  --text: #e8e9ec;
  --muted: #8a8f9c;
  --accent: #5b8def;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
}

#update-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: #e0a030;
  color: #1a1200;
  text-align: center;
  padding: 0.6rem;
  font-size: 0.9rem;
}

#update-banner button {
  background: #1a1200;
  color: white;
  margin-left: 0.5rem;
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
}

/* [hidden] alone loses to any ID-selector display rule below it in
   specificity, which is exactly what let the chat screen (mic/logout/mode
   buttons) render underneath the login screen the whole time — this beats
   both #login-screen and #chat-screen's own display rules regardless of
   declaration order. */
#login-screen[hidden], #chat-screen[hidden] {
  display: none;
}

#login-screen {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 320px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem 2rem;
}

.login-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }

.login-sub {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.25rem 0 1.75rem;
}

.login-card button { width: 100%; }

#login-screen h1, header h1 { font-size: 1.4rem; margin: 0; }

button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1rem;
  font-size: 1rem;
  cursor: pointer;
}

button:disabled { opacity: 0.5; cursor: default; }

input, select {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.6rem;
  font-size: 1rem;
}

#verify-form { display: flex; gap: 0.5rem; margin-top: 1rem; }
#code-input { flex: 1; text-align: center; letter-spacing: 0.3em; }

#login-status { color: var(--muted); }

#chat-screen {
  width: 100%;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.controls { display: flex; gap: 0.5rem; align-items: center; }
.controls button, .controls select { padding: 0.4rem 0.6rem; font-size: 0.85rem; }
#mic-toggle.active, #speaker-toggle.active { background: #3ba55d; }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.msg {
  max-width: 75%;
  padding: 0.6rem 0.9rem;
  border-radius: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
}

.msg.user { align-self: flex-end; background: var(--accent); color: white; }
.msg.bot { align-self: flex-start; background: var(--panel); border: 1px solid var(--border); }
.msg.meta { align-self: center; color: var(--muted); font-size: 0.8rem; }

#chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}

#chat-input { flex: 1; }

/* Siri-style bar waveform, three states driven by adding a class:
   listening: bars are driven live by JS from actual mic volume (Web Audio
   AnalyserNode) — no CSS animation here, height is set per-frame in app.js,
   with a short transition to smooth it. thinking/speaking have no real
   signal to react to (waiting on a network reply / browser TTS exposes no
   audio stream), so those stay as decorative CSS keyframe pulses. */
.waveform {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 32px;
  margin: 0.25rem 0 0.5rem;
}

.waveform[hidden] { display: none; }

.waveform .bar {
  width: 4px;
  height: 8px;
  border-radius: 2px;
  background: var(--accent);
  transition: height 0.07s ease-out;
}

.waveform.thinking .bar {
  background: var(--muted);
  animation-name: wave-think;
  animation-duration: 1.4s;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
}

.waveform.thinking .bar:nth-child(1), .waveform.thinking .bar:nth-child(7) { animation-delay: 0s; }
.waveform.thinking .bar:nth-child(2), .waveform.thinking .bar:nth-child(6) { animation-delay: 0.1s; }
.waveform.thinking .bar:nth-child(3), .waveform.thinking .bar:nth-child(5) { animation-delay: 0.2s; }
.waveform.thinking .bar:nth-child(4) { animation-delay: 0.3s; }

@keyframes wave-think {
  0%, 100% { height: 6px; opacity: 0.5; }
  50% { height: 12px; opacity: 0.9; }
}

.waveform.speaking .bar {
  background: #3ba55d;
  animation-name: wave-speak;
  animation-duration: 0.55s;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
}

.waveform.speaking .bar:nth-child(1), .waveform.speaking .bar:nth-child(7) { animation-delay: 0s; }
.waveform.speaking .bar:nth-child(2), .waveform.speaking .bar:nth-child(6) { animation-delay: 0.08s; }
.waveform.speaking .bar:nth-child(3), .waveform.speaking .bar:nth-child(5) { animation-delay: 0.16s; }
.waveform.speaking .bar:nth-child(4) { animation-delay: 0.24s; }

@keyframes wave-speak {
  0%, 100% { height: 6px; }
  50% { height: 30px; }
}

#voice-status {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0 0 0.5rem;
  min-height: 1em;
}
