/* 全局变量体系 */
:root {
  --primary: #3b82f6;
  --primary-dark: #1d4ed8;
  --accent: #ef4444;
  --bg-main: #f4f6f9;
  --bg-card: #ffffff;
  --text-main: #1f2937;
  --text-muted: #6b7280;
  --border-color: #e5e7eb;
  --radius: 8px;
  --max-w: 1200px;
}

[data-theme="dark"] {
  --bg-main: #111827;
  --bg-card: #1f2937;
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --border-color: #374151;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.6;
}
a { color: inherit; text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--primary); }
img { max-width: 100%; display: block; border-radius: 4px; }

/* 容器基础宽度与内边距（核心防靠边） */
.container { 
  width: 100%; 
  max-width: var(--max-w); 
  margin: 0 auto; 
  padding-left: 16px; 
  padding-right: 16px; 
}

/* 卡片与通用类 */
.card { background: var(--bg-card); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.text-center { text-align: center; }
.mt10 { margin-top: 10px; }
.pt10 { padding-top: 10px; }
.red { color: var(--accent); }
.blue { color: var(--primary); }
.section-title { font-size: 18px; font-weight: 700; margin-bottom: 14px; border-left: 4px solid var(--primary); padding-left: 10px; }

/* 头部 Header */
.header { 
  background: var(--bg-card); 
  border-bottom: 1px solid var(--border-color); 
  position: sticky; 
  top: 0; 
  z-index: 100; 
  width: 100%;
}
.header-wrapper { 
  display: flex; 
  align-items: center; 
  justify-content: space-between; 
  height: 56px; 
  gap: 15px; 
}
.header-left .logo { font-size: 20px; font-weight: bold; color: var(--primary); }
.header-nav { display: flex; gap: 20px; font-size: 15px; font-weight: 500; }
.header-right { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.btn-toggle { background: transparent; border: 1px solid var(--border-color); padding: 4px 8px; border-radius: 4px; cursor: pointer; color: var(--text-main); }

/* ================= 阅读历史下拉菜单 ================= */
.recent-read-wrap {
  position: relative;
  display: inline-block;
}

.btn-history {
  display: inline-block;
  padding: 4px 10px;
  color: var(--primary);
  font-weight: 500;
  cursor: pointer;
}

.recent-read-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 5px;
  width: 280px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  z-index: 999;
}

.recent-read-dropdown::before {
  content: "";
  position: absolute;
  top: -10px;
  left: 0;
  width: 100%;
  height: 10px;
  background: transparent;
}

.recent-read-wrap:hover .recent-read-dropdown,
.recent-read-wrap.active .recent-read-dropdown {
  display: block;
}

.dropdown-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-color);
  font-size: 13px;
  color: var(--text-muted);
}

.dropdown-header .clear-btn {
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
}

.dropdown-list {
  list-style: none;
  max-height: 260px;
  overflow-y: auto;
  margin: 0;
  padding: 6px 0;
}

.dropdown-list li {
  padding: 8px 14px;
  border-bottom: 1px dashed var(--border-color);
  font-size: 13px;
  line-height: 1.4;
}

.dropdown-list li:hover {
  background-color: var(--bg-main);
}

.dropdown-list li:last-child {
  border-bottom: none;
}

