:root {
  /* Surfaces (each step ~+5-7% luminance) */
  --bg: #0b0d12;
  --surface-1: #111722;
  --surface-2: #18202e;
  --surface-3: #212c3d;
  /* Text */
  --text: #eaf0f7;
  --text-muted: #9aa6bb;
  --text-faint: #6b768c;
  /* Borders */
  --border: rgba(255,255,255,.07);
  --border-strong: rgba(255,255,255,.14);
  /* Accent */
  --accent: #6ea0ff;
  --accent-press: #5b8cff;
  --accent-soft: rgba(110,160,255,.16);
  /* Voice states */
  --listen: #6ea0ff;
  --speak: #34d399;
  --speak-soft: rgba(52,211,153,.18);
  --danger: #f87171;
  --user: #2a3550;
  --grad-voice: conic-gradient(from 210deg, #6ea0ff, #34d399, #8b7bff, #6ea0ff);
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-1: 0 8px 24px rgba(0,0,0,.35);
  --shadow-2: 0 20px 60px rgba(0,0,0,.55);
  --ease: cubic-bezier(.2,.8,.2,1);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  letter-spacing: .005em;
}
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 6px 0 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* ---------- Orb (voice presence) ---------- */
.orb { position: relative; width: 128px; height: 128px; display: grid; place-items: center; }
.orb.orb-sm { width: 60px; height: 60px; margin: 0 auto 4px; }
.orb-core {
  position: absolute; inset: 0; border-radius: 50%;
  background: var(--grad-voice); filter: blur(2px);
  transform: scale(calc(.9 + var(--amp,0) * .18));
  transition: transform .08s linear, opacity .3s var(--ease), background .4s var(--ease);
  animation: orbSpin 9s linear infinite, orbBreathe 4s var(--ease) infinite; opacity: .9;
}
.orb-ring {
  position: absolute; inset: -14px; border-radius: 50%;
  background: radial-gradient(closest-side, var(--accent-soft), transparent 70%);
  transform: scale(calc(1 + var(--amp,0) * .5));
  transition: transform .1s linear, background .3s; filter: blur(6px);
}
.orb-bars { display: none; gap: 5px; align-items: center; height: 42px; z-index: 1; }
.orb-bars i {
  width: 5px; border-radius: 3px; height: 14px; background: #0b0d12;
  transform: scaleY(var(--b,.4)); transform-origin: center; transition: transform .07s linear;
}
@keyframes orbSpin { to { transform: rotate(360deg); } }
@keyframes orbBreathe { 0%,100% { filter: blur(2px) brightness(1); } 50% { filter: blur(4px) brightness(1.15); } }
.voice-stage { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 24px 16px 6px; }
.voice-stage[data-state="idle"] .orb-core { opacity: .55; animation-duration: 14s, 6s; }
.voice-stage[data-state="listening"] .orb-bars { display: flex; }
.voice-stage[data-state="speaking"] .orb-core { background: conic-gradient(from 0deg, var(--speak), #6ee7b7, var(--speak)); }
.voice-stage[data-state="speaking"] .orb-ring { background: radial-gradient(closest-side, var(--speak-soft), transparent 70%); }
.voice-stage[data-state="speaking"] .orb-bars { display: flex; }
.voice-stage[data-state="speaking"] .orb-bars i { background: #06231a; }
.voice-stage[data-state="thinking"] .orb-core { animation: orbSpin 2.2s linear infinite, orbBreathe 4s var(--ease) infinite; }
.voice-hint { color: var(--text-muted); font-size: 13px; margin: 0; min-height: 1.2em; }

/* ---------- Login ---------- */
.overlay {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 20px;
  background:
    radial-gradient(1100px 700px at 50% -15%, #16203a 0%, transparent 60%),
    radial-gradient(700px 500px at 90% 110%, #10241e 0%, transparent 55%), var(--bg);
}
.card {
  background: linear-gradient(180deg, var(--surface-1), var(--bg));
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 28px; width: min(360px, 92vw); display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow-2); animation: fadeUp .5s var(--ease) both;
}
.card h1 { margin: 0; font-size: 22px; text-align: center; }
.card .muted { text-align: center; margin: 0 0 4px; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
input {
  background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text);
  padding: 12px 14px; border-radius: 10px; font-size: 16px; outline: none; width: 100%;
}
input:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
.remember { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); cursor: pointer; }
.remember input { width: auto; }
button { cursor: pointer; font-family: inherit; }
.btn-primary {
  background: var(--accent); color: #0b0d12; border: 0; padding: 12px 16px; border-radius: 12px;
  font-size: 16px; font-weight: 700; transition: transform .12s var(--ease), filter .2s, box-shadow .2s;
}
.btn-primary:hover { filter: brightness(1.07); box-shadow: 0 6px 18px var(--accent-soft); }
.btn-primary:active { transform: translateY(1px) scale(.99); }
.ghost { background: transparent; color: var(--text-muted); border: 0; padding: 6px 10px; font-size: 18px; border-radius: 8px; }
.ghost:hover { background: var(--surface-2); color: var(--text); }

/* ---------- App shell ---------- */
#app { display: flex; flex-direction: column; height: 100dvh; }
header {
  display: flex; align-items: center; gap: 10px; padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--border); background: var(--surface-1);
}
.brand { font-size: 16px; }
.voice-select {
  margin-left: auto; background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 6px 8px; font-size: 13px; max-width: 150px;
}
.conn { display: inline-flex; align-items: center; gap: 7px; padding: 4px 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  font-size: 12px; color: var(--text-muted); }
.conn-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); transition: background .3s, box-shadow .3s; }
.conn.on .conn-dot { background: var(--speak); box-shadow: 0 0 0 3px var(--speak-soft); }
.conn.err .conn-dot { background: var(--danger); box-shadow: 0 0 0 3px rgba(248,113,113,.2); }
.banner { padding: 10px 16px; background: #2a2110; color: #ffcf8f; font-size: 14px; border-bottom: 1px solid #4a3a23; }

#transcript { flex: 1; overflow-y: auto; padding: 12px 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: min(78%, 640px); padding: 11px 15px; border-radius: 18px;
  white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; animation: msgIn .28s var(--ease) both; }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.msg.user { align-self: flex-end; color: #fff;
  background: linear-gradient(180deg, var(--accent), var(--accent-press)); border-bottom-right-radius: 6px; box-shadow: var(--shadow-1); }
.msg.ai { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.msg.ai.streaming::after { content: "▍"; margin-left: 1px; color: var(--accent); animation: caret 1s steps(2) infinite; }
@keyframes caret { 50% { opacity: 0; } }
.msg.sys { align-self: center; color: var(--text-muted); font-size: 13px; background: transparent; max-width: 90%; text-align: center; }
.msg.tool { align-self: flex-start; display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px;
  border-radius: 999px; font-size: 13px; background: var(--surface-2); border: 1px solid var(--border); color: var(--accent); }
.msg.tool.done { color: var(--speak); }
.msg.tool::before { content: ""; width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .7s linear infinite; }
.msg.tool.done::before { content: "✓"; border: 0; width: auto; height: auto; animation: none; font-weight: 700; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Footer / controls ---------- */
footer {
  display: flex; gap: 10px; align-items: center;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--surface-1);
}
.mic {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; font-size: 22px;
  background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text);
  transition: transform .15s var(--ease), background .2s, box-shadow .2s; flex: none;
}
.mic:hover { background: var(--surface-3); }
.mic.live { background: var(--danger); color: #fff; animation: micPulse 1.6s var(--ease) infinite; }
.mic:disabled { opacity: .4; cursor: not-allowed; }
@keyframes micPulse { 0% { box-shadow: 0 0 0 0 rgba(248,113,113,.45); } 70% { box-shadow: 0 0 0 16px rgba(248,113,113,0); } 100% { box-shadow: 0 0 0 0 rgba(248,113,113,0); } }
.text-form { display: flex; gap: 8px; flex: 1; min-width: 160px; }
.text-form input { flex: 1; }
.btn-send { background: var(--surface-2); color: var(--text); border: 1px solid var(--border-strong);
  border-radius: 10px; padding: 0 16px; font-size: 18px; font-weight: 700; }
.btn-send:hover { background: var(--surface-3); }

/* ---------- Responsive ---------- */
@media (min-width: 760px) {
  #transcript { width: min(820px, 100%); margin: 0 auto; }
  footer > * { } footer { justify-content: center; }
  .text-form { max-width: 720px; }
}
@media (max-width: 560px) {
  .msg { max-width: 88%; font-size: 17px; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .orb-core { animation: none; transform: none; }
  .orb-bars { display: none !important; }
}
