/* Warm House · 一扇下着雨的窗，灯开着。
   版式：单列聊天。他的话像写在信纸上，你的话是灯下的小气泡，背后是一层很淡的雨。 */
:root {
  --bg: #ECEFF3;
  --surface: rgba(244, 246, 249, 0.84);
  --field: #FBFCFD;
  --fg: #1D2030;
  --muted: #676B7C;
  --line: rgba(29, 32, 48, 0.11);
  --accent: #BF5418;
  --on-accent: #FFFFFF;
  --mine: #F4D9C2;
  --on-mine: #3A2211;
  --note: #E1E5EC;
  --on-note: #464B5C;
  --struck: #777282;
  --moon: #F1E2C0;
  --glow: rgba(214, 120, 52, 0.13);
  --rain-ink: #2A3150;
  --scrim: rgba(18, 20, 30, 0.36);
  --shadow: rgba(18, 20, 30, 0.14);
  --ok: #2E8A56;
  --bad: #C23F38;

  --font-ui: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --font-letter: "Noto Serif SC", "Songti SC", "STSong", "Source Han Serif SC", "SimSun", serif;
  --font-note: "LXGW WenKai", "Kaiti SC", "STKaiti", "KaiTi", var(--font-letter);
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --measure: 42rem;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11131B;
    --surface: rgba(22, 25, 35, 0.86);
    --field: #1A1E2B;
    --fg: #ECE4D8;
    --muted: #8F8C9D;
    --line: rgba(236, 228, 216, 0.10);
    --accent: #EE9350;
    --on-accent: #1C1008;
    --mine: #3B2A1E;
    --on-mine: #F6E5D1;
    --note: #1B1F2C;
    --on-note: #B4AFC1;
    --struck: #9C95A5;
    --moon: #EFD9AA;
    --glow: rgba(238, 147, 80, 0.10);
    --rain-ink: #C8D2FF;
    --scrim: rgba(0, 0, 0, 0.5);
    --shadow: rgba(0, 0, 0, 0.4);
    --ok: #5BC48B;
    --bad: #F06D64;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #11131B;
  --surface: rgba(22, 25, 35, 0.86);
  --field: #1A1E2B;
  --fg: #ECE4D8;
  --muted: #8F8C9D;
  --line: rgba(236, 228, 216, 0.10);
  --accent: #EE9350;
  --on-accent: #1C1008;
  --mine: #3B2A1E;
  --on-mine: #F6E5D1;
  --note: #1B1F2C;
  --on-note: #B4AFC1;
  --struck: #9C95A5;
  --moon: #EFD9AA;
  --glow: rgba(238, 147, 80, 0.10);
  --rain-ink: #C8D2FF;
  --scrim: rgba(0, 0, 0, 0.5);
  --shadow: rgba(0, 0, 0, 0.4);
  --ok: #5BC48B;
  --bad: #F06D64;
  color-scheme: dark;
}

/* ---------- 底子 ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: radial-gradient(120% 55% at 0% 100%, var(--glow), transparent 62%), var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#rain { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }

.app {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--app-top, 0px);
  height: var(--app-h, 100%);
  display: flex;
  flex-direction: column;
  z-index: 1;
}

.bar {
  position: relative;
  z-index: 2;
  background: var(--surface);
  -webkit-backdrop-filter: saturate(1.2) blur(14px);
  backdrop-filter: saturate(1.2) blur(14px);
}

.icon-btn {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--fg);
}
.icon-btn:active { background: var(--note); }

/* ---------- 顶栏 ---------- */
.top {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) 12px 6px;
  border-bottom: 1px solid var(--line);
}
.title-wrap { min-width: 0; display: flex; justify-content: center; }
.title {
  max-width: 100%;
  min-width: 0;
  border: 0;
  background: none;
  padding: 6px 10px;
  border-radius: 10px;
  font: 600 16px/1.3 var(--font-letter);
  letter-spacing: 0.02em;
  color: var(--fg);
}
.title span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-input {
  width: 100%;
  max-width: 18rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  padding: 6px 10px;
  font: 600 16px/1.3 var(--font-letter);
  text-align: center;
  color: var(--fg);
}
.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: 999px;
  padding: 6px 11px;
  background: var(--note);
  color: var(--muted);
  font: 12.5px/1 var(--font-ui);
  white-space: nowrap;
}
.status i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status[data-mode="live"] i, .status[data-mode="claude"] i { background: var(--ok); }
.status[data-mode="demo"] i { background: var(--accent); }
.status[data-mode="offline"] i { background: var(--bad); }
.status[data-mode="offline"] { color: var(--bad); }

