/* ===== 共读 — 深色阅读主题 ===== */

:root {
  --bg: #0f0e0c;
  --bg-card: #171512;
  --bg-elevated: #1c1915;
  --text: #e8ddd0;
  --text-muted: #8a7e72;
  --text-dim: #5a5248;
  --accent: #d4a84b;
  --accent-dim: #a68a3e;
  --accent-green: #6b8e6b;
  --border: #2a2520;
  --font-serif: 'Noto Serif SC', 'STSong', 'Georgia', serif;
  --font-sans: 'Noto Sans SC', system-ui, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 15px; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: #e0c060; }

/* ===== 导航栏 ===== */
.nav-bar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  height: 48px;
  gap: 0.75rem;
}
.nav-brand {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-serif);
}
.nav-subtitle {
  color: var(--text-dim);
  font-size: 0.85rem;
}
.nav-center {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 0 1rem;
}
.search-form { width: 100%; max-width: 320px; }
.search-input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--accent-dim); }
.search-input::placeholder { color: var(--text-dim); }
.nav-right { margin-left: auto; }
.nav-link {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 0.25rem 0.75rem;
  border-radius: 4px;
}
.nav-link:hover { color: var(--text); background: var(--bg-elevated); }

.main-content { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-green);
  color: #fff;
  padding: 0.6rem 1.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 999;
  transition: opacity 0.3s;
}
.toast.hidden { opacity: 0; pointer-events: none; }

/* ===== 首页 ===== */
.home-header { text-align: center; padding: 2rem 0 1.5rem; }
.home-header h1 { font-family: var(--font-serif); font-size: 2rem; color: var(--accent); }
.home-desc { color: var(--text-muted); margin-top: 0.5rem; font-size: 0.95rem; }

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
  max-width: 800px;
  margin: 0 auto;
}
.book-card {
  display: flex;
  gap: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  transition: border-color 0.2s, background 0.2s;
}
.book-card:hover {
  border-color: var(--accent-dim);
  background: var(--bg-elevated);
}
.book-card-emoji { font-size: 2.5rem; }
.book-card-body { flex: 1; }
.book-title { font-size: 1.1rem; font-weight: 600; color: var(--accent); font-family: var(--font-serif); }
.book-author { color: var(--text-muted); font-size: 0.85rem; margin-top: 0.15rem; }
.book-desc { color: var(--text-dim); font-size: 0.85rem; margin-top: 0.3rem; }
.book-meta { margin-top: 0.5rem; font-size: 0.8rem; color: var(--text-dim); }

.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-dim);
}

/* ===== 书本页 ===== */
.book-page { max-width: 700px; margin: 0 auto; }
.book-header { margin-bottom: 1.5rem; }
.book-header h1 { font-family: var(--font-serif); font-size: 1.6rem; }
.back-link { color: var(--text-muted); font-size: 0.9rem; display: inline-block; margin-bottom: 0.5rem; }

.toc-tree ul { list-style: none; padding-left: 1.2rem; margin: 0.3rem 0; }
.toc-tree > ul { padding-left: 0; }
.toc-volume { margin: 0.5rem 0; }
.toc-folder {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.toc-volume > .toc-folder {
  font-weight: 600;
  color: var(--accent);
  font-family: var(--font-serif);
  font-size: 1.05rem;
}
.toc-chapter { margin: 0.15rem 0; }
.toc-chapter > .toc-folder { color: var(--text); font-size: 0.95rem; font-weight: 500; }
.toc-folder:hover { color: var(--accent); }
.toc-toggle { font-size: 0.7rem; color: var(--text-dim); min-width: 1em; }
.toc-folder:hover .toc-toggle { color: var(--accent); }
.toc-subtitle { color: var(--text-dim); font-size: 0.8rem; margin-left: 0.3rem; }
.toc-link {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.toc-link:hover { background: var(--bg-elevated); color: var(--text); }
.toc-link.active { color: var(--accent); background: rgba(212, 168, 75, 0.08); }
.toc-index { color: var(--text-dim); font-size: 0.8rem; min-width: 1.5rem; }

/* ===== 阅读三栏布局 ===== */
.read-layout {
  display: flex;
  gap: 0;
  height: calc(100vh - 48px);
  margin: -1.5rem;
}

/* 左侧目录 */
.read-sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 1rem 0.5rem;
  transition: width 0.2s, min-width 0.2s;
  position: relative;
  height: 100%;
}
.read-sidebar.collapsed {
  width: 40px;
  min-width: 40px;
  overflow: hidden;
}
.read-sidebar.collapsed .sidebar-content { display: none; }
.sidebar-toggle {
  position: absolute;
  top: 0.5rem;
  right: 0.25rem;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.25rem;
  z-index: 1;
}
.sidebar-toggle:hover { color: var(--text); }
.sidebar-content {
  padding-right: 0.5rem;
}
.sidebar-content .toc-tree > ul { padding-left: 0; }
.sidebar-content .toc-link {
  font-size: 0.85rem;
  padding: 0.2rem 0.4rem;
}

/* 中间：原文 */
.read-main {
  flex: 1;
  padding: 2rem 2.5rem;
  overflow-y: auto;
  max-width: 720px;
}
.passage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  font-size: 0.85rem;
}
.breadcrumb { color: var(--text-dim); }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb .sep { margin: 0 0.3rem; }
.passage-progress { color: var(--text-dim); }

.passage-text { margin-bottom: 2rem; }
.passage-title {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.25rem;
}
.passage-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}
.original-text {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 1.9;
  color: var(--text);
}
.original-text p { margin-bottom: 0.5rem; }

