/* three.js knowledge-graph stage and its overlays. */

body { overflow: hidden; }

.shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.viz-layout {
  display: grid;
  grid-template-columns: var(--col-side) minmax(0, 1fr) var(--col-aside);
  flex: 1;
  min-height: 0;
}

.col-filters { border-right: var(--rule-width) solid var(--rule-strong); }
.col-detail { border-left: var(--rule-width) solid var(--rule-strong); }

.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: var(--paper);
}

.canvas-host { position: absolute; inset: 0; }
.canvas-host canvas { display: block; cursor: grab; }
.canvas-host canvas:active { cursor: grabbing; }

/* ------------------------------------------------------------------ overlays
   Opaque paper panels with hairlines. No blur, no translucency. */

.stage-top {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  right: var(--space-3);
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  pointer-events: none;
}
.stage-top > * { pointer-events: auto; }

.glass-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--control-h);
  padding: 0 var(--space-2);
  font-size: var(--text-2xs);
  color: var(--ink-muted);
  background: var(--paper);
  border: var(--rule-width) solid var(--rule-strong);
  border-radius: var(--radius);
}
.glass-bar input {
  width: 180px;
  min-height: auto;
  padding: 0;
  font-size: var(--text-xs);
  background: none;
  border: none;
}
.glass-bar input:focus { outline: none; border: none; }

.stage-legend {
  position: absolute;
  bottom: var(--space-3);
  left: var(--space-3);
  z-index: var(--z-overlay);
  display: flex;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-2xs);
  color: var(--ink-muted);
  background: var(--paper);
  border: var(--rule-width) solid var(--rule-strong);
  border-radius: var(--radius);
}
/* One key per account rather than per node role, so the row has to wrap and
   stay clear of the stats in the opposite corner. */
.stage-legend-wrap {
  flex-wrap: wrap;
  max-width: 58%;
  gap: var(--space-2);
  row-gap: var(--space-1);
}
.legend-item { display: flex; align-items: center; gap: var(--space-1); }
.legend-dot { width: var(--mark-status); height: var(--mark-status); flex: none; }
/* Node-role marks, matching how _paint() weights each role: hubs pull toward
   ink, entities keep their graph colour, memories fade toward the paper. */
.legend-hub { background: var(--scene-highlight); }
.legend-entity { background: var(--data-default); }
.legend-memory { background: var(--scene-dim); }

.stage-stat {
  position: absolute;
  bottom: var(--space-3);
  right: var(--space-3);
  z-index: var(--z-overlay);
  display: flex;
  gap: var(--space-4);
  padding: var(--space-1) var(--space-3);
  background: var(--paper);
  border: var(--rule-width) solid var(--rule-strong);
  border-radius: var(--radius);
}
.stat { display: flex; align-items: baseline; gap: var(--space-1); }
.stat b {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--ink);
  line-height: var(--leading-flat);
}
.stat span {
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-none);
  color: var(--ink-faint);
}

.g3d-tooltip {
  position: absolute;
  z-index: var(--z-tooltip);
  max-width: 240px;
  padding: var(--space-1) var(--space-2);
  font-family: var(--font-ui);
  font-size: var(--text-2xs);
  line-height: var(--leading-snug);
  pointer-events: none;
  opacity: 0;
  color: var(--ink);
  background: var(--paper);
  border: var(--rule-width) solid var(--ink);
  border-radius: var(--radius);
  transition: opacity var(--duration-fast) var(--ease);
}
.g3d-tooltip.visible { opacity: 1; }
.g3d-tooltip strong { display: block; font-weight: var(--weight-medium); }
.g3d-tooltip span { color: var(--ink-faint); }

.stage-loading {
  position: absolute;
  inset: 0;
  z-index: var(--z-overlay);
  display: grid;
  place-items: center;
  background: var(--paper);
}
.stage-loading .inner {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--ink-muted);
}

/* ------------------------------------------------------------- graph toggles */

.toggle-list { display: flex; flex-direction: column; }
.toggle-group + .toggle-group { margin-top: var(--space-3); }
.toggle-group-label {
  font-family: var(--font-ui);
  font-size: var(--text-2xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: var(--space-1) 0;
}
.toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) 0;
  font-size: var(--text-xs);
  color: var(--ink-muted);
  border-bottom: var(--rule-width) solid var(--rule);
  cursor: pointer;
  user-select: none;
  transition: color var(--duration) var(--ease);
}
.toggle-group .toggle:last-child { border-bottom: none; }
.toggle:last-child { border-bottom: none; }
.toggle:hover { color: var(--ink); }
.toggle:focus-within { color: var(--ink); }
.toggle.off { color: var(--ink-faint); }
.toggle .count { margin-left: auto; font-family: var(--font-ui); font-size: var(--text-2xs); color: var(--ink-faint); }

