:root {
  --bg: #0b1420;
  --panel: #111f31;
  --panel-2: #16283d;
  --line: rgba(159, 216, 255, 0.14);
  --text: #e8f2fb;
  --muted: #8fa8c0;
  --accent: #9fd8ff;
  --accent-2: #6fb6e8;
  --user: #1f4d73;
  --danger: #d77b8a;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(circle at 20% 0%, #14263b 0%, var(--bg) 46%, #070e16 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
#app {
  height: 100%;
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 20, 32, 0.82);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #6f8aa3;
  box-shadow: 0 0 0 4px rgba(111, 138, 163, 0.12);
  flex: none;
}
.dot.online { background: #79d7b2; box-shadow: 0 0 0 4px rgba(121, 215, 178, 0.14); }
.dot.offline { background: var(--danger); box-shadow: 0 0 0 4px rgba(215, 123, 138, 0.14); }
.brandText { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.brandText strong { font-size: 16px; letter-spacing: 0.04em; }
.brandText small { color: var(--muted); font-size: 11px; }
.actions { display: flex; gap: 6px; flex: none; }
.ghostBtn {
  color: var(--accent);
  background: rgba(159, 216, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 12px;
}
.ghostBtn:active { background: rgba(159, 216, 255, 0.14); }
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.msg { display: flex; flex-direction: column; max-width: 86%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }
.bubble {
  padding: 10px 13px;
  border-radius: 15px;
  line-height: 1.62;
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.assistant .bubble {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}
.msg.user .bubble {
  background: linear-gradient(180deg, #24567e, var(--user));
  border-bottom-right-radius: 5px;
  color: #f4fbff;
}
.meta { color: var(--muted); font-size: 10px; margin-top: 4px; padding: 0 3px; }
.msg.failed .bubble { border: 1px solid rgba(215, 123, 138, 0.5); }
.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(11, 20, 32, 0.9);
  backdrop-filter: blur(16px);
}
#input {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  padding: 11px 13px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: rgba(17, 31, 49, 0.9);
  color: var(--text);
  outline: none;
  line-height: 1.45;
}
#input:focus { border-color: rgba(159, 216, 255, 0.38); }
#send {
  border: 0;
  border-radius: 13px;
  background: linear-gradient(180deg, #b7e5ff, var(--accent-2));
  color: #082033;
  font-weight: 700;
  padding: 12px 16px;
  min-height: 44px;
}
#send:disabled { opacity: 0.5; }
.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(4, 9, 15, 0.78);
  backdrop-filter: blur(10px);
}
.overlay.hidden { display: none; }
.setupCard {
  width: 100%;
  max-width: 390px;
  border-radius: 20px;
  padding: 24px 20px;
  background: linear-gradient(180deg, #14263b, #0d1928);
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  text-align: center;
}
.setupIcon {
  width: 54px;
  height: 54px;
  line-height: 54px;
  margin: 0 auto 14px;
  border-radius: 16px;
  background: linear-gradient(135deg, #b7e5ff, #6fb6e8);
  color: #082033;
  font-weight: 800;
  font-size: 24px;
}
.setupCard h1 { margin: 0 0 8px; font-size: 20px; }
.setupCard p { color: var(--muted); font-size: 13px; line-height: 1.7; margin: 0 0 14px; }
.setupCard input, .sheet input {
  width: 100%;
  padding: 12px 13px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(9, 18, 29, 0.9);
  color: var(--text);
  outline: none;
  margin-bottom: 10px;
}
.primaryBtn {
  width: 100%;
  border: 0;
  border-radius: 11px;
  padding: 12px 14px;
  background: linear-gradient(180deg, #b7e5ff, var(--accent-2));
  color: #082033;
  font-weight: 700;
}
.dangerBtn {
  width: 100%;
  margin-top: 8px;
  border: 1px solid rgba(215, 123, 138, 0.35);
  border-radius: 11px;
  padding: 11px 14px;
  background: rgba(215, 123, 138, 0.08);
  color: #f0b9c2;
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  max-height: 78vh;
  overflow-y: auto;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, #14263b, #0b1420);
  box-shadow: 0 -18px 50px rgba(0, 0, 0, 0.35);
}
.sheet.hidden { display: none; }
.sheetHead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.fieldLabel { display: block; color: var(--muted); font-size: 12px; margin: 8px 0 6px; }
.hint { color: var(--muted); font-size: 11px; line-height: 1.6; margin: 10px 0 0; }
.memoryList { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.memoryItem {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  background: rgba(17, 31, 49, 0.7);
  font-size: 13px;
  line-height: 1.55;
  color: #d5e7f5;
}
.memoryAdd { display: flex; gap: 8px; align-items: flex-end; }
.memoryAdd input { margin-bottom: 0; flex: 1; }
.memoryAdd .primaryBtn { width: auto; flex: none; padding: 12px 14px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  max-width: 86vw;
  padding: 9px 13px;
  border-radius: 10px;
  background: rgba(8, 16, 26, 0.94);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12px;
  line-height: 1.5;
}
.toast.hidden { display: none; }
@media (min-width: 720px) {
  .messages { padding-left: 22px; padding-right: 22px; }
  .bubble { font-size: 15.5px; }
}
