/* ============================================================================
   《肇春来诗集》· 在线翻阅
   ----------------------------------------------------------------------------
   令牌沿用站点的 base.css(浅色默认 + 琥珀金强调)，这里只加「书」的部分:
   纸、书脊、翻页时的那层影子。

   页面尺寸由 JS 算好写进 style,CSS 只管怎么摆放 —— 纸的宽高要和 PDF 的
   比例(419.04 × 594.96 pt)对上，不然字会被拉扁。
   ========================================================================== */

.reader {
  background:
    radial-gradient(1200px 620px at 50% -10%, var(--bg-1), transparent 70%),
    var(--bg-0);
  min-height: 100vh;
}

.reader-main {
  padding-top: calc(var(--header-h) + 12px);
  padding-bottom: 20px;
}

/* ── 扉页 ────────────────────────────────────────────────────────────── */
/* 上面每让出 100px，书就长 100px —— 这里只留一个标题。 */
.reader-head {
  display: flex;
  align-items: baseline;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 16px;
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.reader-title {
  font-family: var(--font-serif);
  font-size: clamp(19px, 2.2vw, 24px);
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-0);
}

/* ── 工具条 ──────────────────────────────────────────────────────────── */
.reader-bar {
  position: sticky;
  top: var(--header-h);
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  width: 100%;
  max-width: var(--max);
  margin: 8px auto 0;
  padding: 6px var(--gutter);
}

.reader-bar__group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.reader-bar__group--right { margin-left: auto; }

.tool {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 13px;
  border: 1px solid var(--border-strong);
  border-radius: 99px;
  background: transparent;
  color: var(--text-1);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1;
  cursor: pointer;
  transition: color .2s ease, border-color .2s ease, background .2s ease, opacity .2s ease;
}

.tool:hover {
  color: var(--accent-text);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.tool:active { transform: translateY(1px); }

.tool svg { width: 14px; height: 14px; flex: none; }

.tool--icon { padding: 0; width: 34px; justify-content: center; }

.tool[disabled] {
  opacity: .38;
  cursor: default;
  pointer-events: none;
}

.zoom {
  display: flex;
  gap: 6px;
}

/* 页码输入 */
.reader-bar__group--page {
  gap: 6px;
  padding: 0 4px;
}

.page-input {
  width: 62px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-1);
  color: var(--text-0);
  font-family: var(--font-mono);
  font-size: 13.5px;
  text-align: center;
}

.page-input:focus {
  outline: none;
  border-color: var(--accent);
}

.page-total {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
}

/* ── 目录 ────────────────────────────────────────────────────────────── */
/* 目录做成工具条底下弹出来的一层，不占地方 ——
   展开的时候书不会跟着缩一下，读着书跳来跳去最烦人。 */
.toc {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  z-index: 50;
  width: min(620px, calc(100vw - 40px));
  max-height: min(70vh, 560px);
  overflow-y: auto;
  transform: translateX(-50%);
  padding: 20px 24px 22px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--bg-1);
  box-shadow: var(--shadow-lg);
}

.toc[hidden] { display: none; }

.toc__head {
  display: flex;
  align-items: center;
  margin-bottom: 14px;
}

.toc__title {
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 700;
  color: var(--text-0);
}

.toc__close {
  margin-left: auto;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-2);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.toc__close:hover { color: var(--accent-text); background: var(--accent-soft); }

.toc__list { counter-reset: none; list-style: none; }

.toc__list li + li { border-top: 1px solid var(--border); }

.toc__link {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 12px 4px;
  color: var(--text-1);
  font-size: 15px;
  transition: color .2s ease;
}

.toc__link:hover { color: var(--accent-text); }

.toc__link.is-current { color: var(--text-0); font-weight: 700; }

/* 篇章加重，下面的小节缩进一点、字小一点 */
.toc__link:not(.toc__link--sub) .toc__name {
  font-weight: 600;
  color: var(--text-0);
}

.toc__link--sub { padding-left: 22px; }
.toc__link--sub .toc__name { font-size: 14px; }

.toc__name { flex: 1; }

.toc__page {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-3);
}

.toc__note {
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--text-3);
}

/* ── 书台 ────────────────────────────────────────────────────────────── */
.stage {
  position: relative;
  display: flex;
  align-items: safe center;
  justify-content: safe center;
  height: 74vh;
  margin-top: 4px;
  padding: 14px 16px 16px;
  overflow: auto;
}

/* 用 margin:auto 居中，不用 flex 的 justify-content:center ——
   放大之后书比台面宽,flex 居中会让左边那截滚不到,auto 居中不会。

   width:max-content 是关键：书要正好包住两页，不然「点在书的右半边还是左半边」
   会按空白处的中心算，点右页也可能被当成往回翻。 */
.book {
  position: relative;
  display: flex;
  flex: none;                 /* 台面再窄也不许把书压扁 */
  width: max-content;
  margin: 0 auto;
  perspective: 2600px;
  perspective-origin: 50% 40%;
}

.book--single { perspective: none; }

.book[hidden] { display: none; }

/* 一张纸 */
.slot {
  position: relative;
  background: #fff;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, .10);
  box-shadow: 0 22px 48px -26px rgba(0, 0, 0, .55);
}

