:root {
  --bg: #f6f1e9; --card: #fffdf9; --ink: #2b2722; --muted: #8a8178; --line: #e6ddd0;
  --accent: #c0643c; --accent-ink: #fff; --danger: #b23a3a; --chip: #efe7da;
  --radius: 14px; --tab-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #161513; --card: #211f1c; --ink: #ece6dc; --muted: #9a9187; --line: #34302b;
          --accent: #e08158; --chip: #2c2925; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans", "Noto Sans CJK SC", sans-serif; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* 按钮 */
.btn { border: 0; border-radius: 999px; padding: 10px 18px; background: var(--chip); cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost.light { color: #fff; }
.delete-btn { flex: none; padding: 6px 12px; font-size: 14px; background: transparent; color: var(--danger);
  border: 1.5px solid color-mix(in srgb, var(--danger) 55%, transparent); }
.btn.small { padding: 4px 10px; font-size: 14px; }
.btn:disabled { opacity: .5; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 20px; width: 40px; height: 40px; cursor: pointer; }

/* 登录 */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(340px, 100%); display: grid; gap: 14px; text-align: center; }
.login-card h1 { margin: 0; font-size: 26px; }
.login-card p { margin: 0; }
.login-icon { width: 72px; height: 72px; margin: 0 auto; border-radius: 18px; }
.login-card input { padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); font-size: 17px; }
.err { color: var(--danger); min-height: 1.6em; }
.boot { min-height: 100dvh; }

/* 页面框架 */
.page { max-width: 680px; margin: 0 auto; padding: calc(var(--safe-t) + 8px) 16px calc(var(--tab-h) + var(--safe-b) + 24px); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; }
.topbar h2 { margin: 0; font-size: 22px; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b); z-index: 10; }
.tabbar a { flex: 1; height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 12px; color: var(--muted); text-decoration: none; }
.tabbar a.on { color: var(--accent); }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* 写日记 */
.date-pick { position: relative; min-width: 0; font-size: 20px; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.date-pick::after { content: "▾"; font-size: 14px; color: var(--muted); }
.date-pick input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.new-btn { flex: none; padding: 9px 16px; font-size: 15px; box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 35%, transparent); }
.topbar h2 small { font-size: 14px; font-weight: 400; }
.save-state { margin-right: 2px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.weather-row { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.weather { flex: 1; border: 0; background: var(--chip); border-radius: 999px; padding: 8px 14px; font-size: 15px; min-width: 0; }
.moods { display: flex; justify-content: space-between; gap: 2px; margin: 0 0 10px; }
.moods button { flex: 1; border: 0; background: transparent; border-radius: 12px; padding: 4px 0; font-size: 11px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; cursor: pointer; }
.moods button span { font-size: 26px; line-height: 1.25; filter: grayscale(.85); opacity: .55; transition: transform .15s; }
.moods button.on { background: var(--chip); color: var(--ink); font-weight: 600; }
.moods button.on span { filter: none; opacity: 1; transform: scale(1.12); }
.hint { margin: 0 0 8px; padding: 8px 12px; background: var(--chip); border-radius: 10px; font-size: 14px; }
.hint a { color: var(--accent); }
#content { width: 100%; min-height: 40dvh; border: 0; border-radius: var(--radius); background: var(--card); padding: 16px;
  font-size: 17px; line-height: 1.8; resize: none; outline: none; box-shadow: 0 1px 0 var(--line); }
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.photos .ph, .photo-add { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--chip); }
.photos .ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photos .ph.uploading::after { content: "上传中…"; position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(0,0,0,.35); color: #fff; font-size: 13px; }
.photo-add { display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted);
  border: 1.5px dashed var(--line); cursor: pointer; }
.photo-add span { font-size: 30px; line-height: 1; }
.photo-add input { position: absolute; inset: 0; opacity: 0; }

/* 时间线 */
.search { width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 10px 16px; margin-bottom: 8px; }
.month { margin: 18px 4px 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.card { display: block; width: 100%; text-align: left; border: 0; background: var(--card); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 10px; cursor: pointer; box-shadow: 0 1px 0 var(--line); }
.card-head { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.card-head b { font-size: 16px; }
.card-head .mood { font-size: 18px; margin-left: 4px; }
.card-head span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card p { margin: 6px 0 0; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.card .thumbs { display: flex; gap: 6px; margin-top: 8px; }
.card .thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.empty { text-align: center; color: var(--muted); padding: 48px 0; }

/* 问日记 */
.ask-page { display: flex; flex-direction: column; min-height: 100dvh; }
.chat { flex: 1; display: flex; flex-direction: column; gap: 12px; padding-bottom: 80px; }
.chat-empty { color: var(--muted); display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.chip { border: 0; background: var(--chip); border-radius: 999px; padding: 8px 14px; cursor: pointer; text-align: left; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--card); border-bottom-left-radius: 4px; box-shadow: 0 1px 0 var(--line); }
.msg.bot.err { color: var(--danger); }
.msg .stage { color: var(--muted); font-size: 14px; }
.msg .meta { color: var(--muted); font-size: 12px; margin-top: 6px; }
.sources { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.sources button { border: 1px solid var(--line); background: transparent; border-radius: 10px; padding: 6px 10px; text-align: left; cursor: pointer; font-size: 14px; }
.sources b { color: var(--accent); margin-right: 6px; }
.ask-bar { position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + var(--safe-b)); display: flex; gap: 8px;
  padding: 8px 12px; background: var(--bg); max-width: 680px; margin: 0 auto; }
.ask-bar textarea { flex: 1; border: 1px solid var(--line); background: var(--card); border-radius: 20px; padding: 9px 14px;
  resize: none; max-height: 120px; outline: none; font-size: 16px; }

/* 大图 */
.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 30; display: flex; flex-direction: column; }
.viewer img { flex: 1; min-height: 0; object-fit: contain; width: 100%; }
.viewer-bar { display: flex; justify-content: space-between; padding: 12px 16px calc(12px + var(--safe-b)); }

.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: 14px; opacity: 0;
  transition: opacity .2s; pointer-events: none; z-index: 40; }
.toast.show { opacity: 1; }
