:root {
  --bg: #0e1116;
  --panel: #161b22;
  --line: #262d38;
  --text: #e6edf3;
  --muted: #8b96a5;
  --accent: #4f8cff;
  --listen: #ef4d5f;
  --think: #f0b429;
  --speak: #2ecc9a;
  --user-bg: #1f3a68;
  --bot-bg: #1b222c;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa; --panel: #ffffff; --line: #dfe4ec; --text: #1a2230; --muted: #5d6878;
    --user-bg: #d8e6ff; --bot-bg: #ffffff;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.app {
  max-width: 760px; height: 100%; margin: 0 auto; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
h1 { margin: 0; font-size: 1.25rem; }
.sub { margin: 0; color: var(--muted); font-size: .875rem; }
.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: .85rem; }
.switch { display: flex; align-items: center; gap: 6px; cursor: pointer; color: var(--muted); }
select, .ghost, .textform input, .textform button {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; font: inherit;
}
select { max-width: 170px; }
.ghost, .textform button { cursor: pointer; }
.ghost:hover, .textform button:hover { border-color: var(--accent); }

.chat {
  flex: 1; overflow-y: auto; padding: 8px 2px; display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth;
}
.msg { max-width: 82%; padding: 10px 14px; border-radius: 16px; border: 1px solid var(--line); white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--user-bg); border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--bot-bg); border-bottom-left-radius: 4px; }
.msg.event { align-self: center; font-size: .8rem; color: var(--speak); background: transparent; border-style: dashed; }
.msg.error { align-self: center; color: var(--listen); background: transparent; border-color: var(--listen); font-size: .875rem; }

.stage { display: flex; flex-direction: column; align-items: center; gap: 10px; padding-bottom: 6px; }
.live { min-height: 1.5em; color: var(--muted); font-style: italic; text-align: center; }
.status { color: var(--muted); font-size: .875rem; }

.orb {
  --c: var(--accent);
  position: relative; width: 96px; height: 96px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--c); color: #fff; display: grid; place-items: center;
  transition: background .25s, transform .15s;
}
.orb:hover { transform: scale(1.04); }
.orb:focus-visible { outline: 3px solid var(--text); outline-offset: 4px; }
.mic { width: 38px; height: 38px; fill: currentColor; position: relative; z-index: 1; }
.ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--c); opacity: 0; }
.orb.listening { --c: var(--listen); }
.orb.thinking  { --c: var(--think); }
.orb.speaking  { --c: var(--speak); }
.orb.listening .ring, .orb.speaking .ring { animation: pulse 1.8s ease-out infinite; }
.orb.listening .r2, .orb.speaking .r2 { animation-delay: .6s; }
.orb.listening .r3, .orb.speaking .r3 { animation-delay: 1.2s; }
.orb.thinking .mic { animation: spin 1.1s linear infinite; }
@keyframes pulse { 0% { transform: scale(1); opacity: .7; } 100% { transform: scale(1.9); opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .orb *, .orb { animation: none !important; } }

.textform { display: flex; gap: 8px; width: 100%; }
.textform input { flex: 1; }
.warn { color: var(--think); font-size: .85rem; margin: 0; text-align: center; }

@media (max-width: 520px) {
  .msg { max-width: 92%; }
  .controls { gap: 8px; }
}

.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.chips button {
  background: transparent; color: var(--text); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 12px; font: inherit; font-size: .8rem; cursor: pointer;
}
.chips button:hover { border-color: var(--accent); color: var(--accent); }

/* Modo burbuja (iframe): más compacto */
.embed .app { padding: 10px; gap: 8px; max-width: none; }
.embed h1 { font-size: 1rem; }
.embed .sub { display: none; }
.embed .controls { gap: 6px; font-size: .78rem; }
.embed select { max-width: 120px; }
.embed .msg { max-width: 92%; }
.embed .controls { flex-wrap: wrap; width: 100%; }
.embed .switch span { white-space: nowrap; }
.embed .top { flex-direction: column; width: 100%; }
.embed select { max-width: 110px; min-width: 0; }
html.embed, .embed body { overflow-x: hidden; }

/* Textos largos (URLs) no deben desbordar ni generar scroll horizontal */
.msg { overflow-wrap: anywhere; word-break: break-word; }
.chat { min-height: 0; overflow-x: hidden; }
.app { overflow: hidden; }
.embed .app { min-height: 0; }
.embed .chat { flex: 1 1 0; min-height: 140px; }
.embed .stage { flex: 0 0 auto; gap: 6px; }
.embed .orb { width: 72px; height: 72px; }
.embed .mic { width: 30px; height: 30px; }
.embed .msg { font-size: .9rem; padding: 8px 12px; }
.embed .chips button { font-size: .75rem; padding: 4px 8px; }
.embed .app:has(.msg.user) .chips { display: none; }   /* tras la primera pregunta, más espacio al chat */
.embed .status { text-align: center; font-size: .78rem; }
.chat { scrollbar-width: thin; scrollbar-color: var(--muted) transparent; }
