/* ── 主题变量 ─────────────────────────────────── */
:root {
  --bg: #ffffff;
  --card: #f8f8f8;
  --border: #e5e5e5;
  --text: #1a1a1a;
  --muted: #888;
  --accent: #5b7fe8;
  --accent-dim: #eef1fd;
  --red: #e05252;
  --green: #3db87a;
  --orange: #e09a30;
  --sidebar-w: 280px;
  --topbar-h: 56px;
}
body.dark {
  --bg: #141414;
  --card: #1e1e1e;
  --border: #2e2e2e;
  --text: #e8e8e8;
  --muted: #666;
  --accent: #7b9ef5;
  --accent-dim: #1e2540;
  --red: #e06464;
  --green: #45c985;
  --orange: #f0aa40;
}

/* ── 基础 ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: "PingFang SC", "HarmonyOS Sans SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  transition: background .25s, color .25s;
}
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }

/* ── 工具类 ────────────────────────────────────── */
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ── 顶栏 ──────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 20px;
  gap: 12px; z-index: 100;
  transition: transform .3s ease;
}
/* 下划时隐藏顶栏 */
body.topbar-hidden .topbar {
  transform: translateY(-100%);
}
body.topbar-hidden .layout {
  margin-top: 0;
}
body.topbar-hidden .sidebar {
  top: 0;
}

.topbar-chapter {
  flex: 1; text-align: center;
  font-size: .95rem; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 0 8px;
}
.icon-btn {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 1.1rem; padding: 6px 8px;
  border-radius: 8px; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--border); color: var(--text); }

/* ── 布局 ──────────────────────────────────────── */
.layout {
  display: flex;
  margin-top: var(--topbar-h);
  min-height: calc(100vh - var(--topbar-h));
  transition: margin-top .3s ease;
}

/* 左侧边栏 */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  position: fixed;
  top: var(--topbar-h); left: 0; bottom: 0;
  overflow-y: auto;
  transition: transform .25s ease, top .3s ease;
  z-index: 90;
  display: flex; flex-direction: column;
}
.sidebar.collapsed { transform: translateX(-100%); }

.sidebar-head {
  padding: 16px 16px 8px;
  font-size: .75rem; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .08em;
}

/* 小说列表 */
.novel-item {
  padding: 10px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background .15s;
}
.novel-item:hover { background: var(--border); }
.novel-item.active { border-left-color: var(--accent); background: var(--accent-dim); }
.novel-item .novel-name { font-size: .95rem; font-weight: 600; color: var(--text); }
.novel-item .novel-meta { font-size: .75rem; color: var(--muted); margin-top: 2px; }

/* 侧栏底部 */
.sidebar-footer {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.logout-btn {
  width: 100%; padding: 8px;
  background: none; border: 1px solid var(--border);
  border-radius: 8px; color: var(--muted);
  font-size: .85rem; cursor: pointer;
  transition: all .15s;
}
.logout-btn:hover { border-color: var(--red); color: var(--red); }

/* 章节列表 */
.chapter-list { padding-bottom: 20px; }
.chapter-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px 8px 24px;
  cursor: pointer; font-size: .9rem;
  transition: background .15s;
}
.chapter-item:hover { background: var(--border); }
.chapter-item.active { color: var(--accent); font-weight: 600; }

/* ── 主内容 ─────────────────────────────────────── */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  transition: margin-left .25s;
  display: flex;
  flex-direction: column;
}
.main.sidebar-collapsed { margin-left: 0; }

/* 阅读器 */
.reader-area {
  flex: 1;
  max-width: 780px;
  margin: 0 auto;
  padding: 40px 24px 80px;
  width: 100%;
}

