@import url('https://fonts.googleapis.com/css2?family=Frank+Ruhl+Libre:wght@300;400;700&family=Inter:wght@300;400;600&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: #0a0a1a;
  color: #e0e0e0;
  font-family: 'Inter', sans-serif;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

#stars-canvas {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  z-index: 0; pointer-events: none;
}

#graph-container {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  z-index: 1;
}

#info-panel {
  position: fixed; top: 20px; left: 20px; width: 400px;
  max-height: calc(100vh - 40px);
  background: rgba(15, 15, 35, 0.92);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(120, 80, 200, 0.3);
  border-radius: 16px;
  padding: 24px;
  z-index: 10;
  overflow-y: auto;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 60px rgba(100, 60, 180, 0.1);
}

#info-panel h1 {
  font-family: 'Frank Ruhl Libre', serif;
  font-size: 22px; font-weight: 700;
  background: linear-gradient(135deg, #c084fc, #818cf8, #67e8f9);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}

#info-panel .subtitle {
  font-size: 12px; color: #888; margin-bottom: 16px;
  letter-spacing: 0.5px;
}

#node-title {
  font-family: 'Frank Ruhl Libre', serif;
  font-size: 28px; font-weight: 700; color: #fff;
  margin-bottom: 4px; direction: rtl;
  min-height: 36px;
}

#node-category {
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 1.5px; margin-bottom: 12px;
  padding: 3px 10px; border-radius: 20px;
  display: inline-block;
}

#node-description {
  font-size: 14px; line-height: 1.7; color: #c0c0d0;
  margin-bottom: 16px; direction: rtl; text-align: right;
}

#node-cgc {
  font-size: 13px; line-height: 1.6; color: #a0a0c0;
  padding: 12px; border-radius: 10px;
  background: rgba(100, 60, 180, 0.1);
  border-right: 3px solid rgba(120, 80, 200, 0.5);
  direction: ltr; text-align: left;
  margin-bottom: 12px;
}

#node-cgc-label {
  font-size: 10px; text-transform: uppercase;
  letter-spacing: 1px; color: #8080a0; margin-bottom: 6px;
}

#node-source {
  font-size: 11px; line-height: 1.5; color: #707090;
  padding: 8px 12px; border-radius: 8px;
  background: rgba(60, 60, 100, 0.15);
  border-right: 2px solid rgba(80, 80, 140, 0.4);
  direction: rtl; text-align: right;
  margin-bottom: 12px;
}

#node-source-label {
  font-size: 10px; text-transform: uppercase;
  letter-spacing: 1px; color: #606080; margin-bottom: 4px;
}

.connections-list {
  font-size: 12px; color: #909090; margin-top: 8px;
}
.connections-list span {
  display: inline-block; padding: 2px 8px; margin: 2px;
  background: rgba(255,255,255,0.06); border-radius: 12px;
  cursor: pointer; transition: all 0.2s;
}
.connections-list span:hover {
  background: rgba(120, 80, 200, 0.3); color: #fff;
}

#legend {
  position: fixed; bottom: 20px; left: 20px;
  background: rgba(15, 15, 35, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(120, 80, 200, 0.2);
  border-radius: 12px; padding: 14px 18px;
  z-index: 10; display: flex; gap: 16px; flex-wrap: wrap;
  font-size: 11px; direction: rtl;
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot {
  width: 10px; height: 10px; border-radius: 50%;
  box-shadow: 0 0 6px currentColor;
}

#controls {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; gap: 8px; z-index: 10; flex-wrap: wrap;
  justify-content: flex-end; direction: rtl;
}
#controls button {
  background: rgba(15, 15, 35, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(120, 80, 200, 0.3);
  color: #c0c0d0; padding: 8px 14px; border-radius: 10px;
  cursor: pointer; font-size: 12px; transition: all 0.2s;
  font-family: 'Inter', sans-serif;
}
#controls button:hover {
  background: rgba(120, 80, 200, 0.3); color: #fff;
  box-shadow: 0 0 20px rgba(120, 80, 200, 0.3);
}
#controls button.active {
  background: rgba(120, 80, 200, 0.4);
  border-color: rgba(120, 80, 200, 0.6);
  color: #fff;
}

