/* ===========================================================
   Knowledge graph page
   The graph is an immersive dark scene in BOTH themes: the wrapper
   re-declares the dark design tokens locally, so every token used
   inside it resolves to its dark value even under [data-bs-theme="light"].
   =========================================================== */

.graph-wrapper {
  /* ---- Local dark tokens (copy of the dark :root values) ---- */
  color-scheme: dark;
  --surface:       oklch(0.18 0.005 250);
  --panel:         oklch(0.22 0.006 250);
  --panel-alt:     oklch(0.25 0.006 250);
  --panel-hover:   oklch(0.28 0.007 250);
  --border:        oklch(0.32 0.008 250);
  --border-strong: oklch(0.42 0.010 250);
  --text:          oklch(0.92 0.005 250);
  --text-soft:     oklch(0.78 0.008 250);
  --text-muted:    oklch(0.68 0.012 220);
  --accent:        oklch(0.65 0.14 245);
  --accent-strong: oklch(0.58 0.16 245);
  --accent-soft:   oklch(0.65 0.14 245 / 0.16);
  --token-keyword: oklch(0.65 0.14 245);
  --token-string:  oklch(0.72 0.13 145);
  --token-preprocessor: oklch(0.65 0.16 25);
  --status-err:    oklch(0.65 0.16 25);
  --shadow-lg:     0 6px 24px oklch(0.10 0.01 250 / 0.5);

  /* Fills the viewport between the sticky chrome and the status bar. */
  position: fixed;
  inset: var(--chrome-h) 0 var(--statusbar-h) 0;
  z-index: 1;
  margin: 0;
  overflow: hidden;
  background: radial-gradient(ellipse at center, var(--panel) 0%, var(--surface) 100%);
  color: var(--text);
  font-family: var(--font-ui);
}

.graph-wrapper [hidden] {
  display: none !important;
}

.kg-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

#graph {
  position: absolute;
  inset: 0;
}

/* Glass surface shared by the floating cards */
.glass-panel {
  background: color-mix(in oklch, var(--panel) 78%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}

/* ---- Info box ---- */
.info-box {
  position: absolute;
  top: var(--space-4);
  left: var(--space-5);
  z-index: 20;
  max-width: 380px;
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  border-top: 2px solid var(--token-keyword);
  animation: panel-in var(--dur-4) var(--ease-out-quint) backwards;
}

.info-box h3 {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--token-keyword);
  margin: 0 0 var(--space-3) 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Decorative dot: two soft pulses on arrival, then it rests. */
.info-box h3::before {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--token-keyword);
  border-radius: 50%;
  animation: pulse 2s var(--ease-in-out-sine) 2;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.5; }
}

.info-box p {
  font-size: var(--text-sm);
  color: var(--text-soft);
  margin: 0;
  line-height: 1.6;
}

.info-box .close-info {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--control-h);
  height: var(--control-h);
  padding: 0;
  background: none;
  border: 0;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition: color var(--motion-fast), background var(--motion-fast);
}

.info-box .close-info:hover {
  color: var(--text);
  background: var(--panel-hover);
}

/* ---- Top-right HUD: stats + reset button ---- */
.hud-right {
  position: absolute;
  top: var(--space-4);
  right: var(--space-5);
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-3);
}

.stats-badge {
  display: flex;
  gap: var(--space-4);
}

.stat-item {
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-lg);
  text-align: center;
  min-width: 100px;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: 500;
  color: var(--token-keyword);
  display: block;
}

.stat-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: var(--space-1);
}

.graph-controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.control-btn {
  width: var(--control-h);
  height: var(--control-h);
  padding: 0;
  border-radius: var(--radius);
  background: color-mix(in oklch, var(--panel) 80%, transparent);
  border: 1px solid var(--border-strong);
  color: var(--text-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  transition: background var(--motion-base), border-color var(--motion-base), color var(--motion-base), transform var(--motion-base);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.control-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--token-keyword);
}

