:root {
  --bg: #2b2f33;
  --bg-deep: #1f2327;
  --panel: #353a40;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f2f2f2;
  --muted: #b7bdc5;
  --accent: #d4b36a;
  --desk: #c4a574;
  --desk-dark: #9a7a4d;
  --shadow: 0 28px 60px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #7a1f24;
  background-image: url("./assets/bg-red.jpg?v=20261114e");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

.app {
  position: relative;
  width: 100%;
  height: 100%;
  display: block;
  overflow: hidden;
  background: transparent;
}

/* 默认无外框：顶栏/底栏浮层，封面时隐藏 */
.app.chrome-hidden .topbar,
.app.chrome-hidden .toolbar,
.app.chrome-hidden .side-nav {
  opacity: 0 !important;
  pointer-events: none !important;
  visibility: hidden !important;
}

/* H5 ?????????????? */
.bgm-btn {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  z-index: 40;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: #f6e6c8;
  background: rgba(40, 8, 12, 0.45);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(6px);
  -webkit-tap-highlight-color: transparent;
}

.bgm-btn .bgm-icon {
  font-size: 16px;
  line-height: 1;
  display: inline-block;
  transform-origin: 50% 50%;
}

.bgm-btn.is-on .bgm-icon {
  animation: bgm-spin 3.6s linear infinite;
}

.bgm-btn.is-off {
  opacity: 0.72;
}

.bgm-btn.is-off .bgm-icon {
  animation: none;
  position: relative;
}

.bgm-btn.is-off .bgm-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 1.5px;
  background: #f6e6c8;
  transform: translate(-50%, -50%) rotate(-35deg);
  border-radius: 1px;
}

@keyframes bgm-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.scene {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  background-color: #7a1f24;
  background-image: url("./assets/bg-red.jpg?v=20261114e");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.scene-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transform: scale(1.02);
  opacity: 1;
  filter: none;
}

.scene-veil {
  position: absolute;
  inset: 0;
  background: transparent;
}

.topbar,
.toolbar {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 44px;
  padding: 0.35rem 0.85rem;
  background: rgba(40, 8, 12, 0.55);
  border-color: rgba(255, 220, 160, 0.1);
  backdrop-filter: blur(10px);
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.topbar {
  top: 0;
  border-bottom: 1px solid var(--line);
}

.toolbar {
  bottom: 0;
  border-top: 1px solid var(--line);
  justify-content: center;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.brand-en {
  color: var(--accent);
  font-size: 0.68rem;
  letter-spacing: 0.24em;
}

.brand strong {
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-size: clamp(0.92rem, 1.8vw, 1.12rem);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.15rem 0.35rem 0.15rem 0.75rem;
}

.search input {
  width: min(220px, 34vw);
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.icon-btn,
.tool,
.side-nav,
.gate-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.stage {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  /* ????????????????????????? */
  grid-template-columns: 1fr;
  align-items: center;
  gap: 0;
  min-height: 0;
  padding: 0;
  background: transparent;
}

.viewport {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: transparent;
}

.zoom-layer {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  transform-origin: center center;
  transition: transform 0.18s ease;
  cursor: default;
}

.zoom-layer.panning {
  cursor: grab;
}

.zoom-layer.dragging {
  cursor: grabbing;
  transition: none;
}

.book-shell {
  position: relative;
  /* 单页：宽高由 JS 按竖版比例尽量撑满舞台 */
  width: 420px;
  height: 590px;
  filter: drop-shadow(0 18px 36px rgba(0, 0, 0, 0.5));
  background: transparent;
}

.book {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
}

.book-shell.is-cover .book {
  visibility: hidden;
  pointer-events: none;
}

.page-sheet {
  width: 100%;
  height: 100%;
  background: #fff;
  overflow: hidden;
}

.page-sheet img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.closed-cover {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: block;
  background: #fff;
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.45),
    8px 0 18px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  overflow: hidden;
}

.closed-cover[hidden] {
  display: none !important;
}

.closed-cover img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  object-position: center;
  display: block;
  background: #fff;
  user-select: none;
  -webkit-user-drag: none;
}

.closed-spine {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 10px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.45), rgba(255, 255, 255, 0.08) 45%, rgba(0, 0, 0, 0.2));
  pointer-events: none;
}