/* ── Representation Systems Drawer ── */
#rep-drawer {
  position: fixed; top: 12px; right: 12px; z-index: 100;
  direction: rtl;
}
#rep-drawer-toggle {
  background: rgba(12, 12, 30, 0.7);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(120, 80, 200, 0.35);
  color: rgba(200, 180, 255, 0.9);
  padding: 7px 16px; border-radius: 20px;
  cursor: pointer; font-size: 12px; font-weight: 500;
  font-family: 'Inter', sans-serif;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  letter-spacing: 0.3px;
}
#rep-drawer-toggle:hover {
  background: rgba(120, 80, 200, 0.15);
  border-color: rgba(120, 80, 200, 0.6);
  box-shadow: 0 0 24px rgba(120, 80, 200, 0.15);
  color: #fff;
}
#rep-drawer-toggle.open {
  background: rgba(120, 80, 200, 0.2);
  border-color: rgba(120, 80, 200, 0.6);
  color: #fff;
}
#rep-drawer-panel {
  position: absolute; top: 40px; right: 0;
  width: min(480px, calc(100vw - 40px)); max-height: calc(100vh - 120px);
  overflow-y: auto; overflow-x: hidden;
  background: rgba(8, 8, 24, 0.92);
  backdrop-filter: blur(24px) saturate(1.2);
  border: 1px solid rgba(120, 80, 200, 0.2);
  border-radius: 16px; padding: 16px 14px;
  display: grid; gap: 12px;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.6),
    0 0 1px rgba(120, 80, 200, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.03);
  /* Animation */
  opacity: 1; transform: translateY(0) scale(1);
  transform-origin: top right;
  transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
#rep-drawer-panel.hidden {
  opacity: 0; transform: translateY(-8px) scale(0.97);
  pointer-events: none;
}
.rep-drawer-header {
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(120, 80, 200, 0.12);
  margin-bottom: 2px;
}
.rep-category {
  display: grid; gap: 6px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}
.rep-category:last-child { border-bottom: none; }
.rep-cat-label {
  font-size: 9px; color: rgba(180, 160, 220, 0.5);
  text-transform: uppercase; letter-spacing: 1.2px;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  padding: 0 2px;
}
.rep-cat-items {
  display: flex; gap: 5px; flex-wrap: wrap;
}
#rep-drawer-panel button {
  background: rgba(20, 18, 40, 0.6);
  border: 1px solid rgba(120, 80, 200, 0.15);
  color: rgba(200, 190, 230, 0.75);
  padding: 5px 11px; border-radius: 14px;
  cursor: pointer; font-size: 11px;
  font-family: 'Inter', sans-serif;
  font-weight: 400;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
}
#rep-drawer-panel button:hover {
  background: rgba(120, 80, 200, 0.15);
  border-color: rgba(120, 80, 200, 0.4);
  color: #fff;
  box-shadow: 0 0 14px rgba(120, 80, 200, 0.12);
  transform: translateY(-1px);
}
#rep-drawer-panel button.active {
  background: rgba(120, 80, 200, 0.25);
  border-color: rgba(120, 80, 200, 0.6);
  color: #fff;
  box-shadow: 0 0 16px rgba(120, 80, 200, 0.2);
}
.rep-drawer-header button {
  font-weight: 600 !important;
  font-size: 12px !important;
  padding: 6px 14px !important;
}
/* Scrollbar */
#rep-drawer-panel::-webkit-scrollbar { width: 5px; }
#rep-drawer-panel::-webkit-scrollbar-track { background: transparent; }
#rep-drawer-panel::-webkit-scrollbar-thumb {
  background: rgba(120, 80, 200, 0.25); border-radius: 3px;
}
#rep-drawer-panel::-webkit-scrollbar-thumb:hover {
  background: rgba(120, 80, 200, 0.4);
}

.tooltip {
  position: absolute; pointer-events: none;
  background: rgba(15, 15, 35, 0.95);
  border: 1px solid rgba(120, 80, 200, 0.4);
  border-radius: 8px; padding: 8px 12px;
  font-size: 12px; color: #e0e0e0;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  z-index: 20; opacity: 0; transition: opacity 0.2s;
  max-width: 220px; direction: rtl;
}

#info-panel::-webkit-scrollbar { width: 4px; }
#info-panel::-webkit-scrollbar-track { background: transparent; }
#info-panel::-webkit-scrollbar-thumb { background: rgba(120,80,200,0.3); border-radius: 2px; }

