@font-face {
  font-family: "迫真打字油印体";
  src: url("../assets/fonts/real-typewriter.woff2") format("woff2");
  /* 单字重文件（Light），声明全字重区间避免浏览器假粗 */
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #2a2620;
  --cloth-ink: #241f18;
  --brown: #4a3a33;
  --brown-2: #5a463c;
  --paper: #f6efe3;
  --paper-2: #efe6d5;
  --line: #d8c9b0;
  --head: #eadfca;
  --muted: #6b5847;
  --cream: #f3ead9;
  --font-serif: "迫真打字油印体", "Songti SC", "STSong", "SimSun", serif;
  --font-display: "迫真打字油印体", "Songti SC", "STSong", serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font-serif);
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
  background: linear-gradient(180deg, #e9dcc2, #ddc9a4);
  -webkit-font-smoothing: antialiased;
}

/* ─── 长卷背景（滚轮横展） ─── */
.bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
}

#bgImg {
  position: absolute;
  top: 50%;
  left: 0;
  height: 100vh;
  height: 100dvh;
  width: auto;
  transform: translate3d(0, -50%, 0);
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
  /* 默认轻透：隐约可见背景长卷；「展画卷」模式下恢复全幅 */
  opacity: 0.2;
  transition: opacity 0.9s ease;
}

body[data-mode="painting"] #bgImg {
  opacity: 1;
}

/* fixed 锁死舞台：任何情况下文档都不可纵向滚动
   （手机浏览器缩放/内核差异下 100dvh 失效也不会露出滚动条） */
.stage {
  position: fixed;
  inset: 0;
  z-index: 1;
}

/* ─── 顶栏 ─── */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 18px 28px;
  z-index: 30;
  pointer-events: none;
}

.topbar > * {
  pointer-events: auto;
}

.brand {
  font-family: var(--font-display);
  font-size: 21px;
  letter-spacing: 0.08em;
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(255, 250, 240, 0.35);
}

.brand__sub {
  display: block;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.ui-btn {
  background-color: var(--brown);
  background-image: repeating-linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.055) 0 2px,
    transparent 2px 6px
  );
  color: var(--cream);
  font-family: var(--font-serif);
  font-size: 15px;
  letter-spacing: 0.28em;
  text-indent: 0.28em;
  padding: 10px 22px;
  border: 1px solid #3a2c26;
  border-radius: 4px;
  box-shadow:
    0 8px 22px rgba(40, 28, 20, 0.35),
    inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  cursor: pointer;
}

.ui-btn:hover {
  background-color: var(--brown-2);
}

.ui-btn[aria-expanded="true"] {
  box-shadow:
    0 8px 22px rgba(40, 28, 20, 0.35),
    inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}

/* 顶栏右侧按钮组：音乐（BGM 开关）+ 音律（面板） */
.topbar__actions {
  display: flex;
  gap: 12px;
}

/* 音乐关闭态：降透明表示 BGM 已停 */
.ui-btn.is-off {
  opacity: 0.55;
}

/* ─── 场景切换钮（仿 chimes 参考站 country-btn：
   84px 手绘波浪墨线框 + 目标小图标 + 标签，hover 上移 2px）
   左右两个按钮同时常显：左=上一张、右=下一张（顺序循环，JS 按 SCENE_ORDER 更新） ─── */
.country-btn {
  position: fixed;
  /* z-index 45 高于音律面板(40)：按钮永不被遮挡、永远可见 */
  z-index: 45;
  top: 34%;
  transform: translateY(-50%);
  width: 80px;
  height: 80px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  appearance: none;
  background-color: transparent;
  background-image: url("../assets/selector-frame.svg");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 84px 84px;
  border: none;
  outline: none;
  box-shadow: none;
  border-radius: 0;
  cursor: pointer;
  color: var(--ink);
  overflow: visible;
  box-sizing: border-box;
  transition:
    transform 220ms cubic-bezier(0.42, 0, 1, 1),
    opacity 220ms ease,
    right 0.3s ease,
    filter 220ms ease;
}