/* ---- Side panel (drawer) ---- */
.side-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(480px, 100%);
  z-index: 40;
  overflow-y: auto;
  background: color-mix(in oklch, var(--panel) 95%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  /* Closed: off-canvas and out of the tab order. Exit runs at ~75% of the entrance. */
  transform: translateX(100%);
  visibility: hidden;
  transition: transform var(--dur-2) var(--ease-out-quint), visibility 0s linear var(--dur-2);
}

.side-panel.open {
  transform: none;
  visibility: visible;
  transition: transform var(--dur-3) var(--ease-out-quint), visibility 0s;
}

.panel-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-6);
  background: linear-gradient(135deg, var(--accent-soft) 0%, transparent 100%), var(--panel);
  border-bottom: 1px solid var(--border);
}

.panel-header h2 {
  flex: 1;
  min-width: 0;
  font-size: var(--text-lg);
  font-weight: 500;
  margin: 0;
  color: var(--text);
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.close-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--control-h);
  height: var(--control-h);
  padding: 0;
  cursor: pointer;
  background: var(--panel-alt);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-soft);
  font-size: 1.25rem;
  line-height: 1;
  transition: background var(--motion-fast), border-color var(--motion-fast), color var(--motion-fast), transform var(--motion-fast);
}

.close-btn:hover {
  background: color-mix(in oklch, var(--status-err) 20%, transparent);
  border-color: color-mix(in oklch, var(--status-err) 50%, transparent);
  color: var(--status-err);
}

.panel-content {
  padding: var(--space-6);
}

/* ---- Article card ---- */
.article-card {
  background: color-mix(in oklch, var(--panel-alt) 60%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
  transition: border-color var(--motion-base), transform var(--motion-base), box-shadow var(--motion-base);
}

.article-card:hover {
  border-color: var(--accent);
}

.article-meta {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

/* Badges are .chip; only the token differs. */
.meta-tag {
  --chip-token: var(--token-keyword);
  gap: 6px;
}

.meta-tag.date {
  --chip-token: var(--token-string);
}

.article-summary {
  line-height: 1.8;
  font-size: var(--text-sm);
  color: var(--text-soft);
}

.article-summary strong {
  color: var(--accent);
  font-weight: 500;
}

.btn-visit {
  margin-top: var(--space-5);
  gap: var(--space-2);
  text-decoration: none;
}

/* ---- Entity panel ---- */
.entity-stats {
  background: color-mix(in oklch, var(--panel-alt) 60%, transparent);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.entity-stats-icon {
  width: 48px;
  height: 48px;
  background: var(--accent-soft);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--token-keyword);
  font-size: 1.5rem;
}

.entity-stats-text {
  flex: 1;
}

.entity-stats-count {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: 500;
  color: var(--text);
}

.entity-stats-label {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.entity-article-item {
  display: block;
  background: color-mix(in oklch, var(--panel-alt) 40%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  color: inherit;
  text-decoration: none;
  transition: background var(--motion-base), border-color var(--motion-base), transform var(--motion-base);
}

.entity-article-item:hover {
  background: var(--panel-hover);
  border-color: var(--accent);
  color: inherit;
}

.entity-article-item h4 {
  font-size: var(--text-sm);
  font-weight: 500;
  margin: 0 0 var(--space-3) 0;
  color: var(--text);
  line-height: 1.5;
}

.entity-article-item .item-meta {
  display: flex;
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-bottom: var(--space-3);
  font-family: var(--font-mono);
}

.entity-article-item .item-summary {
  font-size: var(--text-sm);
  color: var(--text-soft);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.read-more {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
  font-size: var(--text-sm);
  color: var(--token-keyword);
  font-weight: 500;
}

.read-more svg {
  transition: transform var(--motion-base);
}

/* ---- Timeline ---- */
.timeline-container {
  position: absolute;
  bottom: var(--space-5);
  left: 0;
  right: 0;
  margin-inline: auto;
  z-index: 20;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-lg);
  width: min(800px, calc(100% - var(--space-6)));
}

.timeline-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.timeline-title {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.date-range-display {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--token-keyword);
  background: var(--accent-soft);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius);
}

.timeline-controls {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.date-display {
  min-width: 140px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: var(--text-base);
  color: var(--text);
  font-weight: 500;
}

/* The input is a full-height touch target; the visible 6px track is drawn on the track pseudo. */
.timeline-slider {
  flex: 1 1 auto;
  min-width: 0;
  height: var(--control-h);
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

.timeline-slider::-webkit-slider-runnable-track {
  height: 6px;
  background: var(--border-strong);
  border-radius: 3px;
}

.timeline-slider::-moz-range-track {
  height: 6px;
  background: var(--border-strong);
  border-radius: 3px;
}

.timeline-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -7px;
  background: var(--accent);
  border: 2px solid var(--surface);
  border-radius: 50%;
  box-shadow: 0 0 0 4px var(--accent-soft);
  cursor: pointer;
  transition: transform var(--motion-base);
}

.timeline-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--accent);
  border: 2px solid var(--surface);
  border-radius: 50%;
  box-shadow: 0 0 0 4px var(--accent-soft);
  cursor: pointer;
  transition: transform var(--motion-base);
}

.timeline-slider:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 4px;
  box-shadow: none;
}

/* ---- Loading overlay (covers the graph area only, never the site chrome) ---- */
.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: radial-gradient(ellipse at center, var(--panel) 0%, var(--surface) 100%);
  transition: opacity var(--dur-3) var(--ease-out-quint);
}

