:root {
  --night: #0a121e;
  --night-2: #132a3f;
  --moon: #f6e7c6;
  --gold: #d9a441;
  --gold-deep: #b0761a;
  --ink: #e9e4d9;
  --ink-dim: #9aa7b4;
  --bot: rgba(255, 255, 255, 0.055);
  --bot-line: rgba(255, 255, 255, 0.09);
  --serif: Georgia, "Songti SC", "SimSun", "Noto Serif SC", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--night);
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body { position: relative; }

/* ---------- 背景 ---------- */
.sky {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 80% at 78% 8%, rgba(255, 231, 186, 0.13), transparent 55%),
    radial-gradient(90% 70% at 10% 100%, rgba(28, 63, 92, 0.55), transparent 60%),
    linear-gradient(180deg, #0c1826 0%, #0a121e 55%, #070d16 100%);
}

.moon {
  position: absolute;
  top: -70px;
  right: -60px;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 38%, #fff8e6, #f2dcaa 45%, #d6b273 70%, #b5905a 100%);
  box-shadow: 0 0 90px 30px rgba(246, 231, 198, 0.14), 0 0 200px 70px rgba(217, 164, 65, 0.1);
  opacity: 0.85;
  animation: breathe 9s ease-in-out infinite;
}

.moon::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 62% 28%, rgba(180, 150, 100, 0.25) 0 12%, transparent 13%),
    radial-gradient(circle at 34% 62%, rgba(180, 150, 100, 0.18) 0 9%, transparent 10%),
    radial-gradient(circle at 70% 66%, rgba(180, 150, 100, 0.14) 0 6%, transparent 7%);
}

@keyframes breathe {
  0%, 100% { opacity: 0.82; }
  50% { opacity: 0.95; }
}

.haze {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 40%, rgba(10, 18, 30, 0.5) 100%);
  pointer-events: none;
}

