:root {
  --accent: #1a7f4e;
  --accent-soft: #e6f4ec;
  --accent-dark: #125e38;
  --bg: #f5f7f6;
  --panel: #ffffff;
  --border: #e2e8e4;
  --text: #22302a;
  --text-2: #6b7a72;
  --sidebar-w: 330px;
  --topbar-h: 52px;
  --toolbar-h: 48px;
}

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

html, body { height: 100%; }

body {
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* 顶栏 */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: linear-gradient(90deg, #14532d, #1a7f4e);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
  position: relative;
  z-index: 5;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.hamburger {
  display: none;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,.16);
  color: #fff;
  font-size: 19px;
  cursor: pointer;
  flex-shrink: 0;
}
.hamburger:active { background: rgba(255,255,255,.3); }
.brand { display: flex; align-items: center; gap: 8px; font-size: 17px; font-weight: 600; letter-spacing: 1px; }
.brand-icon { font-size: 20px; }
.topbar-meta { font-size: 13px; opacity: .92; flex-shrink: 0; }

/* 手机端抽屉遮罩 */
.backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 60;
  opacity: 0;
  transition: opacity .2s;
}
.backdrop.show { opacity: 1; }

/* 主体两栏 */
.main { display: flex; height: calc(100vh - var(--topbar-h)); }

/* 左侧目录 */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.search-wrap {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.search-wrap input {
  flex: 1;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 10px;
  font-size: 13px;
  outline: none;
  background: #fbfcfb;
}
.search-wrap input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.btn-mini {
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text-2);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-mini:hover { border-color: var(--accent); color: var(--accent); }

.tree { flex: 1; overflow-y: auto; padding: 6px 8px 12px; }
.tree::-webkit-scrollbar { width: 8px; }
.tree::-webkit-scrollbar-thumb { background: #c9d6cf; border-radius: 4px; }

.book { margin-bottom: 4px; }
.book-head {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 10px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(90deg, #2e8b57, #3aa06a);
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  margin-bottom: 4px;
}
.book-head .arrow { transition: transform .15s; font-size: 11px; }
.book.open .book-head .arrow { transform: rotate(90deg); }
.book-head .book-count { margin-left: auto; font-size: 11px; font-weight: 400; opacity: .85; }

.chapter { margin: 2px 0; }
.chapter-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px 6px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  border-radius: 6px;
}
.chapter-head:hover { background: #f0f5f2; }
.chapter-head .arrow { transition: transform .15s; font-size: 10px; color: var(--text-2); }
.chapter.open .chapter-head .arrow { transform: rotate(90deg); }
.chapter-head .chapter-count { margin-left: auto; font-size: 11px; color: var(--text-2); }

.lesson {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px 6px 28px;
  font-size: 13px;
  color: #37433d;
  cursor: pointer;
  border-radius: 6px;
  line-height: 1.35;
}
.lesson:hover { background: var(--accent-soft); color: var(--accent-dark); }
.lesson.active { background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }
.lesson .doc-ico { font-size: 12px; opacity: .75; flex-shrink: 0; }

.sidebar-foot {
  padding: 8px 12px;
  font-size: 11px;
  color: var(--text-2);
  border-top: 1px solid var(--border);
  text-align: center;
  background: #fafcfb;
}

/* 右侧阅读区 */
.viewer { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.viewer-toolbar {
  height: var(--toolbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.doc-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toolbar-controls { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.toolbar-controls button {
  min-width: 30px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
  line-height: 1;
}
.toolbar-controls button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.toolbar-controls button:disabled { opacity: .4; cursor: default; }
.toolbar-controls .zoom-level, .toolbar-controls .page-info {
  font-size: 12px;
  color: var(--text-2);
  min-width: 44px;
  text-align: center;
}
.toolbar-controls .sep { width: 1px; height: 20px; background: var(--border); margin: 0 6px; }

.viewer-body {
  flex: 1;
  overflow: auto;
  background: #e8edea;
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
  touch-action: pan-y;
  overscroll-behavior: contain;
}
.viewer-body::-webkit-scrollbar { width: 10px; height: 10px; }
.viewer-body::-webkit-scrollbar-thumb { background: #b8c6be; border-radius: 5px; }

#pdfCanvas {
  background: #fff;
  box-shadow: 0 2px 14px rgba(0,0,0,.18);
  border-radius: 2px;
  display: none;
  max-width: none;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-2);
  font-size: 15px;
}
.placeholder-icon { font-size: 56px; opacity: .5; }

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(232,237,234,.7);
  z-index: 10;
}
.loading span {
  padding: 10px 22px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,.12);
  font-size: 14px;
  color: var(--text);
}

/* ===== 手机端：目录抽屉 + 紧凑工具栏 ===== */
@media (max-width: 768px) {
  .hamburger { display: block; }

  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: min(84vw, 330px);
    min-width: 0;
    transform: translateX(-105%);
    transition: transform .22s ease;
    z-index: 70;
    box-shadow: 2px 0 14px rgba(0,0,0,.18);
  }
  .sidebar.open { transform: translateX(0); }
  .backdrop.show { display: block; }

  .main { display: block; }
  .viewer { height: calc(100vh - var(--topbar-h)); }

  .topbar { padding: 0 10px; }
  .brand { font-size: 15px; }
  .brand-icon { font-size: 17px; }

  .viewer-toolbar {
    flex-wrap: wrap;
    padding: 6px 10px;
    gap: 6px;
    height: auto;
    min-height: var(--toolbar-h);
  }
  .doc-title { order: -1; width: 100%; font-size: 13px; }
  .toolbar-controls { gap: 3px; }
  .toolbar-controls button { min-width: 32px; height: 32px; padding: 0 6px; }
  .toolbar-controls .zoom-level, .toolbar-controls .page-info { min-width: 38px; }
  .toolbar-controls .sep { margin: 0 3px; }

  .viewer-body { padding: 10px; }

  .lesson { padding-left: 22px; }
}

@media (max-width: 900px) and (min-width: 769px) {
  .sidebar { width: 250px; min-width: 250px; }
  .doc-title { max-width: 40vw; }
}
