@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-panel: rgba(26, 26, 46, 0.95);
  --text-primary: #e6e6e6;
  --text-muted: #8b949e;
  --text-dimmed: #6e7681;
  --border-subtle: rgba(240, 246, 252, 0.1);
  --domain-physics: #5B8DEF;
  --domain-math: #EF5B5B;
  --domain-ee: #5BEF7B;
  --domain-rf: #EFB85B;
  --panel-width: 400px;
  --header-height: 60px;
  --transition-speed: 300ms;
  --font-stack: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-stack);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
  gap: 20px;
}

.header-left {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex-shrink: 0;
  gap: 2px;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  white-space: nowrap;
  margin: 0;
}

.header-subtitle {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
  white-space: nowrap;
  margin: 0;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.domain-filters {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.domain-toggle {
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-stack);
  cursor: pointer;
  transition: all var(--transition-speed) ease;
  border: 1.5px solid;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 72px;
}

.domain-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  display: none;
}

.domain-toggle:not(.active) .domain-indicator {
  display: inline-block;
}

.domain-label {
  letter-spacing: 0.02em;
}

.domain-toggle[data-domain="physics"] {
  color: var(--domain-physics);
  border-color: rgba(91, 141, 239, 0.3);
}
.domain-toggle[data-domain="physics"].active {
  background: rgba(91, 141, 239, 0.2);
  border-color: var(--domain-physics);
  color: var(--domain-physics);
}

.domain-toggle[data-domain="math"] {
  color: var(--domain-math);
  border-color: rgba(239, 91, 91, 0.3);
}
.domain-toggle[data-domain="math"].active {
  background: rgba(239, 91, 91, 0.2);
  border-color: var(--domain-math);
  color: var(--domain-math);
}

.domain-toggle[data-domain="ee"] {
  color: var(--domain-ee);
  border-color: rgba(91, 239, 123, 0.3);
}
.domain-toggle[data-domain="ee"].active {
  background: rgba(91, 239, 123, 0.2);
  border-color: var(--domain-ee);
  color: var(--domain-ee);
}

.domain-toggle[data-domain="rf"] {
  color: var(--domain-rf);
  border-color: rgba(239, 184, 91, 0.3);
}
.domain-toggle[data-domain="rf"].active {
  background: rgba(239, 184, 91, 0.2);
  border-color: var(--domain-rf);
  color: var(--domain-rf);
}

.domain-toggle:not(.active):hover {
  border-color: currentColor;
  background: rgba(255, 255, 255, 0.04);
}

.domain-toggle:not(.active) {
  opacity: 0.5;
}

.domain-toggle:not(.active):hover {
  opacity: 0.8;
}

.search-container {
  position: relative;
  flex-shrink: 1;
  min-width: 180px;
  max-width: 280px;
}

.search-input {
  width: 100%;
  padding: 8px 32px 8px 36px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-stack);
  outline: none;
  transition: border-color var(--transition-speed) ease, background var(--transition-speed) ease;
}

.search-input::placeholder {
  color: var(--text-dimmed);
}

.search-input:focus {
  border-color: rgba(91, 141, 239, 0.5);
  background: rgba(255, 255, 255, 0.09);
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-dimmed);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  font-family: var(--font-stack);
}

.search-clear:hover {
  color: var(--text-primary);
}

/* ===== Hide library navigation hint ===== */
.scene-nav-info {
  display: none !important;
}

/* ===== 3D Graph Container ===== */
#graph-container {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
}

#graph-3d,
#graph-svg {
  width: 100%;
  height: 100%;
}

#graph-3d canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
  outline: none;
}

/* ===== Tooltip ===== */
.tooltip {
  position: absolute;
  padding: 12px 16px;
  background: rgba(22, 27, 34, 0.95);
  border: 1px solid var(--border-subtle);
  border-top: 2px solid var(--text-dimmed);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-primary);
  pointer-events: none;
  max-width: 320px;
  z-index: 300;
  backdrop-filter: blur(8px);
  line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.tooltip-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.tooltip-body {
  color: var(--text-muted);
  font-size: 11px;
}

/* ===== Side Panel ===== */
.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--panel-width);
  background: var(--bg-panel);
  border-left: 3px solid var(--text-muted);
  transform: translateX(100%);
  transition: transform var(--transition-speed) ease, width var(--transition-speed) ease;
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  backdrop-filter: blur(12px);
}

.side-panel.panel-expanded {
  width: clamp(500px, 50vw, 800px);
}

.side-panel.visible {
  transform: translateX(0);
}

.side-panel[data-domain="physics"] { border-left-color: var(--domain-physics); }
.side-panel[data-domain="math"] { border-left-color: var(--domain-math); }
.side-panel[data-domain="ee"] { border-left-color: var(--domain-ee); }
.side-panel[data-domain="rf"] { border-left-color: var(--domain-rf); }

.panel-expand {
  position: absolute;
  top: 16px;
  right: 56px;
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(240, 246, 252, 0.2);
  border-radius: 8px;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-speed) ease;
  z-index: 1;
}

.panel-expand:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(240, 246, 252, 0.35);
}

.panel-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(240, 246, 252, 0.2);
  border-radius: 8px;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-speed) ease;
  z-index: 1;
}

.panel-close:hover {
  background: rgba(255, 255, 255, 0.18);
  border-color: rgba(240, 246, 252, 0.35);
}

.panel-domain-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 24px 24px 12px 24px;
}

