/* Autonomous-driving research-insight 3D atlas — visual chrome.
   The WebGL canvas owns the page; the HTML chrome is a thin overlay. */

:root {
  --bg-deep: #03040b;
  --bg-mid:  #070a1c;
  --ink:     #e6edf3;
  --ink-dim: #95a3b8;
  --ink-mute:#586378;
  --line:    #1f2638;
  --line-bright: #2d3a55;
  --accent:  #6cb1ff;
  --accent-warm:#ffaa55;
  --accent-strong:#ff6b6b;
  --accent-soft:#a78bfa;
  --pane-bg: rgba(8, 12, 24, 0.72);
  --pane-bg-strong: rgba(8, 12, 24, 0.92);
  --pane-border: rgba(91, 117, 161, 0.28);
  --chip-bg: rgba(22, 30, 50, 0.78);
  --chip-bg-active: rgba(108, 177, 255, 0.22);
  --shadow-soft: 0 10px 35px rgba(0, 0, 0, 0.45);
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: radial-gradient(ellipse at 50% 40%, #0b1129 0%, #03040b 60%, #000000 100%);
}

body { -webkit-font-smoothing: antialiased; }

canvas#atlasCanvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  z-index: 0;
}

/* ---------- top bar ---------- */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: linear-gradient(180deg, rgba(3,5,15,0.86) 0%, rgba(3,5,15,0.35) 75%, transparent 100%);
  backdrop-filter: blur(8px);
  pointer-events: auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo {
  font-size: 22px;
  color: var(--accent);
  text-shadow: 0 0 12px rgba(108,177,255,0.65);
}
.brand .title-block { display: flex; flex-direction: column; line-height: 1.15; }
.brand .title { font-weight: 600; font-size: 15px; }
.brand .subtitle { font-size: 11px; color: var(--ink-dim); }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.topbar-actions input[type="search"] {
  background: var(--chip-bg);
  border: 1px solid var(--pane-border);
  color: var(--ink);
  padding: 7px 11px;
  border-radius: 8px;
  font-size: 13px;
  width: 280px;
  outline: none;
}
.topbar-actions input[type="search"]:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(108,177,255,0.25); }

.iconbtn {
  background: var(--chip-bg);
  border: 1px solid var(--pane-border);
  color: var(--ink);
  border-radius: 8px;
  padding: 6px 11px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}
.iconbtn:hover { background: rgba(108,177,255,0.22); border-color: rgba(108,177,255,0.55); }
.iconbtn.active { background: rgba(255,170,85,0.22); border-color: rgba(255,170,85,0.55); color: var(--accent-warm); }

/* ---------- side panels ---------- */
.side-panel {
  position: fixed;
  top: 60px;
  bottom: 12px;
  width: 320px;
  background: var(--pane-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--pane-border);
  border-radius: var(--radius);
  padding: 14px 14px 18px;
  overflow-y: auto;
  z-index: 25;
  box-shadow: var(--shadow-soft);
}
.side-panel.left  { left: 12px; }
.side-panel.right { right: 12px; width: 460px; }
.side-panel.collapsed { transform: translateX(-110%); }
.side-panel[aria-hidden="true"].right { transform: translateX(110%); pointer-events: none; }
.side-panel.right { transition: transform 0.28s ease; }
.side-panel.left  { transition: transform 0.28s ease; }

