@import url('./f/fonts.css');

:root {
  --paper: #F4EFE6;
  --paper-warm: #FAF6EE;
  --ink: #1C1916;
  --ink-soft: rgba(28, 25, 22, 0.64);
  --verm: #B3261E;
  --lijiang: #2D615B;
  --lantern: #E58A3A;
  --gold: #C98E26;

  --accent: var(--lijiang);
  --ui-bg: rgba(247, 242, 233, 0.84);
  --ui-bg-strong: rgba(251, 248, 241, 0.96);
  --ui-fg: #1C1916;
  --ui-muted: rgba(28, 25, 22, 0.58);
  --ui-border: rgba(28, 25, 22, 0.12);
  --ui-shadow: 0 10px 28px rgba(42, 30, 16, 0.12);

  --font-title: 'ZMX', 'Songti SC', 'Noto Serif CJK SC', 'STSong', KaiTi, serif;
  --font-ui: 'MSZ', 'Songti SC', 'Noto Serif CJK SC', 'PingFang SC', serif;
  --font-body: 'Songti SC', 'Noto Serif CJK SC', 'STSong', 'PingFang SC', serif;
}

/* Six-Realm Palette Accents */
body[data-segment="lijiang"] { --accent: #2D615B; }
body[data-segment="daxu"] { --accent: #A93024; }
body[data-segment="villages"] { --accent: #5C6B57; }
body[data-segment="waterfalls"] { --accent: #2E6B7E; }
body[data-segment="ginkgo"] { --accent: #C2871E; }
body[data-segment="night"] {
  --accent: #E58A3A;
  --ui-bg: rgba(16, 25, 45, 0.80);
  --ui-bg-strong: rgba(20, 30, 52, 0.96);
  --ui-fg: #F4EFE6;
  --ui-muted: rgba(244, 239, 230, 0.68);
  --ui-border: rgba(229, 138, 58, 0.28);
  --ui-shadow: 0 14px 36px rgba(4, 8, 20, 0.50);
}

/* 2.5D Four-Realm Themes */
body[data-mode="depth"] {
  --accent: #C2871E;
  --ui-bg: rgba(247, 242, 233, 0.84);
  --ui-bg-strong: rgba(251, 248, 241, 0.96);
  --ui-fg: #1C1916;
  --ui-muted: rgba(28, 25, 22, 0.58);
  --ui-border: rgba(28, 25, 22, 0.12);
  --ui-shadow: 0 10px 28px rgba(42, 30, 16, 0.14);
}
body[data-mode="depth"][data-depth-scene="lijiang"] { --accent: #2D615B; }
body[data-mode="depth"][data-depth-scene="dajing"] { --accent: #3B6E8C; }
body[data-mode="depth"][data-depth-scene="paideng"] {
  --accent: #E58A3A;
  --ui-bg: rgba(16, 25, 45, 0.80);
  --ui-bg-strong: rgba(20, 30, 52, 0.96);
  --ui-fg: #F4EFE6;
  --ui-muted: rgba(244, 239, 230, 0.68);
  --ui-border: rgba(229, 138, 58, 0.28);
  --ui-shadow: 0 14px 36px rgba(4, 8, 20, 0.50);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  touch-action: pan-x pan-y; /* 禁止整页捏合缩放，地图自己的缩放不受影响 */
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#stage {
  position: fixed;
  inset: 0;
  z-index: 1;
}
#stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#stage canvas.dragging {
  cursor: grabbing;
}
#stage canvas.pointer {
  cursor: pointer;
}

#vignette {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(128% 102% at 50% 48%, transparent 66%, rgba(44, 34, 20, 0.12) 100%);
  transition: background 0.7s ease;
}
body[data-mode="walk"][data-segment="night"] #vignette,
body[data-mode="depth"][data-depth-scene="paideng"] #vignette {
  background: radial-gradient(122% 98% at 50% 48%, transparent 58%, rgba(6, 11, 24, 0.48) 100%);
}

#mode-veil {
  position: fixed;
  inset: 0;
  z-index: 22;
  pointer-events: none;
  background: var(--paper);
  opacity: 0;
  transition: opacity 0.26s ease;
}
#mode-veil.flash {
  opacity: 0.74;
}

/* ==================== Floating Screen-Space Rice-Paper Tags & Portal Banner ==================== */
.tag-layer {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  overflow: hidden;
}
body[data-mode="depth"] .tag-layer {
  display: none;
}

.paper-tag {
  position: absolute;
  left: 0;
  top: 0;
  appearance: none;
  border: 1px solid rgba(28, 25, 22, 0.24);
  background: rgba(251, 247, 239, 0.95);
  color: #1C1916;
  padding: 4px 10px 4px 8px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: 0.05em;
  white-space: nowrap;
  box-shadow: 0 5px 14px rgba(24, 18, 10, 0.16), inset 0 0 0 1px rgba(255, 255, 255, 0.65);
  transform: translate3d(-999px, -999px, 0);
  opacity: 0;
  pointer-events: none;
  cursor: pointer;
  will-change: transform, opacity;
  transition: opacity 0.2s ease;
}
body[data-segment="night"] .paper-tag {
  background: rgba(252, 246, 236, 0.96);
  border-color: rgba(229, 138, 58, 0.55);
  box-shadow: 0 6px 18px rgba(4, 8, 20, 0.42);
}
.paper-tag.vis {
  pointer-events: auto;
}
.paper-tag .tag-tick {
  width: 2.5px;
  height: 10px;
  border-radius: 2px;
  background: var(--accent);
  flex-shrink: 0;
}

.portal-banner {
  position: absolute;
  left: 0;
  top: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px 4px 6px;
  border-radius: 999px;
  background: rgba(250, 244, 232, 0.94);
  border: 1px solid rgba(179, 38, 30, 0.34);
  color: #1C1916;
  box-shadow: 0 8px 22px rgba(28, 20, 10, 0.22);
  white-space: nowrap;
  transform: translate3d(-999px, -999px, 0);
  opacity: 0;
  pointer-events: none;
  will-change: transform, opacity;
}
.portal-seal {
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--verm);
  color: #FAF6EE;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  font-family: var(--font-ui);
}
.portal-banner-txt {
  font-family: var(--font-title);
  font-size: 13.5px;
  letter-spacing: 0.08em;
}

