/* ============================================================
   Between the Spines · 书店寻书
   奶白粉彩底 · Didot 风大标题 · 一排竖立书脊 · 悬停翻开封面
   ============================================================ */

:root {
  --bg: #ece9e2;            /* 随悬停书籍切换 */
  --ink: #141414;           /* 墨色随悬停书籍色板切换，保证深色背景下可读 */
  --ink-muted: rgba(20, 20, 20, 0.52);  /* 由 app.js 随色板同步更新 */
  --panel: rgba(255, 255, 255, 0.86);
  --shelf-scale: 1;         /* 书籍整体缩放系数，移动端媒体查询下调 */
}

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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  transition: background 0.9s cubic-bezier(0.4, 0, 0.2, 1);
}

.stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;   /* 移动端地址栏收起/展开时视口高度准确 */
  display: flex;
  flex-direction: column;
}

/* ---------- 巨型背景书名字 ---------- */
.bg-word {
  position: absolute;
  left: 0;
  right: 0;
  top: 16vh;
  bottom: 32vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.9s ease;
}
.bg-word.show { opacity: 1; }
.bg-word span {
  font-family: "Noto Serif SC", "Playfair Display", serif;
  font-weight: 600;
  font-size: clamp(180px, 34vh, 380px);
  line-height: 1;
  letter-spacing: 0.04em;
  white-space: nowrap;
  color: var(--ink);
  opacity: 0.07;
}

/* ---------- 顶部角标 ---------- */
.corner {
  position: absolute;
  top: 40px;
  font-size: 10px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-muted);
  line-height: 1.7;
  z-index: 30;
}
.corner-left { left: 48px; }
.corner-right { right: 48px; text-align: right; }
.corner .line2 { opacity: 0.75; }
.corner-link {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--ink-muted);
  padding-bottom: 1px;
  transition: opacity 0.3s ease, color 0.7s ease, border-color 0.7s ease;
}
.corner-link:hover { opacity: 0.6; }

.corner, .title, .eyebrow, .side-label,
.counter #curIdx, .counter #totalIdx, .footer-hint {
  transition: color 0.7s ease;
}

/* ---------- 搜索 ---------- */
.search-box {
  position: absolute;
  top: 96px;
  right: 48px;
  z-index: 40;
}
.search-box input {
  width: 176px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--ink-muted);
  padding: 6px 2px;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--ink);
  text-align: right;
  outline: none;
  border-radius: 0;
  transition: border-color 0.3s ease, color 0.7s ease;
  -webkit-appearance: none;
}
.search-box input:focus {
  border-color: var(--ink);
}
.search-box input::placeholder {
  color: var(--ink-muted);
  font-size: 9px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}
.search-box input::-webkit-search-cancel-button { -webkit-appearance: none; }
.search-feedback {
  min-height: 16px;
  margin-top: 5px;
  color: var(--ink-muted);
  font-size: 8px;
  letter-spacing: 0.08em;
  text-align: right;
  white-space: nowrap;
}

/* ---------- 标题 ---------- */
.header {
  text-align: center;
  /* 大字标题与下方筛选小字之间的协调段落间距（版式主节奏） */
  margin-bottom: clamp(32px, 5vh, 60px);
}

.eyebrow {
  font-size: 10px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 16px;
}

.title {
  font-family: "Playfair Display", "Noto Serif SC", serif;
  font-size: clamp(44px, 7vw, 112px);
  font-weight: 400;
  line-height: 0.95;
  letter-spacing: 0.06em;
  color: var(--ink);
}

/* ---------- 版头留白带：标题+筛选+说明同一纵向流，统一节奏、互不重叠 ---------- */
.masthead {
  position: absolute;
  top: 12vh;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 40;
  pointer-events: none;
}
.masthead .header { pointer-events: none; }
.masthead .cats { pointer-events: auto; }

/* ---------- 种类分类筛选 ---------- */
.cats {
  width: 100%;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 24px;
  padding: 0 10vw;
}
.chip {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--ink-muted);
  padding: 4px 1px 6px;
  transition: color 0.3s ease;
}
.chip sup {
  font-family: "Playfair Display", serif;
  font-size: 8px;
  margin-left: 4px;
  opacity: 0.7;
}
.chip::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--ink);
  transform: scaleX(0);
  transition: transform 0.3s ease;
}
.chip:hover { color: var(--ink); }
.chip.active { color: var(--ink); }
.chip.active::after { transform: scaleX(1); }

