:root {
  --paper: #f2ecdf;
  --paper-deep: #e7dfcd;
  --ink: #2b2620;
  --ink-soft: #6b6154;
  --red: #9e2b22;
  --red-deep: #7e1f18;
  --gold: #c9962e;
  --gold-soft: #e4c878;
  --qing: #2f5d50;
  --card-bg: rgba(247, 242, 231, 0.94);
  --shadow: 0 8px 30px rgba(43, 38, 32, 0.18);
  --serif: "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body { font-family: var(--sans); color: var(--ink); background: var(--paper); }

#scene-container { position: fixed; inset: 0; }
#scene-container canvas { display: block; }

.hidden { display: none !important; }

/* ---------- 加载 ---------- */
#loading {
  position: fixed; inset: 0; z-index: 100;
  background: var(--paper);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  transition: opacity 0.7s ease;
}
#loading.done { opacity: 0; pointer-events: none; }
.seal {
  width: 84px; height: 84px; background: var(--red); color: #fff;
  font-family: var(--serif); font-size: 30px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px; letter-spacing: 2px;
  writing-mode: vertical-rl;
  box-shadow: var(--shadow);
  animation: seal-pulse 1.6s ease-in-out infinite;
}
@keyframes seal-pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.05); } }
.loading-title { font-family: var(--serif); font-size: 28px; letter-spacing: 8px; }
.loading-sub { color: var(--ink-soft); font-size: 13px; letter-spacing: 3px; }

/* ---------- 标题 ---------- */
#masthead {
  position: fixed; top: 20px; left: 22px; z-index: 20;
  display: flex; align-items: center; gap: 12px; pointer-events: none;
}
.seal-small {
  width: 46px; height: 46px; background: var(--red); color: #fff; border-radius: 6px;
  font-family: var(--serif); font-size: 16px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; writing-mode: vertical-rl;
  letter-spacing: 1px; box-shadow: var(--shadow);
}
#masthead h1 { font-family: var(--serif); font-size: 26px; letter-spacing: 5px; }
#masthead p { font-size: 11px; color: var(--ink-soft); letter-spacing: 1px; margin-top: 4px; }

/* ---------- 工具栏 ---------- */
#toolbar {
  position: fixed; top: 20px; right: 22px; z-index: 20;
  display: flex; gap: 8px;
}
.tool {
  font-family: var(--sans); font-size: 13px; padding: 8px 14px;
  background: var(--card-bg); color: var(--ink);
  border: 1px solid rgba(43,38,32,0.15); border-radius: 6px; cursor: pointer;
  backdrop-filter: blur(6px); transition: all 0.2s;
}
.tool:hover { border-color: var(--red); color: var(--red); }
.tool.active { background: var(--red); color: #fff; border-color: var(--red); }
.tool.primary { background: var(--red); color: #fff; border-color: var(--red); font-weight: 600; }
.tool.primary:hover { background: var(--red-deep); }

/* ---------- 拆解控制 ---------- */
#controls {
  position: fixed; left: 22px; bottom: 46px; z-index: 20;
  width: 340px; padding: 16px 18px 12px;
  background: var(--card-bg); border: 1px solid rgba(43,38,32,0.12);
  border-radius: 10px; box-shadow: var(--shadow); backdrop-filter: blur(8px);
}
.control-row { display: flex; align-items: center; gap: 10px; }
.control-label { font-family: var(--serif); font-size: 15px; font-weight: 700; letter-spacing: 2px; }
#explode-pct { font-size: 12px; color: var(--ink-soft); width: 38px; text-align: right; font-variant-numeric: tabular-nums; }
#explode-slider { flex: 1; appearance: none; -webkit-appearance: none; height: 4px; border-radius: 2px;
  background: linear-gradient(90deg, var(--gold), var(--red)); outline: none; cursor: pointer; }