.pane-section { margin-bottom: 18px; }
.pane-section h3 {
  margin: 0 0 8px;
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
  font-weight: 600;
}
.layer-buttons { display: flex; flex-direction: column; gap: 6px; }
.layer-btn {
  text-align: left;
  background: var(--chip-bg);
  border: 1px solid var(--pane-border);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.layer-btn:hover { background: rgba(108,177,255,0.22); }
.layer-btn.active { background: rgba(108,177,255,0.32); border-color: var(--accent); color: var(--accent); }
.hint { font-size: 11.5px; color: var(--ink-mute); margin-top: 8px; line-height: 1.5; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--chip-bg);
  border: 1px solid var(--pane-border);
  color: var(--ink);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 11.5px;
  font-family: inherit;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.chip:hover { background: rgba(108,177,255,0.18); }
.chip.active { background: var(--chip-bg-active); border-color: rgba(108,177,255,0.55); color: var(--accent); }
.chip .swatch { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.legend li { font-size: 11.5px; color: var(--ink-dim); display: flex; align-items: center; gap: 8px; }
.legend .swatch { width: 16px; height: 3px; border-radius: 2px; flex-shrink: 0; }
.legend .swatch.dashed { background-image: linear-gradient(90deg, currentColor 50%, transparent 50%); background-size: 6px 100%; }

.time-row { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; font-size: 12px; color: var(--ink-dim); }
input#yearSlider { width: 100%; accent-color: var(--accent); }

.graph-stats p { font-size: 11.5px; color: var(--ink-mute); line-height: 1.6; margin: 0; }

/* ---------- right side card ---------- */
.rp-header { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.rp-header .iconbtn.close, .rp-header #closeRight {
  flex-shrink: 0;
  font-size: 16px;
  padding: 2px 9px;
}
.rp-title-block { display: flex; flex-direction: column; flex: 1; }
.rp-kind { font-size: 10.5px; color: var(--accent-warm); letter-spacing: 0.06em; text-transform: uppercase; }
.rp-title { font-size: 16px; font-weight: 600; color: var(--ink); line-height: 1.3; margin-top: 2px; word-break: break-word; overflow-wrap: break-word; }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.tab {
  background: transparent;
  border: none;
  color: var(--ink-dim);
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  border-radius: 6px 6px 0 0;
  font-family: inherit;
}
.tab.active { color: var(--accent); background: rgba(108,177,255,0.10); }
.card-body { font-size: 13.5px; line-height: 1.65; color: var(--ink); overflow-wrap: break-word; }
.card-body h1, .card-body h2, .card-body h3 { color: var(--accent-warm); margin-top: 18px; margin-bottom: 6px; }
.card-body h1 { font-size: 18px; }
.card-body h2 { font-size: 15px; }
.card-body h3 { font-size: 13.5px; color: var(--accent); }
.card-body code { background: rgba(36, 50, 80, 0.6); padding: 0 4px; border-radius: 3px; font-size: 0.9em; }
.card-body pre { background: rgba(10, 16, 30, 0.85); padding: 10px 12px; border-radius: 8px; overflow-x: auto; font-size: 12px; }
.card-body a { color: var(--accent); text-decoration: none; border-bottom: 1px dashed rgba(108,177,255,0.4); }
.card-body a:hover { color: var(--accent-warm); border-bottom-color: var(--accent-warm); }
.card-body blockquote { border-left: 3px solid var(--accent); padding-left: 10px; color: var(--ink-dim); margin: 10px 0; }
.card-body ul, .card-body ol { padding-left: 22px; }
.card-body table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 12.5px; }
.card-body th, .card-body td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.card-body .katex { font-size: 1em; }
/* Long display equations must scroll within their own box, never widen the
   panel. Without this a single wide $$…$$ (e.g. a logsumexp) pushes the whole
   card into horizontal overflow and breaks the layout. */
.card-body .katex-display,
.lens-body .katex-display { overflow-x: auto; overflow-y: hidden; max-width: 100%; padding: 2px 0 4px; }
.card-body .math-block,
.lens-body .math-block { overflow-x: auto; max-width: 100%; }
.card-body .math-display,
.lens-body .math-display { display: inline-block; max-width: 100%; overflow-x: auto; vertical-align: middle; }

.trace-block { background: rgba(108,177,255,0.08); border-left: 3px solid var(--accent); padding: 10px 12px; margin: 10px 0; border-radius: 4px; }
.trace-block h4 { margin: 0 0 6px; font-size: 12.5px; color: var(--accent); letter-spacing: 0.04em; text-transform: uppercase; }
.trace-block ul { padding-left: 18px; margin: 4px 0; }
.trace-block li { font-size: 12.5px; line-height: 1.55; cursor: pointer; }
.trace-block li:hover { color: var(--accent-warm); }
.trace-block .blockkind { font-size: 10.5px; color: var(--ink-mute); margin-right: 6px; }

/* ---------- dynamic insight panel ---------- */
.insight-report {
  margin-top: 24px;
  padding: 14px 16px;
  background: rgba(108, 177, 255, 0.06);
  border: 1px solid rgba(108, 177, 255, 0.22);
  border-radius: 8px;
}
.insight-report h2 {
  margin-top: 0;
  margin-bottom: 6px;
  font-size: 14px;
  color: var(--accent-warm);
  letter-spacing: 0.04em;
}
.insight-summary {
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink);
  margin: 0 0 10px;
}
.insight-hint {
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink-mute);
  margin: 0 0 10px;
}
/* ---------- research lens ---------- */
.lens-title {
  margin-top: 0;
  margin-bottom: 6px;
  font-size: 14px;
  color: var(--accent-warm);
  letter-spacing: 0.04em;
}
.lens-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
  margin: 8px 0 20px;
}
.lens-cell {
  border-left: 2px solid rgba(108, 177, 255, 0.4);
  padding: 2px 0 2px 12px;
}
.lens-cell h4 {
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 0.04em;
  margin: 0 0 5px;
}
.lens-body {
  font-size: 12.8px;
  line-height: 1.62;
  color: var(--ink);
}
.lens-body p { margin: 0 0 6px; }
.lens-body p:last-child { margin-bottom: 0; }
.lens-body code { font-size: 0.92em; }
.lens-body .katex { font-size: 1em; }
.reused-list {
  padding-left: 18px;
  margin: 0;
  list-style: disc;
}
.reused-list li {
  font-size: 12.5px;
  line-height: 1.55;
  margin-bottom: 3px;
}
.insight-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px 16px;
  margin-top: 8px;
}
.insight-cell h4 {
  font-size: 12px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 4px;
}
.insight-cell p {
  font-size: 12.5px;
  line-height: 1.55;
  margin: 0;
  color: var(--ink);
}
.insight-cell p.insight-empty {
  color: var(--ink-mute);
  font-style: italic;
}
.next-suggestions {
  padding-left: 18px;
  margin: 0;
}
.next-suggestions li {
  font-size: 12.5px;
  line-height: 1.55;
  margin-bottom: 3px;
}
.open-problems {
  padding-left: 18px;
  margin: 0;
  list-style: disc;
}
.open-problems li {
  font-size: 12.5px;
  line-height: 1.55;
  margin-bottom: 3px;
}
@media (max-width: 920px) {
  .insight-grid { grid-template-columns: 1fr; }
  .lens-grid { grid-template-columns: 1fr; }
}

