:root {
  --bg: #0b1220;
  --card: #141c2e;
  --text: #e8eefc;
  --muted: #9aa8c7;
  --accent: #5b8cff;
  --accent2: #3dd6c6;
  --danger: #ff6b8a;
  --bubble-user: #243356;
  --bubble-ai: #1a2338;
  --radius: 14px;
  font-family: "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(1200px 600px at 10% -10%, #1a2a4a, var(--bg));
  color: var(--text);
}
#app { max-width: 720px; margin: 0 auto; padding: 16px 16px 32px; }
.view.hidden, .hidden { display: none !important; }
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.top h1, .top h2 { margin: 0; font-size: 1.25rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.card {
  background: var(--card);
  border: 1px solid #243049;
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.gate { margin-top: 12vh; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; }
.field input, .field select, textarea {
  background: #0e1628;
  border: 1px solid #2a3a5c;
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
}
.btn {
  border: 1px solid #334766;
  background: #1a2740;
  color: var(--text);
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #7a5cff);
  border: none;
  font-weight: 600;
}
.btn.ghost { background: transparent; }
.error { color: var(--danger); margin: 0; }
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 560px) {
  .mode-grid { grid-template-columns: 1fr; }
}
.mode-card {
  text-align: left;
  background: var(--card);
  border: 1px solid #2a3a5c;
  border-radius: var(--radius);
  padding: 20px;
  color: inherit;
  cursor: pointer;
}
.mode-card:hover { border-color: var(--accent); }
.mode-title { display: block; font-size: 1.2rem; font-weight: 700; margin-bottom: 6px; }
.mode-desc { color: var(--muted); font-size: 0.9rem; }
.bubbles {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 40vh;
  max-height: calc(100dvh - 200px);
  overflow-y: auto;
  padding: 8px 0 16px;
}
.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble.user {
  align-self: flex-end;
  background: var(--bubble-user);
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--bubble-ai);
  border: 1px solid #2a3a5c;
}
.bubble.system {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
}
.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  position: sticky;
  bottom: 0;
  padding-top: 8px;
  background: linear-gradient(transparent, var(--bg) 30%);
}
.composer textarea { resize: vertical; min-height: 48px; }
.sep { border: none; border-top: 1px solid #2a3a5c; margin: 8px 0; width: 100%; }
.chat-meta { text-align: right; }
.chat-meta strong { display: block; }

/* Spoken voice chrome */
.spoken-composer {
  position: sticky;
  bottom: 0;
  padding: 12px 0 8px;
  background: linear-gradient(transparent, var(--bg) 24%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.spoken-status {
  margin: 0;
  font-size: 0.9rem;
  text-align: center;
}
.spoken-interim {
  margin: 0;
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 10px;
  background: #0e1628;
  border: 1px dashed #3a4f78;
  color: var(--muted);
  font-size: 0.95rem;
  text-align: center;
}
.spoken-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.mic-btn {
  min-width: 140px;
  padding: 14px 22px;
  font-weight: 600;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.mic-btn.listening {
  box-shadow: 0 0 0 3px rgba(61, 214, 198, 0.45);
  animation: mic-pulse 1.2s ease-in-out infinite;
}
.mic-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: none;
}
@keyframes mic-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}
.spoken-fallback {
  width: 100%;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}
.spoken-fallback summary {
  cursor: pointer;
  margin-bottom: 8px;
}
.spoken-text-form {
  width: 100%;
  position: static;
  background: none;
  padding-top: 0;
}
