/* ============================================================================
   STAG Brain Navigator — design system
   Dark "observatory" · charcoal-ink canvas · golden-hour accent (brand-locked)
   Type on a contrast axis: Newsreader (display serif) + Geist + Geist Mono
   ========================================================================== */

/* ---- fonts (self-hosted, offline) ---------------------------------------- */
@font-face {
  font-family: "Newsreader";
  src: url("../fonts/newsreader-normal.woff2") format("woff2");
  font-weight: 200 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Newsreader";
  src: url("../fonts/newsreader-italic.woff2") format("woff2");
  font-weight: 200 700; font-style: italic; font-display: swap;
}
@font-face {
  font-family: "Geist";
  src: url("../fonts/geist-normal.woff2") format("woff2");
  font-weight: 100 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("../fonts/geist-mono-normal.woff2") format("woff2");
  font-weight: 300 700; font-style: normal; font-display: swap;
}

/* ---- tokens -------------------------------------------------------------- */
:root {
  /* ink canvas */
  --bg:          oklch(0.155 0.014 256);
  --bg-deep:     oklch(0.125 0.013 258);
  --surface:     oklch(0.198 0.016 256);
  --surface-2:   oklch(0.238 0.018 256);
  --surface-3:   oklch(0.285 0.018 256);
  --border:      oklch(0.318 0.016 256);
  --border-2:    oklch(0.40 0.018 256);

  /* text */
  --ink:         oklch(0.965 0.006 250);
  --ink-2:       oklch(0.805 0.012 250);
  --ink-3:       oklch(0.668 0.012 250);
  --ink-faint:   oklch(0.535 0.012 250);

  /* golden-hour accent (brand-locked single accent) */
  --gold:        oklch(0.83 0.135 80);
  --gold-bright: oklch(0.90 0.118 88);
  --gold-deep:   oklch(0.72 0.14 70);
  --gold-soft:   oklch(0.83 0.135 80 / 0.14);
  --gold-line:   oklch(0.83 0.135 80 / 0.34);
  --on-gold:     oklch(0.18 0.03 78);

  --danger:      oklch(0.70 0.15 25);

  /* radius — shape lock: panels 14 · controls 10 · chips 8 · pill 999 */
  --r-panel: 14px;
  --r-ctrl: 10px;
  --r-chip: 8px;
  --r-pill: 999px;

  /* motion */
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --dur-fast: 150ms;
  --dur: 260ms;
  --dur-slow: 440ms;

  /* z-scale */
  --z-graph: 1;
  --z-legend: 10;
  --z-sidebar: 30;
  --z-topbar: 50;
  --z-overlay: 60;
  --z-drawer: 70;
  --z-toast: 90;
  --z-tip: 100;

  --topbar-h: 60px;
  --sidebar-w: 300px;
  --font-body: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Newsreader", Georgia, "Times New Roman", serif;
  --font-mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;

  color-scheme: dark;
}

/* ---- reset / base -------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink-2);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden; /* app owns its own scroll regions */
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer;
  touch-action: manipulation; -webkit-touch-callout: none; }
/* interactive chrome: tap goes to the control, not an OS-detected sub-link/callout */
.fcard, .dcard, .tree__file, .tree__folderbtn, .legend__item, .linkrow, .btn, .icon-btn {
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
}
input { font: inherit; }
::selection { background: var(--gold-soft); color: var(--ink); }

/* tasteful scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 999px;
  border: 3px solid transparent; background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--border-2); }

/* deep-space vignette behind everything */
#app::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% -10%, oklch(0.24 0.03 268 / 0.55), transparent 60%),
    radial-gradient(80% 60% at 100% 110%, oklch(0.2 0.04 70 / 0.18), transparent 70%),
    var(--bg-deep);
}
/* faint film grain — fixed, non-repainting */
#app::after {
  content: ""; position: fixed; inset: 0; z-index: var(--z-tip); pointer-events: none;
  opacity: 0.025; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---- shared atoms -------------------------------------------------------- */
