:root {
  --bg: #fafafa;
  --panel: #ffffff;
  --ink: #1a1a1a;
  --ink-soft: #555;
  --ink-faint: #999;
  --line: #ebebeb;
  --accent: #6b4a7a;
  --bubble-me: #1a1a1a;
  --bubble-me-text: #fafafa;
  --bubble-yan: #f1efed;
  --bubble-yan-text: #1a1a1a;
  --serif: "Cormorant Garamond", "Source Han Serif SC", "Noto Serif SC", "Songti SC", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --panel-max: 760px;
}

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

html, body {
  margin: 0; padding: 0;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  overflow: hidden;
}

/* ────── Tab ────── */
.mobile-tabs {
  flex: 0 0 auto;
  display: flex;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  width: 100%;
}
.mobile-tabs .tab {
  flex: 1;
  background: transparent;
  border: none;
  padding: 14px 0;
  font-family: inherit;
  font-size: 15px;
  color: var(--ink-faint);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  letter-spacing: 0.05em;
}
.mobile-tabs .tab.active {
  color: var(--ink);
  border-bottom-color: var(--ink);
  font-weight: 500;
}

/* ────── 主面板 ────── */
.chat, .moments {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: var(--panel-max);
  margin: 0 auto;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.moments { background: var(--bg); }
body.view-chat .moments { display: none; }
body.view-moments .chat { display: none; }

/* ────── 聊天 ────── */
.chat-header {
  flex: 0 0 auto;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: baseline; justify-content: space-between;
}
.chat-header .name {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 500;
  letter-spacing: 0.05em;
}
.chat-header .meta { display: flex; align-items: center; gap: 8px; }
.chat-header .meta button {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.chat-header .meta button:hover { border-color: var(--ink); color: var(--ink); }
.chat-header .meta button.off { color: var(--ink-faint); }

.chat-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 22px 24px;
  display: flex; flex-direction: column; gap: 10px;
}

.msg-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  position: relative;
  max-width: 100%;
}
.msg-wrap.from-me { align-items: flex-end; }

.msg {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 15px;
  line-height: 1.55;
  user-select: text;
}
.msg.me {
  background: var(--bubble-me);
  color: var(--bubble-me-text);
  border-bottom-right-radius: 4px;
}
.msg.yan {
  background: var(--bubble-yan);
  color: var(--bubble-yan-text);
  border-bottom-left-radius: 4px;
}
.msg.image-msg {
  padding: 6px;
  max-width: 280px;
  border-radius: 14px;
}
.msg.image-msg.yan { background: var(--bubble-yan); border-bottom-left-radius: 4px; }
.msg.image-msg.me { background: var(--bubble-me); border-bottom-right-radius: 4px; }
.msg.image-msg img { display: block; width: 100%; border-radius: 10px; }
.msg.image-msg .caption {
  padding: 8px 10px 4px;
  font-size: 14px;
  white-space: pre-wrap;
}
.msg.image-msg.yan .caption { color: var(--bubble-yan-text); }
.msg.image-msg.me .caption { color: var(--bubble-me-text); }

.msg.sys {
  align-self: center;
  background: transparent;
  color: var(--ink-faint);
  font-size: 12px;
  letter-spacing: 0.05em;
}
.typing {
  align-self: flex-start;
  color: var(--ink-faint);
  font-size: 13px;
  padding: 6px 14px;
  font-style: italic;
}

/* 日期/时间分界线 */
.date-divider {
  align-self: center;
  background: transparent;
  color: var(--ink-faint);
  font-size: 11px;
  letter-spacing: 0.08em;
  padding: 6px 12px;
  margin: 6px 0 2px;
  text-align: center;
}
.date-divider.full {
  font-weight: 500;
  color: var(--ink-soft);
  font-size: 12px;
  margin-top: 14px;
}

