:root,
[data-theme="light"] {
  --bg: #f5f6f9;
  --surface: #ffffff;
  --surface2: #eef0f5;
  --surface3: #e4e7ee;
  --border: #dce0e8;
  --border2: #c8cdd8;
  --text: #1a1d2e;
  --text2: #4a5072;
  --text3: #8890aa;
  --accent: #2b5ae0;
  --accent-bg: rgba(43, 90, 224, .08);
  --green: #0f8a3e;
  --green-bg: rgba(15, 138, 62, .08);
  --orange: #c06a08;
  --orange-bg: rgba(192, 106, 8, .1);
  --red: #c42020;
  --red-bg: rgba(196, 32, 32, .08);
  --purple: #6d28d9;
  --purple-bg: rgba(109, 40, 217, .08);
  --shadow: 0 8px 24px rgba(20, 28, 48, .08);
  --radius: 8px;
}

[data-theme="dark"] {
  --bg: #0e1018;
  --surface: #181b26;
  --surface2: #222634;
  --surface3: #2c3046;
  --border: #2e3348;
  --border2: #3d4260;
  --text: #e2e5f0;
  --text2: #aab2cf;
  --text3: #70799e;
  --accent: #6c8cff;
  --accent-bg: rgba(108, 140, 255, .12);
  --green: #4ade80;
  --green-bg: rgba(74, 222, 128, .12);
  --orange: #fb923c;
  --orange-bg: rgba(251, 146, 60, .12);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, .12);
  --purple: #a78bfa;
  --purple-bg: rgba(167, 139, 250, .12);
  --shadow: 0 10px 28px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Noto Sans SC", sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button { color: inherit; }

.kg-app {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr) 360px;
  height: 100vh;
  overflow: hidden;
}

.kg-sidebar,
.detail-pane {
  min-width: 0;
  background: var(--surface);
  border-color: var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.kg-sidebar { border-right: 1px solid var(--border); }
.detail-pane { border-left: 1px solid var(--border); }

.kg-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 17px 16px 13px;
  border-bottom: 1px solid var(--border);
}
.kg-head h1 { margin: 0; color: var(--accent); font-size: 18px; line-height: 1.2; }
.kg-head p { margin: 4px 0 0; color: var(--text3); font-size: 12px; }

.site-nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.site-nav a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  border-radius: var(--radius);
  color: var(--text2);
  text-decoration: none;
  font-size: 12px;
  border: 1px solid transparent;
}
.site-nav a:hover { background: var(--surface2); }
.site-nav a.active {
  color: var(--accent);
  border-color: var(--border);
  background: var(--accent-bg);
  font-weight: 700;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.mode-tab {
  min-height: 30px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text2);
  cursor: pointer;
  font-size: 12px;
}
.mode-tab:hover { background: var(--surface2); }
.mode-tab.active {
  background: var(--accent-bg);
  border-color: var(--border);
  color: var(--accent);
  font-weight: 700;
}

.panel { padding: 12px; border-bottom: 1px solid var(--border); }
.panel.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.view-panel { display: none; }
.view-panel.active { display: block; }
.panel-title {
  margin-bottom: 9px;
  color: var(--text3);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .7px;
  text-transform: uppercase;
}
.panel-note { margin: 0 0 9px; color: var(--text2); font-size: 12px; }

.field {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  background: var(--bg);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.field::placeholder { color: var(--text3); }
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.filter-grid label span { display: block; margin-bottom: 3px; color: var(--text3); font-size: 11px; }

.checkline {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 9px;
  color: var(--text2);
  font-size: 12px;
}
.checkline input { width: 15px; height: 15px; accent-color: var(--accent); }

.button-row, .path-row { display: flex; gap: 8px; margin-top: 9px; }
.path-row .field { width: 96px; flex-shrink: 0; }
.btn, .icon-btn {
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text2);
  cursor: pointer;
  transition: border-color .14s, background .14s, color .14s;
}
.btn { padding: 6px 12px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn:hover, .icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.05); color: #fff; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  flex-shrink: 0;
  font-size: 12px;
}

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.stat-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  padding: 9px 10px;
}
.stat-card strong { display: block; color: var(--accent); font-size: 18px; line-height: 1.1; }
.stat-card span { color: var(--text3); font-size: 11px; }

