/* 国家地理分级阅读 · 课文 PDF / 打印样式 */
:root {
  --ng-gold: #f5c400;
  --ng-gold-dim: #c9a008;
  --ink: #1a1a1a;
  --ink-soft: #5a5a5a;
  --paper: #f7f5f0;
  --paper-edge: #e8e4db;
  --frame: #d4cfc3;
  --accent: #0277bd;
  --wild: #2c4a3e;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body.ng-story-print-body {
  font-family: "Noto Sans SC", "Segoe UI", sans-serif;
  background: #eceff1;
  color: var(--ink);
  padding: 1rem;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.no-print {
}

.ng-story-toolbar {
  max-width: 52rem;
  margin: 0 auto 1rem;
  background: #fff;
  border-radius: 14px;
  padding: 1.1rem 1.25rem;
  border-left: 5px solid var(--ng-gold);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

.ng-story-toolbar h1 {
  font-family: "Source Serif 4", "Noto Serif SC", Georgia, serif;
  font-size: 1.35rem;
  color: var(--accent);
  margin-bottom: 0.4rem;
  line-height: 1.35;
}

.ng-story-toolbar p {
  font-size: 0.88rem;
  color: #546e7a;
  line-height: 1.55;
  margin-bottom: 0.65rem;
}

.ng-story-toolbar .row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  margin: 0.5rem 0;
}

.ng-story-toolbar label {
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.ng-story-btn {
  font-family: "Noto Sans SC", sans-serif;
  font-weight: 700;
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 0.5rem 1.1rem;
  background: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  text-decoration: none;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  touch-action: manipulation;
}

.ng-story-btn.primary {
  background: var(--ng-gold);
  border-color: var(--ng-gold-dim);
}

.ng-story-btn.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.ng-story-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

#storyPrintArea {
  max-width: 52rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-x: hidden;
}

/* ── A4 页面（所有预览、导出与打印统一为 210mm × 297mm）── */
.story-print-sheet {
  width: 210mm;
  height: 297mm;
  min-height: 297mm;
  margin: 0 auto;
  background: var(--paper);
  position: relative;
  overflow: hidden;
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.1);
  page-break-after: always;
  break-after: page;
}

.story-print-sheet:last-child {
  page-break-after: auto;
  break-after: auto;
}

.story-print-sheet::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
  background: var(--ng-gold);
  z-index: 2;
}

.story-print-inner {
  padding: 12mm 16mm 12mm 18mm;
  height: 297mm;
  min-height: 297mm;
  display: flex;
  flex-direction: column;
}

/* 封面 · 全幅大图 + 底部渐变 */
.story-print-cover {
  background:
    radial-gradient(120% 70% at 82% 8%, rgba(245, 196, 0, 0.28), transparent 52%),
    linear-gradient(165deg, #12263a 0%, #0b1724 42%, #070d14 100%);
  color: #fff;
}

.story-print-cover::before {
  width: 100%;
  height: 7px;
  bottom: auto;
  background: linear-gradient(90deg, var(--ng-gold) 0%, #ffe082 46%, var(--ng-gold) 100%);
}

.story-print-cover .story-print-inner {
  position: relative;
  z-index: 2;
  justify-content: flex-end;
  align-items: stretch;
  text-align: left;
  padding: 0;
  color: #fff;
}

.cover-hero {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: inherit;
}

.cover-hero-img {
  display: block;
  position: absolute;
  left: 0;
  top: 0;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  object-fit: contain;
  object-position: center center;
}

.cover-hero-img.is-hide {
  display: none !important;
}

.cover-hero-fallback {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  font-size: 96px;
  opacity: 0.55;
}

.cover-hero-img.is-hide ~ .cover-hero-fallback {
  display: flex;
}

.cover-scrim {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(
      180deg,
      rgba(7, 12, 20, 0.18) 0%,
      rgba(7, 12, 20, 0.04) 28%,
      rgba(7, 12, 20, 0.38) 56%,
      rgba(7, 12, 20, 0.92) 100%
    ),
    linear-gradient(90deg, rgba(7, 12, 20, 0.28) 0%, transparent 42%);
  pointer-events: none;
}

.cover-copy {
  position: relative;
  z-index: 2;
  padding: 0 18mm 8mm 18mm;
  max-width: 176mm;
}

.cover-kicker {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--ng-gold);
}

.story-print-cover h2 {
  font-family: "Source Serif 4", "Noto Serif SC", Georgia, serif;
  font-size: 2.85rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.16;
  max-width: 168mm;
  margin: 0 0 12px;
  text-align: left;
  text-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
}

.cover-tag {
  display: inline-block;
  margin: 0;
  padding-top: 10px;
  border-top: 2px solid var(--ng-gold);
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.86);
}

