:root {
  --primary: #4f46e5;
  --primary-soft: #eef2ff;
  --amber: #f59e0b;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .04);
  --maxw: 480px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(10px);
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 18px; color: var(--primary); white-space: nowrap; }
.theme-toggle {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  width: 36px; height: 36px; border-radius: 50%; cursor: pointer; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.theme-ico { width: 18px; height: 18px; stroke: currentColor; }
.search-bar { flex: 1; }
.search-bar input {
  width: 100%; border: 1px solid var(--line); border-radius: 999px;
  padding: 9px 14px; font-size: 14px; background: #f1f5f9; outline: none;
}
.search-bar input:focus { border-color: var(--primary); background: #fff; }

/* View */
.app-view {
  max-width: var(--maxw); margin: 0 auto; padding: 16px 16px 90px;
}

/* Feed tabs */
.feed-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.feed-tabs button {
  border: none; background: #fff; color: var(--muted);
  padding: 7px 14px; border-radius: 999px; font-size: 13px; cursor: pointer;
  border: 1px solid var(--line);
}
.feed-tabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.section-title { font-size: 15px; font-weight: 700; margin: 4px 0 12px; }

/* Card */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 14px;
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex: 0 0 auto;
  overflow: hidden;
}
.avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.uname { font-weight: 600; font-size: 14px; cursor: pointer; }
.meta { font-size: 12px; color: var(--muted); }

.excerpt-content { display: flex; gap: 12px; }
.book-cover {
  width: 46px; height: 62px; border-radius: 6px; color: #fff; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
  writing-mode: vertical-rl; padding: 4px; line-height: 1.2;
}
.excerpt-content blockquote {
  font-size: 15px; line-height: 1.7; color: #1e293b;
  border-left: 3px solid var(--primary); padding-left: 10px; flex: 1;
}
.note { font-size: 13px; color: var(--muted); margin-top: 8px; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { font-size: 12px; color: var(--primary); background: var(--primary-soft); padding: 3px 9px; border-radius: 999px; }

.card-foot { display: flex; gap: 6px; margin-top: 12px; }
.act {
  flex: 1; border: 1px solid var(--line); background: #fff; color: var(--muted);
  border-radius: 10px; padding: 7px 0; font-size: 13px; cursor: pointer;
}
.act.on { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); font-weight: 600; }
.act-edit { color: var(--text); border-color: var(--line); }
.act-edit:hover { border-color: var(--primary); color: var(--primary); }
.act-del { color: #ef4444; border-color: #fecaca; }
.act-del:hover { border-color: #ef4444; background: #fef2f2; }

.book-ref { font-size: 12px; color: var(--muted); margin-top: 10px; cursor: pointer; }
.book-ref:hover { color: var(--primary); }

/* 评论楼中楼（嵌套回复） */
.reply-box { margin: 0 0 4px 18px; border-left: 2px solid var(--line); padding-left: 8px; }
.comment-list { padding: 0 2px; }
.btn-reply { margin-top: 6px; background: none; border: none; color: var(--primary); font-size: 12px; cursor: pointer; padding: 0; }
.btn-reply:hover { text-decoration: underline; }
.reply-to { color: var(--primary); font-size: 13px; margin-right: 4px; }
.reply-target { display: inline-block; background: var(--primary-soft); color: var(--primary); border-radius: 8px; padding: 4px 10px; font-size: 13px; }

/* Bottom nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  max-width: var(--maxw); margin: 0 auto;
  display: flex; align-items: center; justify-content: space-around;
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-btn {
  flex: 1; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 7px 0 8px; color: var(--muted); position: relative;
  transition: color .18s;
}
.nav-icon { width: 22px; height: 22px; flex-shrink: 0; }
.nav-btn span { font-size: 10px; line-height: 1.2; white-space: nowrap; }
.nav-btn.active { color: var(--primary); }
.nav-btn.active .nav-icon { stroke: var(--primary); }
/* 激活态：图标上方加一短横线指示 */
.nav-btn.active::before {
  content:''; position:absolute; top:2px; left:50%; transform:translateX(-50%);
  width:16px; height:2.5px; border-radius:2px; background:var(--primary);
}
.nav-publish {
  flex: 0 0 52px; width: 52px; height: 52px; margin: -14px 4px 4px;
  border-radius: 50%; background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff; box-shadow: 0 4px 14px rgba(245,158,11,.40);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s, box-shadow .15s;
}
.nav-publish svg { width: 24px; height: 24px; }
.nav-publish:active { transform: scale(.92); box-shadow: 0 2px 8px rgba(245,158,11,.30); }

/* Modal */
/* 真实滚动根是 documentElement(html)，仅锁 body 无法阻止背景滚动，故 html/body 一起锁 */
html.modal-open, body.modal-open { overflow: hidden; }
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: #fff; width: 100%; max-width: var(--maxw); border-radius: 18px 18px 0 0;
  padding: 18px 16px 28px; max-height: 90vh; overflow-y: auto;
}
/* 桌面端（宽屏）：弹窗改为居中浮窗并支持拖拽；移动端保持底部抽屉不变 */
@media (min-width: 768px) {
  .modal-mask { align-items: center; }
  .modal {
    position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
    width: auto; min-width: 360px; max-width: 520px; border-radius: 18px;
    max-height: 86vh; box-shadow: 0 24px 70px rgba(0, 0, 0, .35);
  }
  .modal h3 { cursor: move; user-select: none; }
}
.modal h3 { font-size: 16px; margin-bottom: 14px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.id-mic-btn {
  border: 1px solid var(--primary); color: var(--primary); background: #fff;
  border-radius: 999px; padding: 4px 12px; font-size: 12px; cursor: pointer; user-select: none;
}
.id-mic-btn:hover { background: var(--primary); color: #fff; }
.id-mic-btn.on { background: #ef4444; color: #fff; border-color: #ef4444; animation: mic-pulse 1.2s ease-in-out infinite; }
.id-mic-btn:disabled { cursor: not-allowed; }
/* 语音输入：悬浮于正文输入框右下角的圆形按钮 */
.ta-wrap { position: relative; }
#f-content { padding-bottom: 54px; }
.mic-fab {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 12px;
  width: 42px; height: 42px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--primary); background: rgba(255,255,255,.66); color: var(--primary);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  font-size: 20px; line-height: 1; cursor: pointer; user-select: none;
  box-shadow: 0 2px 8px rgba(0,0,0,.14); transition: all .15s;
}
.mic-fab .nav-icon { width: 19px; height: 19px; }
.mic-fab:hover { background: rgba(79,70,229,.78); color: #fff; }
.mic-fab.on { background: rgba(239,68,68,.8); color: #fff; border-color: rgba(239,68,68,.8); animation: mic-pulse 1.2s ease-in-out infinite; }
.mic-fab:disabled { opacity: .5; cursor: not-allowed; }
@keyframes mic-pulse { 0%,100% { opacity: 1; } 50% { opacity: .65; } }
.mic-hint {
  font-size: 12px; color: var(--muted); padding: 4px 8px; margin: 4px 0;
  background: #f1f5f9; border-radius: 6px; min-height: 18px;
}
.mic-hint.on { background: #fef2f2; color: #b91c1c; }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 14px; outline: none; font-family: inherit;
}
.field textarea { resize: vertical; min-height: 80px; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--primary); }
.tag-input { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--primary-soft); color: var(--primary); border-radius: 999px; padding: 5px 10px; font-size: 12px; }
.chip x { margin-left: 6px; cursor: pointer; }
.modal-actions { display: flex; gap: 10px; margin-top: 14px; }
.btn {
  flex: 1; border: none; border-radius: 12px; padding: 12px; font-size: 15px; cursor: pointer; font-weight: 600;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-ghost { background: #f1f5f9; color: var(--muted); }
.btn-featured { background: #fff7ed; color: #ea580c; border: 1px solid #fdba74; font-weight: 600; }
.card-preview {
  background: var(--primary-soft); border-radius: 12px; padding: 14px; margin-bottom: 14px;
}
.card-preview .pc-book { font-weight: 700; font-size: 13px; }
.card-preview blockquote { border-left: 3px solid var(--primary); padding-left: 10px; margin: 8px 0; font-size: 14px; }

/* Profile */
.profile-head { position: relative; display: flex; gap: 14px; align-items: center; background: #fff; border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
/* 「我的」页右上角设置按钮（与编辑铅笔同款圆形风格） */
.profile-set-btn { margin-left: auto; align-self: flex-start; font-size: 15px; }
/* 设置下拉菜单（设置 / 关于 / 退出登录） */
.profile-menu {
  position: absolute; top: 50px; right: 12px; z-index: 20;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); overflow: hidden; min-width: 116px;
}
.profile-menu-item {
  display: block; width: 100%; text-align: left; border: none; background: transparent;
  padding: 11px 14px; font-size: 14px; color: var(--text); cursor: pointer;
}
.profile-menu-item:hover { background: var(--primary-soft); }
.profile-menu-item.danger { color: #ef4444; }
.profile-menu-item.danger:hover { background: #fee2e2; }
.about-box { padding: 8px 4px 14px; text-align: center; }
.about-logo { font-size: 18px; font-weight: 700; margin-bottom: 10px; }
.about-line { font-size: 13px; color: var(--muted); margin: 4px 0; }
.profile-head .avatar { width: 56px; height: 56px; font-size: 20px; }
.stat-row { display: flex; gap: 18px; margin-top: 10px; }
.stat-row div { font-size: 13px; color: var(--muted); }
.stat-row b { color: var(--text); font-size: 16px; }
.btn-follow { border: 1px solid var(--primary); color: var(--primary); background: #fff; border-radius: 999px; padding: 6px 16px; font-size: 13px; cursor: pointer; }
.btn-follow.on { background: var(--primary); color: #fff; }

/* My-followed-books row */
.book-row { display: flex; gap: 12px; align-items: center; background: #fff; border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); margin-bottom: 10px; }
.book-row .meta { font-size: 12px; margin-top: 4px; }

/* 关注的书：多列网格书卡（一屏看更多，比整行列表更紧凑） */
.book-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding: 4px 0; }
.book-cell { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.book-cell .book-cover { width: 100%; aspect-ratio: 3 / 4; border-radius: 6px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 15px; font-weight: 700; cursor: pointer; }
.book-cell .bc-title { font-size: 13px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.book-cell .bc-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.book-cell .bc-followers { font-size: 11px; color: var(--primary); margin-top: 4px; }
.book-cell .bc-unfollow { font-size: 12px; color: var(--primary); cursor: pointer; align-self: flex-start; margin-top: 2px; }

/* ===== 统一统计胶囊：关注人数 / 粉丝数 视觉一致 ===== */
.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
}
.stat-pill svg { width: 12px; height: 12px; flex-shrink: 0; }
.stat-pill .num { font-variant-numeric: tabular-nums; }

/* ===== 我关注的人 ===== */
.user-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 4px 0; }
.user-cell { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; }
.user-row { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.user-row .avatar { width: 40px; height: 40px; font-size: 16px; flex-shrink: 0; }
.user-meta { min-width: 0; }
.user-meta .uname { font-size: 14px; font-weight: 600; line-height: 1.3; }
.user-meta .meta { font-size: 11px; color: var(--muted); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.user-meta .followers-line { margin-top: 4px; }
.user-cell .bc-unfollow { font-size: 12px; color: var(--primary); cursor: pointer; align-self: flex-start; }


/* Book / User detail */
.detail-hero { background: #fff; border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: flex; gap: 14px; margin-bottom: 16px; }
.detail-hero .book-cover { width: 64px; height: 88px; font-size: 15px; }
.detail-hero h2 { font-size: 17px; }
.detail-hero .author { color: var(--muted); font-size: 13px; margin-top: 4px; }
.back-link { color: var(--primary); font-size: 14px; cursor: pointer; margin-bottom: 12px; display: inline-block; }

/* Empty */
.empty { text-align: center; color: var(--muted); padding: 40px 0; font-size: 14px; }
/* 发现流无限滚动：底部状态提示 + 哨兵占位 */
.feed-status { text-align: center; color: var(--muted); font-size: 13px; padding: 18px 0 28px; }
#discoverSentinel, #followingSentinel { height: 1px; }

/* 分段控件（我的页：摘要 / 评论） */
.seg { display: flex; gap: 8px; padding: 4px; margin: 14px 0 0; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.seg-btn { flex: 1; min-width: 0; padding: 9px 0; border: none; background: transparent; color: var(--muted); font-size: 14px; font-weight: 600; border-radius: 9px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg-btn.on { background: var(--primary); color: #fff; }
/* 关注页分段控件：去掉多余横向内缩后与下方卡片等宽；这里单独补回与流内容的纵向间距（不动消息页 .msg-toolbar 内的 .seg） */
#followingSeg { margin-bottom: 14px; }

/* 我的评论 - 评论项 */
.comment-item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 10px 16px; box-shadow: var(--shadow); }
.comment-item .comment-body { font-size: 14px; color: var(--text); margin: 6px 0; }
.comment-item .comment-origin { font-size: 12px; color: var(--muted); border-left: 3px solid var(--primary); padding-left: 8px; }
.comment-item .comment-reply-to { font-size: 12px; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 6px 8px; margin-bottom: 6px; }
.comment-item .ci-foot { display: flex; gap: 10px; margin-top: 10px; }
.ci-del { color: #ef4444; border-color: #fecaca; }
.ci-del:hover { background: #fef2f2; }

/* ============ 暗色模式 ============ */
[data-theme="dark"] {
  --primary: #818cf8;
  --primary-soft: #1e1b4b;
  --amber: #fbbf24;
  --bg: #0b1020;
  --card: #151b2e;
  --text: #e6e9f2;
  --muted: #94a3b8;
  --line: #232b42;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  --input-bg: #1c2336;
  --header-bg: rgba(15, 20, 36, .9);
  --nav-bg: #121829;
  --quote: #cbd5e1;
}

[data-theme="dark"] body { background: var(--bg); color: var(--text); }

[data-theme="dark"] .app-header {
  background: var(--header-bg);
  border-bottom-color: var(--line);
}
[data-theme="dark"] .search-bar input { background: var(--input-bg); color: var(--text); border-color: var(--line); }
[data-theme="dark"] .search-bar input:focus { background: var(--input-bg); }

[data-theme="dark"] .feed-tabs button { background: var(--card); color: var(--muted); border-color: var(--line); }
[data-theme="dark"] .feed-tabs button.active { background: var(--primary); color: #0b1020; border-color: var(--primary); }

[data-theme="dark"] .card { background: var(--card); }
[data-theme="dark"] .excerpt-content blockquote { color: var(--quote); }
[data-theme="dark"] .act { background: var(--card); color: var(--muted); border-color: var(--line); }
[data-theme="dark"] .act.on { background: var(--primary-soft); }
/* 深色模式下 .act 的通用覆盖会盖掉 .act-del/.act-edit 的专属色，这里显式还原（特异性更高） */
[data-theme="dark"] .act-edit { color: var(--text); }
[data-theme="dark"] .act-del { color: #f87171; border-color: #7f1d1d; }
[data-theme="dark"] .act-del:hover { color: #fca5a5; border-color: #f87171; background: rgba(248,113,113,.12); }

[data-theme="dark"] .bottom-nav { background: var(--nav-bg); border-top-color: var(--line); }

[data-theme="dark"] .modal { background: var(--card); }
[data-theme="dark"] .field input, [data-theme="dark"] .field textarea, [data-theme="dark"] .field select {
  background: var(--input-bg); color: var(--text); border-color: var(--line);
}
[data-theme="dark"] .btn-ghost { background: var(--input-bg); color: var(--muted); }
[data-theme="dark"] .btn-featured { background: rgba(249,115,22,.16); color: #fdba74; border-color: #ea580c; }
[data-theme="dark"] .card-preview { background: var(--primary-soft); }

[data-theme="dark"] .profile-head, [data-theme="dark"] .detail-hero { background: var(--card); }
[data-theme="dark"] .modal-mask { background: rgba(0, 0, 0, .65); }
[data-theme="dark"] .chip { background: var(--primary-soft); }

[data-theme="dark"] .seg { background: var(--input-bg); border-color: var(--line); }
[data-theme="dark"] .seg-btn { color: var(--muted); }
/* 深色模式下 --primary 偏亮，白字落在其上对比不足；选中态改用「深底+亮字」保证清晰 */
[data-theme="dark"] .seg-btn.on { background: var(--card); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
[data-theme="dark"] .vis-seg .seg-btn.on { background: var(--card); color: var(--text); border: 1px solid var(--line); box-shadow: 0 1px 6px rgba(0,0,0,.35); }

/* My-followed-books row dark */
[data-theme="dark"] .book-row { background: var(--card-bg); }
[data-theme="dark"] .id-mic-btn { background: var(--card); color: var(--primary); }
[data-theme="dark"] .mic-hint { background: var(--input-bg); }
[data-theme="dark"] .mic-hint.on { background: #2a1620; }
[data-theme="dark"] .comment-item { background: var(--card); border-color: var(--line); }
[data-theme="dark"] .comment-item .comment-reply-to { background: var(--input-bg); }
[data-theme="dark"] .ci-del { color: #f87171; border-color: #5b2330; }
[data-theme="dark"] .ci-del:hover { background: #2a1620; }

/* ===== 资料编辑按钮 ===== */
.btn-edit {
  border: none; background: var(--primary-soft); color: var(--primary);
  width: 26px; height: 26px; border-radius: 50%; font-size: 14px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  padding: 0; line-height: 1; transition: background .15s, color .15s;
}
.btn-edit:hover { background: var(--primary); color: #fff; }

/* ===== 头像色板 ===== */
.swatches { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.swatch {
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  display: inline-block; border: 2px solid transparent; transition: transform .15s;
  box-sizing: border-box;
}
.swatch:hover { transform: scale(1.08); }
.swatch.on { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg) inset; }
.swatch.custom {
  background: linear-gradient(45deg, #f43f5e, #f59e0b, #10b981, #0ea5e9, #8b5cf6);
  position: relative; overflow: hidden; border-color: var(--line);
}
.swatch.custom input[type="color"] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; border: 0; padding: 0; background: none;
}
[data-theme="dark"] .btn-edit { background: var(--primary-soft); }
[data-theme="dark"] .swatch.custom { border-color: var(--line); }

/* ===== 头像编辑（颜色 / 上传图片）===== */
.avatar-edit { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.avatar-edit .avatar { width: 56px; height: 56px; font-size: 20px; }
.avatar-edit-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.avatar-edit-actions .btn { padding: 6px 14px; font-size: 13px; }
#e-upload-btn:disabled { opacity: .6; cursor: default; }
.avatar-hint { font-size: 12px; color: var(--muted); }

/* ===== 下拉刷新指示器（仅旋转，无文字） ===== */
.ptr {
  height: 0; overflow: hidden; display: flex; align-items: center; justify-content: center;
  gap: 8px; transition: height .15s ease-out;
}
.ptr-spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--primary);
  display: inline-block;
}
.ptr.loading .ptr-spinner { animation: ptr-rotate .8s linear infinite; }
@keyframes ptr-rotate { to { transform: rotate(360deg); } }

/* ===== 发布：书籍搜索选择 ===== */
.book-picker { position: relative; }
#f-book-search {
  width: 100%; box-sizing: border-box;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 14px; line-height: 1.4; outline: none; font-family: inherit;
  background: var(--input-bg); color: var(--text);
}
#f-book-search::placeholder { color: var(--muted); }
#f-book-search:focus { border-color: var(--primary); }
.book-results {
  /* 改为普通文档流：避免被 .panel 的 overflow:hidden 裁剪，结果完整显示且可点击 */
  margin-top: 8px;
  background: var(--card-bg); border: 1px solid var(--line); border-radius: 12px;
  max-height: 280px; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.book-opt {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; font-size: 14px;
  cursor: pointer; border-bottom: 1px solid var(--line); min-width: 0;
}
.book-opt .bo-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-opt .bo-title { color: var(--text); font-weight: 600; font-size: 13px; }
.book-opt .bo-author { color: var(--muted); font-size: 13px; }
.book-opt:last-child { border-bottom: none; }
.book-opt:hover { background: var(--input-bg); }
.book-opt.add { color: var(--primary); font-weight: 600; }
.book-opt.empty { color: var(--muted); cursor: default; }
.book-opt.empty:hover { background: transparent; }
.book-opt.cur { background: var(--primary-soft); }
.book-opt.cur:hover { background: var(--primary-soft); }
.book-opt .bo-cur { margin-left: auto; flex: 0 0 auto; font-size: 12px; color: var(--primary); font-weight: 700; }
.book-cover.sm {
  width: 28px; height: 28px; border-radius: 6px; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px; font-weight: 700; letter-spacing: .5px;
  writing-mode: vertical-rl; line-height: 1.1;
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}
.selected-book { margin: 0 0 8px; display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 8px 10px; background: var(--primary-soft); border: 1px solid var(--primary); border-radius: 10px; color: var(--text); min-width: 0; }
.selected-book .bo-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selected-book .meta { color: var(--muted); }

/* 发布：书籍选择头部——色块图标 + 突出整行，作为「当前书籍」选择条 */
#bookPanelHead { background: var(--primary-soft); border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--text); padding: 13px 14px; transition: background .15s; }
#bookPanelHead:hover { background: #e3e8ff; }
#bookPanelHead .book-head-main { display: flex; align-items: center; gap: 8px; min-width: 0; }
#bookPanelHead .book-cover.sm { flex: 0 0 auto; } /* 收缩行色块图标与项目一致，避免被拉伸 */
#bookPanelHead .panel-caret { color: var(--primary); font-size: 16px; font-weight: 700; line-height: 1; }
/* 分享界面「字体·字号·颜色」三角，沿用搜索书籍三角风格（primary 色 / 16px / 700） */
#fontPanelHead .panel-caret { color: var(--primary); font-size: 16px; font-weight: 700; line-height: 1; }
/* 发布头部：书名加粗、作者名不加粗（与书名区分层级） */
#bookPanelAuthor { font-weight: 400; opacity: .8; margin-left: 2px; }
/* 深色模式：primary-soft 带紫调与亮色块图标叠在一起刺眼，改用中性 input-bg + 细边框保持轮廓 */
[data-theme="dark"] #bookPanelHead { background: var(--input-bg); border: 1px solid var(--line); }
[data-theme="dark"] #bookPanelHead:hover { background: #232b42; }

/* ===== 可见范围分段（样式由 .vis-seg 提供，发布弹窗元素同时挂 seg/vis-seg 两个类）===== */
/* 发布弹窗内的可见范围：独占整行、左右对齐，避免被通用 .seg 的页边距挤偏 */
.vis-block { display: flex; flex-direction: column; gap: 8px; }
.vis-seg { display: flex; width: 100%; margin: 0; padding: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.vis-seg .seg-btn { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 0; font-size: 14px; font-weight: 600; border-radius: 9px; color: var(--muted); background: transparent; opacity: .7; transition: all .18s; }
.vis-seg .seg-btn:hover:not(.on) { background: var(--input-bg); opacity: 1; }
.vis-seg .seg-btn.on { background: var(--primary); color: #fff; font-weight: 700; opacity: 1; box-shadow: 0 2px 8px rgba(79,70,229,.40); }
.vis-ico { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; }
.vis-hint { font-size: 12px; color: #15803d; margin: 0 2px; display: flex; align-items: center; gap: 6px; }
.vis-hint::before { content: "●"; font-size: 9px; line-height: 1; }
.vis-hint.private { color: #B45309; }
[data-theme="dark"] .vis-seg { background: var(--input-bg); }
[data-theme="dark"] .vis-hint { color: #4ADE80; }
[data-theme="dark"] .vis-hint.private { color: #FCD34D; }

/* ===== 分享弹窗 ===== */
.share-modal { max-width: 380px; }
.share-modal .modal-actions { gap: 8px; }
.share-modal .modal-actions .btn { flex: 1; padding: 10px 8px; font-size: 14px; }
.share-stage { display: flex; justify-content: center; margin: 4px 0 6px; }
#shareCanvas { width: 280px; height: 280px; border-radius: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.18); background: #eee; }
.bg-thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.bg-thumb {
  width: 62px; height: 62px; border-radius: 12px; cursor: pointer;
  position: relative; border: 2px solid transparent; overflow: hidden;
  display: flex; align-items: flex-end; transition: transform .12s;
}
.bg-thumb:hover { transform: translateY(-2px); }
.bg-thumb span {
  font-size: 10px; color: #fff; width: 100%; text-align: center; padding: 2px 0;
  background: rgba(0,0,0,.30); text-shadow: 0 1px 2px rgba(0,0,0,.5);
}
.bg-thumb.on { border-color: var(--primary); box-shadow: 0 0 0 2px #fff inset; }
.bg-thumb.add { background: rgba(79,70,229,.08); border: 2px dashed var(--primary); align-items: center; justify-content: center; }
.bg-thumb.add span { background: none; color: var(--primary); text-shadow: none; font-weight: 600; padding: 0; }
.bg-thumb.add:hover { background: rgba(79,70,229,.16); }
/* ===== 分享：字体 / 字号 / 颜色 可折叠面板 ===== */
.panel { margin-top: 12px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--card-bg); }
.panel-head { width: 100%; display: flex; align-items: center; justify-content: space-between; padding: 11px 14px; background: none; border: none; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--text); }
.panel-caret { color: var(--muted); font-size: 12px; transition: transform .18s; }
.panel-caret.open { transform: none; }
.panel-body { padding: 2px 14px 14px; border-top: 1px solid var(--line); }
.panel-body .field { margin-top: 12px; }
.panel-body .field > label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.label-row2 { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.label-row2 label { font-size: 12px; color: var(--muted); }
.opt-row { display: flex; gap: 8px; flex-wrap: wrap; }
.opt { border: 1px solid var(--line); background: var(--input-bg); color: var(--text); border-radius: 8px; padding: 6px 14px; font-size: 13px; cursor: pointer; transition: all .12s; }
.opt:hover { border-color: var(--primary); }
.opt.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.range { width: 100%; accent-color: var(--primary); cursor: pointer; }
.mini-val { font-size: 13px; color: var(--primary); font-weight: 600; }
.share-extra { display: flex; gap: 18px; justify-content: center; margin-top: 12px; }
.link-btn { background: none; border: none; color: var(--primary); font-size: 13px; cursor: pointer; padding: 0; }
.link-btn:hover { text-decoration: underline; }

/* ===== 私密徽标（独占一行，置于正文列之外）===== */
.badge-private {
  display: block; width: fit-content; font-size: 12px; color: #B45309;
  background: #FEF3C7; border-radius: 6px; padding: 2px 8px; margin: 0 0 8px;
}
[data-theme="dark"] .badge-private { color: #FCD34D; background: #3a2e12; }

/* ===== 消息中心 ===== */
/* 底栏「消息」按钮未读红点角标 */
.nav-btn { position: relative; }
.nav-badge {
  position: absolute; top: 2px; right: 50%; margin-right: -18px;
  min-width: 15px; height: 15px; padding: 0 3px;
  background: #ef4444; color: #fff;
  font-size: 10px;
  border-radius: 999px; text-align: center;
  box-shadow: 0 1px 3px rgba(239,68,68,.35);
  font-weight: 700; box-sizing: border-box;
  display: inline-flex; align-items: center; justify-content: center;
  pointer-events: none;
}
/* 关键：覆盖上面的 display，确保 unreadCount=0 时 hidden 真正生效，避免显示红「0」 */
.nav-badge[hidden] { display: none !important; }
.nav-badge-num { display: inline-block; transform: translateY(1px); }

/* 筛选条 + 全部已读按钮 */
.msg-toolbar {
  display: flex; flex-direction: column; align-items: stretch;
  gap: 10px; margin: 4px 0 14px;
}
.msg-toolbar .seg { flex: none; width: 100%; margin: 0; }
.msg-toolbar .read-all { align-self: flex-end; }
.btn-link {
  background: none; border: none; color: var(--primary);
  font-size: 13px; cursor: pointer; padding: 6px 4px; white-space: nowrap;
}
.btn-link:hover { text-decoration: underline; }

/* 通知条目 */
.notif-list { display: flex; flex-direction: column; gap: 8px; }
.notif {
  display: flex; gap: 12px; align-items: center;
  padding: 12px 14px; background: var(--card);
  border-radius: var(--radius); box-shadow: var(--shadow);
  cursor: pointer; transition: background .15s, transform .1s;
  border-left: 3px solid transparent;
}
.notif:hover { background: var(--primary-soft); }
.notif:active { transform: scale(.99); }
.notif.unread { border-left-color: var(--primary); background: var(--primary-soft); }
.notif.unread .notif-content { font-weight: 600; color: var(--text); }

.notif-icon {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 16px; font-weight: 700;
  flex-shrink: 0;
}
.notif-icon svg { width: 18px; height: 18px; stroke: currentColor; }
.notif-icon.like    { background: #ef4444; }
.notif-icon.comment { background: #4f46e5; }
.notif-icon.follow  { background: #10b981; }
.notif-icon.new_excerpt { background: #8b5cf6; }
.notif-icon.system  { background: #f59e0b; }

.notif-content {
  flex: 1; min-width: 0; font-size: 14px; line-height: 1.4; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis;
}
.notif-time { font-size: 12px; flex-shrink: 0; }

/* 暗色适配 */
[data-theme="dark"] .notif { background: var(--card); }
[data-theme="dark"] .notif:hover { background: rgba(79, 70, 229, .15); }
[data-theme="dark"] .notif.unread { background: rgba(79, 70, 229, .18); }
[data-theme="dark"] .btn-link { color: #a5b4fc; }

/* ===== 后台运营台 ===== */
body.admin-mode .app-header,
body.admin-mode .bottom-nav { display: none; }
body.admin-mode .app-view { padding: 0; max-width: 100%; }

.admin-shell { display: flex; min-height: 100vh; }
.admin-side {
  width: 200px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--line);
  padding: 16px 12px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.admin-logo { font-weight: 800; font-size: 16px; color: var(--primary); padding: 6px 8px 14px; }
.admin-side nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.admin-link {
  display: block; padding: 10px 12px; border-radius: 10px; color: var(--text);
  text-decoration: none; font-size: 14px; font-weight: 600;
}
.admin-link:hover { background: var(--primary-soft); }
.admin-link.active { background: var(--primary); color: #fff; }
.admin-logout {
  margin-top: 8px; padding: 9px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--muted); cursor: pointer; font-size: 13px; font-weight: 600;
}
.admin-logout:hover { color: #ef4444; border-color: #fecaca; }

.admin-main { flex: 1; padding: 20px 24px; max-width: 1000px; }
.admin-title { font-size: 20px; font-weight: 800; margin-bottom: 14px; }
.admin-count {
  font-size: 13px; font-weight: 600; color: var(--primary); background: var(--primary-soft);
  padding: 2px 9px; border-radius: 999px; margin-left: 6px;
}
.admin-toolbar { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; }
.admin-toolbar .btn { flex: 0 0 auto; padding: 10px 16px; }
.admin-input {
  flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  font-size: 14px; background: #fff; color: var(--text); font-family: inherit;
}
.admin-input:focus { outline: none; border-color: var(--primary); }

.admin-table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.admin-table th, .admin-table td { padding: 10px 12px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--line); }
.admin-table th { background: #f8fafc; font-weight: 700; color: var(--muted); }
/* 可点击排序的表头 */
.admin-table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.admin-table th.sortable:hover { background: #eef1fb; color: var(--primary); }
.admin-table th.sortable.active { color: var(--primary); }
.admin-table th.sortable.active:hover { background: #e7ebfa; }
[data-theme="dark"] .admin-table th.sortable:hover { background: #243049; color: #a5b4fc; }
[data-theme="dark"] .admin-table th.sortable.active { color: #a5b4fc; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tbody tr:hover { background: #fafbff; }
.cell-clip { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-num { white-space: nowrap; }
.cell-actions { white-space: nowrap; }
.cell-actions .btn { padding: 6px 10px; font-size: 12px; flex: 0 0 auto; margin-right: 4px; }

/* 摘要管理「精选」列横排：状态标签 + 切换按钮同一行 */
.cell-featured { text-align: center; }
.featured-row { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.featured-tag { font-size: 11px; padding: 2px 9px; border-radius: 999px; font-weight: 600; background: #e2e8f0; color: #64748b; }
.featured-tag.on { background: #fff7ed; color: #ea580c; }
[data-theme="dark"] .featured-tag { background: #334155; color: #94a3b8; }
[data-theme="dark"] .featured-tag.on { background: rgba(249,115,22,.16); color: #fdba74; }
.admin-filter-note { font-size: 12px; color: var(--muted); margin: 6px 0 10px; }
.admin-filter-note .btn { padding: 2px 8px; font-size: 12px; margin-left: 6px; }
.excerpt-snippet { max-width: 200px; color: var(--muted); }

.badge-status { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.badge-status.normal { background: #dcfce7; color: #16a34a; }
.badge-status.pending { background: #fef9c3; color: #ca8a04; }
.badge-status.removed { background: #fee2e2; color: #ef4444; }
.badge-status.open { background: #fee2e2; color: #ef4444; }
.badge-status.upheld { background: #fee2e2; color: #ef4444; }
.badge-status.dismissed { background: #e2e8f0; color: #64748b; }
.btn.danger, .btn-ghost.danger { color: #ef4444; }
.btn-ghost.danger:hover { background: #fee2e2; }

.admin-pager { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.admin-pager .btn { flex: 0 0 auto; padding: 8px 14px; }
.admin-pager-info { font-size: 13px; color: var(--muted); }
.admin-pager .btn[disabled] { opacity: .5; cursor: not-allowed; }

.data-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.data-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.data-card.danger { border: 1px solid #fecaca; }
.data-label { font-size: 13px; color: var(--muted); }
.data-val { font-size: 30px; font-weight: 800; margin: 6px 0 2px; }
.data-card.danger .data-val { color: #ef4444; }
.data-sub { font-size: 12px; color: var(--muted); }
.admin-quick { display: flex; gap: 10px; margin-top: 18px; }
.admin-quick .btn { flex: 0 0 auto; padding: 10px 16px; }

.admin-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; max-width: 560px; margin-bottom: 14px; }
.admin-card-title { font-weight: 700; font-size: 16px; margin-bottom: 6px; }
.admin-card-desc { font-size: 13px; color: var(--muted); margin-bottom: 14px; line-height: 1.6; }
.admin-card-result { margin-top: 12px; font-size: 13px; color: var(--text); }
.admin-card-result[hidden] { display: none; }

/* 书库导入进度条 + 逐主题详情 */
.lib-current { font-size: 13px; color: var(--primary); margin-bottom: 8px; font-weight: 600; }
.lib-progress { height: 10px; background: var(--bg); border-radius: 6px; overflow: hidden; margin: 6px 0 4px; }
.lib-progress-bar { height: 100%; background: var(--primary); border-radius: 6px; transition: width .4s ease; }
.lib-progress-text { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.lib-detail { border-top: 1px solid var(--border, #e2e8f0); margin-top: 4px; padding-top: 8px; }
.lib-detail-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; }
.lib-detail-icon { width: 18px; text-align: center; flex: none; }
.lib-detail-topic { font-weight: 600; flex: none; min-width: 120px; }
.lib-detail-info { color: var(--muted); font-size: 12px; }
.lib-detail-row.fail .lib-detail-info { color: #ef4444; }
.lib-done { font-size: 14px; font-weight: 700; margin-bottom: 6px; }

.admin-login { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.admin-login-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px; width: 320px; }
.admin-login-logo { font-weight: 800; font-size: 17px; color: var(--primary); margin-bottom: 6px; }
.admin-login-tip { font-size: 13px; color: var(--muted); margin-bottom: 16px; }
.admin-login-card .admin-input { width: 100%; margin-bottom: 12px; }
.admin-login-err { color: #ef4444; font-size: 13px; margin-top: 8px; }
.admin-login-err[hidden] { display: none; }
.admin-back-user { display: block; text-align: center; font-size: 13px; color: var(--primary); margin-top: 14px; text-decoration: none; }

/* 书库管理：书源选择行 */
.lib-source-row { font-size: 13px; color: var(--muted); margin: 10px 0 14px; }
.lib-source-row .admin-input { margin-left: 6px; padding: 5px 8px; }
.lib-done-note { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* 暗色适配 */
[data-theme="dark"] .admin-side,
[data-theme="dark"] .admin-table,
[data-theme="dark"] .data-card,
[data-theme="dark"] .admin-card,
[data-theme="dark"] .admin-login-card { background: #1e293b; }
[data-theme="dark"] .admin-table th { background: #0f172a; }
[data-theme="dark"] .admin-input { background: #0f172a; border-color: #334155; }
[data-theme="dark"] .admin-link:hover { background: rgba(79,70,229,.2); }
[data-theme="dark"] .admin-table tbody tr:hover { background: #243049; }
