/* Knowledge-graph renderer styles — shared by graph.html (immersive, full-bleed) and by
 * the embedded section on index / projects / writing / radar.
 *
 * Everything is positioned inside `.graph-root`, never against the viewport, so the same
 * rules serve a 560px section and a full-screen page. `graph.html` makes `.graph-root`
 * fixed; the pages make it a relative box.
 *
 * Colour variables fall back, because the four pages define a smaller palette than
 * graph.html does.
 */
.graph-root {
  position: relative;
  --g-paper: var(--paper, #080808);
  --g-panel: rgba(16, 16, 16, .88);
  --g-soft: var(--panel-soft, #141414);
  --g-ink: var(--ink, #f5f5f5);
  --g-muted: var(--muted, #a7a7a7);
  --g-dim: var(--dim, #6b6b6b);
  --g-line: var(--line, rgba(255, 255, 255, 0.10));
  --g-line-strong: var(--line-strong, rgba(255, 255, 255, 0.22));
  --g-mint: #6ee7b7;
  --g-mono: var(--headerFont, ui-monospace, "SFMono-Regular", "JetBrains Mono", monospace);
  --g-body: var(--bodyFont, system-ui, -apple-system, "Segoe UI", sans-serif);
}

.graph-canvas { position: absolute; inset: 0; }

/* P4 box-select rectangle. A DOM overlay appended into `.graph-canvas` (never drawn on the
 * force-graph canvas itself, which repaints every frame and would erase it) — position:
 * absolute against that container's own box, so the left/top/width/height the drag handler
 * writes are already in the right coordinate space. pointer-events: none — the drag is
 * tracked by `host`'s own pointer listeners, this div is paint only. */
.graph-marquee {
  position: absolute; z-index: 4; pointer-events: none;
  border: 1px dashed var(--g-mint);
  background: color-mix(in srgb, var(--g-mint) 12%, transparent);
}

/* The console graph beside the headline. It replaces the hand-drawn SVG and inherits its
 * box: the pages' own `.mini-graph` rule already sets width/max-width/aspect-ratio. */
.graph-mini { cursor: grab; }
.graph-mini:active { cursor: grabbing; }
.graph-mini .graph-canvas canvas { border-radius: 2px; }

/* Top-right: the console box shrinks to ~96px on a phone, and anything anchored to its
 * bottom edge lands in the middle of the card. The top-right corner is the one corner the
 * graph never fills, at any size. */
.graph-mini-open {
  position: absolute; right: 0; top: 0; z-index: 3;
  font-family: var(--g-mono); font-size: 10px; letter-spacing: .04em;
  color: var(--g-dim); text-decoration: none; cursor: pointer;
  padding: 2px 4px; border-radius: 2px; background: var(--g-panel);
}
.graph-mini-open:hover { color: var(--g-mint); }

.graph-hud {
  position: absolute; z-index: 5;
  background: var(--g-panel);
  border: 1px solid var(--g-line);
  backdrop-filter: blur(8px);
  font-family: var(--g-mono);
  font-size: 12px;
  color: var(--g-ink);
}

.graph-controls { top: 16px; left: 16px; padding: 12px 14px; width: 244px; }
.graph-title {
  margin: 0 0 10px; font-size: 12px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--g-dim); font-weight: 500;
}
/* `more` folds the panel on a phone. Above 720px there is room for everything, so the
 * button is hidden and `.collapsed` means nothing. Named `graph-toggle`, NOT `graph-more`:
 * that class already belongs to the "+ N more" truncation notice in the panel and results. */
.graph-toggle { display: none; }
/* the search box + `more` share a row on touch (see the media block); on desktop this wrapper
 * is transparent (display:contents) so the searchbar behaves exactly as a direct child did. */
.graph-searchrow { display: contents; }
.graph-field {
  display: block; color: var(--g-dim); margin: 0 0 4px;
  font-size: 10px; letter-spacing: .1em; text-transform: uppercase;
}
.graph-row { display: flex; gap: 6px; margin-bottom: 10px; }
.graph-row button {
  flex: 1; padding: 5px 0; cursor: pointer;
  background: transparent; color: var(--g-muted);
  border: 1px solid var(--g-line); border-radius: 2px; font: inherit;
}
.graph-row button:hover { color: var(--g-ink); border-color: var(--g-line-strong); }
.graph-row button[aria-pressed="true"] {
  background: var(--g-ink); color: var(--g-paper); border-color: var(--g-ink);
}

.graph-searchbar {
  display: flex; align-items: center; gap: 6px; margin-bottom: 8px;
  background: var(--g-soft); border: 1px solid var(--g-line);
  border-radius: 2px; padding-right: 7px;
}
.graph-searchbar:focus-within { border-color: rgba(110, 231, 183, 0.45); }
.graph-search {
  flex: 1; min-width: 0; padding: 6px 7px;
  background: transparent; color: var(--g-ink); border: 0; font: inherit;
}
.graph-search:focus { outline: none; }
.graph-search::placeholder { color: var(--g-dim); }
.graph-kbd {
  font-size: 9px; color: var(--g-dim); border: 1px solid var(--g-line);
  border-radius: 2px; padding: 1px 4px; white-space: nowrap;
}

.graph-filters { flex-wrap: wrap; margin-bottom: 8px; }
.graph-filters button { flex: 0 0 auto; padding: 3px 7px; font-size: 10px; }

.graph-suggest { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }
.graph-suggest:empty { margin-bottom: 0; }
.graph-chip {
  cursor: pointer; padding: 3px 7px; font: inherit; font-size: 10px;
  color: var(--tint); background: transparent; border-radius: 2px;
  border: 1px solid color-mix(in srgb, var(--tint) 35%, transparent);
}
.graph-chip:hover { background: color-mix(in srgb, var(--tint) 12%, transparent); }
.graph-chip em { color: var(--g-dim); font-style: normal; margin-left: 6px; }

.graph-results { max-height: 220px; overflow-y: auto; margin-bottom: 10px; }
.graph-results:empty { margin-bottom: 0; }
.graph-result {
  display: block; width: 100%; padding: 4px 6px; cursor: pointer; color: var(--g-muted);
  background: transparent; font: inherit; text-align: left;
  border: 0; border-left: 2px solid transparent; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.graph-result:hover { color: var(--g-ink); background: var(--g-soft); border-left-color: var(--tint); }
.graph-rkind { color: var(--g-dim); margin-right: 8px; font-size: 10px; }
.graph-search-feed, .graph-actions button {
  margin-top: 6px; padding: 5px 7px; cursor: pointer; font: inherit;
  color: var(--g-muted); background: transparent; border: 1px solid var(--g-line); border-radius: 2px;
}
.graph-search-feed:hover, .graph-actions button:hover { color: var(--g-ink); border-color: var(--g-line-strong); }
.graph-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.graph-actions button { margin-top: 0; }
.graph-result:focus-visible, .graph-search-feed:focus-visible, .graph-actions button:focus-visible {
  outline: 2px solid var(--g-mint); outline-offset: 2px;
}

.graph-legend { border-top: 1px solid var(--g-line); padding-top: 9px; color: var(--g-dim); line-height: 1.9; }
.graph-legend i {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 7px; vertical-align: 0;
}
.graph-stats { margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--g-line); color: var(--g-dim); }

.graph-detail {
  top: 16px; right: 16px; padding: 14px 16px; width: 320px;
  max-height: calc(100% - 32px); overflow-y: auto; display: none;
}
.graph-detail.open { display: block; }
.graph-kind { color: var(--g-dim); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; }
.graph-detail .graph-label {
  margin: 6px 0 10px; font-size: 15px; font-family: var(--g-body);
  font-weight: 600; line-height: 1.35; color: var(--g-ink);
}
.graph-meta {
  margin: 0 0 14px; display: grid; grid-template-columns: auto 1fr;
  gap: 3px 12px; color: var(--g-muted);
}
.graph-meta dt { color: var(--g-dim); }
.graph-meta dd { margin: 0; }
.graph-meta a { color: var(--g-mint); }
.graph-sections h3 {
  margin: 12px 0 5px; font-size: 10px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--tint); font-weight: 500; opacity: .75;
}
.graph-sections ul { margin: 0; padding-left: 15px; color: var(--g-muted); line-height: 1.75; }
.graph-sections li { cursor: pointer; }
.graph-sections li::marker { color: var(--g-dim); }
.graph-sections a, .graph-sections span {
  color: var(--g-muted); text-decoration: none; border-bottom: 1px solid transparent;
}
.graph-sections a:hover, .graph-sections li:hover span {
  color: var(--tint); border-bottom-color: color-mix(in srgb, var(--tint) 45%, transparent);
}
/* Concept/topic neighbours: info only, not a door to another concept's panel — no pointer,
 * no hover-underline, so the row never LOOKS like a link it isn't. */
.graph-sections li.graph-inert { cursor: default; }
.graph-sections li.graph-inert:hover span {
  color: var(--g-muted); border-bottom-color: transparent;
}
.graph-src { color: var(--g-dim); font-style: normal; font-size: 10px; }
.graph-ext { color: var(--g-dim); text-decoration: none; font-size: 10px; padding: 0 2px; }
.graph-ext:hover { color: var(--g-ink); }
.graph-more { color: var(--g-dim); list-style: none; margin-left: -15px; cursor: default; padding: 4px 0; }
.graph-loading { margin: 12px 0 0; color: var(--g-dim); }
.graph-close {
  position: absolute; top: 12px; right: 14px; cursor: pointer;
  color: var(--g-dim); background: none; border: 0; font: inherit;
  min-width: 44px; min-height: 44px;
}
.graph-close:hover { color: var(--g-ink); }
.graph-close-back { display: none; }
.graph-navcluster button:focus-visible, .graph-grainzoom:focus-visible, .graph-close:focus-visible {
  outline: 2px solid var(--g-mint); outline-offset: 2px;
}

/* Bottom-right nav cluster: pan/zoom's own corner, and now the box-select toggle's home too
 * (moved out of the top-left settings panel — see the graph.js comment above this markup for
 * why). Same button styling throughout, so select reads as one more navigation control, not
 * a bolt-on. */
.graph-navcluster {
  right: 16px; bottom: 16px; padding: 4px; display: flex; flex-direction: column; gap: 4px;
}
.graph-navcluster button {
  width: 28px; height: 28px; cursor: pointer; font: inherit; font-size: 13px;
  background: transparent; color: var(--g-muted);
  border: 1px solid var(--g-line); border-radius: 2px;
}
.graph-navcluster button:hover { color: var(--g-ink); border-color: var(--g-line-strong); }
.graph-navcluster .graph-select-btn[aria-pressed="true"] {
  background: var(--g-ink); color: var(--g-paper); border-color: var(--g-ink);
}

/* Pure zoom slider — no grain, no bands: bottom = 1X (this instance's own fit-to-view zoom),
 * top = 10X, log scale between, with 1X/2X/5X/10X tick labels (positioned by graph.js —
 * calibrateZoomRange sets each tick's `top` from the graph's own measured fit-zoom). Docked
 * to the canvas' right edge, vertically centered — its own column, not sharing the
 * `.graph-navcluster` corner. `touch-action: none` keeps a touch drag from also scrolling the
 * page; the element sits outside `.graph-canvas`, so none of this ever reaches d3-zoom. */
.graph-grainzoom {
  /* .graph-hud already sets position:absolute; that same declaration is what makes this
   * element the containing block for the tick/thumb children below (position:absolute does
   * not need position:relative to also serve that role). */
  top: 50%; right: 16px; transform: translateY(-50%);
  width: 28px; height: 180px; padding: 8px 0;
  cursor: pointer; touch-action: none;
  transition: opacity .15s;
}
.graph-grainzoom-tick {
  position: absolute; left: 4px; right: 4px; height: 0;
  border-top: 1px solid var(--g-line);
}
.graph-grainzoom-tick span {
  position: absolute; top: -4px; left: 100%; margin-left: 5px;
  font-size: 8px; letter-spacing: .06em; color: var(--g-dim); white-space: nowrap;
}
.graph-grainzoom-thumb {
  position: absolute; left: 50%; top: 0; width: 10px; height: 10px;
  margin-left: -5px; margin-top: -5px; border-radius: 50%;
  background: var(--g-ink); border: 1px solid var(--g-paper);
  box-shadow: 0 0 0 1px var(--g-line-strong);
  cursor: grab; pointer-events: none;
}
.graph-grainzoom:active .graph-grainzoom-thumb { cursor: grabbing; }
/* The drawer covers the graph on a phone (see the touch media query below); on any width
 * it takes over the same right edge the slider docks to, so it fades out while open. */
.graph-root.detail-open .graph-grainzoom { opacity: 0; pointer-events: none; }

.graph-foot {
  bottom: 16px; left: 16px; padding: 7px 11px; color: var(--g-dim);
  display: flex; align-items: center; gap: 14px;
}
.graph-home, .graph-open {
  color: var(--g-muted); text-decoration: none; white-space: nowrap;
}
.graph-home { border-right: 1px solid var(--g-line); padding-right: 14px; }
.graph-home:hover, .graph-open:hover { color: var(--g-ink); }
.graph-aside:empty::before { content: "scroll zoom · drag pan · click node"; }
.graph-root.touch-input .graph-aside:empty::before { content: "browse: one finger pan · pinch · tap node"; }

.graph-error { padding: 40px; font-family: var(--g-mono); color: var(--g-muted); line-height: 1.8; }
.graph-error span { color: var(--g-dim); }

/* Phone width OR touch capability. A tablet (768-1024px+) is wider than any phone
 * breakpoint but still fingers-only — hover:none + pointer:coarse catches it where a
 * max-width alone would leave it on the desktop layout with a mouse-sized hit floor. */
@media (max-width: 720px), (hover: none) and (pointer: coarse) {
  /* Folded, the panel is a title, a search box and a `more` button — the graph gets the
   * screen. Expanded, it is the desktop panel. A tablet has room for `calc(100% - 32px)`
   * to mean "most of a 1024px screen", so cap it at the same width the phone panel uses. */
  .graph-controls { width: min(calc(100% - 24px), 380px); top: 12px; left: 12px; padding: 8px 10px; }
  /* Title is a label, not a headline — shrink it and its gap so the graph gets the screen. */
  .graph-title { margin: 0 0 4px; font-size: 9px; letter-spacing: .18em; }
  /* `more` sits on the SEARCH-BOX row, right of it and the same height — so it aligns with the
   * search bar, not the title. The searchbar flexes to fill the rest; SEARCH IN + everything
   * below use full width (no panel padding-right). */
  .graph-searchrow { display: flex; align-items: stretch; gap: 6px; margin-bottom: 6px; }
  .graph-searchrow .graph-searchbar { flex: 1; min-width: 0; margin-bottom: 0; }
  .graph-toggle {
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    background: transparent; color: var(--g-muted); font: inherit; font-size: 11px;
    border: 1px solid var(--g-line); border-radius: 2px; padding: 0 10px; cursor: pointer;
    min-width: 44px; white-space: nowrap;
  }
  .graph-toggle,
  .graph-row button,
  .graph-result,
  .graph-search-feed,
  .graph-actions button,
  .graph-chip {
    min-height: 44px; box-sizing: border-box;
  }
  .graph-toggle, .graph-search-feed, .graph-actions button, .graph-chip { min-width: 44px; }
  .graph-search { min-height: 44px; box-sizing: border-box; }
  .graph-home, .graph-open, .graph-mini-open,
  .graph-detail .graph-meta a, .graph-detail .graph-sections a {
    display: inline-flex; align-items: center; min-width: 44px; min-height: 44px;
    box-sizing: border-box;
  }
  .graph-controls.collapsed .graph-collapsible { display: none; }
  .graph-controls.collapsed .graph-searchbar { margin-bottom: 0; }

  /* Tapping a node opens a full-height drawer over the graph. It is a page, not a tooltip:
   * on a phone the node's articles are the reason you tapped. The controls step aside so
   * two panels never stack, and the drawer's own `← graph` button is the way back. */
  .graph-detail {
    top: 0; bottom: 0; right: 0; left: auto;
    width: min(88vw, 380px); max-height: none;
    padding-top: 44px; border-width: 0 0 0 1px;
  }
  .graph-root.detail-open .graph-controls,
  .graph-root.detail-open .graph-foot,
  .graph-root.detail-open .graph-navcluster { display: none; }
  .graph-close-esc { display: none; }
  .graph-close-back {
    display: inline; color: var(--g-muted);
    border: 1px solid var(--g-line); border-radius: 2px; padding: 4px 8px;
  }
  .graph-close { top: 10px; left: 14px; right: auto; }

  /* the immersive view carries its own way out — never hide it, on any screen */
  .graph-foot { left: 12px; right: 12px; bottom: 10px; gap: 10px; padding: 4px 8px; font-size: 11px; }
  /* one line on a phone — nowrap + a shorter hint so `← home | …` never wraps to two rows */
  .graph-foot .graph-aside { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .graph-root.touch-input .graph-aside:empty::before { content: "1-finger pan · pinch · tap"; }
  /* Pinch handles zoom on touch, so the +/-/fit buttons have nothing to do; the remaining
   * button becomes the Move/Arrange toggle. */
  .graph-navcluster [data-zoom] { display: none; }

  /* move + reset ride the RIGHT END of the foot bar — one stylish toolbar row, not a floating
   * box. The cluster is stripped of its own panel (transparent, no border/blur/padding) and
   * absolutely positioned over the foot's empty right side. Height matches the foot box
   * (`← home` is a 44px touch target + 6px top/bottom padding = 56px) so align-items:center
   * drops the buttons onto the bar's centre line. Zoom buttons are already display:none here,
   * so the row is just [move][⟲]. If the foot's height changes, re-match this height. */
  .graph-navcluster {
    bottom: 10px; right: 18px; left: auto; top: auto; height: 52px; z-index: 6;
    flex-direction: row; align-items: center; gap: 6px;
    padding: 0; background: transparent; border: 0; backdrop-filter: none; box-shadow: none;
  }
  /* taller buttons fill the (tightened) bar — reads as part of the toolbar, not floating chips */
  .graph-navcluster button { width: 32px; height: 34px; font-size: 13px; }
  /* `move`/`arrange` carries a text label so it needs width; keep it compact and match `clear`. */
  .graph-root.touch-input .graph-navcluster .graph-select-btn {
    width: 44px; font-size: 0;
  }
  .graph-root.touch-input .graph-navcluster .graph-select-btn::after {
    content: attr(data-touch-label); font-size: 9px; letter-spacing: 0.02em;
  }
  .graph-root.touch-input .graph-navcluster .graph-clear-btn { width: 44px; }

  /* Pinch zoom has no fine-grained precision; the slider is the accurate way to reach a
   * given zoom here, so — unlike the nav cluster's zoom buttons above — it stays visible and
   * grows for a fingertip. */
  .graph-grainzoom { width: 30px; height: 150px; }
  .graph-grainzoom-thumb { width: 12px; height: 12px; margin-left: -6px; margin-top: -6px; }
}