.stars {
  position: absolute;
  inset: 0;
  opacity: 0.55;
  background-image:
    radial-gradient(1.4px 1.4px at 12% 18%, #fff, transparent),
    radial-gradient(1px 1px at 26% 8%, #ffeccc, transparent),
    radial-gradient(1.6px 1.6px at 44% 22%, #fff, transparent),
    radial-gradient(1px 1px at 62% 12%, #fff, transparent),
    radial-gradient(1.2px 1.2px at 84% 30%, #ffeccc, transparent),
    radial-gradient(1px 1px at 8% 46%, #fff, transparent),
    radial-gradient(1.3px 1.3px at 34% 40%, #fff, transparent),
    radial-gradient(1px 1px at 70% 48%, #fff, transparent);
  animation: twinkle 6s ease-in-out infinite alternate;
}

@keyframes twinkle {
  from { opacity: 0.35; }
  to { opacity: 0.7; }
}

.hills {
  position: absolute;
  left: -5%;
  right: -5%;
  bottom: 0;
  height: 190px;
  background:
    radial-gradient(60% 100% at 20% 100%, #0c1a26 0 60%, transparent 61%),
    radial-gradient(70% 100% at 62% 100%, #0a1521 0 60%, transparent 61%),
    radial-gradient(50% 100% at 92% 100%, #0b1926 0 60%, transparent 61%);
  filter: blur(0.3px);
  opacity: 0.9;
}

/* ---------- 布局 ---------- */
.app {
  position: relative;
  z-index: 1;
  height: 100%;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(2px);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: linear-gradient(180deg, rgba(9, 16, 27, 0.96), rgba(10, 18, 30, 0.74));
  backdrop-filter: blur(16px);
  flex-shrink: 0;
}

.avatar {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(246, 231, 198, 0.25), 0 4px 16px rgba(217, 164, 65, 0.22);
}

.avatar svg { width: 100%; height: 100%; display: block; }

.who { flex: 1; min-width: 0; }

.who h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--moon);
}

.who p {
  margin: 3px 0 0;
  font-size: 11.5px;
  color: var(--ink-dim);
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #67c98a;
  box-shadow: 0 0 6px #67c98a;
}

.reset {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink-dim);
  cursor: pointer;
  transition: 0.2s;
}

.reset:hover { color: var(--moon); border-color: rgba(246, 231, 198, 0.35); transform: rotate(-40deg); }
.reset svg { width: 16px; height: 16px; }

/* ---------- 消息流 ---------- */
.thread {
  flex: 1;
  overflow-y: auto;
  padding: 22px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

/* 消息少的时候贴底，像微信 */
.thread > .msg:first-child { margin-top: auto; }

.thread::-webkit-scrollbar { width: 5px; }
.thread::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 99px; }

.msg {
  display: flex;
  gap: 10px;
  min-width: 0;
  animation: rise 0.42s cubic-bezier(0.22, 0.8, 0.3, 1) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.msg.me { flex-direction: row-reverse; }

.msg .face {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  align-self: flex-end;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(246, 231, 198, 0.18);
}

.msg .face svg { width: 100%; height: 100%; display: block; }

.msg.me .face {
  background: linear-gradient(135deg, #3c5a75, #243b52);
  display: grid;
  place-items: center;
  font-size: 12px;
  color: #cfe0ee;
}

.bubble-wrap { max-width: min(80%, 480px); min-width: 0; display: flex; flex-direction: column; gap: 7px; }
.msg.me .bubble-wrap { align-items: flex-end; }

.bubble {
  padding: 11px 15px;
  border-radius: 4px 16px 16px 16px;
  background: var(--bot);
  border: 1px solid var(--bot-line);
  font-size: 15px;
  line-height: 1.72;
  white-space: pre-wrap;
  word-break: break-word;
  backdrop-filter: blur(8px);
}

.msg.me .bubble {
  border-radius: 16px 4px 16px 16px;
  background: linear-gradient(135deg, #e5b45a, #c08a2c);
  border-color: rgba(255, 255, 255, 0.15);
  color: #241603;
  font-weight: 500;
}

.bubble.typing { display: flex; gap: 4px; padding: 15px; }
.bubble.typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ink-dim);
  animation: bounce 1.3s infinite;
}
.bubble.typing i:nth-child(2) { animation-delay: 0.18s; }
.bubble.typing i:nth-child(3) { animation-delay: 0.36s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.caret {
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 2px;
  vertical-align: -0.15em;
  background: var(--gold);
  animation: blink 1s steps(2) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

/* 引用依据 */
.sources { font-size: 11.5px; color: var(--ink-dim); }

.sources summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
  transition: color 0.2s;
}
.sources summary::-webkit-details-marker { display: none; }
.sources summary:hover { color: var(--gold); }
.sources summary::before { content: "❖"; font-size: 9px; opacity: 0.8; }

.source-body {
  margin-top: 8px;
  padding: 12px 14px;
  border-left: 2px solid rgba(217, 164, 65, 0.4);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 0 8px 8px 0;
  line-height: 1.7;
  font-size: 12px;
  color: #b4bfc9;
  white-space: pre-wrap;
  max-height: 220px;
  overflow-y: auto;
}

.source-body b { color: var(--moon); font-weight: 600; display: block; margin-bottom: 6px; }

.err { color: #ffb4a8; }

/* ---------- 输入区 ---------- */
.composer {
  flex-shrink: 0;
  padding: 8px 18px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  background: linear-gradient(180deg, rgba(10, 18, 30, 0.4), rgba(8, 14, 23, 0.92));
  backdrop-filter: blur(14px);
}

.suggestions {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 6px 0 10px;
  scrollbar-width: none;
}
.suggestions::-webkit-scrollbar { display: none; }
.suggestions:empty { display: none; }

.chip {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 99px;
  border: 1px solid rgba(246, 231, 198, 0.22);
  background: rgba(246, 231, 198, 0.05);
  color: #ddd3bf;
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.22s;
}
.chip:hover {
  background: rgba(217, 164, 65, 0.16);
  border-color: rgba(217, 164, 65, 0.55);
  color: var(--moon);
  transform: translateY(-1px);
}

#form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 6px 6px 6px 16px;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.045);
  transition: border-color 0.25s, box-shadow 0.25s;
}

#form:focus-within {
  border-color: rgba(217, 164, 65, 0.55);
  box-shadow: 0 0 0 3px rgba(217, 164, 65, 0.09);
}

#input {
  flex: 1;
  border: 0;
  background: none;
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  padding: 7px 0;
  resize: none;
  max-height: 120px;
  outline: none;
}
#input::placeholder { color: #68798a; }

#send {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #e5b45a, #bf8828);
  color: #2a1b04;
  cursor: pointer;
  transition: 0.2s;
}
#send:hover { transform: scale(1.06); box-shadow: 0 4px 16px rgba(217, 164, 65, 0.35); }
#send:disabled { opacity: 0.35; cursor: not-allowed; transform: none; box-shadow: none; }
#send svg { width: 18px; height: 18px; }

.fineprint {
  margin: 10px 0 0;
  text-align: center;
  font-size: 10.5px;
  color: #55646f;
  letter-spacing: 0.06em;
}

@media (max-width: 560px) {
  .thread { padding: 18px 14px 4px; gap: 15px; overflow-x: hidden; }
  .bubble-wrap { max-width: calc(100vw - 92px); }
  .bubble { font-size: 14.5px; }
  .composer { padding: 6px 14px calc(12px + env(safe-area-inset-bottom)); }
  .moon { width: 190px; height: 190px; top: -80px; right: -70px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
