/* 回忆录工具 · 样式（移动优先，长辈友好：大字、高对比、暖色） */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "微软雅黑", sans-serif;
  background: #f6f1e7;
  color: #3a3226;
  line-height: 1.7;
  min-height: 100vh;
}
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 1rem; }
.hidden { display: none !important; }

/* ===== 顶部导航 ===== */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: linear-gradient(135deg, #a4552f 0%, #8c3d24 100%);
  color: #fff;
  padding: 0.6rem 0.9rem;
  display: flex; align-items: center; gap: 0.5rem;
  box-shadow: 0 2px 8px rgba(60,30,10,.25);
}
.topbar .brand { font-size: 1.1rem; font-weight: 700; letter-spacing: 1px; white-space: nowrap; }
.topbar nav { display: flex; gap: 0.25rem; overflow-x: auto; margin-left: auto; }
.topbar nav a {
  color: rgba(255,255,255,.85); text-decoration: none;
  padding: 0.35rem 0.6rem; border-radius: 999px; font-size: 0.95rem; white-space: nowrap;
}
.topbar nav a.active, .topbar nav a:hover { background: rgba(255,255,255,.18); color: #fff; }

/* ===== 通用布局 ===== */
.page { max-width: 860px; margin: 0 auto; padding: 1rem 0.9rem 4rem; }
.card {
  background: #fffdf8; border: 1px solid #e8ddc8; border-radius: 14px;
  padding: 1rem 1.1rem; margin-bottom: 0.9rem;
  box-shadow: 0 1px 4px rgba(120,90,40,.08);
}
.card h3 { font-size: 1.12rem; color: #7a3d1e; margin-bottom: 0.5rem; }
.muted { color: #8d8272; font-size: 0.9rem; }
.btn {
  display: inline-block; border: none; border-radius: 10px;
  background: #a4552f; color: #fff; font-size: 1rem;
  padding: 0.55rem 1.1rem; transition: opacity .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: #efe5d2; color: #6b4a1f; }
.btn.small { font-size: 0.88rem; padding: 0.35rem 0.75rem; border-radius: 8px; }
.btn.danger { background: #b3432b; }
.btn.success { background: #4d7c4a; }
.btn.ghost { background: transparent; color: #a4552f; border: 1px solid #d9b89a; }

/* ===== 登录页 ===== */
#view-login { max-width: 420px; margin: 8vh auto; padding: 0 1rem; }
.login-logo { text-align: center; font-size: 2.6rem; margin-bottom: 0.2rem; }
.login-card h2 { text-align: center; color: #7a3d1e; margin-bottom: 0.3rem; }
.login-card p.sub { text-align: center; color: #8d8272; margin-bottom: 1.2rem; }
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.92rem; color: #6b5d45; margin-bottom: 0.3rem; }
.field input, .field textarea, .field select {
  width: 100%; padding: 0.65rem 0.75rem; border: 1.5px solid #d8cbb0; border-radius: 10px;
  background: #fff; color: #3a3226;
}
.field input:focus, .field textarea:focus { outline: none; border-color: #a4552f; }
.field .err { color: #b3432b; font-size: 0.85rem; margin-top: 0.25rem; min-height: 1.1rem; }
.otp-row { display: flex; gap: 0.6rem; }
.otp-row input { flex: 1; }
.otp-row .btn { white-space: nowrap; }

/* ===== 人生地图（首页）===== */
.hero {
  background: linear-gradient(135deg, #b8683a 0%, #8c3d24 100%);
  border-radius: 16px; color: #fff; padding: 1.2rem 1.2rem; margin-bottom: 1rem;
  box-shadow: 0 4px 14px rgba(140,61,36,.3);
}
.hero h2 { font-size: 1.35rem; margin-bottom: 0.2rem; }
.hero .stats { display: flex; gap: 1.2rem; margin-top: 0.6rem; }
.hero .stat { background: rgba(255,255,255,.14); border-radius: 10px; padding: 0.4rem 0.8rem; }
.hero .stat b { font-size: 1.3rem; }
.hero .stat span { font-size: 0.85rem; opacity: .9; margin-left: 0.2rem; }

.chapter-card { margin-bottom: 1rem; }
.chapter-head { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.chapter-head .ch-title { font-size: 1.1rem; font-weight: 700; color: #5c3418; }
.chapter-head .ch-brief { color: #8d8272; font-size: 0.85rem; }
.chapter-progress {
  margin-left: auto; font-size: 0.85rem; color: #fff; border-radius: 999px;
  padding: 0.15rem 0.7rem; background: #b68a5c;
}
.chapter-progress.done { background: #4d7c4a; }
.topic-grid { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.7rem; }
.topic-chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  border: 1.5px solid #dccdb2; border-radius: 999px;
  background: #fff; color: #5c4a2e; font-size: 0.92rem;
  padding: 0.3rem 0.75rem; text-decoration: none;
}
.topic-chip .dot { width: 9px; height: 9px; border-radius: 50%; background: #cfc4ae; flex: none; }
.topic-chip.drafted { border-color: #7fae7c; background: #eef5ec; }
.topic-chip.drafted .dot { background: #4d7c4a; }
.topic-chip.chatted { border-color: #d9a05f; background: #faf0e2; }
.topic-chip.chatted .dot { background: #c77b2f; }

/* ===== 对话页 ===== */
.chat-topic-head {
  background: #fffdf8; border: 1px solid #e8ddc8; border-radius: 12px;
  padding: 0.7rem 1rem; margin-bottom: 0.8rem;
}
.chat-topic-head b { color: #7a3d1e; font-size: 1.05rem; }
.chat-topic-head .back { float: right; font-size: 0.9rem; color: #a4552f; text-decoration: none; margin-top: 0.15rem; }
#chat-box {
  display: flex; flex-direction: column; gap: 0.7rem;
  padding: 0.3rem 0.1rem 6.5rem;
  min-height: 50vh;
}
.msg { max-width: 88%; padding: 0.6rem 0.85rem; border-radius: 14px; font-size: 1.05rem; white-space: pre-wrap; word-break: break-word; }
.msg.ai { align-self: flex-start; background: #fffdf8; border: 1px solid #e8ddc8; border-top-left-radius: 4px; }
.msg.user { align-self: flex-end; background: #a4552f; color: #fff; border-top-right-radius: 4px; }
.msg .who { display: block; font-size: 0.75rem; opacity: .65; margin-bottom: 0.15rem; }
.msg .photo-thumb { max-width: 100%; border-radius: 8px; margin-top: 0.4rem; }
.typing { align-self: flex-start; color: #b09c7c; font-size: 0.95rem; padding: 0.4rem 0.6rem; }

.chat-input-bar {
  position: fixed; bottom: var(--kb-h, 0px); left: 0; right: 0;
  background: #f6f1e7; border-top: 1px solid #e0d3b8;
  padding: 0.6rem 0.9rem calc(0.6rem + env(safe-area-inset-bottom));
  z-index: 60;
}
/* 键盘/语音面板弹起时：收起顶栏、压扁输入框，保证输入内容完整可见 */
body.kb-open .topbar { display: none; }
body.kb-open .chat-input-bar textarea { min-height: 56px; }
body.kb-open .chat-hint { display: none; }
.chat-input-bar .inner { max-width: 860px; margin: 0 auto; }
.chat-input-bar textarea {
  width: 100%; min-height: 110px; max-height: 240px; resize: none;
  border: 1.5px solid #d8cbb0; border-radius: 12px; padding: 0.7rem 0.85rem; background: #fff;
  font-size: 1.18rem; line-height: 1.6;
}
.btn-voice { position: relative; }
.btn-voice.recording { background: #b3432b; color: #fff; animation: voice-pulse 1.2s ease-in-out infinite; }
@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(179, 67, 43, 0.45); }
  50% { box-shadow: 0 0 0 8px rgba(179, 67, 43, 0); }
}
.chat-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap; align-items: center; }
.chat-actions .spacer { flex: 1; }
.chat-hint { font-size: 0.85rem; color: #a4805a; }

/* 照片区 */
.photo-strip { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 0.6rem 0; }
.photo-item { position: relative; width: 96px; }
.photo-item img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; border: 1px solid #d8cbb0; display: block; }
.photo-item .cap {
  font-size: 0.75rem; color: #6b5d45; background: #fffdf8; border: 1px solid #e8ddc8; border-radius: 6px;
  padding: 0.15rem 0.3rem; margin-top: 0.25rem; width: 100%;
}
.photo-item .del {
  position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; border-radius: 50%;
  background: #b3432b; color: #fff; border: none; font-size: 13px; line-height: 22px; text-align: center;
}
.upload-btn-wrap { display: flex; align-items: center; gap: 0.4rem; }
.upload-btn-wrap input[type=file] { display: none; }

/* 成文卡片 */
.compose-card {
  border: 1.5px dashed #c99a5f; background: #fdf8ee; border-radius: 12px; padding: 0.8rem;
}
.compose-card .title { color: #7a3d1e; font-weight: 700; margin-bottom: 0.4rem; }
.compose-preview {
  background: #fff; border: 1px solid #e0d3b8; border-radius: 10px; padding: 0.7rem;
  font-size: 1.02rem; white-space: pre-wrap; min-height: 60px; max-height: 40vh; overflow-y: auto;
}
.compose-actions { display: flex; gap: 0.5rem; margin-top: 0.6rem; }
.moves-note { margin-top: 0.5rem; }
.moves-note-inner {
  background: #eef4ea; border: 1px solid #c4d6b8; color: #3d5a2e;
  border-radius: 10px; padding: 0.55rem 0.7rem; font-size: 0.92rem; line-height: 1.6;
}

/* ===== 回忆录预览 ===== */
.book { background: #fffdf8; border: 1px solid #e8ddc8; border-radius: 14px; padding: 1.4rem 1.2rem; }
.book .book-title { text-align: center; font-size: 1.6rem; color: #7a3d1e; font-weight: 800; letter-spacing: 2px; }
.book .book-author { text-align: center; color: #8d8272; margin: 0.3rem 0 1rem; }
.book h2.ch { font-size: 1.25rem; color: #8c3d24; margin: 1.4rem 0 0.4rem; border-bottom: 2px solid #e0d3b8; padding-bottom: 0.3rem; }
.book h3.tp { font-size: 1.08rem; color: #5c4a2e; margin: 0.9rem 0 0.3rem; }
.book p.body { text-indent: 2em; margin-bottom: 0.5rem; }
.book .section-tools { float: right; }
.book .contribution {
  background: #f3ede0; border-left: 4px solid #c99a5f; border-radius: 0 10px 10px 0;
  padding: 0.6rem 0.8rem; margin: 0.6rem 0; font-size: 0.98rem;
}
.book .contribution .who { color: #8c6a3a; font-size: 0.85rem; margin-bottom: 0.2rem; }
.book .photos-row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 0.5rem 0; }
.book .photos-row img { width: 110px; height: 110px; object-fit: cover; border-radius: 8px; border: 1px solid #d8cbb0; }

/* ===== 分享管理 ===== */
.share-item { border-bottom: 1px dashed #d8cbb0; padding: 0.7rem 0; }
.share-item:last-child { border-bottom: none; }
.share-link-row { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.share-link-row code {
  background: #f0e9d8; border-radius: 6px; padding: 0.2rem 0.5rem; font-size: 0.85rem; word-break: break-all;
}
.contribution-item { background: #faf5ea; border-radius: 10px; padding: 0.6rem 0.8rem; margin-top: 0.6rem; }
.contribution-item.pending { border-left: 4px solid #c77b2f; }
.contribution-item.approved { border-left: 4px solid #4d7c4a; }
.contribution-item .head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.badge { font-size: 0.75rem; border-radius: 999px; padding: 0.1rem 0.55rem; background: #e8ddc8; color: #6b4a1f; }
.badge.pending { background: #f5e2c8; color: #a4651e; }
.badge.approved { background: #e2efe0; color: #3f6b3c; }

/* ===== 历史页 ===== */
.history-item { display: flex; justify-content: space-between; align-items: center; padding: 0.55rem 0; border-bottom: 1px dashed #e0d3b8; }
.history-item a { color: #a4552f; text-decoration: none; font-size: 0.95rem; }

/* ===== 弹窗 ===== */
.modal-mask {
  position: fixed; inset: 0; background: rgba(40,25,10,.45); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal {
  background: #fffdf8; border-radius: 14px; width: 100%; max-width: 640px;
  max-height: 86vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal .modal-head { padding: 0.8rem 1rem; border-bottom: 1px solid #e8ddc8; display: flex; align-items: center; }
.modal .modal-head b { color: #7a3d1e; }
.modal .modal-head .close { margin-left: auto; border: none; background: none; font-size: 1.4rem; color: #8d8272; }
.modal .modal-body { padding: 0.9rem 1rem; overflow-y: auto; }
.modal textarea.full { width: 100%; min-height: 200px; border: 1.5px solid #d8cbb0; border-radius: 10px; padding: 0.6rem; font-size: 1.02rem; }
.modal .modal-foot { padding: 0.7rem 1rem; border-top: 1px solid #e8ddc8; display: flex; gap: 0.5rem; justify-content: flex-end; }

/* toast */
#toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 200;
  background: rgba(60,40,20,.88); color: #fff; padding: 0.5rem 1.1rem; border-radius: 999px;
  font-size: 0.95rem; max-width: 90vw; text-align: center;
  transition: opacity .25s; opacity: 0; pointer-events: none;
}
#toast.show { opacity: 1; }

/* 加载 */
.loading-block { text-align: center; color: #a08a66; padding: 2.5rem 0; }

@media (min-width: 720px) {
  .page { padding: 1.2rem 1.2rem 4rem; }
  .msg { max-width: 75%; }
  .hero h2 { font-size: 1.5rem; }
}
