:root {
  --paper: #efe9dc;
  --paper-strong: #f5f0e5;
  --ink: #1c1e1c;
  --ink-soft: #5c5b52;
  --ink-faint: #8a877b;
  --cinnabar: #9a2b23;
  --line: rgba(28, 30, 28, 0.18);
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", serif;
  --sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: #0b1116;
  color: var(--ink);
  font-family: var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#gl {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  cursor: grab;
  touch-action: none;
}
#gl:active { cursor: grabbing; }

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 44%, rgba(8, 12, 16, 0) 48%, rgba(8, 12, 16, 0.34) 100%),
    linear-gradient(to bottom, rgba(8, 12, 16, 0.18), rgba(8, 12, 16, 0) 22%, rgba(8, 12, 16, 0) 72%, rgba(8, 12, 16, 0.28));
  z-index: 1;
}

/* ---------------- 加载 ---------------- */
#loading {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at 50% 40%, #1a2833 0%, #0b1116 62%, #070b0e 100%);
  color: var(--paper);
  transition: opacity 0.85s ease, visibility 0.85s ease;
}
#loading.hide {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.loading-inner { text-align: center; transform: translateY(-3vh); }
.loading-seal {
  width: 46px;
  height: 46px;
  margin: 0 auto 22px;
  display: grid;
  place-items: center;
  background: var(--cinnabar);
  color: #f6efe0;
  font-family: var(--serif);
  font-size: 26px;
  line-height: 1;
  box-shadow: 0 0 0 1px rgba(246, 239, 224, 0.22) inset;
}
.loading-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 25px;
  letter-spacing: 0.26em;
  text-indent: 0.26em;
  font-weight: 500;
}
.loading-sub {
  margin: 12px 0 26px;
  font-size: 11px;
  letter-spacing: 0.22em;
  color: rgba(239, 233, 220, 0.52);
}
.loading-bar {
  width: 190px;
  height: 1px;
  margin: 0 auto;
  background: rgba(239, 233, 220, 0.18);
  overflow: hidden;
}
.loading-bar i {
  display: block;
  height: 100%;
  width: 40%;
  background: linear-gradient(90deg, transparent, #d4b66b, transparent);
  animation: loadSweep 1.15s ease-in-out infinite;
}
@keyframes loadSweep {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(360%); }
}

/* ---------------- 展签 ---------------- */
#titleCard {
  position: fixed;
  top: 26px;
  left: 28px;
  z-index: 3;
  display: flex;
  gap: 17px;
  padding: 18px 22px 17px 18px;
  max-width: 400px;
  background: rgba(241, 235, 222, 0.93);
  border: 1px solid rgba(255, 255, 255, 0.32);
  box-shadow: 0 18px 48px rgba(4, 8, 11, 0.30);
  backdrop-filter: blur(12px) saturate(1.05);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.9s ease 0.35s, transform 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) 0.35s;
}
body.ready #titleCard { opacity: 1; transform: none; }

.seal {
  flex: 0 0 auto;
  width: 45px;
  height: 45px;
  display: grid;
  place-items: center;
  background: var(--cinnabar);
  color: #f7f0e2;
  font-family: var(--serif);
  font-size: 25px;
  line-height: 1;
  transform: translateY(2px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

#titleCard h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
  font-size: 42px;
  line-height: 1;
  letter-spacing: 0.16em;
}
.title-en {
  margin: 7px 0 0;
  font-family: var(--serif);
  font-size: 11.5px;
  letter-spacing: 0.07em;
  color: var(--ink-soft);
}
.title-meta {
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  line-height: 1.75;
  color: var(--ink-soft);
  letter-spacing: 0.03em;
}
.title-meta span { display: block; }

/* ---------------- 控制条 ---------------- */
#controls {
  position: fixed;
  right: 28px;
  bottom: 26px;
  z-index: 4;
  display: flex;
  align-items: stretch;
  padding: 5px;
  background: rgba(241, 235, 222, 0.93);
  border: 1px solid rgba(255, 255, 255, 0.32);
  box-shadow: 0 14px 38px rgba(4, 8, 11, 0.28);
  backdrop-filter: blur(12px) saturate(1.05);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.9s ease 0.55s, transform 0.9s ease 0.55s;
}
body.ready #controls { opacity: 1; transform: none; }

#controls button {
  position: relative;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 12.5px;
  letter-spacing: 0.04em;
  padding: 10px 13px;
  min-height: 40px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s ease, color 0.2s ease;
}
#controls button:hover { background: rgba(28, 30, 28, 0.06); }
#controls button:focus-visible,
.legend button:focus-visible,
#btnSkip:focus-visible {
  outline: 2px solid var(--cinnabar);
  outline-offset: 1px;
}
#controls button[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 4px;
  height: 2px;
  background: var(--cinnabar);
}
#controls button + button::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  width: 1px;
  background: var(--line);
}

