/* [bookshelf] 首页书架 + PDF 阅读器（连续滚动 / 缩放 / 高亮备注） */

/* ==================== 一、书架区块 ==================== */

#bookshelf .books-shell {
  width: 92%;
  max-width: 960px;
  margin: 0 auto;
  text-align: left;
}

#bookshelf .books-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, .25);
  padding-bottom: 8px;
  margin-bottom: 14px;
}

#bookshelf .books-title {
  margin: 0;
  font-weight: 300;
  letter-spacing: 2px;
  color: #fff;
}

#bookshelf .books-count {
  font-size: 12px;
  color: rgba(255, 255, 255, .5);
}

/* 上传进度条 */
#bookshelf .books-upload-bar { margin-bottom: 14px; }

#bookshelf .bu-text {
  font-size: 12px;
  color: rgba(255, 255, 255, .7);
  margin-bottom: 6px;
  word-break: break-all;
}

#bookshelf .bu-track {
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, .12);
  overflow: hidden;
}

#bookshelf .bu-fill {
  height: 100%;
  width: 0;
  background: #2179ec;
  transition: width .15s linear;
}

/* 卡片 */
#bookshelf .books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

#bookshelf .book-card {
  position: relative;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 8px;
  background: rgba(255, 255, 255, .06);
  color: #fff;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .15s;
  -webkit-tap-highlight-color: transparent;
}

#bookshelf .book-card:hover,
#bookshelf .book-card:active {
  background: rgba(255, 255, 255, .13);
  border-color: rgba(255, 255, 255, .35);
}

#bookshelf .book-card.confirming {
  transform: none;
  border-color: rgba(255, 255, 255, .2);
  background: rgba(255, 255, 255, .06);
}

#bookshelf .bc-icon {
  font-size: 22px;
  color: rgba(255, 255, 255, .45);
  margin-bottom: 10px;
}

#bookshelf .bc-title {
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  padding-right: 18px;
}

#bookshelf .bc-dir {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .12);
  color: rgba(255, 255, 255, .65);
}

#bookshelf .bc-meta {
  margin-top: 8px;
  font-size: 11px;
  color: rgba(255, 255, 255, .4);
}

#bookshelf .bc-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: rgba(255, 255, 255, .3);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#bookshelf .bc-del:hover,
#bookshelf .bc-del:active {
  background: rgba(255, 255, 255, .14);
  color: #ff6b6b;
}

#bookshelf .bc-confirm {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(22, 22, 22, .96);
  text-align: center;
}

#bookshelf .book-card.confirming .bc-confirm { display: flex; }

#bookshelf .bc-confirm-text {
  font-size: 12px;
  color: rgba(255, 255, 255, .8);
  line-height: 1.4;
  word-break: break-word;
  max-height: 3.2em;
  overflow: hidden;
}

#bookshelf .bc-confirm-btns { display: flex; gap: 8px; }

#bookshelf .bc-btn {
  border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 6px;
  background: rgba(255, 255, 255, .1);
  color: #eee;
  font-size: 12px;
  padding: 5px 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#bookshelf .bc-btn:active { background: rgba(255, 255, 255, .22); }
#bookshelf .bc-btn.bc-danger { background: #c9302c; border-color: #c9302c; color: #fff; }

#bookshelf .books-msg {
  padding: 40px 0;
  text-align: center;
  color: rgba(255, 255, 255, .55);
  font-size: 14px;
}

#bookshelf .books-msg .btn { margin-top: 12px; }

/* ==================== 二、阅读器 ==================== */

.bk-reader {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 2000;
  display: none;
  flex-direction: column;
  background: #141414;
  color: #eee;
}

.bk-reader.open { display: flex; }

/* ---------- 通用按钮 ---------- */

.bk-btn {
  background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .16);
  color: #eee;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 14px;
  line-height: 1.2;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.bk-btn:active { background: rgba(255, 255, 255, .22); }
