/* ===== 字体 ===== */
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;600;700&display=swap');

/* ===== CSS 变量 ===== */
:root {
  --bg: #faf7f2;
  --bg-card: #ffffff;
  --text: #3d3228;
  --text-secondary: #8c7b6b;
  --text-muted: #bfb3a4;
  --accent: #b8864e;
  --accent-hover: #9a6d3e;
  --border: #ebe6de;
  --shadow: 0 1px 3px rgba(60, 40, 20, 0.05);
  --shadow-hover: 0 4px 16px rgba(60, 40, 20, 0.1);

  /* 阅读页默认 - 暖纸色 */
  --reading-bg: #f5efe0;
  --reading-text: #4a3b2f;

  --font-size-base: 25px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* 阅读主题 */
[data-theme="light"] {
  --reading-bg: #ffffff;
  --reading-text: #2a2a2a;
}

[data-theme="wheat"] {
  --reading-bg: #f5efe0;
  --reading-text: #4a3b2f;
}

[data-theme="green"] {
  --reading-bg: #d5e4d0;
  --reading-text: #2d3d26;
}

[data-theme="dark"] {
  --reading-bg: #1c1c1c;
  --reading-text: #b0a99b;
}

/* 字号 */
[data-fontsize="small"]  { --font-size-base: 19px; }
[data-fontsize="medium"] { --font-size-base: 22px; }
[data-fontsize="large"]  { --font-size-base: 25px; }

/* ===== 重置 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

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

a { color: inherit; text-decoration: none; }

/* ===== 首页 ===== */
.home-header {
  text-align: center;
  padding: 40px 20px 24px;
}

.home-header h1 {
  font-family: "Noto Serif SC", serif;
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 2px;
}

.home-header .subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* 书架 */
.bookshelf {
  padding: 0 16px 40px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px 16px;
}

.bookshelf .book-item {
  width: 110px;
}

@media (min-width: 420px) {
  .bookshelf .book-item {
    width: 120px;
  }
}

.book-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.2s ease;
}

.book-item:active {
  transform: scale(0.96);
}

.book-cover {
  width: 100%;
  aspect-ratio: 3/4.2;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(60, 40, 20, 0.12);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.book-cover::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 40%;
  background: linear-gradient(rgba(255,255,255,0.12), transparent);
  border-radius: 6px 6px 0 0;
  pointer-events: none;
}

.book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0;
  left: 0;
}

.book-cover-text {
  font-family: "Noto Serif SC", serif;
  font-size: 18px;
  font-weight: 700;
  color: rgba(255,255,255,0.92);
  text-align: center;
  line-height: 1.4;
  position: relative;
  z-index: 1;
}

