/* 资治通鉴 AI 深度解析 - 日系极简雅致版样式 */

/* === 1. 变量与日式传统色定义 === */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-serif: "Noto Serif SC", "Georgia", "Source Han Serif", serif;
  
  --transition-speed: 0.35s;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* 鸟之子色/和纸复古主题 (默认) */
body.theme-paper {
  --bg-color: #faf7f0;       /* 象牙白/和纸色 */
  --bg-card: #f3efe6;       /* 练色，微深 */
  --text-main: #2b2521;      /* 墨色 */
  --text-meta: #7c7267;      /* 焦茶 */
  --primary-color: #a63f2b;   /* 朱砂红，点睛之笔 */
  --border-color: #e5ded0;   /* 极细浅边 */
  --accent-line: #d8cbb5;
  --shadow-color: rgba(43, 37, 33, 0.03);
  --blockquote-bg: #f4f0e6;
  --blockquote-border: #a63f2b;
}

/* 苔绿/静谧若竹主题 */
body.theme-green {
  --bg-color: #f1f3ec;       /* 白练绿 */
  --bg-card: #e4e8dc;       /* 浅苔 */
  --text-main: #1c261e;      /* 深绿褐 */
  --text-meta: #627265;      /* 浅海松茶 */
  --primary-color: #2b5c3e;   /* 千岁绿 */
  --border-color: #d6ded0;
  --accent-line: #b3c2ae;
  --shadow-color: rgba(28, 38, 30, 0.03);
  --blockquote-bg: #e6eade;
  --blockquote-border: #2b5c3e;
}

/* 漆黑/暗夜静思主题 */
body.theme-night {
  --bg-color: #141517;       /* 漆黑 */
  --bg-card: #1c1e21;       /* 墨灰 */
  --text-main: #959da5;      /* 鼠色 */
  --text-meta: #5a626a;      /* 暗焦茶 */
  --primary-color: #bd8dc9;   /* 藤紫 */
  --border-color: #272a2e;
  --accent-line: #424950;
  --shadow-color: rgba(0, 0, 0, 0.2);
  --blockquote-bg: #191b1d;
  --blockquote-border: #bd8dc9;
}

/* 极简素白主题 */
body.theme-light {
  --bg-color: #faf9f8;       /* 素白 */
  --bg-card: #ffffff;
  --text-main: #202020;      /* 纯黑 */
  --text-meta: #808080;
  --primary-color: #c62828;   /* 绯红 */
  --border-color: #ecebeb;
  --accent-line: #dcdcdc;
  --shadow-color: rgba(0, 0, 0, 0.02);
  --blockquote-bg: #f5f4f3;
  --blockquote-border: #c62828;
}

/* === 2. 基础重置 === */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-serif); /* 默认全面使用宋体，拉满日系文学感 */
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.9; /* 大气的行高 */
  transition: background-color var(--transition-speed), color var(--transition-speed);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary-color);
  text-decoration: none;
}

/* === 3. 页面布局与导航 === */
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  background-color: var(--primary-color); /* 单色细线，避开廉价渐变 */
  width: 0%;
  z-index: 1001;
  transition: width 0.15s ease;
}

.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(52px + var(--safe-top));
  padding-top: var(--safe-top);
  background-color: rgba(250, 247, 240, 0.85); /* 朦胧半透明 */
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 0.5px solid var(--border-color); /* 极细线 */
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 16px;
  padding-right: 16px;
  z-index: 999;
  transition: transform 0.3s cubic-bezier(0.1, 0.9, 0.2, 1), background-color var(--transition-speed), border-color var(--transition-speed);
}

body.theme-green .navbar { background-color: rgba(241, 243, 236, 0.85); }
body.theme-night .navbar { background-color: rgba(20, 21, 23, 0.85); }
body.theme-light .navbar { background-color: rgba(250, 249, 248, 0.85); }

.navbar.hidden {
  transform: translateY(-100%);
}

.navbar-title {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 1px;
  max-width: 60%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--text-main);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 0.2s;
}

