:root {
  --primary: hsl(263 70% 58%);
  --surface: #120c16;
  --panel: #1b1222;
  --paper: #f5ecdc;
  --muted: #b9a9cf;
  color-scheme: dark;
  font-family: "Geist", "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at 50% 20%, hsl(263 50% 22%), var(--surface) 70%);
  color: var(--paper);
}

.stage { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; padding: 24px; }
@media (max-width: 480px) { .stage { padding: 12px; } }

.widget {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid hsl(263 40% 30% / 0.6);
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 30px 80px -20px hsl(263 70% 10% / 0.9);
}

.widget-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid hsl(263 30% 25% / 0.6);
}
.widget-head strong { font-size: 17px; margin-right: 8px; }
.ai-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: hsl(263 70% 58% / 0.2); color: var(--muted);
}
.head-actions { display: flex; align-items: center; gap: 10px; }
.mode { font-size: 11px; color: var(--muted); }
.icon-btn {
  position: relative;
  display: grid; place-items: center;
  width: 38px; height: 38px; padding: 0;
  background: hsl(263 30% 14%); color: var(--paper);
  border: 1px solid hsl(263 70% 62% / 0.75); border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s, transform 0.1s;
}
.icon-btn .icon { width: 19px; height: 19px; }
.icon-btn .icon-on { display: none; }
.icon-btn[aria-pressed="true"] .icon-on { display: block; }
.icon-btn[aria-pressed="true"] .icon-off { display: none; }
.icon-btn:active { transform: scale(0.94); }
.icon-btn:focus-visible { outline: 2px solid var(--paper); outline-offset: 2px; }

/* Glowing outline so the controls read as tappable at a glance. */
.icon-btn.glow { box-shadow: 0 0 0 1px hsl(263 70% 62% / 0.35), 0 0 12px 1px hsl(263 80% 62% / 0.45); }
.icon-btn.glow:hover { border-color: hsl(263 85% 72%); box-shadow: 0 0 0 1px hsl(263 85% 72% / 0.5), 0 0 18px 3px hsl(263 85% 65% / 0.6); }
.icon-btn[aria-pressed="true"] { background: var(--primary); border-color: hsl(263 90% 78%); }
.icon-btn[aria-pressed="true"].glow { box-shadow: 0 0 0 1px hsl(263 90% 78% / 0.6), 0 0 20px 4px hsl(263 90% 65% / 0.7); }
/* The mic breathes until voice mode is on: the one control we most want visitors to find. */
#voice.glow:not([aria-pressed="true"]):not(:disabled) { animation: invite 2.6s ease-in-out infinite; }
@keyframes invite {
  0%, 100% { box-shadow: 0 0 0 1px hsl(263 70% 62% / 0.35), 0 0 10px 1px hsl(263 80% 62% / 0.35); }
  50% { box-shadow: 0 0 0 1px hsl(263 85% 72% / 0.6), 0 0 22px 5px hsl(263 85% 65% / 0.65); }
}

/* Tooltips: on hover and keyboard focus; app.js also flashes them briefly after a tap on touch screens. */
.icon-btn[data-tip]::after {
  content: attr(data-tip);
  position: absolute; top: calc(100% + 10px); right: 0; z-index: 5;
  white-space: nowrap; pointer-events: none;
  padding: 6px 10px; border-radius: 8px;
  background: hsl(270 30% 8% / 0.96); border: 1px solid hsl(263 70% 62% / 0.5);
  color: var(--paper); font-size: 12px; font-weight: 500;
  box-shadow: 0 6px 18px hsl(270 60% 4% / 0.6);
  opacity: 0; transform: translateY(-4px);
  transition: opacity 0.15s, transform 0.15s;
}
.icon-btn[data-tip]:hover::after,
.icon-btn[data-tip]:focus-visible::after,
.icon-btn[data-tip].show-tip::after { opacity: 1; transform: translateY(0); }

.avatar-wrap {
  position: relative;
  background: radial-gradient(ellipse at 50% 40%, hsl(263 60% 40% / 0.55), transparent 70%);
  overflow: hidden;
}
#avatar { display: block; width: 100%; height: auto; aspect-ratio: 800 / 560; }
.icon-btn:disabled { opacity: 0.4; cursor: default; box-shadow: none; animation: none; }
.voice-state {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  padding: 4px 10px; border-radius: 999px; font-size: 12px;
  background: hsl(280 30% 6% / 0.8); color: var(--muted); opacity: 0; transition: opacity 0.2s;
}
.voice-state.visible { opacity: 1; }
.voice-state[data-state="hearing"] { color: white; background: hsl(263 70% 45% / 0.9); }

.caption {
  position: absolute; left: 12px; right: 12px; bottom: 10px; margin: 0;
  padding: 8px 12px; border-radius: 14px; font-size: 14px; line-height: 1.35;
  background: hsl(280 30% 6% / 0.82); text-align: center;
  opacity: 0; transition: opacity 0.2s;
}
.caption.visible { opacity: 1; }

.log { max-height: 200px; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.log:empty { display: none; }
.msg { max-width: 85%; padding: 8px 12px; border-radius: 14px; font-size: 14px; line-height: 1.4; }
.msg.user { align-self: flex-end; background: var(--primary); color: white; }
.msg.bot { align-self: flex-start; background: hsl(263 25% 18%); }
.msg.error { align-self: center; font-size: 12px; color: var(--muted); background: none; }

.demo-row { display: flex; justify-content: center; padding: 6px 16px 2px; }
.chip {
  background: hsl(263 25% 18%); color: inherit; border: 1px solid hsl(263 30% 30%);
  border-radius: 999px; padding: 6px 12px; font-size: 12px; cursor: pointer;
}

.composer { display: flex; gap: 8px; padding: 8px 16px 6px; }
.composer input {
  flex: 1; background: hsl(263 25% 12%); color: inherit; border: 1px solid hsl(263 30% 30%);
  border-radius: 12px; padding: 10px 12px; font-size: 14px;
}
.composer input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.send {
  background: var(--primary); color: white; border: 0; border-radius: 12px;
  padding: 0 14px; font-weight: 600; cursor: pointer;
}
.send:disabled { opacity: 0.5; cursor: default; }
.disclosure { margin: 0; padding: 4px 16px 12px; font-size: 11px; line-height: 1.45; color: var(--muted); }
.disclosure a { color: inherit; }

@media (prefers-reduced-motion: reduce) {
  .caption { transition: none; }
  #voice.glow { animation: none !important; }
  .icon-btn, .icon-btn[data-tip]::after { transition: none; }
}
