/* =========================================================
   主题：星轨
   深色 = 夜空：蓝黑底，冰蓝星光与微粒
   浅色 = 星图纸：冷白纸面，墨蓝线条
   颜色都集中在这里；--particle / --orbit / --glow 是 "r,g,b" 形式，供 Canvas 使用
   ========================================================= */
:root {
  --bg: #F2F4F8;
  --bg-elev: #FAFBFD;
  --text: #18233A;
  --muted: #66728A;
  --line: rgba(30, 52, 96, .14);
  --line-strong: rgba(30, 52, 96, .34);
  --accent: #2F5BB7;
  --accent-text: #FFFFFF;
  --frame-user: rgba(47, 91, 183, .55);
  --frame-ai: rgba(30, 52, 96, .20);
  --danger: #B42318;
  --code-bg: rgba(30, 52, 96, .06);
  --scrim: rgba(12, 20, 38, .28);
  --particle: 47, 91, 183;
  --particle-strength: .45;
  --orbit: 30, 52, 96;
  --glow: 47, 91, 183;
  --planet: #18233A;
  --font: system-ui, -apple-system, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #060912;
  --bg-elev: #0A0F1B;
  --text: #DCE5F2;
  --muted: #7F8BA3;
  --line: rgba(132, 164, 214, .16);
  --line-strong: rgba(150, 185, 240, .40);
  --accent: #8DB4FF;
  --accent-text: #06101F;
  --frame-user: rgba(141, 180, 255, .55);
  --frame-ai: rgba(132, 164, 214, .22);
  --danger: #FF8A8A;
  --code-bg: rgba(140, 170, 220, .08);
  --scrim: rgba(0, 0, 0, .55);
  --particle: 150, 185, 255;
  --particle-strength: 1;
  --orbit: 150, 185, 240;
  --glow: 94, 142, 240;
  --planet: #E8F0FF;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #060912;
    --bg-elev: #0A0F1B;
    --text: #DCE5F2;
    --muted: #7F8BA3;
    --line: rgba(132, 164, 214, .16);
    --line-strong: rgba(150, 185, 240, .40);
    --accent: #8DB4FF;
    --accent-text: #06101F;
    --frame-user: rgba(141, 180, 255, .55);
    --frame-ai: rgba(132, 164, 214, .22);
    --danger: #FF8A8A;
    --code-bg: rgba(140, 170, 220, .08);
    --scrim: rgba(0, 0, 0, .55);
    --particle: 150, 185, 255;
  --particle-strength: 1;
    --orbit: 150, 185, 240;
    --glow: 94, 142, 240;
    --planet: #E8F0FF;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.7 var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, textarea:focus-visible, input:focus-visible, a:focus-visible {
  outline: 1px solid var(--accent); outline-offset: 2px;
}
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

.primary { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 999px; padding: 10px 18px; }
.ghost { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; color: var(--muted); font-size: 14px; }
.wide { width: 100%; }
.outline { background: none; border: 1px solid var(--line-strong); border-radius: 999px; padding: 9px 18px; color: var(--text); }
.icon-btn { background: none; border: 0; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 999px; color: var(--text); }
.icon-btn:active { background: var(--line); }

/* ---------- 背景微粒 ---------- */
.particles { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }

/* ---------- 开场 ---------- */
.splash {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: grid; place-items: center; transition: opacity .5s ease;
}
.splash canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.splash-name {
  position: absolute; left: 0; right: 0; top: 68%; margin: 0; text-align: center;
  font: 400 22px/1 var(--serif); letter-spacing: .5em; text-indent: .5em; color: var(--text);
  opacity: 0; animation: name-in 1.2s ease .9s forwards;
}
.splash.leaving { opacity: 0; }
@keyframes name-in { to { opacity: .9; } }