/* 左右站位：左按钮=上一张（从左进场），右按钮=下一张（从右进场） */
.nav-btn--left {
  left: 28px;
}
.nav-btn--right {
  right: 28px;
}

/* 音律面板展开时（右侧高 732px），右侧按钮让位到面板左边，避免压在面板上 */
body.panel-open .nav-btn--right {
  right: 356px;
}

.country-btn:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 4px;
}

.country-btn:hover {
  transform: translateY(calc(-50% - 2px));
}

.country-btn:active {
  transform: translateY(-50%);
}

/* 不可点击时置灰（切换动画进行中）：保持可见，只降饱和 + 轻降透明 */
.country-btn:disabled {
  opacity: 0.55;
  filter: grayscale(1);
  cursor: default;
  transform: translateY(-50%);
}

.country-btn__icon {
  position: relative;
  display: block;
  width: 76px;
  height: 24px;
  overflow: hidden;
  flex-shrink: 0;
}

.country-btn__icon img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.country-btn__label {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 15px;
  line-height: 0.98;
  letter-spacing: 0.1em;
  color: var(--ink);
  white-space: nowrap;
}

/* ─── 场景：虹桥 + 诗帘 ─── */
.area {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  /* 桥/船 + 诗帘整体下移：给桅杆与顶栏留出空间，远离底部文案；
     --pad-extra 由 JS 计算：垂直富余空间的一部分补到上方（高视口居中） */
  padding-top: calc(13vh + var(--pad-extra, 0px));
}

.scene {
  position: relative;
  width: 720px;
  /* 窄屏下保持 720px 布局宽（仅靠 --s 缩放），
     防止 flex 收缩到 680px 导致桥/船/诗帘坐标错位 */
  flex: 0 0 720px;
  transform: scale(var(--s, 1));
  transform-origin: top center;
}

/* A/B 双缓冲图层：切换时旧层滑出与新层滑入同时走（走到一半即可看到新图） */
.slide {
  position: absolute;
  inset: 0;
  will-change: transform;
}

/* 场景后的径向暗晕：把桥与诗帘从流动的画卷背景里托出来 */
.scene::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 350px;
  width: 1180px;
  height: 820px;
  transform: translate(-50%, -50%);
  background: radial-gradient(
    ellipse at center,
    rgba(40, 28, 16, 0.14) 0%,
    rgba(40, 28, 16, 0.07) 42%,
    transparent 72%
  );
  z-index: -1;
  pointer-events: none;
}

.bridge {
  position: relative;
  z-index: 3;
  width: 680px;
  height: 211px;
  margin: 0 auto;
}

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

.bridge img[hidden] {
  display: none;
}

/* 帆船：与桥底对齐（共用 211px 基线）。
   fanchuan-web.png 内容底（水线）≈ 图高 95%，桥图内容底 ≈ 96%；
   宽 600px → 图高 ≈346px，底缘外扩 9px，使船水线与桥水线同高，
   桅杆高出场景顶约 78px（顶栏之下仍有空间） */
.bridge .bridge__boat {
  position: absolute;
  left: 50%;
  bottom: -9px;
  transform: translateX(-50%);
  width: 600px;
  height: auto;
}

/* 城楼：与桥底对齐（共用 211px 基线）。
   chenglou-web.png 内容底（石基底）≈ 图高 89.1%、内容顶（宝顶）≈ 图高 5.2%；
   宽 470px → 图高 352px，底缘外扩 30px，使石基底与水线同高（≈202.5px），
   宝顶距视口顶约 24px（900px 屏，完整可见） */
.bridge .bridge__tower {
  position: absolute;
  left: 50%;
  bottom: -30px;
  transform: translateX(-50%);
  width: 470px;
  height: auto;
}