/* The box replaces the old colour swatch and carries both jobs: the border is
   always the graph's colour so it still reads as the legend key, and the fill
   states whether the graph is in the scene. Fill — not the tick — is the
   primary signal, so the row stays legible if the tick fails to paint. */
.toggle .toggle-box {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: var(--mark-check);
  height: var(--mark-check);
  /* Explicit, because the shared input rule in base.css sets a field padding
     and a 28px min-height that would otherwise distort the box. */
  min-height: 0;
  padding: 0;
  margin: 0;
  border: var(--rule-width) solid var(--graph-color);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  transition: background-color var(--duration) var(--ease);
}
.toggle .toggle-box:checked { background-color: var(--graph-color); }

/* Drawn in --paper because the data palette inverts luminance between themes:
   dark swatches on light paper, light swatches on dark paper. Matching the page
   background therefore contrasts against the fill in both. */
.toggle .toggle-box:checked::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 47%;
  width: 6px;
  height: 3px;
  transform: translate(-50%, -50%) rotate(-45deg);
  border-left: 1.5px solid var(--paper);
  border-bottom: 1.5px solid var(--paper);
}

/* -------------------------------------------------------------- detail panel */

.detail-body { font-size: var(--text-xs); line-height: var(--leading-normal); }

/* Was an uppercase letter-spaced kicker. Now a plain monospace label. */
.detail-kind {
  display: block;
  margin-bottom: var(--space-2);
  font-family: var(--font-ui);
  font-size: var(--text-2xs);
  letter-spacing: var(--tracking-none);
  color: var(--ink-faint);
}
.detail-title {
  margin: 0 0 var(--space-3);
  font-family: var(--font-prose);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
  overflow-wrap: break-word;
}
.detail-title-sm { font-size: var(--text-md); }
.detail-text {
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
  font-family: var(--font-prose);
  font-size: var(--text-sm);
  line-height: var(--leading-prose);
  background: var(--paper-sunken);
  border-left: 2px solid var(--ink);
  overflow-wrap: break-word;
}

.kv { display: grid; grid-template-columns: 84px 1fr; gap: var(--space-1) var(--space-2); font-size: var(--text-2xs); }
.kv dt { color: var(--ink-faint); }
.kv dd { margin: 0; overflow-wrap: break-word; }

/* -------------------------------------------------------------- entry list */

.entry-list { display: flex; flex-direction: column; }
.entry {
  padding: var(--space-2) 0;
  font-family: var(--font-prose);
  font-size: var(--text-sm);
  line-height: var(--leading-prose);
  border-bottom: var(--rule-width) solid var(--rule);
}
.entry:last-child { border-bottom: none; }
/* An entry keyed to its graph by a coloured left rule. */
.entry-ruled { padding-left: var(--space-2); border-left: 2px solid var(--rule-strong); }
.entry .meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-1);
  font-family: var(--font-ui);
  font-size: var(--text-2xs);
  color: var(--ink-faint);
}
.entry .meta .spacer { flex: 1; }

/* ---------------------------------------------------------------- responsive
   The stage takes the whole page and the two columns become drawers opened from
   the overlay bar, so a phone can still pick graphs and read the inspector. */

/* With both columns in place the stage is too narrow for the mouse hints to
   clear the counters in the opposite corner. */
@media (max-width: 1300px) {
  .stage-legend .legend-item.faint { display: none; }
}

@media (max-width: 1024px) {
  .viz-layout { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 820px) {
  .stage-top {
    top: var(--space-2);
    left: var(--space-2);
    right: var(--space-2);
    gap: var(--space-2);
  }
  /* The search field earns its own row; the scene keys share the next one. */
  .stage-top .search-bar { flex: 1 1 100%; }
  .glass-bar input { width: 100%; min-width: 0; }

  /* Node roles are legible from the scene itself once space is this tight, and
     the hints describe a mouse. */
  .stage-legend { display: none; }
  .stage-stat {
    left: var(--space-2);
    right: var(--space-2);
    bottom: var(--space-2);
    justify-content: space-between;
    gap: var(--space-2);
  }
}

@media (max-width: 560px) {
  #scene-title { display: none; }
}