.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--ink-faint);
}
.mono { font-family: var(--font-mono); }
.tnum { font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex; align-items: center; gap: 0.5em;
  padding: 0.62em 1.05em; border-radius: var(--r-ctrl);
  font-weight: 500; letter-spacing: 0.01em;
  border: 1px solid var(--border-2); color: var(--ink);
  background: var(--surface-2);
  transition: transform var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--surface-3); border-color: var(--border-2); }
.btn:active { transform: translateY(1px); }
.btn--gold {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: var(--on-gold); border-color: transparent; font-weight: 600;
  box-shadow: 0 1px 0 oklch(1 0 0 / 0.3) inset,
    0 8px 26px oklch(0.83 0.135 80 / 0.28);
}
.btn--gold:hover { filter: brightness(1.05); background: linear-gradient(180deg, var(--gold-bright), var(--gold)); }
.btn--ghost { background: transparent; border-color: var(--border); color: var(--ink-2); }
.btn--ghost:hover { color: var(--ink); border-color: var(--border-2); background: var(--surface); }

:where(button, a, input, [tabindex]):focus-visible {
  outline: 2px solid var(--gold); outline-offset: 2px; border-radius: var(--r-ctrl);
}

.chip {
  display: inline-flex; align-items: center; gap: 0.4em;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.04em;
  padding: 0.28em 0.6em; border-radius: var(--r-chip);
  border: 1px solid var(--border); color: var(--ink-3); background: var(--surface);
}
.dot { width: 8px; height: 8px; border-radius: 999px; flex: none; }

/* ============================================================================
   APP SHELL
   ========================================================================== */
#app { position: relative; height: 100dvh; isolation: isolate; }

.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: var(--z-topbar);
  display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: oklch(0.155 0.014 256 / 0.72);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  border-bottom: 1px solid var(--border);
}
.topbar__left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.icon-btn {
  display: grid; place-items: center; width: 38px; height: 38px;
  border-radius: var(--r-ctrl); color: var(--ink-2);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }
.sidebar-toggle { display: none; }

/* wordmark */
.wordmark { display: inline-flex; align-items: center; gap: 10px; }
.wordmark__mark { width: 30px; height: 30px; flex: none; color: var(--gold); }
.wordmark__type { display: flex; flex-direction: column; line-height: 0.92; }
.wordmark__type b {
  font-family: var(--font-display); font-weight: 600; font-size: 19px;
  letter-spacing: 0.14em; color: var(--ink); padding-left: 2px;
}
.wordmark__type span {
  font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.42em;
  color: var(--ink-faint); padding-left: 4px;
}

.topbar__spacer { flex: 1; }

/* global search */
.search {
  position: relative; display: flex; align-items: center;
  width: min(420px, 42vw);
}
.search svg.search__icon {
  position: absolute; left: 12px; width: 16px; height: 16px;
  color: var(--ink-faint); pointer-events: none;
}
.search input {
  width: 100%; height: 40px; padding: 0 38px 0 36px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-pill); color: var(--ink);
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.search input::placeholder { color: var(--ink-faint); }
.search input:focus { outline: none; border-color: var(--gold-line); background: var(--surface-2); }
.search kbd {
  position: absolute; right: 10px; font-family: var(--font-mono); font-size: 11px;
  color: var(--ink-faint); border: 1px solid var(--border); border-radius: 6px;
  padding: 1px 6px; background: var(--bg);
}
.search__clear {
  position: absolute; right: 8px; width: 26px; height: 26px; display: none;
  place-items: center; color: var(--ink-3); border-radius: 8px;
}
.search--filled .search__clear { display: grid; }
.search--filled kbd { display: none; }