/* 人物：脚底与水线对齐（共用 211px 基线）。
   renwu-web.png 为用户抠图裁剪的纯人物条（1175×267），脚底 ≈ 图高 98.1%；
   宽 720px → 图高 164px，底缘内收 5px，脚底与水线同高（≈202.5px） */
.bridge .bridge__person {
  position: absolute;
  left: 50%;
  bottom: 5px;
  transform: translateX(-50%);
  width: 720px;
  height: auto;
}

/* 近侧栏杆前层：与 .bridge 完全重合，z-index 5 高于诗帘画布(2) */
.bridge-front {
  position: absolute;
  z-index: 5;
  top: 0;
  left: 50%;
  width: 680px;
  height: 211px;
  transform: translateX(-50%);
  pointer-events: none;
}

.bridge-front img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.bridge-shadow {
  position: absolute;
  z-index: 1;
  left: 50%;
  top: 178px;
  width: 560px;
  height: 64px;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at center, rgba(48, 31, 15, 0.3), transparent 70%);
  pointer-events: none;
  transition: opacity 0.45s ease;
}

/* 与 main.js 常量对齐：strings 顶 = BRIDGE_H(211) + CLOTH_GAP(-14) = 197px；
   画布含 PAD(300) 四周留白。诗帘顶行钉在 197+7=204px，
   被桥图水面（0–211px）盖住一点点，图在字上层 */
.strings {
  position: absolute;
  left: 0;
  top: 197px;
  width: 720px;
  height: 0;
  z-index: 2;
}

.strings canvas {
  position: absolute;
  left: -300px;
  top: -300px;
  display: block;
}

/* ─── 底部文案 ─── */
.bottom-copy {
  position: fixed;
  left: 5vw;
  right: 5vw;
  bottom: 52px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  z-index: 20;
  pointer-events: none;
}

.bottom-copy > * {
  pointer-events: auto;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 0.12em;
  color: #4a4036;
}

.eyebrow strong {
  font-size: 14px;
  font-weight: 900;
}

.title {
  margin: 0;
  max-width: 12em;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(30px, 4.6vw, 52px);
  line-height: 1.28;
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(255, 250, 240, 0.3);
}

.aside-block {
  text-align: right;
  flex-shrink: 0;
}

.aside {
  margin: 0 0 14px;
  max-width: 240px;
  margin-left: auto;
  /* 右缘与「关于」/ .view-btn（right: 20px）对齐 */
  margin-right: calc(20px - 5vw);
  font-size: 12.5px;
  line-height: 1.9;
  color: #453b31;
}

.about-btn {
  font-family: var(--font-serif);
  font-size: 13px;
  letter-spacing: 0.2em;
  color: var(--ink);
  background: none;
  border: 0;
  border-bottom: 1px solid #6b5847;
  padding: 2px 1px 3px;
  /* 上移并右移：右缘与 .view-btn（right: 20px）对齐，避开「展画卷」按钮
     （右对齐行内元素需负 margin-right 才能向视口边缘方向偏移） */
  margin-right: calc(20px - 5vw);
  margin-bottom: 12px;
  cursor: pointer;
}

.about-btn:hover {
  color: var(--brown);
  border-color: var(--brown);
}

/* ─── 展卷进度 ─── */
.hud {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  width: min(340px, 52vw);
  z-index: 20;
  pointer-events: none;
}

.hud__track {
  position: relative;
  height: 2px;
  background: rgba(42, 38, 32, 0.25);
}

.hud__fill {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background: var(--ink);
}

.hud__labels {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: #57493c;
}

/* ─── 控制面板（自绘，仿参考站 Tweakpane） ─── */
.panel-anchor {
  pointer-events: none;
}

.panel {
  position: fixed;
  top: 64px;
  right: 20px;
  width: 320px;
  max-height: calc(100vh - 78px);
  max-height: calc(100dvh - 78px);
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--paper), var(--paper-2));
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 16px 48px rgba(56, 40, 26, 0.35);
  overflow: hidden;
  pointer-events: auto;
}

