/* 司南·典籍阁 — 手机优先电子书阅读站 */
/* 支持：古纸（antique）/ 夜间（night）双色主题，竖排阅读，字号可调 */

/* ─── CSS 变量 ─── */
:root {
  --font-size: 18px;
  --line-height: 1.9;

  /* 古纸主题（默认） */
  --bg: #f5ead4;
  --bg-card: #fdf5e6;
  --bg-header: #8b5e3c;
  --text: #3a2009;
  --text-muted: #7a5c3a;
  --text-light: #b8916a;
  --accent: #8b2500;
  --accent-light: #c4763a;
  --border: #d4b896;
  --shadow: rgba(58,32,9,0.10);
  --tag-bg: #eedfc2;
  --btn-bg: #8b5e3c;
  --btn-text: #fdf5e6;
  --reader-bg: #fdf5e6;
}

[data-theme="night"] {
  --bg: #1a1208;
  --bg-card: #231a0e;
  --bg-header: #120d05;
  --text: #e8d5b0;
  --text-muted: #b0935e;
  --text-light: #7a6040;
  --accent: #d4824a;
  --accent-light: #e09a66;
  --border: #3a2a15;
  --shadow: rgba(0,0,0,0.4);
  --tag-bg: #2d1f0a;
  --btn-bg: #4a3018;
  --btn-text: #e8d5b0;
  --reader-bg: #1e1508;
}

/* ─── 基础重置 ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: var(--font-size); scroll-behavior: smooth; }
body {
  font-family: "STSong", "SimSun", "Songti SC", "Source Han Serif SC", Georgia, serif;
  background: var(--bg);
  color: var(--text);
  line-height: var(--line-height);
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; border: none; outline: none; font-family: inherit; }

/* ─── 页头 ─── */
.site-header {
  background: var(--bg-header);
  color: var(--btn-text);
  padding: 0 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: 52px;
  box-shadow: 0 2px 8px var(--shadow);
}
.site-header .logo {
  font-size: 1.1rem;
  font-weight: bold;
  letter-spacing: 0.05em;
  color: #fdf5e6;
  white-space: nowrap;
}
.site-header .subtitle {
  font-size: 0.7rem;
  opacity: 0.7;
  flex: 1;
}
.header-btn {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  color: #fdf5e6;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 0.75rem;
  transition: background 0.2s;
}
.header-btn:hover { background: rgba(255,255,255,0.25); }

/* ─── 搜索栏 ─── */
.search-bar {
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.search-bar input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.search-bar input:focus { border-color: var(--accent); }
.search-bar input::placeholder { color: var(--text-light); }

/* ─── 分类标签栏 ─── */
.cat-tabs {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}
.cat-tabs::-webkit-scrollbar { display: none; }
.cat-tab {
  white-space: nowrap;
  padding: 0.3rem 0.75rem;
  border-radius: 16px;
  font-size: 0.8rem;
  background: var(--tag-bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: all 0.2s;
}
.cat-tab.active, .cat-tab:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ─── 书架 ─── */
.bookshelf {
  padding: 1rem;
  max-width: 800px;
  margin: 0 auto;
}
.section-heading {
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  color: var(--text-light);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
  margin: 1.2rem 0 0.75rem;
  text-transform: uppercase;
}
.section-heading:first-of-type { margin-top: 0.25rem; }

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
}
@media (max-width: 380px) {
  .book-grid { grid-template-columns: repeat(2, 1fr); }
}

.book-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem 0.75rem;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  box-shadow: 0 1px 4px var(--shadow);
  position: relative;
}
.book-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
}
.book-card:active { transform: translateY(0); }