.topbar__stats {
  display: flex; gap: 18px; font-family: var(--font-mono); font-size: 11px;
  color: var(--ink-faint);
}
.topbar__stats b { color: var(--ink-2); font-weight: 500; }
.topbar__stats span { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.topbar__stats .lab { font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase; }

/* ---- workspace grid ------------------------------------------------------ */
.workspace {
  position: absolute; inset: var(--topbar-h) 0 0 0; z-index: var(--z-graph);
  display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 0;
  transition: grid-template-columns var(--dur) var(--ease);
}
.workspace.sidebar-collapsed { grid-template-columns: 0 1fr; }

/* ---- sidebar ------------------------------------------------------------- */
.sidebar {
  position: relative; z-index: var(--z-sidebar);
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: oklch(0.165 0.014 256 / 0.78);
  backdrop-filter: blur(12px);
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.sidebar__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px; flex: none;
}
.sidebar__head .eyebrow { font-size: 10px; }
.sidebar__count { font-family: var(--font-mono); font-size: 11px; color: var(--ink-faint); }
.tree { flex: 1; overflow-y: auto; padding: 2px 8px 24px; min-height: 0; }

.tree__folder { margin-bottom: 1px; }
.tree__folderbtn {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 7px 8px; border-radius: var(--r-chip); color: var(--ink-2);
  text-align: left; transition: background var(--dur-fast) var(--ease);
}
.tree__folderbtn:hover { background: var(--surface); color: var(--ink); }
.tree__folderbtn .caret {
  width: 14px; height: 14px; flex: none; color: var(--ink-faint);
  transition: transform var(--dur-fast) var(--ease);
}
.tree__folder.open > .tree__folderbtn .caret { transform: rotate(90deg); }
.tree__folderbtn .swatch { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.tree__folderbtn .name { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree__folderbtn .n { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-faint); }

.tree__files {
  display: none; padding: 2px 0 6px 14px; margin-left: 13px;
  border-left: 1px solid var(--border);
}
.tree__folder.open > .tree__files { display: block; }
.tree__file {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 5px 8px; border-radius: var(--r-chip); color: var(--ink-3);
  text-align: left; font-size: 13px; line-height: 1.35;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.tree__file:hover { background: var(--surface); color: var(--ink); }
.tree__file.active { background: var(--gold-soft); color: var(--ink); }
.tree__file .ti { width: 13px; height: 13px; flex: none; color: var(--ink-faint); }
.tree__file.active .ti { color: var(--gold); }
.tree__file .label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree__file mark { background: var(--gold-soft); color: var(--gold-bright); border-radius: 3px; }

.tree__empty { padding: 24px 12px; color: var(--ink-faint); font-size: 13px; text-align: center; }
.tree__sub { padding-left: 6px; margin: 6px 0 2px; }
.tree__sub .eyebrow { font-size: 9px; }

/* ---- main stage (graph + reader) ----------------------------------------- */
.stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#graph { position: absolute; inset: 0; z-index: var(--z-graph); }
#graph canvas { display: block; }

.stage__hint {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: var(--z-legend); font-family: var(--font-mono); font-size: 11px;
  color: var(--ink-faint); letter-spacing: 0.04em; padding: 6px 14px;
  background: oklch(0.155 0.014 256 / 0.6); border: 1px solid var(--border);
  border-radius: var(--r-pill); backdrop-filter: blur(8px);
  pointer-events: none; transition: opacity var(--dur) var(--ease);
}

/* graph controls (zoom / fit) */
.gcontrols {
  position: absolute; right: 16px; bottom: 18px; z-index: var(--z-legend);
  display: flex; flex-direction: column; gap: 6px;
}
.gcontrols button {
  width: 36px; height: 36px; display: grid; place-items: center;
  background: oklch(0.198 0.016 256 / 0.8); border: 1px solid var(--border);
  border-radius: var(--r-ctrl); color: var(--ink-2);
  backdrop-filter: blur(8px); transition: all var(--dur-fast) var(--ease);
}
.gcontrols button:hover { color: var(--ink); border-color: var(--border-2); background: var(--surface-2); }
.gcontrols svg { width: 16px; height: 16px; }

/* ---- legend -------------------------------------------------------------- */
.legend {
  position: absolute; left: 16px; top: 16px; z-index: var(--z-legend);
  width: 224px; max-height: calc(100% - 32px); display: flex; flex-direction: column;
  background: oklch(0.165 0.014 256 / 0.74); border: 1px solid var(--border);
  border-radius: var(--r-panel); backdrop-filter: blur(16px) saturate(1.2);
  box-shadow: 0 20px 50px oklch(0 0 0 / 0.4); overflow: hidden;
  transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.legend__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px 8px;
}
.legend__head .eyebrow { font-size: 10px; }
.legend__collapse { display: flex; align-items: center; gap: 7px; padding: 2px;
  border-radius: 6px; }
.legend__collapse:hover .eyebrow { color: var(--ink-2); }
.legend__caret { width: 14px; height: 14px; color: var(--ink-faint);
  transform: rotate(90deg); transition: transform var(--dur-fast) var(--ease); }
.legend.collapsed .legend__caret { transform: rotate(0deg); }
.legend.collapsed .legend__list { display: none; }
.legend.collapsed .legend__toggleall { display: none; }
.legend.collapsed { width: auto; }
.legend__toggleall { font-family: var(--font-mono); font-size: 10px; color: var(--ink-faint);
  letter-spacing: 0.06em; padding: 2px 4px; border-radius: 6px; }
.legend__toggleall:hover { color: var(--gold); }
.legend__list { overflow-y: auto; padding: 2px 8px 10px; }
.legend__item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 5px 7px; border-radius: var(--r-chip); text-align: left;
  color: var(--ink-2); transition: background var(--dur-fast) var(--ease);
}
.legend__item:hover { background: var(--surface); }
.legend__item .swatch {
  width: 11px; height: 11px; border-radius: 4px; flex: none;
  box-shadow: 0 0 8px var(--sw, transparent);
  transition: opacity var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.legend__item .name { flex: 1; min-width: 0; font-size: 12.5px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.legend__item .n { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-faint); }
.legend__item.off { color: var(--ink-faint); }
.legend__item.off .swatch { opacity: 0.22; box-shadow: none; }
.legend__item.off .name { text-decoration: line-through; text-decoration-color: var(--border-2); }

/* ============================================================================
   HOME / DASHBOARD  (full overlay view)
   ========================================================================== */
.home {
  position: absolute; inset: var(--topbar-h) 0 0 0; z-index: var(--z-overlay);
  overflow-y: auto; overflow-x: hidden;
  opacity: 1; transition: opacity var(--dur) var(--ease);
  background:
    radial-gradient(120% 80% at 50% -10%, oklch(0.22 0.03 268 / 0.6), transparent 55%),
    radial-gradient(70% 60% at 100% 110%, oklch(0.2 0.05 70 / 0.16), transparent 70%),
    var(--bg-deep);
}
/* sprite icons created via the icon() helper need explicit sizing per context */
.btn svg { width: 17px; height: 17px; flex: none; }
.chip svg { width: 13px; height: 13px; flex: none; color: var(--ink-faint); }
.links__col h4 svg { width: 14px; height: 14px; flex: none; }
.dcard__open svg { width: 14px; height: 14px; flex: none; }
.home[hidden] { display: none; }
.home__inner { max-width: 1180px; margin: 0 auto; padding: clamp(40px, 7vh, 84px) 28px 96px; }

/* hero */
.hero { position: relative; display: grid; grid-template-columns: 1.15fr 0.85fr;
  gap: 40px; align-items: center; }
.hero__kicker { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.hero__kicker .line { height: 1px; width: 40px; background: var(--gold-line); }
.hero h1 {
  font-family: var(--font-display); font-weight: 400; color: var(--ink);
  font-size: clamp(2.6rem, 5.2vw, 4.3rem); line-height: 1.02;
  letter-spacing: -0.02em; text-wrap: balance;
}
.hero h1 em { font-style: italic; color: var(--gold); }
.hero__thesis {
  margin-top: 24px; max-width: 60ch; font-size: clamp(15px, 1.6vw, 17px);
  line-height: 1.7; color: var(--ink-2); text-wrap: pretty;
}
.hero__thesis strong { color: var(--ink); font-weight: 600; }
.hero__front {
  margin-top: 22px; padding: 14px 18px; border-left: 0;
  border: 1px solid var(--border); border-radius: var(--r-panel);
  background: linear-gradient(120deg, var(--gold-soft), transparent 70%);
  font-family: var(--font-display); font-style: italic; font-size: 16.5px;
  color: var(--ink); line-height: 1.5; max-width: 56ch;
}
.hero__cta { margin-top: 30px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.hero__cta .meta { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-faint); }

/* the constellation mark on the right of the hero */
.hero__art {
  position: relative; aspect-ratio: 1; width: 100%; max-width: 380px; justify-self: end;
}
.hero__art canvas { width: 100%; height: 100%; display: block; }

/* stat strip */
.statstrip {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px;
  margin-top: 56px; background: var(--border); border: 1px solid var(--border);
  border-radius: var(--r-panel); overflow: hidden;
}
.statstrip > div { background: var(--surface); padding: 18px 20px; }
.statstrip .v { font-family: var(--font-display); font-size: 30px; color: var(--ink);
  line-height: 1; font-variant-numeric: tabular-nums; }
.statstrip .k { margin-top: 7px; font-family: var(--font-mono); font-size: 10.5px;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-faint); }

/* section heading */
.home section { margin-top: 64px; }
.home__sectionhead { display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; margin-bottom: 22px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.home__sectionhead h2 { font-family: var(--font-display); font-weight: 400; color: var(--ink);
  font-size: clamp(1.4rem, 2.6vw, 2rem); letter-spacing: -0.01em; }
.home__sectionhead p { color: var(--ink-3); font-size: 13.5px; max-width: 46ch; text-align: right; }

/* folder cards */
.folders { display: grid; grid-template-columns: repeat(auto-fill, minmax(248px, 1fr)); gap: 14px; }
.fcard {
  position: relative; text-align: left; padding: 18px; border-radius: var(--r-panel);
  background: var(--surface); border: 1px solid var(--border); overflow: hidden;
  transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease),
    background var(--dur) var(--ease);
}
.fcard::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: radial-gradient(130% 100% at 100% 0%,
    color-mix(in oklab, var(--fc, var(--gold)) 14%, transparent), transparent 52%);
  opacity: 0.55; transition: opacity var(--dur) var(--ease);
}
.fcard:hover { transform: translateY(-3px); background: var(--surface-2);
  border-color: color-mix(in oklab, var(--fc, var(--gold)) 42%, var(--border)); }
.fcard:hover::before { opacity: 1; }
.fcard__top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.fcard__num { font-family: var(--font-mono); font-size: 12px; color: var(--fc); letter-spacing: 0.1em; }
.fcard__count { font-family: var(--font-mono); font-size: 12px; color: var(--ink-3);
  display: flex; align-items: center; gap: 6px; }
.fcard__count .dot { background: var(--fc); box-shadow: 0 0 10px var(--fc); }
.fcard h3 { font-size: 16px; color: var(--ink); font-weight: 600; letter-spacing: -0.01em; }
.fcard p { margin-top: 6px; font-size: 13px; color: var(--ink-3); line-height: 1.5; }
.fcard__go { margin-top: 14px; display: flex; align-items: center; gap: 6px;
  font-family: var(--font-mono); font-size: 11px; color: var(--ink-faint);
  letter-spacing: 0.04em; transition: color var(--dur-fast) var(--ease); }
.fcard:hover .fcard__go { color: var(--fc); }
.fcard__go svg { width: 13px; height: 13px; transition: transform var(--dur) var(--ease); }
.fcard:hover .fcard__go svg { transform: translateX(3px); }

/* open decisions */
.decisions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.dcard {
  position: relative; padding: 20px; border-radius: var(--r-panel);
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border); text-align: left;
  transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.dcard:hover { transform: translateY(-3px); border-color: var(--gold-line); }
.dcard__tag { display: inline-flex; align-items: center; gap: 7px; margin-bottom: 14px;
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--gold); }
.dcard__tag .num { width: 22px; height: 22px; display: grid; place-items: center;
  border: 1px solid var(--gold-line); border-radius: 999px; color: var(--gold);
  font-size: 11px; letter-spacing: 0; }
.dcard h3 { font-family: var(--font-display); font-weight: 500; font-size: 18px; color: var(--ink);
  line-height: 1.2; }
.dcard p { margin-top: 9px; font-size: 13px; color: var(--ink-3); line-height: 1.55; }
.dcard__open { margin-top: 14px; font-family: var(--font-mono); font-size: 11px; color: var(--ink-faint);
  display: flex; align-items: center; gap: 6px; }
.dcard:hover .dcard__open { color: var(--gold); }

.home__foot { margin-top: 70px; padding-top: 18px; border-top: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 14px; justify-content: space-between;
  font-family: var(--font-mono); font-size: 11px; color: var(--ink-faint); }
.home__foot a:hover { color: var(--gold); }

/* ============================================================================
   READER DRAWER
   ========================================================================== */
.reader {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: var(--z-drawer);
  width: min(640px, 50vw); display: flex; flex-direction: column;
  background: oklch(0.175 0.013 256 / 0.97);
  backdrop-filter: blur(20px); border-left: 1px solid var(--border);
  box-shadow: -28px 0 70px oklch(0 0 0 / 0.5);
  transform: translateX(100%); transition: transform var(--dur-slow) var(--ease);
}
.reader.open { transform: translateX(0); }
.reader__head {
  flex: none; padding: 16px 20px 14px; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px;
  background: linear-gradient(180deg, var(--surface), transparent);
}
.reader__crumbs { display: flex; align-items: center; gap: 8px; min-width: 0;
  font-family: var(--font-mono); font-size: 11px; color: var(--ink-faint); }
.reader__crumbs .sw { width: 8px; height: 8px; border-radius: 3px; flex: none; }
.reader__crumbs .path { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader__headrow { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.reader__title { font-family: var(--font-display); font-weight: 500; color: var(--ink);
  font-size: clamp(1.25rem, 2.4vw, 1.7rem); line-height: 1.12; letter-spacing: -0.015em;
  text-wrap: balance; }
.reader__actions { display: flex; gap: 4px; flex: none; }
.reader__meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.reader__body { flex: 1; overflow-y: auto; padding: 24px 28px 60px; min-height: 0; }

/* prose typography */
.prose { color: var(--ink-2); font-size: 15px; line-height: 1.72; max-width: 70ch; }
.prose > *:first-child { margin-top: 0 !important; }
.prose h1, .prose h2, .prose h3, .prose h4 {
  font-family: var(--font-display); color: var(--ink); font-weight: 500;
  line-height: 1.18; letter-spacing: -0.01em; text-wrap: balance;
}
.prose h1 { font-size: 1.7em; margin: 1.6em 0 0.5em; }
.prose h2 { font-size: 1.34em; margin: 1.7em 0 0.5em; padding-bottom: 0.3em;
  border-bottom: 1px solid var(--border); }
.prose h3 { font-size: 1.12em; margin: 1.5em 0 0.4em; color: var(--ink); }
.prose h4 { font-size: 1em; margin: 1.3em 0 0.3em; color: var(--ink-2); font-family: var(--font-body);
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.85em; }
.prose p { margin: 0.85em 0; }
.prose a { color: var(--gold); text-decoration: underline; text-decoration-color: var(--gold-line);
  text-underline-offset: 2px; transition: text-decoration-color var(--dur-fast) var(--ease); }
.prose a:hover { text-decoration-color: var(--gold); }
.prose strong { color: var(--ink); font-weight: 600; }
.prose em { color: var(--ink); }
.prose ul, .prose ol { margin: 0.85em 0; padding-left: 1.4em; }
.prose li { margin: 0.3em 0; }
.prose li::marker { color: var(--gold-deep); }
.prose blockquote {
  margin: 1.1em 0; padding: 2px 0 2px 18px; border-left: 2px solid var(--gold-line);
  color: var(--ink); font-family: var(--font-display); font-style: italic; font-size: 1.05em;
}
.prose blockquote p { margin: 0.4em 0; }
.prose code {
  font-family: var(--font-mono); font-size: 0.85em; padding: 0.12em 0.4em;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--gold-bright);
}
.prose pre {
  margin: 1.1em 0; padding: 14px 16px; background: var(--bg-deep);
  border: 1px solid var(--border); border-radius: var(--r-ctrl); overflow-x: auto;
}
.prose pre code { background: none; border: none; padding: 0; color: var(--ink-2); }
.prose hr { margin: 1.8em 0; border: none; border-top: 1px solid var(--border); }
.prose img { max-width: 100%; border-radius: var(--r-ctrl); }

/* markdown tables */
.prose table { width: 100%; border-collapse: collapse; margin: 1.2em 0; font-size: 13.5px;
  display: block; overflow-x: auto; }
.prose th, .prose td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border);
  vertical-align: top; }
