/* ============================================================
   reader.css —— 教材书架 + 阅读器专用样式
   ============================================================ */

/* ================= 书架页 ================= */
.shelf-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 18px;
}
.shelf-bar .search-inline {
  flex: 1; min-width: 200px;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px;
}
.shelf-bar .search-inline:focus-within { border-color: var(--primary); }
.shelf-bar .search-inline input { flex: 1; border: none; background: none; outline: none; font-size: 14.5px; min-width: 0; }
.shelf-bar .search-inline .ic { width: 17px; height: 17px; color: var(--text-3); }
.shelf-bar select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 14px; min-height: 38px; outline: none;
}
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.book-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 10px;
  transition: transform .15s ease, border-color .15s ease;
}
.book-card:hover { transform: translateY(-2px); border-color: var(--text-3); }
.book-top { display: flex; gap: 12px; align-items: center; }
.book-cover {
  width: 42px; height: 54px; border-radius: 5px; flex: none;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 20px; font-weight: 700;
}
.book-name { font-size: 16px; font-weight: 700; line-height: 1.35; word-break: break-all; }
.book-sub { font-size: 12.5px; color: var(--text-3); margin-top: 3px; }
.book-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.book-progress { height: 6px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.book-progress i { display: block; height: 100%; background: var(--primary); border-radius: 4px; }
.book-actions { display: flex; gap: 8px; margin-top: 2px; }
.book-actions .btn { flex: 1; min-height: 36px; font-size: 13.5px; }

/* ================= 阅读器整体 ================= */
.reader {
  display: flex; flex-direction: column;
  height: calc(100vh - var(--topbar-h));
  background: var(--bg);
}
.reader-toolbar {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-bottom: 1px solid var(--border);
  background: var(--surface); flex: none; overflow-x: auto;
}
.reader-toolbar .rt-title { font-size: 15px; font-weight: 700; white-space: nowrap; padding-right: 6px; }
.reader-toolbar .rt-sep { width: 1px; height: 22px; background: var(--border); flex: none; margin: 0 4px; }
.reader-toolbar .icon-btn { width: 38px; height: 38px; flex: none; }
.reader-toolbar .rt-grow { flex: 1; }
.reader-toolbar .rt-progress { font-size: 13px; color: var(--text-2); white-space: nowrap; flex: none; }
.reader-toolbar::-webkit-scrollbar { height: 0; }   /* 隐藏横向滚动条，仍可滑动 */

/* 阅读进度细条（紧贴工具栏下方） */
.reader-pbar { height: 3px; flex: none; background: var(--surface-2); }
.reader-pbar i { display: block; height: 100%; width: 0; background: var(--primary); transition: width .2s ease; }

.reader-body { flex: 1; display: flex; min-height: 0; }

/* ---- 目录侧栏 ---- */
.toc {
  width: 264px; flex: none; border-right: 1px solid var(--border);
  background: var(--surface); overflow-y: auto; padding: 10px 8px;
}
.toc-node { user-select: none; }
.toc-label {
  display: flex; align-items: center; gap: 4px;
  padding: 7px 6px; border-radius: var(--radius-sm);
  font-size: 14px; color: var(--text-2); line-height: 1.3;
  min-height: 34px; cursor: pointer;
}
.toc-label:hover { background: var(--surface-2); }
.toc-label.active { background: var(--primary-soft); color: var(--primary-strong); font-weight: 600; }
.toc-label .toc-arrow { width: 16px; height: 16px; flex: none; transition: transform .15s ease; color: var(--text-3); }
.toc-label .toc-arrow.open { transform: rotate(90deg); }
.toc-label .toc-dot { width: 16px; flex: none; }
.toc-label .t-text { flex: 1; word-break: break-all; }
.toc-label .toc-state { flex: none; font-size: 12px; }
.toc-children { display: block; }
.toc-children.hidden { display: none; }
.toc-label.lvl-1 { font-weight: 600; color: var(--text); }

/* ---- 正文区 ---- */
.reader-scroll { flex: 1; overflow-y: auto; min-width: 0; }
.reader-content {
  max-width: 760px; margin: 0 auto; padding: 30px 30px 60px;
  font-size: var(--reader-font, 17px);
  line-height: var(--reader-lh, 1.75);
}
.reader-content .sec-title { font-size: 1.5em; font-weight: 700; margin-bottom: 18px; line-height: 1.3; }
.reader-content .sec-mark { display: flex; gap: 8px; margin-bottom: 22px; flex-wrap: wrap; }
.reader-content .sec-mark .btn { min-height: 36px; font-size: 13.5px; }
.reader-content p { margin: 0 0 14px; }
.reader-content h1, .reader-content h2, .reader-content h3, .reader-content h4 { margin: 26px 0 12px; line-height: 1.35; }
.reader-content h2 { font-size: 1.3em; }
.reader-content h3 { font-size: 1.15em; }
.reader-content ul, .reader-content ol { margin: 0 0 14px; padding-left: 1.6em; }
.reader-content li { margin-bottom: 6px; }
.reader-content blockquote {
  margin: 0 0 14px; padding: 10px 16px; border-left: 3px solid var(--primary);
  background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--text-2);
}
.reader-content pre {
  margin: 0 0 14px; padding: 14px 16px; border-radius: var(--radius-sm);
  background: var(--surface-2); overflow-x: auto; line-height: 1.5;
}
.reader-content code { font-family: Consolas, "Courier New", monospace; font-size: .9em; }
.reader-content :not(pre) > code { background: var(--surface-2); padding: 2px 6px; border-radius: 4px; }
.reader-content table { border-collapse: collapse; width: 100%; margin: 0 0 16px; font-size: .92em; }
.reader-content th, .reader-content td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }
.reader-content th { background: var(--surface-2); font-weight: 600; }
.reader-content hr { border: none; border-top: 1px solid var(--border); margin: 22px 0; }

