/* ---------- 1. 主题变量 ---------- */
:root {
  --blue:        #007bff;
  --blue-dark:   #0056b3;
  --gray-bg:     rgb(245, 247, 253);
  --gray-line:   #e8e8e8;
  --text-main:   #333;
  --text-sub:    #666;
  --radius-s:    4px;
  --radius-round:20px;
}

/* ---------- 2. Reset ---------- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  font-family: Arial, sans-serif;
  background: var(--gray-bg);
  overflow-x: hidden;
}
a {
  color: inherit;
  text-decoration: none;
}

/* ---------- 3. 通用布局 ---------- */
.container {
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
  padding: 10px 20px 20px;
  min-height: 800px;
}
@media (max-width: 1200px) {
  .container { width: 95%; }
}

/* ---------- 4. 顶部导航 ---------- */
.nav-bar {
  width: 100%;
  height: 80px;
  background: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, .1);
}
.nav-wrapper {
  max-width: 1200px;
  height: 100%;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.nav-left {
  display: flex;
  align-items: center;
  gap: 20px;
}
.nav-left img { vertical-align: middle; }

.nav-item {
  padding: 10px;
  margin-right: 20px;
  color: var(--text-main);
  transition: color .2s;
}
.nav-item:hover,
.nav-item.active { color: var(--blue); }

.login-btn {
  padding: 8px 15px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius-s);
  cursor: pointer;
  transition: background .2s;
}
.login-btn:hover { background: var(--blue-dark); }

/* 用户头像 & 下拉菜单 */
#user-box { position: relative; }
.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
}
.user-menu {
  position: absolute;
  top: 55px;
  right: 0;
  display: none;
  min-width: 140px;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .1);
  z-index: 999;
  flex-direction: column;
}
.user-menu a {
  display: block;
  padding: 10px 16px;
  font-size: 14px;
  color: var(--text-main);
  white-space: nowrap;
  transition: background .2s, color .2s;
}
.user-menu a:hover {
  background: #f6f9ff;
  color: var(--blue);
}
.user-menu.show { display: flex; }
.logout-link,
#logout-link {
  color: #e74c3c;
  font-weight: 600;
}
.logout-link:hover,
#logout-link:hover {
  background: #ffecec;
  color: #c0392b;
}

/* ---------- 5. 学段 & Tab 区 ---------- */
.top-bar {
  display: flex;
  align-items: center;
  gap: 30px;
  margin-bottom: 20px;
}
#subject-select { position: relative; display: inline-flex; align-items: center; }
#subject-grade {
  background: var(--blue);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: var(--radius-s);
  font-size: 16px;
  cursor: pointer;
}
#subject-options {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  width: 500px;
  background: #fff;
  border: 1px solid #ddd;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .1);
  padding: 15px;
  border-radius: var(--radius-s);
  z-index: 100;
}
.subject-item {
  display: inline-block;
  padding: 3px 8px;
  margin-right: 15px;
  color: var(--blue);
  cursor: pointer;
  border-radius: var(--radius-s);
}
.subject-item:hover { background: #f0f6ff; }
.subject-item.active {
  background: #f0f6ff;
  color: var(--text-main);
}

/* 原卷 / 章节 Tab */
.subject-header {
  display: flex;
  gap: 20px;
  margin-bottom: 15px;
}
.subject-tab {
  cursor: pointer;
  padding: 10px 18px;
  font-size: 18px;
  color: var(--text-sub);
  border-radius: var(--radius-s);
  transition: background .2s, color .2s;
}
.subject-tab:hover,
.subject-tab.active { background: #f0f6ff; color: var(--blue); }

/* ---------- 6. 筛选器 ---------- */
.filter-container {
  margin: 20px 0;
  padding: 20px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .08);
}
.filter-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 15px;
}
.filter-label {
  min-width: 60px;
  padding-top: 5px;
  color: var(--text-sub);
}
.filter-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 15px;
}
.filter-option {
  padding: 5px 12px;
  background: #f5f5f5;
  border-radius: 15px;
  color: var(--text-sub);
  cursor: pointer;
  transition: .2s;
}
.filter-option:hover,
.filter-option.active { background: #e3f2fd; color: var(--blue); }

/* 排序 */
.sort-options {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-top: 15px;
  padding-top: 15px;
  border-top: 1px solid #eee;
}
.sort-item {
  cursor: pointer;
  padding: 5px 10px;
  border-radius: var(--radius-s);
  color: var(--text-sub);
  transition: .2s;
}
.sort-item:hover,
.sort-item.active { background: #f0f6ff; color: var(--blue); }

/* ---------- 7. 试卷卡片 ---------- */
.paper-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  width: 100%;
  margin-bottom: 15px;
  padding: 18px 22px;
  background: #fff;
  border: 1px solid var(--gray-line);
  border-radius: 8px;
  transition: .3s;
}
.paper-box:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .08);
}
.paper-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.paper-info .row {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  font-size: 14px;
  color: var(--text-sub);
}
.paper-title {
  max-width: 450px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 侧边价格/按钮 */
.paper-side,
.paper-side-3 {
  flex: 0 0 160px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}
.paper-side-3 .line { text-align: right; width: 100%; }
.price-tag {
  font-size: 20px;
  font-weight: 600;
  color: #ff5722;
}
.vip-free {
  font-size: 12px;
  margin-left: 6px;
  color: #00aa55;
}
.download-btn {
  padding: 6px 18px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius-round);
  font-size: 14px;
  cursor: pointer;
  transition: background .2s;
}
.download-btn:hover { background: var(--blue-dark); }