.nav-btn:active {
  opacity: 1;
}

/* === 4. 侧滑目录 === */
.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.25);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
  z-index: 1000;
}

.sidebar-overlay.active {
  opacity: 1;
  visibility: visible;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 82%;
  max-width: 290px;
  background-color: var(--bg-color);
  z-index: 1000;
  transform: translateX(-100%);
  transition: transform 0.35s cubic-bezier(0.15, 0.85, 0.3, 1);
  box-shadow: 1px 0 10px rgba(0,0,0,0.05);
  display: flex;
  flex-direction: column;
  border-right: 0.5px solid var(--border-color);
}

.sidebar.active {
  transform: translateX(0);
}

.sidebar-header {
  height: calc(52px + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 20px;
  padding-right: 12px;
  border-bottom: 0.5px solid var(--border-color);
}

.sidebar-header h2 {
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 1px;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-main);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.6;
}

.toc-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 6px;
  -webkit-overflow-scrolling: touch;
}

/* 目录折叠组样式 */
.toc-group {
  margin-bottom: 4px;
}

.toc-group-header {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-main);
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.toc-group-header:active {
  background-color: var(--bg-card);
}

.toc-group-header .arrow-icon {
  font-size: 9px;
  opacity: 0.5;
  transition: transform 0.2s;
}

.toc-group.collapsed .toc-group-header .arrow-icon {
  transform: rotate(-90deg);
}

.toc-group-items {
  margin-top: 2px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: 1000px;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}

.toc-group.collapsed .toc-group-items {
  max-height: 0;
  margin-top: 0;
}

.toc-item {
  font-size: 13px;
  padding: 8px 24px;
  border-radius: 4px;
  color: var(--text-meta);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background-color 0.2s, color 0.2s;
}

.toc-item:active, .toc-item.active {
  background-color: var(--bg-card);
  color: var(--primary-color);
  font-weight: 500;
}

/* === 5. 阅读设置面板 === */
.settings-panel {
  position: fixed;
  top: calc(58px + var(--safe-top));
  right: 16px;
  background-color: var(--bg-card);
  border: 0.5px solid var(--border-color);
  border-radius: 8px;
  padding: 14px;
  box-shadow: 0 4px 12px var(--shadow-color);
  z-index: 998;
  display: none;
  flex-direction: column;
  gap: 12px;
  min-width: 220px;
  animation: fadeIn 0.15s ease;
}

.settings-panel.active {
  display: flex;
}

.settings-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-label {
  font-size: 13px;
  color: var(--text-meta);
  font-weight: 500;
}

.theme-options {
  display: flex;
  gap: 10px;
}

.theme-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid transparent;
  cursor: pointer;
  outline: none;
}

.theme-btn.active {
  border-color: var(--primary-color);
}