/* ---------------- 柱网图例 ---------------- */
#legend {
  position: fixed;
  left: 28px;
  bottom: 26px;
  z-index: 4;
  width: 226px;
  padding: 12px 12px 8px;
  background: rgba(241, 235, 222, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.32);
  box-shadow: 0 16px 40px rgba(4, 8, 11, 0.28);
  backdrop-filter: blur(12px) saturate(1.05);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: opacity 0.45s ease, transform 0.45s ease, visibility 0.45s;
}
body.is-structure #legend {
  opacity: 1;
  visibility: visible;
  transform: none;
}
.legend-title {
  margin: 0 4px 7px;
  font-size: 10.5px;
  letter-spacing: 0.18em;
  color: var(--ink-faint);
}
.legend button {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: baseline;
  width: 100%;
  padding: 8px 4px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  text-align: left;
  color: var(--ink);
  font-family: var(--sans);
  cursor: pointer;
  transition: background 0.2s ease;
}
.legend button:hover { background: rgba(28, 30, 28, 0.05); }
.legend button .num {
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1;
  color: var(--cinnabar);
}
.legend button .txt { font-size: 12px; letter-spacing: 0.04em; }
.legend button em {
  font-style: normal;
  color: var(--ink-faint);
  margin-left: 7px;
  font-size: 11px;
}
.legend button[aria-pressed="true"] {
  background: rgba(154, 43, 35, 0.07);
  box-shadow: inset 2px 0 0 var(--cinnabar);
}

/* ---------------- 提示与跳过 ---------------- */
#hint {
  position: fixed;
  left: 50%;
  bottom: 30px;
  z-index: 3;
  margin: 0;
  transform: translateX(-50%);
  font-size: 11.5px;
  letter-spacing: 0.12em;
  color: rgba(247, 241, 229, 0.82);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9), 0 0 14px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.8s ease;
  animation: hintFade 2.2s ease 11s forwards;
}
body.ready #hint { opacity: 1; }
body.is-structure #hint { opacity: 0; }
@keyframes hintFade { to { opacity: 0; } }

#btnSkip {
  position: fixed;
  left: 50%;
  bottom: 74px;
  z-index: 5;
  transform: translateX(-50%);
  appearance: none;
  border: 1px solid rgba(241, 235, 222, 0.38);
  background: rgba(15, 21, 26, 0.42);
  color: rgba(247, 241, 229, 0.9);
  font-family: var(--sans);
  font-size: 11.5px;
  letter-spacing: 0.16em;
  padding: 8px 16px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background 0.2s ease, opacity 0.3s ease;
}
#btnSkip:hover { background: rgba(15, 21, 26, 0.62); }
#btnSkip.is-hidden { display: none; }

#disclaimer {
  position: fixed;
  left: 30px;
  top: 50%;
  z-index: 2;
  writing-mode: vertical-rl;
  font-size: 9.5px;
  letter-spacing: 0.22em;
  color: rgba(247, 241, 229, 0.34);
  pointer-events: none;
  transform: translateY(-50%);
}

/* ---------------- 降级 ---------------- */
#fallback {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  text-align: center;
  padding: 24px;
  background: #0b1116;
  color: var(--paper);
}
#fallback.show { display: grid; }
#fallback h2 { font-family: var(--serif); font-weight: 500; letter-spacing: 0.1em; }
#fallback p { color: rgba(239, 233, 220, 0.6); font-size: 13px; }

/* ---------------- 隐藏界面（截图/沉浸） ---------------- */
body.no-ui #titleCard,
body.no-ui #controls,
body.no-ui #legend,
body.no-ui #hint,
body.no-ui #btnSkip,
body.no-ui #disclaimer { display: none !important; }

/* ---------------- 响应式 ---------------- */
@media (max-width: 820px) {
  #titleCard {
    top: 14px;
    left: 14px;
    right: 14px;
    max-width: none;
    padding: 13px 15px 12px 13px;
    gap: 12px;
  }
  .seal { width: 36px; height: 36px; font-size: 21px; }
  #titleCard h1 { font-size: 31px; letter-spacing: 0.14em; }
  .title-en { font-size: 9.5px; margin-top: 5px; }
  .title-meta {
    margin-top: 9px;
    padding-top: 8px;
    font-size: 10px;
    line-height: 1.65;
  }
  .title-meta span:first-child { display: none; }

  #controls {
    left: 12px;
    right: 12px;
    bottom: 12px;
    padding: 4px;
    overflow-x: auto;
    scrollbar-width: none;
    justify-content: flex-start;
    background: rgba(241, 235, 222, 0.86);
  }
  #controls::-webkit-scrollbar { display: none; }
  #controls button { font-size: 12px; padding: 10px 11px; min-height: 42px; }

  #legend {
    left: 12px;
    right: 12px;
    bottom: 82px;
    width: auto;
    padding: 9px 10px 6px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }
  .legend-title { grid-column: 1 / -1; margin-bottom: 5px; }
  .legend button {
    grid-template-columns: 26px 1fr;
    border-top: 0;
    padding: 6px 2px;
  }
  .legend button .num { font-size: 17px; }
  .legend button .txt { font-size: 11px; }
  .legend button em { display: block; margin: 2px 0 0; font-size: 10px; }

  #hint { bottom: 68px; font-size: 10.5px; letter-spacing: 0.08em; width: 100%; text-align: center; }
  #btnSkip { bottom: 112px; font-size: 11px; }
  #disclaimer { display: none; }
}

@media (max-width: 420px) {
  #titleCard h1 { font-size: 27px; }
  .title-en { display: none; }
  .title-meta { margin-top: 7px; }
  #controls button { padding: 9px 9px; font-size: 11.5px; }
}

@media (prefers-reduced-motion: reduce) {
  #titleCard, #controls, #loading, .loading-bar i { transition: none !important; animation: none !important; }
  #hint { animation: none; opacity: 1; }
}
