:root {
  color-scheme: light;
  --page: #f3f4f2;
  --surface: #ffffff;
  --surface-soft: #f7f8f6;
  --ink: #202522;
  --ink-soft: #59615c;
  --line: #d9ddd9;
  --line-strong: #bec6c0;
  --focus: #236b62;
  --hub: #3f6072;
  --topic: #39766d;
  --source: #a56a24;
  --cross: #735b86;
  --wiki: #5f675f;
  --query: #9b4e5e;
  --rail: 286px;
}

* { box-sizing: border-box; }

html,
body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--page);
  color: var(--ink);
  font-family: "Avenir Next", Avenir, "Helvetica Neue", Helvetica, sans-serif;
  font-size: 14px;
}

button,
input,
select { font: inherit; }

button { color: inherit; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  top: -60px;
  left: 12px;
  z-index: 30;
  padding: 8px 12px;
  background: var(--ink);
  color: #fff;
}

.skip-link:focus { top: 12px; }

.app-shell {
  display: grid;
  grid-template-columns: var(--rail) minmax(440px, 1fr) var(--rail);
  width: 100%;
  height: 100vh;
  min-height: 560px;
}

.sidebar,
.reader {
  min-width: 0;
  min-height: 0;
  background: var(--surface);
}

.sidebar {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-right: 1px solid var(--line);
}

.brand-block {
  flex: 0 0 auto;
  padding: 17px 16px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--focus);
  border-radius: 5px;
  color: var(--focus);
  font-size: 11px;
  font-weight: 750;
}

.brand strong,
.brand span { display: block; }

.brand strong {
  font-size: 13px;
  line-height: 1.2;
}

.brand span span {
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 11px;
}

.control-block {
  flex: 0 0 auto;
  margin: 0;
  padding: 15px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
}

.control-block > label:first-child,
.control-block legend,
.control-heading > span {
  display: block;
  padding: 0;
  margin: 0 0 8px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
}

.search-row { position: relative; }

input[type="search"],
.path-controls select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input[type="search"] { padding: 9px 34px 9px 10px; }

.path-controls select {
  margin-bottom: 7px;
  padding: 8px 9px;
}

.icon-button {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 34px;
  height: 34px;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-size: 19px;
  cursor: pointer;
}

.search-results {
  display: grid;
  max-height: 214px;
  overflow-y: auto;
  margin-top: 7px;
}

.search-result {
  display: block;
  width: 100%;
  padding: 8px 5px;
  border: 0;
  border-bottom: 1px solid #e8ebe8;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.search-result:hover,
.search-result.active { background: var(--surface-soft); }

.search-result strong {
  display: block;
  font-size: 12px;
  line-height: 1.3;
}

.search-result span {
  display: block;
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1.35;
}

.search-result mark {
  background: #f3dfb9;
  color: inherit;
}

.filter-list label {
  display: grid;
  grid-template-columns: 16px 9px 1fr auto;
  gap: 7px;
  align-items: center;
  padding: 5px 0;
  cursor: pointer;
}

.filter-list input {
  margin: 0;
  accent-color: var(--focus);
}

.filter-list em {
  color: var(--ink-soft);
  font-size: 10px;
  font-style: normal;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.dot.stock-hub { background: var(--hub); }
.dot.topic-note { background: var(--topic); }
.dot.source-note { background: var(--source); }
.dot.cross-stock { background: var(--cross); }
.dot.wiki-note { background: var(--wiki); }
.dot.query-note { background: var(--query); }

.control-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.control-heading > span { margin-bottom: 8px; }

.text-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--focus);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.primary-button {
  width: 100%;
  border: 1px solid #205f57;
  border-radius: 5px;
  background: var(--focus);
  color: #fff;
  padding: 8px 11px;
  font-weight: 700;
  cursor: pointer;
}

.primary-button:hover { background: #1d5c54; }

.status-text {
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1.4;
}

.path-examples {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-top: 11px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.path-example {
  min-width: 0;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  font-size: 10px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.path-example:hover { border-color: var(--focus); }

.sidebar-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding: 11px 16px;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 10px;
}

.graph-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) 124px;
  min-width: 0;
  min-height: 0;
  background: var(--page);
}

.graph-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 15px 18px 13px;
  border-bottom: 1px solid var(--line);
  background: var(--page);
}

.graph-toolbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 750;
  line-height: 1.25;
}