/* ---------- 图书说明（留白带内，紧随筛选行之下，纯文字无卡片，不遮挡书籍） ---------- */
.book-info {
  width: min(720px, 86vw);
  margin-top: 10px;
  text-align: center;
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.5s ease, transform 0.55s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}
.book-info.active {
  opacity: 1;
  transform: translateY(0);
}
.bi-tag {
  font-size: 9px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin-bottom: 8px;
}
.bi-title {
  font-family: "Noto Serif SC", "Playfair Display", serif;
  font-size: clamp(19px, 2.2vw, 26px);
  font-weight: 600;
  line-height: 1.3;
  color: var(--ink);
}
.bi-sub {
  font-family: "Playfair Display", serif;
  font-style: italic;
  font-size: 13px;
  color: var(--ink-muted);
  margin: 3px 0 9px;
}
.bi-meta {
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  margin-bottom: 9px;
}
.bi-desc {
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink);
  opacity: 0.78;
  max-width: 620px;
  margin: 0 auto;
  display: -webkit-box;
  -webkit-line-clamp: 3; /* 描述扩充后放宽到三行 */
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- 侧边索引 ---------- */
.side {
  position: absolute;
  right: 44px;
  top: 50%;
  transform: translateY(-58%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  z-index: 30;
  pointer-events: none;
}

.side-label {
  writing-mode: vertical-rl;
  font-size: 10px;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.counter {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: "Playfair Display", serif;
  line-height: 1;
}
.counter #curIdx {
  font-size: 44px;
  font-weight: 500;
  color: var(--ink);
}
.counter-slash {
  width: 26px;
  height: 1px;
  background: var(--ink-muted);
  transform: rotate(-56deg);
  margin: 7px 0 5px;
}
.counter #totalIdx {
  font-size: 16px;
  color: var(--ink-muted);
  align-self: flex-end;
}

/* ---------- 书架场景 ---------- */
.shelf-scene {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 62vh;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
  cursor: grab;
  z-index: 5;
  touch-action: none;  /* 触屏上由我们接管拖拽，防浏览器手势中断 pointer 事件 */
}
.shelf-scene.dragging { cursor: grabbing; }

.shelf-track {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 0 8vw 9vh;
  will-change: transform;
}

/* ---------- 单本书 ---------- */
.book-wrap {
  position: relative;
  flex-shrink: 0;
  width: var(--spine-w, 44px);
  height: var(--book-h, 240px);
  transform: rotateZ(var(--tilt, 0deg));
  contain: layout style;
  transition: transform 0.46s cubic-bezier(0.2, 0.72, 0.25, 1);
  cursor: pointer;
}

/* 一次性腾出封面宽度；margin 不参与 transition，避免覆盖相邻书脊与逐帧重排 */
.book-wrap.open {
  z-index: 60;
  transform: rotateZ(0deg);
  margin-right: calc(var(--cover-w, 160px) - var(--spine-w, 44px) + 22px);
}

.book {
  position: relative;
  width: 100%;
  height: 100%;
  /* 每本书独立透视：消除视口边缘书籍透视过强导致的封面提前露出 / 挤压穿帮 */
  perspective: 1300px;
  perspective-origin: 20% 50%;
}

/* 书脊 */
.spine {
  position: absolute;
  inset: 0;
  background: var(--book-color, #46608a);
  border-radius: 5px 3px 3px 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow:
    inset -2px 0 6px rgba(0, 0, 0, 0.14),
    inset 2px 0 4px rgba(255, 255, 255, 0.16),
    3px 6px 16px rgba(0, 0, 0, 0.13);
  z-index: 2;
}

.spine::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.2), transparent 38%, rgba(0, 0, 0, 0.1));
  pointer-events: none;
}

.spine-text {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: var(--spine-fs, 12px);   /* 由 app.js 按书名长度自适应，不再裁切 */
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--spine-ink, rgba(255, 255, 255, 0.96));
  padding: 14px 0 24px;
  max-height: 100%;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.16);
}

.spine-dot {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  background: var(--spine-ink, rgba(255, 255, 255, 0.5));
  opacity: 0.55;
  border-radius: 50%;
}

/* 书页厚度（翻开时露出） */
.pages {
  position: absolute;
  left: 0;
  top: 3px;
  bottom: 3px;
  width: var(--cover-w, 160px);
  background: linear-gradient(180deg, #fdfbf7 0%, #f0ebe2 55%, #e6dfd2 100%);
  transform-origin: left center;
  transform: rotateY(-92deg) translateZ(-2px);
  transition: transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.05);
  backface-visibility: hidden;
  z-index: 1;
}