.bk-btn[disabled] { opacity: .3; }
.bk-btn.active { background: #2179ec; border-color: #2179ec; color: #fff; }
.bk-btn.bk-primary { background: #2179ec; border-color: #2179ec; color: #fff; }

/* ---------- 顶栏 ---------- */

.bk-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: #232323;
  border-bottom: 1px solid rgba(255, 255, 255, .1);
}

.bk-topbar .bk-name {
  flex: 1 1 90px;
  min-width: 0;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bk-zoom {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}

.bk-zoom .bk-zbtn { padding: 6px 10px; font-size: 15px; }

.bk-zoom .bk-zval {
  min-width: 46px;
  text-align: center;
  font-size: 13px;
  color: rgba(255, 255, 255, .75);
  font-variant-numeric: tabular-nums;
}

.bk-annbtn { display: flex; align-items: center; gap: 5px; flex: 0 0 auto; }

.bk-anncount {
  display: inline-block;
  min-width: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .16);
  font-size: 11px;
  line-height: 16px;
  text-align: center;
}

/* ---------- 正文滚动区 ---------- */

.bk-body {
  position: relative;
  flex: 1;
  overflow-x: hidden;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  background: #141414;
}

.bk-pages {
  position: relative;
  margin: 0 auto;
  padding: 14px 0 0;
}

.bk-page {
  position: relative;
  margin: 0 auto 14px;
  background: #fff;
  box-shadow: 0 2px 14px rgba(0, 0, 0, .55);
  overflow: hidden;
}

.bk-page .bk-canvas {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 0;
  display: block;
}

/* 高亮层：在文字层**下面**且不吃事件，绝不妨碍选字 */
.bk-hls {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  pointer-events: none;
}

.bk-hlm {
  position: absolute;
  background: rgba(255, 214, 0, .40);
  border-radius: 2px;
}

.bk-hlm.has-note { background: rgba(255, 166, 0, .48); }

.bk-hlnote {
  position: absolute;
  width: 15px;
  height: 15px;
  margin: -7px 0 0 1px;
  border-radius: 50%;
  background: #ffb400;
  color: #3a2a00;
  font-size: 9px;
  line-height: 15px;
  text-align: center;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

/* ---------- pdf.js 文字层（取自 pdf_viewer.css，opacity 改为 1 让选区更清晰）---------- */

.bk-textlayer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  text-align: initial;
  overflow: hidden;
  opacity: 1;
  line-height: 1;
  -webkit-text-size-adjust: none;
  -moz-text-size-adjust: none;
  text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0 0;
  z-index: 2;
  cursor: text;
}

.bk-textlayer span,
.bk-textlayer br {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}

.bk-textlayer span.markedContent { top: 0; height: 0; }

/* 目录页上的条目行：可点跳转。平时完全透明（不给正文加装饰），只在悬停/按下时给一点底色 */
.bk-toclink {
  position: absolute;
  z-index: 3;
  cursor: pointer;
  border-radius: 3px;
  background: transparent;
  -webkit-tap-highlight-color: rgba(33, 121, 236, .25);
}

.bk-toclink:hover { background: rgba(33, 121, 236, .16); }
.bk-toclink:active { background: rgba(33, 121, 236, .30); }

.bk-textlayer ::selection { background: rgba(33, 121, 236, .45); }
.bk-textlayer br::selection { background: transparent; }

.bk-textlayer .endOfContent {
  display: block;
  position: absolute;
  top: 100%;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: -1;
  cursor: default;
  -webkit-user-select: none;
  user-select: none;
}

.bk-textlayer .endOfContent.active { top: 0; }

/* 状态提示 / 顶部进度条 */
.bk-status {
  position: absolute;
  left: 0;
  right: 0;
  top: 40%;
  text-align: center;
  color: rgba(255, 255, 255, .6);
  font-size: 13px;
  pointer-events: none;
}

.bk-progress {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 2px;
  pointer-events: none;
}

.bk-progress-fill {
  height: 100%;
  width: 0;
  background: #2179ec;
  transition: width .15s linear;
}

/* ---------- 底栏 ---------- */

.bk-bottombar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 14px;
  padding: 9px 12px;
  padding-bottom: calc(9px + env(safe-area-inset-bottom));
  background: #232323;
  border-top: 1px solid rgba(255, 255, 255, .1);
}

/* 底栏里的两组：翻页 / 工具（缩放·适宽·标注） */
.bk-pager {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bk-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.bk-pagebox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}

.bk-pageinput {
  width: 58px;
  text-align: center;
  background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .16);
  color: #eee;
  border-radius: 6px;
  padding: 5px 4px;
  font-size: 14px;
}

.bk-total { color: rgba(255, 255, 255, .6); font-size: 13px; }

/* ---------- 护眼模式（夜间看白底 PDF 不刺眼）----------
   底栏「护眼」按钮切换。只作用于 PDF 页面：降一点亮度 + 叠一层暖色。
   顶/底栏本来就是深色，不刺眼，不动。
   亮度 0.85 = 暗 15%；暖色是暖橙 rgba(255,201,126) 套 26% 不透明度。 */

