/* ══════════════════════════════════════════════════════════
   沉浸式阅读器（桌面端）—— PDF / Word / Markdown 共用一套壳
   配色沿用站点变量：纸色 --paper，珊瑚 --coral，细线 --line
   ══════════════════════════════════════════════════════════ */

.imr {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  opacity: 0;
  transition: opacity .22s ease;
}
.imr.is-on { opacity: 1; }
.imr[hidden] { display: none; }

/* ── 顶栏 ── */
.imr-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  position: relative;
  z-index: 3;
}
.imr-back {
  width: 34px; height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  display: grid; place-items: center;
  flex: none;
  transition: background .18s, border-color .18s;
}
.imr-back:hover { background: var(--paper2); border-color: var(--coral); }
.imr-back svg { width: 15px; height: 15px; }

.imr-heading { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.imr-heading small {
  font-size: 9px; letter-spacing: .15em; font-weight: 700; color: var(--coral);
  text-transform: uppercase;
}
.imr-heading h2 {
  margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.imr-tools { display: flex; align-items: center; gap: 4px; flex: none; }
.imr-btn {
  height: 32px; min-width: 32px; padding: 0 10px;
  border: 1px solid transparent; border-radius: 999px;
  background: transparent; color: var(--muted);
  font-size: 12px; font-weight: 700;
  display: inline-flex; align-items: center; gap: 5px;
  transition: background .18s, color .18s, border-color .18s;
}
.imr-btn:hover { background: var(--paper2); color: var(--ink); }
.imr-btn.is-on { background: var(--ink); color: var(--white); border-color: var(--ink); }
.imr-btn:disabled { opacity: .35; cursor: default; }
.imr-btn svg { width: 15px; height: 15px; }
.imr-btn .imr-badge {
  min-width: 15px; height: 15px; padding: 0 4px; border-radius: 999px;
  background: var(--coral); color: #fff; font-size: 9px; line-height: 15px;
  text-align: center; font-weight: 700;
}
.imr-zoom { font-size: 11px; color: var(--muted); min-width: 38px; text-align: center; font-variant-numeric: tabular-nums; }
.imr-sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }

/* 顶部细进度条 */
.imr-meter { position: absolute; left: 0; bottom: -1px; height: 2px; width: 100%; background: transparent; z-index: 4; }
.imr-meter i { display: block; height: 100%; width: 0; background: var(--coral); transition: width .15s linear; }

/* ── 主体三栏 ── */
.imr-body { flex: 1; min-height: 0; display: flex; position: relative; }

.imr-panel {
  flex: none; width: 0; overflow: hidden auto;
  background: var(--paper);
  border-right: 1px solid var(--line);
  transition: width .24s ease;
  scrollbar-width: thin;
}
.imr-panel.is-open { width: 268px; }
.imr-panel-side { border-right: 0; border-left: 1px solid var(--line); }
.imr-panel-side.is-open { width: 300px; }

.imr-panel-head {
  position: sticky; top: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px 10px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  font-size: 10px; letter-spacing: .14em; font-weight: 700; color: var(--coral);
  text-transform: uppercase;
}
.imr-panel-head button {
  border: 0; background: transparent; color: var(--muted); font-size: 15px; line-height: 1;
  padding: 2px 4px; border-radius: 6px;
}
.imr-panel-head button:hover { color: var(--ink); background: var(--paper2); }
.imr-panel-inner { padding: 10px 10px 40px; }

/* 目录 */
.imr-toc-item {
  display: block; width: 100%; text-align: left;
  border: 0; background: transparent; color: var(--muted);
  padding: 7px 10px; border-radius: 8px;
  font-size: 12px; line-height: 1.55;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .16s, color .16s;
}
.imr-toc-item:hover { background: var(--paper2); color: var(--ink); }
.imr-toc-item.is-current { background: #efe4d6; color: var(--ink); font-weight: 700; }
.imr-toc-item[data-depth="1"] { padding-left: 10px; font-size: 13px; color: var(--ink); font-weight: 600; }
.imr-toc-item[data-depth="2"] { padding-left: 20px; }
.imr-toc-item[data-depth="3"] { padding-left: 32px; font-size: 11.5px; }
.imr-toc-item[data-depth="4"] { padding-left: 44px; font-size: 11px; }
.imr-empty { padding: 16px 12px; font-size: 11.5px; line-height: 1.8; color: var(--muted); }

/* 笔记侧栏 */
.imr-note-card {
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--white);
  padding: 11px 12px; margin-bottom: 9px;
  cursor: pointer;
  transition: border-color .16s, transform .16s;
}
.imr-note-card:hover { border-color: #c8b3a2; transform: translateY(-1px); }
.imr-note-card.is-focus { border-color: var(--coral); box-shadow: 0 0 0 2px rgba(187,99,75,.12); }
.imr-note-quote {
  font-size: 11.5px; line-height: 1.7; color: #6f6861;
  border-left: 2px solid var(--peach); padding-left: 8px; margin: 0 0 7px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.imr-note-text { font-size: 12px; line-height: 1.75; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.imr-note-meta {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 8px; font-size: 9.5px; color: #a49b91; letter-spacing: .04em;
}
.imr-note-tools { display: flex; gap: 6px; }
.imr-note-tools button {
  border: 0; background: transparent; color: #a49b91; font-size: 10px; padding: 2px 3px;
}
.imr-note-tools button:hover { color: var(--coral-dark); }
.imr-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.imr-dot-yellow { background: #e9b18d; }
.imr-dot-green { background: #a9bf9a; }
.imr-dot-blue { background: #9db6c9; }
.imr-dot-pink { background: #dfa8b4; }
.imr-dot-purple { background: #b6a7cd; }

.imr-note-edit { margin-top: 9px; }
.imr-note-edit textarea {
  width: 100%; min-height: 74px; resize: vertical;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--paper); color: var(--ink);
  padding: 8px 9px; font-size: 12px; line-height: 1.7; outline: 0;
}
.imr-note-edit textarea:focus { border-color: var(--coral); }
.imr-note-edit-foot { display: flex; gap: 6px; margin-top: 7px; }
.imr-mini {
  border: 1px solid var(--line); border-radius: 999px; background: transparent;
  color: var(--ink); font-size: 10.5px; font-weight: 700; padding: 4px 11px;
}
.imr-mini:hover { border-color: var(--coral); }
.imr-mini-primary { background: var(--ink); color: var(--white); border-color: var(--ink); }
.imr-mini-primary:hover { background: var(--coral-dark); border-color: var(--coral-dark); }

/* ── 舞台 ── */
.imr-stage {
  flex: 1; min-width: 0; min-height: 0;
  overflow: auto; position: relative;
  background: #eae5dc;
  scroll-behavior: auto;
  overscroll-behavior: contain;
}
.imr-pages { padding: 26px 0 90px; display: flex; flex-direction: column; align-items: center; gap: 18px; }

/* PDF 单页 */
.imr-page {
  position: relative;
  background: #fffdf9;
  box-shadow: 0 4px 18px rgba(42,35,29,.10);
  border-radius: 2px;
  flex: none;
}
.imr-page canvas { display: block; border-radius: 2px; }
.imr-page .imr-page-no {
  position: absolute; right: 8px; bottom: -17px;
  font-size: 9px; color: #a49b91; letter-spacing: .1em;
  font-variant-numeric: tabular-nums;
}
.imr-page.is-pending::after {
  content: ''; position: absolute; inset: 0; border-radius: 2px;
  background: linear-gradient(100deg, #f4efe6 20%, #faf6ef 40%, #f4efe6 60%);
  background-size: 200% 100%;
  animation: imr-shimmer 1.5s linear infinite;
}
@keyframes imr-shimmer { to { background-position: -200% 0; } }

/* PDF 文本层 */
.imr-textLayer {
  position: absolute; inset: 0;
  overflow: hidden; opacity: 1;
  line-height: 1; text-align: initial;
  text-size-adjust: none; forced-color-adjust: none;
  transform-origin: 0 0;
  z-index: 1;
}
.imr-textLayer span,
.imr-textLayer br {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0 0;
}
.imr-textLayer ::selection { background: rgba(187,99,75,.28); }

/* HTML 文档（Word / Markdown / 纯文本） */
.imr-sheet {
  width: min(760px, calc(100% - 48px));
  margin: 0 auto;
  background: #fffdf9;
  box-shadow: 0 4px 20px rgba(42,35,29,.09);
  border-radius: 3px;
  padding: 62px 74px 80px;
  font-size: 15.5px;
  line-height: 2.05;
  color: #33302c;
  overflow-wrap: anywhere;
}
.imr-sheet h1 { font-size: 30px; line-height: 1.45; letter-spacing: -.04em; margin: 0 0 18px; }
.imr-sheet h2 {
  font-size: 22px; line-height: 1.5; letter-spacing: -.03em;
  margin: 2.1em 0 .75em; padding-top: .55em; border-top: 1px solid #eee8de;
}
.imr-sheet h3 { font-size: 17.5px; margin: 1.8em 0 .6em; letter-spacing: -.02em; }
.imr-sheet h4 { font-size: 15px; margin: 1.5em 0 .5em; color: var(--muted); }
.imr-sheet p { margin: 0 0 1.15em; }
.imr-sheet ul, .imr-sheet ol { margin: 0 0 1.15em; padding-left: 1.5em; }
.imr-sheet li { margin: .28em 0; }
.imr-sheet blockquote {
  margin: 1.2em 0; padding: .2em 0 .2em 1.1em;
  border-left: 3px solid var(--peach); color: #6b635b; background: #faf6ef;
}
.imr-sheet code {
  background: #f2ece1; border-radius: 4px; padding: .12em .38em;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: .9em;
}
.imr-sheet pre {
  background: #2f2b27; color: #f2ece1; border-radius: 10px;
  padding: 15px 17px; overflow: auto; margin: 1.2em 0; line-height: 1.65;
}
.imr-sheet pre code { background: transparent; padding: 0; font-size: 12.5px; color: inherit; }
.imr-sheet table { border-collapse: collapse; width: 100%; margin: 1.3em 0; font-size: 13.5px; }
.imr-sheet th, .imr-sheet td { border: 1px solid #e2dbd0; padding: 7px 10px; text-align: left; vertical-align: top; min-width: 5em; }
.imr-sheet th { background: #f6f1e7; font-weight: 700; }
.imr-sheet img { max-width: 100%; height: auto; border-radius: 8px; margin: .4em 0; }
.imr-sheet a { color: var(--coral-dark); text-decoration: underline; text-underline-offset: 2px; }
.imr-sheet hr { border: 0; border-top: 1px solid #e8e1d6; margin: 2em 0; }
.imr-sheet .imr-plain { white-space: pre-wrap; font-family: var(--font-sans); }

/* 搜索命中 */
.imr-sheet mark.imr-hit { background: rgba(233,177,141,.55); color: inherit; border-radius: 3px; padding: 0 1px; }
.imr-sheet mark.imr-hit.is-current { background: var(--coral); color: #fff; }

/* CSS Highlight API：注记（按颜色分组，规则要在样式表里预定义） */
::highlight(imr-yellow) { background-color: rgba(233,177,141,.52); }
::highlight(imr-green) { background-color: rgba(169,191,154,.55); }
::highlight(imr-blue) { background-color: rgba(157,182,201,.52); }
::highlight(imr-pink) { background-color: rgba(223,168,180,.52); }
::highlight(imr-purple) { background-color: rgba(182,167,205,.52); }
::highlight(imr-find) { background-color: rgba(233,177,141,.72); }
::highlight(imr-find-current) { background-color: var(--coral); color: #fff; }

/* 划词浮条 */
.imr-bubble {
  position: fixed; z-index: 96;
  display: flex; align-items: center; gap: 3px;
  padding: 5px 7px;
  background: var(--ink); color: var(--white);
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(48,44,40,.28);
  animation: imr-pop .14s ease;
}
@keyframes imr-pop { from { opacity: 0; transform: translateY(4px) scale(.96); } }
.imr-bubble[hidden] { display: none; }
.imr-swatch {
  width: 19px; height: 19px; border-radius: 50%;
  border: 1.5px solid transparent; padding: 0;
  transition: transform .14s, border-color .14s;
}
.imr-swatch:hover { transform: scale(1.16); border-color: rgba(255,255,255,.85); }
.imr-swatch-yellow { background: #e9b18d; }
.imr-swatch-green { background: #a9bf9a; }
.imr-swatch-blue { background: #9db6c9; }
.imr-swatch-pink { background: #dfa8b4; }
.imr-swatch-purple { background: #b6a7cd; }
.imr-bubble-text {
  border: 0; border-left: 1px solid rgba(255,255,255,.22);
  background: transparent; color: #fff;
  font-size: 11px; font-weight: 700; padding: 2px 8px; margin-left: 3px;
  white-space: nowrap;
}

/* 搜索条 */
.imr-findbar {
  position: absolute; top: 8px; right: 18px; z-index: 5;
  display: flex; align-items: center; gap: 5px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 7px 5px 13px;
  box-shadow: 0 8px 22px rgba(58,43,32,.10);
}
.imr-findbar[hidden] { display: none; }
.imr-findbar input {
  width: 168px; border: 0; background: transparent; outline: 0;
  font-size: 12.5px; color: var(--ink);
}
.imr-findbar input::placeholder { color: #a8a099; }
.imr-find-count {
  font-size: 10.5px; color: var(--muted); min-width: 52px; text-align: right;
  font-variant-numeric: tabular-nums;
}

/* 加载 / 错误 */
.imr-status {
  margin: auto; padding: 40px 24px; text-align: center; color: var(--muted); font-size: 13px; line-height: 1.9;
}
.imr-status strong { display: block; font-size: 18px; color: var(--ink); margin-bottom: 8px; }
.imr-status a { color: var(--coral-dark); text-decoration: underline; }
.imr-spinner {
  width: 22px; height: 22px; margin: 0 auto 14px;
  border: 2px solid var(--line); border-top-color: var(--coral);
  border-radius: 50%; animation: imr-spin .8s linear infinite;
}
@keyframes imr-spin { to { transform: rotate(360deg); } }

/* 手机：immersive 不启用，这里只是兜底 */
@media (max-width: 900px) {
  .imr { display: none !important; }
}
@media (prefers-reduced-motion: reduce) {
  .imr, .imr-panel, .imr-btn, .imr-toc-item { transition: none !important; }
  .imr-page.is-pending::after, .imr-spinner { animation: none; }
}
/* ── EPUB：和 WORD / PDF 同一套书页，章节之间断开 ───────────────── */
.imr-epub-chapter + .imr-epub-chapter{margin-top:2.8em;padding-top:2.4em;border-top:1px solid var(--line,#e8e1d6)}
.imr-epub-chapter p{text-indent:2em}
.imr-epub-chapter p:first-of-type,.imr-epub-chapter blockquote p,.imr-epub-chapter li p{text-indent:0}
.imr-epub-chapter img{display:block;margin:1.3em auto;max-width:100%;height:auto;border-radius:6px}
.imr-epub-chapter hr{border:0;border-top:1px solid var(--line,#e8e1d6);margin:2em 0}
.imr-epub-chapter h1,.imr-epub-chapter h2,.imr-epub-chapter h3{text-indent:0}
.imr-epub-chapter table{font-size:13px}

/* 深色：书页里的表格线、表头、分割线别再用浅色写死 */
:root[data-theme="dark"] .imr-sheet th,
:root[data-theme="dark"] .imr-sheet td{border-color:#3a342c}
:root[data-theme="dark"] .imr-sheet th{background:#241f19}
:root[data-theme="dark"] .imr-sheet hr{border-top-color:#332e27}
:root[data-theme="dark"] .imr-epub-chapter + .imr-epub-chapter{border-top-color:#332e27}

/* 书里的目录/脚注是原书 HTML 的 <a>，拼成一页后锚点失效，别让它长成网页链接 */
.imr-epub-chapter a{color:inherit;text-decoration:none;border-bottom:1px solid rgba(60,45,30,.14)}
:root[data-theme="dark"] .imr-epub-chapter a{border-bottom-color:rgba(255,240,220,.16)}

/* ── 阅读器深色：书页原本写死 #fffdf9 米白纸，夜间直接白板一片 ────── */
:root[data-theme="dark"] .imr-sheet{background:#1b1815;color:#e6ddcd;box-shadow:0 4px 22px rgba(0,0,0,.45)}
:root[data-theme="dark"] .imr-sheet h1,
:root[data-theme="dark"] .imr-sheet h2,
:root[data-theme="dark"] .imr-sheet h3{color:#f2ebdd}
:root[data-theme="dark"] .imr-sheet h4{color:#a89e8f}
:root[data-theme="dark"] .imr-sheet blockquote{background:#231e18;color:#c4bbaa}
:root[data-theme="dark"] .imr-sheet code{background:#2a241d;color:#e8dcc8}
:root[data-theme="dark"] .imr-sheet pre{background:#100e0b;color:#ddd3c1}
:root[data-theme="dark"] .imr-sheet a{color:var(--coral-dark)}
:root[data-theme="dark"] .imr-sheet mark.imr-hit{background:rgba(217,122,95,.4)}
:root[data-theme="dark"] .imr-toc-item.is-current{background:#2a241d}

/* 阅读器舞台底色（原来写死浅灰 #eae5dc，夜里像开着台灯） */
:root[data-theme="dark"] .imr-stage{background:#0e0c0a}

/* 书上插图画在白色画布上，夜里那一片白最扎眼，压一点亮度 */
:root[data-theme="dark"] .imr-epub-chapter img{filter:brightness(.84) contrast(.95)}
