/* 书页 · 手机 / 平板阅读界面 */

:root {
  --ease-out: cubic-bezier(0.22, 0.85, 0.28, 1);
  --dim: 0;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  transition: background-color 0.4s ease, color 0.4s ease;
}

body.reading {
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}

/* ---------- 主题 ---------- */

html[data-theme="paper"] {
  --bg: #eee9de;
  --paper: #fffdf8;
  --ink: #2a2622;
  --muted: rgba(42, 38, 34, 0.55);
  --line: rgba(42, 38, 34, 0.13);
  --surface: rgba(255, 253, 248, 0.92);
  --sheet: #fbf8f2;
  --accent: #8a5a33;
  --accent-ink: #fff8ef;
  --shadow: 0 26px 60px rgba(45, 35, 20, 0.2), 0 2px 8px rgba(45, 35, 20, 0.1);
}

html[data-theme="sepia"] {
  --bg: #e7dcc3;
  --paper: #f6ecd6;
  --ink: #342c1f;
  --muted: rgba(52, 44, 31, 0.55);
  --line: rgba(52, 44, 31, 0.15);
  --surface: rgba(250, 243, 227, 0.94);
  --sheet: #f7efdb;
  --accent: #8d5a2b;
  --accent-ink: #fff9ee;
  --shadow: 0 26px 60px rgba(60, 42, 18, 0.22), 0 2px 8px rgba(60, 42, 18, 0.1);
}

html[data-theme="warm"] {
  --bg: #d3cfc8;
  --paper: #ece9e3;
  --ink: #2b2926;
  --muted: rgba(43, 41, 38, 0.55);
  --line: rgba(43, 41, 38, 0.14);
  --surface: rgba(240, 237, 232, 0.94);
  --sheet: #e8e5df;
  --accent: #5f5a52;
  --accent-ink: #faf8f4;
  --shadow: 0 26px 60px rgba(30, 28, 24, 0.26), 0 2px 8px rgba(30, 28, 24, 0.12);
}

html[data-theme="ink"] {
  --bg: #0c0c0e;
  --paper: #141416;
  --ink: #e8e3d8;
  --muted: rgba(232, 227, 216, 0.5);
  --line: rgba(255, 255, 255, 0.12);
  --surface: rgba(28, 28, 32, 0.9);
  --sheet: #16161a;
  --accent: #d8a86b;
  --accent-ink: #1b1408;
  --shadow: 0 26px 60px rgba(0, 0, 0, 0.7), 0 2px 8px rgba(0, 0, 0, 0.5);
}

/* ---------- 首页 ---------- */

.home {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(30px + env(safe-area-inset-top)) 22px
    calc(28px + env(safe-area-inset-bottom));
}

.home-inner {
  width: min(100%, 440px);
}

.eyebrow {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.24em;
  color: var(--muted);
  text-transform: uppercase;
}

.display {
  margin: 16px 0 18px;
  font-family: "Songti SC", "Noto Serif SC", "Source Han Serif SC", "STSong",
    serif;
  font-size: clamp(40px, 13vw, 62px);
  line-height: 1.06;
  letter-spacing: -0.02em;
  font-weight: 600;
}

.lead {
  margin: 0 0 30px;
  font-size: 14.5px;
  line-height: 1.8;
  color: var(--muted);
  max-width: 34em;
}

.open-form {
  display: grid;
  gap: 12px;
}

.open-form input {
  width: 100%;
  height: 54px;
  padding: 0 18px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.open-form input::placeholder {
  color: var(--muted);
}

.open-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.primary {
  height: 54px;
  border-radius: 16px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

.primary:active {
  transform: scale(0.985);
  opacity: 0.92;
}

.primary.block {
  display: block;
  width: 100%;
  height: 50px;
  margin-top: 16px;
  font-size: 15px;
}

.home-error {
  margin: 14px 0 0;
  font-size: 13px;
  line-height: 1.65;
  color: #b3452f;
}

html[data-theme="ink"] .home-error {
  color: #f08b74;
}

.recent {
  margin-top: 34px;
}

.recent-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--muted);
  margin-bottom: 10px;
}

.recent-note {
  letter-spacing: 0.06em;
}

.recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.recent-list button {
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: left;
  font-size: 14px;
  transition: transform 0.14s ease;
}

.recent-list button:active {
  transform: scale(0.99);
}

.recent-list .recent-page {
  font-size: 12px;
  color: var(--muted);
  flex: none;
}

.recent-list .recent-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.notice {
  margin-top: 34px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.75;
}

.notice summary {
  cursor: pointer;
  letter-spacing: 0.04em;
  outline: none;
}

.notice ul {
  margin: 10px 0 0;
  padding-left: 18px;
}