.btn-theme-paper { background-color: #faf7f0; border-color: #e5ded0; }
.btn-theme-green { background-color: #f1f3ec; border-color: #d6ded0; }
.btn-theme-night { background-color: #1c1e21; }
.btn-theme-light { background-color: #ffffff; border-color: #ecebeb; }

.font-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.font-btn {
  background: var(--bg-color);
  border: 0.5px solid var(--border-color);
  color: var(--text-main);
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font-sans);
}

.font-btn:active {
  background-color: var(--border-color);
}

.font-size-val {
  font-size: 13px;
  min-width: 40px;
  text-align: center;
  font-family: var(--font-sans);
}

/* === 6. 主内容容器 === */
.app-container {
  margin-top: calc(52px + var(--safe-top));
  padding-bottom: calc(40px + var(--safe-bottom));
  min-height: calc(100vh - 52px - var(--safe-top));
}

.view-section {
  display: none;
  animation: fadeIn 0.3s ease;
}

.view-section.active {
  display: block;
}

/* === 7. 首页视图 (Home View) === */
#view-home {
  max-width: 620px;
  margin-left: auto;
  margin-right: auto;
  padding: 30px 20px;
}

.home-hero {
  text-align: center;
  padding: 50px 0 35px;
}

.home-hero h1 {
  font-family: var(--font-serif);
  font-size: 32px;
  font-weight: 500; /* 日系偏爱中粗体，避免过重 */
  letter-spacing: 6px;
  color: var(--text-main);
}

.home-hero .subtitle {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-meta);
  letter-spacing: 3px;
  margin-top: 12px;
  font-weight: 400;
  font-family: var(--font-sans);
}

/* 续读卡片 - 日式极简便签风格 */
.continue-reading {
  background-color: var(--bg-card);
  border: 0.5px solid var(--border-color);
  border-radius: 6px;
  padding: 16px 20px;
  margin-bottom: 36px;
  box-shadow: 0 1px 4px var(--shadow-color);
}

.continue-reading .card-title {
  font-size: 11px;
  color: var(--primary-color);
  font-weight: 500;
  letter-spacing: 1px;
  margin-bottom: 6px;
  font-family: var(--font-sans);
}

.continue-reading .card-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.reading-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.last-book {
  font-size: 11px;
  color: var(--text-meta);
  font-family: var(--font-sans);
}

.last-chapter {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 600;
}

.last-progress {
  font-size: 11px;
  color: var(--text-meta);
  font-family: var(--font-sans);
}

.btn-continue {
  border: 0.5px solid var(--primary-color);
  color: var(--primary-color);
  padding: 6px 16px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.25s;
  font-family: var(--font-sans);
}

.btn-continue:active {
  background-color: var(--primary-color);
  color: #ffffff;
}

.section-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-meta);
  margin-bottom: 16px;
  padding-left: 8px;
  border-left: 2px solid var(--primary-color); /* 朱红色细竖线 */
  letter-spacing: 1px;
  font-family: var(--font-sans);
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (min-width: 480px) {
  .book-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.book-card {
  background-color: var(--bg-color);
  border: 0.5px solid var(--border-color);
  border-radius: 4px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, background-color 0.2s;
  min-height: 80px;
  text-align: center;
}

.book-card:active {
  background-color: var(--bg-card);
  transform: scale(0.98);
}

.book-card-name {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 2px;
}

.book-card-count {
  font-size: 10px;
  color: var(--text-meta);
  font-family: var(--font-sans);
}

/* === 8. 阅读视图 (Reader View) === */
.article-container {
  max-width: 600px; /* 适度收窄，移动端最佳视线宽度 */
  margin-left: auto;
  margin-right: auto;
  padding: 20px 24px;
}

.article-header {
  border-bottom: 0.5px solid var(--border-color);
  padding-bottom: 20px;
  margin-bottom: 32px;
  text-align: center; /* 居中排版，经典日系文学风 */
}

.article-meta-book {
  font-size: 11px;
  color: var(--primary-color);
  letter-spacing: 2px;
  font-weight: 500;
  margin-bottom: 8px;
  font-family: var(--font-sans);
}

.article-title {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 500;
  line-height: 1.4;
  letter-spacing: 2px;
}

/* === 9. Markdown 渲染精细排版 === */
.article-content {
  font-size: 18px; /* 由JS控制 */
  color: var(--text-main);
  line-height: 1.9; /* 宽裕行高，阅读极度舒适 */
  word-wrap: break-word;
}

/* 传统书籍段落排版：首行缩进 2 字符 */
.article-content p {
  margin-bottom: 1.5em;
  text-align: justify;
  text-justify: inter-character;
  text-indent: 2em; /* 缩进 */
}

/* 古文原文区块样式 */
.article-content blockquote {
  background-color: var(--blockquote-bg);
  border-left: 2px solid var(--blockquote-border);
  padding: 12px 18px;
  margin: 2em 0;
  border-radius: 0 4px 4px 0;
  box-shadow: none; /* 拒绝廉价阴影 */
  border-top: 0.5px solid var(--border-color);
  border-right: 0.5px solid var(--border-color);
  border-bottom: 0.5px solid var(--border-color);
}

.article-content blockquote p {
  font-family: var(--font-serif);
  font-size: 0.98em;
  margin-bottom: 0;
  color: var(--text-main);
  text-indent: 0; /* 原文不缩进 */
  letter-spacing: 0.5px;
}

/* 引用里的粗体强调 */
.article-content blockquote p strong {
  color: var(--primary-color);
  font-weight: 600;
}

/* 正文标题排版 */
.article-content h1 {
  font-family: var(--font-serif);
  font-size: 1.25em;
  font-weight: 500;
  color: var(--text-main);
  margin-top: 2.2em;
  margin-bottom: 1.2em;
  text-indent: 0;
  text-align: center;
  position: relative;
  padding-bottom: 10px;
}

/* 标题下方的日式精细红点装饰 */
.article-content h1::after {
  content: "•";
  color: var(--primary-color);
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
}

.article-content h2, .article-content h3 {
  font-family: var(--font-serif);
  font-size: 1.05em;
  font-weight: 600;
  color: var(--text-main);
  margin-top: 1.8em;
  margin-bottom: 0.8em;
  text-indent: 0;
  display: flex;
  align-items: center;
}

.article-content h2::before, .article-content h3::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 4px;
  background-color: var(--primary-color);
  margin-right: 8px;
  border-radius: 50%; /* 圆点替代方块，更显温润 */
}