/* Tab bar */
#panel-tabs {
  display: flex; gap: 2px; margin: 12px 0 0 0;
  border-bottom: 1px solid rgba(120, 80, 200, 0.15);
  padding-bottom: 0;
}
.panel-tab {
  background: transparent;
  border: none; border-bottom: 2px solid transparent;
  color: rgba(200, 200, 220, 0.5);
  padding: 8px 14px; cursor: pointer;
  font-size: 12px; font-family: 'Inter', sans-serif;
  font-weight: 500; letter-spacing: 0.3px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 6px 6px 0 0;
}
.panel-tab:hover {
  color: rgba(200, 200, 220, 0.8);
  background: rgba(120, 80, 200, 0.05);
}
.panel-tab.active {
  color: #c8b8ff;
  border-bottom-color: rgba(120, 80, 200, 0.7);
  background: rgba(120, 80, 200, 0.08);
}

/* Tab content */
#panel-content {
  position: relative; min-height: 100px;
  margin-top: 10px;
}
.tab-pane {
  display: none;
  animation: tabFadeIn 0.2s ease-out;
}
.tab-pane.active { display: block; }
@keyframes tabFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Math tab styling */
#node-math-content {
  font-size: 13px; line-height: 1.7;
  color: rgba(220, 220, 240, 0.85);
}
.math-placeholder {
  color: rgba(160, 160, 180, 0.5);
  font-style: italic; padding: 20px 0;
  text-align: center;
}
.math-section {
  margin-bottom: 14px;
  padding: 10px 12px;
  background: rgba(120, 80, 200, 0.04);
  border-radius: 8px;
  border-left: 3px solid rgba(120, 80, 200, 0.3);
}
.math-section-title {
  font-size: 11px; font-weight: 600;
  color: rgba(180, 160, 240, 0.7);
  text-transform: uppercase; letter-spacing: 0.8px;
  margin-bottom: 6px;
}
.math-formula {
  margin: 8px 0; padding: 8px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 6px;
  overflow-x: auto;
  text-align: center;
}
.math-explanation {
  font-size: 12px; color: rgba(200, 200, 220, 0.7);
  margin-top: 6px; line-height: 1.5;
}
.math-layer-badge {
  display: inline-block;
  background: rgba(120, 80, 200, 0.2);
  border: 1px solid rgba(120, 80, 200, 0.3);
  border-radius: 10px; padding: 2px 8px;
  font-size: 10px; color: #c8b8ff;
  margin-bottom: 8px;
}

/* Multi-representation display sections */
#node-representations {
  margin-bottom: 12px;
}
.rep-section {
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: 10px;
  background: rgba(100, 60, 180, 0.08);
  border-left: 3px solid #818cf8;
}
.rep-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
  font-weight: 600;
}
.rep-content {
  font-size: 13px;
  line-height: 1.6;
  color: #a0a0c0;
  direction: ltr;
  text-align: left;
}

/* Legend link type line samples */
.legend-separator {
  width: 100%;
  height: 1px;
  background: rgba(120, 80, 200, 0.2);
  margin: 4px 0;
}
.legend-line {
  width: 24px;
  height: 2px;
  border-radius: 1px;
  position: relative;
}
.legend-line-solid {
  background: rgba(120, 80, 200, 0.4);
  height: 1.5px;
}
.legend-line-dotted {
  background: transparent;
  border-top: 1px dashed rgba(120, 80, 200, 0.22);
  height: 0;
}
.legend-line-composes {
  background: rgba(234, 179, 8, 0.5);
  height: 2px;
}
.legend-line-feedback {
  background: transparent;
  border-top: 1.5px dashed rgba(34, 211, 238, 0.6);
  height: 0;
  animation: feedback-dash 1s linear infinite;
}

/* Feedback link dash-offset animation */
@keyframes feedback-dash-down {
  from { stroke-dashoffset: 0; }
  to { stroke-dashoffset: -18; }
}
@keyframes feedback-dash-up {
  from { stroke-dashoffset: 0; }
  to { stroke-dashoffset: 18; }
}
@keyframes feedback-dash {
  from { border-top-color: rgba(34, 211, 238, 0.6); }
  to { border-top-color: rgba(34, 211, 238, 0.3); }
}

.link-feedback {
  animation: feedback-dash-down 1s linear infinite;
}
.link-feedback-up {
  animation: feedback-dash-up 1s linear infinite;
}
.link-feedback-down {
  animation: feedback-dash-down 1s linear infinite;
}

