:root {
  --bg: #0a0b0f;
  --bg-2: #11131b;
  --panel: #161925;
  --ink: #e8eaf2;
  --muted: #8b90a3;
  --accent: #7c5cff;
  --accent-2: #29d4c5;
  --accent-warm: #ff7a9c;
  --user: #1f2433;
  --bot: #1a2230;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 18px;
  --shadow: 0 20px 60px rgba(0,0,0,.55);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(1200px 800px at 70% -10%, #1a1638 0%, transparent 55%),
              radial-gradient(900px 700px at 10% 110%, #0f2a2e 0%, transparent 50%),
              var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  overflow: hidden;
}
.hidden { display: none !important; }

/* ---------- Auth gate ---------- */
.gate {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: rgba(6,7,11,.85); backdrop-filter: blur(14px); z-index: 50;
}
.gate-card {
  width: min(360px, 88vw); padding: 38px 30px; text-align: center;
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid rgba(255,255,255,.07); border-radius: 24px; box-shadow: var(--shadow);
}
.gate-card h1 { margin: 18px 0 2px; font-size: 22px; letter-spacing: .3px; }
.gate-sub { margin: 0 0 22px; color: var(--muted); font-size: 13px; }
.gate-orb {
  width: 74px; height: 74px; margin: 0 auto; border-radius: 50%;
  background: conic-gradient(from 0deg, var(--accent), var(--accent-2), var(--accent-warm), var(--accent));
  filter: blur(.3px); animation: spin 7s linear infinite, breathe 3.4s ease-in-out infinite;
  box-shadow: 0 0 50px rgba(124,92,255,.5);
}
.gate input {
  width: 100%; padding: 13px 15px; border-radius: 12px; border: 1px solid rgba(255,255,255,.1);
  background: #0c0e15; color: var(--ink); font-size: 15px; outline: none; margin-bottom: 12px;
}
.gate input:focus { border-color: var(--accent); }
.gate button {
  width: 100%; padding: 13px; border: 0; border-radius: 12px; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #5b3fe0); color: #fff; font-weight: 600; font-size: 15px;
  transition: transform .12s ease, box-shadow .2s ease;
}
.gate button:hover { transform: translateY(-1px); box-shadow: 0 10px 30px rgba(124,92,255,.4); }
.gate-err { color: var(--err); font-size: 13px; min-height: 18px; margin: 12px 0 0; }

/* ---------- App shell ---------- */
.app { height: 100%; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid rgba(255,255,255,.06);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; letter-spacing: .3px; }
.brand-name { font-size: 15px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 0 transparent; transition: .3s; }
.dot.on { background: var(--ok); box-shadow: 0 0 12px var(--ok); }
.dot.off { background: var(--err); }
.meta { display: flex; align-items: center; gap: 8px; }
.chip {
  font-size: 11px; color: var(--muted); padding: 4px 9px; border-radius: 999px;
  background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.06); white-space: nowrap;
}
.ghost {
  background: transparent; color: var(--muted); border: 1px solid rgba(255,255,255,.12);
  border-radius: 999px; padding: 5px 12px; font-size: 12px; cursor: pointer; transition: .15s;
}
.ghost:hover { color: var(--ink); border-color: var(--accent); }

/* ---------- Stage ---------- */
.stage { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.orb-wrap { position: relative; display: grid; place-items: center; padding: 20px 0 6px; flex-shrink: 0; }
#viz { position: absolute; top: 0; pointer-events: none; opacity: .9; }
.orb {
  position: relative; width: 150px; height: 150px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, rgba(124,92,255,.35), rgba(10,11,15,.1) 70%);
  transition: transform .25s ease, filter .3s ease;
}
.orb-core {
  width: 96px; height: 96px; border-radius: 50%;
  background: conic-gradient(from 0deg, var(--accent), var(--accent-2), var(--accent-warm), var(--accent));
  filter: blur(2px); animation: spin 9s linear infinite;
  box-shadow: 0 0 60px rgba(124,92,255,.45);
}
.orb.idle .orb-core { animation: spin 14s linear infinite, breathe 4s ease-in-out infinite; opacity: .55; }
.orb.listening { transform: scale(1.06); filter: drop-shadow(0 0 24px rgba(41,212,197,.55)); }
.orb.listening .orb-core { background: conic-gradient(from 0deg, var(--accent-2), #1ee6c0, var(--accent-2)); animation: spin 4s linear infinite; }
.orb.thinking .orb-core { animation: spin 1.2s linear infinite; }
.orb.speaking { transform: scale(1.04); filter: drop-shadow(0 0 26px rgba(255,122,156,.5)); }
.orb.speaking .orb-core { background: conic-gradient(from 0deg, var(--accent-warm), #ff5c87, var(--accent), var(--accent-warm)); animation: spin 3s linear infinite; }
.stage-label { margin-top: 10px; color: var(--muted); font-size: 13px; letter-spacing: .4px; text-transform: lowercase; }

/* ---------- Transcript ---------- */
.transcript {
  flex: 1; overflow-y: auto; padding: 10px 18px 18px; display: flex; flex-direction: column; gap: 10px;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent;
}
.transcript::-webkit-scrollbar { width: 7px; }
.transcript::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); border-radius: 4px; }
.bubble {
  max-width: 82%; padding: 11px 15px; border-radius: 16px; font-size: 14.5px; line-height: 1.55;
  white-space: pre-wrap; word-wrap: break-word; animation: rise .25s ease;
  border: 1px solid rgba(255,255,255,.05);
}
.bubble.user { align-self: flex-end; background: var(--user); border-bottom-right-radius: 5px; }
.bubble.bot  { align-self: flex-start; background: linear-gradient(180deg, var(--bot), #141b27); border-bottom-left-radius: 5px; }
.bubble.sys  { align-self: center; background: transparent; color: var(--muted); font-size: 12px; padding: 4px 10px; border: 0; }
.bubble .who { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 3px; }
.bubble.bot .who { color: var(--accent-warm); }
.bubble .play {
  display: inline-flex; align-items: center; gap: 5px; margin-top: 7px; font-size: 11px; color: var(--accent-2);
  cursor: pointer; opacity: .8;
}
.bubble .play:hover { opacity: 1; }

/* ---------- Composer ---------- */
.composer { padding: 12px 18px 18px; border-top: 1px solid rgba(255,255,255,.06); flex-shrink: 0; }
.mic {
  display: block; width: 76px; height: 76px; margin: 0 auto 12px; border-radius: 50%; border: 0; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #5b3fe0); color: #fff;
  box-shadow: 0 14px 40px rgba(124,92,255,.45); transition: transform .12s ease, box-shadow .2s ease, background .2s;
  display: grid; place-items: center; touch-action: none;
}
.mic:hover { transform: translateY(-2px); }
.mic:active { transform: scale(.94); }
.mic.recording { background: linear-gradient(135deg, var(--accent-warm), #e23a68); box-shadow: 0 0 0 8px rgba(255,122,156,.18), 0 14px 40px rgba(255,90,120,.5); animation: pulse 1.1s ease-in-out infinite; }
.mic.busy { opacity: .55; pointer-events: none; }
.composer-row { display: flex; gap: 8px; align-items: center; }
#text-in {
  flex: 1; padding: 11px 14px; border-radius: 12px; border: 1px solid rgba(255,255,255,.1);
  background: #0c0e15; color: var(--ink); font-size: 14px; outline: none;
}
#text-in:focus { border-color: var(--accent); }
.send {
  padding: 11px 16px; border: 0; border-radius: 12px; cursor: pointer; font-weight: 600;
  background: rgba(124,92,255,.18); color: var(--ink); border: 1px solid rgba(124,92,255,.35); transition: .15s;
}
.send:hover { background: rgba(124,92,255,.32); }
.speak-toggle, .vad-toggle { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; cursor: pointer; user-select: none; }
.hint { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.status-text { font-size: 12px; color: var(--accent-2); min-height: 16px; }
.status-text.err { color: var(--err); }
.status-text.warn { color: var(--warn); }

/* ---------- Animations ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 8px rgba(255,122,156,.18), 0 14px 40px rgba(255,90,120,.5); } 50% { box-shadow: 0 0 0 16px rgba(255,122,156,.05), 0 14px 40px rgba(255,90,120,.5); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 520px) {
  .bubble { max-width: 88%; }
  .orb { width: 124px; height: 124px; }
  .orb-core { width: 78px; height: 78px; }
}
