/* =============================================================================
   GAKHUR Philosophy Platform — Knowledge Map Styles (Phase 4, Final)
   assets/css/map.css
   =============================================================================
   Contents:
     1.  Map Section wrapper (home page)
     2.  SVG Canvas Container
     3.  Node circles — by type (center / volume / theme)
     4.  Node labels
     5.  Links / edges
     6.  Tooltip
     7.  Map loading state
     8.  Map controls (zoom buttons)
     9.  Responsive
   ============================================================================= */

/* =============================================================================
   1. Map Section Wrapper
   ============================================================================= */
.home-map-section {
  width: 100%;
  padding: 0;
  background-color: var(--bg-alt);
  border-top: 1px solid var(--border-faint);
  position: relative;
}

.home-map-section__header {
  text-align: center;
  padding: 2.5rem var(--gutter) 0;
}

.home-map-section__title {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* =============================================================================
   2. SVG Canvas Container
   ============================================================================= */
#knowledge-map {
  width: 100%;
  height: 520px;
  background-color: var(--bg-alt);
  position: relative;
  overflow: hidden;
  cursor: grab;
  /* Prevent text selection during drag */
  user-select: none;
  -webkit-user-select: none;
}

#knowledge-map:active {
  cursor: grabbing;
}

#knowledge-map svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* =============================================================================
   3. Node Circles — by type
   ============================================================================= */

/* All nodes share base transition */
.map-node circle {
  transition:
    r           0.25s ease,
    opacity     0.2s  ease,
    filter      0.2s  ease,
    stroke-width 0.2s ease;
  cursor: pointer;
}

/* Center node — GAKHUR */
.map-node--center circle {
  r: 34;
  fill: var(--node-color, #2D3561);
  stroke: var(--bg-alt);
  stroke-width: 3;
  filter: drop-shadow(0 2px 6px rgba(45,53,97,0.25));
}

.map-node--center:hover circle,
.map-node--center:focus circle {
  r: 37;
  filter: drop-shadow(0 4px 12px rgba(45,53,97,0.35));
}

/* Volume nodes — Volume I / II / III */
.map-node--volume circle {
  r: 24;
  fill: var(--node-color, #2D3561);
  stroke: var(--bg-alt);
  stroke-width: 2.5;
  filter: drop-shadow(0 2px 5px rgba(0,0,0,0.15));
}

.map-node--volume:hover circle,
.map-node--volume:focus circle {
  r: 27;
  filter: drop-shadow(0 3px 10px rgba(0,0,0,0.22));
}

/* Theme nodes — sub-topics */
.map-node--theme circle {
  r: 16;
  fill: var(--node-color, #6B7280);
  stroke: var(--bg-alt);
  stroke-width: 2;
  opacity: 0.85;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.12));
}

.map-node--theme:hover circle,
.map-node--theme:focus circle {
  r: 18;
  opacity: 1;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.2));
}

/* =============================================================================
   4. Node Labels
   ============================================================================= */
.map-node text {
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  dominant-baseline: middle;
  text-anchor: middle;
  transition: opacity 0.2s ease;
}

/* Center label — inside the node */
.map-node--center text {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  fill: #FFFFFF;
}

/* Volume labels — inside the node */
.map-node--volume text {
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  fill: #FFFFFF;
}

/* Theme labels — below the node */
.map-node--theme .node-label-below {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  fill: var(--text-muted);
  dominant-baseline: auto;
  /* Positioned by map.js: dy = node radius + 14 */
}

.map-node--theme:hover .node-label-below {
  fill: var(--text);
}

/* =============================================================================
   5. Links / Edges
   ============================================================================= */
.map-link {
  fill: none;
  stroke: var(--border);
  stroke-opacity: 0.55;
  transition: stroke-opacity 0.2s ease, stroke-width 0.2s ease;
}

/* center→volume links: slightly more prominent */
.map-link--center-volume {
  stroke-opacity: 0.7;
  stroke-width: 2px;
}

/* volume→theme links */
.map-link--volume-theme {
  stroke-opacity: 0.4;
  stroke-width: 1.5px;
  stroke-dasharray: 4 3;
}

/* Highlighted on node hover — toggled by JS adding .is-highlighted */
.map-link.is-highlighted {
  stroke-opacity: 0.9;
  stroke-width: 2.5px;
}

/* =============================================================================
   6. Tooltip
   ============================================================================= */
.map-tooltip {
  position: absolute;
  z-index: var(--z-overlay);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.875rem 1.125rem;
  max-width: 240px;
  min-width: 160px;
  box-shadow: var(--shadow-md);
  pointer-events: none;

  /* Hidden by default */
  opacity: 0;
  transform: translateY(4px);
  transition:
    opacity   0.18s ease,
    transform 0.18s ease;
}

.map-tooltip.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.map-tooltip__label {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.3rem;
  line-height: 1.3;
}

.map-tooltip__type {
  font-family: var(--font-ui);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 0.5rem;
}

.map-tooltip__summary {
  font-family: var(--font-serif);
  font-size: 0.8rem;
  line-height: 1.55;
  color: var(--text-muted);
  font-style: italic;
}

.map-tooltip__cta {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--link);
  margin-top: 0.5rem;
  display: block;
}

/* =============================================================================
   7. Map Loading State
   ============================================================================= */
.map-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--text-faint);
  pointer-events: none;
}

.map-loading__spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--link);
  border-radius: 50%;
  animation: map-spin 0.8s linear infinite;
}

@keyframes map-spin {
  to { transform: rotate(360deg); }
}

/* Hidden once D3 renders */
.map-loading.is-hidden {
  display: none;
}

/* =============================================================================
   8. Map Zoom Controls
   ============================================================================= */
.map-controls {
  position: absolute;
  bottom: 1.25rem;
  right: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 10;
}

.map-zoom-btn {
  width: 32px;
  height: 32px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--text-muted);
  transition: color var(--transition-fast), background-color var(--transition-fast);
  padding: 0;
}

.map-zoom-btn:hover {
  color: var(--text);
  background-color: var(--bg-alt);
}

.map-zoom-btn:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

.map-hint {
  position: absolute;
  bottom: 1.25rem;
  left: 1.25rem;
  font-family: var(--font-ui);
  font-size: 0.68rem;
  color: var(--text-faint);
  pointer-events: none;
  letter-spacing: 0.03em;
}

/* =============================================================================
   9. Responsive
   ============================================================================= */
@media (max-width: 480px) {
  #knowledge-map {
    height: 360px;
    cursor: default;
  }

  .map-controls {
    bottom: 0.75rem;
    right: 0.75rem;
  }

  .map-hint {
    display: none;
  }

  .map-node--theme text {
    font-size: 9px;
  }
}

@media (min-width: 768px) {
  #knowledge-map {
    height: 540px;
  }
}

@media (min-width: 1024px) {
  #knowledge-map {
    height: 600px;
  }
}