/* ==================== Top Header Bar ==================== */
.top-bar {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  z-index: 12;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  justify-self: start;
  pointer-events: auto;
  min-width: 0;
}

.home-back {
  appearance: none;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--ui-bg);
  color: var(--ui-fg);
  font-family: var(--font-body);
  font-size: 12.5px;
  letter-spacing: 0.14em;
  white-space: nowrap;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: inset 0 0 0 1px var(--ui-border), var(--ui-shadow);
  transition: background 0.3s ease, color 0.3s ease, transform 0.2s ease;
}
.home-back:active {
  transform: scale(0.96);
}

.brand-seal {
  width: 32px;
  height: 32px;
  border-radius: 7px;
  background: var(--verm);
  color: #FAF6EE;
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.05;
  display: grid;
  place-items: center;
  writing-mode: vertical-rl;
  letter-spacing: -1px;
  box-shadow: 0 5px 14px rgba(179, 38, 30, 0.28), inset 0 0 0 1px rgba(255, 242, 228, 0.24);
  flex-shrink: 0;
}

.brand-text {
  white-space: nowrap;
}
.brand-text h1 {
  margin: 0;
  font-family: var(--font-title);
  font-weight: 400;
  font-size: 20px;
  line-height: 1.05;
  letter-spacing: 0.12em;
  color: var(--ui-fg);
  white-space: nowrap;
  transition: color 0.5s ease;
}

.chapter-sub {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  letter-spacing: 0.15em;
  color: var(--ui-muted);
  white-space: nowrap;
  transition: color 0.5s ease;
}

.mode-switch {
  position: relative;
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  width: max-content;
  padding: 3px;
  border-radius: 999px;
  background: var(--ui-bg);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  box-shadow: inset 0 0 0 1px var(--ui-border), var(--ui-shadow);
  pointer-events: auto;
  flex-shrink: 0;
  transition: background 0.5s ease, box-shadow 0.5s ease;
}