/* 注疏区域 */
.annotations-section {
  margin-top: 2rem;
  padding: 1rem 1.25rem;
  background: var(--bg-elevated);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.annotations-title {
  font-family: var(--font-serif);
  font-size: 1rem;
  color: var(--accent-dim);
  margin-bottom: 0.75rem;
}
.annotation-item {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  line-height: 1.6;
}
.annotation-marker {
  color: var(--accent);
  font-weight: 600;
  min-width: 2rem;
  flex-shrink: 0;
}
.annotation-text {
  color: var(--text-muted);
}

.passage-nav {
  display: flex;
  justify-content: space-between;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.nav-btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
  transition: background 0.2s;
}
.nav-btn:hover { background: var(--bg-elevated); }
.nav-btn.disabled { color: var(--text-dim); cursor: default; }
.nav-btn.disabled:hover { background: var(--bg-card); }

/* 右侧：讨论 */
.read-discuss {
  width: 360px;
  min-width: 360px;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
}
.discuss-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.discuss-header h3 { font-size: 1rem; }
.note-badge {
  font-size: 0.8rem;
  color: var(--accent-green);
  cursor: pointer;
}

.discuss-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
}
.discuss-placeholder {
  color: var(--text-dim);
  text-align: center;
  padding: 2rem 0;
  font-size: 0.9rem;
}

.msg { margin-bottom: 1rem; }
.msg-label { font-size: 0.8rem; font-weight: 600; margin-bottom: 0.25rem; }
.msg-user .msg-label { color: var(--accent); }
.msg-ai .msg-label { color: var(--accent-green); }
.msg-content {
  font-size: 0.9rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.discuss-input-area {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
}
.discuss-input {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.6rem;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
}
.discuss-input:focus { border-color: var(--accent-dim); }
.discuss-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.btn {
  padding: 0.45rem 1rem;
  border-radius: 6px;
  border: none;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
  font-family: var(--font-sans);
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent-dim); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent); }
.btn-secondary { background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-ghost { background: none; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }
.btn-success { background: var(--accent-green); color: #fff; }

/* 已有笔记 */
/* 笔记预览 */
.note-preview {
  flex: 1;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}
.note-preview-header h4 { font-size: 0.9rem; color: var(--accent); margin-bottom: 0.5rem; flex-shrink: 0; }
.note-preview-content {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.7;
  white-space: pre-wrap;
  background: var(--bg-elevated);
  padding: 0.75rem;
  border-radius: 6px;
  margin-bottom: 0.5rem;
  flex: 1;
  min-height: 150px;
  overflow-y: auto;
}
.note-preview-content:empty::before {
  content: 'AI 生成中...';
  color: var(--text-dim);
}
.note-preview-actions {
  display: flex;
  gap: 0.5rem;
}
.existing-notes { padding: 1rem 1.25rem; border-top: 1px solid var(--border); }
.existing-notes h4 { font-size: 0.9rem; margin-bottom: 0.5rem; color: var(--text-muted); }
.note-card {
  background: var(--bg-elevated);
  border-radius: 6px;
  padding: 0.6rem;
  margin-bottom: 0.5rem;
}
.note-summary { font-size: 0.85rem; color: var(--text-muted); }
.note-meta { font-size: 0.75rem; color: var(--text-dim); margin-top: 0.25rem; }

/* ===== 笔记页 ===== */
.notes-page { max-width: 800px; margin: 0 auto; }
.notes-header { margin-bottom: 1.5rem; }
.notes-header h1 { font-family: var(--font-serif); }
.notes-filter {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}
.filter-link {
  padding: 0.3rem 0.75rem;
  border-radius: 20px;
  font-size: 0.85rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.filter-link.active, .filter-link:hover {
  background: var(--accent-dim);
  color: #fff;
  border-color: var(--accent-dim);
}

.notes-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 0.75rem;
}
.notes-item-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-dim);
}
.notes-title { font-size: 1rem; color: var(--accent); margin: 0.3rem 0; }
.notes-preview { color: var(--text-muted); font-size: 0.9rem; }
.notes-tags { display: flex; gap: 0.3rem; margin-top: 0.4rem; flex-wrap: wrap; }
.tag {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  background: rgba(212, 168, 75, 0.12);
  color: var(--accent-dim);
}

/* ===== 笔记详情 ===== */
.note-detail-page { max-width: 700px; margin: 0 auto; }
.note-detail header { margin-bottom: 1.5rem; }
.note-detail header h1 { font-family: var(--font-serif); }
.note-detail-meta { display: flex; gap: 0.75rem; color: var(--text-dim); font-size: 0.85rem; margin-top: 0.3rem; align-items: center; }
.note-section { margin-bottom: 1.5rem; }
.note-section h2 { font-size: 1.1rem; color: var(--accent); margin-bottom: 0.5rem; font-family: var(--font-serif); }
.note-section p { color: var(--text-muted); line-height: 1.7; }
.note-section ol { color: var(--text-muted); padding-left: 1.2rem; }
.note-section ol li { margin-bottom: 0.3rem; }

.discussion-log { border-left: 2px solid var(--border); padding-left: 1rem; }
.log-entry { margin-bottom: 0.75rem; }
.log-entry strong { font-size: 0.8rem; }
.log-user strong { color: var(--accent); }
.log-ai strong { color: var(--accent-green); }
.log-entry p { margin-top: 0.2rem; font-size: 0.9rem; color: var(--text-muted); }

/* ===== 滚动条 ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
