:root {
  --bg: #0f1216;
  --bg-soft: #171c23;
  --bg-bubble: #1d2430;
  --line: #2a3340;
  --text: #e8edf4;
  --muted: #8b97a8;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.16);
  --user: #2b5fd9;
  --warn: #ff7a7a;
  --ok: #4ade80;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---------------- 登录 ---------------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2636 0%, var(--bg) 60%);
  z-index: 20;
}

.card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.card .logo { font-size: 34px; line-height: 1; }
.card h1 { font-size: 20px; margin: 0; letter-spacing: 0.2px; }
.card .muted { color: var(--muted); font-size: 14px; margin: 0 0 4px; }

.card input {
  background: #0d1117;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  outline: none;
}
.card input:focus { border-color: var(--accent); }

.card button, .send {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.card button:disabled { opacity: 0.6; }
.error { color: var(--warn); font-size: 13px; min-height: 18px; margin: 0; }

/* ---------------- 主界面 ---------------- */
#app { display: flex; flex-direction: column; height: 100dvh; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 18, 22, 0.9);
  backdrop-filter: blur(8px);
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; white-space: nowrap; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.up { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.down { background: var(--warn); }

.controls { display: flex; align-items: center; gap: 6px; min-width: 0; }

#voiceSelect {
  max-width: 130px;
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
}

.chip {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.chip.off { opacity: 0.45; }
.chip:disabled { opacity: 0.35; cursor: not-allowed; }

#shareBar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}
#shareBar code {
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 84%;
  padding: 10px 13px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15.5px;
  position: relative;
}
.msg.user { align-self: flex-end; background: var(--user); border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--bg-bubble); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.error { align-self: center; background: rgba(255, 122, 122, 0.12); color: var(--warn); border: 1px solid rgba(255, 122, 122, 0.3); font-size: 14px; }
.msg .replay {
  position: absolute;
  right: 6px;
  bottom: -10px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 26px;
  height: 26px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
.msg.assistant { margin-bottom: 10px; }

.typing { align-self: flex-start; display: flex; gap: 4px; padding: 12px 14px; background: var(--bg-bubble); border: 1px solid var(--line); border-radius: var(--radius); }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

footer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
}

#input {
  flex: 1;
  resize: none;
  max-height: 120px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 13px;
  font: inherit;
  font-size: 16px;
  outline: none;
}
#input:focus { border-color: var(--accent); }

.mic, .send {
  border: 0;
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 18px;
  cursor: pointer;
  flex: none;
}
.mic { background: var(--bg-soft); border: 1px solid var(--line); }
.mic.on { background: rgba(255, 122, 122, 0.2); border-color: var(--warn); animation: pulse 1.2s infinite; }
.mic:disabled { opacity: 0.35; cursor: not-allowed; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 122, 122, 0.35); } 50% { box-shadow: 0 0 0 8px rgba(255, 122, 122, 0); } }

.send { background: var(--accent); color: #fff; font-size: 15px; font-weight: 600; }
.send:disabled { opacity: 0.5; cursor: not-allowed; }

.hint {
  margin: 0;
  padding: 0 14px 6px;
  min-height: 16px;
  font-size: 12px;
  color: var(--muted);
}

@media (min-width: 720px) {
  #messages, footer, header, .hint, #shareBar { max-width: 760px; width: 100%; margin: 0 auto; }
  #app { align-items: stretch; }
}