.notice li {
  margin-bottom: 4px;
}

/* ---------- 阅读器 ---------- */

.reader {
  position: fixed;
  inset: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.reader::after {
  content: "";
  position: fixed;
  inset: 0;
  background: #000;
  opacity: var(--dim);
  pointer-events: none;
  z-index: 6;
  transition: opacity 0.25s ease;
}

.stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: pan-y;
  z-index: 2;
}

.reader.fit-width .stage {
  align-items: flex-start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.book {
  position: relative;
  flex: none;
  overflow: hidden;
  border-radius: 3px;
  background: var(--paper);
  box-shadow: var(--shadow);
  perspective: 1900px;
  perspective-origin: 50% 50%;
  transition: box-shadow 0.4s ease;
}

.page-base {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  background: var(--paper);
  -webkit-user-drag: none;
}

.book.crop .page-base {
  transform: scale(1.075);
}

/* 翻页：把要翻走的那一页按弧面逐条画到 canvas 上 —— 纸才会卷起来 */

.flip-canvas {
  position: absolute;
  inset: 0;
  display: block;
  visibility: hidden;
  pointer-events: none;
}

/* 曲面翻页画布贴住书页，越界部分由书页裁掉，翻完不会留一片纸在外面 */

.curl-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  visibility: hidden;
  pointer-events: none;
  z-index: 2;
}

/* 加载 */

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  z-index: 3;
  background: var(--bg);
}

.loading-ring {
  width: 34px;
  height: 34px;
  margin: 0 auto;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

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

/* 错误卡片 */

.error-card {
  position: relative;
  z-index: 7;
  width: min(84%, 360px);
  padding: 26px 24px 20px;
  border-radius: 22px;
  background: var(--sheet);
  box-shadow: var(--shadow);
  text-align: center;
}

.error-card h2 {
  margin: 0 0 10px;
  font-size: 17px;
  font-weight: 600;
}

.error-card p {
  margin: 0 0 20px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--muted);
}

.error-actions {
  display: grid;
  gap: 8px;
}

.ghost {
  height: 46px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: transparent;
  font-size: 14.5px;
  transition: background 0.2s ease;
}

.ghost:active {
  background: var(--line);
}

/* 页码 / 状态条 */

.pager {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 8px);
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 15px;
  border-radius: 999px;
  background: rgba(20, 18, 14, 0.34);
  color: rgba(255, 255, 255, 0.94);
  font-size: 11.5px;
  letter-spacing: 0.08em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s var(--ease-out);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 10;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pager.show {
  opacity: 0.94;
  transform: translate(-50%, 0);
}

.pager-sep {
  opacity: 0.45;
  margin: 0 1px;
}

.pager .stat {
  padding-left: 9px;
  border-left: 1px solid rgba(255, 255, 255, 0.26);
  opacity: 0.86;
}

.hint {
  position: fixed;
  left: 50%;
  bottom: calc(58px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  font-size: 11.5px;
  letter-spacing: 0.12em;
  color: var(--muted);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
  z-index: 10;
}

.hint.show {
  opacity: 0.9;
}

/* ---------- 设置面板 ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 5, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.32s ease;
  z-index: 30;
}

body.sheet-open .sheet-backdrop {
  opacity: 1;
  pointer-events: auto;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 90vh;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  background: var(--sheet);
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -18px 50px rgba(0, 0, 0, 0.24);
  transform: translateY(104%);
  transition: transform 0.42s var(--ease-out);
  pointer-events: none;
  z-index: 40;
  padding-bottom: env(safe-area-inset-bottom);
}

body.sheet-open .sheet {
  transform: translateY(0);
  pointer-events: auto;
}

.sheet-grab {
  width: 38px;
  height: 4px;
  margin: 10px auto 0;
  border-radius: 999px;
  background: var(--line);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px 6px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.sheet-done {
  font-size: 14px;
  color: var(--accent);
  padding: 6px 4px;
}

.sheet-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 18px 26px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.group {
  padding: 16px 0 4px;
}

.group + .group {
  border-top: 1px solid var(--line);
  margin-top: 12px;
}

.group-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 4px 10px;
  font-size: 11.5px;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.group-value {
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

/* 分段控件 */

.slab {
  display: grid;
  gap: 8px;
  padding: 6px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.slab.pad {
  padding: 10px;
}

.seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 13px;
  background: var(--line);
}

.slab .seg {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}

.seg button {
  flex: 1;
  height: 38px;
  padding: 0 4px;
  border-radius: 10px;
  font-size: 13px;
  color: var(--muted);
  transition: background 0.22s ease, color 0.22s ease;
  white-space: nowrap;
}

.seg button[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
}

.seg button.active {
  background: var(--sheet);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

/* 开关键 */

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 2px 6px;
}

.row-label {
  font-size: 14px;
}

.switch {
  position: relative;
  flex: none;
  width: 47px;
  height: 28px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 16%, transparent);
  transition: background 0.22s ease;
}