/* 面板超屏高时内容区可滚（小屏手机必须） */
.pbody {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.panel[hidden] {
  display: none;
}

.phead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--brown);
  color: var(--cream);
  padding: 12px 16px;
}

.ptitle {
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.32em;
}

.pcollapse {
  background: none;
  border: 0;
  color: var(--cream);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 4px;
}

.pbody.is-collapsed {
  display: none;
}

.pfolder-h {
  margin: 0;
  padding: 10px 16px;
  background: var(--head);
  border-top: 1px solid var(--line);
  font-family: var(--font-serif);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.24em;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.pfolder:first-child .pfolder-h {
  border-top: 0;
}

.pfolder:not(.is-open) .prow,
.pfolder:not(.is-open) .pbtn {
  display: none;
}

.prow {
  display: grid;
  grid-template-columns: 84px 1fr 56px;
  align-items: center;
  gap: 10px;
  padding: 7px 16px;
}

.plabel {
  font-size: 12.5px;
  color: #4d4238;
}

.pval {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  text-align: right;
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 3px 6px;
  color: var(--ink);
}

.prow select {
  width: 100%;
  font-family: var(--font-serif);
  font-size: 12.5px;
  color: var(--ink);
  background: #fffdf8;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 4px 6px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  background: #cbb99c;
  border-radius: 1px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -5px;
  background: var(--brown);
  border-radius: 2px;
}

input[type="range"]::-moz-range-track {
  height: 2px;
  background: #cbb99c;
  border-radius: 1px;
}

input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 2px;
  background: var(--brown);
}

.pchk {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--brown);
  cursor: pointer;
}

.pbtn {
  display: block;
  width: calc(100% - 32px);
  margin: 6px 16px 12px;
  padding: 9px 0;
  background: var(--brown);
  color: var(--cream);
  border: 0;
  border-radius: 4px;
  font-family: var(--font-serif);
  font-size: 13.5px;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  cursor: pointer;
}

.pbtn:hover {
  background: var(--brown-2);
}

/* ─── About 弹窗 ─── */
.about {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}

.about[hidden] {
  display: none;
}

.about__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(40, 30, 20, 0.45);
  border: 0;
  cursor: default;
}

.about__panel {
  position: relative;
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 26px;
  width: min(680px, 92vw);
  max-height: 86vh;
  overflow: auto;
  background: linear-gradient(180deg, #f7f0e2, #efe4d0);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 24px 80px rgba(40, 28, 18, 0.5);
  padding: 28px;
}

.about__close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: 0;
  font-family: var(--font-serif);
  font-size: 12px;
  letter-spacing: 0.2em;
  color: var(--muted);
  cursor: pointer;
}

.about__close:hover {
  color: var(--brown);
}

.about__photo img {
  width: 100%;
  border-radius: 8px;
  display: block;
}

.about__title {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 26px;
  letter-spacing: 0.06em;
}

.about__body p {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.95;
  color: #3d342b;
}

.about__credits {
  font-size: 12px !important;
  color: var(--muted) !important;
  line-height: 1.8 !important;
}

.about__links {
  display: flex;
  gap: 18px;
  margin-top: 16px;
}

.about__links a {
  font-size: 12px;
  color: var(--brown);
  border-bottom: 1px solid var(--line);
  padding-bottom: 1px;
}

/* ─── noscript ─── */
.noscript {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 99;
  padding: 14px;
  text-align: center;
  background: var(--brown);
  color: var(--cream);
  font-size: 13px;
}

/* ─── 展画卷 / 回诗帘 模式切换 ─── */
.area,
.bottom-copy {
  transition:
    opacity 0.7s ease,
    transform 0.7s ease;
}

body[data-mode="painting"] .area {
  opacity: 0;
  transform: translateY(-28px);
  pointer-events: none;
}