.chapter-title {
  font-size: 1.6rem; font-weight: 800;
  margin-bottom: 28px; color: var(--text);
  line-height: 1.4;
}
.chapter-content { font-size: 1.05rem; line-height: 1.95; color: var(--text); }
.chapter-content p { margin-bottom: 1.4em; text-indent: 2em; }
.chapter-content hr { border: none; border-top: 1px solid var(--border); margin: 1.5em auto; width: 40%; }
body.hide-dividers .chapter-content hr { display: none; }
.chapter-content h1, .chapter-content h2, .chapter-content h3 {
  margin: 1.5em 0 .8em; font-weight: 700;
}
.chapter-nav {
  display: flex; gap: 12px; justify-content: space-between;
  margin-top: 48px; padding-top: 24px;
  border-top: 1px solid var(--border);
}
.nav-btn {
  padding: 10px 20px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  cursor: pointer; font-size: .9rem; color: var(--text);
  transition: border-color .2s, background .2s;
  flex: 1; text-align: center;
}
.nav-btn:hover { border-color: var(--accent); background: var(--accent-dim); }
.nav-btn:disabled { opacity: .35; cursor: not-allowed; }

/* 空态 */
.empty-state { text-align: center; padding: 80px 24px; color: var(--muted); }
.empty-state .big { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: 1rem; }


