/* LevchykUGS · Trend brains — connected graph.
   Clay design system (DESIGN.md): cream canvas, hairlines, generous radii, Inter fallback stack.
   A vanilla port of MediaMagic's WikiGraph / NodeDetail / WikiMarkdown look. */

:root {
  --canvas: #fffaf0;
  --surface-soft: #faf5e8;
  --surface-card: #f5f0e0;
  --surface-strong: #ebe6d6;
  --ink: #0a0a0a;
  --body: #3a3a3a;
  --muted: #6a6a6a;
  --muted-soft: #9a9a9a;
  --hairline: #e5e5e5;
  --hairline-soft: #f0f0f0;
  --brand-pink: #ff4d8b;
  --brand-teal: #1a3a3a;
  --brand-lavender: #b8a4ed;
  --brand-peach: #ffb084;
  --brand-ochre: #e8b94a;
  --brand-mint: #a4d4c5;
  --brand-coral: #ff6b5a;
  --sky: #38bdf8;
  --font: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-xxl: 24px;
  --drawer-w: 400px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--canvas);
  color: var(--body);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img, video { display: block; max-width: 100%; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Display headlines: Inter 500 with -0.05em tracking approximates Plain Black (DESIGN.md). */
.display { font-weight: 500; letter-spacing: -0.05em; color: var(--ink); line-height: 1.05; }

/* ─── top bar ─────────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  min-height: 64px; padding: 12px 24px; background: var(--canvas);
}
.brand { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-width: 0; }
.wordmark { font-size: 15px; font-weight: 600; letter-spacing: -0.02em; color: var(--ink); white-space: nowrap; }
.counts { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 9999px;
  background: var(--surface-card); color: var(--ink); font-size: 12px; font-weight: 500; line-height: 1.4;
  white-space: nowrap;
}
.pill b { font-weight: 600; }
.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; padding: 2px; border: 1px solid var(--hairline); border-radius: 9999px; background: var(--canvas); }
.seg button {
  border: 0; background: transparent; color: var(--muted); border-radius: 9999px;
  padding: 6px 12px; font-size: 12px; font-weight: 500; line-height: 1.2;
}
.seg button[aria-pressed="true"] { background: var(--surface-card); color: var(--ink); }
.toggle {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--hairline); background: var(--canvas);
  color: var(--muted); border-radius: 9999px; padding: 6px 12px; font-size: 12px; font-weight: 500; line-height: 1.2;
}
.toggle[aria-pressed="true"] { background: var(--surface-card); color: var(--ink); border-color: var(--surface-strong); }
.toggle .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--hairline); }
.toggle[aria-pressed="true"] .dot { background: var(--brand-teal); }
.field {
  height: 34px; padding: 0 12px; border: 1px solid var(--hairline); border-radius: var(--r-md);
  background: var(--canvas); color: var(--ink); font-size: 13px;
}
.field:focus { border-color: var(--ink); }
select.field { max-width: 260px; padding-right: 28px; appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236a6a6a' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
input.field { width: 180px; }
input.field::placeholder { color: var(--muted-soft); }

/* ─── layout ─────────────────────────────────────────────────────────────── */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) var(--drawer-w); gap: 20px; align-items: start;
  padding: 4px 24px 24px;
}
.layout.no-drawer { grid-template-columns: minmax(0, 1fr); }