#explode-slider::-webkit-slider-thumb { appearance: none; -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--red); border: 2px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,0.3); cursor: grab; }
#explode-slider::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--red); border: 2px solid #fff; cursor: grab; }
#stage-name { font-size: 12px; color: var(--qing); margin: 8px 0 10px; letter-spacing: 1px; min-height: 16px; font-weight: 600; }
.control-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.ctl {
  font-size: 12px; padding: 7px 10px; border-radius: 6px; cursor: pointer;
  border: 1px solid rgba(43,38,32,0.2); background: #fffdf7; color: var(--ink); transition: all 0.2s;
}
.ctl:hover { border-color: var(--red); color: var(--red); }
.ctl.accent { background: var(--red); color: #fff; border-color: var(--red); }
.ctl.accent:hover { background: var(--red-deep); }
.ctl:disabled { opacity: 0.4; cursor: default; }
.hint { margin-top: 10px; font-size: 11px; color: var(--ink-soft); letter-spacing: 1px; }

/* ---------- 信息卡 ---------- */
#info-card {
  position: fixed; right: 22px; top: 76px; z-index: 25;
  width: 330px; max-height: calc(100vh - 200px); overflow-y: auto;
  background: var(--card-bg); border: 1px solid rgba(43,38,32,0.12);
  border-top: 4px solid var(--red);
  border-radius: 8px; box-shadow: var(--shadow); backdrop-filter: blur(8px);
  padding: 18px 20px;
}
#info-close, #catalog-close, #sources-close {
  position: absolute; top: 8px; right: 12px; border: none; background: none;
  font-size: 22px; color: var(--ink-soft); cursor: pointer; line-height: 1;
}
#info-close:hover, #catalog-close:hover, #sources-close:hover { color: var(--red); }
#info-category { font-size: 11px; color: var(--gold); letter-spacing: 3px; font-weight: 700; }
#info-name { font-family: var(--serif); font-size: 24px; letter-spacing: 2px; margin: 4px 0 10px; }
#info-intro { font-size: 13px; line-height: 1.8; color: var(--ink); }
#info-card h3 { font-size: 12px; letter-spacing: 2px; margin: 14px 0 6px; padding-left: 8px; border-left: 3px solid var(--qing); color: var(--qing); }
#info-simplify-wrap h3 { border-left-color: var(--gold); color: var(--gold); }
#info-card ul { list-style: none; }
#info-card li { font-size: 12px; line-height: 1.7; color: var(--ink-soft); padding: 3px 0 3px 14px; position: relative; }
#info-facts li::before { content: "◆"; color: var(--qing); position: absolute; left: 0; font-size: 8px; top: 8px; }
#info-simplify li::before { content: "◇"; color: var(--gold); position: absolute; left: 0; font-size: 8px; top: 8px; }
#info-sources { margin-top: 12px; font-size: 11px; color: var(--ink-soft); line-height: 1.7; }
#info-sources a { color: var(--red); text-decoration: none; }
#info-sources a:hover { text-decoration: underline; }

/* ---------- 图录 ---------- */
#catalog {
  position: fixed; left: 22px; top: 90px; z-index: 25;
  width: 300px; max-height: calc(100vh - 220px); overflow-y: auto;
  background: var(--card-bg); border: 1px solid rgba(43,38,32,0.12); border-radius: 8px;
  box-shadow: var(--shadow); backdrop-filter: blur(8px); padding: 16px 18px;
}
.catalog-head { display: flex; align-items: baseline; gap: 10px; }
.catalog-head h2 { font-family: var(--serif); font-size: 20px; letter-spacing: 3px; }
#explored-count { font-size: 11px; color: var(--gold); font-weight: 700; }
.catalog-tip { font-size: 11px; color: var(--ink-soft); margin: 8px 0 12px; line-height: 1.6; }
.catalog-group-title { font-size: 11px; color: var(--qing); letter-spacing: 2px; font-weight: 700; margin: 10px 0 6px; }
#catalog-grid { display: flex; flex-direction: column; }
.catalog-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; margin: 2px 0;
  border: 1px solid rgba(43,38,32,0.1); border-radius: 6px; cursor: pointer;
  font-size: 13px; background: #fffdf7; transition: all 0.15s; text-align: left;
}
.catalog-item:hover { border-color: var(--red); color: var(--red); }
.catalog-item .stamp {
  margin-left: auto; font-size: 10px; color: #fff; background: var(--red);
  border-radius: 3px; padding: 1px 4px; font-family: var(--serif);
  visibility: hidden; transform: rotate(-6deg);
}
.catalog-item.explored .stamp { visibility: visible; }
.catalog-item.selected { border-color: var(--red); box-shadow: 0 0 0 1px var(--red); color: var(--red); }

