/* ===== 全局重置 ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  background: #1a1a1a;
  overflow: hidden;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ===== 主容器 ===== */
.viewer {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh; /* 移动端动态视口高度 */
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== 图片容器 ===== */
.page-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* 自定义手势（捏合缩放 / 平移 / 掀页）需要接管浏览器默认触摸行为 */
.page-container,
.tap-zone {
  touch-action: none;
}

.page-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transform-origin: 0 0;      /* 配合 JS 缩放坐标计算 */
  transition: transform 0.25s ease;
  pointer-events: none;       /* 触摸事件统一交给容器处理 */
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

/* 手势拖动过程中关闭过渡，保证跟手 */
.page-image.no-transition {
  transition: none;
}

/* ===== Canvas 页角卷曲翻页层 ===== */
.curl-canvas {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: none;
  pointer-events: none;
}

.curl-canvas.show {
  display: block;
}

/* ===== 点击翻页热区（左右各 25% 宽度） ===== */
.tap-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 25%;
  z-index: 5;
}

.tap-left {
  left: 0;
}

.tap-right {
  right: 0;
}

/* ===== 翻页按钮 ===== */
.nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.4);
  color: rgba(255, 255, 255, 0.9);
  font-size: 20px;
  line-height: 44px;
  text-align: center;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

.nav-btn:active {
  background: rgba(0, 0, 0, 0.7);
}

.nav-prev {
  left: 10px;
}

.nav-next {
  right: 10px;
}

/* 首页隐藏上一页，末页隐藏下一页 */
.nav-btn.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ===== 页码指示器 ===== */
.page-indicator {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  padding: 5px 14px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.45);
  color: rgba(255, 255, 255, 0.9);
  font-size: 13px;
  letter-spacing: 1px;
  cursor: pointer;
}

.page-indicator:active {
  background: rgba(0, 0, 0, 0.7);
}

/* ===== 缩略图跳转弹层 ===== */
.thumb-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.thumb-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.thumb-panel {
  width: 100%;
  max-height: 70%;
  background: #242424;
  border-radius: 16px 16px 0 0;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}

.thumb-overlay.open .thumb-panel {
  transform: translateY(0);
}

.thumb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: rgba(255, 255, 255, 0.9);
  font-size: 15px;
  padding: 2px 4px 12px;
}

.thumb-close {
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.9);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 18px;
  line-height: 30px;
  text-align: center;
  cursor: pointer;
}

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  overflow-y: auto;
}

.thumb-item {
  position: relative;
  border: 2px solid transparent;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  background: #333;
  aspect-ratio: 859 / 1257;
}

.thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-item .thumb-num {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 0 3px;
  text-align: center;
  font-size: 11px;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
}

/* 当前页高亮 */
.thumb-item.current {
  border-color: #4da3ff;
}