body[data-mode="painting"] .bottom-copy,
body[data-mode="painting"] .hud {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

/* 展画卷状态：隐藏左上标题与左右切换钮（音律按钮保留） */
body[data-mode="painting"] .brand,
body[data-mode="painting"] .nav-btn {
  opacity: 0;
  pointer-events: none;
}
.brand {
  transition: opacity 0.5s ease;
}

/* 桥/船切换时：文案只随场景轻降透明度，位置不动 */
.bottom-copy.is-dipping {
  opacity: 0.25;
}

.view-btn {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 45;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  background-color: var(--brown);
  background-image: repeating-linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.055) 0 2px,
    transparent 2px 6px
  );
  color: var(--cream);
  font-family: var(--font-serif);
  font-size: 13px;
  letter-spacing: 0.24em;
  text-indent: 0.24em;
  padding: 9px 18px;
  border: 1px solid #3a2c26;
  border-radius: 4px;
  box-shadow:
    0 8px 22px rgba(40, 28, 20, 0.35),
    inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  cursor: pointer;
}

.view-btn:hover {
  background-color: var(--brown-2);
}

.view-btn[aria-pressed="true"] {
  background-color: #3a2c26;
}

/* ─── 移动端 ─── */
@media (max-width: 760px) {
  .topbar {
    padding: 14px 16px;
  }

  .brand__sub {
    display: none;
  }

  .area {
    padding-top: calc(10vh + var(--pad-extra, 0px));
  }

  .bottom-copy {
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
    bottom: 84px;
  }

  .aside-block {
    text-align: left;
  }

  .aside {
    margin-left: 0;
    margin-right: 0;
  }

  .about-btn {
    margin-right: 0;
    margin-bottom: 0;
  }

  .panel {
    right: 12px;
    top: 58px;
    width: min(320px, calc(100vw - 24px));
  }

  /* 窄屏下面板近全宽，右按钮不再让位，直接浮在面板之上（z-index 已高于面板） */
  body.panel-open .nav-btn--right {
    right: 28px;
  }

  .about__panel {
    grid-template-columns: 1fr;
  }

  .about__photo {
    max-width: 260px;
  }

  /* 手机：切换钮缩小一号，纸色底 + 投影（top 由 JS 定位到桥面上） */
  .nav-btn {
    width: 68px;
    height: 68px;
    background-image:
      linear-gradient(rgba(246, 239, 227, 0.94), rgba(243, 234, 217, 0.94)),
      url("../assets/selector-frame.svg");
    background-size:
      52px 52px,
      72px 72px;
    background-position: center, center;
    box-shadow: 0 4px 14px rgba(58, 44, 38, 0.32);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  .nav-btn .country-btn__icon {
    width: 56px;
    height: 18px;
  }

  /* 手机：底部进度条收窄，避免与右下「展画卷」按钮重叠 */
  .hud {
    width: 40vw;
    min-width: 118px;
  }

  .view-btn {
    padding: 8px 14px;
  }

  .topbar {
    user-select: none;
    -webkit-user-select: none;
  }
}

/* 手机横屏 / 短视口：文案与场景抢高度——压缩底部文案，收起旁注 */
@media (max-height: 480px) and (orientation: landscape) {
  .topbar {
    padding: 10px 20px;
  }

  .area {
    padding-top: calc(5vh + var(--pad-extra, 0px));
  }

  .bottom-copy {
    left: 4vw;
    right: 4vw;
    bottom: 10px;
    gap: 12px;
  }

  .eyebrow {
    display: none;
  }

  /* 标题压成一行，给场景腾高度 */
  .title {
    font-size: clamp(18px, 6vh, 26px);
    max-width: 20em;
    line-height: 1.2;
  }

  .aside {
    display: none;
  }

  .hud {
    bottom: 12px;
  }

  .view-btn {
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
}