.reader-nav {
  display: flex; gap: 12px; margin-top: 36px; padding-top: 20px;
  border-top: 1px solid var(--border);
}
.reader-nav .btn { flex: 1; min-height: 44px; }

/* ---- 高亮标记（荧光三色） ---- */
mark.hl-yellow, mark.hl-green, mark.hl-pink, mark.search-hit {
  border-radius: 3px; padding: 0 2px; color: inherit;
}
mark.hl-yellow { background: #ffe66b; }
mark.hl-green { background: #a8e6a1; }
mark.hl-pink { background: #ffb3d1; }
mark.search-hit { background: var(--accent-soft); outline: 1px solid var(--accent); }
[data-theme="dark"] mark.hl-yellow { background: #8a7a2b; color: #fff; }
[data-theme="dark"] mark.hl-green { background: #3f7a42; color: #fff; }
[data-theme="dark"] mark.hl-pink { background: #9a4d6b; color: #fff; }

/* ---- 划选工具条 ---- */
.sel-toolbar {
  position: fixed; z-index: 120; display: flex; gap: 4px;
  background: var(--text); border-radius: 8px; padding: 5px;
  box-shadow: var(--shadow-pop);
}
.sel-toolbar .st-btn {
  width: 34px; height: 34px; border-radius: 6px; display: flex;
  align-items: center; justify-content: center; font-size: 13px;
}
.sel-toolbar .st-btn .sw { width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); }
.sel-toolbar .st-btn.note { color: #fff; gap: 4px; width: auto; padding: 0 10px; font-size: 13px; }

/* ---- 侧滑面板（检索 / 划线批注） ---- */
.panel-mask { position: fixed; inset: 0; background: rgba(15,20,25,.4); z-index: 90; }
.side-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 380px; max-width: 92vw; z-index: 91;
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; animation: slide-in .18s ease;
}
@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } }
.side-panel .sp-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.side-panel .sp-head .t { font-size: 16px; font-weight: 700; }
.side-panel .sp-body { flex: 1; overflow-y: auto; padding: 14px 18px; }
.side-panel .sp-foot { padding: 12px 18px; border-top: 1px solid var(--border); }
.search-input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 14.5px; outline: none; background: var(--bg);
}
.search-input:focus { border-color: var(--primary); }
.hit-group { margin-bottom: 14px; }
.hit-group .hg-title { font-size: 14px; font-weight: 700; padding: 8px; background: var(--surface-2); border-radius: var(--radius-sm); cursor: pointer; display: flex; justify-content: space-between; }
.hit-group .hg-snips { padding: 8px 8px 4px; }
.hit-snip { font-size: 13px; color: var(--text-2); padding: 6px 4px; border-bottom: 1px dashed var(--border); cursor: pointer; line-height: 1.5; }
.hit-snip:hover { color: var(--text); }

.ann-item { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 10px; }
.ann-item .ai-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.ann-item .ai-text { font-size: 13.5px; line-height: 1.5; }
.ann-item .ai-note { font-size: 13.5px; margin-top: 8px; padding: 8px 10px; background: var(--surface-2); border-radius: var(--radius-sm); }
.ann-item .ai-actions { display: flex; gap: 8px; margin-top: 8px; }
.ann-item .ai-actions .btn { min-height: 32px; font-size: 12.5px; padding: 0 10px; }
.ann-sec { font-size: 12px; color: var(--text-3); }

/* ---- 移动端目录抽屉 ---- */
.toc-drawer {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 95;
  width: 80vw; max-width: 320px; background: var(--surface);
  box-shadow: var(--shadow-pop); display: flex; flex-direction: column;
  animation: slide-left .18s ease;
}
@keyframes slide-left { from { transform: translateX(-30px); opacity: 0; } }
.toc-drawer .td-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); font-weight: 700; }
.toc-drawer .toc { width: auto; flex: 1; border: none; }

/* ================= 移动端适配 ================= */
@media (max-width: 820px) {
  .reader { height: calc(100vh - var(--topbar-h)); }
  .toc { display: none; }            /* 桌面目录隐藏，用抽屉 */
  .toc-drawer .toc { display: block; }   /* 抽屉内目录正常显示 */
  .reader-content { padding: 22px 18px 60px; }
  .reader-toolbar { padding: 8px 10px; }
  .reader-toolbar .rt-title { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
  .side-panel { width: 100vw; }
}

/* 极窄屏（≤480px）：工具栏只保留操作按钮，书名/分隔符/文字进度隐藏，进度看细条 */
@media (max-width: 480px) {
  .reader-toolbar { gap: 3px; padding: 7px 8px; }
  .reader-toolbar .rt-title,
  .reader-toolbar .rt-sep,
  .reader-toolbar .rt-progress,
  .reader-toolbar .rt-grow { display: none; }
  .reader-toolbar .icon-btn { width: 36px; height: 36px; }
  .reader-content { padding: 20px 15px 70px; }
}
