:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efebe4;
  --text: #2b2926;
  --muted: #77726a;
  --line: #e2ddd4;
  --accent: #3e6f6a;
  --accent-soft: #e3ece9;
  --user-bubble: #3e6f6a;
  --user-text: #ffffff;
  --on-accent: #ffffff;
  --safety-bg: #f3efe3;
  --safety-line: #d9cfb5;
  --radius: 14px;
  --sidebar-w: 280px;
  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1b19;
    --surface: #262422;
    --surface-2: #2f2d2a;
    --text: #ebe7e0;
    --muted: #a39d93;
    --line: #3a3733;
    --accent: #7fb3ab;
    --accent-soft: #2c3a37;
    --user-bubble: #3e6f6a;
    --user-text: #f6f3ee;
    --on-accent: #10201e;
    --safety-bg: #2d2a22;
    --safety-line: #4a4436;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* ---------- 侧栏 ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 14px 10px calc(10px + env(safe-area-inset-bottom));
}
.sidebar-head { display: flex; gap: 8px; align-items: center; }
.btn-new {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 9px 12px;
  text-align: left;
}
.btn-new:hover { border-color: var(--accent); }
.history { flex: 1; overflow-y: auto; margin: 12px 0; }
.history-empty { color: var(--muted); font-size: 14px; padding: 8px; }
.conv {
  position: relative;
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 9px 34px 9px 10px;
  margin-bottom: 2px;
}
.conv:hover { background: var(--surface); }
.conv.active { background: var(--surface); box-shadow: inset 3px 0 0 var(--accent); }
.conv-title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-last { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 12px; color: var(--muted); }
.conv-del {
  position: absolute; right: 6px; top: 8px;
  border: 0; background: transparent; color: var(--muted);
  width: 26px; height: 26px; border-radius: 6px; opacity: 0;
}
.conv:hover .conv-del, .conv:focus-within .conv-del { opacity: 1; }
.conv-del:hover { background: var(--surface-2); color: var(--text); }
.sidebar-foot { display: flex; justify-content: space-between; border-top: 1px solid var(--line); padding-top: 8px; }
.link-btn { border: 0; background: transparent; color: var(--muted); font-size: 13px; padding: 6px; border-radius: 6px; }
.link-btn:hover { color: var(--text); background: var(--surface); }
.scrim { display: none; }

/* ---------- 主区域 ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.brand { border: 0; background: transparent; font-weight: 600; font-size: 16px; padding: 4px 2px; }
.icon-btn {
  border: 0; background: transparent; width: 36px; height: 36px; border-radius: 8px; font-size: 18px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); }
#btnNewTop { margin-left: auto; }
.mode-pill {
  font-size: 12px; color: var(--accent); background: var(--accent-soft);
  padding: 2px 10px; border-radius: 999px; white-space: nowrap;
  transition: opacity .3s;
}
.mode-pill.safety { color: var(--text); background: var(--safety-bg); border: 1px solid var(--safety-line); }
.banner { background: var(--surface-2); color: var(--muted); font-size: 14px; padding: 8px 16px; border-bottom: 1px solid var(--line); }

.view { flex: 1; overflow-y: auto; }

/* 首页母版 */
.home {
  background:
    radial-gradient(ellipse 70% 40% at 50% 0%, var(--accent-soft), transparent 70%),
    var(--bg);
}
.home-inner { max-width: 720px; margin: 0 auto; padding: 48px 20px 32px; text-align: center; }
.hero-mark { width: 44px; height: 44px; color: var(--accent); margin-bottom: 14px; }
.home h1 { font-size: 40px; line-height: 1.2; margin: 0; font-weight: 600; letter-spacing: 3px; }
.hero-identity {
  display: inline-block; margin: 12px 0 0; padding: 2px 12px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: 13px; letter-spacing: 2px;
}
.hero-slogan { margin: 18px 0 0; font-size: 20px; font-weight: 500; letter-spacing: 1px; }
.hero-intro { margin: 18px 0 0; font-size: 16px; line-height: 1.8; }
.hero-body {
  /* 宋体/楷体类字体，比正文黑体更柔和、有书卷气。按顺序使用电脑上已安装的第一个 */
  font-family: "Source Han Serif SC", "Noto Serif SC", "Noto Serif CJK SC", "思源宋体",
    "STZhongsong", "华文中宋", "Songti SC", "STKaiti", "华文楷体", "KaiTi", "楷体", serif;
  color: var(--text); opacity: .78;
  font-size: 17px; line-height: 2.1; letter-spacing: 1px;
  max-width: 30em; margin: 40px auto 0; /* 与上方标题之间多空出一行 */
  text-wrap: balance; /* 各行长度均匀，避免最后一行只剩几个字 */
}

