:root {
  --bg: #07060d;
  --fg: #ece9f5;
  --muted: #8a85a3;
  --faint: #4a4660;
  --line: rgba(255,255,255,.08);
  --accent: #b57bff;
  --accent2: #5fd4ff;
  --err: #ff6b8a;
  --orb: min(72vw, 42dvh, 340px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 300 17px/1.5 Outfit, system-ui, sans-serif;
  display: flex; flex-direction: column; align-items: center;
  height: 100dvh; overflow: hidden;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; cursor: pointer; }

.glow {
  position: fixed; inset: -20%; z-index: -1; pointer-events: none;
  background:
    radial-gradient(40% 35% at 50% 28%, var(--glow, rgba(120,80,255,.22)), transparent 70%),
    radial-gradient(60% 40% at 50% 110%, rgba(60,90,255,.10), transparent 70%);
  transition: background 1.2s ease;
}
body[data-state="listening"] { --glow: rgba(255,80,150,.26); }
body[data-state="thinking"]  { --glow: rgba(80,200,255,.22); }
body[data-state="speaking"]  { --glow: rgba(190,110,255,.30); }

header {
  width: 100%; max-width: 640px; display: flex; align-items: center; justify-content: space-between;
  padding: 14px 4px 0;
}
.brand {
  font-weight: 200; font-size: 22px; letter-spacing: .42em; text-transform: uppercase;
  background: linear-gradient(90deg, #fff, #c9b3ff 60%, #8fdcff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.icon {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: rgba(255,255,255,.03); display: grid; place-items: center; color: var(--muted);
  transition: color .2s, border-color .2s;
}
.icon:hover { color: var(--fg); border-color: rgba(255,255,255,.2); }

.stage { display: flex; flex-direction: column; align-items: center; padding-top: 2dvh; flex: none; }
#orb {
  width: var(--orb); height: var(--orb); border: 0; padding: 0; background: none; border-radius: 50%;
  touch-action: manipulation; transition: transform .25s ease;
}
#orb:active { transform: scale(.97); }
#orb:disabled { cursor: default; }
#orb canvas { width: 100%; height: 100%; display: block; }
#status {
  margin: 4px 0 0; height: 1.5em; font-size: 15px; letter-spacing: .14em; text-transform: lowercase;
  color: var(--muted); transition: color .3s;
}
#status.err { color: var(--err); letter-spacing: .02em; text-transform: none; }

#log {
  flex: 1; width: 100%; max-width: 640px; overflow-y: auto; padding: 18px 4px 28px;
  display: flex; flex-direction: column; gap: 16px; scrollbar-width: none;
  -webkit-mask-image: linear-gradient(transparent, #000 28px, #000 calc(100% - 20px), transparent);
          mask-image: linear-gradient(transparent, #000 28px, #000 calc(100% - 20px), transparent);
}
#log::-webkit-scrollbar { display: none; }
.msg { max-width: 88%; animation: rise .45s cubic-bezier(.2,.8,.2,1) both; }
.me {
  align-self: flex-end; text-align: right; color: var(--muted); font-size: 16px;
  padding: 8px 14px; border-radius: 18px 18px 4px 18px; background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
}
.ai { align-self: flex-start; padding-left: 16px; position: relative; font-size: 18px; }
.ai::before {
  content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 2px; border-radius: 2px;
  background: linear-gradient(var(--accent), var(--accent2));
}
.ai.typing::after { content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; margin-left: 2px; }
.replay {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; padding: 3px 10px 3px 8px;
  border-radius: 99px; border: 1px solid var(--line); background: none; color: var(--muted); font-size: 13px;
}
.replay:hover { color: var(--fg); }
.hint { text-align: center; color: var(--faint); font-size: 15px; margin: auto 0; }

#login { display: flex; gap: 8px; width: 100%; max-width: 360px; flex-wrap: wrap; margin-top: 4dvh; }
#login[hidden] { display: none; }
#login input {
  flex: 1; padding: 14px 18px; border-radius: 99px; border: 1px solid var(--line);
  background: rgba(255,255,255,.04); color: var(--fg); font: inherit; outline: none;
}
#login input:focus { border-color: var(--accent); }
#login button {
  width: 52px; border-radius: 50%; border: 0; font-size: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #0b0716;
}
#loginErr { width: 100%; text-align: center; color: var(--err); margin: 4px 0 0; min-height: 1.5em; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .msg { animation: none; } }