.loading-overlay.is-done {
  opacity: 0;
  pointer-events: none;
}

.loader-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-4);
  text-align: center;
}

/* Spinners are real progress indicators, so they may loop; they stop on error. */
.loader-ring {
  position: relative;
  width: 120px;
  height: 120px;
  margin-bottom: var(--space-6);
  border: 3px solid transparent;
  border-top-color: var(--token-keyword);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loader-ring::before,
.loader-ring::after {
  content: '';
  position: absolute;
  border: 3px solid transparent;
  border-radius: 50%;
}

.loader-ring::before {
  inset: 5px;
  border-top-color: var(--accent);
  animation: spin 2s linear infinite;
}

.loader-ring::after {
  inset: 15px;
  border-top-color: var(--text-soft);
  animation: spin 3s linear infinite;
}

.loading-overlay.is-error .loader-ring,
.loading-overlay.is-error .loader-ring::before,
.loading-overlay.is-error .loader-ring::after {
  animation: none;
  border-top-color: var(--token-preprocessor);
}

.loader-text {
  font-family: var(--font-mono);
  color: var(--token-keyword);
  font-size: var(--text-sm);
  margin-bottom: var(--space-2);
}

.loading-overlay.is-error .loader-text {
  color: var(--status-err);
}

.loader-status {
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* "System Loading" contradicts the error message once loading has failed. */
.loading-overlay.is-error .loader-status {
  display: none;
}

.loader-retry {
  margin-top: var(--space-4);
}

/* ---- Scrollbar ---- */
.side-panel::-webkit-scrollbar {
  width: 8px;
}

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

.side-panel::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-sm);
}

/* ---- Hover effects that move or glow: pointer devices only ---- */
@media (hover: hover) and (pointer: fine) {
  .close-btn:hover {
    transform: rotate(90deg);
  }

  .control-btn:hover {
    transform: scale(1.1);
  }

  .article-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
  }

  .entity-article-item:hover {
    transform: translateX(4px);
  }

  .entity-article-item:hover .read-more svg {
    transform: translateX(4px);
  }

  .timeline-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
  }

  .timeline-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
  }
}

/* ---- Phones ---- */
@media (max-width: 768px) {
  .info-box {
    top: var(--space-3);
    left: var(--space-3);
    max-width: calc(100% - 3 * var(--space-3) - var(--control-h));
    padding: var(--space-4);
  }

  .hud-right {
    top: var(--space-3);
    right: var(--space-3);
  }

  .stats-badge {
    display: none;
  }

  .panel-header,
  .panel-content {
    padding: var(--space-4);
  }

  .timeline-container {
    bottom: var(--space-3);
    width: calc(100% - 2 * var(--space-3));
    padding: var(--space-3) var(--space-4);
  }

  .timeline-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
  }

  .date-display {
    min-width: 0;
    text-align: left;
    font-size: var(--text-sm);
  }
}