.mode-pill-bg {
  position: absolute;
  top: 3px;
  left: 3px;
  width: calc(50% - 3px);
  height: calc(100% - 6px);
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.15);
  transition: transform 0.34s cubic-bezier(0.22, 1, 0.36, 1), background 0.45s ease;
}
body[data-mode="depth"] .mode-pill-bg {
  transform: translateX(100%);
}

.mode-btn {
  position: relative;
  z-index: 1;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ui-fg);
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0.08em;
  padding: 7px 15px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color 0.3s ease;
}
.mode-btn.active {
  color: #FAF6EE;
}

.top-right {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
  flex-shrink: 0;
}

.gyro-btn {
  appearance: none;
  border: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  background: var(--ui-bg);
  color: var(--ui-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: inset 0 0 0 1px var(--ui-border), var(--ui-shadow);
  transition: background 0.3s ease, color 0.3s ease, transform 0.2s ease;
}
.gyro-btn.active {
  background: var(--accent);
  color: #FAF6EE;
}

.night-btn {
  appearance: none;
  border: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  background: var(--ui-bg);
  color: var(--ui-muted);
  font: inherit;
  font-size: 13px;
  line-height: 1;
  display: none;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: inset 0 0 0 1px var(--ui-border), var(--ui-shadow);
  transition: background 0.3s ease, color 0.3s ease;
}
body[data-mode="map"] .night-btn {
  display: grid;
}
.night-btn.active {
  background: var(--accent);
  color: #FAF6EE;
}
@media (max-width: 480px) {
  .night-btn {
    width: 28px;
    height: 28px;
  }
}

.stamp-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px 4px 6px;
  border-radius: 999px;
  background: var(--ui-bg);
  color: var(--ui-fg);
  white-space: nowrap;
  flex-shrink: 0;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: inset 0 0 0 1px var(--ui-border), var(--ui-shadow);
  transition: background 0.5s ease, color 0.5s ease, opacity 0.35s ease;
}

.stamp-icon {
  width: 22px;
  height: 22px;
  border-radius: 5px;
  background: var(--verm);
  color: #FAF6EE;
  font-family: var(--font-ui);
  font-size: 12px;
  display: grid;
  place-items: center;
  transform: rotate(-4deg);
  flex-shrink: 0;
}

.stamp-count {
  font-size: 12.5px;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stamp-flash {
  position: absolute;
  left: 5px;
  top: 50%;
  width: 24px;
  height: 24px;
  margin-top: -12px;
  border-radius: 6px;
  border: 1.5px solid var(--verm);
  background: rgba(179, 38, 30, 0.94);
  color: #FAF6EE;
  font-family: var(--font-ui);
  font-size: 13px;
  display: grid;
  place-items: center;
  opacity: 0;
  transform: scale(0.5) rotate(-12deg);
  pointer-events: none;
}

.stamp-pill.stamping {
  animation: pillBounce 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}
.stamp-pill.stamping .stamp-flash {
  animation: microSealFlash 0.84s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes pillBounce {
  0% { transform: scale(1); }
  40% { transform: scale(1.08); }
  100% { transform: scale(1); }
}
@keyframes microSealFlash {
  0% { opacity: 0; transform: scale(1.55) rotate(-16deg); box-shadow: 0 0 0 0 rgba(179, 38, 30, 0.5); }
  26% { opacity: 1; transform: scale(1.02) rotate(-4deg); box-shadow: 0 0 0 7px rgba(179, 38, 30, 0.16); }
  72% { opacity: 0.9; transform: scale(1) rotate(-4deg); box-shadow: 0 0 0 13px rgba(179, 38, 30, 0); }
  100% { opacity: 0; transform: scale(0.9) rotate(-4deg); box-shadow: 0 0 0 16px rgba(179, 38, 30, 0); }
}

/* ==================== Sub-Header Row: Filter Bar + Portal Quick-Hop ==================== */
.sub-bar {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 48px);
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  z-index: 11;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
body[data-mode="depth"] .sub-bar {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-6px);
}

.filter-bar {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--ui-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: inset 0 0 0 1px var(--ui-border), var(--ui-shadow);
  pointer-events: auto;
}
.filter-bar::-webkit-scrollbar {
  display: none;
}

.filter-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ui-muted);
  font-family: var(--font-body);
  font-size: 12px;
  line-height: 1.2;
  letter-spacing: 0.05em;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.24s ease, color 0.24s ease;
}
.filter-btn:hover {
  color: var(--ui-fg);
}
.filter-btn.active {
  background: var(--accent);
  color: #FAF6EE;
}

