/* ==================== Paper ==================== */
.paper {
  width: 780px;
  height: 990px;
  background: var(--color-paper);
  color: var(--color-paper-text);
  box-shadow: var(--shadow-paper);
  border-radius: 2px;
  position: relative;
  flex-shrink: 0;
  transition: background 0.3s ease;
  overflow: hidden;
}

.paper-content {
  padding: 80px 90px;
  height: 990px;
  box-sizing: border-box;
  position: relative;
  overflow: hidden;
}

/* Pagination support */
.page-break {
  page-break-after: always;
  break-after: page;
}

@media print {
  .paper {
    box-shadow: none;
    margin-bottom: 0;
    page-break-after: always;
  }
}

/* ==================== Paper Header Footer ==================== */
.paper-header {
  position: absolute;
  top: 40px;
  left: 90px;
  right: 90px;
  height: 30px;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  font-family: var(--font-serif);
  display: flex;
  align-items: center;
  border: none !important;
  border-bottom: none !important;
  padding-bottom: 0;
  box-shadow: none !important;
}

/* Chapter first page - hide header and footer */
.chapter-first-page .paper-header,
.chapter-first-page .paper-footer {
  display: none;
}

.paper-even .paper-header {
  justify-content: flex-start;
}

.paper-odd .paper-header {
  justify-content: flex-end;
}

.paper-footer {
  position: absolute;
  bottom: 40px;
  left: 90px;
  right: 90px;
  height: 30px;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  font-family: var(--font-serif);
  display: flex;
  align-items: center;
  justify-content: center;
  border: none !important;
  border-top: none !important;
  padding-top: 0;
  box-shadow: none !important;
}

.page-number {
  font-size: 0.9rem;
  letter-spacing: 0.1em;
  user-select: none;
  -webkit-user-select: none;
}

/* 页眉页脚整体不可选中，避免跨页选择时选到页码、书名、章名 */
.paper-header,
.paper-footer {
  user-select: none;
  -webkit-user-select: none;
}

/* Print layout - gutter */
.paper-print.paper-odd .paper-content {
  padding-left: 120px;
  padding-right: 90px;
}

.paper-print.paper-even .paper-content {
  padding-left: 90px;
  padding-right: 120px;
}

.paper-print.paper-odd .paper-header {
  left: 120px;
  right: 90px;
}

.paper-print.paper-even .paper-header {
  left: 90px;
  right: 120px;
}

.paper-print.paper-odd .paper-footer {
  left: 120px;
  right: 90px;
}

.paper-print.paper-even .paper-footer {
  left: 90px;
  right: 120px;
}

/* Mobile layout */
.paper-mobile {
  width: 420px;
  min-height: 740px;
}

.paper-mobile .paper-content {
  padding: 50px 40px;
  min-height: 740px;
}

.paper-mobile .paper-header {
  top: 25px;
  left: 40px;
  right: 40px;
}

.paper-mobile .paper-footer {
  bottom: 25px;
  left: 40px;
  right: 40px;
}

/* ==================== Text Styles ==================== */
.book-text p {
  text-indent: 2em;
  margin-bottom: 0.8em;
  text-align: justify;
  text-align-last: left;
  text-justify: inter-character;
}

/* 跨页续段：段落前半部分在上一页，后半部分流到下一页时，无首行缩进和上边距 */
.book-text p.para-continue,
.book-text .para-continue,
.section-page .book-text p.para-continue,
.section-page .book-text .para-continue,
.chapter-page .book-text p.para-continue,
.chapter-page .book-text .para-continue {
  text-indent: 0 !important;
  margin-top: 0 !important;
}

.book-text p:last-child {
  margin-bottom: 0;
}

.book-text h3,
.book-text .h3 {
  font-family: var(--font-heiti);
  font-size: 1.2rem;
  font-weight: 600;
  margin: 24px 0 12px;
  text-indent: 0;
}

.book-text h4,
.book-text .h4 {
  font-family: var(--font-heiti);
  font-size: 1.1rem;
  font-weight: 600;
  margin: 20px 0 10px;
  text-indent: 0;
}

.book-text .sub-title,
.section-page .book-text .sub-title {
  font-family: var(--font-heiti-bold) !important;
  font-size: 1.15rem;
  font-weight: 700;
  margin: 24px 0 12px;
  text-indent: 0;
}

.book-text .emphasis {
  font-weight: 700;
  font-family: inherit !important;
  text-emphasis: filled dot;
  -webkit-text-emphasis: filled dot;
  text-emphasis-position: under;
  -webkit-text-emphasis-position: under;
}

.book-text .faint,
.book-text p .faint,
.book-text p.faint,
.section-page .book-text p .faint,
.section-page .book-text .faint {
  font-family: '华文仿宋', 'STFangsong', 'FangSong', '仿宋', 'Noto Serif SC', serif !important;
  font-size: 0.9em !important;
  opacity: 0.7;
}