.switch i {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.24);
  transition: transform 0.24s var(--ease-out);
}

.switch[aria-checked="true"] {
  background: var(--accent);
}

.switch[aria-checked="true"] i {
  transform: translateX(19px);
}

/* 底色 */

.swatches {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px 6px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.swatches button {
  display: grid;
  gap: 8px;
  justify-items: center;
  padding: 8px 0 6px;
  border-radius: 14px;
  border: 1px solid transparent;
  font-size: 12px;
  color: var(--muted);
  transition: border-color 0.2s ease, color 0.2s ease;
}

.swatches button.active {
  border-color: var(--accent);
  color: var(--ink);
}

.chip {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--chip);
  border: 1px solid rgba(0, 0, 0, 0.12);
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.4);
}

.chip::after {
  content: "✓";
  font-size: 15px;
  line-height: 1;
  color: var(--check, #fff);
  opacity: 0;
  transform: scale(0.62);
  transition: opacity 0.18s ease, transform 0.18s var(--ease-out);
}

.swatches button.active .chip::after {
  opacity: 1;
  transform: scale(1);
}

/* 亮度 */

.range {
  width: 100%;
  height: 26px;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  accent-color: var(--accent);
}

.range::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 18%, transparent);
}

.range::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -9.5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22);
}

/* 书签 */

.bookmarks {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  max-height: 210px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.bookmarks li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bookmarks .jump {
  flex: 1;
  min-height: 42px;
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: left;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}

.bookmarks .jump small {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
}

.bookmarks .remove {
  width: 44px;
  height: 42px;
  border-radius: 12px;
  font-size: 12.5px;
  color: var(--muted);
}

.fineprint {
  margin: 10px 4px 0;
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--muted);
}

/* 事实表 */

.facts {
  margin: 0;
  display: grid;
  gap: 9px;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 13px;
}

.facts div {
  display: flex;
  gap: 14px;
}

.facts dt {
  flex: none;
  width: 4.5em;
  color: var(--muted);
}

.facts dd {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 分享二维码 ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 6, 4, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(100%, 340px);
  padding: 22px 20px 18px;
  border-radius: 24px;
  background: var(--sheet);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.36);
  text-align: center;
  animation: pop 0.28s var(--ease-out);
}

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.94) translateY(10px);
  }
}

.modal-card h2 {
  margin: 0 0 6px;
  font-size: 16.5px;
  font-weight: 600;
}

.modal-lead {
  margin: 0 auto;
  max-width: 16em;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--muted);
}

.qr-wrap {
  width: fit-content;
  margin: 16px auto 10px;
  padding: 10px;
  border-radius: 18px;
  background: #fff;
  line-height: 0;
}

#qrCanvas {
  display: block;
}

.qr-caption {
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.modal-actions .primary {
  height: 46px;
  border-radius: 14px;
  font-size: 14.5px;
}

.modal-actions .ghost {
  height: 46px;
}

/* Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(72px + env(safe-area-inset-bottom));
  transform: translate(-50%, 6px);
  max-width: 78vw;
  padding: 11px 18px;
  border-radius: 999px;
  background: rgba(20, 18, 14, 0.86);
  color: #fff;
  font-size: 12.5px;
  line-height: 1.4;
  text-align: center;
  opacity: 0;
  transition: opacity 0.28s ease, transform 0.28s var(--ease-out);
  pointer-events: none;
  z-index: 80;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* 平板：首页更居中，设置面板居中成卡片，阅读器仍然满屏 */

@media (min-width: 700px) {
  .home {
    padding-left: 40px;
    padding-right: 40px;
  }

  .home-inner {
    width: min(100%, 520px);
  }

  .display {
    font-size: clamp(56px, 8vw, 76px);
  }

  .sheet {
    left: 50%;
    right: auto;
    width: min(92vw, 620px);
    transform: translate(-50%, 104%);
    border-radius: 26px;
    bottom: 22px;
  }

  body.sheet-open .sheet {
    transform: translate(-50%, 0);
  }

  .pager {
    bottom: calc(26px + env(safe-area-inset-bottom));
  }

  .sheet-body {
    padding: 4px 22px 28px;
  }
}

/* 降低动态效果 */

@media (prefers-reduced-motion: reduce) {
  .sheet,
  .sheet-backdrop,
  .pager,
  .hint,
  .toast,
  .modal-card {
    transition-duration: 0.01ms;
    animation-duration: 0.01ms;
  }
}
