/* === 钟毓中医古籍 - 样式表 === */

/* CSS 变量 */
:root {
  --bg-primary: #f3f2eb;
  --bg-white: #ffffff;
  --bg-warm: #fffff9;
  --text-primary: #333333;
  --text-secondary: #666666;
  --text-muted: #999999;
  --accent: #a33823;
  --accent-light: #fff1ee;
  --border: #cacaca;
  --border-light: #eeeeee;
  --border-gold: #ccb289;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);

  /* 书封颜色 */
  --cover-0: #405370;
  --cover-1: #6898a7;
  --cover-2: #746174;
  --cover-3: #a98463;
  --cover-4: #b25d43;
  --cover-5: #637c79;

  --cover-inner: #fffbf5;
  --cover-border: #999693;

  --header-height: 50px;
  --tab-height: 40px;
  --max-width: 1080px;

  /* 封面自适应：每行7本，根据屏幕宽度自动计算 */
  --books-per-row: 7;
  --book-gap: 16px;
  --scroll-padding: 15px;
  --book-cover-width: calc((100vw - 2 * var(--scroll-padding) - (var(--books-per-row) - 1) * var(--book-gap)) / var(--books-per-row));
  --book-cover-height: calc(var(--book-cover-width) * 258 / 197);
}

/* 基础重置 */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  background-color: var(--bg-primary);
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
  -webkit-overflow-scrolling: touch;
  min-width: 320px;
}

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

ul, li {
  list-style: none;
}

img {
  display: block;
  max-width: 100%;
}

input, button {
  -webkit-appearance: none;
  border-radius: 0;
  font-family: inherit;
  font-size: inherit;
}

.none {
  display: none !important;
}

/* === 应用容器 === */
.app {
  width: 100%;
  max-width: var(--max-width);
  min-width: 320px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* === 头部 === */
.header {
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
  z-index: 100;
}

.header-title {
  font-size: 18px;
  font-weight: bold;
  color: var(--text-primary);
}

.header-back {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 20px;
  color: var(--text-secondary);
}

/* === 搜索栏 === */
.search-bar {
  padding: 10px 15px;
  background: var(--bg-white);
  flex-shrink: 0;
}

.search-wrapper {
  display: flex;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.search-input {
  flex: 1;
  height: 34px;
  padding: 6px 12px;
  border: none;
  outline: none;
  font-size: 14px;
  background: var(--bg-warm);
  color: var(--text-primary);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-btn {
  width: 60px;
  height: 34px;
  border: none;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
}

/* === 标签导航 === */
.tabs {
  display: flex;
  background: var(--bg-white);
  flex-shrink: 0;
}

.tab-item {
  flex: 1;
  text-align: center;
  height: var(--tab-height);
  line-height: var(--tab-height);
  font-size: 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  color: var(--text-secondary);
}

.tab-item.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: bold;
}

/* === 内容区域 === */
.content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* === 轮播图 === */
.banner {
  position: relative;
  overflow: hidden;
  background: var(--bg-white);
}

.banner-track {
  display: flex;
  transition: transform 0.8s ease;
}

.banner-slide {
  min-width: 100%;
  aspect-ratio: 3 / 1;
  overflow: hidden;
}

.banner-slide img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.banner-dots {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
}

.banner-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.5);
  cursor: pointer;
  transition: all 0.3s;
}

.banner-dot.active {
  background: #fff;
  width: 20px;
  border-radius: 4px;
}

/* === 区块标题 === */
.section {
  background: var(--bg-white);
  margin-top: 5px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px 8px;
}

.section-title {
  font-size: 16px;
  font-weight: bold;
  color: var(--text-primary);
}

.section-more {
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 2px;
}

.section-more::after {
  content: '›';
  font-size: 16px;
}

/* === 书籍封面 === */
.book-cover {
  display: block;
  width: var(--book-cover-width);
  height: var(--book-cover-height);
  position: relative;
  cursor: pointer;
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
}

.book-cover-inner {
  position: absolute;
  top: 8.9%;
  left: 6.6%;
  max-width: 77.7%;
  min-height: 45%;
  max-height: 73.3%;
  padding: 2.5%;
  background: var(--cover-inner);
}

