/* 树洞 · 样式
   知识内容派生自 MIT 许可开源项目「狗头军师 / Goutoujunshi」（原作者 powerycy） */

:root {
  color-scheme: light;
  --bg: #f6f4ee;
  --bg-2: #efece3;
  --surface: #ffffff;
  --ink: #2f3430;
  --ink-soft: #5d6560;
  --muted: #949b95;
  --line: #e6e2d8;
  --line-2: #d8d3c5;
  --moss: #6f8f7a;
  --moss-deep: #4f6f5c;
  --moss-soft: #e7efe8;
  --amber: #c98a2e;
  --amber-soft: #fbf1dd;
  --danger: #c4453c;
  --danger-soft: #fbe9e7;
  --radius: 20px;
  --radius-sm: 14px;
  --shadow: 0 2px 6px rgba(60, 70, 60, 0.05), 0 12px 34px rgba(60, 70, 60, 0.07);
  --shadow-soft: 0 1px 3px rgba(60, 70, 60, 0.05), 0 6px 18px rgba(60, 70, 60, 0.05);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1100px 620px at 12% -8%, #eef3ec 0%, rgba(238, 243, 236, 0) 62%),
    radial-gradient(900px 520px at 96% 6%, #f6efe0 0%, rgba(246, 239, 224, 0) 58%),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 15.5px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input, textarea { font: inherit; color: inherit; }

/* ---------------- 顶栏 ---------------- */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: rgba(246, 244, 238, 0.86);
  backdrop-filter: saturate(1.2) blur(10px);
  z-index: 5;
}
.tb-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 14px;
  transition: background 0.16s, border-color 0.16s, color 0.16s;
}
.tb-btn:hover { background: var(--surface); border-color: var(--line); color: var(--ink); }
.tb-btn.primary { background: var(--moss); border-color: var(--moss); color: #fff; font-weight: 600; }
.tb-title { font-weight: 650; letter-spacing: 0.06em; color: var(--ink); }
.tb-logo {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #a9c3b0, var(--moss-deep));
  box-shadow: inset 0 -3px 6px rgba(0,0,0,0.16);
}
.tb-right { display: flex; gap: 6px; }

/* ---------------- 对话区 ---------------- */

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.thread {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 22px 16px 8px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.thread-inner { max-width: 660px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }

.msg { display: flex; gap: 10px; align-items: flex-end; animation: pop 0.34s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(0.985); } to { opacity: 1; transform: none; } }

.msg .who {
  flex: 0 0 30px;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #a9c3b0, var(--moss-deep));
  box-shadow: inset 0 -3px 6px rgba(0,0,0,0.16);
  margin-bottom: 2px;
}

.bubble {
  max-width: min(78%, 520px);
  padding: 12px 16px;
  border-radius: 18px 18px 18px 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble.long { line-height: 1.85; }
.bubble em { font-style: normal; color: var(--moss-deep); font-weight: 600; }
.bubble strong { font-weight: 700; }
.bubble .k { color: var(--moss-deep); font-weight: 600; }

.msg.me { flex-direction: row-reverse; }
.msg.me .bubble {
  background: var(--moss-soft);
  border-color: #d3e2d7;
  border-radius: 18px 18px 6px 18px;
  color: #2b3a31;
}

.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: 0.18s; }
.typing i:nth-child(3) { animation-delay: 0.36s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.28; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* 卡片：事实 vs 解释 */
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}
.split > div {
  background: #fbfaf6;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13.6px;
  line-height: 1.7;
}
.split h6 { margin: 0 0 6px; font-size: 12px; letter-spacing: 0.5px; color: var(--muted); font-weight: 700; }
.split .fact h6 { color: var(--moss-deep); }
.split .story h6 { color: var(--amber); }

/* 计划卡 */
.plan { background: #fbfaf6; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px 16px; margin-top: 10px; }
.plan .row { padding: 9px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.plan .row:last-child { border-bottom: 0; }
.plan .row b { display: block; font-size: 12.5px; color: var(--muted); font-weight: 700; letter-spacing: 0.4px; margin-bottom: 3px; }
.plan .row.todo b { color: var(--moss-deep); }
.plan .row.watch b { color: var(--amber); }
.plan .row.stop b { color: var(--danger); }

/* 知识卡 */
.kcard {
  display: flex; flex-direction: column; gap: 8px;
  background: linear-gradient(180deg, #fbfaf6, #f7f5ef);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  margin-top: 10px;
}
.kcard .kt { font-size: 13.5px; font-weight: 650; color: var(--moss-deep); }
.kcard .kd { font-size: 13.4px; color: var(--ink-soft); }

/* ---------------- 底部操作条 ---------------- */

.dock {
  flex: 0 0 auto;
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(246,244,238,0) 0%, var(--bg) 34%);
}
.dock-inner { max-width: 660px; margin: 0 auto; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 15px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 14.2px;
  box-shadow: var(--shadow-soft);
  transition: transform 0.12s, border-color 0.16s, background 0.16s;
}
.chip:hover { border-color: var(--moss); background: #fbfdfb; }
.chip:active { transform: scale(0.97); }
.chip.ghost { background: transparent; box-shadow: none; border-style: dashed; color: var(--ink-soft); }
.chip.quick { font-size: 13.6px; padding: 7px 13px; }

.composer { display: flex; gap: 9px; align-items: flex-end; }
.composer textarea {
  flex: 1 1 auto;
  min-height: 50px;
  max-height: 34vh;
  padding: 13px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line-2);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  outline: none;
  resize: none;
  line-height: 1.7;
}
.composer textarea:focus { border-color: var(--moss); box-shadow: 0 0 0 3px rgba(111,143,122,0.16); }
.send {
  flex: 0 0 auto;
  width: 50px; height: 50px;
  border-radius: 50%;
  border: 0;
  background: var(--moss);
  color: #fff;
  font-size: 19px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(79, 111, 92, 0.3);
  transition: transform 0.12s, background 0.16s;
}
.send:active { transform: scale(0.94); }
.send:disabled { background: var(--line-2); box-shadow: none; cursor: default; }

.hint-line { font-size: 12.6px; color: var(--muted); margin-top: 9px; line-height: 1.6; }

/* ---------------- 抽屉 ---------------- */

.sheet-mask {
  position: fixed; inset: 0; background: rgba(47, 52, 48, 0.34);
  opacity: 0; pointer-events: none; transition: opacity 0.24s; z-index: 20;
}
.sheet-mask.on { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; z-index: 21;
  top: 0; right: 0; height: 100%;
  width: min(560px, 94vw);
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: -16px 0 44px rgba(47, 52, 48, 0.16);
  transform: translateX(102%);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex; flex-direction: column;
}
.sheet.on { transform: none; }
.sheet-head {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 20px; border-bottom: 1px solid var(--line); font-weight: 650;
}
.sheet-body { flex: 1 1 auto; overflow-y: auto; padding: 18px 22px 60px; }

.rec { padding: 13px 0; border-bottom: 1px dashed var(--line); }
.rec:last-child { border-bottom: 0; }
.rec .when { font-size: 12.4px; color: var(--muted); }
.rec .txt { margin-top: 5px; white-space: pre-wrap; word-break: break-word; }
.rec .tagline { display: inline-block; margin: 6px 6px 0 0; font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--moss-soft); color: var(--moss-deep); }
.empty { color: var(--muted); font-size: 13.6px; line-height: 1.8; }

.spark { width: 100%; height: 88px; display: block; }
.sec-title { font-size: 13px; font-weight: 700; letter-spacing: 0.5px; color: var(--ink-soft); margin: 22px 0 8px; }
.sec-title:first-child { margin-top: 0; }

/* ---------------- 急救浮层 ---------------- */

.calm {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(246, 244, 238, 0.97);
  backdrop-filter: blur(6px);
  display: none; place-items: center;
}
.calm.on { display: grid; }
.calm-box { position: relative; width: min(420px, 92vw); text-align: center; padding: 26px 20px; }
.calm-close { position: absolute; top: 0; right: 6px; border: 0; background: transparent; font-size: 17px; color: var(--muted); cursor: pointer; }
.calm-stage { position: relative; width: 200px; height: 200px; margin: 6px auto 4px; display: grid; place-items: center; }
.calm-ring { position: absolute; inset: 0; border-radius: 50%; border: 1.5px dashed var(--line-2); }
.calm-ball {
  width: 92px; height: 92px; border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #b6cdbc, var(--moss-deep));
  box-shadow: 0 12px 30px rgba(79, 111, 92, 0.28);
  transition: transform 4s cubic-bezier(0.4, 0, 0.2, 1);
  transform: scale(0.7);
}
.calm-label {
  position: absolute; bottom: 4px; font-size: 15px; font-weight: 650; color: var(--moss-deep);
  background: rgba(255,255,255,0.9); padding: 3px 13px; border-radius: 999px;
}
.calm-count { font-size: 13px; color: var(--muted); margin-bottom: 16px; }
.calm-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.calm-extra { margin-top: 20px; text-align: left; }
.ground-list { display: flex; flex-direction: column; gap: 10px; }
.ground-list label { display: block; font-size: 13.4px; color: var(--ink-soft); }
.ground-list input {
  width: 100%; margin-top: 5px; padding: 9px 13px; border-radius: 12px;
  border: 1px solid var(--line-2); background: var(--surface); outline: none;
}
.ground-list input:focus { border-color: var(--moss); }

/* ---------------- 通用 ---------------- */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 10px 18px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--surface);
  cursor: pointer; font-size: 14px; transition: all 0.16s;
}
.btn:hover { border-color: var(--moss); color: var(--moss-deep); }
.btn.primary { background: var(--moss); border-color: var(--moss); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--moss-deep); border-color: var(--moss-deep); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn.small { padding: 6px 13px; font-size: 13px; }

