/* 朵朵 —— 云朵的浅蓝，安静、不吵闹 */
:root {
  --bg: #f2f6fb;
  --bg-soft: #e7edf6;
  --card: #ffffff;
  --ink: #333b47;
  --ink-soft: #7e8a9c;
  --accent: #7d9bd4;
  --accent-soft: #dce7f6;
  --line: #dbe4f0;
  --ok: #6f9c7f;
  --radius: 14px;
  --wallpaper-veil: rgba(242, 246, 251, .76);
  font-size: 15px;
}
/* 夜间：深青的夜，月光蓝 */
[data-theme="dark"] {
  --bg: #141923;
  --bg-soft: #1b2230;
  --card: #1f2735;
  --ink: #dde3ec;
  --ink-soft: #8b96a8;
  --accent: #8fa8d9;
  --accent-soft: #2b3a54;
  --line: #2c3546;
  --ok: #7aa98a;
  --wallpaper-veil: rgba(17, 22, 32, .70);
}
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
body, input, textarea, select, .msg .bubble, .panel, .mem-card, .modal, header, #sidebar, #composer {
  transition: background-color .25s, color .25s, border-color .25s;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--ink);
}
button {
  font: inherit; color: inherit; background: none; border: none; cursor: pointer;
}
input, textarea, select {
  font: inherit; color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
::placeholder { color: var(--ink-soft); opacity: .65; }

/* ---------- 登录 ---------- */
#login-view {
  height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px;
}
#login-view h1 { font-weight: 500; letter-spacing: .35em; margin: 0; text-indent: .35em; }
#login-view p { color: var(--ink-soft); margin: 0; }
#login-form { display: flex; gap: 8px; }
#login-form input { width: 220px; text-align: center; }
.btn {
  background: var(--accent); color: #fff;
  border-radius: 10px; padding: 9px 18px;
  transition: opacity .15s;
}
.btn:hover { opacity: .88; }
.btn.ghost { background: var(--bg-soft); color: var(--ink); }
.btn.small { padding: 5px 12px; font-size: .88rem; }
.error-text { color: var(--accent); min-height: 1.2em; font-size: .9rem; }

/* ---------- 主框架 ---------- */
#app-view { height: 100%; display: none; flex-direction: column; }
header {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px; border-bottom: 1px solid var(--line);
  background: var(--card);
}
header .title { letter-spacing: .3em; text-indent: .3em; font-size: 1.02rem; white-space: nowrap; }
nav { display: flex; gap: 4px; margin-left: 8px; }
nav button {
  padding: 7px 14px; border-radius: 10px; color: var(--ink-soft);
}
nav button.active { background: var(--accent-soft); color: var(--ink); }
header .spacer { flex: 1; }
#memory-dot { width: 8px; height: 8px; border-radius: 50%; background: #ccc; }
#memory-dot.ok { background: var(--ok); }
#memory-dot.bad { background: var(--accent); }

main { flex: 1; min-height: 0; display: flex; }

/* ---------- 对话页 ---------- */
#chat-page { flex: 1; display: flex; min-height: 0; }
#sidebar {
  width: 230px; border-right: 1px solid var(--line);
  background: var(--bg-soft); display: flex; flex-direction: column;
}
#sidebar .side-head { padding: 12px; }
#conv-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.conv-item {
  padding: 9px 10px; border-radius: 10px; cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  color: var(--ink-soft); font-size: .93rem;
}
.conv-item:hover { background: var(--line); }
.conv-item.active { background: var(--card); color: var(--ink); }
.conv-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .del { visibility: hidden; color: var(--ink-soft); }
.conv-item:hover .del { visibility: visible; }

#chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
#chat-main::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background-image: var(--wallpaper, none);
  background-size: cover; background-position: center;
}
#chat-main::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: var(--wallpaper-veil);
  display: var(--veil-display, none);
}
#messages, #composer { position: relative; z-index: 1; }
#messages { flex: 1; overflow-y: auto; padding: 26px 0; }
.msg { max-width: 720px; margin: 0 auto 18px; padding: 0 24px; display: flex; }
.msg .bubble {
  padding: 12px 16px; border-radius: var(--radius);
  line-height: 1.75; white-space: pre-wrap; word-break: break-word;
  max-width: 88%;
}
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--accent-soft); }
.msg.assistant .bubble { background: var(--card); border: 1px solid var(--line); }
.msg .bubble code { background: var(--bg-soft); border-radius: 4px; padding: 1px 5px; font-size: .9em; }
.msg .bubble pre { background: var(--bg-soft); padding: 10px; border-radius: 8px; overflow-x: auto; white-space: pre; }
.tool-chip {
  max-width: 720px; margin: -8px auto 14px; padding: 0 24px;
  font-size: .85rem; color: var(--ink-soft);
}
.tool-chip .chip {
  display: inline-block; background: var(--bg-soft); border-radius: 999px;
  padding: 4px 12px; cursor: pointer;
}
.tool-chip .detail {
  display: none; margin-top: 6px; background: var(--bg-soft);
  border-radius: 10px; padding: 10px 12px; white-space: pre-wrap;
  max-height: 240px; overflow-y: auto; font-size: .85rem;
}
.tool-chip.open .detail { display: block; }
.notice { text-align: center; color: var(--ink-soft); font-size: .85rem; margin: 8px 0 14px; }

/* 每句话下面的小时间：像微信那样，安安静静的 */
.msg-time {
  max-width: 720px; margin: -14px auto 6px; padding: 0 26px;
  font-size: .72rem; color: var(--ink-soft); opacity: .6;
}
.msg-time.right { text-align: right; }
.msg-time.left { text-align: left; }

/* 节点控制条：编辑 / 重新生成 / 分枝切换 */
.node-controls {
  max-width: 720px; margin: -12px auto 14px; padding: 0 24px;
  display: flex; gap: 8px; align-items: center;
  font-size: .8rem; color: var(--ink-soft);
}
.node-controls.right { justify-content: flex-end; }
.node-controls.left { justify-content: flex-start; }
.node-controls button {
  color: var(--ink-soft); background: none; border-radius: 8px; padding: 2px 8px;
}
.node-controls button:hover { background: var(--bg-soft); color: var(--ink); }
.branchers { display: inline-flex; gap: 2px; align-items: center; }
.branchers button { font-size: 1rem; padding: 0 6px; }
.edit-area {
  display: block; width: calc(100% - 48px); max-width: 672px;
  margin: 0 auto 8px; min-height: 90px; line-height: 1.7;
}

/* 壁纸预览：小舞台，铺上纱，放一个示例气泡 */
.wp-stage { position: relative; margin-top: 8px; border-radius: 10px; overflow: hidden; }
.wp-stage img { display: block; width: 100%; max-height: 200px; object-fit: cover; }
.wp-stage .wp-veil { position: absolute; inset: 0; background: var(--wallpaper-veil); }
.wp-stage .wp-bubble {
  position: absolute; left: 12px; bottom: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; font-size: .85rem;
}

/* thinking：淡淡的一栏，想看就展开 */
.thinking-wrap { max-width: 720px; margin: 0 auto 10px; padding: 0 24px; }
.thinking-wrap .t-head {
  font-size: .82rem; color: var(--ink-soft); cursor: pointer; user-select: none;
  display: inline-flex; align-items: center; gap: 6px;
}
.thinking-wrap .t-head::before { content: '◌'; }
.thinking-wrap.open .t-head::before { content: '◉'; }
.thinking-wrap .t-body {
  display: none; margin-top: 6px;
  border-left: 2px solid var(--line);
  padding: 6px 12px; color: var(--ink-soft);
  font-size: .88rem; line-height: 1.7; white-space: pre-wrap; word-break: break-word;
}
.thinking-wrap.open .t-body { display: block; }