.prose thead th { color: var(--ink); font-weight: 600; background: var(--surface);
  position: sticky; top: 0; border-bottom: 1px solid var(--border-2); }
.prose tbody tr:hover { background: var(--surface); }

/* CSV table view */
.csv { font-size: 13px; }
.csv__bar { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 12px; color: var(--ink-faint); font-family: var(--font-mono); font-size: 11px; }
.csv__scroll { overflow: auto; border: 1px solid var(--border); border-radius: var(--r-ctrl);
  max-height: 70vh; }
table.csv__table { border-collapse: collapse; width: 100%; }
.csv__table th, .csv__table td { padding: 8px 12px; border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border); white-space: nowrap; }
.csv__table td { color: var(--ink-2); }
.csv__table tbody td:first-child { color: var(--ink); font-weight: 500; }
.csv__table tbody td.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }
.csv__table thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2); color: var(--ink);
  font-weight: 600; cursor: pointer; user-select: none; text-align: left;
}
.csv__table thead th:hover { background: var(--surface-3); }
.csv__table thead th .arrow { color: var(--gold); margin-left: 4px; font-size: 10px; }
.csv__table tbody tr:nth-child(even) { background: oklch(0.2 0.016 256 / 0.4); }
.csv__table tbody tr:hover { background: var(--gold-soft); }

