/* 阅读器：三栏、分批渲染、稳定锚点、位置记忆 */
.reader-body { background: var(--bg); }

.readlayout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 200px;
  gap: 26px;
  align-items: start;
  padding: 18px 0 80px;
}

/* 左栏 */
.rail { position: sticky; top: 68px; max-height: calc(100vh - 92px); overflow: auto; }
.tocfilter {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  margin-bottom: 10px;
  color: var(--ink);
}
.tocfilter:focus { outline: none; border-color: #c3cdf0; box-shadow: 0 0 0 3px #eef1ff; }

.tocgroup { margin-bottom: 6px; }
.tocgroup > button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  padding: 6px 8px;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--dimmer);
  cursor: pointer;
  font-family: inherit;
}
.tocgroup > button:hover { color: var(--ink); }
.tocgroup .caret { transition: transform .15s; display: inline-block; }
.tocgroup.closed .caret { transform: rotate(-90deg); }
.tocgroup.closed .tocitems { display: none; }

.tocitems a {
  display: flex;
  gap: 6px;
  align-items: baseline;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--dim);
  font-size: 13px;
  line-height: 1.45;
}
.tocitems a:hover { background: var(--surface); color: var(--ink); text-decoration: none; }
.tocitems a.on { background: var(--ink); color: #fff; }
.tocitems a .n { color: var(--dimmer); font-size: 11px; font-variant-numeric: tabular-nums; }
.tocitems a.on .n { color: rgba(255,255,255,.6); }
.tocitems a .w { margin-left: auto; color: var(--dimmer); font-size: 10.5px; }

.tocfoot { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); }
.tocfoot a { display: block; padding: 4px 10px; font-size: 12px; color: var(--dimmer); }
.tocfoot a:hover { color: var(--ink); text-decoration: none; }