.article-content strong {
  color: var(--primary-color);
  font-weight: 600;
}

.article-content em {
  font-style: normal;
  border-bottom: 0.5px dashed var(--primary-color);
  padding-bottom: 1px;
}

.article-content hr {
  border: 0;
  height: 0.5px;
  background-color: var(--border-color);
  margin: 2.5em 0;
}

/* === 10. 翻页导航 === */
.article-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 48px;
  border-top: 0.5px solid var(--border-color);
  padding-top: 24px;
}

.footer-nav-btn {
  flex: 1;
  background-color: var(--bg-color);
  border: 0.5px solid var(--border-color);
  color: var(--text-main);
  padding: 12px 8px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 64px;
  transition: background-color 0.2s;
}

.footer-nav-btn:active {
  background-color: var(--bg-card);
}

.footer-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.footer-nav-btn .label {
  font-size: 9px;
  color: var(--text-meta);
  letter-spacing: 0.5px;
  font-family: var(--font-sans);
}

.footer-nav-btn .chapter-nav-title {
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.footer-nav-btn .arrow {
  display: none; /* 隐藏粗箭头，保持极简 */
}

/* === 11. 回到顶部 === */
.btn-back-to-top {
  position: fixed;
  right: 20px;
  bottom: calc(20px + var(--safe-bottom));
  background-color: rgba(250, 247, 240, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text-main);
  border: 0.5px solid var(--border-color);
  width: 40px;
  height: 40px;
  border-radius: 4px; /* 方中带圆 */
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.3s, transform 0.3s, visibility 0.3s;
  z-index: 99;
}

body.theme-green .btn-back-to-top { background-color: rgba(241, 243, 236, 0.9); }
body.theme-night .btn-back-to-top { background-color: rgba(28, 30, 33, 0.9); }

.btn-back-to-top.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.btn-back-to-top:active {
  background-color: var(--bg-card);
}

/* === 12. 骨架屏 === */
.toc-skeleton {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 10px;
}

.toc-skeleton div {
  height: 20px;
  background-color: var(--bg-card);
  border-radius: 2px;
  animation: pulse 1.8s infinite ease-in-out;
}

.toc-skeleton div:nth-child(2) { width: 75%; }
.toc-skeleton div:nth-child(3) { width: 85%; }

.skeleton-screen {
  padding: 10px 0;
}

.skeleton-line {
  height: 16px;
  background-color: var(--bg-card);
  margin-bottom: 12px;
  border-radius: 2px;
  animation: pulse 1.8s infinite ease-in-out;
}

.skeleton-line.title {
  height: 24px;
  width: 50%;
  margin-bottom: 24px;
}

.skeleton-line.short {
  width: 35%;
}

/* === 13. 动画 === */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0% { opacity: 0.5; }
  50% { opacity: 0.8; }
  100% { opacity: 0.5; }
}
