:root {
  color-scheme: light;
  --shell-bg: oklch(0.965 0.012 98);
  --paper: oklch(0.985 0.008 92);
  --panel-bg: color-mix(in oklch, var(--paper) 90%, oklch(0.92 0.008 120));
  --panel-border: oklch(0.84 0.012 116 / 0.6);
  --panel-shadow: 0 10px 24px rgba(76, 79, 53, 0.05);
  --frame-shadow: 0 14px 32px rgba(68, 72, 48, 0.08);
  --ink: oklch(0.27 0.026 135);
  --muted: oklch(0.48 0.015 126);
  --accent: oklch(0.37 0.05 138);
  --accent-2: oklch(0.62 0.06 77);
  --hotspot: rgba(52, 101, 67, 0.1);
  --hotspot-border: rgba(52, 101, 67, 0.38);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.96), transparent 32%),
    linear-gradient(180deg, oklch(0.978 0.01 100) 0%, oklch(0.952 0.015 108) 100%);
  overflow-x: hidden;
  overflow-y: auto;
}

body {
  padding: 8px;
}

.app-shell {
  max-width: 720px;
  margin: 0 auto;
  min-height: calc(100svh - 16px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.topbar,
.hintbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  background: rgba(251, 249, 241, 0.72);
  box-shadow: var(--panel-shadow);
}

.topbar {
  margin-bottom: 8px;
}

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

.book-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.book-title {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", "Songti SC", "STSong", serif;
  font-size: clamp(1rem, 0.98rem + 0.3vw, 1.18rem);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.page-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.page-name {
  margin: 0;
  max-width: 22ch;
  font-size: 12px;
  line-height: 1.25;
  color: var(--muted);
  text-align: right;
}

.page-counter {
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid rgba(52, 101, 67, 0.12);
  background: rgba(255, 255, 255, 0.66);
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
}

.viewer-shell {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  min-height: 0;
}

.viewer {
  min-width: 0;
  min-height: 0;
}

.page-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 842 / 1684;
  margin: 0 auto;
  padding: 0;
  border-radius: 18px;
  overflow: hidden;
  border: 0;
  box-shadow: var(--frame-shadow);
  touch-action: pan-y;
  background: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.page-sheet {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  overflow: hidden;
  transform: translate3d(0, 0, 0);
  will-change: transform;
}

.page-sheet-preview {
  opacity: 0;
  pointer-events: none;
}

.page-stage.is-dragging .page-sheet-preview,
.page-stage.is-animating .page-sheet-preview {
  opacity: 1;
}

.page-image {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 18px;
  pointer-events: none;
}

.hotspot-layer {
  position: absolute;
  inset: 0;
}

.qrcode-layer {
  position: absolute;
  inset: 0;
  /* 容器透传点击，避免盖住下方 hotspot-layer 的 button；
     子节点 img 通过 .qrcode-hotspot 的 pointer-events:auto 单独接收长按 */
  pointer-events: none;
}

.hotspot {
  position: absolute;
  border: 1px dashed var(--hotspot-border);
  background: var(--hotspot);
  border-radius: 8px;
  cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease;
}

.hotspot.hidden-hotspot {
  opacity: 0;
  border-color: transparent;
  background: transparent;
}

/* 二维码识别热点：盖一张真实 <img>（opacity:0 完全隐藏），微信内长按时触发
   原生"识别图中二维码"菜单。
   - 实测 opacity:0 可正常触发微信识别（微信读取 img 的 src 数据，与可见性无关）。
   - 真正影响识别稳定性的根因：翻页时若把 img 从 DOM 销毁再重建，微信识别 hook
     在重建窗口期会失效、回退到 iOS 系统图片菜单。已在 app.js 用 img 节点池复用解决。
   - -webkit-touch-callout / user-select 必须开启，否则部分微信版本不弹菜单。 */
.qrcode-hotspot {
  position: absolute;
  opacity: 0;
  pointer-events: auto;
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
}

.hotspot:hover,
.hotspot:focus-visible {
  transform: scale(1.02);
  background: rgba(40, 104, 71, 0.22);
  outline: none;
}

.overlay-action {
  position: absolute;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid rgba(63, 88, 62, 0.08);
  border-radius: 999px;
  background: rgba(251, 249, 241, 0.42);
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  box-shadow: 0 6px 10px rgba(60, 71, 49, 0.05);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  transition: transform 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
  touch-action: manipulation;
}

.overlay-action.debug-frame {
  outline: 1px dashed rgba(209, 138, 70, 0.8);
  outline-offset: 2px;
}

.overlay-action:hover,
.overlay-action:focus-visible {
  transform: translateY(-1px);
  background: rgba(255, 251, 245, 0.62);
  box-shadow: 0 8px 14px rgba(60, 71, 49, 0.08);
}

.overlay-action:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

.action-icon {
  font-size: 16px;
  line-height: 1;
}

.action-label {
  font-size: 12px;
  line-height: 1;
}

.nav-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(63, 88, 62, 0.12);
  border-radius: 50%;
  background: rgba(250, 248, 241, 0.82);
  color: var(--accent);
  font-size: 24px;
  line-height: 1;
  box-shadow: 0 8px 14px rgba(60, 71, 49, 0.06);
  cursor: pointer;
}

.nav-button svg {
  display: block;
  pointer-events: none;
}

.nav-button:disabled {
  opacity: 0.35;
  cursor: default;
}

.hintbar p {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(11, 27, 18, 0.7);
}

.modal.hidden,
.hidden {
  display: none;
}

.modal-panel {
  width: min(100%, 720px);
  border-radius: 24px;
  background: #fffdf8;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
}

.modal-close {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(40, 104, 71, 0.1);
  color: var(--accent);
  font-size: 28px;
  cursor: pointer;
}

.modal-body {
  padding: 16px;
}

#modal-video {
  width: 100%;
  max-height: 70vh;
  border-radius: 12px;
  background: #000;
}