/* 正文 */
.article {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 34px 46px 54px;
  box-shadow: var(--shadow-sm);
  min-height: 62vh;
  max-width: 46em;
  margin: 0 auto;
  font-size: var(--read-size, 17px);
}
.article h1 { font-family: var(--serif); font-size: 29px; line-height: 1.35; margin: 0 0 6px; letter-spacing: 1px; }
.article .meta { color: var(--dimmer); font-size: 12.5px; margin-bottom: 22px; }
.article p { font-size: var(--read-size, 17px); line-height: var(--read-lh, 1.9); margin: 0 0 12px; color: #1b2130; }
.article li { font-size: var(--read-size, 17px); line-height: var(--read-lh, 1.9); }
.article blockquote { line-height: 1.8; }
.article h2 { font-size: 20px; margin: 32px 0 10px; }
.article h3 { font-size: 15.5px; margin: 22px 0 8px; }

.article .chrow { font-size: calc(var(--read-size, 17px) - 3px); }

/* 骨架 / 错误 */
.skel { padding: 10px 0; }
.skel-line { height: 12px; border-radius: 6px; background: linear-gradient(90deg, #eef1f7, #f7f9fd, #eef1f7); background-size: 200% 100%; animation: skel 1.2s infinite; margin: 10px 0; }
.skel-line.w60 { width: 60%; }
.skel-line.w80 { width: 80%; }
@keyframes skel { to { background-position: -200% 0; } }

.article .loadmore { display: block; width: 100%; margin: 18px 0 0; padding: 10px; border: 1px dashed var(--line); border-radius: 10px; background: var(--surface-2); color: var(--dim); font-size: 13px; cursor: pointer; font-family: inherit; }
.article .errbox { padding: 18px; border: 1px solid #f6d5d1; background: #fdf3f2; border-radius: 12px; color: #a52a1e; }
.article .errbox button { margin-top: 10px; padding: 8px 16px; border-radius: 9px; border: 1px solid var(--ink); background: var(--ink); color: #fff; cursor: pointer; font-family: inherit; }

/* 右栏 */
.rail-right a { display: block; padding: 4px 8px; font-size: 12.5px; color: var(--dim); border-left: 2px solid transparent; }
.rail-right a:hover { color: var(--ink); text-decoration: none; }
.rail-right a.lv3 { padding-left: 18px; font-size: 12px; color: var(--dimmer); }
.rail-right a.on { border-left-color: var(--brand); color: var(--ink); background: var(--surface); }

/* 续读条 */
.resume {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 10px 16px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow); font-size: 13px; color: var(--dim); z-index: 40;
}
.resume[hidden] { display: none; }

@media (max-width: 1080px) {
  .readlayout { grid-template-columns: 220px minmax(0, 1fr); }
  .rail-right { display: none; }
}
@media (max-width: 780px) {
  .readlayout { grid-template-columns: 1fr; }
  #toc {
    position: fixed; inset: 56px auto 0 0; width: min(78vw, 320px); z-index: 45;
    background: var(--surface); border-right: 1px solid var(--line);
    padding: 12px; max-height: none;
    transform: translateX(-102%); transition: transform .2s ease;
  }
  body.toc-open #toc { transform: none; }
  .article { padding: 22px 18px 34px; }
  .article h1 { font-size: 23px; }
}

/* 锚点闪烁高亮 */
.article .flash { animation: flash 1.2s ease; }
@keyframes flash { 0% { background: #fff6d8; } 100% { background: transparent; } }

/* ══════════════ M2：高亮 / 划词工具条 / 书签 / 摘录面板 ══════════════ */

/* 正文里的四色高亮：用 <mark>，打印与复制都还是原文 */
.article mark.hl {
  padding: 1px 0;
  border-radius: 3px;
  color: inherit;
  background: transparent;
  box-shadow: inset 0 -0.62em 0 var(--hl-yellow, #ffe9a3);
  cursor: pointer;
}
.article mark.hl-yellow { --hl-yellow: #ffe9a3; }
.article mark.hl-green { --hl-yellow: #c8f0d4; }
.article mark.hl-blue { --hl-yellow: #cfe2ff; }
.article mark.hl-pink { --hl-yellow: #ffd9e6; }
.article mark.hl:hover { filter: saturate(1.35); }

/* 划词工具条（fixed，跟随选区） */
.selbar {
  position: fixed;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 12px;
  background: #11141c;
  box-shadow: 0 10px 26px -10px rgba(16, 24, 40, .5);
}
.selbar[hidden] { display: none; }
.selbar .sw {
  width: 22px; height: 22px; padding: 0;
  border: 2px solid rgba(255, 255, 255, .28);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  display: grid; place-items: center;
}
.selbar .sw i { width: 12px; height: 12px; border-radius: 50%; display: block; }
.selbar .sw.yellow i { background: #ffe9a3; }
.selbar .sw.green i { background: #c8f0d4; }
.selbar .sw.blue i { background: #cfe2ff; }
.selbar .sw.pink i { background: #ffd9e6; }
.selbar .sw:hover { border-color: #fff; transform: translateY(-1px); }
.selbar-sp { width: 1px; height: 18px; background: rgba(255, 255, 255, .18); margin: 0 2px; }
.selbar-btn {
  border: none;
  background: transparent;
  color: #e8ecf6;
  font-size: 12.5px;
  font-family: inherit;
  padding: 4px 7px;
  border-radius: 7px;
  cursor: pointer;
}
.selbar-btn:hover { background: rgba(255, 255, 255, .14); color: #fff; }

/* 右栏：本页笔记 */
.railnotes { margin-top: 18px; padding-top: 12px; border-top: 1px dashed var(--line); }
.railnote {
  display: flex; gap: 6px; align-items: baseline;
  width: 100%; text-align: left;
  padding: 5px 8px; margin-bottom: 2px;
  border: none; background: transparent; border-radius: 7px;
  font-size: 12px; color: var(--dim); font-family: inherit; cursor: pointer;
}
.railnote:hover { background: var(--surface); color: var(--ink); }
.railnote-empty { font-size: 11.5px; color: var(--dimmer); padding: 4px 8px; line-height: 1.6; }
.railnote-foot { font-size: 11px; color: var(--dimmer); padding: 6px 8px 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; background: #ffe9a3; }
.dot.green { background: #7fdca0; }
.dot.blue { background: #9cc4ff; }
.dot.pink { background: #ffb3cc; }
.dot.ex { background: var(--brand); }
.dot.bm { background: var(--gold); }

/* 笔记面板 */
.notes-mask { position: fixed; inset: 0; background: rgba(17, 20, 28, .28); z-index: 70; }
.notes-mask[hidden] { display: none; }
.notes-panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 71;
  width: min(92vw, 400px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: -16px 0 40px -24px rgba(16, 24, 40, .4);
}
.notes-panel[hidden] { display: none; }
.notes-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.notes-head b { font-size: 14.5px; letter-spacing: .04em; }
.notes-head .dimmer { font-size: 11.5px; }
.notes-head .ghost { margin-left: auto; }
.notes-body { flex: 1; overflow: auto; padding: 10px 12px 16px; }
.notes-empty { color: var(--dimmer); font-size: 13px; line-height: 1.9; padding: 26px 12px; text-align: center; }
.notes-dochead {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11.5px; letter-spacing: .1em; color: var(--dimmer);
  padding: 10px 4px 6px;
}
.notes-dochead b { font-weight: 500; color: var(--ink); }
.notes-row { display: flex; gap: 8px; padding: 8px 4px 12px; border-bottom: 1px dashed var(--line-2); }
.notes-row .dot { margin-top: 6px; }
.notes-main { flex: 1; min-width: 0; }
.notes-quote { font-size: 12.5px; line-height: 1.7; color: var(--ink); word-break: break-word; }
.notes-note {
  width: 100%; margin: 6px 0 4px; padding: 4px 7px;
  border: 1px solid var(--line); border-radius: 7px;
  font-size: 12px; font-family: inherit; color: var(--ink); background: var(--surface-2);
}
.notes-note:focus { outline: none; border-color: #c3cdf0; box-shadow: 0 0 0 2px #eef1ff; }
.notes-meta { display: flex; align-items: center; gap: 10px; font-size: 11px; color: var(--dimmer); }
.notes-meta a { color: var(--brand); }
.notes-del { border: none; background: transparent; color: var(--dimmer); font-size: 11px; cursor: pointer; font-family: inherit; padding: 0; }
.notes-del:hover { color: var(--red); }
.notes-foot { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.notes-foot .btn { flex: 1; font-size: 12.5px; padding: 8px 10px; }

/* toast */
.notes-toast {
  position: fixed; left: 50%; bottom: 78px; transform: translate(-50%, 8px);
  padding: 8px 16px; border-radius: 999px;
  background: #11141c; color: #fff; font-size: 12.5px;
  opacity: 0; pointer-events: none; transition: .18s; z-index: 80;
}
.notes-toast.on { opacity: 1; transform: translate(-50%, 0); }

body.notes-open { overflow: hidden; }

@media (max-width: 1080px) {
  .railnotes { display: none; }
}

/* ══════════════ M4：划词即问 ══════════════ */
.ask-panel {
  position: fixed; right: 18px; bottom: 18px; z-index: 72;
  width: min(92vw, 440px); max-height: 76vh;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow);
}
.ask-panel[hidden] { display: none; }
.ask-head {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 14px; border-bottom: 1px solid var(--line);
}
.ask-head b { font-size: 13.5px; letter-spacing: .04em; }
.ask-head .dimmer { font-size: 11px; }
.ask-head .ghost { margin-left: auto; }
.ask-body { overflow: auto; padding: 12px 14px 14px; }
.ask-quote {
  margin: 0 0 10px; padding: 8px 12px;
  border-left: 3px solid var(--brand); border-radius: 0 8px 8px 0;
  background: var(--surface-2); color: var(--dim);
  font-size: 12.5px; line-height: 1.85;
}
.ask-quote .ctx { color: var(--dimmer); }
.ask-form { display: flex; gap: 8px; }
.ask-form input {
  flex: 1; padding: 8px 11px;
  border: 1px solid var(--line); border-radius: 9px;
  font-size: 13px; font-family: inherit; background: var(--surface); color: var(--ink);
}
.ask-form input:focus { outline: none; border-color: #c3cdf0; box-shadow: 0 0 0 2px #eef1ff; }
.ask-form .btn { padding: 6px 16px; font-size: 13px; }
.ask-answer { margin-top: 10px; font-size: 13.5px; line-height: 1.9; color: #1b2130; }
.ask-answer p { margin: 0 0 8px; }
.ask-answer ul, .ask-answer ol { margin: 0 0 8px; padding-left: 20px; }
.ask-answer.err { color: var(--red); }
.ask-src { margin-top: 10px; }
.src-title { font-size: 11.5px; color: var(--dimmer); letter-spacing: .1em; margin-bottom: 6px; }
.cite {
  display: block; padding: 8px 10px; margin-bottom: 6px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); color: inherit;
}
.cite:hover { text-decoration: none; border-color: #cfd6e4; }
.cite-label {
  font-size: 11px; color: var(--brand); background: var(--brand-soft);
  border: 1px solid #dfe3ff; padding: 1px 7px; border-radius: 999px; margin-right: 6px;
}
.cite-head { font-size: 12px; color: var(--dim); }
.cite-quote { display: block; margin-top: 4px; font-size: 12px; color: var(--dimmer); line-height: 1.7; }
.ask-foot { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.ask-foot .btn { padding: 6px 14px; font-size: 12.5px; }

.digest-points { margin: 0 0 8px; padding-left: 20px; font-size: 13px; line-height: 1.85; color: #1b2130; }
.digest-points li { margin-bottom: 3px; }
.digest-panel .cite { padding: 6px 10px; }

@media (max-width: 780px) {
  .ask-panel { right: 8px; left: 8px; bottom: 8px; width: auto; max-height: 70vh; }
}

/* 窄屏：顶栏多了「检索 / 书签 / 笔记」，必须允许换行，否则 375px 会横向溢出 */
@media (max-width: 780px) {
  .reader-body .nav { flex-wrap: wrap; gap: 8px 10px; padding: 8px 12px; }
  .reader-body .nav .links { order: 3; flex-basis: 100%; margin-left: 0; gap: 2px; }
  .reader-body .nav .links a { padding: 5px 9px; font-size: 12.5px; }
  .reader-body .nav .sp { display: none; }
  .reader-body .nav .ghost { padding: 5px 10px; font-size: 12px; }
  .reader-body .nav #btnChat { display: none; }
}
