/* Graph view — full-viewport WebGL canvas with floating UI panels. */
:root {
  --g-bg: #0b0b0d;
  --g-panel: rgba(18, 18, 22, 0.62);
  --g-panel-strong: rgba(22, 22, 26, 0.78);
  --g-border: rgba(255, 255, 255, 0.09);
  --g-text: #d8d8dc;
  --g-text-dim: #8a8a93;
  --g-accent: #7dd3fc;
  --g-accent-warm: #ffd866;
  --g-focus: #7dd3fc;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--g-bg);
  color: var(--g-text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

/* Reset button defaults so semantic <button> doesn't visually break layout */
button {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

:focus-visible {
  outline: 2px solid var(--g-focus);
  outline-offset: 2px;
  border-radius: 4px;
}

#graph-container {
  position: fixed;
  inset: 0;
  background: var(--g-bg);
}
#graph-container canvas { display: block; }

/* 3d-force-graph hover tooltip — make it legible against any node color. */
.scene-tooltip {
  background: rgba(8, 8, 10, 0.94) !important;
  color: #fff !important;
  font-family: 'Inter', system-ui, sans-serif !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  padding: 8px 12px !important;
  border-radius: 8px !important;
  border: 1px solid rgba(255, 255, 255, 0.16) !important;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.7);
  letter-spacing: 0.01em;
  pointer-events: none;
  max-width: 320px;
}
.scene-tooltip .tt-action {
  color: var(--g-accent);
  font-size: 11px;
  font-weight: 500;
  margin-top: 4px;
  text-transform: lowercase;
  letter-spacing: 0.02em;
}
.scene-tooltip .tt-preview {
  color: rgba(255, 255, 255, 0.62);
  font-size: 11px;
  font-weight: 400;
  margin-top: 4px;
  line-height: 1.4;
}

/* Top bar */
.g-topbar {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  z-index: 10;
  pointer-events: none;
}
.g-topbar > * { pointer-events: auto; }

.g-title {
  font-family: 'Clash Grotesk', sans-serif;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.01em;
  border-left: 2px solid var(--g-accent);
  padding: 8px 14px;
  color: var(--g-text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.g-title:hover { color: var(--g-accent); }
.g-title svg { width: 14px; height: 14px; }

.g-search {
  flex: 1;
  max-width: 360px;
  position: relative;
}
.g-search input {
  width: 100%;
  background: var(--g-panel);
  border: 1px solid var(--g-border);
  backdrop-filter: blur(14px);
  color: var(--g-text);
  padding: 9px 14px 9px 36px;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  box-sizing: border-box;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 8px 32px rgba(0,0,0,0.35);
}
.g-search input::placeholder { color: var(--g-text-dim); }
.g-search input:focus { border-color: var(--g-accent); box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 0 0 3px rgba(125,211,252,0.18); }
.g-search::before {
  content: '';
  position: absolute;
  left: 12px;
  top: 50%;
  width: 14px;
  height: 14px;
  transform: translateY(-50%);
  background: currentColor;
  color: var(--g-text-dim);
  -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="7"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>') center/contain no-repeat;
  mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="7"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>') center/contain no-repeat;
  pointer-events: none;
}

.g-search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 360px;
  overflow-y: auto;
  background: var(--g-panel-strong);
  backdrop-filter: blur(14px);
  border: 1px solid var(--g-border);
  border-radius: 8px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 12px 36px rgba(0,0,0,0.4);
  display: none;
}
.g-search-results.visible { display: block; }
.g-search-result {
  padding: 9px 14px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
}
.g-search-result:last-child { border-bottom: none; }
.g-search-result:hover, .g-search-result.active { background: rgba(125, 211, 252, 0.08); }
.g-search-result .swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 8px;
}
.g-search-result .label-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g-search-result .kind {
  color: var(--g-text-dim);
  font-size: 11px;
  font-style: italic;
  font-family: 'Clash Grotesk', sans-serif;
}
.g-search-empty {
  padding: 14px;
  font-size: 12px;
  color: var(--g-text-dim);
  text-align: center;
}

/* Side panel */
.g-panel {
  position: fixed;
  top: 70px;
  bottom: 12px;
  left: 12px;
  width: 250px;
  background: var(--g-panel);
  border: 1px solid var(--g-border);
  backdrop-filter: blur(14px);
  border-radius: 12px;
  font-size: 13px;
  z-index: 5;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 12px 36px rgba(0,0,0,0.4);
  max-height: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.g-panel .g-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px 6px 14px;
  flex: 0 0 auto;
}
.g-panel .g-panel-head .g-panel-title {
  font-size: 11px;
  font-style: italic;
  font-family: 'Clash Grotesk', sans-serif;
  color: var(--g-text-dim);
  font-weight: 500;
  text-transform: lowercase;
  letter-spacing: 0.01em;
}
.g-panel .g-panel-help {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--g-border);
  background: transparent;
  color: var(--g-text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.g-panel .g-panel-help:hover { color: var(--g-accent); border-color: rgba(125,211,252,0.4); background: rgba(125,211,252,0.06); }
.g-panel .g-panel-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0 14px 12px 14px;
}
.g-panel .g-panel-foot {
  position: sticky;
  bottom: 0;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 10px 12px;
  background: var(--g-panel-strong);
  border-top: 1px solid var(--g-border);
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
  backdrop-filter: blur(14px);
}
.g-panel h3 {
  margin: 0 0 8px 0;
  font-size: 11px;
  font-style: italic;
  font-family: 'Clash Grotesk', sans-serif;
  color: var(--g-text-dim);
  font-weight: 500;
  text-transform: lowercase;
  letter-spacing: 0.01em;
}
.g-panel .legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  margin: 0 -8px 2px -8px;
  cursor: pointer;
  user-select: none;
  border-radius: 6px;
  width: calc(100% + 16px);
  min-height: 28px;
  box-sizing: border-box;
  font-size: 13px;
  color: var(--g-text);
  transition: background 0.15s ease;
}
.g-panel .legend-row:hover { background: rgba(255, 255, 255, 0.04); }
.g-panel .legend-row.disabled { opacity: 0.4; }
.g-panel .legend-row.disabled .swatch { opacity: 0.3; }
.g-panel .legend-row .swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 10px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
}
/* Monochrome glyph swatches for kind toggles (shape, not color) */
.g-panel .legend-row .glyph {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--g-text-dim);
  font-size: 12px;
  line-height: 1;
  font-family: ui-monospace, monospace;
  transition: color 0.15s ease;
}
.g-panel .legend-row[aria-pressed="true"] .glyph { color: var(--g-accent); }
.g-panel .legend-row .glyph.glyph-hexagon,
.g-panel .legend-row .glyph.glyph-square,
.g-panel .legend-row .glyph.glyph-triangle,
.g-panel .legend-row .glyph.glyph-pentagon {
  background: currentColor;
}
.g-panel .legend-row .glyph.glyph-hexagon {
  clip-path: polygon(25% 6.7%, 75% 6.7%, 100% 50%, 75% 93.3%, 25% 93.3%, 0% 50%);
}
.g-panel .legend-row .glyph.glyph-square {
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
}
.g-panel .legend-row .glyph.glyph-triangle {
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.g-panel .legend-row .glyph.glyph-pentagon {
  clip-path: polygon(50% 0, 100% 38%, 82% 100%, 18% 100%, 0 38%);
}
.g-panel details.sections-block { margin-top: 12px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,0.06); }
.g-panel details.sections-block > summary {
  list-style: none;
  cursor: pointer;
  font-size: 11px;
  font-style: italic;
  font-family: 'Clash Grotesk', sans-serif;
  color: var(--g-text-dim);
  font-weight: 500;
  text-transform: lowercase;
  letter-spacing: 0.01em;
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.g-panel details.sections-block > summary::-webkit-details-marker { display: none; }
.g-panel details.sections-block > summary::before {
  content: '▸';
  font-size: 10px;
  transition: transform 0.15s ease;
  display: inline-block;
}
.g-panel details.sections-block[open] > summary::before { transform: rotate(90deg); }
.g-panel .legend-row .label-text { flex: 1; }
.g-panel .legend-row .count {
  color: var(--g-text-dim);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.g-panel .filter-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.g-panel .alt-link {
  display: block;
  margin-top: 12px;
  padding: 8px 10px;
  background: rgba(125, 211, 252, 0.08);
  border: 1px solid rgba(125, 211, 252, 0.18);
  color: var(--g-accent);
  font-size: 12px;
  text-decoration: none;
  border-radius: 6px;
  text-align: center;
}
.g-panel .alt-link:hover { background: rgba(125, 211, 252, 0.14); }

.g-panel .hint {
  margin-top: 12px;
  padding: 10px;
  background: rgba(255,255,255,0.025);
  border-radius: 8px;
  color: var(--g-text-dim);
  font-size: 11px;
  line-height: 1.5;
}

.g-btn {
  background: var(--g-panel);
  border: 1px solid var(--g-border);
  backdrop-filter: blur(14px);
  color: var(--g-text);
  padding: 9px 14px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  box-sizing: border-box;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.g-btn:hover { color: var(--g-accent); border-color: rgba(125, 211, 252, 0.4); background: rgba(125,211,252,0.06); }
.g-btn[aria-pressed="true"] {
  background: rgba(125, 211, 252, 0.12);
  border-color: rgba(125, 211, 252, 0.4);
  color: var(--g-accent);
}

/* Hover info card */
.g-info {
  position: fixed;
  bottom: 12px;
  right: 12px;
  width: 320px;
  max-width: 80vw;
  background: var(--g-panel-strong);
  border: 1px solid var(--g-border);
  backdrop-filter: blur(14px);
  border-radius: 12px;
  padding: 16px 18px;
  font-size: 13px;
  z-index: 5;
  display: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 12px 36px rgba(0,0,0,0.4);
}
.g-info.visible { display: block; }
.g-info h2 {
  margin: 0 0 4px 0;
  font-size: 18px;
  font-family: 'Clash Grotesk', sans-serif;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.g-info .kind {
  color: var(--g-text-dim);
  font-size: 11px;
  font-style: italic;
  font-family: 'Clash Grotesk', sans-serif;
  margin-bottom: 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.g-info .kind .swatch {
  width: 8px; height: 8px; border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
}
.g-info .meta {
  font-size: 12px;
  color: var(--g-text-dim);
  margin-top: 8px;
  line-height: 1.55;
}
.g-info .preview {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.06);
  font-size: 12px;
  color: var(--g-text-dim);
  line-height: 1.5;
}
.g-info .preview .head {
  font-style: italic;
  font-family: 'Clash Grotesk', sans-serif;
  font-size: 11px;
  color: var(--g-text-dim);
  margin-bottom: 4px;
}
.g-info .preview ul { margin: 0; padding-left: 16px; color: var(--g-text); }
.g-info .preview li { margin-bottom: 2px; }
.g-info a {
  color: var(--g-accent);
  text-decoration: none;
  font-size: 12px;
  word-break: break-all;
}
.g-info a:hover { text-decoration: underline; }
.g-info .action-hint {
  display: inline-block;
  margin-top: 10px;
  padding: 4px 8px;
  background: rgba(125, 211, 252, 0.08);
  border: 1px solid rgba(125, 211, 252, 0.18);
  color: var(--g-accent);
  font-size: 11px;
  border-radius: 4px;
}

/* Breadcrumb chip */
.g-crumb {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--g-panel-strong);
  border: 1px solid var(--g-border);
  backdrop-filter: blur(14px);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--g-text);
  z-index: 6;
  display: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 8px 24px rgba(0,0,0,0.4);
}
.g-crumb.visible { display: inline-flex; align-items: center; gap: 6px; }
.g-crumb .arrow { color: var(--g-text-dim); }

/* Onboarding overlay */
.g-onboard {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.g-onboard.hidden { display: none; }
.g-onboard .card {
  background: var(--g-panel-strong);
  border: 1px solid var(--g-border);
  border-radius: 12px;
  padding: 24px 28px;
  max-width: 460px;
  font-size: 13px;
  color: var(--g-text);
  line-height: 1.6;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 24px 60px rgba(0,0,0,0.6);
}
.g-onboard h2 {
  font-family: 'Clash Grotesk', sans-serif;
  font-weight: 600;
  margin: 0 0 12px 0;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.g-onboard ul { padding-left: 18px; margin: 8px 0 16px 0; }
.g-onboard li { margin-bottom: 4px; }
.g-onboard kbd {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: ui-monospace, monospace;
  font-size: 11px;
}
.g-onboard .ok {
  display: inline-block;
  margin-top: 8px;
  padding: 8px 16px;
  background: var(--g-accent);
  color: #000;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.g-onboard .ok:hover { background: #a8e0fd; }

/* Loading overlay */
.g-loading {
  position: fixed;
  inset: 0;
  background: var(--g-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  z-index: 20;
  transition: opacity 0.4s ease-out;
}
.g-loading.hidden { opacity: 0; pointer-events: none; }
.g-loading .label {
  color: var(--g-text-dim);
  font-size: 13px;
  font-family: 'Inter', sans-serif;
}
.g-loading .dots {
  display: inline-flex;
  gap: 6px;
}
.g-loading .dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--g-accent);
  animation: g-pulse 1.2s ease-in-out infinite;
}
.g-loading .dots span:nth-child(2) { animation-delay: 0.2s; }
.g-loading .dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes g-pulse {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1.1); }
}

/* Toast */
.g-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--g-panel-strong);
  border: 1px solid var(--g-border);
  backdrop-filter: blur(14px);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--g-text);
  z-index: 25;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.g-toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Skip link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 12px;
  background: var(--g-accent);
  color: #000;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 100;
  text-decoration: none;
}
.skip-link:focus { top: 12px; }