.bk-eyebtn { flex: 0 0 auto; }

.bk-eyebtn.active {
  background: #d9a441;
  border-color: #d9a441;
  color: #241a00;
}

/* 降亮度只作用在 canvas 上：整本书有 384 个 .bk-page div，
   但只有可见的几页才有 canvas，加 filter 的层数少得多（省内存/不卡）。 */
.bk-pages.bk-eye .bk-canvas { filter: brightness(.85) contrast(.97); }

/* 还没渲染出 canvas 的页（快速滚动时）也不能是纯白，给个同色调的底，
   叠上暖色罩子后 ≈ 已渲染页的颜色，不会闪一下白。 */
.bk-pages.bk-eye .bk-page { background: #d8cdb8; }

/* 暖色罩子：z-index 4 在文字层(2)/目录热点(3)之上，但 pointer-events:none，
   所以照样能选字、点目录。 */
.bk-pages.bk-eye .bk-page::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 4;
  pointer-events: none;
  background: rgba(255, 201, 126, .26);
}

/* ---------- 标注浮层（选区动作）---------- */

.bk-selpop {
  position: fixed;
  z-index: 2600;
  display: flex;
  gap: 6px;
  padding: 5px;
  border-radius: 9px;
  background: #2c2c2c;
  border: 1px solid rgba(255, 255, 255, .14);
  box-shadow: 0 6px 22px rgba(0, 0, 0, .5);
}

.bk-selpop-btn {
  border: 0;
  border-radius: 6px;
  background: rgba(255, 255, 255, .1);
  color: #eee;
  font-size: 13px;
  padding: 6px 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.bk-selpop-btn:active { background: rgba(255, 255, 255, .25); }

/* ---------- 备注编辑弹层 ---------- */

.bk-editpop {
  position: fixed;
  z-index: 2700;
  width: 290px;
  max-width: calc(100vw - 20px);
  padding: 10px;
  border-radius: 10px;
  background: #2c2c2c;
  border: 1px solid rgba(255, 255, 255, .14);
  box-shadow: 0 10px 34px rgba(0, 0, 0, .6);
}

.bk-editpop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.bk-editpop-page { font-size: 12px; color: rgba(255, 255, 255, .55); }

.bk-editpop-del {
  border: 0;
  background: transparent;
  color: #ff7b7b;
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
}

.bk-editpop-quote {
  font-size: 12px;
  line-height: 1.5;
  color: rgba(255, 255, 255, .62);
  max-height: 4.5em;
  overflow: auto;
  border-left: 2px solid rgba(255, 255, 255, .2);
  padding-left: 8px;
  margin-bottom: 8px;
}

.bk-editpop-note {
  width: 100%;
  box-sizing: border-box;
  min-height: 76px;
  resize: vertical;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 6px;
  color: #eee;
  font-size: 13px;
  line-height: 1.5;
  padding: 7px 9px;
  font-family: inherit;
}

.bk-editpop-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

/* ---------- 标注列表 ---------- */

.bk-annpanel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 320px;
  max-width: 88vw;
  z-index: 2500;
  display: flex;
  flex-direction: column;
  background: #1e1e1e;
  border-left: 1px solid rgba(255, 255, 255, .12);
  box-shadow: -8px 0 28px rgba(0, 0, 0, .45);
  transform: translateX(102%);
  transition: transform .22s ease;
}

.bk-annpanel.open { transform: translateX(0); }

.bk-annpanel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  padding-top: calc(12px + env(safe-area-inset-top));
  border-bottom: 1px solid rgba(255, 255, 255, .1);
}

.bk-annpanel-title { font-size: 14px; color: #fff; }

.bk-annpanel-close { padding: 4px 10px; font-size: 16px; }

.bk-annpanel-list { flex: 1; overflow-y: auto; padding: 8px; }

.bk-annpanel-empty {
  text-align: left;
  padding: 10px 16px 20px;
  color: rgba(255, 255, 255, .45);
  font-size: 12px;
  line-height: 1.6;
}

.bk-annitem {
  padding: 9px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid rgba(255, 255, 255, .08);
  margin-bottom: 8px;
  cursor: pointer;
}

.bk-annitem:active { background: rgba(255, 255, 255, .12); }

.bk-annitem-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}

.bk-annitem-page {
  font-size: 11px;
  font-weight: 700;
  color: #ffb400;
  background: rgba(255, 180, 0, .14);
  border-radius: 4px;
  padding: 1px 5px;
}