.closed-edge {
  position: absolute;
  right: -11px;
  top: 2%;
  bottom: 2%;
  width: 12px;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(90deg, #1a1a1a, #6a6a6a 40%, #222);
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

/* 双开中间：书脊阴影 + 轻微开页弧度感（参考云展网） */
.book-gutter {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 86px;
  transform: translateX(-50%);
  z-index: 6;
  pointer-events: none;
  background:
    linear-gradient(
      90deg,
      transparent 0%,
      rgba(0, 0, 0, 0.015) 18%,
      rgba(0, 0, 0, 0.06) 34%,
      rgba(0, 0, 0, 0.16) 46%,
      rgba(0, 0, 0, 0.38) 50%,
      rgba(0, 0, 0, 0.15) 54%,
      rgba(0, 0, 0, 0.05) 66%,
      rgba(0, 0, 0, 0.012) 82%,
      transparent 100%
    );
}

.book-gutter::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(
      90deg,
      transparent 0%,
      rgba(255, 255, 255, 0.1) 40%,
      rgba(255, 255, 255, 0.18) 46%,
      transparent 49.5%,
      transparent 50.5%,
      rgba(0, 0, 0, 0.12) 55%,
      rgba(0, 0, 0, 0.04) 64%,
      transparent 100%
    );
}

.book-gutter::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  transform: translateX(-50%);
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.08),
    rgba(0, 0, 0, 0.28) 18%,
    rgba(0, 0, 0, 0.34) 50%,
    rgba(0, 0, 0, 0.26) 82%,
    rgba(0, 0, 0, 0.08)
  );
  opacity: 0.85;
}

.book-gutter[hidden] {
  display: none !important;
}

.book-shell.is-cover .book-gutter {
  display: none !important;
}

/* 左右书边：错落书页厚度 */
.page-stack {
  position: absolute;
  top: 1px;
  bottom: 1px;
  z-index: 4;
  pointer-events: none;
  overflow: hidden;
  background-image: repeating-linear-gradient(
    90deg,
    #fbfaf7 0 1px,
    #e8e2d6 1px 2px,
    #f4f0e8 2px 3px,
    #d8d0c2 3px 4px
  );
  background-size: 4px 100%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
  transition: width 0.28s ease;
}

.page-stack.left {
  left: 0;
  transform: translateX(-100%);
  border-radius: 2px 0 0 2px;
  box-shadow:
    -2px 0 6px rgba(0, 0, 0, 0.18),
    inset -2px 0 4px rgba(0, 0, 0, 0.08);
}

.page-stack.right {
  right: 0;
  transform: translateX(100%);
  border-radius: 0 2px 2px 0;
  box-shadow:
    2px 0 6px rgba(0, 0, 0, 0.18),
    inset 2px 0 4px rgba(0, 0, 0, 0.08);
}

.page-stack::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.35),
    transparent 18%,
    transparent 82%,
    rgba(0, 0, 0, 0.12)
  );
  pointer-events: none;
}

.page-stack[hidden] {
  display: none !important;
}

/* 单页模式：右侧书口白边厚度（截图效果） */
.book-shell.single-page {
  overflow: visible;
}

.book-shell.single-page::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 10px;
  z-index: 5;
  pointer-events: none;
  background: linear-gradient(
    90deg,
    rgba(0, 0, 0, 0.35),
    rgba(0, 0, 0, 0.08) 55%,
    transparent
  );
}

.book-shell.single-page .page-stack.left {
  left: 0;
  transform: translateX(-92%);
  background-image: linear-gradient(
    90deg,
    #2a2a2a,
    #555 40%,
    #1f1f1f
  );
  box-shadow: -1px 0 4px rgba(0, 0, 0, 0.25);
}

.book-shell.single-page .page-stack.right {
  right: -1px;
  top: 0;
  bottom: 0;
  transform: none;
  border-radius: 0 3px 3px 0;
  background-color: #f7f4ef;
  background-image: repeating-linear-gradient(
    90deg,
    #ffffff 0 1px,
    #ece7de 1px 2px,
    #f8f5ef 2px 3px,
    #ddd5c8 3px 4px
  );
  background-size: 4px 100%;
  box-shadow:
    3px 2px 10px rgba(0, 0, 0, 0.28),
    inset 1px 0 0 rgba(255, 255, 255, 0.7),
    inset -1px 0 0 rgba(0, 0, 0, 0.06);
}