.dropdown-list li a.book-title {
  display: block;
  font-weight: bold;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dropdown-list li a.book-title:hover {
  color: var(--primary);
}

.dropdown-list li a.chap-title {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.dropdown-list li a.chap-title:hover {
  color: var(--primary);
}

.dropdown-list .empty-tip {
  text-align: center;
  color: var(--text-muted);
  padding: 15px 0;
}

/* 搜索表单 */
.search-form { display: flex; max-width: 520px; margin: 15px auto 20px; }
.search-form .text { flex: 1; padding: 10px 14px; border: 1px solid var(--border-color); border-right: none; border-radius: var(--radius) 0 0 var(--radius); outline: none; background: var(--bg-card); color: var(--text-main); }
.search-form button { padding: 0 22px; background: var(--primary); color: #fff; border: none; border-radius: 0 var(--radius) var(--radius) 0; cursor: pointer; }

/* 面包屑 */
.breadcrumb { display: flex; flex-wrap: wrap; gap: 8px; font-size: 13px; color: var(--text-muted); margin: 15px 0; list-style: none; }
.breadcrumb li+li:before { content: "/"; padding-right: 8px; color: #9ca3af; }

/* 首页布局 */
.home-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-top: 15px; }
.hot-commend-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.commend-item { display: flex; gap: 16px; background: var(--bg-main); padding: 12px; border-radius: var(--radius); border: 1px solid var(--border-color); }
.commend-item:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); }
.commend-item .commend-cover { width: 120px; height: 160px; flex-shrink: 0; overflow: hidden; border-radius: 4px; background: #e2e8f0; }
.commend-item .commend-cover img { width: 100%; height: 100%; object-fit: cover; }
.commend-item dl { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.commend-item dl dt { margin-bottom: 6px; }
.commend-item dl dt a { font-size: 16px; font-weight: 700; color: var(--text-main); }
.commend-item .commend-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; display: flex; justify-content: space-between; }
.commend-item .commend-meta .sort-tag { background: rgba(59, 130, 246, 0.1); color: var(--primary); padding: 1px 6px; border-radius: 3px; }
.commend-item dl dd { font-size: 13px; color: var(--text-muted); line-height: 1.6; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }

.simple-rank-list li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--border-color); font-size: 14px; }
.simple-rank-list li span { color: var(--text-muted); }
.update-table-list li { display: flex; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border-color); font-size: 14px; gap: 8px; }
.update-table-list .s1 { width: 70px; color: var(--text-muted); }
.update-table-list .s2 { width: 180px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.update-table-list .s3 { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-muted); }
.update-table-list .s4 { width: 100px; text-align: right; color: var(--text-muted); }
.update-table-list .s5 { width: 80px; text-align: right; font-size: 12px; color: #9ca3af; }

/* 详情页专属样式 */
.book-detail-box { display: flex; gap: 24px; }
.book-detail-box .bookcover { width: 150px; height: 200px; flex-shrink: 0; border-radius: 6px; overflow: hidden; box-shadow: 0 4px 10px rgba(0,0,0,0.1); background: #e2e8f0; }
.book-detail-box .bookcover img { width: 100%; height: 100%; object-fit: cover; }
.book-detail-info { flex: 1; display: flex; flex-direction: column; }
.book-detail-info .booktitle { font-size: 24px; font-weight: 700; margin-bottom: 10px; }
.book-detail-info .booktag { display: flex; flex-wrap: wrap; gap: 15px; font-size: 14px; margin-bottom: 12px; }
.book-detail-info .bookintro { font-size: 14px; color: var(--text-muted); line-height: 1.7; margin-bottom: 12px; }
.book-detail-info .book-latest { font-size: 14px; margin-bottom: 15px; }
.book-actions { display: flex; gap: 12px; margin-top: auto; }
.btn-action { padding: 8px 24px; border-radius: 4px; font-size: 14px; background: var(--primary); color: #fff !important; font-weight: 500; cursor: pointer; }
.btn-action.sec { background: var(--bg-main); color: var(--text-main) !important; border: 1px solid var(--border-color); }

/* 章节 3 列网格排版 */
.chapter-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.chapter-grid dd { margin: 0; background: var(--bg-main); border: 1px solid var(--border-color); border-radius: 4px; padding: 8px 12px; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chapter-grid dd a { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 物理分页控制器 */
.pages { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.btn-page { display: inline-block; padding: 6px 14px; background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 4px; color: var(--text-main); font-size: 13px; cursor: pointer; }
.btn-page:hover { background: var(--primary); color: #fff !important; border-color: var(--primary); }
.page-select { padding: 6px 12px; border-radius: 4px; border: 1px solid var(--border-color); background: var(--bg-main); color: var(--text-main); font-size: 14px; outline: none; }

/* 阅读页专用 */
.reader-wrapper { max-width: 860px; margin: 0 auto; }
.reader-box { background: var(--bg-card); padding: 30px; border-radius: var(--radius); }
.reader-title { text-align: center; font-size: 24px; margin-bottom: 15px; }
.readcontent { font-size: 19px; line-height: 2; margin: 30px 0; word-break: break-all; }
.readcontent p { text-indent: 2em; margin-bottom: 18px; }
.reader-nav-btns { display: flex; justify-content: center; gap: 12px; margin: 25px 0; }
.reader-nav-btns a { padding: 8px 24px; border: 1px solid var(--border-color); border-radius: 4px; background: var(--bg-main); font-size: 15px; }

/* 底部 */
.footer { border-top: 1px solid var(--border-color); padding: 25px 0; margin-top: 30px; text-align: center; font-size: 13px; color: var(--text-muted); }

/* ================= 移动端精准自适应与边距修正 (<= 768px) ================= */
@media (max-width: 768px) {
  /* 强制给手机端容器保留 16px 舒适安全边距 */
  .container {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }

  /* 头部导航区域重排与内边距保护 */
  .header-wrapper { 
    height: auto; 
    flex-wrap: wrap; 
    padding: 12px 0 8px; 
    gap: 10px;
  }
  
  .header-left .logo {
    font-size: 21px;
  }

  .header-nav { 
    order: 3; 
    width: 100%; 
    overflow-x: auto; 
    padding-top: 10px; 
    padding-bottom: 4px;
    border-top: 1px solid var(--border-color); 
    white-space: nowrap; 
    gap: 22px;
  }
  
  .header-nav a {
    font-size: 15px;
  }

  .home-grid { grid-template-columns: 1fr; }
  
  .recent-read-dropdown { 
    right: 0; 
    width: 260px; 
  }

  .hot-commend-list { grid-template-columns: 1fr; gap: 12px; }
  .commend-item .commend-cover { width: 100px; height: 135px; }
  .commend-item dl dd { -webkit-line-clamp: 3; }

  .update-table-list .s3, .update-table-list .s4, .update-table-list .s5 { display: none; }
  .update-table-list .s2 { width: auto; flex: 1; }

  .book-detail-box { flex-direction: column; align-items: center; text-align: center; gap: 15px; }
  .book-detail-box .bookcover { width: 120px; height: 160px; }
  .book-detail-info .booktag { justify-content: center; }
  .book-actions { justify-content: center; }
  .chapter-grid { grid-template-columns: 1fr; gap: 6px; }
  .chapter-grid dd { padding: 10px 14px; }

  .reader-box { padding: 15px; }
  .readcontent { font-size: 17px; }
}