.portal-hop-btn {
  appearance: none;
  border: 1px solid rgba(179, 38, 30, 0.28);
  background: var(--ui-bg-strong);
  color: var(--ui-fg);
  padding: 6px 11px;
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 11.5px;
  line-height: 1.2;
  letter-spacing: 0.05em;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  pointer-events: auto;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--ui-shadow);
  transition: transform 0.2s ease, border-color 0.3s ease;
}
.portal-hop-btn:hover {
  border-color: var(--verm);
  transform: translateY(-1px);
}
.portal-hop-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--verm);
  box-shadow: 0 0 0 3px rgba(179, 38, 30, 0.18);
  animation: portalPulse 2.1s ease-in-out infinite;
}
@keyframes portalPulse {
  50% { transform: scale(1.25); box-shadow: 0 0 0 5px rgba(179, 38, 30, 0.06); }
}

/* ==================== Bottom Docks ==================== */
.bottom-dock {
  position: fixed;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 12;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  width: min(640px, calc(100vw - 16px));
  pointer-events: none;
}
.bottom-dock[hidden] {
  display: none;
}
/* 画境 9 个按钮：电脑端放宽一点，手机端靠横滑 */
.bottom-dock.depth-dock { width: min(860px, calc(100vw - 16px)); }

.journey-track-wrap,
.depth-track-wrap {
  width: min(460px, 90vw);
  display: flex;
  align-items: center;
  gap: 9px;
  pointer-events: auto;
}

.depth-edge-label {
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--ui-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.journey-track {
  position: relative;
  flex: 1;
  height: 20px;
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;
}

.journey-rail {
  width: 100%;
  height: 2.5px;
  border-radius: 999px;
  background: var(--ui-border);
  transition: background 0.5s ease;
}

.journey-fill {
  position: absolute;
  left: 0;
  height: 2.5px;
  width: 0%;
  border-radius: 999px;
  background: var(--accent);
  pointer-events: none;
  transition: background 0.45s ease;
}

.portal-tick {
  position: absolute;
  top: 50%;
  width: 6px;
  height: 6px;
  margin-left: -3px;
  margin-top: -3px;
  border-radius: 1px;
  transform: rotate(45deg);
  background: var(--paper-warm);
  border: 1.4px solid var(--verm);
  pointer-events: none;
  opacity: 0.85;
}

.journey-thumb {
  position: absolute;
  left: 0%;
  top: 50%;
  width: 13px;
  height: 13px;
  margin-left: -6.5px;
  margin-top: -6.5px;
  border-radius: 50%;
  background: var(--paper-warm);
  border: 2.3px solid var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.24);
  pointer-events: none;
  transition: border-color 0.45s ease, transform 0.18s ease;
}
.journey-track:hover .journey-thumb,
.journey-track.scrubbing .journey-thumb {
  transform: scale(1.22);
}

.chapter-pills,
.depth-scenes {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  width: max-content;
  max-width: calc(100vw - 16px);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  gap: 2px;
  padding: 3.5px;
  border-radius: 999px;
  background: var(--ui-bg);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  box-shadow: inset 0 0 0 1px var(--ui-border), var(--ui-shadow);
  pointer-events: auto;
  transition: background 0.5s ease, box-shadow 0.5s ease;
}
.chapter-pills::-webkit-scrollbar,
.depth-scenes::-webkit-scrollbar {
  display: none;
}

.chapter-pill {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ui-fg);
  font-family: var(--font-body);
  font-size: 12px;
  line-height: 1.2;
  letter-spacing: 0.04em;
  padding: 6.5px 12px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 4.5px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.26s ease, color 0.26s ease;
}
.chapter-pill:hover {
  background: rgba(128, 110, 86, 0.10);
}
.chapter-pill.active {
  background: var(--accent);
  color: #FAF6EE;
}
/* 画境素材首次点到才下载：下载期间按钮轻轻呼吸 */
.chapter-pill.loading { animation: pill-load 0.9s ease-in-out infinite alternate; }
@keyframes pill-load { from { opacity: 1; } to { opacity: 0.45; } }

