:root {
  --bg: #0a0714;
  --panel: #150f26;
  --line: #241a3d;
  --text: #f0eaf8;
  --muted: #9b8fbd;
  --accent: #ff6b9d;
  --accent-2: #ffa96b;
}

* { box-sizing: border-box; }

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

body {
  background: radial-gradient(ellipse at 50% 0%, #1d1233 0%, var(--bg) 60%);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: grid;
  grid-template-rows: 1fr auto auto;
  overflow: hidden;
}

/* ── Stage ───────────────────────────────────────────────────────────── */

#stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
}

/* TalkingHead appends its own <canvas> here and sizes itself from this
   element's clientWidth/clientHeight, so it needs a real box, not just a
   stretchy parent. */
#face {
  position: absolute;
  inset: 0;
}

#recenter {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 3;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(21, 15, 38, .8);
  color: var(--muted);
  font-size: 17px;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

#recenter:hover { color: var(--text); border-color: var(--accent); }
#recenter:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Start (audio needs a gesture) ───────────────────────────────────── */

#start {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  border: 0;
  background: radial-gradient(ellipse at 50% 45%, rgba(36, 20, 58, .55) 0%, rgba(10, 7, 20, .92) 70%);
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
  cursor: pointer;
  letter-spacing: .01em;
}

#start .dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.5s ease-in-out infinite;
}

#start:hover .dot { background: var(--accent-2); }
#start:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; }

/* ── Loading ─────────────────────────────────────────────────────────── */

/* An explicit `display` on an element beats the UA stylesheet's
   `[hidden] { display: none }`, so without this the invisible loading overlay
   stays laid out on top of the page and silently swallows every click. */
[hidden] { display: none !important; }

#loading {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 14px;
  color: var(--muted);
  text-align: center;
  padding: 20px;
  background: var(--bg);
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}

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

/* ── Thinking ────────────────────────────────────────────────────────── */

#thinking {
  position: absolute;
  bottom: 16px;
  display: flex;
  gap: 5px;
  padding: 9px 14px;
  border-radius: 100px;
  background: rgba(21, 15, 38, .88);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

#thinking .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.3s ease-in-out infinite;
}

#thinking .dot:nth-child(2) { animation-delay: .18s; }
#thinking .dot:nth-child(3) { animation-delay: .36s; }

@keyframes pulse {
  0%, 60%, 100% { opacity: .28; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ── Subtitle ────────────────────────────────────────────────────────── */

#subtitle {
  position: absolute;
  bottom: 54px;
  max-width: 46ch;
  margin: 0;
  padding: 11px 18px;
  border-radius: 14px;
  background: rgba(10, 7, 20, .88);
  border: 1px solid var(--line);
  text-align: center;
  font-size: 1.02rem;
  backdrop-filter: blur(8px);
}

/* ── Controls ────────────────────────────────────────────────────────── */

#controls {
  display: flex;
  gap: 9px;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: rgba(10, 7, 20, .6);
}

#controls button {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 19px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

#controls button:hover:not(:disabled) { border-color: var(--accent); }
#controls button:disabled { opacity: .4; cursor: not-allowed; }

#mic.live {
  background: var(--accent);
  color: #2b0a18;
  border-color: var(--accent);
  animation: ring 1.4s ease-in-out infinite;
}

@keyframes ring {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 157, .5); }
  50% { box-shadow: 0 0 0 9px rgba(255, 107, 157, 0); }
}

#text {
  flex: 1;
  min-width: 0;
  height: 46px;
  padding: 0 18px;
  border-radius: 23px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: .96rem;
}

#text::placeholder { color: #6b5f88; }
#text:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

#send {
  background: var(--accent);
  color: #2b0a18;
  border-color: var(--accent);
  font-weight: 700;
}

/* ── Transcript ──────────────────────────────────────────────────────── */

#log {
  max-height: 25vh;
  overflow-y: auto;
  padding: 10px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  border-top: 1px solid var(--line);
  scrollbar-width: thin;
}

.line {
  max-width: 76%;
  padding: 8px 14px;
  border-radius: 14px;
  font-size: .93rem;
}

.line.you {
  align-self: flex-end;
  background: var(--accent);
  color: #2b0a18;
  border-bottom-right-radius: 4px;
}

.line.dezzy {
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

/* An empty placeholder line while she is still thinking — reserves the space so
   the transcript does not jump when the text lands. */
.line.dezzy:empty::after {
  content: '';
  display: inline-block;
  width: 34px;
  height: 8px;
  border-radius: 4px;
  background: var(--line);
}

.line.failed {
  color: #ffa8a8;
  border-color: #5a2b34;
}

@media (max-width: 560px) {
  .line { max-width: 88%; }
  #log { max-height: 30vh; }
  #subtitle { bottom: 50px; font-size: .95rem; max-width: 34ch; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
}