/* 表情徽章 */
.reactions {
  display: flex;
  gap: 4px;
  margin-top: 2px;
  padding: 0 6px;
}
.react {
  font-size: 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1px 6px;
  cursor: pointer;
  line-height: 1.4;
  user-select: none;
}
.react-yan { border-color: var(--line); }
.react-me { border-color: var(--ink); }

/* 表情菜单 */
.react-menu {
  position: absolute;
  top: -38px;
  left: 0;
  display: flex;
  gap: 2px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 4px 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  z-index: 100;
}
.from-me .react-menu { left: auto; right: 0; }
.react-menu button {
  background: transparent;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}
.react-menu button:hover { background: #f3f1ee; }

/* 心声 */
.inner-wrap { margin-top: 4px; max-width: 78%; }
.inner-btn {
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--ink-faint);
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.1em;
  padding: 3px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.inner-btn:hover { color: var(--ink-soft); border-color: var(--ink-soft); }
.inner-btn.open { color: var(--accent); border-color: var(--accent); border-style: solid; }
.inner-body {
  margin-top: 6px;
  padding: 10px 14px;
  background: #2a2533;
  color: #e8e3ec;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.6;
  font-style: italic;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* 输入区 */
.chat-input {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  padding: 12px 18px calc(14px + var(--safe-bottom));
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--panel);
  flex-wrap: wrap;
}
.chat-input .attach {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 38px; height: 38px;
  font-size: 20px;
  cursor: pointer;
  flex: 0 0 auto;
}
.chat-input .attach:hover { border-color: var(--ink); color: var(--ink); }
.chat-input textarea {
  flex: 1 1 auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 16px;
  resize: none;
  min-height: 42px;
  max-height: 160px;
  outline: none;
  background: #fafafa;
}
.chat-input textarea:focus { border-color: var(--ink); }
.chat-input #send {
  background: var(--ink);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 0 18px;
  height: 42px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 0.05em;
}
.chat-input #send:disabled { background: var(--ink-faint); cursor: not-allowed; }

.pending-img {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 0 8px;
  order: -1;
}
.pending-img img { max-width: 80px; max-height: 80px; border-radius: 8px; }
.pending-img button {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  border-radius: 50%;
  width: 24px; height: 24px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

/* ────── 朋友圈 ────── */
.moments-header {
  flex: 0 0 auto;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: baseline; justify-content: space-between;
}
.moments-header .title {
  font-family: var(--serif);
  font-size: 20px;
  letter-spacing: 0.1em;
}
.moments-header button {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.moments-header button:hover { border-color: var(--ink); color: var(--ink); }

.publish-box {
  flex: 0 0 auto;
  padding: 12px 24px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.publish-box textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  background: #fafafa;
  resize: none;
  outline: none;
}
.publish-box textarea:focus { border-color: var(--ink); }
.publish-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  gap: 8px;
}
.publish-img {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink-soft);
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
.publish-send {
  background: var(--ink);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}
.publish-images-preview {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.publish-images-preview .thumb {
  position: relative;
  width: 64px; height: 64px;
}
.publish-images-preview .thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 8px;
}
.publish-images-preview .thumb button {
  position: absolute;
  top: -6px; right: -6px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--ink);
  color: white;
  border: none;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.moments-feed {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 24px calc(40px + var(--safe-bottom));
}
.moment { padding: 18px 0; border-bottom: 1px solid var(--line); }
.moment:last-child { border-bottom: none; }

.moment-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}
.moment-head .who {
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.05em;
  color: var(--ink);
}
.moment-me .moment-head .who { color: var(--accent); }
.moment-head .when {
  color: var(--ink-faint);
  font-size: 11px;
  letter-spacing: 0.05em;
}

.moment .text {
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.7;
  color: var(--ink);
  white-space: pre-wrap;
}
.moment-me .text { font-family: var(--sans); font-size: 15px; }

