:root {
  --bg: #060913;
  --ink: #e8ecf6;
  --dim: #93a0b8;
  --panel: rgba(13, 18, 32, .86);
  --line: rgba(148, 163, 190, .18);
  --accent: #8ab6ff;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: radial-gradient(1200px 800px at 70% 20%, #0b1226 0%, var(--bg) 55%);
  color: var(--ink);
  font: 14px/1.6 -apple-system, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#gl.dragging { cursor: grabbing; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: 0; left: 0; padding: 22px 26px;
  max-width: min(520px, 92vw);
  pointer-events: none;
  z-index: 5;
}
#hud h1 {
  font-family: "Songti SC", "Noto Serif SC", serif;
  font-size: 30px; letter-spacing: .12em; font-weight: 700;
  text-shadow: 0 0 24px rgba(138, 182, 255, .35);
}
#hud .tagline { margin-top: 6px; color: var(--ink); opacity: .92; }
#hud .tagline b { color: var(--accent); font-variant-numeric: tabular-nums; }
#hud .source { margin-top: 2px; font-size: 12px; color: var(--dim); }
#hud .source a { color: var(--dim); pointer-events: auto; }
#hud .source a:hover { color: var(--accent); }

#chips { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 7px; pointer-events: auto; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(10, 15, 28, .55);
  color: var(--ink); font-size: 12.5px; cursor: pointer;
  transition: opacity .15s, border-color .15s, transform .1s;
  user-select: none; -webkit-user-select: none;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); box-shadow: 0 0 8px var(--c); }
.chip .n { color: var(--dim); font-size: 11px; font-variant-numeric: tabular-nums; }
.chip:hover { border-color: var(--c); }
.chip.off { opacity: .32; }
.chip.off .dot { box-shadow: none; }
.chip:active { transform: scale(.96); }

/* ---------- 搜索 ---------- */
#searchbox { position: fixed; top: 22px; right: 24px; z-index: 6; width: min(300px, 60vw); }
#search {
  width: 100%; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  font: inherit; font-size: 13px; outline: none; backdrop-filter: blur(10px);
}
#search:focus { border-color: var(--accent); }
#search::placeholder { color: var(--dim); }
#search-results {
  margin-top: 8px; border-radius: 14px; overflow: hidden auto; max-height: 46vh;
  border: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(14px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}
.sr {
  display: flex; align-items: baseline; gap: 8px; width: 100%;
  padding: 8px 13px; border: 0; background: none; color: var(--ink);
  font: inherit; font-size: 13px; text-align: left; cursor: pointer;
}
.sr:hover, .sr.active { background: rgba(138, 182, 255, .12); }
.sr .dot { flex: none; width: 7px; height: 7px; border-radius: 50%; align-self: center; }
.sr .lb { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr .ctx { flex: none; color: var(--dim); font-size: 11px; }

/* ---------- 提示 ---------- */
#hint {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  color: var(--dim); font-size: 12px; letter-spacing: .04em;
  padding: 5px 14px; border-radius: 999px; background: rgba(8, 12, 24, .5);
  pointer-events: none; z-index: 4; white-space: nowrap;
}

/* ---------- 学科漂浮标签 ---------- */
#subject-labels { position: fixed; inset: 0; pointer-events: none; z-index: 3; }
.slabel {
  position: absolute; transform: translate(-50%, -50%);
  font-family: "Songti SC", "Noto Serif SC", serif;
  font-size: 15px; letter-spacing: .3em; color: var(--c);
  text-shadow: 0 0 12px color-mix(in srgb, var(--c) 60%, transparent);
  opacity: .8; white-space: nowrap; transition: opacity .2s;
}
.slabel.hidden { opacity: 0; }