/* 开始卡片：首页的主要入口 */
.start-card {
  margin: 36px auto 0; max-width: 600px; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  padding: 22px 22px 16px; box-shadow: 0 6px 24px rgba(40, 60, 55, .06);
}
.start-card:focus-within { border-color: var(--accent); }
.start-title { margin: 0; color: var(--accent); font-size: 13px; letter-spacing: 2px; }
.start-question { display: block; margin: 6px 0 12px; font-size: 19px; font-weight: 500; }
.start-card textarea {
  width: 100%; min-height: 84px; max-height: 240px; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
}
.start-card textarea:focus { border-color: var(--accent); }
.start-foot { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.start-reassure { flex: 1; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.start-reassure span + span::before { content: ' '; }

.choices { margin-top: 32px; }
.section-label {
  display: flex; align-items: center; gap: 14px;
  color: var(--muted); font-size: 13px; letter-spacing: 1px; margin: 0 auto 14px; max-width: 600px;
}
.section-label::before, .section-label::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.entries { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 600px; margin: 0 auto; }
.entry {
  display: flex; align-items: center; gap: 10px; text-align: left;
  border: 1px solid var(--line); background: var(--surface); border-radius: 14px;
  padding: 12px 14px; font-size: 15px; line-height: 1.4;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.entry:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(40, 60, 55, .08); }
.entry:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.entry-icon { font-size: 18px; line-height: 1; flex-shrink: 0; font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif; }

.closing { margin: 40px 0 0; font-size: 16px; letter-spacing: 2px; }
.closing::before {
  content: ''; display: block; width: 28px; height: 2px; background: var(--accent);
  margin: 0 auto 12px; border-radius: 2px; opacity: .7;
}
.home-footnote { margin: 28px 0 0; font-size: 12px; color: var(--muted); }

/* 对话 */
.messages { max-width: 760px; margin: 0 auto; padding: 24px 20px 12px; }
.msg { margin-bottom: 18px; display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: var(--radius); white-space: normal; word-wrap: break-word; }
.msg.user .bubble { background: var(--user-bubble); color: var(--user-text); border-bottom-right-radius: 4px; }
.msg.ai .bubble { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble p { margin: 0 0 .6em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: .2em 0 .6em; padding-left: 1.4em; }
.msg-mode { font-size: 12px; color: var(--muted); margin: 0 0 4px 4px; }
.msg-error { color: var(--muted); font-size: 14px; }
.retry { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 2px 10px; font-size: 13px; margin-left: 6px; }
.typing::after { content: '▍'; animation: blink 1s steps(1) infinite; color: var(--muted); }
@keyframes blink { 50% { opacity: 0; } }

/* 安全求助条：平静，不用警告色 */
.safety-bar {
  max-width: 760px; width: calc(100% - 40px); margin: 0 auto 8px;
  background: var(--safety-bg); border: 1px solid var(--safety-line); border-radius: 12px;
  padding: 10px 14px; font-size: 14px; display: flex; gap: 12px; align-items: center;
}
.safety-bar p { margin: 0; flex: 1; }
.safety-actions { flex-shrink: 0; }

/* 输入区 */
.composer {
  max-width: 760px; width: 100%; margin: 0 auto;
  padding: 6px 20px calc(10px + env(safe-area-inset-bottom));
}
.beian { margin: 6px 0 0; text-align: center; font-size: 12px; line-height: 1.4; }
.beian a { color: var(--muted); text-decoration: none; }
.beian a:hover { text-decoration: underline; }
.input-row {
  display: flex; gap: 8px; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 8px 8px 8px 14px;
}
.input-row:focus-within { border-color: var(--accent); }
textarea {
  flex: 1; border: 0; outline: 0; resize: none; background: transparent; color: var(--text);
  font: inherit; font-size: 16px; line-height: 1.6; max-height: 180px; padding: 4px 0;
}
.btn-send {
  border: 0; background: var(--accent); color: var(--on-accent); border-radius: 10px; padding: 7px 16px; flex-shrink: 0;
}
.btn-send:disabled { opacity: .45; cursor: default; }
.footnote { font-size: 12px; color: var(--muted); text-align: center; margin: 6px 0 0; }

/* 引导弹窗 */
.modal {
  position: fixed; inset: 0; background: rgba(20, 18, 15, .45);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50;
}
.modal-card {
  background: var(--surface); border-radius: 18px; max-width: 520px; width: 100%;
  padding: 28px 26px; max-height: 90vh; overflow-y: auto;
}
.modal-card h2 { margin: 0 0 12px; font-size: 22px; font-weight: 600; }
.modal-card p { margin: 0 0 10px; }
.modal-card ul { padding-left: 1.2em; margin: 6px 0 12px; }
.modal-card .welcome-first { font-size: 20px; font-weight: 600; margin-bottom: 12px; }
.modal-card ul.promise { list-style: none; padding: 12px 16px; margin: 16px 0; background: var(--surface-2); border-radius: 12px; }
.modal-card ul.promise li + li { margin-top: 4px; }
.muted { color: var(--muted); font-size: 14px; }
.btn-primary { margin-top: 10px; width: 100%; border: 0; background: var(--accent); color: var(--on-accent); border-radius: 12px; padding: 12px; font-size: 16px; }

.code-card { max-width: 380px; }
.code-card input {
  width: 100%; margin: 8px 0 4px; padding: 11px 12px; font: inherit; font-size: 16px;
  color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; outline: 0;
}
.code-card input:focus { border-color: var(--accent); }
.code-error { color: #a4553f; font-size: 14px; margin: 4px 0 0; }

.only-mobile { display: none; }

/* ---------- 手机 ---------- */
@media (max-width: 760px) {
  .only-mobile { display: inline-flex; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 40; width: min(84vw, 320px);
    padding-top: calc(14px + env(safe-area-inset-top));
    transform: translateX(-100%); transition: transform .2s ease;
  }
  .sidebar.open { transform: none; box-shadow: 0 0 30px rgba(0,0,0,.2); }
  .scrim.open { display: block; position: fixed; inset: 0; background: rgba(20,18,15,.35); z-index: 30; }
  .conv-del { opacity: 1; }
  .topbar { padding-left: 8px; padding-right: 8px; gap: 4px; }
  .mode-pill { margin-left: 4px; }
  .home-inner { padding: 28px 16px 24px; }
  .hero-mark { width: 34px; height: 34px; margin-bottom: 8px; }
  .home h1 { font-size: 32px; letter-spacing: 2px; }
  .hero-slogan { font-size: 17px; margin-top: 14px; }
  .hero-intro { font-size: 15px; margin-top: 14px; }
  .hero-body { font-size: 15.5px; letter-spacing: .5px; margin-top: 30px; }
  .start-card { margin-top: 26px; padding: 18px 16px 14px; border-radius: 18px; }
  .start-question { font-size: 17px; }
  .choices { margin-top: 26px; }
  .entries { grid-template-columns: 1fr 1fr; gap: 8px; }
  .entry { padding: 12px; font-size: 14px; }
  .closing { margin-top: 30px; font-size: 15px; }
  .messages { padding: 16px 16px 8px; }
  .bubble { max-width: 90%; }
  .composer { padding-left: 12px; padding-right: 12px; }
  .safety-bar { width: calc(100% - 24px); flex-direction: column; align-items: flex-start; gap: 4px; }
}