.note {
  border-radius: var(--radius-sm); padding: 12px 15px; font-size: 13.6px; line-height: 1.75;
  border: 1px solid var(--line); background: #fbfaf6; margin-bottom: 12px;
}
.note.danger { background: var(--danger-soft); border-color: #f3d3d0; color: #93322c; }
.note.warn { background: var(--amber-soft); border-color: #f0dcb8; color: #855a16; }

.hotline { display: flex; gap: 12px; align-items: baseline; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.hotline:last-child { border-bottom: 0; }
.hotline .num { flex: 0 0 108px; font-weight: 700; color: var(--danger); letter-spacing: 0.5px; }
.hotline .desc { flex: 1; font-size: 13.4px; color: var(--ink-soft); }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 18px);
  background: rgba(47,52,48,0.94); color: #fff; padding: 10px 20px; border-radius: 999px;
  font-size: 13.5px; opacity: 0; pointer-events: none; transition: all 0.24s; z-index: 60;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 560px) {
  body { font-size: 15.5px; }
  .thread { padding: 16px 12px 6px; }
  .dock { padding: 8px 12px calc(12px + env(safe-area-inset-bottom)); }
  .bubble { max-width: 84%; }
  .split { grid-template-columns: 1fr; }
  .tb-btn span.tb-title { display: inline; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