.result-box { margin-top: 9px; color: var(--text2); font-size: 12.5px; }
.result-box.compact { max-height: 150px; overflow: auto; }
.result-list { flex: 1; min-height: 0; overflow: auto; padding-right: 2px; }
.result-item {
  display: block;
  width: 100%;
  margin-bottom: 7px;
  padding: 9px 10px;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.result-item:hover { border-color: var(--accent); background: var(--accent-bg); }
.result-item strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--accent);
  font-size: 13px;
}
.result-item span {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  color: var(--text3);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kg-main { min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.graph-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.toolbar-title { min-width: 0; }
.toolbar-title strong { display: block; font-size: 15px; }
.toolbar-title span { display: block; color: var(--text3); font-size: 12px; }
.toolbar-actions { display: flex; gap: 8px; flex-shrink: 0; }
.mobile-only { display: none; }

.graph-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(rgba(120, 130, 160, .08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 130, 160, .08) 1px, transparent 1px),
    var(--bg);
  background-size: 28px 28px;
}
#graphCanvas { display: block; width: 100%; height: 100%; cursor: grab; }
#graphCanvas.dragging { cursor: grabbing; }

.legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 24px);
  overflow: hidden;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.legend-item { display: inline-flex; align-items: center; gap: 5px; color: var(--text2); font-size: 11px; white-space: nowrap; }
.swatch { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.tooltip {
  position: absolute;
  z-index: 5;
  display: none;
  max-width: 280px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 12px;
  pointer-events: none;
}
.tooltip strong { display: block; color: var(--accent); font-size: 12.5px; }

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  color: var(--text2);
  font-size: 13px;
  z-index: 10;
}
.loading.hidden { display: none; }
.loader {
  width: 34px;
  height: 34px;
  border: 3px solid var(--surface3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.detail-pane header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}
.detail-pane .panel-title { margin: 0; }
.detail-content { flex: 1; min-height: 0; overflow: auto; padding: 14px; }
.detail-content.empty { display: flex; align-items: center; justify-content: center; color: var(--text3); font-size: 13px; }

.detail-title { margin-bottom: 12px; }
.detail-title h2 { margin: 0; color: var(--text); font-size: 20px; line-height: 1.35; }
.detail-title p { margin: 5px 0 0; color: var(--text2); font-size: 12px; overflow-wrap: anywhere; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface2);
  color: var(--text2);
  font-size: 11px;
  font-weight: 700;
}
.badge.type { background: var(--purple-bg); color: var(--purple); }
.badge.high, .badge.supported, .badge.canonical, .badge.active { background: var(--green-bg); color: var(--green); }
.badge.medium, .badge.needs-review { background: var(--orange-bg); color: var(--orange); }
.badge.low, .badge.unverified, .badge.stub { background: var(--red-bg); color: var(--red); }

.detail-section {
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.detail-section h3 { margin: 0 0 8px; color: var(--text3); font-size: 11px; letter-spacing: .5px; text-transform: uppercase; }
.detail-section p { margin: 0; color: var(--text); font-size: 13px; overflow-wrap: anywhere; }
.kv { display: grid; grid-template-columns: minmax(88px, .45fr) minmax(0, 1fr); gap: 6px; margin-top: 6px; font-size: 12px; }
.kv dt { color: var(--text3); }
.kv dd { min-width: 0; margin: 0; color: var(--text); overflow-wrap: anywhere; }
.rel-list, .claim-list { display: flex; flex-direction: column; gap: 7px; }
.rel-card, .claim-card {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
}
.rel-card { cursor: pointer; }
.rel-card:hover { border-color: var(--accent); background: var(--accent-bg); }
.rel-card strong { color: var(--accent); }
.quote {
  margin-top: 7px;
  padding: 8px 10px;
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  background: var(--accent-bg);
  color: var(--text);
  overflow-wrap: anywhere;
}
.source-line { margin-top: 6px; color: var(--text3); font-size: 11px; overflow-wrap: anywhere; }
.empty-note { color: var(--text3); font-size: 12px; }
.path-chain { display: flex; flex-direction: column; gap: 5px; }
.path-step { padding: 7px 8px; border-radius: 6px; background: var(--surface2); color: var(--text2); font-size: 12px; }
.path-step strong { color: var(--accent); }
mark { padding: 0 2px; border-radius: 3px; background: var(--orange-bg); color: var(--orange); }

.mobile-scrim { display: none; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 4px; }

@media (max-width: 1180px) {
  .kg-app { grid-template-columns: 310px minmax(0, 1fr); }
  .detail-pane {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    width: min(380px, 92vw);
    box-shadow: var(--shadow);
    transform: translateX(100%);
    transition: transform .18s ease;
  }
  .detail-pane.open { transform: translateX(0); }
}

@media (max-width: 760px) {
  .kg-app { grid-template-columns: 1fr; }
  .mobile-only { display: inline-flex; }
  .kg-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: min(86vw, 330px);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow);
    transform: translateX(-105%);
    transition: transform .18s ease;
  }
  body.menu-open .kg-sidebar { transform: translateX(0); }
  .mobile-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgba(10, 14, 24, .45);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
  }
  body.menu-open .mobile-scrim { opacity: 1; pointer-events: auto; }
  .graph-toolbar { min-height: 54px; padding: 10px; }
  .toolbar-actions .btn { padding: 6px 9px; }
  .legend { display: none; }
}