/* ─── canvas card ────────────────────────────────────────────────────────── */
.canvas { border: 1px solid var(--hairline); border-radius: var(--r-xl); background: var(--surface-soft); overflow: hidden; min-width: 0; }
.canvas-rel { position: relative; }
.scroller { overflow: auto; overscroll-behavior: contain; padding: 16px; max-height: 82vh; scrollbar-width: thin; }
.stage { position: relative; }
.stage-head {
  position: absolute; top: 0; text-align: center; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.14em; color: var(--muted); line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stage-head small { display: block; font-size: 9px; font-weight: 500; letter-spacing: 0.08em; color: var(--muted-soft); text-transform: none; }
.edges { position: absolute; left: 0; pointer-events: none; overflow: visible; }
.edges path { fill: none; transition: stroke-opacity .3s ease-out, stroke-width .3s ease-out; }
.cards { position: absolute; left: 0; }
.scroll-fade {
  pointer-events: none; position: absolute; right: 0; top: 0; height: 100%; width: 48px;
  background: linear-gradient(to left, var(--surface-soft), rgba(250, 245, 232, 0));
}
.empty {
  padding: 48px 24px; text-align: center; color: var(--muted-soft); font-size: 13px;
}

/* ─── cards ──────────────────────────────────────────────────────────────── */
.card {
  position: absolute; display: flex; flex-direction: column; text-align: left; overflow: hidden;
  border-radius: var(--r-md); border: 1px solid var(--hairline); background: var(--canvas);
  padding: 8px 10px 8px 14px; margin: 0; color: var(--body);
  transition: height .3s ease-out, top .3s ease-out, left .3s ease-out, opacity .3s ease-out, box-shadow .3s ease-out, border-color .3s ease-out;
}
.card:hover { border-color: rgba(26, 58, 58, .4); box-shadow: 0 1px 2px rgba(0, 0, 0, .05); }
.card.in-highlight { border-color: rgba(26, 58, 58, .4); box-shadow: 0 1px 2px rgba(0, 0, 0, .05); }
.card.is-selected {
  border-color: var(--ink); box-shadow: 0 0 0 2px rgba(10, 10, 10, .15), 0 4px 6px -1px rgba(0, 0, 0, .1), 0 2px 4px -2px rgba(0, 0, 0, .1);
}
.card.is-collapsed { padding: 0 8px; }
.card.dim-25 { opacity: .25; }
.card.dim-50 { opacity: .5; }
.card.is-stale { border-style: dashed; }
.accent { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }
.dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; flex: none; }
.kicker { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; min-width: 0; }
.kicker-l {
  display: inline-flex; align-items: center; gap: 6px; min-width: 0;
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted-soft);
}
.kicker-t { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.badges { display: inline-flex; align-items: center; gap: 6px; flex: none; }
.badge {
  display: inline-flex; align-items: center; border-radius: 9999px; padding: 2px 6px;
  font-size: 9px; font-weight: 700; line-height: 1.2; text-transform: lowercase;
  background: var(--surface-card); color: var(--muted-soft); border: 1px solid var(--hairline);
}
.badge-verified { background: var(--brand-teal); color: #fff; border-color: var(--brand-teal); }
.badge-stale { background: var(--brand-ochre); color: var(--ink); border-color: var(--brand-ochre); }
.card-title {
  flex: none; margin-top: 2px; font-size: 13px; font-weight: 600; line-height: 1.35; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.chips { margin-top: auto; flex: 0 1 auto; min-height: 0; overflow: hidden; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding-top: 6px; }
.chip {
  display: inline-block; vertical-align: middle; border-radius: 9999px; background: var(--surface-card);
  padding: 2px 6px; font-size: 9.5px; font-weight: 500; line-height: 1.3; color: var(--muted);
  max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.well {
  margin-top: 4px; flex: 1 1 auto; min-height: 0; border-radius: 7px; background: var(--surface-card);
  overflow: hidden; position: relative;
}
.well img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.well .ph { position: absolute; inset: 0; display: grid; place-items: center; font-size: 9.5px; color: #b8b0a0; text-align: center; padding: 4px; }
.tf-title { margin-top: 4px; font-size: 11px; font-weight: 600; line-height: 1.25; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tf-meta { margin-top: 2px; font-size: 9.5px; font-weight: 600; color: var(--body); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tf-meta i { font-style: normal; color: #ccc; }
.pill-row { display: flex; height: 100%; align-items: center; gap: 6px; padding-left: 6px; min-width: 0; }
.pill-kind { flex: 0 1 auto; min-width: 0; max-width: 58%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 8.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted-soft); }
.status-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--surface-card); box-shadow: 0 0 0 1px rgba(0, 0, 0, .1); }
.status-dot.st-verified { background: var(--brand-teal); }
.status-dot.st-stale { background: var(--brand-ochre); }
.status-dot.st-source { background: var(--surface-strong); }
.pill-title { min-width: 0; flex: 1; font-size: 11px; font-weight: 500; color: #2a2a2a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ─── legend ─────────────────────────────────────────────────────────────── */
.legend {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; border-top: 1px solid var(--hairline);
  padding: 10px 16px; font-size: 11px; color: var(--muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-line { width: 20px; height: 0; border-top: 2px solid rgba(26, 58, 58, .5); margin-top: 1px; }
.legend-line.amber { border-color: var(--brand-ochre); }
.legend-line.purple { border-color: var(--brand-lavender); border-top-style: dashed; }
.legend-line.sky { border-color: var(--sky); }
.legend-btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--hairline); border-radius: 9999px;
  background: var(--surface-soft); padding: 4px 12px; font-size: 11px; font-weight: 500; color: var(--muted);
}
.legend-btn:hover { border-color: rgba(26, 58, 58, .4); color: var(--ink); }
.legend-hint { margin-left: auto; font-style: italic; color: var(--muted-soft); }

/* ─── drawer ─────────────────────────────────────────────────────────────── */
.drawer { position: sticky; top: 16px; height: 82vh; min-width: 0; }
.drawer-card {
  height: 100%; display: flex; flex-direction: column; overflow: hidden;
  border: 1px solid var(--hairline); border-radius: var(--r-xl); background: var(--canvas);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, .1), 0 8px 10px -6px rgba(0, 0, 0, .1);
}
.drawer-empty {
  height: 100%; min-height: 280px; display: flex; align-items: center; justify-content: center; text-align: center;
  border: 1px solid var(--hairline); border-radius: var(--r-xl); background: var(--canvas); padding: 32px;
}
.drawer-empty p { max-width: 220px; margin: 0; font-size: 13px; color: var(--muted-soft); }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 20px 12px; border-bottom: 1px solid var(--hairline); }
.drawer-head .min { min-width: 0; }
.kicker-lg { margin: 0; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-title { margin: 2px 0 0; font-size: 20px; }
.btn-x {
  flex: none; width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted-soft); font-size: 14px;
}
.btn-x:hover { background: var(--surface-card); color: var(--ink); }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 20px; }
.label { margin: 0 0 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted-soft); }
.field-p { margin: 0; font-size: 14px; color: var(--body); line-height: 1.6; white-space: pre-wrap; }
.chiprow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tag { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 9999px; font-size: 12px; font-weight: 500; background: var(--surface-card); color: var(--muted); }
.tag-ink { background: var(--brand-teal); color: #fff; }
.tag-ochre { background: var(--brand-ochre); color: var(--ink); font-weight: 600; }
.tag-line { background: var(--surface-soft); border: 1px solid var(--hairline); }
.tag-mint { background: var(--brand-mint); color: var(--ink); }
.tag-lavender { background: var(--brand-lavender); color: var(--ink); }
.link-btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--hairline); border-radius: 9999px;
  background: var(--surface-soft); padding: 6px 12px; font-size: 13px; font-weight: 500; color: var(--brand-teal); text-decoration: none;
}
.link-btn:hover { border-color: rgba(26, 58, 58, .4); }
.link-plain { color: var(--brand-teal); text-decoration: underline; text-underline-offset: 2px; word-break: break-all; font-size: 13px; }
.media { width: 100%; border-radius: 14px; border: 1px solid var(--hairline); background: var(--surface-card); overflow: hidden; }
.media video { width: 100%; max-height: 420px; background: #000; }
.media img { width: 100%; height: auto; }
.media-note { padding: 12px 14px; font-size: 12px; color: var(--muted-soft); }
.notice { border: 1px dashed var(--hairline); border-radius: var(--r-md); background: var(--surface-soft); padding: 12px 16px; }
.notice p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.6; }
.notice ul { margin: 6px 0 0; padding: 0; list-style: none; columns: 2; font-size: 12px; color: var(--muted); }
.notice li { font-family: var(--mono); font-size: 11px; line-height: 1.7; break-inside: avoid; }
.deps { display: flex; flex-direction: column; gap: 12px; padding-top: 8px; border-top: 1px solid var(--hairline); }
.dep-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.dep-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 9999px; font-size: 12px;
  background: var(--surface-soft); border: 1px solid var(--hairline); color: var(--body); max-width: 100%;
}
.dep-chip:hover { border-color: rgba(26, 58, 58, .4); color: var(--ink); }
.dep-chip span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.dep-chip .dot { width: 6px; height: 6px; }
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; border: 1px solid var(--hairline); background: var(--surface-card); }