.book-title {
  font-size: 1rem;
  font-weight: bold;
  color: var(--text);
  line-height: 1.3;
}
.book-author {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.4;
}
.book-dynasty {
  font-size: 0.68rem;
  color: var(--text-light);
}
.book-status {
  margin-top: auto;
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 0.65rem;
  display: inline-block;
  width: fit-content;
}
.book-status.pending { background: #fff3cd; color: #856404; }
.book-status.partial { background: #d1ecf1; color: #0c5460; }
.book-status.done { background: #d4edda; color: #155724; }
.book-alias-note {
  position: absolute;
  top: 6px; right: 6px;
  font-size: 0.6rem;
  background: #ffeeba;
  color: #856404;
  padding: 1px 4px;
  border-radius: 4px;
}

/* ─── 书目详情页 ─── */
.book-detail {
  max-width: 700px;
  margin: 0 auto;
  padding: 1rem;
}
.book-detail-header {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.2rem;
  margin-bottom: 1rem;
}
.book-detail-title {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--text);
}
.book-detail-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}
.book-detail-meta {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.meta-chip {
  background: var(--tag-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 0.72rem;
  color: var(--text-muted);
}
.meta-chip.warning { background: #fff3cd; border-color: #ffc107; color: #856404; }

.book-detail-note {
  margin-top: 0.75rem;
  padding: 0.6rem 0.75rem;
  background: #fffbe6;
  border-left: 3px solid #f0b429;
  border-radius: 4px;
  font-size: 0.8rem;
  color: #7a5c3a;
  line-height: 1.6;
}
[data-theme="night"] .book-detail-note {
  background: #2a2000;
  color: #c8a86e;
  border-left-color: #c88a30;
}

.book-detail-source {
  margin-top: 0.6rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.book-detail-source a { color: var(--accent); }

.section-title {
  font-size: 0.85rem;
  font-weight: bold;
  color: var(--text-muted);
  margin: 1rem 0 0.5rem;
  letter-spacing: 0.05em;
}

/* ─── 片段引文列表 ─── */
.fragment-list { display: flex; flex-direction: column; gap: 0.6rem; }
.fragment-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  cursor: pointer;
  transition: background 0.15s;
}
.fragment-item:hover { background: var(--tag-bg); }
.fragment-ref {
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: bold;
  margin-bottom: 0.3rem;
}
.fragment-text {
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.8;
}
.fragment-source {
  margin-top: 0.3rem;
  font-size: 0.65rem;
  color: var(--text-light);
}

/* 待补提示 */
.pending-notice {
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.pending-notice .icon { font-size: 2rem; margin-bottom: 0.5rem; }
.pending-notice a { color: var(--accent); }

/* ─── 阅读器 ─── */
.reader-container {
  background: var(--reader-bg);
  min-height: calc(100vh - 52px);
}
.reader-toolbar {
  position: sticky;
  top: 52px;
  z-index: 90;
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.reader-toolbar .breadcrumb {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.fs-btn {
  background: var(--tag-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 0.8rem;
}
.fs-btn:hover { background: var(--border); }

/* 竖排阅读内容 */
.reader-content {
  padding: 1.5rem 1rem;
  max-width: 700px;
  margin: 0 auto;
}
.reader-content.vertical {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  column-count: 2;
  column-gap: 2rem;
  height: calc(100vh - 120px);
  overflow-x: auto;
  overflow-y: hidden;
}
.reader-content.horizontal {
  writing-mode: horizontal-tb;
}

.chapter-heading {
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--accent);
  margin-bottom: 1rem;
}
.passage-text {
  font-size: 1rem;
  line-height: var(--line-height);
  color: var(--text);
  text-align: justify;
  white-space: pre-wrap;
}
.passage-source {
  margin-top: 1.5rem;
  font-size: 0.7rem;
  color: var(--text-light);
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
}
.passage-block {
  margin-bottom: 1.6rem;
  padding-bottom: 1.2rem;
  border-bottom: 1px dashed var(--border);
}
.passage-block:last-of-type { border-bottom: none; }
.passage-attr {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  font-style: italic;
}
.passage-note {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  padding: 0.4rem 0.6rem;
  background: var(--tag-bg);
  border-left: 3px solid var(--accent-light);
  border-radius: 0 4px 4px 0;
  line-height: 1.6;
}
.passage-pending {
  color: var(--text-light);
  font-style: italic;
  padding: 0.6rem 0;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.pending-chapter { opacity: 0.6; }
.pending-chapter .fragment-text { font-style: italic; }

/* ─── 返回按钮 ─── */
.back-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--btn-text);
  background: none;
  font-size: 0.85rem;
  padding: 4px 0;
}

/* ─── 加载提示 ─── */
.loading {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ─── 版权声明 ─── */
.license-footer {
  padding: 1rem;
  text-align: center;
  font-size: 0.65rem;
  color: var(--text-light);
  border-top: 1px solid var(--border);
  line-height: 1.8;
  margin-top: 2rem;
}
.license-footer a { color: var(--accent-light); }

/* ─── 搜索结果高亮 ─── */
mark {
  background: #fff176;
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
}
[data-theme="night"] mark { background: #5a4000; }

/* ─── 无障碍 ─── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ─── 动画 ─── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn 0.25s ease; }

/* ─── 字号浮层 ─── */
.fs-panel {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  box-shadow: 0 4px 16px var(--shadow);
  z-index: 200;
  transition: opacity 0.2s;
}
.fs-panel.hidden { opacity: 0; pointer-events: none; }
.fs-label { font-size: 0.75rem; color: var(--text-muted); }
.fs-step {
  width: 32px; height: 32px;
  background: var(--btn-bg);
  color: var(--btn-text);
  border-radius: 6px;
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
}

/* ─── 竖排切换 ─── */
.orientation-btn {
  background: var(--tag-bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 0.75rem;
}
.orientation-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
