/* ===== 初中理科知识树 · 网站样式 ===== */
:root {
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --text: #2b2b2b;
  --text-light: #7f8c8d;
  --border: #dce3ea;
  --accent: #2e86c1;
  --accent-dark: #1a5276;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: "Microsoft YaHei", "微软雅黑", "PingFang SC", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
}

/* ===== 顶部导航 ===== */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
  color: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 12px 18px 0;
}
.site-title {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
}
.site-title h1 { font-size: 22px; }
.site-title .subtitle { font-size: 13px; opacity: 0.85; }

/* 学科 Tab */
.subject-tabs { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.subject-tabs button {
  border: 2px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.15);
  color: #fff; font-size: 16px; font-weight: bold;
  padding: 10px 26px; border-radius: 24px;
  cursor: pointer; transition: all 0.25s;
  font-family: inherit;
}
.subject-tabs button:hover {
  background: rgba(255, 255, 255, 0.4);
  transform: translateY(-2px);
}
.subject-tabs button.active {
  background: #ffffff; color: var(--accent-dark);
  border-color: #ffffff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  transform: translateY(-2px);
}

/* 搜索栏 */
.search-wrap { padding: 12px 0 14px; }
.search-box {
  position: relative; max-width: 720px; margin: 0 auto;
}
.search-box input {
  width: 100%; padding: 12px 48px 12px 18px;
  font-size: 15px; border: none; border-radius: 24px;
  outline: none; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  font-family: inherit;
}
.search-box .search-icon {
  position: absolute; right: 16px; top: 50%; transform: translateY(-50%);
  font-size: 18px; color: var(--text-light);
}
.search-stats {
  max-width: 720px; margin: 4px auto 0; font-size: 12px; color: #d6eaf8;
  padding-left: 18px;
}

/* ===== 主内容 ===== */
.main {
  max-width: 1200px; margin: 0 auto; padding: 20px 18px 60px;
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 20px;
  align-items: start;
}