/* LOD aggregate badges */
.lod-badge {
  font-size: 9px;
  font-weight: 600;
  fill: #fff;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

#lang-switcher {
  position: fixed; top: 14px; right: 120px;
  display: flex; gap: 4px; z-index: 10;
}
#lang-switcher button {
  background: rgba(12, 12, 30, 0.7);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(120, 80, 200, 0.25);
  color: rgba(200, 200, 220, 0.7); padding: 6px 10px; border-radius: 14px;
  cursor: pointer; font-size: 11px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: 'Inter', sans-serif;
}
#lang-switcher button:hover {
  background: rgba(120, 80, 200, 0.15);
  border-color: rgba(120, 80, 200, 0.5);
  color: #fff;
}
#lang-switcher button.active {
  background: rgba(120, 80, 200, 0.3);
  border-color: rgba(120, 80, 200, 0.6);
  color: #fff;
}

/* AI Chat Tab */
#ai-chat {
  display: flex; flex-direction: column;
  height: calc(100vh - 280px); max-height: 400px;
}
#ai-messages {
  flex: 1; overflow-y: auto;
  padding: 8px 0; display: flex; flex-direction: column; gap: 8px;
}
.ai-msg {
  padding: 8px 12px; border-radius: 12px;
  font-size: 13px; line-height: 1.5;
  max-width: 90%; word-wrap: break-word;
  animation: tabFadeIn 0.2s ease-out;
}
.ai-msg.ai-user {
  align-self: flex-end;
  background: rgba(120, 80, 200, 0.2);
  border: 1px solid rgba(120, 80, 200, 0.3);
  color: #e0e0f0; direction: rtl; text-align: right;
}
.ai-msg.ai-bot {
  align-self: flex-start;
  background: rgba(40, 40, 70, 0.6);
  border: 1px solid rgba(100, 100, 150, 0.2);
  color: #c8c8e0; direction: ltr; text-align: left;
}
.ai-msg.ai-system {
  align-self: center;
  background: transparent;
  color: rgba(160, 160, 200, 0.5);
  font-style: italic; font-size: 12px;
  text-align: center;
}
.ai-msg.ai-loading {
  align-self: flex-start;
  background: rgba(40, 40, 70, 0.4);
  color: rgba(160, 160, 200, 0.6);
  font-style: italic;
}
#ai-input-row {
  display: flex; gap: 6px; margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(120, 80, 200, 0.1);
}
#ai-input {
  flex: 1;
  background: rgba(20, 20, 45, 0.8);
  border: 1px solid rgba(120, 80, 200, 0.25);
  border-radius: 10px; padding: 8px 12px;
  color: #e0e0f0; font-size: 13px;
  font-family: 'Inter', sans-serif;
  outline: none; direction: rtl;
  transition: border-color 0.2s;
}
#ai-input:focus {
  border-color: rgba(120, 80, 200, 0.5);
}
#ai-input::placeholder { color: rgba(160, 160, 200, 0.4); }
#ai-send {
  background: rgba(120, 80, 200, 0.3);
  border: 1px solid rgba(120, 80, 200, 0.4);
  border-radius: 10px; padding: 8px 14px;
  color: #c8b8ff; cursor: pointer;
  font-size: 14px; font-weight: 600;
  transition: all 0.2s;
}
#ai-send:hover {
  background: rgba(120, 80, 200, 0.5);
  color: #fff;
}
#ai-send:disabled {
  opacity: 0.4; cursor: not-allowed;
}
#ai-messages::-webkit-scrollbar { width: 4px; }
#ai-messages::-webkit-scrollbar-track { background: transparent; }
#ai-messages::-webkit-scrollbar-thumb { background: rgba(120, 80, 200, 0.2); border-radius: 2px; }


/* AI interactive elements */
.ai-node-ref {
  display: inline;
  color: #c084fc;
  cursor: pointer;
  border-bottom: 1px dotted rgba(192, 132, 252, 0.4);
  transition: all 0.2s;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  padding: 0 2px;
}
.ai-node-ref:hover {
  color: #fff;
  background: rgba(120, 80, 200, 0.2);
  border-radius: 3px;
  border-bottom-color: transparent;
}
.ai-typing {
  animation: aiTyping 1.2s infinite;
  letter-spacing: 2px;
}
@keyframes aiTyping {
  0%, 60% { opacity: 0.3; }
  30% { opacity: 1; }
}
.ai-msg.ai-bot strong {
  color: #e0d0ff;
}