/* ─── wiki markdown (WikiMarkdown.tsx port) ──────────────────────────────── */
.wiki-prose { min-width: 0; }
.wiki-prose > :first-child { margin-top: 0; }
.wiki-prose h1 { font-size: 24px; font-weight: 500; letter-spacing: -0.05em; line-height: 1.1; color: var(--ink); margin: 0 0 24px; padding-bottom: 12px; border-bottom: 1px solid var(--hairline); }
.wiki-prose h2 { font-size: 18px; font-weight: 600; color: var(--ink); margin: 32px 0 12px; line-height: 1.3; }
.wiki-prose h3 { font-size: 16px; font-weight: 600; color: var(--ink); margin: 24px 0 8px; }
.wiki-prose h4, .wiki-prose h5, .wiki-prose h6 { font-size: 14px; font-weight: 600; color: var(--ink); margin: 20px 0 6px; }
.wiki-prose p { font-size: 14px; color: var(--body); line-height: 1.625; margin: 0 0 16px; }
.wiki-prose ul, .wiki-prose ol { margin: 0 0 16px; padding-left: 16px; }
.wiki-prose ul { list-style: none; padding-left: 0; }
.wiki-prose ul > li { display: flex; gap: 8px; font-size: 14px; color: var(--body); line-height: 1.625; margin-bottom: 6px; }
.wiki-prose ul > li::before { content: "—"; color: var(--muted-soft); flex: none; }
.wiki-prose ul > li > * { min-width: 0; }
.wiki-prose ul > li > p { margin: 0; }
.wiki-prose ul ul { margin: 4px 0 0; width: 100%; }
.wiki-prose ol > li { font-size: 14px; color: var(--body); line-height: 1.625; margin-bottom: 6px; }
.wiki-prose ol > li > p { margin: 0; }
.wiki-prose blockquote { border-left: 2px solid var(--brand-ochre); padding-left: 16px; margin: 16px 0; font-size: 14px; color: var(--muted); font-style: italic; }
.wiki-prose blockquote p { color: inherit; margin-bottom: 8px; }
.wiki-prose code { font-family: var(--mono); font-size: 12px; background: var(--surface-soft); border: 1px solid var(--hairline); border-radius: 4px; padding: 1px 6px; }
.wiki-prose pre { margin: 0 0 16px; overflow-x: auto; }
.wiki-prose pre code { display: block; padding: 16px; border-radius: var(--r-sm); white-space: pre; }
.wiki-prose a { color: var(--ink); text-decoration: underline; text-underline-offset: 2px; }
.wiki-prose a:hover { color: var(--body); }
.wiki-prose a.node-link { text-decoration-color: rgba(26, 58, 58, .4); }
.wiki-prose .dead-link { color: var(--muted-soft); border-bottom: 1px dotted var(--muted-soft); }
.wiki-prose strong { font-weight: 600; color: var(--ink); }
.wiki-prose em { font-style: italic; color: var(--body); }
.wiki-prose hr { border: 0; border-top: 1px solid var(--hairline); margin: 24px 0; }
.wiki-prose img { max-width: 100%; height: auto; border-radius: var(--r-md); border: 1px solid var(--hairline); margin: 8px 0 16px; background: var(--surface-card); }
.wiki-prose .table-wrap { overflow-x: auto; margin: 0 0 16px; border: 1px solid var(--hairline); border-radius: var(--r-sm); }
.wiki-prose table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.wiki-prose th, .wiki-prose td { text-align: left; vertical-align: top; padding: 6px 10px; border-bottom: 1px solid var(--hairline); color: var(--body); line-height: 1.5; }
.wiki-prose th { background: var(--surface-soft); color: var(--ink); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.wiki-prose tr:last-child td { border-bottom: 0; }

/* ─── animations ─────────────────────────────────────────────────────────── */
@keyframes dashFlow { from { stroke-dashoffset: 0; } to { stroke-dashoffset: -20; } }
.wiki-edge-flow { animation: dashFlow .7s linear infinite; }
@media (prefers-reduced-motion: reduce) {
  .wiki-edge-flow { animation: none; }
  .card, .edges path { transition: none; }
}

/* ─── responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1200px) {
  :root { --drawer-w: 340px; }
  input.field { width: 150px; }
}
@media (max-width: 1024px) {
  :root { --drawer-w: 320px; }
  .topbar { padding: 12px 16px; }
  .layout { padding: 4px 16px 16px; gap: 16px; }
  select.field { max-width: 200px; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .drawer { position: static; height: auto; }
  .drawer-card { height: auto; max-height: 75vh; }
  .drawer-empty { min-height: 120px; }
  .legend-hint { margin-left: 0; }
}