/* ---------- 聊天区 ---------- */
.scroller {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.thread {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 18px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.day, .notice {
  align-self: center;
  font: 12px/1.4 var(--font-ui);
  color: var(--muted);
  letter-spacing: 0.06em;
  text-align: center;
}
.notice { padding: 3px 12px; border-radius: 999px; background: var(--note); letter-spacing: 0.02em; }

/* 你的话 */
.msg.mine {
  align-self: flex-end;
  max-width: min(82%, 30rem);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.bubble {
  background: var(--mine);
  color: var(--on-mine);
  padding: 9px 14px;
  border-radius: 18px 18px 6px 18px;
  font: 15.5px/1.6 var(--font-ui);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.imgs { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.imgs img { width: 132px; height: 132px; object-fit: cover; border-radius: 14px; display: block; max-width: 100%; }
.img-missing {
  width: 132px; height: 72px; border-radius: 14px; display: grid; place-items: center;
  background: var(--note); color: var(--muted); font-size: 12.5px;
}
.msg.mine .sub { font-size: 12px; color: var(--muted); }

/* 他的话 */
.msg.him {
  align-self: stretch;
  min-width: 0;
  font-family: var(--font-letter);
  font-size: 16.5px;
  line-height: 1.85;
  color: var(--fg);
}
.parts { min-width: 0; }

.md { min-width: 0; overflow-wrap: anywhere; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 0.85em; }
.md h3, .md h4, .md h5, .md h6 { font-family: var(--font-ui); font-weight: 650; line-height: 1.4; margin: 1.1em 0 0.45em; text-wrap: balance; }
.md h3 { font-size: 18px; }
.md h4 { font-size: 16.5px; }
.md h5, .md h6 { font-size: 15px; }
.md ul, .md ol { margin: 0 0 0.85em; padding-left: 1.4em; }
.md li { margin: 0.2em 0; }
.md li.d1 { margin-left: 1.2em; }
.md li.d2 { margin-left: 2.4em; }
.md li.d3 { margin-left: 3.6em; }
.md blockquote { margin: 0 0 0.85em; padding: 1px 0 1px 12px; border-left: 2px solid var(--line); color: var(--muted); }
.md a { color: var(--accent); text-underline-offset: 2px; }
.md strong { font-weight: 650; }
.md code { font-family: var(--font-mono); font-size: 0.84em; background: var(--note); color: var(--on-note); padding: 0.1em 0.35em; border-radius: 5px; }
.md pre.code {
  margin: 0 0 0.85em;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--note);
  color: var(--on-note);
  overflow-x: auto;
  font: 13px/1.6 var(--font-mono);
}
.md pre.code code { background: none; padding: 0; font-size: inherit; color: inherit; }
.md hr {
  border: 0;
  height: 1px;
  margin: 1.1em 0;
  background: linear-gradient(90deg, transparent, var(--line) 18%, var(--line) 82%, transparent);
}
.md del {
  color: var(--struck);
  text-decoration-line: line-through;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--accent);
}
.table-wrap { overflow-x: auto; margin: 0 0 0.85em; }
.md table { border-collapse: collapse; min-width: 100%; font: 14px/1.5 var(--font-ui); }
.md th, .md td { border-bottom: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.md th { font-weight: 600; color: var(--muted); }

/* 回复开头那段代码块：心里话 */
.inner {
  margin: 0 0 0.7em;
  padding: 12px 15px 13px;
  border-radius: 4px 16px 16px 16px;
  background: var(--note);
  color: var(--on-note);
  font-family: var(--font-note);
  font-size: 15px;
  line-height: 1.8;
}
.inner-label {
  display: block;
  margin-bottom: 6px;
  font: 600 11px/1 var(--font-ui);
  letter-spacing: 0.24em;
  color: var(--accent);
}
.inner-text { white-space: pre-wrap; overflow-wrap: anywhere; }

/* 思考过程 */
.think { margin: 0 0 12px; font-family: var(--font-ui); }
.think summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px 4px 8px;
  border-radius: 999px;
  background: var(--note);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  cursor: pointer;
  user-select: none;
}
.think summary::-webkit-details-marker { display: none; }
.think summary svg { transition: transform 0.2s ease; }
.think[open] summary svg { transform: rotate(90deg); }
.think-body {
  margin-top: 8px;
  padding: 2px 0 2px 12px;
  border-left: 2px solid var(--line);
  max-height: 45vh;
  overflow-y: auto;
  color: var(--muted);
  font: 14px/1.75 var(--font-note);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* 用了工具 */
.tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  margin: 0 0 12px;
  padding: 4px 11px;
  border: 1px dashed var(--line);
  border-radius: 999px;
  color: var(--muted);
  font: 12.5px/1.5 var(--font-ui);
}
.tool em { font-style: normal; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tool .tick { color: var(--muted); }
.tool.done .tick { color: var(--ok); }
.tool.failed .tick { color: var(--bad); }

/* 每条回复底下那一行 */
.foot {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 12px;
  min-height: 24px;
  margin-top: 6px;
  color: var(--muted);
  font: 12px/1.5 var(--font-ui);
}
.foot time { font-variant-numeric: tabular-nums; }
.link-btn {
  border: 0;
  background: none;
  padding: 2px 0;
  color: var(--muted);
  font: inherit;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 3px;
}
.link-btn.strong { color: var(--accent); text-decoration-color: currentColor; }
.err { color: var(--bad); }
.dots { display: inline-flex; gap: 4px; align-items: center; }
.dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); opacity: 0.3; animation: blink 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* 空房间 */
.empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px 16px;
  text-align: center;
  pointer-events: none;
}
.empty-art { width: 176px; max-width: 60%; height: auto; margin-bottom: 14px; color: var(--muted); }
.empty-art .drops path, .empty-art .house path, .empty-art .string {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.empty-art .drops { opacity: 0.45; }
.empty-art .moon { fill: var(--moon); }
.empty-art .window { fill: var(--accent); }
.empty-art .lamp { fill: var(--accent); opacity: 0.16; }
.empty-art .spill { fill: var(--accent); opacity: 0.3; }
.empty h1 { margin: 0; font: 600 26px/1.3 var(--font-letter); letter-spacing: 0.06em; text-wrap: balance; }
.empty p { margin: 0; color: var(--muted); font: 15px/1.6 var(--font-ui); }
.empty .empty-demo { margin-top: 12px; max-width: 18rem; font-size: 13px; }

.jump {
  position: absolute;
  right: 16px;
  bottom: calc(var(--composer-h, 64px) + 12px);
  z-index: 3;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--field);
  color: var(--fg);
  box-shadow: 0 4px 14px var(--shadow);
}

/* ---------- 输入栏 ---------- */
.composer {
  padding: 8px 12px calc(env(safe-area-inset-bottom, 0px) + 8px);
  border-top: 1px solid var(--line);
}
:root.kb .composer { padding-bottom: 8px; }
.composer .row { max-width: var(--measure); margin: 0 auto; display: flex; align-items: flex-end; gap: 6px; }
.field {
  flex: 1;
  min-width: 0;
  display: flex;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--field);
}
.field:focus-within { border-color: var(--accent); }
.field textarea {
  flex: 1;
  min-width: 0;
  max-height: 140px;
  padding: 9px 14px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--fg);
  font: 16px/1.5 var(--font-ui);
}
.field textarea::placeholder { color: var(--muted); }
.send {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.send:disabled { opacity: 0.32; cursor: default; }
.send:not(:disabled):active { transform: scale(0.94); }

.tray { max-width: var(--measure); margin: 0 auto 8px; display: flex; gap: 10px; overflow-x: auto; padding: 6px 4px 2px; }
.thumb { position: relative; flex: none; }
.thumb img { width: 64px; height: 64px; object-fit: cover; border-radius: 12px; display: block; }
.thumb button {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--fg);
  color: var(--bg);
}