/* ---------- 登录 ---------- */
.login { position: relative; min-height: 100%; display: grid; justify-items: center; align-items: end; padding: 24px 24px calc(14vh + env(safe-area-inset-bottom)); z-index: 1; overflow: hidden; }
.login-orbits { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .7; }
.login-box { position: relative; width: min(300px, 100%); display: flex; flex-direction: column; gap: 10px; }
.wordmark { font: 400 24px/1 var(--serif); letter-spacing: .5em; text-indent: .5em; text-align: center; margin: 0 0 18px; }
.login-box label { font-size: 13px; color: var(--muted); }
.login-box input {
  font: inherit; padding: 11px 14px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: transparent; color: var(--text);
}
.form-error { color: var(--danger); font-size: 14px; min-height: 1.4em; margin: 0; text-align: center; }

/* ---------- 布局 ---------- */
.app { position: relative; z-index: 1; height: 100dvh; display: flex; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100dvh; position: relative; }
.topbar {
  display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top) + 4px) 6px 4px;
  border-bottom: 1px solid var(--line);
}
.conv-title { flex: 1; min-width: 0; margin: 0; text-align: center; display: flex; flex-direction: column; line-height: 1.25; }
.conv-name { font: 400 17px var(--serif); letter-spacing: .3em; text-indent: .3em; }
.conv-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-sub:empty { display: none; }

.drawer {
  position: fixed; inset: 0 auto 0 0; width: min(300px, 84vw); z-index: 20;
  background: var(--bg-elev); border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top);
  transform: translateX(-100%); transition: transform .22s ease;
}
.drawer.open { transform: none; }
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 15; }
.drawer-head, .drawer-foot { padding: 12px; }
.drawer-foot { padding-bottom: calc(env(safe-area-inset-bottom) + 12px); border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; }
.conv-list { list-style: none; margin: 0; padding: 0 8px; flex: 1; overflow-y: auto; }
.conv-item { display: flex; align-items: center; border-radius: 10px; border: 1px solid transparent; }
.conv-item.active { border-color: var(--line-strong); }
.conv-open { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 10px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.conv-more { flex: none; width: 36px; height: 36px; border: 0; background: none; color: var(--muted); border-radius: 8px; }

.setting { display: flex; flex-direction: column; gap: 6px; }
.setting-label { font-size: 12px; color: var(--muted); }
.segmented { display: flex; border: 1px solid var(--line-strong); border-radius: 999px; padding: 2px; }
.segmented button { flex: 1; border: 0; background: none; border-radius: 999px; padding: 5px 0; font-size: 13px; color: var(--muted); }
.segmented button[aria-checked="true"] { background: var(--accent); color: var(--accent-text); }
.avatar-row { display: flex; gap: 8px; }
.avatar-pick { flex: 1; display: flex; align-items: center; gap: 8px; background: none; border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px 4px 4px; font-size: 14px; }

@media (min-width: 900px) {
  .drawer { position: static; transform: none; transition: none; }
  .scrim { display: none !important; }
  #menu { visibility: hidden; }
}

/* ---------- 头像 ---------- */
.avatar {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--line-strong); background: var(--bg) center / cover no-repeat;
  display: grid; place-items: center; color: var(--accent); overflow: hidden;
}
.avatar svg { width: 22px; height: 22px; stroke-width: 1; }
.avatar .initial { font: 400 13px var(--serif); color: var(--muted); }

/* ---------- 状态条 ---------- */
.status { font-size: 12px; color: var(--muted); text-align: center; padding: 3px 12px; letter-spacing: .05em; }
.status.error { color: var(--danger); }

/* ---------- 消息 ---------- */
.scroller { flex: 1; overflow-y: auto; overscroll-behavior: contain; overflow-anchor: auto; }
.messages { max-width: 760px; margin: 0 auto; padding: 18px 14px 10px; display: flex; flex-direction: column; gap: 20px; }
.empty { text-align: center; color: var(--muted); padding: 32vh 20px 0; font: 400 15px/1.8 var(--serif); letter-spacing: .1em; }