.cover-footer {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  padding: 0 18mm 16mm;
}

.cover-hint {
  margin: 0;
  max-width: 110mm;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.78);
}

.story-qr {
  width: 18mm;
  text-align: center;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  box-sizing: border-box;
}

.story-qr img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  max-width: 100%;
  margin: 0;
  padding: 2mm;
  background: #fff;
  border: 1px solid var(--frame);
  border-radius: 2px;
  box-sizing: border-box;
  object-fit: contain;
}

.story-qr-cap {
  display: block;
  width: 100%;
  margin-top: 2px;
  font-size: 0.58rem;
  line-height: 1.2;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}

.story-qr.is-hide {
  display: none;
}

.story-print-cover .story-qr.story-qr--cover {
  width: 34mm;
  margin-top: 0;
  padding: 3.2mm 3.2mm 2.6mm;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

.story-print-cover .story-qr.story-qr--cover img {
  width: 100%;
  height: auto;
  max-width: 100%;
  padding: 0;
  border: 0;
  border-radius: 2mm;
}

.story-print-cover .story-qr.story-qr--cover .story-qr-cap {
  font-size: 0.58rem;
  margin-top: 1.6mm;
  color: #3d4a55;
}

/* 内容页顶栏 */
.story-page-hdr {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  border-bottom: 2px solid var(--ng-gold);
  padding-bottom: 6px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.story-page-hdr .book-name {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
  padding-top: 2px;
}

.story-hdr-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  flex-shrink: 0;
}

.story-page-hdr .page-num {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

/* 插图区：相框随图片等比缩放，最大高度 82mm */
.story-art-wrap {
  flex: 0 0 auto;
  width: 100%;
  height: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2mm 0 3mm;
  min-height: 0;
  max-height: 82mm;
}

.story-polaroid {
  background: #fff;
  border: 1px solid var(--frame);
  border-radius: 4px;
  padding: 6px 6px 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  width: 100%;
  height: auto;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.story-polaroid::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 6px;
  height: 3px;
  background: var(--ng-gold);
  opacity: 0.5;
}

.story-polaroid img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 76mm;
  object-fit: contain;
  object-position: center center;
  margin: 0 auto;
  border-radius: 2px;
}

.story-polaroid img.is-hide {
  display: none !important;
}

.story-polaroid .art-fallback {
  display: none;
  font-size: 4rem;
  text-align: center;
  padding: 1rem;
  width: 100%;
  height: 100%;
  line-height: 70mm;
}

.story-polaroid img.is-hide + .art-fallback {
  display: block;
}

/* 文字区 · 金字塔朗读 */
.story-text-block {
  flex: 1 1 auto;
  min-height: 0;
  padding-top: 2mm;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.story-num-badge {
  display: inline-block;
  align-self: flex-start;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 0.88rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border-radius: 999px;
  padding: 3px 12px;
  margin-bottom: 6px;
  flex-shrink: 0;
}

.story-pyramid-print {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.28em;
  width: 100%;
  font-family: "Source Serif 4", Georgia, "Noto Serif SC", serif;
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1.28;
  color: var(--ink);
}

.pyramid-print--short { font-size: 2.55rem; gap: 0.38em; }
.pyramid-print--mid { font-size: 2.15rem; gap: 0.3em; }
.pyramid-print--long { font-size: 1.78rem; gap: 0.24em; }
.pyramid-print--xl { font-size: 1.55rem; gap: 0.16em; }
.pyramid-print--xxl { font-size: 1.18rem; gap: 0.1em; }
.pyramid-print--mega { font-size: 1.02rem; gap: 0.06em; }
.pyramid-print--sent { font-size: 1.38rem; gap: 0.22em; }

.story-text-block:has(.pyramid-print--xxl),
.story-text-block:has(.pyramid-print--mega),
.story-text-block:has(.pyramid-print--sent) {
  justify-content: flex-start;
}

.pyramid-print--sent .py-print-layer {
  width: 100%;
  max-width: 100%;
  align-items: flex-start;
}

.pyramid-print--sent .py-text {
  white-space: normal;
}

.py-print-layer {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.4rem;
  width: var(--py-w, 70%);
  max-width: 100%;
  padding: 0.22em 0.55em 0.22em 0.32em;
  border-radius: 8px;
  background: #fff;
  border: 2px solid #1a1a1a;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.08);
}

.pyramid-print--xxl .py-print-layer,
.pyramid-print--mega .py-print-layer {
  padding: 0.1em 0.4em 0.1em 0.25em;
  border-width: 1.5px;
  border-radius: 6px;
}

.py-print-layer .py-idx {
  flex: 0 0 1.45em;
  width: 1.45em;
  height: 1.45em;
  border-radius: 50%;
  background: var(--ng-gold);
  color: #1a1a1a;
  font-size: 0.55em;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: "Noto Sans SC", sans-serif;
}

.py-print-layer .py-text {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.py-print-layer .py-old {
  color: #5a6a78;
  font-weight: 600;
}

.py-print-layer .py-new {
  color: #0e3a5a;
  font-weight: 800;
}

.story-divider {
  width: 48px;
  height: 3px;
  background: linear-gradient(90deg, var(--ng-gold), transparent);
  margin: 8px 0 8px;
  border-radius: 2px;
  flex-shrink: 0;
}

.story-zh {
  font-size: 1.48rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--wild);
  flex-shrink: 0;
}

.story-text-block:has(.pyramid-print--xl) .story-zh { font-size: 1.38rem; }
.story-text-block:has(.pyramid-print--xxl) .story-zh { font-size: 1.22rem; }
.story-text-block:has(.pyramid-print--mega) .story-zh,
.story-text-block:has(.pyramid-print--sent) .story-zh { font-size: 1.18rem; }

.story-zh.is-hidden {
  display: none;
}

/* 屏幕预览缩放由 ng-story-print.js 的 fitPreview 写入 transform */

/* 窄屏预览保持 A4 几何，由 JS 按容器宽度缩放；导出时不得套用这套规则。 */
@media screen and (max-width: 800px) {
  body.ng-story-print-body:not(.is-exporting) {
    padding: 0.5rem;
  }
}

/* html2pdf 必须始终按真实 A4 尺寸采集，不能继承窄屏预览缩放。 */
body.ng-story-print-body.is-exporting {
  padding: 0;
}

#storyPrintArea.is-exporting {
  width: 210mm;
  max-width: none;
  gap: 0;
}

#storyPrintArea.is-exporting .story-print-sheet {
  width: 210mm !important;
  /* 留出 1mm 栅格化余量，避免 html2pdf 将恰好 297mm 的页误判为跨页。 */
  height: 296mm !important;
  min-height: 296mm !important;
  margin: 0 !important;
  transform: none !important;
  box-shadow: none;
  page-break-after: auto !important;
  break-after: auto !important;
}

#storyPrintArea.is-exporting .story-print-inner {
  height: 296mm !important;
  min-height: 296mm !important;
}

@media print {
  body.ng-story-print-body {
    background: #fff;
    padding: 0;
  }

  .no-print {
    display: none !important;
  }

  #storyPrintArea {
    width: 210mm;
    max-width: none;
    gap: 0;
  }

  .story-print-sheet {
    box-shadow: none;
    margin: 0;
    width: 210mm !important;
    height: auto !important;
    min-height: 296mm !important;
    overflow: visible;
    transform: none !important;
  }

  .story-print-inner {
    height: auto !important;
    min-height: 296mm !important;
  }
}

@page {
  size: A4 portrait;
  margin: 0;
}