.graph-toolbar p {
  margin: 3px 0 0;
  color: var(--ink-soft);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.graph-actions {
  display: flex;
  flex-shrink: 0;
}

.tool-button {
  min-width: 34px;
  height: 30px;
  border: 1px solid var(--line-strong);
  border-right: 0;
  background: #fff;
  cursor: pointer;
}

.tool-button:first-child { border-radius: 5px 0 0 5px; }
.tool-button:last-child {
  border-right: 1px solid var(--line-strong);
  border-radius: 0 5px 5px 0;
}

.tool-button.zoom-level {
  min-width: 54px;
  font-size: 10px;
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background-color: #fbfcfa;
  background-image:
    linear-gradient(#e8ebe7 1px, transparent 1px),
    linear-gradient(90deg, #e8ebe7 1px, transparent 1px);
  background-size: 36px 36px;
}

#graphSvg {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
  cursor: grab;
  touch-action: none;
}

#graphSvg:active { cursor: grabbing; }

.edge {
  stroke: #adb6af;
  stroke-width: 1;
  opacity: .48;
  vector-effect: non-scaling-stroke;
}

.edge.focused {
  stroke: var(--focus);
  stroke-width: 2;
  opacity: 1;
}

.node { cursor: pointer; }

.node circle {
  stroke: #fff;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.node:hover circle,
.node.selected circle {
  stroke: var(--ink);
  stroke-width: 2.5;
}

.node.path circle {
  stroke: var(--focus);
  stroke-width: 3;
}

.node text {
  fill: var(--ink);
  font-size: 10px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #fbfcfa;
  stroke-width: 3px;
  stroke-linejoin: round;
  pointer-events: none;
}

.node-label-sub {
  fill: var(--ink-soft);
  font-size: 8px;
  font-weight: 600;
}

.node.dim,
.edge.dim { opacity: .1; }

.node.hidden,
.edge.hidden { display: none; }

.graph-key {
  position: absolute;
  left: 12px;
  bottom: 10px;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(255, 255, 255, .92);
  color: var(--ink-soft);
  font-size: 9px;
}

.graph-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
}

.graph-empty[hidden] { display: none; }

.research-trail {
  min-width: 0;
  padding: 10px 16px 12px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.trail-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 7px;
}

.trail-heading h2 {
  margin: 0;
  font-size: 11px;
}

.trail-heading span {
  color: var(--ink-soft);
  font-size: 9px;
}

.trail-items {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.trail-item {
  flex: 0 0 158px;
  min-height: 70px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-top: 3px solid var(--hub);
  border-radius: 4px;
  background: var(--surface-soft);
  text-align: left;
  cursor: pointer;
}

.trail-item.topic-note { border-top-color: var(--topic); }
.trail-item.source-note { border-top-color: var(--source); }
.trail-item.cross-stock { border-top-color: var(--cross); }
.trail-item.wiki-note { border-top-color: var(--wiki); }

.trail-item strong {
  display: block;
  font-size: 10px;
  line-height: 1.3;
}

.trail-item span {
  display: block;
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 9px;
}

.trail-empty {
  padding: 18px 0;
  color: var(--ink-soft);
  font-size: 10px;
}

.reader {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  border-left: 1px solid var(--line);
}

.reader-head {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 17px 16px 12px;
  border-bottom: 1px solid var(--line);
}

.reader-type {
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 700;
}

.reader h2 {
  margin: 6px 0 0;
  font-size: 18px;
  line-height: 1.2;
}

.ticker {
  flex: 0 0 auto;
  padding: 4px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface-soft);
  color: var(--hub);
  font-size: 10px;
  font-weight: 800;
}

.reader-meta {
  flex: 0 0 auto;
  padding: 9px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.reader-body {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 17px 16px 24px;
  font-size: 13px;
  line-height: 1.58;
}

.reader-placeholder {
  color: var(--ink-soft);
  line-height: 1.55;
}

.reader-body > *:first-child { margin-top: 0; }
.reader-body > *:last-child { margin-bottom: 0; }

.reader-body h1,
.reader-body h2,
.reader-body h3,
.reader-body h4 {
  margin: 1.15em 0 .42em;
  color: var(--ink);
  line-height: 1.25;
}

.reader-body h1 { font-size: 19px; }
.reader-body h2 { font-size: 16px; }
.reader-body h3 { font-size: 14px; }
.reader-body h4 { font-size: 13px; }

.reader-body p,
.reader-body ul,
.reader-body ol,
.reader-body blockquote { margin: .68em 0; }

.reader-body ul,
.reader-body ol { padding-left: 1.2rem; }

.reader-body li { margin: .28em 0; }

.reader-body a {
  color: var(--focus);
  font-weight: 700;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  cursor: pointer;
}

.reader-body blockquote {
  padding: .4rem .7rem;
  border-left: 3px solid #7da49e;
  background: #f1f6f4;
}

.reader-body code,
.external-path {
  padding: .1em .3em;
  border-radius: 3px;
  background: #eef0ed;
  color: #39413c;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .85em;
}

.reader-body pre {
  overflow: auto;
  padding: 10px;
  border-radius: 5px;
  background: #222925;
  color: #f0f2ef;
}

.broken-link { color: #a64052; }

.connections {
  flex: 0 0 190px;
  min-height: 0;
  overflow: hidden;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.connection-tabs {
  display: flex;
  height: 37px;
  border-bottom: 1px solid var(--line);
}

.connection-tab {
  flex: 1;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}

.connection-tab.active {
  border-bottom-color: var(--focus);
  color: var(--ink);
}

.connection-tab span { color: var(--ink-soft); }

.link-list {
  display: grid;
  gap: 5px;
  max-height: 152px;
  overflow-y: auto;
  padding: 10px 12px 12px;
}

.link-list[hidden] { display: none; }

.link-list button {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.link-list button:hover { border-color: var(--focus); }

.link-empty {
  padding: 12px;
  color: var(--ink-soft);
  font-size: 10px;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1120px) {
  :root { --rail: 238px; }
  .control-block { padding-left: 13px; padding-right: 13px; }
  .brand-block { padding-left: 13px; padding-right: 13px; }
  .path-examples { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  body { overflow: auto; }

  .app-shell {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }

  .graph-panel {
    order: 1;
    grid-template-rows: auto 62vh 112px;
    min-height: 720px;
  }

  .sidebar {
    order: 2;
    width: 100%;
    overflow: visible;
    border-top: 1px solid var(--line);
    border-right: 0;
  }

  .reader {
    order: 3;
    width: 100%;
    height: 70vh;
    min-height: 540px;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .path-examples { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 520px) {
  .graph-toolbar { align-items: flex-start; }
  .graph-toolbar h1 { font-size: 15px; }
  .graph-panel { grid-template-rows: auto 60vh 106px; }
  .path-examples { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
