/* ── 沙龙 · 样式 ─────────────────────────────────────────────────────────
   设计语言：纸感暖中性底 + 赤陶一点信号色。明亮、安静、留白多。
   尺寸系统取自 design-lab/SPEC.md：12/13/15/17/20/25/31 字号，
   间距 4/8/12/16/20/24/32/48，圆角 6/10/14，所有可点元素 ≥44px。
   禁止：emoji、渐变、彩色阴影、玻璃拟态、装饰花纹、居中一切。        */

:root {
  --bg: #FAF9F7;
  --surface: #FFFFFF;
  --surface-2: #F4F1EC;
  --border: #E7E3DC;
  --border-strong: #D8D2C8;
  --ink: #1C1917;
  --ink-2: #57534E;
  --ink-3: #8A8378;
  --accent: #BC5230;
  --accent-soft: #FBEDE7;
  --accent-ink: #FFFFFF;
  --danger: #B42318;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-pill: 999px;

  --sans: "Noto Sans SC", "Noto Sans CJK SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --serif: "Noto Serif SC", "Noto Serif CJK SC", "Songti SC", "Source Han Serif SC", Georgia, serif;

  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px -16px rgba(0, 0, 0, .12);
  --bar-h: 56px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.75;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  -webkit-font-smoothing: antialiased;
}

body[data-view="thread"] { overflow: hidden; }

button, input, textarea { font-family: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── 通用按钮 ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--ink-2);
  font-size: 15px;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}

.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:disabled:hover { background: transparent; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 500;
}
.btn-primary:hover { background: #A84628; border-color: #A84628; }

.btn-ghost { color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); }

.btn-tiny {
  min-height: 44px;
  padding: 0 10px;
  font-size: 13px;
  color: var(--ink-3);
  gap: 4px;
}
.btn-tiny:hover { color: var(--ink); background: var(--surface-2); }

/* ── 视图 ──────────────────────────────────────────────────────────── */
.view { min-height: 100vh; min-height: 100dvh; }
.view[hidden] { display: none !important; }

.app-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--bar-h);
  /* 桌面端把顶栏内容对齐到正文列（640px），移动端退回 12px 页边 */
  padding-left: max(12px, calc((100vw - 640px) / 2));
  padding-right: max(8px, calc((100vw - 640px) / 2));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.brand-mark { color: var(--accent); display: inline-flex; }
.brand-name {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: .04em;
}

.btn-exit { font-size: 13px; color: var(--ink-3); }

.bar-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 4px 20px 48px;
}

/* ── 首页四块 ──────────────────────────────────────────────────────── */
.block {
  padding: 24px 0;
  border-top: 1px solid var(--border);
}
.block:first-of-type { border-top: 0; padding-top: 20px; }
.block-last { padding-bottom: 32px; }

.label {
  margin: 0 0 12px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: .08em;
  color: var(--ink-3);
}

.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.block-head .label { margin-bottom: 0; }
.block-tools { display: flex; align-items: center; gap: 2px; }

/* 5.1 他在 */
.here-line {
  margin: 0;
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.7;
  color: var(--ink);
  letter-spacing: .01em;
}

/* 5.2 Inspiration */
.card-list { display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card-title {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: .01em;
}

.card-hook { margin: 0; color: var(--ink-2); font-size: 15px; line-height: 1.75; }

.card-go {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 44px;
  margin-top: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.card-go:hover { text-decoration: underline; text-underline-offset: 3px; }

.card-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
  color: var(--ink-3);
  font-size: 12px;
  line-height: 1.5;
}

.card-quiet { box-shadow: none; border-style: dashed; background: transparent; }

.archive { margin-top: 16px; padding-top: 12px; border-top: 1px dashed var(--border-strong); }
.archive-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.archive-title { font-size: 12px; letter-spacing: .1em; color: var(--ink-3); }
.card-list-quiet .card-title { font-size: 15px; }

/* 5.3 开口 */
.composer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 12px 12px 10px;
  box-shadow: var(--shadow);
}
.composer textarea {
  display: block;
  width: 100%;
  min-height: 48px;
  max-height: 40vh;
  padding: 2px 2px 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.7;
  resize: none;
  outline: none;
}
.composer textarea::placeholder { color: var(--ink-3); }
.composer-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.composer-hint { font-size: 12px; color: var(--ink-3); }
.btn-send { font-size: 14px; padding: 0 14px; }

