:root {
  --bg: #05080d;
  --panel: #0c131c;
  --line: #1a2633;
  --text: #d7e6f2;
  --muted: #6f8597;
  --cyan: #3ad8ff;
  --amber: #ffb547;
  --level: 0;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { display: flex; flex-direction: column; height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
button { font: inherit; color: inherit; cursor: pointer; }

header { display: flex; align-items: center; gap: .6rem; padding: .7rem 1rem; border-bottom: 1px solid var(--line); }
.brand { letter-spacing: .35em; font-weight: 600; font-size: .85rem; color: var(--cyan); }
.conn { width: .5rem; height: .5rem; border-radius: 50%; background: var(--muted); }
.conn.on { background: #3ddc84; }
.conn.off { background: #ff5c5c; }
nav { margin-left: auto; display: flex; gap: .4rem; }
nav button { background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: .3rem .8rem; font-size: .8rem; color: var(--muted); }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#log { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .5rem; }
.msg { max-width: 85%; padding: .55rem .8rem; border-radius: 1rem; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: #13324a; border-bottom-right-radius: .3rem; }
.msg.bot  { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: .3rem; }
.msg.sys  { align-self: center; color: var(--muted); font-size: .8rem; }

.stage { display: flex; flex-direction: column; align-items: center; padding: .5rem 0 1rem; }
#status { margin: .8rem 0 0; color: var(--muted); font-size: .9rem; min-height: 1.3em; }
.tool { margin: .2rem 0 0; color: var(--amber); font-size: .8rem; min-height: 1.1em; }

#orb { position: relative; width: 9rem; height: 9rem; border: 0; border-radius: 50%; background: transparent; padding: 0;
  -webkit-tap-highlight-color: transparent; }
#orb .core, .orb-static .core { position: absolute; inset: 22%; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #c9f4ff, var(--cyan) 35%, #0a4a66 75%);
  box-shadow: 0 0 2rem rgba(58, 216, 255, .35); transition: transform .08s linear, filter .3s; }
#orb .ring { position: absolute; inset: 6%; border-radius: 50%; border: 2px solid rgba(58, 216, 255, .25); }

body[data-state="off"] #orb .core { filter: grayscale(1) brightness(.5); box-shadow: none; }
body[data-state="connecting"] #orb .ring { animation: spin 1.2s linear infinite; border-top-color: var(--cyan); }
body[data-state="listening"] #orb .core { transform: scale(calc(1 + var(--level) * .25)); }
body[data-state="hearing"] #orb .core { transform: scale(calc(1.05 + var(--level) * .35)); box-shadow: 0 0 3.5rem rgba(58, 216, 255, .6); }
body[data-state="transcribing"] #orb .ring,
body[data-state="thinking"] #orb .ring { animation: spin 1s linear infinite; border-top-color: var(--amber); border-right-color: var(--amber); }
body[data-state="thinking"] #orb .core { animation: breathe 1.6s ease-in-out infinite; filter: hue-rotate(-150deg) saturate(1.3); }
body[data-state="speaking"] #orb .core { animation: talk .5s ease-in-out infinite alternate; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe { 50% { transform: scale(.9); } }
@keyframes talk { from { transform: scale(.97); } to { transform: scale(1.08); } }

#typeForm { display: flex; gap: .5rem; padding: .6rem 1rem 1rem; border-top: 1px solid var(--line); }
#typeForm input { flex: 1; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: .6rem 1rem; color: var(--text); font-size: 16px; }
#typeForm button { width: 2.6rem; border-radius: 50%; border: 0; background: var(--cyan); color: #00222e; }

/* login */
body.login { justify-content: center; align-items: center; }
.login-card { width: min(20rem, 88vw); display: flex; flex-direction: column; gap: .8rem; align-items: stretch; text-align: center; }
.login-card h1 { letter-spacing: .4em; font-size: 1.1rem; color: var(--cyan); margin: 0 0 .5rem; font-weight: 600; }
.orb-static { position: relative; width: 6rem; height: 6rem; margin: 0 auto; }
.login-card input { background: var(--panel); border: 1px solid var(--line); border-radius: .7rem; padding: .8rem 1rem; color: var(--text); font-size: 16px; }
.login-card button { border: 0; border-radius: .7rem; padding: .8rem; background: var(--cyan); color: #00222e; font-weight: 600; }
.login-card button:disabled { opacity: .5; }
.err { color: #ff7b7b; min-height: 1.2em; margin: 0; font-size: .9rem; }
