:root {
  --bg: #0b0e1c;
  --bg2: #121731;
  --card: #171d3b;
  --line: rgba(255, 255, 255, 0.09);
  --text: #eef1ff;
  --muted: #8f98c4;
  --accent: #6b7cff;
  --accent2: #9aa8ff;
  --danger: #ff6b7d;
  --user: #2a3270;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

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;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input, select { font: inherit; color: inherit; }

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: var(--safe-t);
  background: radial-gradient(120% 60% at 50% 0%, #1a2150 0%, var(--bg) 60%);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 8px;
  border-bottom: 1px solid var(--line);
}
.title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 8px;
  border-radius: 10px;
}
.icon-btn {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--accent2);
  flex: none;
}
.icon-btn:active { background: var(--card); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  padding: 24px;
  max-width: 320px;
}
.empty h2 { color: var(--text); margin: 14px 0 6px; font-size: 22px; }
.empty p { margin: 4px 0; }

.msg {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  position: relative;
}
.msg.user { align-self: flex-end; background: var(--user); border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.error { align-self: center; background: rgba(255, 107, 125, 0.12); color: var(--danger); font-size: 14px; }
.msg.pending { opacity: 0.85; }
.msg .replay {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin: 4px 0 -4px -6px;
  border-radius: 50%;
  color: var(--muted);
}
.msg .replay:active { background: var(--bg2); }
.msg .interrupted { color: var(--muted); font-size: 12px; display: block; margin-top: 2px; }

.dots { display: inline-flex; gap: 5px; padding: 4px 0; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent2); animation: bounce 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; } 40% { transform: scale(1); opacity: 1; } }

.dock {
  padding: 8px 12px calc(12px + var(--safe-b));
  border-top: 1px solid var(--line);
  background: rgba(11, 14, 28, 0.85);
  backdrop-filter: blur(10px);
}
.status { margin: 0 0 6px; min-height: 20px; text-align: center; color: var(--muted); font-size: 14px; }
.live { margin: 0 0 8px; text-align: center; color: var(--accent2); font-style: italic; }

.controls { display: flex; align-items: center; gap: 12px; }
.composer {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 4px 4px 4px 16px;
  min-width: 0;
}
.composer input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; padding: 10px 0; font-size: 16px; }
.send { width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: white; display: grid; place-items: center; flex: none; }

.mic {
  position: relative;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.mic .mic-icon { position: relative; z-index: 1; color: white; }
.orb {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #d3dbff, #6b7cff 55%, #3b46c9);
  box-shadow: 0 0 0 0 rgba(107, 124, 255, 0.5), 0 8px 24px rgba(59, 70, 201, 0.5);
  transition: transform 0.2s;
}
.orb-small { position: relative; width: 64px; height: 64px; margin: 0 auto 8px; display: block; }
.mic[data-state="listening"] .orb { animation: pulse 1.4s infinite; background: radial-gradient(circle at 35% 30%, #ffd3d9, #ff6b7d 55%, #c93b4e); }
.mic[data-state="thinking"] .orb { animation: breathe 1.2s infinite ease-in-out; opacity: 0.8; }
.mic[data-state="speaking"] .orb { animation: speak 0.9s infinite ease-in-out; background: radial-gradient(circle at 35% 30%, #d3ffe8, #4fd6a0 55%, #2a9a70); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255, 107, 125, 0.6); } 100% { box-shadow: 0 0 0 26px rgba(255, 107, 125, 0); } }
@keyframes breathe { 0%, 100% { transform: scale(0.94); } 50% { transform: scale(1.04); } }
@keyframes speak { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.1); } }

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 10; }
.drawer, .sheet {
  position: fixed;
  z-index: 11;
  background: var(--bg2);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: calc(14px + var(--safe-t)) 14px calc(14px + var(--safe-b));
}
.drawer { top: 0; bottom: 0; left: 0; width: min(88vw, 380px); border-right: 1px solid var(--line); animation: slide-in 0.2s ease-out; }
.sheet { left: 0; right: 0; bottom: 0; border-radius: 20px 20px 0 0; border-top: 1px solid var(--line); animation: rise 0.2s ease-out; max-height: 85dvh; overflow-y: auto; }
@keyframes slide-in { from { transform: translateX(-100%); } }
@keyframes rise { from { transform: translateY(100%); } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer-head h2 { margin: 0; font-size: 18px; }

button.primary { background: var(--accent); color: white; font-weight: 600; padding: 12px 18px; border-radius: 14px; }
button.ghost { background: var(--card); padding: 12px 18px; border-radius: 14px; border: 1px solid var(--line); }
button.danger { color: var(--danger); }
button.wide { width: 100%; }

.tabs { display: flex; gap: 6px; background: var(--card); border-radius: 12px; padding: 4px; }
.tab { flex: 1; padding: 8px; border-radius: 9px; color: var(--muted); }
.tab.on { background: var(--bg); color: var(--text); }

.thread-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 6px; }
.thread-list li { display: flex; align-items: stretch; background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.thread-list li.current { border-color: var(--accent); }
.thread-open { flex: 1; min-width: 0; text-align: left; padding: 10px 12px; }
.thread-open b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-open small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-open .when { font-size: 11px; opacity: 0.8; }
.thread-act { padding: 0 12px; color: var(--muted); font-size: 13px; border-left: 1px solid var(--line); }
.thread-act:active { background: var(--bg2); }
.thread-empty { color: var(--muted); text-align: center; padding: 24px 0; }
.busy-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #4fd6a0; margin-right: 6px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 6px 0; }
.row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.col { display: flex; flex-direction: column; gap: 6px; }
.col select { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.col input[type="range"] { accent-color: var(--accent); }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: radial-gradient(120% 60% at 50% 0%, #1a2150 0%, var(--bg) 60%); }
.login-card { width: min(100%, 360px); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-card h1 { margin: 0; }
.login-card p { margin: 0; color: var(--muted); }
.login-card input { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; text-align: center; font-size: 17px; outline: 0; }
.login-card input:focus { border-color: var(--accent); }
.error { color: var(--danger) !important; min-height: 20px; }