/* ---------- mermaid diagrams ---------- */
.mermaid-rendered {
  background: rgba(8, 12, 24, 0.55);
  border: 1px solid rgba(91, 117, 161, 0.2);
  border-radius: 8px;
  padding: 14px 12px;
  margin: 14px 0;
  overflow-x: auto;
  text-align: center;
}
.mermaid-rendered svg { max-width: 100%; height: auto; display: inline-block; }
/* Pull diagram text onto the dark theme. mermaid's dark theme is close but
   uses its own palette — we nudge the few inline `fill` colours that bleed
   through so labels stay legible on the card background. */
.mermaid-rendered svg .nodeLabel,
.mermaid-rendered svg .edgeLabel,
.mermaid-rendered svg foreignObject div,
.mermaid-rendered svg foreignObject span {
  color: var(--ink) !important;
  fill: var(--ink) !important;
  background: transparent !important;
}
.mermaid-rendered svg .edgePath path,
.mermaid-rendered svg .flowchart-link {
  stroke: var(--accent);
}
.mermaid-rendered svg .marker { fill: var(--accent); stroke: var(--accent); }
.mermaid-rendered svg .cluster rect {
  fill: rgba(108,177,255,0.06) !important;
  stroke: rgba(108,177,255,0.35) !important;
}

.mermaid-error {
  border-left: 3px solid var(--accent-strong);
  background: rgba(255, 107, 107, 0.10);
  color: var(--accent-strong);
  font-size: 11.5px;
  padding: 6px 10px;
  margin: 10px 0 4px;
  border-radius: 4px;
  letter-spacing: 0.04em;
}
.mermaid-error::before {
  content: "图未能渲染";
  font-weight: 600;
}