#composer {
  border-top: 1px solid var(--line); background: var(--card);
  padding: 12px 24px 16px;
}
#composer .inner { max-width: 720px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
#input {
  flex: 1; resize: none; max-height: 180px; line-height: 1.6;
}
#send-btn { align-self: flex-end; }
#send-btn:disabled { opacity: .5; cursor: default; }

/* ---------- 记忆页 ---------- */
#memory-page { flex: 1; overflow-y: auto; display: none; }
.mem-wrap { max-width: 860px; margin: 0 auto; padding: 24px; }
.mem-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.mem-toolbar input { flex: 1; min-width: 200px; }
.panel {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px;
}
.panel h3 { margin: 0 0 8px; font-size: .95rem; font-weight: 600; }
.panel pre {
  white-space: pre-wrap; word-break: break-word; margin: 0;
  font-family: inherit; font-size: .92rem; line-height: 1.7;
  max-height: 420px; overflow-y: auto;
}
.mem-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px;
}
.mem-card .meta { font-size: .8rem; color: var(--ink-soft); margin-bottom: 8px; display: flex; gap: 10px; flex-wrap: wrap; }
.mem-card .content { line-height: 1.75; white-space: pre-wrap; word-break: break-word; }
.mem-card .actions { margin-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.mem-card .actions button {
  font-size: .82rem; color: var(--ink-soft); background: var(--bg-soft);
  border-radius: 8px; padding: 4px 10px;
}
.mem-card .actions button:hover { color: var(--ink); }
.mem-card textarea { width: 100%; min-height: 120px; margin-top: 8px; line-height: 1.7; }
.mem-empty { color: var(--ink-soft); text-align: center; padding: 30px 0; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(60, 50, 40, .35);
  display: none; align-items: center; justify-content: center; z-index: 10;
}
.modal-mask.open { display: flex; }
.modal {
  background: var(--card); border-radius: var(--radius);
  width: min(560px, 92vw); max-height: 86vh; overflow-y: auto;
  padding: 20px 22px;
}
.modal h2 { margin: 0 0 14px; font-size: 1.05rem; font-weight: 600; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .88rem; color: var(--ink-soft); margin-bottom: 5px; }
.field select, .field input, .field textarea { width: 100%; }
.field textarea { min-height: 140px; line-height: 1.7; }
.field .hint { font-size: .8rem; color: var(--ink-soft); margin-top: 4px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

@media (max-width: 700px) {
  :root { font-size: 16px; } /* iPhone 上防止输入框聚焦时自动放大 */
  #sidebar { position: absolute; z-index: 5; height: calc(100% - 45px); top: 45px; left: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.12); }
  #sidebar.open { transform: none; }
  #menu-btn { display: inline-block !important; padding: 6px 10px; }
  header { padding: 8px 10px calc(8px); padding-top: calc(8px + env(safe-area-inset-top)); gap: 6px; }
  header .title { letter-spacing: .12em; text-indent: .12em; font-size: .95rem; }
  nav { margin-left: 0; }
  nav button { white-space: nowrap; }
  .conv-item .del { visibility: visible; } /* 手机没有"悬停"，按钮常驻 */
  #composer { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .msg { padding: 0 14px; }
  .msg .bubble { max-width: 94%; }
  .tool-chip, .thinking-wrap { padding: 0 14px; }
  .btn { padding: 10px 16px; }
  .mem-wrap { padding: 14px; }
  nav button { padding: 8px 12px; }
}
#menu-btn { display: none; }

/* 语音按钮 */
#mic-btn, #speak-btn { font-size: 1.05rem; padding: 8px 6px; align-self: flex-end; }

/* 弹窗滚动条：圆角处不再顶出尖角 */
.modal::-webkit-scrollbar { width: 8px; }
.modal::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
.modal::-webkit-scrollbar-track { background: transparent; margin: 16px 0; }
.modal { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