.book-shell.is-cover .page-stack.left {
  display: none !important;
}

.book-shell.is-cover .page-stack.right {
  right: -1px;
  transform: none;
  border-radius: 0 2px 2px 0;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 3;
  background: transparent;
}

.placeholder.hidden {
  display: none;
}

.placeholder-card,
.gate-card {
  width: min(420px, 88vw);
  padding: 2rem 1.4rem;
  text-align: center;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.placeholder-card {
  color: #fff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

.placeholder-card h1,
.gate-card h1 {
  margin: 0.85rem 0 0.7rem;
  font-family: "Songti SC", "STSong", "SimSun", serif;
  font-size: clamp(1.15rem, 3vw, 1.55rem);
  font-weight: 700;
  line-height: 1.35;
}

.placeholder-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.book-icon {
  width: 54px;
  height: 42px;
  margin: 0 auto;
  border: 2px solid #fff;
  border-radius: 4px;
  position: relative;
}

.book-icon::before,
.book-icon::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  height: 2px;
  background: #fff;
}

.book-icon::before {
  top: 12px;
}

.book-icon::after {
  top: 20px;
  width: 55%;
}

.book-icon.large {
  width: 68px;
  height: 52px;
}

.side-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 6;
  width: 48px;
  height: 72px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
  color: rgba(255, 255, 255, 0.85);
  font-size: 2rem;
  line-height: 1;
  transition: opacity 0.28s ease;
}

.side-nav.left {
  left: max(4px, env(safe-area-inset-left));
}

.side-nav.right {
  right: max(4px, env(safe-area-inset-right));
}

.side-nav:hover {
  background: rgba(0, 0, 0, 0.42);
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

.tool {
  min-width: 36px;
  height: 36px;
  padding: 0 0.45rem;
  border-radius: 6px;
  color: #dfe3e8;
}

.tool:hover,
.tool.active {
  background: rgba(255, 255, 255, 0.08);
}

.tool:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.page-box input {
  width: 78px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #2a2e33;
  color: var(--text);
  text-align: center;
}

.thumbs {
  position: absolute;
  left: 0;
  top: 52px;
  bottom: 56px;
  width: min(320px, 86vw);
  background: rgba(28, 31, 35, 0.96);
  border-right: 1px solid var(--line);
  transform: translateX(-105%);
  transition: transform 0.24s ease;
  z-index: 8;
  display: flex;
  flex-direction: column;
}

.thumbs.open {
  transform: translateX(0);
}

.thumbs-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--line);
}

.thumbs-grid {
  overflow: auto;
  padding: 0.75rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.thumb {
  appearance: none;
  border: 1px solid transparent;
  background: #111;
  padding: 0;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.thumb img {
  display: block;
  width: 100%;
  height: 120px;
  object-fit: cover;
  object-position: top center;
}

.thumb span {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 0.2rem;
  background: rgba(0, 0, 0, 0.55);
  font-size: 0.75rem;
  text-align: center;
}

.thumb.active,
.thumb:hover {
  border-color: var(--accent);
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 76px;
  transform: translateX(-50%);
  z-index: 20;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font-size: 0.86rem;
}

.gate {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background-color: rgba(40, 8, 10, 0.55);
  background-image: url("./assets/bg-red.jpg?v=20261114e");
  background-size: cover;
  background-position: center;
}

.gate.hidden {
  display: none;
}

.gate-btn {
  margin-top: 1.2rem;
  min-width: 168px;
  padding: 0.7rem 1.2rem;
  border-radius: 8px;
  background: #1f2327;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
}

.gate-btn:hover {
  background: #171a1d;
}

@media (max-width: 860px) {
  .brand strong {
    max-width: 42vw;
  }

  .plant {
    display: none;
  }

  .side-nav {
    width: 36px;
    height: 56px;
    font-size: 1.5rem;
  }

  .toolbar {
    gap: 0.45rem;
    padding-bottom: 0.55rem;
  }
}