/* backlinks / outgoing links panel */
.links { margin-top: 30px; padding-top: 8px; }
.links__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 6px; }
@media (max-width: 560px) { .links__grid { grid-template-columns: 1fr; } }
.links__col h4 { display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-faint); }
.links__col h4 .c { color: var(--gold); }
.linkrow {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  padding: 8px 10px; border-radius: var(--r-chip); color: var(--ink-2);
  border: 1px solid transparent; transition: background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease); margin-bottom: 4px;
}
.linkrow:hover { background: var(--surface); border-color: var(--border); color: var(--ink); }
.linkrow .sw { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.linkrow .t { flex: 1; min-width: 0; font-size: 13px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
.linkrow .w { font-family: var(--font-mono); font-size: 10px; color: var(--ink-faint); }
.links__empty { color: var(--ink-faint); font-size: 12.5px; font-style: italic; padding: 4px 0; }

/* ---- hover preview card (graph) ----------------------------------------- */
.nodecard {
  position: fixed; z-index: var(--z-toast); width: 260px; pointer-events: none;
  padding: 12px 14px; border-radius: var(--r-ctrl);
  background: oklch(0.18 0.014 256 / 0.96); border: 1px solid var(--border-2);
  box-shadow: 0 18px 50px oklch(0 0 0 / 0.55); backdrop-filter: blur(10px);
  opacity: 0; transform: translateY(4px); transition: opacity var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease);
}
.nodecard.show { opacity: 1; transform: translateY(0); }
.nodecard__type { display: flex; align-items: center; gap: 7px; margin-bottom: 7px;
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-faint); }
.nodecard__title { font-family: var(--font-display); font-size: 15.5px; color: var(--ink);
  line-height: 1.18; margin-bottom: 5px; }
