:root {
  --primary: #6650a4;
  --primary-container: #e8ddff;
  --surface-variant: #e7e0ec;
  --error-container: #ffdad6;
  --on-error-container: #410e0b;
  --text: #1c1b1f;
  --bg: #fffbfe;
  --border: #cac4d0;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.app-title {
  font-size: 1.1rem;
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
}

.podcast-select {
  flex: 0 1 260px;
  min-width: 160px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.banner {
  padding: 10px 16px;
  font-size: 0.9rem;
}

.banner-error {
  background: var(--error-container);
  color: var(--on-error-container);
}

.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message-row {
  display: flex;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.assistant {
  justify-content: flex-start;
}

.bubble {
  max-width: min(560px, 85vw);
  border-radius: 16px;
  padding: 10px 14px;
  background: var(--surface-variant);
}

.message-row.user .bubble {
  background: var(--primary-container);
}

.bubble.error {
  background: var(--error-container);
  color: var(--on-error-container);
}

.bubble-content p {
  margin: 0 0 8px;
}

.bubble-content p:last-child {
  margin-bottom: 0;
}

.bubble-content ul {
  margin: 4px 0;
  padding-left: 20px;
}

.bubble-content a {
  color: var(--primary);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.citations {
  margin-top: 8px;
  font-size: 0.78rem;
  opacity: 0.8;
}

.citations div {
  margin-top: 2px;
}

.bubble-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 6px;
}

.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.question-input {
  flex: 1 1 auto;
  resize: none;
  max-height: 120px;
  padding: 10px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.3;
}

.question-input:focus {
  outline: 2px solid var(--primary);
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--surface-variant);
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: default;
  background: transparent;
}

.icon-btn-primary {
  background: var(--primary);
  color: white;
}

.icon-btn-primary:hover {
  background: var(--primary);
  opacity: 0.9;
}

.icon-btn-small {
  width: 28px;
  height: 28px;
}

.mic-listening,
.speak-btn.speaking {
  background: var(--error-container);
  color: var(--on-error-container);
}

@media (max-width: 480px) {
  .app-title {
    font-size: 1rem;
  }
  .podcast-select {
    flex-basis: 100%;
  }
}