/* 5.4 最近聊过 */
.thread-list { list-style: none; margin: 0; padding: 0; }

/* 空态 / 加载态：不留白，用一句人话占住这个位置 */
.row-note {
  margin: 0;
  padding: 14px 0;
  color: var(--ink-3);
  font-size: 14px;
  line-height: 1.7;
}
.card-list[data-busy] { opacity: .5; transition: opacity .15s ease; }
.thread-list li + li { border-top: 1px solid var(--border); }

.thread-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 12px 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.thread-row:hover .thread-name { color: var(--accent); }

.thread-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.thread-name {
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.45;
  color: var(--ink);
}
.thread-line {
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thread-when { flex-shrink: 0; font-size: 12px; color: var(--ink-3); }
.thread-arrow { flex-shrink: 0; display: inline-flex; color: var(--border-strong); }

/* ── 对话视图 ──────────────────────────────────────────────────────── */
/* 贴住「可视视口」：--app-h / --app-top 由 app.js 用 visualViewport 写进来。
   键盘弹出时可视高度变小，这个盒子跟着变矮，dock 输入条就自然抬到键盘上方，
   不会被盖住；不支持 visualViewport 的老浏览器退回 100dvh。 */
.view-thread {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--app-top, 0px);
  height: var(--app-h, 100dvh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}
.view-thread[hidden] { display: none !important; }
.view-thread .app-bar { flex-shrink: 0; }
.btn-back { padding: 0 10px; font-size: 14px; color: var(--ink-2); }

.thread-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 20px 8px;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

.msg { display: flex; min-width: 0; max-width: 100%; }
.msg-me { justify-content: flex-end; }
.msg-body {
  max-width: 86%;
  font-size: 15px;
  line-height: 1.75;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg-me .msg-body {
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink);
}
.msg-him .msg-body { font-family: var(--serif); font-size: 16px; color: var(--ink); }
.msg-thinking .msg-body { color: var(--ink-3); }

/* 流式到达时的光标：让「还在写」有个落点 */
.msg-streaming .msg-body::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 2px;
  vertical-align: -0.15em;
  background: var(--accent);
  animation: caret 1s steps(2, start) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

/* 失败提示：系统提示样式，不是他的气泡；右边挂「重试」 */
.msg-sys { justify-content: flex-start; }
.note {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 10px 10px 10px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.6;
}
.note-icon { display: inline-flex; color: var(--accent); flex-shrink: 0; }
.note-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.note-retry { flex-shrink: 0; color: var(--accent); font-size: 13px; }

.dots { display: inline-flex; gap: 4px; align-items: center; height: 22px; }
.dots i {
  width: 5px; height: 5px; border-radius: var(--r-pill);
  background: var(--ink-3); opacity: .35;
  animation: dot 1.1s ease-in-out infinite;
}
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 60%, 100% { opacity: .25; } 30% { opacity: .8; } }

.composer-dock {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: auto;
  max-width: 640px;
  margin: 8px 20px calc(12px + env(safe-area-inset-bottom));
  padding: 8px 8px 8px 12px;
}
.composer-dock textarea { min-height: 44px; padding: 10px 0; }

/* ── 门禁 ──────────────────────────────────────────────────────────── */
.view-gate {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 28px;
}
.view-gate[hidden] { display: none !important; }

.gate-inner { width: 100%; max-width: 400px; }
.gate-mark { color: var(--accent); display: inline-flex; }
.gate-title {
  margin: 20px 0 16px;
  font-family: var(--serif);
  font-size: 31px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: .04em;
}
.gate-q {
  margin: 0 0 24px;
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.6;
  color: var(--ink-2);
}
.gate-form { display: flex; flex-direction: column; gap: 12px; }
.gate-form input {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.4;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.gate-form input::placeholder { color: var(--ink-3); font-size: 15px; }
.gate-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#gate-submit { min-height: 52px; width: 100%; font-size: 16px; }
.gate-foot { margin: 32px 0 0; font-size: 12px; color: var(--ink-3); letter-spacing: .04em; }

/* ── 窄屏微调 ──────────────────────────────────────────────────────── */
@media (max-width: 380px) {
  .page { padding-left: 16px; padding-right: 16px; }
  .msg-body { max-width: 92%; }
  .composer-dock { margin-left: 16px; margin-right: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