/* 封面（从书脊左缘翻开） */
.cover {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cover-w, 160px);
  height: 100%;
  transform-origin: left center;
  transform: rotateY(-92deg);
  transition: transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  border-radius: 3px 5px 5px 3px;
  overflow: hidden;
  backface-visibility: hidden;
  background: var(--book-color, #46608a);
  box-shadow:
    10px 14px 34px rgba(0, 0, 0, 0.2),
    0 0 0 1px rgba(0, 0, 0, 0.04);
  z-index: 3;
}

.book-wrap.open .cover { transform: rotateY(-6deg); }  /* 留 6° 微开，更有精装书立体感 */
.book-wrap.open .pages { transform: rotateY(0deg) translateZ(-2px); }
.book-wrap.preparing,
.book-wrap.open,
.book-wrap.preparing .cover,
.book-wrap.open .cover,
.book-wrap.preparing .pages,
.book-wrap.open .pages { will-change: transform; }

/* 封面质感：铰链折痕 + 四缘受光 + 斜向光泽 */
.cover::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    /* 靠书脊一侧的精装铰链折痕 */
    linear-gradient(90deg,
      rgba(0, 0, 0, 0.30) 0%,
      rgba(0, 0, 0, 0.14) 1.8%,
      rgba(255, 255, 255, 0.16) 3.6%,
      rgba(0, 0, 0, 0.12) 5.6%,
      rgba(255, 255, 255, 0.05) 7.4%,
      transparent 10%),
    /* 右缘、上下缘受光 */
    linear-gradient(270deg, rgba(0, 0, 0, 0.16) 0%, transparent 4%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.12) 0%, transparent 4%, transparent 95%, rgba(0, 0, 0, 0.14) 100%);
}
.cover::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.09) 48%, transparent 57%);
}

/* 设计款封面（旧版质感：渐变底 + 标签 + 竖排书名 + 作者页脚 + 色带），真实封面叠加其上 */
.cover-design {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 14px 14px 12px 20px;
  background: linear-gradient(155deg, var(--cover-a, #46608a) 0%, var(--cover-b, #7a8fb4) 100%);
  color: var(--cover-ink, #fff);
}
.cover-design::after {
  /* 纸张肌理高光 */
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.14), transparent 42%),
    linear-gradient(300deg, rgba(0, 0, 0, 0.08), transparent 46%);
  pointer-events: none;
}
.cover-design .cover-tag {
  font-family: "Playfair Display", serif;
  font-style: italic;
  font-size: 9px;
  letter-spacing: 0.08em;
  opacity: 0.85;
}
.cover-design .cover-title {
  font-family: "Noto Serif SC", serif;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.45;
  letter-spacing: 0.06em;
}
.cover-design .cover-title.vertical {
  writing-mode: vertical-rl;
  align-self: center;
  letter-spacing: 0.3em;
}
.cover-design .cover-footer {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 8.5px;
  letter-spacing: 0.06em;
  opacity: 0.85;
}
.cover-design .cover-band {
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--cover-accent, #c8a24b);
  opacity: 0.9;
}

.cover img {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* 真实封面就位后：封面比例已随原图重塑，底层设计款隐藏避免透色/多余绘制 */
.book-wrap.real-cover .cover-design { visibility: hidden; }

/* 地面阴影 */
.book-shadow {
  position: absolute;
  bottom: -26px;
  left: -15%;
  width: 130%;
  height: 16px;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.18) 0%, transparent 70%);
  filter: blur(5px);
  pointer-events: none;
  z-index: -1;
}

/* 被筛选掉的书 */
.book-wrap.hidden { display: none; }

/* 无匹配结果提示 */
.empty-hint {
  position: absolute;
  left: 50%;
  bottom: 22vh;
  transform: translateX(-50%);
  font-size: 11px;
  letter-spacing: 0.3em;
  color: var(--ink-muted);
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}
.empty-hint.show { opacity: 1; }

/* ---------- 底部提示 ---------- */
.footer-hint {
  position: absolute;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-muted);
  animation: pulse 2.8s infinite;
  z-index: 20;
  pointer-events: none;
}
@keyframes pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.8; }
}
.footer-hint .hint-mobile { display: none; }
@media (hover: none) and (pointer: coarse) {
  /* 触屏设备：提示改为点按 */
  .footer-hint .hint-desktop { display: none; }
  .footer-hint .hint-mobile { display: inline; }
}