.msg { display: flex; gap: 10px; align-items: flex-start; max-width: 100%; }
.msg.user { flex-direction: row-reverse; }
.msg.user .msg-avatar:not(.has-image) { display: none; }
.msg-body { min-width: 0; display: flex; flex-direction: column; max-width: calc(100% - 40px); }
.msg.user .msg-body { align-items: flex-end; max-width: 86%; }
.bubble {
  border: 1px solid var(--frame-ai); border-radius: 2px 14px 14px 14px;
  padding: 9px 14px; overflow-wrap: anywhere; min-height: 2.4em;
}
.msg.user .bubble {
  border-color: var(--frame-user); border-radius: 14px 2px 14px 14px;
  white-space: pre-wrap;
}
.msg.user .bubble:empty, .msg.user .bubble[hidden] { display: none; }
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble p, .bubble ul, .bubble ol, .bubble blockquote { margin: 0 0 .7em; }
.bubble ul, .bubble ol { padding-left: 1.3em; }
.bubble blockquote { border-left: 1px solid var(--line-strong); padding-left: 12px; color: var(--muted); }
.bubble a { color: var(--accent); text-underline-offset: 3px; }
.bubble h3, .bubble h4, .bubble h5, .bubble h6 { font-size: 1em; font-weight: 600; margin: 1em 0 .4em; }
.bubble code { font-family: var(--mono); font-size: .86em; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
.bubble hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.code { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 .7em; overflow: hidden; }
.code-bar { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); padding: 3px 6px 0 12px; }
.code-bar button { background: none; border: 0; color: var(--muted); padding: 4px 8px; font-size: 12px; }
.code pre { margin: 0; padding: 6px 12px 12px; overflow-x: auto; }
.code pre code { background: none; padding: 0; font-size: 13px; line-height: 1.55; }

.cursor::after { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; vertical-align: middle; background: var(--accent); margin-left: 6px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .2; } }
@media (prefers-reduced-motion: reduce) { .cursor::after { animation: none; } .drawer { transition: none; } .splash-name { animation: none; opacity: .9; } }

.msg-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.msg-meta.error { color: var(--danger); }
.msg-actions { display: flex; gap: 2px; margin-top: 2px; }
.msg-actions button { background: none; border: 0; color: var(--muted); font-size: 12.5px; padding: 5px 8px; border-radius: 8px; }
.msg-actions button:active { background: var(--line); }

.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.msg.user .attachments { justify-content: flex-end; }
.attachments img { max-width: 180px; max-height: 180px; border-radius: 10px; border: 1px solid var(--line); display: block; object-fit: cover; }
.file-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 5px 10px; border: 1px solid var(--line-strong); border-radius: 999px; color: var(--text); text-decoration: none; max-width: 220px; }
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.edit-box { width: min(560px, 78vw); display: flex; flex-direction: column; gap: 8px; }
.edit-box textarea { font: inherit; width: 100%; min-height: 90px; padding: 10px; border-radius: 10px; border: 1px solid var(--accent); background: transparent; color: var(--text); resize: vertical; }
.edit-box .row { display: flex; justify-content: flex-end; gap: 8px; }

.jump {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom));
  background: var(--bg-elev); border: 1px solid var(--line-strong); color: var(--text);
  border-radius: 999px; padding: 5px 14px; font-size: 13px;
}

/* ---------- 输入区 ---------- */
.composer { padding: 8px 8px calc(env(safe-area-inset-bottom) + 10px); }
.composer-row { max-width: 760px; margin: 0 auto; display: flex; align-items: flex-end; gap: 6px; }
#input {
  flex: 1; font: inherit; resize: none; max-height: 40dvh; min-height: 44px;
  padding: 10px 16px; border-radius: 22px; border: 1px solid var(--line-strong);
  background: color-mix(in srgb, var(--bg) 80%, transparent); color: var(--text); line-height: 1.5;
}
#input::placeholder { color: var(--muted); }
.send-btn { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; }
.send-btn:disabled { opacity: .4; cursor: default; }
.pending-files { max-width: 760px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 6px; }
.pending-files:not(:empty) { padding-bottom: 8px; }
.pending-files .file-chip button { border: 0; background: none; color: var(--muted); padding: 0 2px; }
.usage { font-size: 12px; color: var(--muted); white-space: pre-line; margin: 0; line-height: 1.6; }