/* 封面配色 - 从小说意象提取 */
.book-cover.linyuan  { background: linear-gradient(160deg, #c49a5e 0%, #a67c4a 40%, #8b632e 100%); }
.book-cover.qianzhuo { background: linear-gradient(160deg, #7d9b76 0%, #5d7a5c 40%, #4a6348 100%); }
.book-cover.moqi     { background: linear-gradient(160deg, #b8a084 0%, #9c7f62 40%, #7d5f46 100%); }

.book-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}

.book-author {
  font-size: 11px;
  color: var(--text-muted);
}

/* 页脚 */
.home-footer {
  text-align: center;
  padding: 0 20px 32px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== 小说详情页 ===== */
.detail-header {
  background: var(--bg-card);
  padding: 12px 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--border);
}

.detail-back {
  display: flex;
  align-items: center;
  padding: 8px;
  color: var(--text-secondary);
}

.detail-back svg {
  width: 22px;
  height: 22px;
}

.detail-header-title {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  padding-right: 30px;
}

.detail-info {
  padding: 28px 24px;
  background: var(--bg-card);
  display: flex;
  gap: 16px;
}

.detail-cover {
  width: 90px;
  height: 126px;
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
  box-shadow: 0 4px 20px rgba(60, 40, 20, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  position: relative;
}

.detail-cover::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 40%;
  background: linear-gradient(rgba(255,255,255,0.12), transparent);
  border-radius: 6px 6px 0 0;
  pointer-events: none;
}

.detail-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0;
  left: 0;
}

.detail-cover .book-cover-text {
  font-size: 16px;
}

.detail-meta {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.detail-meta h1 {
  font-family: "Noto Serif SC", serif;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
}

.detail-meta .author {
  font-size: 13px;
  color: var(--text-secondary);
}

.detail-meta .stats {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.detail-desc {
  padding: 16px 24px;
  background: var(--bg-card);
  margin-top: 1px;
}

.detail-desc .desc-text {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.8;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  transition: all 0.3s;
}

.detail-desc .desc-text.expanded {
  -webkit-line-clamp: unset;
}

.detail-desc .expand-btn {
  font-size: 13px;
  color: var(--accent);
  margin-top: 4px;
  display: inline-block;
  cursor: pointer;
}

.start-reading {
  padding: 16px 24px;
  background: var(--bg-card);
  margin-top: 1px;
}

.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px;
  border-radius: 24px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  transition: opacity 0.2s;
}

.btn-primary:active {
  opacity: 0.82;
}

/* 目录 */
.chapter-section {
  background: var(--bg-card);
  margin-top: 8px;
}

.chapter-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}

.chapter-section-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.chapter-section-header span {
  font-size: 13px;
  color: var(--text-muted);
}

.chapter-list {
  padding: 0 24px;
}

.chapter-item {
  display: flex;
  align-items: center;
  padding: 15px 0;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  transition: color 0.15s;
  gap: 8px;
}

.chapter-item:last-child {
  border-bottom: none;
}

.chapter-item:active {
  color: var(--accent);
}

.chapter-num {
  color: var(--text-muted);
  font-size: 13px;
  width: 42px;
  flex-shrink: 0;
}

.chapter-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-words {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ===== 阅读页 ===== */
body.reading-page {
  background: var(--reading-bg);
  overflow-y: scroll;
}

.reading-wrapper {
  width: 100%;
  min-height: 100vh;
  position: relative;
  background: var(--reading-bg);
  transition: background 0.3s;
}

/* 顶部细进度线 */
.reading-progress-line {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  background: var(--accent);
  z-index: 300;
  transition: width 0.15s;
  opacity: 0.5;
}

/* 顶部栏 */
.reader-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--reading-bg);
  display: flex;
  align-items: center;
  padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  gap: 8px;
  z-index: 200;
  transform: translateY(-100%);
  transition: transform 0.28s ease, background 0.3s;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}

.reader-topbar.visible {
  transform: translateY(0);
}

.reader-topbar .back-btn {
  display: flex;
  align-items: center;
  padding: 6px;
  color: var(--reading-text);
  opacity: 0.7;
}

.reader-topbar .back-btn svg {
  width: 22px;
  height: 22px;
}

.reader-topbar .chapter-name {
  flex: 1;
  font-size: 14px;
  color: var(--reading-text);
  opacity: 0.7;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  padding-right: 28px;
}

/* 点击区域 */
.reader-tap-area {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  pointer-events: auto;
}

/* 阅读内容 */
.chapter-content {
  padding: 24px 20px 48px;
  font-family: "FZYouHei", "方正悠黑", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  font-size: var(--font-size-base);
  line-height: 2.0;
  color: var(--reading-text);
  min-height: 80vh;
  letter-spacing: 0.4px;
  transition: color 0.3s;
}

.chapter-content h1 {
  font-size: calc(var(--font-size-base) + 4px);
  font-weight: 700;
  text-align: center;
  margin-bottom: 36px;
  line-height: 1.4;
  padding-top: 12px;
}

.chapter-content p {
  text-indent: 2em;
  margin-bottom: 22px;
  word-break: break-all;
  font-weight: 400;
}

.chapter-content blockquote {
  margin: 24px 0;
  padding: 14px 18px;
  border-left: 2px solid var(--accent);
  background: rgba(0,0,0,0.02);
  border-radius: 0 6px 6px 0;
}

.chapter-content hr {
  border: none;
  height: 1px;
  background: rgba(0,0,0,0.08);
  margin: 40px auto;
  width: 25%;
}

/* 章节底部导航 */
.chapter-bottom-nav {
  display: flex;
  gap: 0;
  padding: 16px 20px calc(16px + var(--safe-bottom));
}

.chapter-bottom-nav a,
.chapter-bottom-nav span {
  flex: 1;
  text-align: center;
  padding: 13px 0;
  font-size: 15px;
  color: var(--accent);
  border-radius: 8px;
  transition: background 0.2s;
}

.chapter-bottom-nav a:active {
  background: rgba(184, 134, 78, 0.08);
}

.chapter-bottom-nav span {
  color: var(--text-muted);
}

/* 底部工具栏 */
.reader-bottombar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--reading-bg);
  z-index: 200;
  transform: translateY(100%);
  transition: transform 0.28s ease, background 0.3s;
  padding-bottom: var(--safe-bottom);
  border-top: 1px solid rgba(0,0,0,0.05);
}

.reader-bottombar.visible {
  transform: translateY(0);
}

/* 进度区域 */
.reader-progress-area {
  padding: 14px 20px 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.reader-progress-area .prev-ch,
.reader-progress-area .next-ch {
  font-size: 14px;
  color: var(--reading-text);
  opacity: 0.6;
  flex-shrink: 0;
  padding: 4px 6px;
  transition: opacity 0.2s;
}

.reader-progress-area .prev-ch:active,
.reader-progress-area .next-ch:active {
  opacity: 1;
}

.reader-progress-bar {
  flex: 1;
  height: 2px;
  background: rgba(0,0,0,0.08);
  border-radius: 1px;
}

.reader-progress-bar .fill {
  height: 100%;
  background: var(--accent);
  border-radius: 1px;
  transition: width 0.15s;
}

/* 主题选择 */
.theme-row {
  padding: 10px 20px;
  display: flex;
  gap: 14px;
  justify-content: center;
}

.theme-circle {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s;
  flex-shrink: 0;
}

.theme-circle.active {
  border-color: var(--accent);
}

.theme-circle:active {
  transform: scale(0.88);
}

.theme-circle.light  { background: #ffffff; border: 1px solid #ddd; }
.theme-circle.light.active { border-color: var(--accent); border-width: 2px; }
.theme-circle.wheat  { background: #f5efe0; }
.theme-circle.green  { background: #d5e4d0; }
.theme-circle.dark   { background: #1c1c1c; }

/* 字号调节 */
.fontsize-row {
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.fontsize-row .fontsize-label {
  font-size: 13px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.fontsize-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 15px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

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

.fontsize-current {
  flex: 1;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
}

/* 底部菜单 */
.reader-menu-row {
  display: flex;
  padding: 6px 0 14px;
  border-top: 1px solid rgba(0,0,0,0.05);
}

.reader-menu-row a,
.reader-menu-row button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0;
  font-size: 11px;
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
}

.reader-menu-row svg {
  width: 22px;
  height: 22px;
}

/* ===== 目录下拉面板 ===== */
.dir-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 400;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}

.dir-overlay.visible {
  pointer-events: auto;
  opacity: 1;
}

.dir-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.35);
}

.dir-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 300px;
  max-width: 85vw;
  background: var(--bg-card);
  transform: translateX(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}

.dir-overlay.visible .dir-panel {
  transform: translateX(0);
}

.dir-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  font-size: 16px;
  font-weight: 600;
}

.dir-close-btn {
  background: none;
  border: none;
  padding: 4px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
}

.dir-close-btn svg {
  width: 20px;
  height: 20px;
}

.dir-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  -webkit-overflow-scrolling: touch;
}

.dir-item {
  display: flex;
  align-items: center;
  padding: 15px 20px;
  gap: 10px;
  transition: background 0.15s;
  border-bottom: 1px solid var(--border);
}

.dir-item:active {
  background: rgba(0,0,0,0.03);
}

.dir-item.active {
  color: var(--accent);
}

.dir-item-num {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.dir-item.active .dir-item-num {
  color: var(--accent);
}

.dir-item-main {
  flex: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.dir-item-title {
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dir-item-words {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ===== 章节字数（详情页目录） ===== */

/* ===== 选中 ===== */
::selection {
  background: rgba(184, 134, 78, 0.2);
  color: inherit;
}

/* ===== 滚动条隐藏 ===== */
::-webkit-scrollbar { width: 0; }

/* ===== 桌面端 ===== */
@media (min-width: 768px) {
  body {
    background: #e8e2d8;
  }

  .phone-frame {
    max-width: 420px;
    margin: 0 auto;
    min-height: 100vh;
    background: var(--bg);
    box-shadow: 0 0 60px rgba(40, 20, 0, 0.15);
    position: relative;
  }

  .reading-wrapper {
    max-width: 420px;
    margin: 0 auto;
    min-height: 100vh;
    background: var(--reading-bg);
    box-shadow: 0 0 60px rgba(40, 20, 0, 0.15);
    position: relative;
  }

  /* 阅读页约束 */
  .reading-wrapper .reader-topbar {
    max-width: 420px;
    left: 50%;
    right: auto;
    transform: translateX(-50%) translateY(-100%);
  }

  .reading-wrapper .reader-topbar.visible {
    transform: translateX(-50%) translateY(0);
  }

  .reading-wrapper .reader-bottombar {
    max-width: 420px;
    left: 50%;
    right: auto;
    transform: translateX(-50%) translateY(100%);
  }

  .reading-wrapper .reader-bottombar.visible {
    transform: translateX(-50%) translateY(0);
  }

  .reading-wrapper .reading-progress-line {
    max-width: 420px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }

  .reading-wrapper .reader-tap-area {
    max-width: 420px;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
  }
}