/* 侧边栏 */
.sidebar {
  position: sticky; top: 160px;
  background: var(--card-bg); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.sidebar h2 {
  font-size: 14px; color: var(--accent-dark);
  padding: 12px 16px; background: #eaf2f8; border-bottom: 1px solid var(--border);
}
.branch-list { max-height: 460px; overflow-y: auto; padding: 6px; }
.branch-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  font-size: 13.5px; color: var(--text);
  transition: background 0.15s;
}
.branch-item:hover { background: #f0f6fb; }
.branch-item.active { background: #dbe9f7; color: var(--accent-dark); font-weight: bold; }
.branch-item .dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.branch-item .range { margin-left: auto; font-size: 11.5px; color: var(--text-light); }

/* 总览图 */
.overview {
  background: var(--card-bg); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 20px;
  cursor: zoom-in;
}
.overview img { width: 100%; border-radius: 8px; display: block; }
.overview .tip { text-align: center; font-size: 12px; color: var(--text-light); margin-top: 8px; }

/* 当前学科横幅 */
.subject-banner {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
  border-radius: 10px; padding: 14px 20px; margin-bottom: 14px;
  color: #fff;
}
.subject-banner-icon { font-size: 34px; }
.subject-banner-text h3 { font-size: 20px; margin: 0; }
.subject-banner-sub { font-size: 12.5px; opacity: 0.9; margin-top: 2px; }

/* 知识树叶列表 */
.leaf-card {
  background: var(--card-bg); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 12px;
  border-left: 4px solid var(--accent);
  overflow: hidden;
}
.leaf-card.hidden { display: none; }
.leaf-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; cursor: pointer; user-select: none;
}
.leaf-header:hover { background: #f7fafc; }
.leaf-num {
  flex-shrink: 0; width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: bold;
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.leaf-title { font-size: 16px; font-weight: bold; flex: 1; }
.leaf-branch {
  flex-shrink: 0; font-size: 11.5px; color: var(--accent-dark);
  background: #eaf2f8; border-radius: 12px; padding: 2px 10px;
}
.leaf-arrow { flex-shrink: 0; color: var(--text-light); transition: transform 0.2s; font-size: 14px; }
.leaf-card.open .leaf-arrow { transform: rotate(180deg); }

/* 展开详情 */
.leaf-detail { display: none; padding: 4px 18px 18px; border-top: 1px dashed var(--border); }
.leaf-card.open .leaf-detail { display: block; }
.leaf-card.open .leaf-header { background: #f7fafc; }

.field {
  margin-top: 14px; background: #f8fafc; border-radius: 10px; padding: 12px 16px;
}
.field-tag {
  display: inline-block; font-size: 12px; font-weight: bold;
  padding: 2px 12px; border-radius: 12px; margin-bottom: 6px;
  background: var(--accent); color: #fff;
}
.field-body { font-size: 14.5px; color: var(--text); }
.field-body strong { color: #b03a2e; }
.field-body .math-block { text-align: center; margin: 6px 0; }

/* 上一片/下一片 */
.leaf-nav {
  display: flex; justify-content: space-between; gap: 10px; margin-top: 16px;
}
.leaf-nav button {
  border: 1px solid var(--border); background: var(--card-bg);
  padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 13px;
  color: var(--accent-dark); font-family: inherit;
}
.leaf-nav button:hover { background: #eaf2f8; }
.leaf-nav button:disabled { opacity: 0.4; cursor: not-allowed; }

/* 搜索高亮 */
mark { background: #ffe58a; border-radius: 3px; padding: 0 2px; }

/* 空结果 */
.empty-state {
  text-align: center; padding: 50px 20px; color: var(--text-light); font-size: 15px;
}

/* 回到顶部 */
.back-top {
  position: fixed; right: 24px; bottom: 24px;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); color: #fff; border: none; font-size: 20px;
  cursor: pointer; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  display: none; z-index: 99;
}
.back-top.show { display: block; }

/* 图片放大弹窗 */
.lightbox {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.85); justify-content: center; align-items: center;
  cursor: zoom-out; padding: 24px;
}
.lightbox.show { display: flex; }
.lightbox img { max-width: 94%; max-height: 94%; border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,0.5); }

/* 页脚 */
footer {
  text-align: center; padding: 20px; font-size: 12.5px; color: var(--text-light);
}

/* ===== 响应式 ===== */

/* ---------- 平板适配 ---------- */
@media (max-width: 1024px) {
  .main { grid-template-columns: 200px 1fr; }
  .sidebar { top: 150px; }
  .branch-list { max-height: 400px; }
}

/* ---------- 手机适配 ---------- */
@media (max-width: 768px) {
  /* 顶部导航 */
  .topbar-inner { padding: 10px 12px 0; }
  .site-title h1 { font-size: 18px; }
  .site-title .subtitle { font-size: 11px; }
  .subject-tabs { gap: 6px; margin-top: 10px; }
  .subject-tabs button { font-size: 14px; padding: 8px 14px; border-width: 1.5px; }
  .subject-tabs button:hover { transform: none; }
  .subject-tabs button.active { transform: none; }

  /* 搜索栏 */
  .search-wrap { padding: 10px 0 12px; }
  .search-box input { padding: 10px 40px 10px 14px; font-size: 14px; }
  .search-stats { font-size: 11px; padding-left: 8px; }

  /* 主内容 */
  .main { grid-template-columns: 1fr; padding: 14px 12px 50px; gap: 14px; }

  /* 侧边栏 → 横向滚动树枝标签 */
  .sidebar { position: static; order: -1; }
  .sidebar h2 { font-size: 13px; padding: 10px 12px; }
  .branch-list {
    max-height: none; display: flex; flex-wrap: nowrap;
    overflow-x: auto; gap: 6px; padding: 8px;
    -webkit-overflow-scrolling: touch;
  }
  .branch-item { flex: 0 0 auto; white-space: nowrap; font-size: 12.5px; padding: 7px 10px; }
  .branch-item .range { display: none; }

  /* 学科横幅 */
  .subject-banner { padding: 10px 14px; gap: 10px; }
  .subject-banner-icon { font-size: 26px; }
  .subject-banner-text h3 { font-size: 17px; }
  .subject-banner-sub { font-size: 11px; }

  /* 树叶卡片 */
  .leaf-card { border-left-width: 3px; margin-bottom: 10px; }
  .leaf-header { padding: 10px 12px; gap: 10px; flex-wrap: wrap; }
  .leaf-header:hover { background: transparent; }
  .leaf-num { width: 32px; height: 32px; font-size: 13px; }
  .leaf-title { font-size: 15px; }
  .leaf-branch { display: none; }
  .leaf-detail { padding: 2px 12px 14px; }
  .leaf-card.open .leaf-header { background: transparent; }

  /* 字段 */
  .field { padding: 10px 12px; margin-top: 12px; }
  .field-tag { font-size: 11px; padding: 1px 10px; }
  .field-body { font-size: 14px; }
  /* 公式防溢出 */
  .field-body .math-block,
  .field-body mjx-container {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    max-width: 100%; padding: 2px 0;
  }
  .field-body mjx-container { display: block; }

  /* 上一片/下一片 */
  .leaf-nav button { font-size: 12px; padding: 7px 10px; }
  .leaf-nav { gap: 6px; }

  /* 其他 */
  .back-top { right: 14px; bottom: 14px; width: 40px; height: 40px; font-size: 18px; }
  .lightbox { padding: 12px; }
  .empty-state { padding: 40px 14px; font-size: 14px; }
  footer { font-size: 11px; padding: 16px 12px; }
}

/* ---------- 超小屏手机适配 ---------- */
@media (max-width: 400px) {
  .site-title h1 { font-size: 16px; }
  .site-title .subtitle { font-size: 10px; }
  .subject-tabs button { font-size: 13px; padding: 7px 10px; }
  .leaf-num { width: 28px; height: 28px; font-size: 12px; }
  .leaf-title { font-size: 14px; }
  .subject-banner-text h3 { font-size: 16px; }
  .search-box input { font-size: 13px; }
}