/* Mobile FAB toggle — hidden on desktop */
.g-panel-toggle {
  display: none;
  position: fixed;
  bottom: 16px;
  left: 16px;
  z-index: 8;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--g-panel-strong);
  border: 1px solid var(--g-border);
  backdrop-filter: blur(14px);
  color: var(--g-text);
  border-radius: 999px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.05);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.g-panel-toggle svg { width: 16px; height: 16px; }
.g-panel-toggle:hover,
.g-panel-toggle[aria-expanded="true"] {
  background: rgba(125,211,252,0.14);
  border-color: rgba(125,211,252,0.4);
  color: var(--g-accent);
}

/* Info-card close button (mobile only — visible via media query) */
.g-info-close {
  display: none;
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--g-border);
  color: var(--g-text);
  font-size: 20px;
  line-height: 1;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

@media (max-width: 720px) {
  .g-panel-toggle { display: inline-flex; }
  .g-info-close { display: inline-flex; }

  /* Legend panel: collapsed by default, slides up when .open */
  .g-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    max-height: 70vh;
    border-radius: 16px 16px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    transform: translateY(100%);
    transition: transform 0.25s ease;
    z-index: 9;
  }
  .g-panel.open { transform: translateY(0); }

  /* Info card: bottom sheet, hidden by default; .visible (set by graph.js) shows it */
  .g-info {
    width: auto;
    left: 12px;
    right: 12px;
    bottom: 72px;
    top: auto;
    max-height: 50vh;
    overflow-y: auto;
    padding-right: 44px;
  }

  .g-search { max-width: none; }
  .g-crumb { display: none !important; }
}