.book-text .quote,
.book-text p.quote {
  font-family: var(--font-fangsong) !important;
  margin: 16px 0;
  padding-left: 2em;
  padding-right: 2em;
  text-indent: 0;
  line-height: 1.9;
  color: var(--color-text-secondary);
  font-size: 0.98rem;
}

.footnote-ref {
  font-size: 0.75em;
  vertical-align: super;
  color: var(--color-primary);
  cursor: pointer;
  padding: 0 2px;
}

.footnotes-section {
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
  font-size: 0.88rem;
  line-height: 1.8;
}

.footnote-item {
  display: flex;
  gap: 8px;
  margin-bottom: 6px 0;
  color: var(--color-text-secondary);
}

.footnote-num {
  flex-shrink: 0;
  font-weight: 600;
  color: var(--color-primary);
  cursor: pointer;
  user-select: none;
}

.footnote-num:hover {
  text-decoration: underline;
}

.footnote-text {
  flex: 1;
  outline: none;
}

.footnote-text:focus {
  background: var(--color-primary-light);
  border-radius: 2px;
}

/* Quote style - 华文仿宋 */
.book-text blockquote,
.book-text .quote,
.book-text p.quote,
.book-text [style*="quote"],
.quote-style,
.section-page .book-text .quote,
.section-page .book-text p.quote,
.section-page .book-text blockquote {
  font-family: var(--font-fangsong) !important;
  font-size: 1rem;
  line-height: 1.9;
  color: var(--color-text-secondary);
  padding-left: 2em;
  padding-right: 2em;
  margin: 16px 0;
  text-indent: 2em;
}

/* Subtitle style */
.book-text h3,
.book-text .subtitle-style,
.section-page .book-text h3,
.section-page .book-text .subtitle-style {
  font-family: var(--font-heiti-bold) !important;
  font-size: 1.2rem;
  font-weight: 600;
  margin: 24px 0 12px;
}

/* ==================== Font Family Fixing ==================== */
.title-page-content,
.preface-page .book-text,
.chapter-page .book-text,
.section-page .book-text {
  font-family: var(--font-body) !important;
  font-size: 1.3rem !important;
  line-height: 1.8;
}

.chapter-summary,
.section-abstract {
  font-family: var(--font-kaiti) !important;
  font-size: 1.3rem !important;
  line-height: 1.9;
}

.title-page-content *,
.preface-page .book-text *,
.chapter-page .book-text *,
.section-page .book-text * {
  font-family: inherit !important;
  font-size: inherit !important;
}

/* 排除特殊样式元素，让 quote/sub-title/faint 保持自定义字体 */
/* 注意：emphasis 不排除，保持正文字体，仅加粗+着重号 */
.section-page .book-text .quote,
.section-page .book-text p.quote,
.section-page .book-text blockquote,
.section-page .book-text .sub-title,
.book-text .quote,
.book-text p.quote,
.book-text blockquote,
.book-text .sub-title {
  font-family: var(--font-fangsong) !important;
}

.book-text .sub-title,
.section-page .book-text .sub-title {
  font-family: var(--font-heiti-bold) !important;
}

/* ==================== Paragraph Spacing ==================== */
.book-text p,
.title-page-content p,
.preface-page .book-text p,
.chapter-summary p,
.section-abstract p {
  margin-bottom: 0.8em !important;
  text-indent: 2em;
  font-size: inherit !important;
}
/* 需求3：节摘要默认首行缩进（包括裸文字和首段 <p>） */
.section-abstract {
  text-indent: 2em;
}

.book-text p:last-child,
.title-page-content p:last-child,
.preface-page .book-text p:last-child,
.chapter-summary p:last-child,
.section-abstract p:last-child {
  margin-bottom: 0 !important;
}

/* Section content paragraph indent */
.section-page .book-text p {
  text-indent: 2em;
  margin-bottom: 0.8em;
}

/* Chapter content paragraph indent */
.chapter-page .book-text p {
  text-indent: 2em;
  margin-bottom: 0.8em;
}

/* ==================== Editable Elements ==================== */
.book-text:focus {
  background-color: transparent !important;
}

/* Custom cursor color for book text */
.book-text,
.title-page-content,
.chapter-summary,
.section-abstract {
  caret-color: var(--color-paper-text);
}

.book-text,
.title-page-content {
  min-height: 100px;
  padding: 0;
  font-family: var(--font-body);
}

.chapter-summary,
.section-abstract {
  min-height: 60px;
  padding: 0;
  position: relative;
}

.chapter-summary:focus,
.section-abstract:focus {
  outline: none;
  background-color: transparent !important;
}

/* Remove any focus highlighting */
.chapter-summary:focus,
.section-abstract:focus {
  outline: none;
  background-color: transparent !important;
}