.bk-annitem-tag {
  font-size: 10px;
  color: rgba(255, 255, 255, .5);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 4px;
  padding: 0 4px;
}

.bk-annitem-del {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, .35);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}

.bk-annitem-del:hover { color: #ff6b6b; }

.bk-annitem-text {
  text-align: left;
  font-size: 12.5px;
  line-height: 1.55;
  color: rgba(255, 255, 255, .8);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.bk-annitem-note {
  text-align: left;
  margin-top: 6px;
  font-size: 12.5px;
  line-height: 1.55;
  color: #ffd479;
  border-left: 2px solid rgba(255, 180, 0, .5);
  padding-left: 7px;
  white-space: pre-wrap;
}

/* ---------- 目录面板（从左侧滑出，与右侧标注面板对称）---------- */

.bk-tocbtn { flex: 0 0 auto; }

.bk-tocpanel {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 330px;
  max-width: 88vw;
  z-index: 2500;
  display: flex;
  flex-direction: column;
  background: #1e1e1e;
  border-right: 1px solid rgba(255, 255, 255, .12);
  box-shadow: 8px 0 28px rgba(0, 0, 0, .45);
  transform: translateX(-102%);
  transition: transform .22s ease;
}

.bk-tocpanel.open { transform: translateX(0); }

.bk-tocpanel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  padding-top: calc(12px + env(safe-area-inset-top));
  border-bottom: 1px solid rgba(255, 255, 255, .1);
}

.bk-tocpanel-title { font-size: 14px; color: #fff; }
.bk-tocpanel-close { padding: 4px 10px; font-size: 16px; }

.bk-tocpanel-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px 0 16px;
}

.bk-tocitem {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 12px;
  padding-right: 12px;
  font-size: 13px;
  line-height: 1.45;
  color: rgba(255, 255, 255, .82);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.bk-tocitem:active { background: rgba(255, 255, 255, .1); }
.bk-tocitem.active { background: rgba(33, 121, 236, .18); color: #fff; }

/* 注意：CodiMD 首页的 body 带 text-align: center，会继承进阅读器。
   下面这些块级元素必须显式声明对齐，否则短文本（如"译者前言"、高亮文字）会居中。 */

.bk-tocitem-title {
  flex: 1;
  min-width: 0;
  word-break: break-word;
  text-align: left;
}

.bk-tocitem-page {
  flex: 0 0 auto;
  text-align: right;
  font-size: 11px;
  color: rgba(255, 255, 255, .4);
  font-variant-numeric: tabular-nums;
}

.bk-tocitem.active .bk-tocitem-page { color: rgba(255, 255, 255, .7); }

/* ---------- 侧栏让位：侧栏打开时正文整体收缩让开，不被面板盖住 ----------
   目录在左让 330px、标注在右让 320px；330/320 分别等于 .bk-tocpanel /
   .bk-annpanel 的 width（必须一致）。只在面板呈"侧栏"形态的宽度下生效；
   <=600px 时面板是满屏的，本来就没有可让的空间。 */

@media (min-width: 601px) {
  .bk-reader.toc-open .bk-body { margin-left: 330px; }
  .bk-reader.ann-open .bk-body { margin-right: 320px; }
}

/* ---------- 移动端 ---------- */

@media (max-width: 600px) {
  #bookshelf .books-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }

  .bk-topbar { gap: 6px; padding: 7px 8px; padding-top: calc(7px + env(safe-area-inset-top)); }
  .bk-topbar .bk-name { flex: 1 1 auto; font-size: 13px; }
  .bk-btn { padding: 5px 8px; font-size: 12.5px; }
  .bk-zoom .bk-zbtn { padding: 4px 7px; font-size: 14px; }
  .bk-zoom .bk-zval { min-width: 36px; font-size: 12px; }
  .bk-pageinput { width: 46px; padding: 4px 2px; font-size: 13px; }
  /* 底栏塞进 390px：翻页组和工具组各占一行（放得下时自然还是同一行） */
  .bk-bottombar { gap: 6px 8px; padding: 7px 6px; padding-bottom: calc(7px + env(safe-area-inset-bottom)); }
  .bk-pager { gap: 6px; }
  .bk-tools { gap: 4px; }
  .bk-annpanel { width: 100%; max-width: none; }
  .bk-tocpanel { width: 100%; max-width: none; }
  .bk-pages { padding-top: 8px; }
  .bk-page { margin-bottom: 8px; }
}