.moment .image-grid {
  margin-top: 10px;
  display: grid;
  gap: 4px;
  max-width: 320px;
}
.moment .image-grid.count-1 { grid-template-columns: 1fr; max-width: 280px; }
.moment .image-grid.count-2,
.moment .image-grid.count-4 { grid-template-columns: 1fr 1fr; }
.moment .image-grid.count-3,
.moment .image-grid.count-5,
.moment .image-grid.count-6,
.moment .image-grid.count-7,
.moment .image-grid.count-8,
.moment .image-grid.count-9 { grid-template-columns: 1fr 1fr 1fr; }

.moment .image-wrap {
  border-radius: 6px;
  overflow: hidden;
  background: #eee;
  aspect-ratio: 1 / 1;
}
.moment .image-grid.count-1 .image-wrap { aspect-ratio: auto; max-height: 280px; }
.moment .image-wrap img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}

.moment .actions {
  margin-top: 12px;
  display: flex; gap: 16px;
  font-size: 13px;
  color: var(--ink-soft);
}
.moment .actions button {
  background: transparent;
  border: none;
  padding: 6px 0;
  cursor: pointer;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 13px;
  display: inline-flex; align-items: center; gap: 5px;
}
.moment .actions button:hover { color: var(--ink); }
.moment .actions .liked { color: #c0392b; }

.moment .liked-by {
  margin-top: 10px;
  padding: 8px 12px;
  background: #f5f3f1;
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink-soft);
}
.moment .liked-by .heart { color: #c0392b; margin-right: 6px; }

.moment .comments {
  margin-top: 6px;
  padding: 4px 12px;
  background: #f5f3f1;
  border-radius: 6px;
}
.moment .liked-by + .comments {
  margin-top: 0;
  border-top: 1px solid #e8e4e0;
  border-radius: 0 0 6px 6px;
}
.moment .comment { padding: 6px 0; font-size: 13px; line-height: 1.55; }
.moment .comment .who { color: var(--accent); margin-right: 4px; }
.moment .comment.yan .who { color: var(--ink); font-weight: 500; }

.moment .comment-input {
  margin-top: 10px;
  display: flex; gap: 6px;
}
.moment .comment-input input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  background: white;
}
.moment .comment-input input:focus { border-color: var(--ink); }
.moment .comment-input button {
  background: var(--ink);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0 14px;
  cursor: pointer;
  font-size: 13px;
}

.moments-empty {
  color: var(--ink-faint);
  font-size: 13px;
  padding: 40px 0;
  text-align: center;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d9d9d9; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #b9b9b9; }

/* ────── 桌面端 ────── */
@media (min-width: 769px) {
  body { background: #f3f1ee; }
  .mobile-tabs {
    max-width: var(--panel-max);
    margin: 0 auto;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
  }
  .chat, .moments {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}

/* ────── 手机 ────── */
@media (max-width: 768px) {
  .chat-header { padding: 12px 16px; }
  .chat-header .name { font-size: 22px; }
  .chat-header .meta button { font-size: 11px; padding: 5px 8px; }
  .chat-log { padding: 16px 14px; gap: 10px; }
  .msg { max-width: 85%; }
  .msg.image-msg { max-width: 75%; }
  .chat-input { padding: 10px 12px calc(12px + var(--safe-bottom)); gap: 6px; }
  .chat-input textarea { padding: 10px 12px; font-size: 16px; }
  .chat-input #send { padding: 0 14px; height: 42px; }
  .chat-input .attach { width: 38px; height: 38px; }
  .moments-header { padding: 12px 16px; }
  .moments-header .title { font-size: 17px; }
  .publish-box { padding: 10px 16px 12px; }
  .moments-feed { padding: 12px 16px calc(40px + var(--safe-bottom)); }
  .moment .text { font-size: 16px; }
  .moment .image-grid { max-width: 100%; }
  .moment .actions button { padding: 8px 0; font-size: 14px; }
  .inner-wrap { max-width: 90%; }
}

@media (max-width: 380px) {
  .chat-header .name { font-size: 20px; }
  .chat-header .meta { gap: 6px; }
  .chat-header .meta button { font-size: 10px; padding: 5px 7px; }
}
