:root {
  --bg: #0B0C24;
  --bg2: #1E1F4F;
  --panel: rgba(30, 31, 79, 0.55);
  --panel-solid: #17183f;
  --line: rgba(201, 211, 255, 0.14);
  --text: #E6E9FF;
  --muted: #9298B8;
  --accent: #9AA8F0;
  --accent-strong: #7A8CE0;
  --pink: #F5C2E7;
  --moon: #FFF6D8;
  --danger: #ff8fa3;
  --radius: 18px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }

.sky {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(1px 1px at 12% 18%, #fff8 50%, transparent 51%),
    radial-gradient(1px 1px at 72% 12%, #fff6 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 85% 40%, #fff5 50%, transparent 51%),
    radial-gradient(1px 1px at 30% 70%, #fff4 50%, transparent 51%),
    radial-gradient(1px 1px at 55% 85%, #fff5 50%, transparent 51%),
    radial-gradient(120% 80% at 30% 0%, #3B3F8F 0%, var(--bg2) 45%, var(--bg) 100%);
}

/* ---------- login ---------- */
.login {
  height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 16px; text-align: center; gap: 4px;
}
.login-avatar { width: 112px; height: 112px; border-radius: 50%; box-shadow: 0 0 60px #9AA8F055; margin-bottom: 8px; }
.login h1 { margin: 0; font-size: 34px; letter-spacing: 0.5px; }
.login form { width: min(340px, 100%); display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.login input {
  width: 100%; padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 17px; outline: none;
}
.login input:focus { border-color: var(--accent); }
.primary {
  padding: 14px; border: 0; border-radius: 14px; font-weight: 600; font-size: 17px; color: #0B0C24;
  background: linear-gradient(135deg, var(--moon), var(--pink) 60%, var(--accent));
}
.error { color: var(--danger); min-height: 1.4em; margin: 0; font-size: 14px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }

/* ---------- app shell ---------- */
.app {
  height: 100%; height: 100dvh; display: grid; grid-template-rows: auto auto 1fr auto auto;
  max-width: 760px; margin: 0 auto;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.top { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.avatar { width: 42px; height: 42px; border-radius: 50%; box-shadow: 0 0 18px #9AA8F044; }
.who { flex: 1; min-width: 0; }
.name { font-weight: 650; font-size: 17px; }
.status { color: var(--muted); font-size: 13px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel);
  display: grid; place-items: center; color: var(--muted);
}
.banner { margin: 0 16px 8px; padding: 8px 12px; border-radius: 12px; background: #ff8fa322; color: var(--pink); font-size: 14px; }

/* ---------- transcript ---------- */
.log {
  overflow-y: auto; padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 10px;
  overscroll-behavior: contain; scroll-behavior: smooth;
  mask-image: linear-gradient(to bottom, transparent 0, #000 18px, #000 calc(100% - 12px), transparent 100%);
}
.msg { max-width: 86%; padding: 10px 14px; border-radius: var(--radius); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, #7A8CE0cc, #9AA8F0bb); color: #0B0C24; border-bottom-right-radius: 6px; }
.msg.rem { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.rem a { color: var(--pink); }
.msg.rem.streaming::after { content: "▍"; color: var(--accent); animation: blink 1s steps(1) infinite; margin-left: 1px; }
.msg.note { align-self: center; color: var(--muted); font-size: 13px; background: none; padding: 2px 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--accent);
  border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; margin: 2px 0 6px; white-space: nowrap;
}
.chip::before { content: "☾"; }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 24px; }
.empty b { color: var(--text); display: block; font-size: 18px; margin-bottom: 4px; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- orb ---------- */
.stage { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 6px 16px 10px; }
.live { min-height: 1.5em; max-width: 100%; text-align: center; color: var(--text); opacity: .85; font-size: 15px; padding: 0 8px; }
.live:empty::before { content: "\00a0"; }
.hint { color: var(--muted); font-size: 13px; min-height: 1.2em; }
.orb {
  --level: 0;
  position: relative; width: 112px; height: 112px; border: 0; padding: 0; border-radius: 50%; background: none;
  display: grid; place-items: center; touch-action: manipulation;
}
.orb .core {
  position: relative; z-index: 2; width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center;
  color: #1E1F4F;
  background: radial-gradient(circle at 35% 30%, var(--moon), #F3D9FF 55%, #C9B5FF);
  box-shadow: 0 0 calc(30px + var(--level) * 50px) #F5C2E766, inset -8px -10px 20px #9AA8F088;
  transform: scale(calc(1 + var(--level) * 0.08));
  transition: transform .08s linear, box-shadow .2s;
}
.orb .ring {
  position: absolute; inset: 10px; border-radius: 50%; border: 2px solid #9AA8F055; z-index: 1;
  transform: scale(calc(1 + var(--level) * 0.35)); transition: transform .1s linear; opacity: 0;
}
.orb .r2 { border-color: #F5C2E744; transform: scale(calc(1 + var(--level) * 0.6)); }
.orb .stop, .orb .dots { display: none; }
.orb[data-state="listening"] .ring, .orb[data-state="speaking"] .ring { opacity: 1; }
.orb[data-state="listening"] .core { background: radial-gradient(circle at 35% 30%, #fff, var(--pink) 60%, #e59bd0); }
.orb[data-state="thinking"] .mic, .orb[data-state="speaking"] .mic { display: none; }
.orb[data-state="thinking"] .dots { display: flex; gap: 6px; }
.orb[data-state="speaking"] .stop { display: block; }
.orb[data-state="thinking"] .core { animation: breathe 1.6s ease-in-out infinite; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: #1E1F4F; animation: dot 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 80%, 100% { transform: translateY(0); opacity: .4; } 40% { transform: translateY(-6px); opacity: 1; } }
@keyframes breathe { 50% { transform: scale(1.05); box-shadow: 0 0 60px #9AA8F099, inset -8px -10px 20px #9AA8F088; } }
.orb:focus-visible { outline: 2px solid var(--accent); outline-offset: 6px; }

/* ---------- composer ---------- */
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 6px 16px 14px; }
.composer textarea {
  flex: 1; resize: none; max-height: 140px; padding: 12px 14px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit; font-size: 16px; outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.send {
  width: 46px; height: 46px; flex: none; border-radius: 14px; border: 0; color: #0B0C24;
  background: linear-gradient(135deg, var(--moon), var(--pink));
  display: grid; place-items: center;
}

/* ---------- settings ---------- */
.sheet { position: fixed; inset: 0; background: #05061299; display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet-card {
  width: min(520px, 100%); background: var(--panel-solid); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 22px 22px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 6px; max-height: 90dvh; overflow-y: auto;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 19px; }
.row { display: flex; flex-direction: column; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.row small { display: block; color: var(--muted); font-size: 12.5px; }
.row.toggle { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.inline { display: flex; gap: 8px; }
select, .ghost {
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit;
}
select { flex: 1; }
.ghost.danger { color: var(--danger); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"] { width: 44px; height: 26px; accent-color: var(--accent); flex: none; }
.sheet-actions { display: flex; gap: 8px; padding: 12px 0 4px; }
.sheet-actions .ghost { flex: 1; }

@media (min-width: 700px) {
  .orb { width: 128px; height: 128px; }
  .orb .core { width: 104px; height: 104px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