.book-cover-title {
  line-height: 1;
  font-size: calc(var(--book-cover-width) * 0.117);
  color: var(--text-primary);
  padding: 5px 0;
  border: 1px solid var(--cover-border);
  text-align: center;
  writing-mode: vertical-rl;
  direction: rtl;
  cursor: pointer;
}

.book-cover-spine {
  position: absolute;
  right: 0;
  top: 0;
  width: 9.6%;
  height: 100%;
  border-left: 1px solid var(--cover-inner);
}

.book-cover-spine-line {
  height: 25%;
  border-bottom: 1px solid var(--cover-inner);
}

.book-cover-spine-line:first-child,
.book-cover-spine-line:last-child {
  height: 12.5%;
}

.book-cover-spine-line:last-child {
  border-bottom: none;
}

/* 封面颜色 */
.cover-0 { background-color: var(--cover-0); }
.cover-1 { background-color: var(--cover-1); }
.cover-2 { background-color: var(--cover-2); }
.cover-3 { background-color: var(--cover-3); }
.cover-4 { background-color: var(--cover-4); }
.cover-5 { background-color: var(--cover-5); }

/* 小封面（列表页用） */
.book-cover-sm {
  width: 75px;
  height: 100px;
}

.book-cover-sm .book-cover-inner {
  top: 10px;
  left: 6px;
  max-width: 95px;
  min-height: 55px;
  max-height: 83px;
  padding: 2px;
}

.book-cover-sm .book-cover-title {
  line-height: 1;
  font-size: 12px;
  min-width: 14px;
  padding: 2px 1px;
}

/* === 书籍横向滚动列表 === */
.book-scroll-list {
  padding: 0 15px 15px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.book-scroll-list::-webkit-scrollbar {
  display: none;
}

.book-scroll-inner {
  display: flex;
  gap: var(--book-gap);
}

.book-card {
  flex-shrink: 0;
  width: var(--book-cover-width);
  text-align: center;
}

.book-card .book-cover {
  margin: 0 auto 8px;
}

.book-card-title {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* === 书籍列表（纵向） === */
.book-list {
  padding: 0 15px 15px;
}

.book-list-item {
  display: flex;
  gap: 15px;
  padding: 15px 0;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
}

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

.book-list-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.book-list-name {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-list-author {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.book-list-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-list-read {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 16px;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 4px;
  font-size: 12px;
  text-align: center;
}

/* === 分类页面 === */
.category-section {
  padding: 0 15px;
}

.category-title {
  font-size: 14px;
  line-height: 40px;
  color: var(--text-primary);
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding-bottom: 15px;
}

.category-tag {
  display: block;
  height: 32px;
  line-height: 32px;
  text-align: center;
  font-size: 14px;
  border: 1px solid var(--border-gold);
  border-radius: 16px;
  background: var(--bg-warm);
  color: var(--text-primary);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 8px;
  transition: all 0.2s;
}

.category-tag:active {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

/* === 书籍详情 === */
.detail-header {
  padding: 15px;
  background: var(--bg-white);
  display: flex;
  gap: 15px;
}

.detail-info {
  flex: 1;
  min-width: 0;
}

.detail-name {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 8px;
}

.detail-author {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.detail-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.detail-buttons {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.detail-btn {
  height: 34px;
  line-height: 34px;
  padding: 0 20px;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  text-align: center;
  border: 1px solid var(--accent);
  transition: all 0.2s;
}

.detail-btn-read {
  background: var(--accent);
  color: #fff;
}

.detail-btn-shelf {
  background: #fff;
  color: var(--accent);
}

.detail-btn-shelf.in-shelf {
  background: var(--border);
  border-color: var(--border);
  color: #fff;
}

/* 详情Tab */
.detail-tabs {
  display: flex;
  background: var(--bg-white);
  margin-top: 5px;
}

.detail-tab {
  flex: 1;
  text-align: center;
  height: 40px;
  line-height: 40px;
  font-size: 14px;
  cursor: pointer;
  border-top: 1px solid var(--border-light);
  position: relative;
}

.detail-tab.active {
  color: var(--accent);
}

.detail-tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--accent);
}

.detail-content {
  background: var(--bg-white);
  padding: 15px;
  font-size: 14px;
  line-height: 1.8;
  text-align: justify;
  text-indent: 2em;
}

.catalog-list {
  background: var(--bg-white);
  padding: 10px 15px;
}

.catalog-item {
  line-height: 36px;
  font-size: 14px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-light);
  padding-left: 10px;
}

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

.catalog-item.level2 {
  padding-left: 30px;
  color: var(--text-secondary);
}

/* === 我的书架 === */
.bookshelf-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 15px;
  height: 44px;
  background: var(--bg-white);
}

.bookshelf-title {
  font-size: 14px;
  font-weight: bold;
}

.bookshelf-actions {
  display: flex;
  gap: 12px;
}

.bookshelf-btn {
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  background: none;
  padding: 4px 8px;
}

.bookshelf-btn.danger {
  color: var(--accent);
}

.bookshelf-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
  padding: 15px;
  background: var(--bg-white);
}

.bookshelf-item {
  text-align: center;
  position: relative;
  cursor: pointer;
}

.bookshelf-item .book-cover {
  margin: 0 auto 8px;
  width: 100%;
  max-width: 122px;
  height: auto;
  aspect-ratio: 122/160;
}

.bookshelf-check {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: #fff;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #fff;
}

.bookshelf-check.checked {
  background: var(--accent);
  border-color: var(--accent);
}

.bookshelf-item-name {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bookshelf-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

/* === Toast消息 === */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.75);
  color: #fff;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  z-index: 9999;
  pointer-events: none;
  animation: toastIn 0.3s ease;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* === 阅读器 === */
.reader-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 15px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.reader-toolbar-title {
  font-size: 14px;
  font-weight: bold;
  color: var(--text-primary);
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-toolbar-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.reader-toolbar-btn {
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  background: none;
  padding: 4px 8px;
  border-radius: 4px;
}

.reader-toolbar-btn.active {
  color: var(--accent);
  background: var(--accent-light);
}

.reader-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 18px;
  background: var(--bg-warm);
  -webkit-overflow-scrolling: touch;
}

.reader-content.night {
  background: #1a1a1a;
  color: #a0a0a0;
}

.reader-chapter-title {
  font-size: 18px;
  font-weight: bold;
  text-align: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--border-light);
}

.reader-content.night .reader-chapter-title {
  border-bottom-color: #333;
  color: #ccc;
}

.reader-text {
  font-size: 16px;
  line-height: 2;
  text-align: justify;
  text-indent: 2em;
}

.reader-text.font-sm { font-size: 14px; }
.reader-text.font-lg { font-size: 18px; }
.reader-text.font-xl { font-size: 20px; }

.reader-content.night .reader-text {
  color: #b0b0b0;
}

.reader-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 15px;
  background: var(--bg-white);
  border-top: 1px solid var(--border-light);
  flex-shrink: 0;
}