.panel-domain-badge[data-domain="physics"] {
  background: rgba(91, 141, 239, 0.15);
  color: var(--domain-physics);
}
.panel-domain-badge[data-domain="math"] {
  background: rgba(239, 91, 91, 0.15);
  color: var(--domain-math);
}
.panel-domain-badge[data-domain="ee"] {
  background: rgba(91, 239, 123, 0.15);
  color: var(--domain-ee);
}
.panel-domain-badge[data-domain="rf"] {
  background: rgba(239, 184, 91, 0.15);
  color: var(--domain-rf);
}

#panel-domain-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.panel-title {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
  line-height: 1.3;
  margin: 0 24px 6px 24px;
  padding-right: 56px;
}

.panel-level {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 24px 8px 24px;
  text-transform: capitalize;
}

.panel-content {
  padding: 8px 24px 24px 24px;
  overflow-y: auto;
  flex: 1;
}

.panel-content::-webkit-scrollbar {
  width: 6px;
}

.panel-content::-webkit-scrollbar-track {
  background: transparent;
}

.panel-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.panel-content::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.18);
}

.panel-section {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.panel-section:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.panel-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dimmed);
  margin-bottom: 10px;
}

.panel-terms {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.panel-term {
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-primary);
  font-weight: 400;
}

.panel-text {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-muted);
}

.panel-text p {
  margin-bottom: 8px;
}

.panel-text strong {
  color: var(--text-primary);
  font-weight: 600;
}

.panel-connections {
  list-style: none;
}

.connection-item {
  padding: 8px 12px;
  margin-bottom: 4px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition-speed) ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.connection-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.connection-item .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.connection-item .edge-type {
  font-size: 10px;
  color: var(--edge-color, var(--text-dimmed));
  margin-left: auto;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: color-mix(in srgb, var(--edge-color, var(--text-dimmed)) 15%, transparent);
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
  white-space: nowrap;
}

/* ===== Legend ===== */
.legend {
  position: fixed;
  bottom: 20px;
  left: 20px;
  background: rgba(22, 27, 34, 0.85);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 12px 16px;
  z-index: 50;
  backdrop-filter: blur(8px);
  min-width: 160px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.legend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.legend-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dimmed);
  margin-bottom: 0;
}

.legend-toggle {
  background: none;
  border: none;
  color: var(--text-dimmed);
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition-speed) ease, transform var(--transition-speed) ease;
}

.legend-toggle:hover {
  color: var(--text-muted);
}

.legend.legend-collapsed .legend-toggle svg {
  transform: rotate(180deg);
}

.legend.legend-collapsed .legend-section {
  display: none;
}

.legend-section-label {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dimmed);
  opacity: 0.7;
  margin-bottom: 4px;
}

.legend-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 8px;
  margin-bottom: 8px;
}

.legend-section + .legend-section {
  border-top: 1px solid var(--border-subtle);
  padding-top: 8px;
}

.legend-section:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Edge type color swatches */
.legend-edge-swatch {
  width: 24px;
  height: 4px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* Edge type 2-column grid */
.legend-edge-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
}

/* Node geometry legend shapes */
.legend-shape {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: inline-block;
}

.legend-shape-icosa {
  background: var(--text-muted);
  clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%);
}

.legend-shape-sphere {
  background: var(--text-muted);
  border-radius: 50%;
}

.legend-shape-octa {
  background: var(--text-muted);
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}

/* ===== Stats Overlay ===== */
.stats-overlay {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: rgba(22, 27, 34, 0.6);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 10px 14px;
  padding-top: 12px;
  z-index: 50;
  backdrop-filter: blur(8px);
  overflow: hidden;
}

.stats-overlay::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--domain-physics), var(--domain-rf));
}

.stats-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 11px;
  line-height: 1.8;
}

.stats-label {
  color: var(--text-dimmed);
}

.stats-value {
  color: var(--text-muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ===== View Controls ===== */
.view-controls {
  position: absolute;
  top: 12px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 4px;
  z-index: 50;
  background: rgba(22, 27, 34, 0.85);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 4px;
  backdrop-filter: blur(8px);
}

.view-btn {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  font-family: var(--font-stack);
  cursor: pointer;
  transition: all var(--transition-speed) ease;
}

.view-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.view-btn.active {
  background: rgba(91, 141, 239, 0.3);
  border-color: rgba(91, 141, 239, 0.5);
  color: var(--text-primary);
}

.view-divider {
  width: 1px;
  height: 20px;
  background: var(--border-subtle);
  margin: 0 2px;
}

.view-switch-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dimmed);
  text-decoration: none;
  border: 1px solid var(--border-subtle);
  padding: 3px 10px;
  border-radius: 12px;
  transition: all var(--transition-speed) ease;
}

.view-switch-link:hover {
  color: var(--text-muted);
  border-color: rgba(240, 246, 252, 0.2);
  background: rgba(255, 255, 255, 0.04);
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .side-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 60vh;
    max-height: 60vh;
    border-left: none;
    border-top: 3px solid var(--text-muted);
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
  }

  .side-panel.visible {
    transform: translateY(0);
  }

  .side-panel[data-domain="physics"] { border-top-color: var(--domain-physics); border-left-color: transparent; }
  .side-panel[data-domain="math"] { border-top-color: var(--domain-math); border-left-color: transparent; }
  .side-panel[data-domain="ee"] { border-top-color: var(--domain-ee); border-left-color: transparent; }
  .side-panel[data-domain="rf"] { border-top-color: var(--domain-rf); border-left-color: transparent; }

  #header {
    padding: 0 16px;
    gap: 12px;
  }

  .header-subtitle {
    display: none;
  }

  .domain-toggle {
    padding: 4px 10px;
    font-size: 11px;
  }

  .search-container {
    min-width: 140px;
  }

  .legend {
    bottom: 12px;
    left: 12px;
    padding: 10px 14px;
  }

  .stats-overlay {
    bottom: 12px;
    right: 12px;
  }
}