/* ---------- 抽屉 ---------- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 19;
  background: var(--scrim);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.28s ease, visibility 0s linear 0.28s;
}
.scrim.open { opacity: 1; visibility: visible; transition: opacity 0.28s ease; }
.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  width: min(86vw, 320px);
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 0 calc(env(safe-area-inset-bottom, 0px) + 12px);
  background: var(--field);
  border-right: 1px solid var(--line);
  transform: translateX(-102%);
  visibility: hidden;
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.28s;
}
.drawer.open { transform: none; visibility: visible; transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px 12px; }
.brand { font: 600 19px/1.2 var(--font-letter); letter-spacing: 0.03em; }
.pill-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 13px;
  background: var(--note);
  color: var(--fg);
  font: 13px/1 var(--font-ui);
}
.chat-list { list-style: none; margin: 0; padding: 4px 8px; flex: 1; overflow-y: auto; }
.chat-item { display: flex; align-items: center; gap: 2px; border-radius: 12px; }
.chat-item.active { background: var(--note); }
.chat-open {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  padding: 10px;
  text-align: left;
  color: var(--fg);
  font: 15px/1.35 var(--font-ui);
}
.chat-open span, .chat-open small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-open small { margin-top: 3px; color: var(--muted); font-size: 12px; }
.chat-del { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 10px; background: none; color: var(--muted); }
.chat-item.confirming { padding: 8px 10px; gap: 8px; flex-wrap: wrap; background: var(--note); }
.confirm-q { flex: 1 1 100%; font: 14px/1.4 var(--font-ui); }
.drawer-foot { display: flex; flex-direction: column; gap: 10px; padding: 12px 16px 0; border-top: 1px solid var(--line); }
.usage { color: var(--muted); font: 12.5px/1.6 var(--font-ui); }
.usage b { color: var(--fg); font-weight: 600; font-variant-numeric: tabular-nums; }
.usage.warn b { color: var(--accent); }
.ghost-btn { align-self: flex-start; border: 0; background: none; padding: 6px 0; color: var(--fg); font: 15px/1.3 var(--font-ui); }

/* ---------- 设置 ---------- */
.sheet {
  width: min(calc(100vw - 32px), 420px);
  max-height: 86dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--field);
  color: var(--fg);
  box-shadow: 0 20px 60px var(--shadow);
}
.sheet::backdrop { background: var(--scrim); }
.sheet form { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
.sheet h2 { margin: 0; font: 600 20px/1.3 var(--font-letter); }
.sheet h2:focus { outline: none; }
.mode-line { margin: 0; padding: 10px 12px; border-radius: 12px; background: var(--note); color: var(--muted); font: 13px/1.55 var(--font-ui); }
.field-group { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.lbl { color: var(--muted); font: 13px/1.3 var(--font-ui); }
.text {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 var(--font-ui);
}
.text::placeholder { color: var(--muted); }
.text.area { min-height: 7em; max-height: 32vh; line-height: 1.5; resize: vertical; }
.persona-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.hint { color: var(--muted); font: 12px/1.5 var(--font-ui); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 10px; font: 15px/1.4 var(--font-ui); }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.test-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.test-result { color: var(--muted); font: 13px/1.4 var(--font-ui); }
.test-result.ok { color: var(--ok); }
.test-result.bad { color: var(--bad); }
.sheet-actions { display: flex; justify-content: flex-end; gap: 10px; }
.btn {
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--note);
  color: var(--fg);
  font: 15px/1 var(--font-ui);
}
.btn.primary { border-color: transparent; background: var(--accent); color: var(--on-accent); }
.btn.small { padding: 7px 12px; font-size: 13.5px; }
.btn.danger { color: var(--bad); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--composer-h, 64px) + 20px);
  z-index: 30;
  max-width: calc(100vw - 32px);
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font: 13px/1.4 var(--font-ui);
  box-shadow: 0 6px 20px var(--shadow);
}

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