/* ── 搜索栏 ──────────────────────────────────────── */
.search-bar {
  position: fixed; top: var(--topbar-h); left: var(--sidebar-w); right: 0;
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: 10px 16px; z-index: 95;
  display: flex; flex-direction: column; gap: 0;
  transition: left .25s;
}
body.topbar-hidden .search-bar { top: 0; }
.search-row { display: flex; align-items: center; gap: 6px; }
.search-counter {
  font-size: .78rem; color: var(--accent); white-space: nowrap;
  background: var(--accent-dim); border-radius: 10px;
  padding: 2px 10px; font-weight: 600; text-align: center;
}
.search-nav-btn { padding: 5px 8px; font-size: 1rem; }
.search-nav-btn:disabled { opacity: .3; cursor: not-allowed; }
.search-input {
  flex: 1; min-width: 0; padding: 8px 12px;
  background: var(--bg); border: 1.5px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: .95rem; font-family: inherit;
  outline: none; transition: border-color .2s;
}
.search-input:focus { border-color: var(--accent); }
.search-close-btn { color: var(--text) !important; font-size: 1rem; opacity: .7; }
.search-close-btn:hover { opacity: 1; }
.search-hl { background: rgba(255,200,0,.35); border-radius: 2px; }
.search-hl.current { background: rgba(255,130,0,.7); color: #fff; border-radius: 2px; }
body.dark .search-hl { background: rgba(255,200,0,.2); }
body.dark .search-hl.current { background: rgba(255,140,0,.6); color: #fff; }

/* 搜索栏布局调整（有侧栏时） */
.search-bar.sidebar-collapsed { left: 0; }
@media (max-width: 768px) {
  .search-bar { left: 0; }
}

/* ── 批注气泡（桌面：浮动；移动：底部固定条） ──── */
.ann-bubble {
  position: fixed; z-index: 200;
  background: var(--text); color: var(--bg);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
  pointer-events: auto;
}
.ann-bubble::after {
  content: ''; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: var(--text);
}
.ann-bubble.flipped::after {
  top: auto; bottom: 100%;
  border-top-color: transparent; border-bottom-color: var(--text);
}
.ann-bubble-btn {
  background: none; border: none; cursor: pointer;
  color: inherit; font-size: .9rem; font-weight: 600;
  padding: 10px 18px; white-space: nowrap;
  min-height: 44px;
  display: flex; align-items: center; gap: 6px;
}

/* 移动端：底部全宽固定条，避开系统弹窗 */
@media (max-width: 768px) {
  .ann-bubble {
    left: 0 !important; right: 0 !important;
    top: auto !important;
    bottom: 0;
    border-radius: 10px 10px 0 0;
    display: flex; justify-content: center;
  }
  .ann-bubble::after, .ann-bubble.flipped::after { display: none; }
  .ann-bubble-btn { width: 100%; justify-content: center; font-size: 1rem; padding: 14px; }
}

/* ── 批注高亮 ─────────────────────────────────────── */
.ann-pending {
  background: rgba(255, 180, 0, .45);
  border-bottom: 2px solid rgba(255, 140, 0, .9);
  border-radius: 2px;
}
body.dark .ann-pending {
  background: rgba(255, 200, 0, .3);
  border-bottom: 2px solid rgba(255, 180, 0, .8);
}
.ann-mark {
  background: rgba(255, 214, 0, .28);
  border-bottom: 2px solid rgba(255, 180, 0, .7);
  border-radius: 2px; cursor: pointer;
  transition: background .15s;
}
.ann-mark:hover { background: rgba(255, 180, 0, .45); }
body.dark .ann-mark { background: rgba(255, 200, 0, .18); }
body.dark .ann-mark:hover { background: rgba(255, 200, 0, .32); }
.ann-mark.ann-mark-focus {
  animation: annFlash .6s ease 2;
}
@keyframes annFlash {
  0%, 100% { background: rgba(255, 214, 0, .28); }
  50% { background: rgba(255, 140, 0, .65); }
}

/* ── 批注弹窗 ─────────────────────────────────────── */
.ann-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 300; padding: 20px;
}
.ann-modal-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 24px; width: 100%; max-width: 420px;
  box-shadow: 0 12px 48px rgba(0,0,0,.2);
}
/* 手机端：底部弹出 sheet */
@media (max-width: 768px) {
  .ann-modal {
    align-items: flex-end;
    padding: 0;
  }
  .ann-modal-card {
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
    max-width: 100%;
    animation: slideUp .22s ease;
  }
  .ann-modal-input { font-size: 1rem; } /* 防止 iOS 自动缩放 */
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.ann-modal-title { font-size: 1rem; font-weight: 700; margin-bottom: 12px; }
.ann-modal-anchor {
  font-size: .85rem; color: var(--muted);
  background: var(--bg); border-left: 3px solid var(--accent);
  padding: 6px 10px; border-radius: 4px; margin-bottom: 12px;
  line-height: 1.6;
}
.ann-modal-input {
  width: 100%; padding: 10px 12px;
  background: var(--bg); border: 1.5px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: .9rem;
  font-family: inherit; resize: vertical; outline: none;
  transition: border-color .2s; margin-bottom: 14px;
}
.ann-modal-input:focus { border-color: var(--accent); }
.ann-modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.ann-cancel-btn {
  padding: 8px 18px; background: none; border: 1px solid var(--border);
  border-radius: 8px; color: var(--muted); cursor: pointer; font-size: .88rem;
  transition: all .15s;
}
.ann-cancel-btn:hover { border-color: var(--text); color: var(--text); }
.ann-confirm-btn {
  padding: 8px 18px; background: var(--accent); color: #fff;
  border: none; border-radius: 8px; cursor: pointer;
  font-size: .88rem; font-weight: 600; transition: opacity .2s;
}
.ann-confirm-btn:hover { opacity: .85; }
.ann-delete-btn {
  padding: 8px 18px; background: none; border: 1px solid var(--red);
  border-radius: 8px; color: var(--red); cursor: pointer;
  font-size: .88rem; transition: all .15s;
}
.ann-delete-btn:hover { background: var(--red); color: #fff; }
.ann-view-note {
  font-size: .95rem; line-height: 1.7; color: var(--text);
  margin-bottom: 8px; white-space: pre-wrap;
}
.ann-modal-meta { font-size: .78rem; color: var(--muted); margin-bottom: 14px; }

/* ── 加载动画 ────────────────────────────────────── */
.spinner {
  display: inline-block; width: 20px; height: 20px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 移动端适配 ──────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 100vw; }

  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }

  .main { margin-left: 0 !important; }
  .reader-area { padding: 24px 16px 64px; }
  .chapter-title { font-size: 1.3rem; }
  .chapter-content { font-size: .98rem; }

  .sidebar-overlay {
    display: none;
    position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 85;
  }
  .sidebar-overlay.show { display: block; }
}


/* ── 搜索栏滑入动画 ──────────────────────────────── */
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
body.search-open .search-bar { animation: slideDown .2s ease; }

/* ── PC 顶栏面包屑 ───────────────────────────────── */
.topbar-breadcrumb {
  flex: 1; display: flex; align-items: center; gap: 6px;
  overflow: hidden; min-width: 0;
}
.breadcrumb-novel {
  font-size: .8rem; color: var(--muted); white-space: nowrap;
  flex-shrink: 0; max-width: 160px;
  overflow: hidden; text-overflow: ellipsis;
}
.breadcrumb-sep { color: var(--border); flex-shrink: 0; }
.breadcrumb-chapter {
  font-size: .95rem; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