.pill-dot {
  width: 4.5px;
  height: 4.5px;
  border-radius: 1px;
  transform: rotate(45deg);
  background: currentColor;
  opacity: 0.48;
  flex-shrink: 0;
}
.chapter-pill.active .pill-dot {
  opacity: 1;
}

.depth-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  pointer-events: auto;
}

/* ==================== Upgraded Rice-Paper Gazetteer Sheet ==================== */
.card-backdrop {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: rgba(18, 14, 10, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.26s ease;
}
.card-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.detail-card {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 52px);
  right: max(18px, env(safe-area-inset-right));
  z-index: 16;
  width: min(378px, calc(100vw - 24px));
  max-height: calc(100vh - max(28px, env(safe-area-inset-top)) - 68px);
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  background: var(--ui-bg-strong);
  color: var(--ui-fg);
  backdrop-filter: blur(22px) saturate(1.18);
  -webkit-backdrop-filter: blur(22px) saturate(1.18);
  box-shadow: inset 0 0 0 1px var(--ui-border), 0 24px 56px rgba(20, 14, 8, 0.28);
  overflow: hidden;
  opacity: 0;
  transform: translate3d(0, 16px, 0);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.detail-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 24px;
  right: 24px;
  height: 2.5px;
  border-radius: 0 0 3px 3px;
  background: var(--accent);
  z-index: 4;
}
.detail-card.open {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  pointer-events: auto;
}

.card-drag-bar {
  position: relative;
  flex-shrink: 0;
  height: 44px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  touch-action: none;
}

.card-handle {
  display: none;
}

.card-cat {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.1em;
  white-space: nowrap;
  background: rgba(179, 38, 30, 0.09);
  color: var(--accent);
  border: 1px solid var(--ui-border);
}

.card-close {
  appearance: none;
  border: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(28, 25, 22, 0.08);
  color: var(--ui-fg);
  font-size: 19px;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s ease;
}
body[data-segment="night"] .card-close,
body[data-mode="depth"][data-depth-scene="paideng"] .card-close {
  background: rgba(244, 239, 230, 0.14);
}
.card-close:hover {
  background: rgba(179, 38, 30, 0.16);
}

.card-scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 2px 18px 18px;
}
.card-scroll::-webkit-scrollbar {
  width: 4px;
}
.card-scroll::-webkit-scrollbar-thumb {
  background: var(--ui-border);
  border-radius: 4px;
}

/* 3-Layer Interactive Peep-in-Fan Circular Diorama Window */
.fan-stage-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 0 10px;
}

.fan-window {
  position: relative;
  width: 188px;
  height: 188px;
  border-radius: 50%;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  background: #EFE7D6;
  box-shadow: 0 12px 28px rgba(24, 16, 8, 0.18);
}
.fan-window:active {
  cursor: grabbing;
}

.fan-layer {
  position: absolute;
  inset: 0;
  will-change: transform;
}

.fan-bg {
  inset: -16px;
  background-size: cover;
  background-position: center 42%;
  opacity: 0.92;
  transition: transform 0.12s ease-out;
}

.fan-mid {
  display: grid;
  place-items: center;
  padding: 16px;
  transition: transform 0.12s ease-out;
}
.fan-mid img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 9px 14px rgba(20, 14, 8, 0.28));
  pointer-events: none;
}

.fan-fx {
  width: 100%;
  height: 100%;
  pointer-events: none;
  transition: transform 0.12s ease-out;
}

.fan-rim {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow:
    inset 0 0 0 3px rgba(179, 38, 30, 0.62),
    inset 0 0 0 6.5px rgba(250, 244, 232, 0.85),
    inset 0 0 0 7.5px rgba(201, 142, 38, 0.55),
    inset 0 10px 22px rgba(24, 16, 8, 0.16);
  pointer-events: none;
}

.fan-hint {
  margin-top: 6px;
  font-size: 10.5px;
  letter-spacing: 0.16em;
  color: var(--ui-muted);
}