/* ---------- HUD overlay (3D labels) ---------- */
.hud-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}
.hud-label {
  position: absolute;
  transform: translate(-50%, -100%);
  background: rgba(8, 12, 24, 0.72);
  border: 1px solid rgba(255,255,255,0.10);
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 10.5px;
  color: var(--ink);
  white-space: nowrap;
  pointer-events: none;
  text-shadow: 0 0 4px rgba(0,0,0,0.9);
  transition: opacity 0.15s ease;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-label.dim { opacity: 0.18; }
.hud-label.highlight {
  background: rgba(255, 170, 85, 0.92);
  color: #0f172a;
  border-color: rgba(255,170,85,0.85);
  font-weight: 600;
  text-shadow: none;
  z-index: 5;
}
.hud-label.paradigm {
  font-size: 14px;
  letter-spacing: 0.15em;
  font-weight: 700;
  background: transparent;
  border: none;
  text-shadow: 0 0 18px rgba(255,170,85,0.6), 0 0 6px rgba(0,0,0,0.95);
  color: #ffe9c8;
}
.hud-label.pulsing {
  animation: pulse-glow 1.6s ease-in-out infinite;
  border-color: rgba(255, 210, 130, 0.85);
}
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 200, 120, 0.0); transform: translate(-50%, -100%) scale(1); }
  50%      { box-shadow: 0 0 14px 4px rgba(255, 200, 120, 0.55); transform: translate(-50%, -100%) scale(1.06); }
}

/* anchor-link bodies are rewritten card links; the .inert variant is one whose
   target id was not found in the graph and should not look clickable. */
.card-body a.anchor-link { cursor: pointer; }
.card-body a.anchor-link.inert {
  color: var(--ink-mute);
  cursor: not-allowed;
  border-bottom-style: dotted;
}

/* ---------- context HUD (hover detail) ---------- */
.context-hud {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  pointer-events: none;
}
.context-hover {
  background: var(--pane-bg-strong);
  border: 1px solid var(--pane-border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 12.5px;
  color: var(--ink);
  max-width: 520px;
  display: none;
  box-shadow: var(--shadow-soft);
}
.context-hover.visible { display: block; }
.context-hover .ch-kind { font-size: 10.5px; color: var(--accent-warm); letter-spacing: 0.06em; text-transform: uppercase; }
.context-hover .ch-title { font-size: 14px; font-weight: 600; margin: 2px 0 4px; }
.context-hover .ch-summary { font-size: 12px; color: var(--ink-dim); line-height: 1.5; }
.context-hover .ch-meta { font-size: 10.5px; color: var(--ink-mute); margin-top: 4px; }

/* ---------- loading overlay ---------- */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 50%, #0b1129 0%, #030712 70%);
  transition: opacity 0.5s ease;
}
.loading-overlay.fade { opacity: 0; pointer-events: none; }
.loading-core { text-align: center; }
.loading-ring {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(108,177,255,0.18);
  border-top-color: var(--accent);
  border-right-color: var(--accent-warm);
  margin: 0 auto 18px;
  animation: spin 1.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-title { font-size: 16px; color: var(--ink); margin: 4px 0; }
.loading-status { font-size: 12px; color: var(--ink-dim); margin: 0; }

/* ---------- help ---------- */
.help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
}
.help-overlay.visible { display: flex; }
.help-card {
  background: var(--pane-bg-strong);
  border: 1px solid var(--pane-border);
  border-radius: 12px;
  padding: 24px 28px;
  max-width: 580px;
  position: relative;
  box-shadow: var(--shadow-soft);
}
.help-card h2 { margin-top: 0; font-size: 18px; color: var(--accent-warm); }
.help-card ul { padding-left: 18px; }
.help-card li { margin-bottom: 6px; font-size: 13px; line-height: 1.55; color: var(--ink); }
.help-card .help-note { font-size: 12px; color: var(--ink-dim); margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.help-card kbd { background: var(--chip-bg); border: 1px solid var(--pane-border); padding: 1px 6px; border-radius: 4px; font-size: 11px; }
.iconbtn.close { position: absolute; top: 12px; right: 12px; font-size: 18px; padding: 1px 9px; }

/* mobile */
@media (max-width: 920px) {
  .topbar-actions input[type="search"] { width: 160px; }
  .side-panel.left { width: 280px; }
  .side-panel.right { width: 100vw; right: 0; top: auto; bottom: 0; max-height: 72vh; border-radius: 14px 14px 0 0; }
  .brand .subtitle { display: none; }
}
@media (max-width: 640px) {
  .side-panel.left { display: none; }
  .topbar-actions input[type="search"] { width: 120px; }
}
@media (min-width: 1401px) {
  .side-panel.right { width: 520px; }
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(108,177,255,0.22); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(108,177,255,0.45); }