.reader-nav-btn {
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  background: var(--bg-white);
  color: var(--text-secondary);
}

.reader-nav-btn:active {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

.reader-nav-info {
  font-size: 12px;
  color: var(--text-muted);
}

/* 章节目录抽屉 */
.reader-drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: none;
}

.reader-drawer-overlay.show {
  display: block;
}

.reader-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: 75%;
  max-width: 320px;
  height: 100%;
  background: var(--bg-white);
  z-index: 201;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}

.reader-drawer.show {
  transform: translateX(0);
}

.reader-drawer-header {
  padding: 15px;
  font-size: 16px;
  font-weight: bold;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.reader-drawer-close {
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.reader-drawer-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
}

.reader-drawer-item {
  padding: 10px 20px;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
}

.reader-drawer-item:active,
.reader-drawer-item.active {
  color: var(--accent);
  background: var(--accent-light);
}

.reader-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

/* === 响应式 === */
@media (max-width: 750px) {
  :root {
    --book-gap: 8px;
    --scroll-padding: 10px;
  }
  .book-cover .book-cover-inner {
    top: 8.9%;
    left: 6.6%;
    max-width: 77.7%;
    min-height: 45%;
    max-height: 73.3%;
    padding: 2.5%;
  }
  .book-cover .book-cover-title {
    line-height: 1;
    font-size: calc(var(--book-cover-width) * 0.117);
    min-width: 14px;
    padding: 2px 1px;
  }
  .book-cover .book-cover-spine {
    width: 9.6%;
  }
  .book-list-item {
    gap: 12px;
  }
  .detail-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  .detail-buttons {
    justify-content: center;
  }
  .bookshelf-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }
}