.slot--left  { border-radius: 3px 0 0 3px; border-right: none; }
.slot--right { border-radius: 0 3px 3px 0; border-left: none; }
.slot--one   { border-radius: 3px; transition: transform .2s ease, opacity .2s ease; }

/* 单页模式换页：轻轻滑过去 */
.slot--one.is-out-left  { transform: translateX(-10%); opacity: 0; }
.slot--one.is-out-right { transform: translateX(10%); opacity: 0; }
.slot--one.is-in-right  { transform: translateX(10%); opacity: 0; }
.slot--one.is-in-left   { transform: translateX(-10%); opacity: 0; }

.slot canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #fff;
}

/* 纸还没渲染出来的时候，先是一层淡淡的灰 */
.slot.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, #f4f4f6 30%, #fbfbfc 50%, #f4f4f6 70%);
  background-size: 300% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  0%   { background-position: 140% 0; }
  100% { background-position: -40% 0; }
}

/* 空白页(全书最后一页) */
.slot__blank {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  background: #faf9f6;
  color: #a9a49a;
  font-family: var(--font-serif);
  font-size: 14px;
  letter-spacing: .2em;
}

/* 书脊：一道压出来的阴影 */
.spine {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 46px;
  transform: translateX(-50%);
  z-index: 3;
  pointer-events: none;
  background:
    linear-gradient(to right, transparent, rgba(0, 0, 0, .16) 45%, rgba(0, 0, 0, .20) 50%, rgba(0, 0, 0, .10) 56%, transparent);
  opacity: .85;
}

/* 翻起来的那一张 */
.leaf {
  position: absolute;
  top: 0;
  left: 50%;
  z-index: 4;
  transform-style: preserve-3d;
  transform-origin: left center;
  transform: rotateY(-180deg);
  visibility: hidden;
  pointer-events: none;
}

.leaf.is-active { visibility: visible; }

.leaf__face {
  position: absolute;
  inset: 0;
  background: #fff;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border: 1px solid rgba(0, 0, 0, .10);
}

.leaf__face--front { box-shadow: 0 22px 48px -26px rgba(0, 0, 0, .55); }
.leaf__face--back  { transform: rotateY(180deg); }

.leaf__face canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #fff;
}

/* 翻页时纸面上的那层暗影 */
.leaf__shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(to left, rgba(0, 0, 0, .30), rgba(0, 0, 0, 0) 55%);
}

/* 翻的时候，底下那一页也压一层影 */
.stage.is-flipping .slot--left::before,
.stage.is-flipping .slot--right::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.stage.is-flipping .slot--left::before {
  background: linear-gradient(to right, rgba(0, 0, 0, .16), transparent 40%);
}

.stage.is-flipping .slot--right::before {
  background: linear-gradient(to left, rgba(0, 0, 0, .16), transparent 40%);
}

/* ── 加载 / 出错 ─────────────────────────────────────────────────────── */
.stage__loading,
.stage__error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 14px;
  color: var(--text-2);
}

.stage__loading[hidden],
.stage__error[hidden] { display: none; }

.stage__error a { color: var(--accent-text); text-decoration: underline; }

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── 进度 ────────────────────────────────────────────────────────────── */
.reader-foot {
  width: 100%;
  max-width: var(--max);
  margin: 2px auto 0;
  padding: 0 var(--gutter);
}

.progress {
  flex: 1;
  height: 2px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
}

.progress__bar {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .35s cubic-bezier(.22, .61, .36, 1);
}

/* 进度条和页码并排一行 —— 底下只留这一行，别再占地方 */
.reader-foot__row {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12px;
  color: var(--text-3);
}

.reader-foot__page {
  font-family: var(--font-mono);
  color: var(--text-2);
  white-space: nowrap;
}

/* 无障碍 */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.noscript {
  max-width: 640px;
  margin: 40px auto;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  text-align: center;
  color: var(--text-1);
}

.noscript a { color: var(--accent-text); text-decoration: underline; }

/* ── 窄屏 ────────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  .reader-main { padding-top: calc(var(--header-h) + 8px); }

  /* 手机上把字都收起来 —— 屏幕小，书比说明重要 */
  .reader-title { font-size: 19px; }

  .reader-bar { gap: 6px 8px; padding: 6px var(--gutter); }
  .reader-bar__group { gap: 6px; }
  .reader-bar__group--right { margin-left: 0; }
  .tool span { display: none; }
  .tool { padding: 0; width: 34px; justify-content: center; }
  .tool--icon { width: 34px; }
  .page-total { display: none; }
  .page-input { width: 46px; padding: 0 4px; }

  .stage { height: 66vh; padding: 8px 10px 10px; }
  .toc { padding: 16px 18px 18px; }
}

@media (max-width: 480px) {
  .reader-sub { font-size: 14px; }
  .page-input { width: 54px; }
}

/* 系统开了「减弱动态效果」就别翻了，直接换页 */
@media (prefers-reduced-motion: reduce) {
  .leaf { transition: none !important; }
  .slot.is-loading::after { animation: none; }
  .spinner { animation-duration: 2s; }
}