/* Gazetteer Typography & Archival Cells */
.card-head-block {
  margin-bottom: 10px;
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 3px;
}
.card-zone {
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--ui-muted);
}
.card-code {
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: var(--ui-muted);
  font-variant-numeric: tabular-nums;
  opacity: 0.72;
}

.card-title {
  margin: 0 0 6px;
  font-family: var(--font-title);
  font-weight: 400;
  font-size: 24px;
  line-height: 1.15;
  letter-spacing: 0.06em;
}

.card-tagline {
  margin: 0;
  padding-left: 9px;
  border-left: 2.5px solid var(--accent);
  font-size: 13px;
  line-height: 1.55;
  color: var(--ui-fg);
  opacity: 0.92;
}

.fact-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 11px 0 12px;
}

.fact-cell {
  padding: 7px 9px;
  border-radius: 10px;
  background: rgba(128, 110, 86, 0.08);
  border: 1px solid var(--ui-border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.fact-cell-wide {
  grid-column: 1 / -1;
}
.fact-k {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--ui-muted);
}
.fact-v {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.38;
  color: var(--ui-fg);
}

.lore-section {
  margin-bottom: 11px;
}
.lore-h {
  margin: 0 0 5px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 6px;
}
.lore-h::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 1px;
  transform: rotate(45deg);
  background: var(--accent);
}
.lore-p {
  margin: 0;
  font-size: 13px;
  line-height: 1.72;
  color: var(--ui-fg);
  opacity: 0.9;
  text-align: justify;
}