/* ---------- 详情卡 ---------- */
#card {
  position: fixed; right: 24px; top: 84px; z-index: 7;
  width: min(340px, calc(100vw - 32px));
  max-height: calc(100vh - 120px); overflow-y: auto;
  padding: 18px 18px 16px; border-radius: 18px;
  background: var(--panel); border: 1px solid var(--line);
  backdrop-filter: blur(16px);
  box-shadow: 0 18px 60px rgba(0, 0, 0, .55);
  animation: cardin .18s ease-out;
}
@keyframes cardin { from { opacity: 0; transform: translateY(8px); } }
#card-close {
  position: absolute; top: 10px; right: 12px;
  border: 0; background: none; color: var(--dim); font-size: 20px; cursor: pointer;
}
#card-close:hover { color: var(--ink); }
#card .kind {
  display: inline-block; font-size: 11px; letter-spacing: .15em;
  padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--kc, var(--line)); color: var(--kc, var(--dim));
}
#card h2 { margin: 9px 0 4px; font-size: 18px; line-height: 1.45; font-weight: 600; }
.bookrow { display: flex; gap: 11px; margin: 10px 0 4px; align-items: center; }
.bookrow img {
  width: 46px; height: 62px; object-fit: cover; border-radius: 5px;
  background: #1a2137; box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
}
.bookrow .dim, .dim { color: var(--dim); font-size: 12px; }
#card-chain { margin: 12px 0 4px; list-style: none; }
#card-chain li {
  position: relative; padding: 5px 0 5px 18px; font-size: 13px;
  border-left: 1px solid var(--line); margin-left: 5px;
}
#card-chain li::before {
  content: ""; position: absolute; left: -3.5px; top: 12px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--dim);
}
#card-chain li.cur::before { background: var(--kc, var(--accent)); box-shadow: 0 0 8px var(--kc, var(--accent)); }
#card-chain li .role { display: block; font-size: 10.5px; letter-spacing: .1em; color: var(--dim); }
#card-chain li a { color: var(--ink); text-decoration: none; cursor: pointer; }
#card-chain li a:hover { color: var(--accent); }
#card-chain li.cur > span { color: var(--ink); }
.cta {
  display: block; margin-top: 12px; padding: 9px 0; text-align: center;
  border-radius: 12px; background: rgba(138, 182, 255, .14);
  border: 1px solid rgba(138, 182, 255, .4); color: var(--accent);
  text-decoration: none; font-size: 13.5px; letter-spacing: .05em;
}
.cta:hover { background: rgba(138, 182, 255, .24); }

/* ---------- tooltip ---------- */
#tooltip {
  position: fixed; z-index: 8; pointer-events: none;
  padding: 5px 11px; border-radius: 9px; max-width: 300px;
  background: rgba(9, 13, 26, .92); border: 1px solid var(--line);
  font-size: 12.5px; color: var(--ink);
  transform: translate(12px, -50%);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#tooltip .ctx { color: var(--dim); font-size: 11px; margin-left: 6px; }

/* ---------- loading ---------- */
#loading {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: var(--bg); color: var(--dim); letter-spacing: .2em; font-size: 13px;
  transition: opacity .5s;
}
#loading.done { opacity: 0; pointer-events: none; visibility: hidden; transition: opacity .5s, visibility 0s .5s; }
#loading .orb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 30px var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(.55); opacity: .5; } }

/* ---------- 移动端 ---------- */
@media (max-width: 640px) {
  #hud { padding: 14px 16px; }
  #hud h1 { font-size: 22px; }
  #hud .tagline { font-size: 12.5px; line-height: 1.5; }
  #searchbox { top: auto; bottom: 52px; right: 12px; left: 12px; width: auto; }
  #search-results { position: absolute; bottom: 100%; margin: 0 0 8px; width: 100%; }
  #hint { bottom: 12px; font-size: 10.5px; max-width: 94vw; white-space: normal; text-align: center; }
  #card {
    right: 8px; left: 8px; top: auto; bottom: 104px; width: auto;
    max-height: 46vh;
  }
}