.nodecard__sum { font-size: 12px; color: var(--ink-3); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.nodecard__foot { margin-top: 8px; display: flex; gap: 12px; font-family: var(--font-mono);
  font-size: 10px; color: var(--ink-faint); }

/* ---- loading / states ---------------------------------------------------- */
.boot {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center;
  background: var(--bg-deep); transition: opacity var(--dur-slow) var(--ease);
}
.boot.gone { opacity: 0; pointer-events: none; }
.boot__inner { text-align: center; }
.boot__mark { width: 54px; height: 54px; color: var(--gold); margin: 0 auto 18px;
  animation: pulse 2.4s var(--ease-in-out) infinite; }
.boot__txt { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.24em;
  text-transform: uppercase; color: var(--ink-faint); }
.boot__err { max-width: 440px; color: var(--ink-3); font-size: 13px; line-height: 1.6; }
.boot__err code { font-family: var(--font-mono); color: var(--gold-bright); font-size: 12px; }
@keyframes pulse { 0%,100% { opacity: 0.5; transform: scale(0.96); }
  50% { opacity: 1; transform: scale(1.02); } }

/* toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px);
  z-index: var(--z-toast); padding: 10px 16px; border-radius: var(--r-pill);
  background: var(--surface-2); border: 1px solid var(--border-2); color: var(--ink);
  font-size: 13px; box-shadow: 0 16px 40px oklch(0 0 0 / 0.5); opacity: 0;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 1080px) {
  .hero { grid-template-columns: 1fr; }
  .hero__art { display: none; }
  .decisions { grid-template-columns: 1fr; }
  .topbar__stats { display: none; }
}
@media (max-width: 860px) {
  .sidebar-toggle { display: grid; }
  #treeCollapse { display: none; }       /* hamburger owns the tree on mobile */
  /* sidebar is an absolute drawer, so it leaves the grid flow: the stage must
     take the single remaining column, otherwise it collapses to 0 width. */
  .workspace { grid-template-columns: 1fr; }
  .sidebar {
    position: absolute; inset: 0 auto 0 0; width: 84vw; max-width: 320px;
    transform: translateX(-100%); transition: transform var(--dur) var(--ease);
    z-index: var(--z-overlay);
    box-shadow: 24px 0 60px oklch(0 0 0 / 0.5);
  }
  .workspace.sidebar-open .sidebar { transform: translateX(0); }
  /* scrim behind the open drawer */
  .workspace.sidebar-open::before {
    content: ""; position: absolute; inset: 0; z-index: calc(var(--z-overlay) - 1);
    background: oklch(0 0 0 / 0.5);
  }
  .reader { width: 100%; }
  .topbar { gap: 10px; padding: 0 12px; }
  .topbar__spacer { display: none; }
  .search { flex: 1; width: auto; min-width: 0; }
  .legend {
    width: min(220px, 64vw); top: 12px; left: 12px;
    max-height: calc(100% - 90px);
  }
}
@media (max-width: 560px) {
  .statstrip { grid-template-columns: repeat(2, 1fr); }
  .folders { grid-template-columns: 1fr; }
  .home__sectionhead { flex-direction: column; }
  .home__sectionhead p { text-align: left; }
  .wordmark__type span { display: none; }
  .home__inner { padding: 32px 18px 80px; }
  /* compact topbar: mark + search + icon-only graph toggle */
  #graphBtn { padding: 0; width: 38px; height: 38px; justify-content: center;
    border-radius: var(--r-ctrl); }
  #graphBtn .btn__label { display: none; }
  .reader__body { padding: 20px 16px 56px; }
  .reader__head { padding: 14px 16px 12px; }
  .gcontrols { right: 10px; bottom: 12px; }
  .stage__hint { font-size: 10px; padding: 5px 10px; bottom: 12px;
    max-width: 90vw; text-align: center; }
}

/* ============================================================================
   REDUCED MOTION
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important; scroll-behavior: auto !important;
  }
  .reader { transition: none; }
}