/* ---------- 导览 ---------- */
#tour-bar {
  position: fixed; left: 50%; bottom: 46px; transform: translateX(-50%); z-index: 26;
  width: min(680px, calc(100vw - 400px));
  background: var(--card-bg); border: 1px solid rgba(43,38,32,0.12);
  border-top: 4px solid var(--gold); border-radius: 10px; box-shadow: var(--shadow);
  padding: 14px 20px; backdrop-filter: blur(8px);
}
.tour-progress { display: flex; gap: 6px; margin-bottom: 8px; }
.tour-dot { width: 8px; height: 8px; border-radius: 50%; background: rgba(43,38,32,0.15); }
.tour-dot.on { background: var(--gold); }
.tour-body h2 { font-family: var(--serif); font-size: 18px; letter-spacing: 2px; margin-bottom: 6px; }
.tour-body p { font-size: 13px; line-height: 1.8; color: var(--ink-soft); }
.tour-buttons { display: flex; gap: 8px; margin-top: 10px; justify-content: flex-end; }

/* ---------- 标注与提示 ---------- */
#labels-layer { position: fixed; inset: 0; z-index: 10; pointer-events: none; overflow: hidden; }
.part-label {
  position: absolute; transform: translate(-50%, -100%);
  font-size: 12px; letter-spacing: 1px; white-space: nowrap;
  background: rgba(43,38,32,0.82); color: #f2ecdf; padding: 3px 9px; border-radius: 4px;
  pointer-events: auto; cursor: pointer; transition: background 0.2s;
}
.label-leader { position: absolute; height: 1px; background: rgba(43,38,32,0.45); transform-origin: 0 0; pointer-events: none; }
.label-leader::after { content: ""; position: absolute; left: -2px; top: -2px; width: 4px; height: 4px; border-radius: 50%; background: rgba(43,38,32,0.6); }
.part-label:hover { background: var(--red); }
#tooltip {
  position: fixed; z-index: 30; pointer-events: none;
  background: var(--ink); color: var(--paper); font-size: 12px; letter-spacing: 1px;
  padding: 4px 10px; border-radius: 4px; transform: translate(12px, 12px);
}

/* ---------- 页脚与来源 ---------- */
#credits {
  position: fixed; bottom: 12px; left: 22px; z-index: 15;
  font-size: 11px; color: var(--ink-soft); letter-spacing: 1px;
}
#credits .link { border: none; background: none; color: var(--red); font-size: 11px; cursor: pointer; text-decoration: underline; }
#sources-modal {
  position: fixed; inset: 0; z-index: 60; background: rgba(43,38,32,0.45);
  display: flex; align-items: center; justify-content: center;
}
.sources-box {
  position: relative; width: min(560px, 90vw); max-height: 80vh; overflow-y: auto;
  background: var(--paper); border-radius: 10px; border-top: 5px solid var(--red);
  padding: 26px 30px; box-shadow: var(--shadow);
}
.sources-box h2 { font-family: var(--serif); font-size: 22px; letter-spacing: 3px; margin-bottom: 12px; }
.sources-box p { font-size: 13px; line-height: 1.9; color: var(--ink-soft); margin-bottom: 10px; }
.sources-box ul { list-style: none; margin: 10px 0; }
.sources-box li { font-size: 12px; line-height: 1.8; padding: 4px 0; border-bottom: 1px dashed rgba(43,38,32,0.15); }
.sources-box a { color: var(--red); text-decoration: none; }
.sources-box a:hover { text-decoration: underline; }
.sources-note { font-size: 11px !important; color: var(--gold) !important; }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  #masthead h1 { font-size: 20px; }
  #masthead p { display: none; }
  #controls { width: calc(100vw - 44px); bottom: 40px; }
  #info-card { width: calc(100vw - 44px); right: 22px; top: auto; bottom: 190px; max-height: 45vh; }
  #catalog { width: calc(100vw - 44px); }
  #tour-bar { width: calc(100vw - 44px); bottom: auto; top: 80px; }
  #toolbar { top: auto; bottom: 4px; right: 12px; gap: 4px; }
  .tool { padding: 6px 9px; font-size: 12px; }
  #credits { display: none; }
}