.video-placeholder {
  display: grid;
  gap: 8px;
  min-height: 220px;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 760px) {
  body {
    padding: 2px;
  }

  .topbar,
  .hintbar {
    padding: 6px 8px;
    border-radius: 10px;
  }

  .book-title {
    font-size: 0.98rem;
  }

  .viewer-shell {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .nav-button {
    position: fixed;
    top: 60%;
    transform: translateY(-50%);
    z-index: 20;
    width: 44px;
    height: 44px;
    font-size: 26px;
    background: rgba(250, 248, 241, 0.3);
  }

  .nav-button.prev {
    left: max(12px, env(safe-area-inset-left));
  }

  .nav-button.next {
    right: max(12px, env(safe-area-inset-right));
  }

  .page-stage {
    border-radius: 0;
    width: 100vw;
    max-width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
  }

  .hotspot-layer {
    inset: 0;
  }

  .overlay-action {
    width: 36px;
    height: 36px;
  }

  .page-meta {
    gap: 6px;
  }

  .page-name {
    font-size: 11px;
    max-width: 13ch;
  }

  .hintbar {
    justify-content: center;
  }

  .hintbar p {
    text-align: center;
  }

  .eyebrow {
    display: none;
  }

  .hintbar {
    display: none;
  }
}

.btn-toc-subtle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 6px 6px;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 8px;
  transition: background-color 150ms ease;
}

.btn-toc-subtle:hover,
.btn-toc-subtle:focus-visible {
  background: rgba(40, 104, 71, 0.08);
  outline: none;
}

/* Gesture Hint Overlay */
.gesture-hint-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.4s ease;
  pointer-events: none; /* Let touches pass through to trigger dismissal */
}

.gesture-hint-overlay.fade-out {
  opacity: 0;
}

.hint-content {
  text-align: center;
  color: white;
}

.gesture-icons {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.gesture-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.hint-text {
  font-size: 25px; /* 配套文字大小，原来是15px，可以自己改大一点，比如 20px, 22px */
  line-height: 1.4;
  letter-spacing: 0.08em;
  font-weight: 500; /* 稍微加粗一点 */
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
  color: rgba(255, 255, 255, 0.95);
}

@keyframes swipe-h-anim {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-15px); }
  75% { transform: translateX(15px); }
}

/* Toast Notification */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, calc(-50% + 15px)) scale(0.95);
  background: color-mix(in oklch, var(--accent) 90%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--paper);
  padding: 14px 28px;
  border-radius: 32px;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.5px;
  opacity: 0;
  transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1), transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 100;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 12px 24px rgba(30, 45, 38, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.1) inset;
}

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