/* 1. 树容器：固定宽度、高度，超出时滚动 */
#chapter-tree {
  width: 280px;              /* 与现有布局保持一致 */
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  padding: 10px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,.08);
}

/* 2. 树节点通用样式 */
.tree-node {
  margin: 4px 0;
  font-size: 14px;
}

/* 3. 树折叠/展开触发器 */
.tree-caret {
  position: relative;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background .2s;
}

/* 悬停背景 */
.tree-caret:hover {
  background: #f0f6ff;
}

/* 4. 缩进：根据层级自动调整左内边距 */
.tree-caret[data-level="1"] { padding-left: 24px; }
.tree-caret[data-level="2"] { padding-left: 40px; }
.tree-caret[data-level="3"] { padding-left: 56px; }
/* 如果还有更深层级，依此类推 */

/* 5. 折叠/展开指示器：用 ::before 绘制小三角 */
.tree-caret.has-child::before {
  content: "▶";
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%) rotate(0deg);
  font-size: 0.8em;
  color: #666;
  transition: transform .2s;
}

/* 展开时旋转三角 */
.tree-caret.tree-caret-down::before {
  transform: translateY(-50%) rotate(90deg);
}

/* 6. 嵌套容器：折叠隐藏 */
.nested {
  display: none;
  margin-top: 2px;
}

/* 展开时显示 */
.nested.active {
  display: block;
}

/* 7. 选中节点高亮 */
.tree-caret.selected {
  background: #e3f2fd;
  color: #007bff;
}

/* 8. 滚动条美化（Webkit） */
#chapter-tree::-webkit-scrollbar {
  width: 6px;
}
#chapter-tree::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.1);
  border-radius: 3px;
}
#chapter-tree::-webkit-scrollbar-track {
  background: transparent;
}


/* ---------- 9. 分页 ---------- */
.pagination {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin: 20px 0;
}
.page-btn,
.page-num {
  min-width: 32px;
  height: 32px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: var(--radius-s);
  font-size: 14px;
  cursor: pointer;
}
.page-btn:hover,
.page-num.active { border-color: var(--blue); color: var(--blue); }

/* ---------- 10. 模态弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, .5);
  z-index: 9999;
}
.modal-content {
  padding: 30px 40px;
  background: #fff;
  border-radius: 8px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .2);
}
.modal-close {
  position: absolute;
  top: 10px;
  left: 12px;
  font-size: 20px;
  font-weight: 700;
  color: #999;
  cursor: pointer;
  user-select: none;
}
.modal-close:hover { color: #333; }

/* 通用弹窗内元素 */
.modal-content img {
  width: 220px;
  height: 220px;
  margin: 20px 0;
  border: 1px solid #eee;
}
.agree { font-size: 13px; color: #666; }

/* 下载 & 支付弹窗 */
.pay-wrapper { width: 380px; }
.qr-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin: 20px 0;
}
.qr-box img { width: 230px; height: 230px; border: 1px solid #eee; }
.amount {
  font-size: 28px;
  font-weight: 700;
  color: #ff5722;
}
.scan-tip { font-size: 15px; color: #333; }

.agree-box { font-size: 13px; color: #666; }
.agree-box input { margin-right: 4px; vertical-align: middle; }

.primary-btn,
.secondary-btn {
  width: 100%;
  border: none;
  border-radius: var(--radius-round);
  font-size: 16px;
  cursor: pointer;
}
.primary-btn {
  margin: 18px 0;
  padding: 12px 0;
  background: var(--blue);
  color: #fff;
}
.secondary-btn {
  padding: 10px 0;
  background: #f5f5f5;
  color: var(--text-main);
  font-size: 14px;
}

/* 特定：试卷付费弹窗结构微调 */
#paper-pay-modal .modal-content.pay-wrapper {
  padding: 30px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .2);
}
#paper-pay-modal .modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 24px;
  color: #999;
}
#paper-pay-modal .modal-close:hover { color: #333; }

/* ---------- 11. 联系我们区 ---------- */
#contact-wrapper {
  padding: 40px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .08);
}
#contact-wrapper h2 { margin-bottom: 20px; }

/* ---------- 12. 页脚 ---------- */
.site-footer {
  margin-top: 40px;
  padding: 20px;
  background: #efefef;
  color: #000;
  text-align: center;
}

/* ---------- 13. 响应式 ---------- */
@media (max-width: 768px) {
  .filter-item       { flex-direction: column; align-items: flex-start; }
  .paper-side        { align-items: flex-start; margin-top: 15px; }
  #chapter-wrapper   { flex-direction: column; }
  #chapter-tree      { max-height: none; }
}

/* 章节模式首个筛选器贴顶 */
#chapter-wrapper .filter-container { margin-top: 0; }

/* main 与导航的间距 */
main { margin-top: 10px; }

/* nav & tab 无多余 margin-bottom */
#subject-select,
.subject-header { margin-bottom: 0; }

/* —— 下载格式选择 —— */
#type-list > div:hover img { transform:scale(1.05); }
#type-list img { transition:.25s; border-radius:8px; box-shadow:0 2px 6px rgba(0,0,0,.08); }
