/* Layout: two panes. Left, a reading column (search, node card, relations); right, the node's local graph.
   Under 860px they stack: search, graph, then the text, and the page scrolls. */
:root {
  --paper: #f6f7f9;
  --surface: #ffffff;
  --ink: #1b2130;
  --muted: #5d6475;
  --line: #d9dde6;
  --accent: #1f5f8b;
  --accent-soft: #e2edf5;
  /* graph */
  --canvas: #eef1f5;
  --edge: #9aa3b5;
  --n-ancestor: #4a5468;
  --n-child: #2f8f6f;
  --n-sibling: #b0b7c6;
  --display: "Literata", Georgia, "Times New Roman", serif;
  --body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --step--1: 0.8125rem;
  --step-0: 1rem;
  --step-1: 1.1875rem;
  --step-3: 1.875rem;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12161e; --surface: #1a1f2a; --ink: #e5e8ef; --muted: #9aa2b4;
    --line: #2d3443; --accent: #7cb7e0; --accent-soft: #1d3142;
    --canvas: #0d1017; --edge: #4a5366; --n-ancestor: #c3c9d6; --n-child: #5cc29c; --n-sibling: #5b6478;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #12161e; --surface: #1a1f2a; --ink: #e5e8ef; --muted: #9aa2b4;
  --line: #2d3443; --accent: #7cb7e0; --accent-soft: #1d3142;
  --canvas: #0d1017; --edge: #4a5366; --n-ancestor: #c3c9d6; --n-child: #5cc29c; --n-sibling: #5b6478;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: var(--step-0)/1.55 var(--body);
}
a { color: var(--accent); }
a:focus-visible, button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--mono); font-size: var(--step--1); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---- layout ---- */
.app { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-areas: "search" "graph" "panel"; }
.bar { grid-area: search; }
.graph { grid-area: graph; }
.panel { grid-area: panel; min-width: 0; }
.bar, main, .foot { padding-inline: 16px; }
.graph { position: relative; height: 55vh; min-height: 18rem; margin-inline: 16px; }

@media (min-width: 860px) {
  body { overflow: hidden; }
  .app {
    height: 100%;
    grid-template-columns: minmax(20rem, 32rem) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "search graph" "panel graph";
  }
  .panel { overflow-y: auto; }
  .graph { height: auto; min-height: 0; margin: 16px 16px 16px 0; }
}

/* ---- search ---- */
.bar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 3;
  padding-block: 12px; background: var(--paper);
}
#q {
  width: 100%; padding: 0.7rem 0.9rem; font: inherit; font-size: var(--step-1);
  color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
}
.results {
  position: absolute; left: 16px; right: 16px; top: calc(100% - 6px);
  list-style: none; margin: 0; padding: 4px; max-height: 70vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.14);
}
.results a { display: grid; gap: 2px; padding: 8px 10px; border-radius: 6px; text-decoration: none; color: var(--ink); }
.results a:hover, .results a[aria-selected="true"] { background: var(--accent-soft); }
.results .k { font-weight: 700; }
.results .d, .results .via, .results .note { color: var(--muted); font-size: var(--step--1); }
.results .d { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .note { padding: 8px 10px; }

/* ---- graph ---- */
.graph { background: var(--canvas); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
#graph { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#graph.dragging { cursor: grabbing; }
#graph.over-node { cursor: pointer; }
.graph-top {
  position: absolute; inset: 10px 10px auto 10px; display: flex; flex-wrap: wrap; gap: 8px 16px;
  justify-content: space-between; align-items: center; pointer-events: none;
}
.graph-top > * { pointer-events: auto; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: var(--step--1); color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.focus { background: var(--accent); box-shadow: 0 0 0 2px var(--canvas), 0 0 0 3px var(--accent); }
.dot.ancestor { background: var(--n-ancestor); }
.dot.child { background: var(--n-child); }
.dot.sibling { background: var(--n-sibling); }
.graph-controls { display: flex; gap: 8px; align-items: center; }
.toggle { display: flex; gap: 6px; align-items: center; font-size: var(--step--1); color: var(--muted); cursor: pointer; }
.graph-controls .more { background: var(--surface); }
.graph-hint { position: absolute; left: 12px; right: 12px; bottom: 8px; margin: 0; font-size: var(--step--1); color: var(--muted); pointer-events: none; }
.tip {
  position: absolute; z-index: 2; max-width: min(22rem, calc(100% - 24px)); padding: 8px 10px; pointer-events: none;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.14); font-size: var(--step--1);
}
.tip strong { display: block; font-size: var(--step-0); }
.tip span { color: var(--muted); }

/* ---- node card and relations ---- */
.status { color: var(--muted); padding-block: 2rem; }
article { display: grid; gap: 1.25rem; padding-block: 0.5rem 2rem; }
.eyebrow { margin: 0; color: var(--muted); font-size: var(--step--1); letter-spacing: 0.04em; text-transform: uppercase; }
.eyebrow .mono { text-transform: none; letter-spacing: 0; }
h1 { margin: 0; font: 600 var(--step-3)/1.2 var(--display); text-wrap: balance; overflow-wrap: anywhere; }
.definition { margin: 0; font: var(--step-1)/1.5 var(--display); max-width: 65ch; }
.aliases, .qual { margin: 0; color: var(--muted); }
section[aria-labelledby] { display: grid; gap: 0.6rem; border-top: 1px solid var(--line); padding-top: 1rem; }
h2 { margin: 0; font-size: var(--step--1); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.count { font-variant-numeric: tabular-nums; letter-spacing: 0; text-transform: none; }

.trails { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.trails li { line-height: 1.8; overflow-wrap: anywhere; }
.trails .sep { color: var(--muted); margin-inline: 0.3em; }
.trails .here { font-weight: 700; }

.list { list-style: none; margin: 0; padding: 0; display: grid; }
.list li { display: flex; justify-content: space-between; gap: 1rem; padding-block: 0.35rem; border-bottom: 1px solid var(--line); min-width: 0; }
.list li a { min-width: 0; overflow-wrap: anywhere; }
.list .n { color: var(--muted); font-variant-numeric: tabular-nums; font-size: var(--step--1); white-space: nowrap; }
.group { display: grid; gap: 0.4rem; }
.group h3 { margin: 0; font-size: var(--step-0); font-weight: 400; color: var(--muted); }
.group h3 a { font-weight: 700; }

.filter { font: inherit; padding: 0.45rem 0.7rem; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; max-width: 20rem; }
.more {
  justify-self: start; font: inherit; font-size: var(--step--1); color: var(--accent);
  background: none; border: 1px solid var(--line); border-radius: 999px; padding: 0.3rem 0.8rem; cursor: pointer;
}
.more:hover { background: var(--accent-soft); }
.empty { margin: 0; color: var(--muted); }
.foot { padding-block: 1.5rem 2.5rem; color: var(--muted); font-size: var(--step--1); border-top: 1px solid var(--line); }
.foot p { margin: 0 0 0.4rem; }
