:root {
  color-scheme: dark;
  --bg: #0a0a0b;
  --bg-panel: rgba(20, 20, 22, 0.92);
  --surface-high: #1c1c1f;
  --border: rgba(255, 255, 255, 0.18);
  --border-strong: rgba(255, 255, 255, 0.28);
  --text: #fafafa;
  --muted: #a1a1a6;
  --accent: #38d39f;
  --accent-2: #45e4ae;
  --danger: #d05f5f;
  --user: #15372d;
  --assistant: #141416;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(56, 211, 159, 0.12), transparent 30%),
    linear-gradient(180deg, #0b0c0d 0%, #0a0a0b 100%);
  color: var(--text);
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
button, input { font: inherit; }
textarea { font: inherit; }
code { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.page { width: min(1100px, calc(100vw - 32px)); margin: 0 auto; }
.hero { padding: 48px 0 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.title { margin: 0; font-size: clamp(2rem, 6vw, 4.25rem); line-height: 0.96; letter-spacing: -0.04em; }
.subtitle { margin: 8px 0 0; color: var(--muted); max-width: 48rem; }
.top-gap { margin-top: 12px; }
.card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 24px; backdrop-filter: blur(18px); box-shadow: 0 24px 80px rgba(0, 0, 0, 0.32); }
.panel { padding: 20px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.toolbar, .mode-row, .composer-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.text-composer { display: flex; flex-direction: column; gap: 12px; margin: 16px 0 14px; }
.chat-grid { display: grid; grid-template-columns: 1fr; gap: 20px; padding-bottom: 32px; }
.messages { min-height: 58vh; max-height: 64vh; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.message { border-radius: 14px; padding: 6px 8px; border: 1px solid var(--border); white-space: pre-wrap; line-height: 1.28; }
.message.user { align-self: flex-end; background: linear-gradient(180deg, rgba(56, 211, 159, 0.22), rgba(56, 211, 159, 0.14)); max-width: 78%; }
.message.assistant { background: linear-gradient(180deg, rgba(28, 28, 31, 0.98), rgba(20, 20, 22, 0.98)); max-width: 84%; }
.message .meta {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  margin-bottom: 2px;
  letter-spacing: 0.02em;
  text-transform: lowercase;
}
.message.pending {
  align-self: flex-start;
  background: linear-gradient(180deg, rgba(28, 28, 31, 0.94), rgba(20, 20, 22, 0.94));
  border-color: rgba(56, 211, 159, 0.18);
}
.message.pending .message-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 18px;
}
.message.pending .typing {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 18px;
}
.pending-stage {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 2px;
}
.message-stage {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.28;
}
.stage-text {
  font: inherit;
  color: inherit;
}
.stage-spinner {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 1.5px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent);
  animation: stageSpin 0.75s linear infinite;
  flex-shrink: 0;
}
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.message.pending .typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(56, 211, 159, 0.9);
  animation: typingPulse 1s infinite ease-in-out;
}
.message.pending .typing-dot:nth-child(2) { animation-delay: 0.15s; }
.message.pending .typing-dot:nth-child(3) { animation-delay: 0.3s; }
.message.error {
  border-color: rgba(208, 95, 95, 0.4);
}
.message.error .message-body {
  color: #ffb7b7;
}
.thinking {
  margin-top: 8px;
  border-left: 3px solid rgba(56, 211, 159, 0.52);
  padding: 6px 8px;
  background: rgba(56, 211, 159, 0.08);
  color: #d5f8ea;
  border-radius: 10px;
  font-size: 0.84rem;
}
.tool {
  margin-top: 8px;
  border-radius: 10px;
  padding: 0;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.92rem;
  overflow: hidden;
}
.tool summary {
  list-style: none;
  cursor: pointer;
  padding: 8px 10px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid transparent;
}
.tool[open] summary {
  border-bottom-color: rgba(255, 255, 255, 0.08);
}
.tool summary::-webkit-details-marker { display: none; }
.tool-body { padding: 8px 10px; }
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); background: rgba(255, 255, 255, 0.03); }
.small { font-size: 0.88rem; }
.mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
.input, .button { width: 100%; border-radius: 14px; border: 1px solid var(--border); padding: 14px 16px; }
.input { background: rgba(12, 12, 14, 0.86); color: var(--text); }
.chat-input {
  min-height: 28px;
  max-height: 160px;
  resize: none;
  border: 0;
  padding: 0;
  background: transparent;
}
.button { background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%); color: #04101a; font-weight: 700; cursor: pointer; }
.button.secondary { background: rgba(255, 255, 255, 0.04); color: var(--text); }
.button:disabled { opacity: 0.55; cursor: wait; }
.audio-player { width: 100%; margin-top: 4px; }
.bubble-audio {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  padding: 6px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.bubble-audio-label {
  font-size: 0.78rem;
  color: var(--text);
}
.bubble-audio button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(56, 211, 159, 0.14);
  color: var(--accent);
  cursor: pointer;
  padding: 0;
}
.bubble-audio button:hover {
  background: rgba(56, 211, 159, 0.22);
}
.bubble-audio svg {
  width: 14px;
  height: 14px;
}
.composer-shell,
.audio-composer {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 10px 12px;
  background: rgba(12, 12, 14, 0.9);
}
.audio-composer { padding-left: 10px; }
.composer-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.icon-button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-button svg { width: 20px; height: 20px; }
.icon-button.secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.icon-button.send {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #04101a;
}
.icon-button.recording {
  background: rgba(208, 95, 95, 0.16);
  color: #ffb3b3;
  border: 1px solid rgba(208, 95, 95, 0.32);
}
.inline-player {
  margin-top: 0;
  flex: 1;
  min-width: 0;
}
.voice-bubble { display: flex; flex-direction: column; gap: 3px; }
.voice-bubble .bubble-audio {
  margin-top: 0;
}
.status { color: var(--muted); min-height: 1.4rem; }
.danger { color: var(--danger); }
.pre { margin-bottom: 0; white-space: pre-wrap; }
@keyframes typingPulse {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
  40% { transform: translateY(-2px); opacity: 1; }
}
@keyframes stageSpin {
  to { transform: rotate(360deg); }
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 8, 14, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.modal {
  width: min(460px, calc(100vw - 32px));
  padding: 24px;
}
.modal-title {
  margin: 14px 0 0;
  font-size: 2rem;
}
.hidden { display: none; }
body.auth-pending {
  overflow: hidden;
}
@media (max-width: 920px) {
  .messages { max-height: none; }
  .message.user, .message.assistant { max-width: 100%; }
  .hero { align-items: flex-start; }
}
