/* 页边 · 平板阅读 */
@font-face { font-family: "Page Serif"; src: url(serif-400.woff2) format("woff2"); font-weight: 400; font-display: block; }
@font-face { font-family: "Page Serif"; src: url(serif-600.woff2) format("woff2"); font-weight: 600; font-display: block; }
@font-face { font-family: "Page Kai"; src: url(kai.woff2) format("woff2"); font-weight: 400; font-display: block; }

:root {
  --paper: #F4F2EC;
  --paper-2: #EAE7DF;
  --print: #23211E;
  --muted: #6E6A62;
  --faint: #A29D93;
  --rule: #DAD6CC;
  --ink: #2944B3;
  --ink-soft: rgba(41, 68, 179, .55);
  --sel: rgba(41, 68, 179, .13);
  --canvas: #1D1E21;
  --serif: "Page Serif", "Songti SC", "Noto Serif CJK SC", serif;
  --kai: "Page Kai", "Kaiti SC", "STKaiti", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
  --ease-out: cubic-bezier(.2, .75, .25, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--canvas); overflow: hidden; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus { outline: none; }
button:focus-visible { outline: 1.5px solid var(--print); outline-offset: 2px; border-radius: 4px; }
svg { display: block; }

/* 展示画布：屏幕按比例放进视口 */
.stage { position: fixed; inset: 0; }
.screen {
  position: absolute; left: 0; top: 0;
  width: 1024px; height: 1366px;
  transform-origin: 0 0;
  background: var(--paper);
  color: var(--print);
  overflow: hidden;
  user-select: none; -webkit-user-select: none;
}
.stage[data-loading] .screen { visibility: hidden; }

/* 书页 */
.page { position: absolute; inset: 0; }
.runhead {
  position: absolute; left: 96px; right: 56px; top: 42px;
  display: flex; justify-content: space-between;
  font: 400 13px/20px var(--serif); color: var(--muted); letter-spacing: .06em;
  transition: opacity .2s;
}
.runhead.is-hidden { opacity: 0; }

.viewport { position: absolute; left: 0; top: 96px; width: 1024px; height: 1154px; overflow: hidden; }
.layer { position: absolute; left: 0; top: 0; height: 1154px; will-change: transform; }
.layer.is-turning { transition: transform .32s var(--ease-out); }

.flow {
  position: absolute; left: 96px; top: 0;
  width: 640px; height: 1154px;
  column-width: 640px; column-gap: 384px; column-fill: auto;
  font: 400 20px/38px var(--serif);
  color: var(--print);
  text-align: justify;
  line-break: strict;
  word-break: normal;
  text-spacing-trim: normal;
  text-autospace: normal;
  font-kerning: normal;
  orphans: 2; widows: 2;
  user-select: text; -webkit-user-select: text;
  cursor: text;
}
.flow::selection, .flow *::selection { background: var(--sel); }
.flow p { margin: 0; text-indent: 2em; text-wrap: pretty; }
.flow p + p { margin-top: 0; }

/* 章首页 */
.opener { break-inside: avoid; padding-top: 98px; height: 342px; user-select: none; -webkit-user-select: none; cursor: default; }
.opener .no { display: block; font: 400 17px/38px var(--serif); color: var(--muted); letter-spacing: .24em; }
.opener h1 { margin: 2px 0 0 -3px; font: 600 44px/56px var(--serif); letter-spacing: .12em; color: var(--print); }
.opener .epi { margin: 26px 0 0; font: 400 16px/26px var(--serif); color: var(--muted); text-align: right; text-indent: 0; }
.opener .epi cite { display: block; margin-top: 2px; font-style: normal; }

/* 墨迹层：划线与批注 */
.ink { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.ink .stroke { fill: var(--ink); }
.ink .wave { fill: none; stroke: var(--ink); stroke-width: 1.35; stroke-linecap: round; stroke-linejoin: round; }
.ink .dot { fill: var(--ink); }
.ink .nib { fill: var(--ink); }

.hit { position: absolute; cursor: pointer; }

.note {
  position: absolute; width: 192px;
  font: 400 16px/26px var(--kai);
  color: var(--ink);
  text-align: left;
  word-break: break-all;
  line-break: strict;
  text-wrap: pretty;
  text-spacing-trim: normal;
  transition: top .28s var(--ease-out), opacity .45s;
  cursor: pointer;
}
.note .ch { display: inline; animation: settle .26s var(--ease-out) both; }
@keyframes settle { from { opacity: 0; filter: blur(1.2px); } to { opacity: 1; filter: none; } }
.note.is-editing { cursor: text; }
.note .field { outline: none; caret-color: var(--ink); min-height: 26px; user-select: text; -webkit-user-select: text; white-space: pre-wrap; }
.note .field:empty::before { content: attr(data-placeholder); color: var(--ink-soft); }
.note .caret {
  display: inline-block; width: 1.5px; height: 19px; margin: 0 0 -3px 1px;
  background: var(--ink); animation: blink 1.06s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.note .acts { display: flex; gap: 4px; margin: 4px 0 0 -10px; font: 500 13px/20px var(--sans); }
.note .acts button { height: 44px; padding: 0 10px; border-radius: 6px; color: var(--muted); }
.note .acts button.done { color: var(--ink); }
.note .acts button:hover { background: rgba(35, 33, 30, .05); }
.note .acts button:active { opacity: .6; }

/* 自绘选区 */
.sel { position: absolute; left: 0; top: 0; pointer-events: none; }
.sel .tint { position: absolute; background: var(--sel); border-radius: 1px; }
.sel .handle { position: absolute; width: 2px; background: var(--ink); border-radius: 1px; }
.sel .handle::after {
  content: ""; position: absolute; left: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--ink);
}
.sel .handle.start::after { top: -9px; }
.sel .handle.end::after { bottom: -9px; }

/* 选中菜单 */
.selmenu {
  position: absolute; z-index: 20;
  display: flex; align-items: center;
  height: 46px; padding: 0 5px;
  background: var(--print); color: var(--paper);
  border-radius: 8px;
  font: 500 14px/20px var(--sans);
  opacity: 0; transform: translateY(4px) scale(.98); transform-origin: 50% 100%;
  pointer-events: none;
  transition: opacity .16s, transform .2s var(--ease-out);
}
.selmenu.on { opacity: 1; transform: none; pointer-events: auto; }
.selmenu::after {
  content: ""; position: absolute; left: var(--tip, 50%); bottom: -6px; width: 12px; height: 12px; margin-left: -6px;
  background: var(--print); transform: rotate(45deg); border-radius: 0 0 2px 0;
}
.selmenu.below::after { bottom: auto; top: -6px; border-radius: 2px 0 0 0; }
.selmenu button { position: relative; z-index: 1; height: 46px; padding: 0 13px; border-radius: 6px; white-space: nowrap; transition: opacity .12s; }
.selmenu button:active, .selmenu button.is-pressed { background: rgba(244, 242, 236, .16); }
.selmenu .mk { width: 44px; padding: 0; display: grid; place-items: center; opacity: .62; }
.selmenu .mk.cur { opacity: 1; }
.selmenu .mk svg { width: 24px; height: 12px; overflow: visible; }
.selmenu .mk .ln { fill: currentColor; }
.selmenu .mk .wv { fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; }
.selmenu .sep { width: 1px; height: 20px; margin: 0 5px; background: rgba(244, 242, 236, .2); }
.selmenu .danger { color: #F2B8A8; }

/* 页脚：页码、进度线、本章剩余 */
.folio {
  position: absolute; left: 96px; right: 56px; bottom: 0; height: 116px;
  display: flex; align-items: center; gap: 18px;
  font: 400 13px/20px var(--sans); color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.folio .pg { min-width: 28px; letter-spacing: .02em; }
.folio .left { white-space: nowrap; }
.rail { flex: 1; height: 24px; position: relative; }
.rail svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.rail .seg { stroke: var(--rule); stroke-width: 1; }
.rail .seg.read { stroke: #8F8A80; }
.rail .tick { stroke: var(--ink); stroke-width: 1.2; stroke-linecap: round; }
.rail .tick.fresh { animation: tickin .5s var(--ease-out) both; transform-box: fill-box; transform-origin: 50% 100%; }
@keyframes tickin { from { transform: scaleY(0); } to { transform: none; } }
.rail .here, .toc-rule .here { fill: var(--ink); stroke: var(--paper); stroke-width: 1.5; }

/* 顶栏：轻点页面中间出现 */
.bar {
  position: absolute; left: 0; right: 0; top: 0; height: 76px; z-index: 12;
  display: flex; align-items: center; gap: 8px;
  padding: 0 44px 0 74px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  transform: translateY(-101%);
  transition: transform .26s var(--ease-out);
  font: 400 14px/20px var(--sans);
}
.bar.on { transform: none; }
.bar .back { display: flex; align-items: center; gap: 2px; height: 44px; padding: 0 10px 0 6px; color: var(--print); }
.bar .back svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.bar .title { flex: 1; text-align: center; color: var(--muted); font-size: 13px; letter-spacing: .04em; }
.bar .tools { display: flex; gap: 4px; }
.bar .tools button { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 8px; color: var(--print); }
.bar .tools button:hover, .bar .back:hover { background: rgba(35, 33, 30, .05); border-radius: 8px; }
.bar .tools button:active, .bar .back:active { opacity: .6; }
.bar .tools svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.bar .tools button[aria-pressed="true"] svg { fill: var(--ink); stroke: var(--ink); }

/* 书签：一条蓝墨水色的丝带从页顶垂下 */
.ribbon {
  position: absolute; top: 0; left: 920px; width: 22px; height: 70px; z-index: 2;
  background: var(--ink);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% calc(100% - 9px), 0 100%);
  transform: translateY(-100%);
  transition: transform .3s var(--ease-out);
}
.ribbon.on { transform: none; }

/* 目录抽屉：盖住版心，页边仍露在外面 */
.scrim { position: absolute; inset: 0; z-index: 14; background: rgba(35, 33, 30, 0); pointer-events: none; transition: background .3s; }
.scrim.on { background: rgba(35, 33, 30, .07); pointer-events: auto; cursor: pointer; }
.drawer {
  position: absolute; left: 0; top: 0; bottom: 0; width: 744px; z-index: 15;
  background: var(--paper-2);
  border-right: 1px solid #D2CDC2;
  transform: translateX(-100%);
  transition: transform .34s var(--ease-out);
  display: flex; flex-direction: column;
  visibility: hidden;
}
.drawer.on { transform: none; visibility: visible; }
.drawer.closing { visibility: visible; transition-duration: .22s; transition-timing-function: cubic-bezier(.4, 0, .9, .5); }
.dw-head { padding: 64px 64px 0 96px; position: relative; }
.dw-head h2 { margin: 0; font: 600 20px/30px var(--serif); letter-spacing: .06em; }
.dw-head .by { margin-top: 2px; font: 400 13px/20px var(--sans); color: var(--muted); }
.dw-head .close { position: absolute; right: 40px; top: 56px; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 8px; }
.dw-head .close svg { width: 18px; height: 18px; fill: none; stroke: var(--print); stroke-width: 1.4; stroke-linecap: round; }
.dw-head .close:hover { background: rgba(35, 33, 30, .05); }

.dw-tabs { display: flex; gap: 32px; margin: 36px 64px 0 96px; border-bottom: 1px solid var(--rule); font: 400 14px/20px var(--sans); }
.dw-tabs button { position: relative; height: 44px; color: var(--muted); }
.dw-tabs button .n { margin-left: 4px; font-variant-numeric: tabular-nums; color: var(--faint); }
.dw-tabs button[aria-selected="true"] { color: var(--print); font-weight: 500; }
.dw-tabs button[aria-selected="true"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--print); }

.dw-body { flex: 1; overflow: auto; padding: 8px 64px 64px 96px; scrollbar-width: none; }
.dw-body::-webkit-scrollbar { display: none; }

.toc { list-style: none; margin: 0; padding: 0; }
.toc-row {
  position: relative; display: grid; grid-template-columns: 72px 1fr auto; align-items: baseline;
  width: 100%; padding: 24px 0 22px; text-align: left; border-radius: 0;
}
.toc-row:hover .toc-title { color: #000; }
.toc-no { font: 400 13px/20px var(--sans); color: var(--muted); }
.toc-title { font: 400 17px/28px var(--serif); color: var(--print); }
.toc-page { font: 400 13px/20px var(--sans); color: var(--muted); font-variant-numeric: tabular-nums; }
.toc-row.current .toc-title { font-weight: 600; }
.toc-row.unread .toc-title { color: #4A4741; }
.toc-sub { grid-column: 2 / 4; margin-top: 6px; font: 400 13px/20px var(--sans); color: var(--muted); font-variant-numeric: tabular-nums; }
.toc-sub b { font-weight: 400; color: var(--ink); }
.toc-rule { position: absolute; left: 72px; bottom: -2px; width: 512px; height: 12px; overflow: visible; }
.toc-rule .read { stroke: #8F8A80; stroke-width: 1; }
.toc-rule .unread { stroke: #C9C4B9; stroke-width: 1; stroke-dasharray: 1 3; }
.toc-rule .tick { stroke: var(--ink); stroke-width: 1.2; stroke-linecap: round; }

/* 笔记、书签列表 */
.nt-group { margin-top: 28px; font: 400 13px/20px var(--sans); color: var(--muted); }
.nt { padding: 16px 0 18px; border-bottom: 1px solid var(--rule); }
.nt-q { font: 400 16px/30px var(--serif); color: var(--print); }
.nt-q span { background-repeat: no-repeat; background-position: 0 100%; background-size: 100% 4px; background-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%20100%204%22%20preserveAspectRatio%3D%22none%22%3E%3Cpath%20d%3D%22M0%202.3C20%201.6%2060%201.3%20100%201.9L100%202.5C60%202.7%2020%203%200%202.6Z%22%20fill%3D%22%232944B3%22/%3E%3C/svg%3E"); padding-bottom: 3px; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.nt-q span.wave { background-image: none; text-decoration: underline wavy var(--ink) 1px; text-underline-offset: 5px; }
.nt-q span.dots { background-image: none; text-emphasis: dot var(--ink); text-emphasis-position: under; }
.nt-n { margin-top: 6px; font: 400 16px/26px var(--kai); color: var(--ink); }
.nt-meta { margin-top: 6px; font: 400 13px/20px var(--sans); color: var(--faint); font-variant-numeric: tabular-nums; }

/* 提示 */
.toast {
  position: absolute; left: 50%; bottom: 128px; z-index: 30;
  max-width: 560px; padding: 11px 16px; border-radius: 8px;
  background: var(--print); color: var(--paper);
  font: 400 14px/20px var(--sans);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; transform: translate(-50%, 6px);
  transition: opacity .18s, transform .22s var(--ease-out);
  pointer-events: none;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* 展示用：截图时冻结 */
.frozen *, .frozen *::before, .frozen *::after { animation-play-state: paused !important; transition: none !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

.sel.fading .tint, .sel.fading .handle { opacity: 0; transition: opacity .5s; }
.sel.half .tint { opacity: .45; }
.sel.half .handle { opacity: 0; }
.toast.has-act { display: flex; align-items: center; gap: 18px; pointer-events: auto; }
.toast button { color: var(--paper); font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }
li { list-style: none; }
.toc-rule .here { stroke: var(--paper-2); }
.dw-foot {
  display: flex; justify-content: space-between; margin: 0 64px 0 96px; padding: 18px 0 30px;
  border-top: 1px solid var(--rule);
  font: 400 13px/20px var(--sans); color: var(--muted); font-variant-numeric: tabular-nums;
}
/* 写批注时，页边出现几条淡淡的横格，像在书边写字 */
.note.is-editing .field {
  background-image: linear-gradient(to top, rgba(41, 68, 179, .22) 0, rgba(41, 68, 179, .22) 1px, transparent 1px);
  background-size: 100% 26px;
  min-height: 78px;
}

/* 写批注时的专注：其余文字退成铅灰，这一句和墨迹保持原样 */
.flow, .opener, .ink .marks > g { transition: color .45s, opacity .45s; }
.page.is-annotating .flow { color: rgba(35, 33, 30, .3); }
.page.is-annotating .opener { opacity: .3; }
.page.is-annotating .ink .marks > g:not(.is-current) { opacity: .28; }
.page.is-annotating .note:not(.is-editing) { opacity: .3; }
::highlight(writing) { color: var(--print); }