.lore-tips-box {
  padding: 9px 11px;
  border-radius: 11px;
  background: rgba(201, 142, 38, 0.08);
  border: 1px dashed var(--ui-border);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.card-stamp-btn {
  flex: 1;
  appearance: none;
  border: 0;
  padding: 9px 12px;
  border-radius: 999px;
  background: var(--verm);
  color: #FAF6EE;
  font-family: var(--font-body);
  font-size: 12.5px;
  letter-spacing: 0.1em;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(179, 38, 30, 0.24);
  transition: background 0.28s ease, box-shadow 0.28s ease;
}
.card-stamp-btn.stamped {
  background: var(--lijiang);
  box-shadow: 0 5px 14px rgba(45, 97, 91, 0.24);
}
.btn-seal {
  width: 19px;
  height: 19px;
  border-radius: 4.5px;
  background: rgba(250, 246, 238, 0.22);
  font-family: var(--font-ui);
  font-size: 11.5px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.card-share-btn {
  appearance: none;
  border: 1px solid var(--ui-border);
  background: transparent;
  color: var(--ui-muted);
  padding: 8px 11px;
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 11.5px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s ease, color 0.2s ease;
}
.card-share-btn:hover {
  background: rgba(128, 110, 86, 0.10);
  color: var(--ui-fg);
}

.card-inline-note {
  min-height: 15px;
  margin-top: 7px;
  font-size: 11.5px;
  letter-spacing: 0.08em;
  color: var(--ui-muted);
  text-align: center;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.card-inline-note.show {
  opacity: 1;
}

/* ==================== Preloader ==================== */
.loader {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: var(--paper);
  color: var(--ink);
  display: grid;
  place-items: center;
  transition: opacity 0.65s ease, visibility 0s 0.65s;
}
.loader.done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.loader-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.loader-seal {
  width: 54px;
  height: 54px;
  border-radius: 12px;
  background: var(--verm);
  color: #FAF6EE;
  font-family: var(--font-ui);
  font-size: 22px;
  writing-mode: vertical-rl;
  letter-spacing: -2px;
  display: grid;
  place-items: center;
  box-shadow: 0 12px 26px rgba(179, 38, 30, 0.26);
  animation: sealBreathe 2s ease-in-out infinite;
}
@keyframes sealBreathe {
  50% { transform: scale(0.95); box-shadow: 0 0 0 10px rgba(179, 38, 30, 0.08); }
}
.loader-track {
  width: 170px;
  height: 2px;
  border-radius: 999px;
  background: rgba(28, 25, 22, 0.12);
  overflow: hidden;
}
.loader-bar {
  height: 100%;
  width: 100%;
  background: var(--verm);
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 0.2s ease;
}
.loader-text {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.24em;
  color: var(--ink-soft);
}

/* ==================== Mobile Portrait First (<= 760px) ==================== */
@media (max-width: 760px) {
  .top-bar {
    grid-template-columns: auto 1fr auto;
    gap: 5px;
    top: max(9px, env(safe-area-inset-top));
    left: max(9px, env(safe-area-inset-left));
    right: max(9px, env(safe-area-inset-right));
  }
  .brand-text {
    display: none;
  }
  .home-back {
    height: 30px;
    padding: 0 10px;
    font-size: 11.5px;
    letter-spacing: 0.1em;
  }
  .brand-seal {
    width: 30px;
    height: 30px;
    font-size: 12px;
  }
  .mode-switch {
    justify-self: center;
    padding: 2.5px;
  }
  .mode-pill-bg {
    top: 2.5px;
    left: 2.5px;
    width: calc(50% - 2.5px);
    height: calc(100% - 5px);
  }
  .mode-btn {
    font-size: 11.5px;
    padding: 5.5px 10.5px;
    letter-spacing: 0.03em;
  }
  .gyro-btn {
    width: 28px;
    height: 28px;
  }
  .stamp-pill {
    padding: 3.5px 8.5px 3.5px 5px;
    gap: 4.5px;
  }
  .stamp-icon {
    width: 19px;
    height: 19px;
    font-size: 11px;
  }
  .stamp-count {
    font-size: 11.5px;
  }

  .sub-bar {
    top: calc(max(9px, env(safe-area-inset-top)) + 39px);
    left: 8px;
    right: 8px;
    justify-content: center;
    gap: 5px;
  }
  .filter-bar {
    padding: 2.5px;
    gap: 1px;
  }
  .filter-btn {
    padding: 4px 8px;
    font-size: 11px;
    letter-spacing: 0.02em;
  }
  .portal-hop-btn {
    padding: 5px 8.5px;
    font-size: 11px;
    letter-spacing: 0.02em;
    gap: 4px;
  }

  .bottom-dock {
    bottom: max(9px, env(safe-area-inset-bottom));
    gap: 5px;
    width: calc(100vw - 12px);
  }
  .chapter-pills,
  .depth-scenes {
    max-width: calc(100vw - 12px);
    padding: 2.5px;
    gap: 1.5px;
  }
  .chapter-pill {
    padding: 5.5px 8.5px;
    font-size: 11px;
    letter-spacing: 0.01em;
  }
  .pill-dot {
    display: none;
  }

  .detail-card {
    top: auto;
    left: 8px;
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    width: auto;
    max-height: 76vh;
    border-radius: 22px;
    transform: translate3d(0, 104%, 0);
    transition: opacity 0.24s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  }
  .detail-card.open {
    transform: translate3d(0, 0, 0);
  }
  .card-drag-bar {
    height: 40px;
    padding: 4px 12px 0;
  }
  .card-handle {
    position: absolute;
    left: 50%;
    top: 7px;
    transform: translateX(-50%);
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 4px;
    background: var(--ui-border);
  }
  .fan-window {
    width: 164px;
    height: 164px;
  }
  .card-title {
    font-size: 21px;
  }
  .lore-p {
    font-size: 12.5px;
    line-height: 1.66;
  }
  .card-actions {
    gap: 7px;
  }
  .card-stamp-btn {
    padding: 9px 10px;
    font-size: 12px;
  }
  .card-share-btn {
    padding: 8px 9px;
    font-size: 11px;
  }
}

/* 手机：比例尺移到底部卡片上方，不压顶部乡镇标签（map.css 在后加载，故加权重） */
@media (max-width: 919px) {
  html body .lc-scale-bar {
    top: auto;
    bottom: calc(max(10px, env(safe-area-inset-bottom)) + 128px);
  }
}

/* 夜晚：地图上的左上角品牌字改浅色 */
body[data-night="1"][data-mode="map"] .brand-text h1,
body[data-night="1"][data-mode="map"] .chapter-sub,
body[data-night="1"][data-mode="map"] .dm-home-back strong,
body[data-night="1"][data-mode="map"] .dm-home-back em,
body[data-night="1"][data-mode="map"] .dm-hb-arrow {
  color: #EFE6D2;
  text-shadow: 0 1px 6px rgba(10, 14, 30, 0.6);
}