/* ---------- 响应式 ---------- */
@media (max-width: 768px) {
  :root { --shelf-scale: 0.68; }
  .corner { top: 16px; font-size: 8px; }
  .corner-left { left: 16px; }
  .corner-right { right: 16px; }
  .search-box { top: 62px; right: 16px; }
  .search-box input { width: 124px; font-size: 12px; }  /* ≥12px 防 iOS 聚焦自动缩放 */
  .search-feedback { max-width: 180px; margin-left: auto; font-size: 8px; }
  .bg-word { top: 10vh; bottom: 40vh; }
  .bg-word span { font-size: clamp(88px, 22vh, 210px); }
  .masthead { top: max(10vh, 92px); }
  .title { font-size: clamp(34px, 11vw, 72px); }
  .eyebrow { margin-bottom: 10px; letter-spacing: 0.26em; }
  .header { margin-bottom: clamp(16px, 2.6vh, 28px); }
  .cats {
    justify-content: flex-start;
    flex-wrap: nowrap;
    gap: 4px 18px;
    padding: 0 18px 6px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }
  .cats::-webkit-scrollbar { display: none; }
  .chip {
    flex: 0 0 auto;
    min-height: 40px;
    scroll-snap-align: start;
    font-size: 10px;
    letter-spacing: 0.08em;
    padding: 8px 1px 7px;
  }
  .book-info { width: 92vw; margin-top: 3px; }
  .bi-title { font-size: 17px; }
  .bi-sub { font-size: 11px; margin: 2px 0 6px; }
  .bi-meta { font-size: 10px; margin-bottom: 6px; }
  .bi-desc { -webkit-line-clamp: 3; font-size: 11.5px; line-height: 1.65; }
  .side { display: none; }
  .shelf-scene { height: 54vh; }
  .shelf-track { gap: 7px; padding: 0 7vw 7vh; }
  .spine-text {
    /* 随书高同比例缩字，长书名仍完整不裁切 */
    font-size: max(8px, calc(var(--spine-fs, 12px) * 0.82));
    padding: 10px 0 16px;
  }
  .spine-dot { bottom: 10px; }
  .book-wrap.open { margin-right: calc(var(--cover-w, 118px) - var(--spine-w, 34px) + 12px); }
  .cover-design { padding: 10px 10px 8px 14px; }
  .cover-design .cover-title { font-size: 13px; }
  .book-shadow { bottom: -18px; height: 12px; }
  .footer-hint { bottom: 14px; width: max-content; max-width: 88vw; font-size: 8px; letter-spacing: 0.16em; }
  .footer-hint .hint-desktop { display: none; }
  .footer-hint .hint-mobile { display: inline; }
}

@media (max-width: 480px) {
  .corner-left .line2 { display: none; }
  .corner-right { max-width: 132px; }
  .search-box { top: 54px; }
  .masthead { top: 94px; }
  .title { font-size: clamp(32px, 10.8vw, 46px); }
  .header { margin-bottom: 12px; }
  .book-info { margin-top: 0; }
  .bi-tag { font-size: 8px; margin-bottom: 5px; }
  .bi-title { font-size: 16px; }
  .bi-desc { -webkit-line-clamp: 2; font-size: 11px; }
  .shelf-scene { height: 51vh; }
}

/* ---------- 桌面端矮视口：压缩说明区节奏，避免文字遮挡下方书架 ---------- */
@media (min-width: 769px) and (max-height: 920px) {
  :root { --shelf-scale: 0.94; }
  .masthead { top: 9vh; }
  .header { margin-bottom: clamp(24px, 3.2vh, 42px); }
  .book-info { margin-top: 5px; }
  .bi-title { font-size: clamp(18px, 2vw, 22px); }
  .bi-sub { margin: 2px 0 7px; }
  .bi-meta { margin-bottom: 7px; }
  .bi-desc { -webkit-line-clamp: 2; line-height: 1.6; }  /* 矮窗口描述收为两行 */
}
@media (min-width: 769px) and (max-height: 760px) {
  :root { --shelf-scale: 0.84; }
  .bg-word span { font-size: clamp(120px, 28vh, 280px); }
  .masthead { top: 7.5vh; }
  .bi-desc { font-size: 12px; }
}
