/* neurodigineration network page — interactive cross-disease graph.
 * Dark scientific aesthetic to read as a "data instrument," not a website.
 * Three layers: header (status), full-bleed canvas (D3), slide-in detail panel. */

:root {
  /* Dark theme is the default — matches the data-instrument aesthetic. */
  --bg: #0b0f14;
  --bg-2: #11161d;
  --panel: #161d27;
  --panel-2: #1c2532;
  --ink: #e8edf2;
  --ink-soft: #b6bfca;
  --mute: #7a8593;
  --rule: #243042;
  --rule-strong: #2f3d52;
  --accent: #56b1ff;
  --accent-soft: rgba(86, 177, 255, 0.18);
  --gold: #f6c453;
  --gold-soft: rgba(246, 196, 83, 0.16);
  --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, 0.18);
  --warn: #f97316;
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.18);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 12px 36px rgba(0, 0, 0, 0.55);
  --canvas-glow: rgba(86, 177, 255, 0.06);
}

/* Light-theme override — adopts the arminbayati.com palette so when the
 * SME flips to light mode the network reads as part of the personal site
 * (warm paper background, crimson accent, DM Serif Display / IBM Plex). */
[data-theme="light"] {
  --bg: #fafaf7;            /* arminbayati paper */
  --bg-2: #f4f3ef;          /* arminbayati section-bg */
  --panel: #ffffff;          /* arminbayati card */
  --panel-2: #f4f3ef;
  --ink: #0f1419;            /* arminbayati ink */
  --ink-soft: #1f2937;
  --mute: #6b7280;           /* arminbayati mid */
  --rule: #d4d0c8;           /* arminbayati warm rule */
  --rule-strong: #b8b2a6;
  --accent: #c0392b;         /* arminbayati crimson */
  --accent-soft: #e74c3c20;
  --gold: #b45309;
  --gold-soft: #fff5d6;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --shadow-1: 0 1px 2px rgba(15, 20, 25, 0.06);
  --shadow-2: 0 12px 36px rgba(15, 20, 25, 0.10);
  --canvas-glow: rgba(192, 57, 43, 0.04);
}

/* Brand fonts in light mode — match arminbayati.com */
[data-theme="light"] body {
  font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
[data-theme="light"] code,
[data-theme="light"] .mono,
[data-theme="light"] .node-label {
  font-family: 'IBM Plex Mono', 'SF Mono', Menlo, Consolas, monospace;
}
[data-theme="light"] .brand .logo,
[data-theme="light"] .panel h2,
[data-theme="light"] .help-overlay h4 {
  font-family: 'DM Serif Display', Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--ink); }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: 'SF Mono', Menlo, Consolas, monospace; font-size: 0.92em; background: var(--panel-2); padding: 1px 5px; border-radius: 3px; }
button { font: inherit; color: inherit; }

/* ===== Header ===== */
header.site {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  background: linear-gradient(180deg, rgba(11,15,20,0.95) 0%, rgba(11,15,20,0.78) 100%);
  border-bottom: 1px solid var(--rule);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
/* In light mode the header uses the paper palette so the body and header
 * read as a single page rather than dark-on-light strip. */
[data-theme="light"] header.site {
  background: linear-gradient(180deg, rgba(250, 250, 247, 0.96) 0%, rgba(250, 250, 247, 0.82) 100%);
  border-bottom-color: var(--rule);
}
[data-theme="light"] header.site .brand,
[data-theme="light"] header.site .brand a {
  color: var(--ink);
}
[data-theme="light"] nav.site-nav a { color: var(--ink-soft); }
[data-theme="light"] nav.site-nav a:hover { color: var(--accent); }
header.site .row {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 18px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand .logo {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent); color: #0b0f14;
  display: grid; place-items: center;
  font-family: Georgia, serif; font-weight: 700; font-size: 18px;
}
.brand .name { font-size: 17px; }
.brand .name em { font-style: normal; color: var(--mute); font-weight: 500; font-size: 13px; margin-left: 6px; }
.pill {
  font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 999px; border: 1px solid var(--rule);
  background: var(--panel); color: var(--ink-soft); font-weight: 600;
}
.pill.trained { background: var(--gold-soft); color: var(--gold); border-color: transparent; }
.pill.default { background: var(--panel); color: var(--mute); }
.spacer { flex: 1; }
nav.site-nav { display: flex; gap: 14px; font-size: 13.5px; }
nav.site-nav a { color: var(--ink-soft); }
nav.site-nav a:hover { color: var(--accent); }

/* Theme toggle button + generic header buttons (✦ suggest-open, etc.) */
.theme-toggle,
.header-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid var(--rule);
  background: var(--panel);
  color: var(--ink-soft);
  cursor: pointer;
  display: grid; place-items: center;
  font-size: 14px;
  transition: color 0.15s, border-color 0.15s, transform 0.05s, background 0.15s;
}
.theme-toggle:hover,
.header-btn:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle:active,
.header-btn:active { transform: scale(0.94); }
.header-btn.active { background: var(--accent); color: white; border-color: transparent; }
.theme-toggle .sun { display: none; }
.theme-toggle .moon { display: inline; }
[data-theme="light"] .theme-toggle .sun { display: inline; }
[data-theme="light"] .theme-toggle .moon { display: none; }

/* Disease filter chips */
.disease-filters {
  display: flex; gap: 4px; flex-wrap: wrap;
}
.disease-filters button {
  padding: 4px 10px;
  font-size: 11.5px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--panel);
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.12s;
}
.disease-filters button.active { color: var(--ink); border-color: transparent; }
.disease-filters button:hover { color: var(--ink); }

/* Edge-kind legend (rendered inside the floating .legend-body) */
.edge-legend {
  display: flex; gap: 6px 10px; flex-wrap: wrap;
  font-size: 11px; color: var(--mute);
}
.edge-legend .item {
  display: inline-flex; align-items: center; gap: 5px;
}
.edge-legend .swatch {
  width: 16px; height: 2.5px; border-radius: 1px;
}

/* Floating, collapsible legend panel on the left side of the canvas. */
.legend-float {
  position: fixed;
  top: 72px;
  left: 12px;
  z-index: 30;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  padding: 6px;
  font-size: 11.5px;
  color: var(--ink-soft);
  max-width: 260px;
  user-select: none;
}
.legend-float .legend-toggle {
  display: flex; align-items: center; gap: 6px;
  background: none; border: none; cursor: pointer; padding: 4px 8px;
  color: var(--ink-soft); font-size: 11.5px; font-weight: 600;
  letter-spacing: 0.02em; text-transform: uppercase;
  width: 100%; text-align: left;
}
.legend-float .legend-toggle .caret {
  transition: transform 0.18s;
  font-size: 10px;
}
.legend-float .legend-toggle[aria-expanded="true"] .caret { transform: rotate(90deg); }
.legend-float .legend-body {
  padding: 8px 8px 6px;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 240px;
}
.legend-float .legend-body[hidden] { display: none; }
.legend-float .legend-note {
  font-size: 10.5px; color: var(--mute);
  display: flex; align-items: center; gap: 6px;
  border-top: 1px solid var(--rule); padding-top: 6px;
}
.legend-float .tangential-swatch {
  display: inline-block; width: 24px; height: 0;
  border-top: 1.5px dotted currentColor;
}

/* ===== Canvas ===== */
.canvas-frame {
  position: fixed; top: 56px; left: 0; right: 0; bottom: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse 80% 60% at 50% 40%, var(--canvas-glow) 0%, transparent 70%),
    var(--bg);
}
#graph {
  width: 100%; height: 100%;
  cursor: grab;
}
#graph:active { cursor: grabbing; }

/* SVG-level styling */
.node-bg { fill: var(--panel); stroke: var(--rule); stroke-width: 1.5; transition: stroke 0.15s, fill 0.15s, filter 0.2s; }
.node-bg.dim { opacity: 0.18; }
.node-bg.highlighted { stroke-width: 2.5; filter: drop-shadow(0 0 8px currentColor); }
.node-label { font-family: 'SF Mono', Menlo, Consolas, monospace; font-weight: 600; fill: var(--ink); pointer-events: none; user-select: none; text-anchor: middle; }
.node-sub { font-size: 9.5px; fill: var(--ink-soft); pointer-events: none; user-select: none; text-anchor: middle; }
.node-label.dim, .node-sub.dim { opacity: 0.25; }

.edge { fill: none; transition: opacity 0.15s, stroke-width 0.15s; cursor: pointer; }
.edge.dim { opacity: 0.1; }
.edge.highlighted { stroke-width: 3.2 !important; opacity: 1 !important; }

/* Hover glow color (set per-node by JS via currentColor) */
.node-group { cursor: pointer; }
.node-group:hover .node-bg { filter: brightness(1.2); }

/* ===== Side panel ===== */
.panel {
  position: fixed; top: 56px; right: 0; bottom: 0;
  width: 420px;
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 100%);
  border-left: 1px solid var(--rule);
  /* Shadow only when open — otherwise the blur bleeds back into the
     viewport from the off-screen panel and creates a dark strip on
     the right edge of the canvas. */
  box-shadow: none;
  padding: 22px 24px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.18, 0.9, 0.3, 1), box-shadow 0.28s;
  z-index: 40;
}
.panel.open {
  transform: translateX(0);
  box-shadow: -8px 0 24px rgba(0,0,0,0.4);
}
.panel .close {
  position: absolute; top: 14px; right: 14px;
  width: 28px; height: 28px; border-radius: 6px;
  border: 1px solid var(--rule); background: var(--panel-2);
  color: var(--ink-soft); cursor: pointer;
  display: grid; place-items: center;
  font-size: 16px;
}
.panel .close:hover { color: var(--ink); border-color: var(--accent); }

.panel h2 {
  margin: 0 0 4px;
  font-family: Georgia, serif;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.panel .sub {
  color: var(--mute); font-size: 13px;
  margin: 0 0 18px;
}

/* Edge-detail panel "from → to" header */
.edge-pair {
  display: flex; align-items: center; gap: 10px; margin: 0 0 12px;
  font-family: 'SF Mono', monospace; font-size: 16px;
  flex-wrap: wrap;
}
.edge-pair .arrow { color: var(--accent); font-size: 20px; }
.edge-pair .gene {
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--rule);
}
.edge-kind-pill {
  display: inline-block;
  font-size: 11px; padding: 3px 9px;
  border-radius: 999px; letter-spacing: 0.04em; text-transform: uppercase;
  font-weight: 600; margin-bottom: 12px;
}

.panel section.block {
  margin-bottom: 18px;
  padding: 14px;
  background: var(--bg-2);
  border: 1px solid var(--rule);
  border-radius: 10px;
}
.panel section.block h3 {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--mute);
  font-weight: 600;
}
.panel section.block p { margin: 0 0 8px; color: var(--ink-soft); font-size: 13.5px; line-height: 1.55; }
.panel section.block p:last-child { margin-bottom: 0; }
.panel section.block ul { padding-left: 18px; margin: 0; }
.panel section.block li { margin: 3px 0; font-size: 13px; }
.panel section.block li a { color: var(--accent); font-family: 'SF Mono', monospace; }

/* Rating block */
.rate-block {
  background: linear-gradient(180deg, var(--panel-2) 0%, var(--bg-2) 100%);
  border: 1px solid var(--rule-strong);
  padding: 16px;
  border-radius: 12px;
  margin-top: 6px;
}
.rate-block h3 {
  font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--gold); font-weight: 700; margin: 0 0 12px;
}
.validity-row {
  display: flex; gap: 6px; margin-bottom: 14px;
}
.validity-row button {
  flex: 1; padding: 8px 6px;
  border-radius: 8px; border: 1px solid var(--rule);
  background: var(--panel); color: var(--ink-soft);
  font-size: 12px; font-weight: 600; cursor: pointer;
  text-transform: uppercase; letter-spacing: 0.04em;
  transition: all 0.12s;
}
.validity-row button:hover { border-color: var(--accent); color: var(--ink); }
.validity-row button.sel.yes      { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.validity-row button.sel.no       { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.validity-row button.sel.uncertain{ background: var(--gold-soft); color: var(--gold); border-color: transparent; }

.rate-dim {
  display: grid; grid-template-columns: 110px 1fr 24px; gap: 6px 12px;
  align-items: center; margin-bottom: 6px; font-size: 12px;
}
.rate-dim .lbl { color: var(--ink-soft); }
.rate-dim .stars { display: inline-flex; gap: 3px; }
.rate-dim .star {
  width: 22px; height: 22px;
  border-radius: 5px; border: 1px solid var(--rule);
  background: var(--panel); color: var(--mute);
  display: grid; place-items: center;
  font-size: 13px; cursor: pointer; transition: all 0.1s;
}
.rate-dim .star:hover { border-color: var(--accent); color: var(--accent); }
.rate-dim .star.selected { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.rate-dim .val { font-family: 'SF Mono', monospace; font-size: 10.5px; text-align: right; color: var(--mute); }

.rate-feedback {
  width: 100%; min-height: 60px;
  padding: 8px 10px;
  border-radius: 8px; border: 1px solid var(--rule);
  background: var(--bg); color: var(--ink);
  font: inherit; font-size: 13px;
  resize: vertical; margin: 10px 0 12px;
}
.rate-feedback:focus { border-color: var(--accent); outline: none; }

.rate-save {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--bg);
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: filter 0.12s;
}
.rate-save:hover { filter: brightness(1.05); }
.rate-save:disabled { opacity: 0.5; cursor: not-allowed; }

/* Node-detail variant: list of connected genes */
.connection-list {
  display: flex; flex-direction: column; gap: 4px;
}
.connection-list .conn {
  padding: 6px 10px;
  background: var(--panel-2);
  border: 1px solid var(--rule);
  border-radius: 6px;
  cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px;
  transition: border-color 0.1s, transform 0.05s;
}
.connection-list .conn:hover { border-color: var(--accent); transform: translateX(2px); }
.connection-list .conn .gene { font-family: 'SF Mono', monospace; font-weight: 600; color: var(--ink); min-width: 70px; }
.connection-list .conn .arrow { color: var(--mute); }
.connection-list .conn .kind { color: var(--mute); font-size: 11px; margin-left: auto; }

/* ===== Floating controls (zoom) ===== */
.zoom-controls {
  position: fixed; left: 18px; bottom: 18px;
  display: flex; flex-direction: column; gap: 4px;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 4px;
  z-index: 30;
  box-shadow: var(--shadow-1);
}
.zoom-controls button {
  width: 32px; height: 32px;
  border: none; border-radius: 5px;
  background: transparent; color: var(--ink-soft);
  font-size: 16px; cursor: pointer;
  display: grid; place-items: center;
}
.zoom-controls button:hover { background: var(--panel-2); color: var(--ink); }

/* ===== Help overlay ===== */
/* Hidden by default — opened from the "?" header button. Positioned in
 * the bottom-left so it doesn't overlap the floating Legend (top-left) or
 * the suggest box (bottom-right). */
.help-overlay {
  position: fixed; left: 18px; bottom: 18px;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 12.5px;
  color: var(--ink-soft);
  max-width: 320px;
  box-shadow: var(--shadow-1);
  z-index: 30;
  transition: opacity 0.25s, transform 0.25s;
}
.help-overlay[hidden] { display: none !important; }
.help-overlay.fading { opacity: 0.3; }
.help-overlay h4 { margin: 0 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--gold); }
.help-overlay kbd {
  font-family: 'SF Mono', monospace; font-size: 11px;
  padding: 1px 5px; border-radius: 3px;
  background: var(--bg-2); border: 1px solid var(--rule);
}
.help-overlay button.dismiss {
  background: transparent; border: 1px solid var(--rule);
  color: var(--mute); border-radius: 4px;
  padding: 2px 8px; margin-top: 8px;
  font-size: 10.5px; cursor: pointer;
}
.help-overlay button.dismiss:hover { color: var(--ink); }

/* ===== Corner prompt — SME suggests a connection, Claude proposes ===== */
.suggest-card {
  position: fixed; right: 18px; bottom: 18px;
  width: 320px; max-width: calc(100vw - 36px);
  background: var(--panel);
  border: 1px solid var(--rule-strong);
  border-radius: 12px;
  padding: 12px 14px;
  z-index: 35;
  box-shadow: var(--shadow-2);
  transition: width 0.2s, padding 0.2s;
}
.suggest-card.collapsed {
  width: auto; padding: 8px 12px;
}
.suggest-card .head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 6px;
  cursor: pointer;
}
.suggest-card .head h4 {
  margin: 0; font-size: 11px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--gold);
  font-weight: 700; flex: 1;
}
.suggest-card .head .toggle,
.suggest-card .head .close {
  font-size: 14px; color: var(--mute);
  background: none; border: none; cursor: pointer;
  width: 22px; height: 22px;
  border-radius: 4px;
  transition: color 0.12s, background 0.12s;
}
.suggest-card .head .toggle:hover,
.suggest-card .head .close:hover { color: var(--ink); background: var(--panel-2, rgba(0,0,0,0.04)); }
.suggest-card[hidden] { display: none !important; }
.suggest-card.collapsed .body { display: none; }
.suggest-card .body { display: block; }
.suggest-card .hint {
  font-size: 11.5px; color: var(--mute); margin-bottom: 8px;
}
.suggest-card textarea {
  width: 100%; min-height: 60px;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font: inherit; font-size: 13px;
  resize: vertical;
}
.suggest-card textarea:focus { border-color: var(--accent); outline: none; }
.suggest-card .row {
  display: flex; gap: 6px; margin-top: 8px; align-items: center;
}
.suggest-card .row button {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent); color: var(--bg);
  font-size: 12px; font-weight: 600; cursor: pointer;
}
.suggest-card .row button:disabled { opacity: 0.5; cursor: progress; }
.suggest-card .row .meta { font-size: 11px; color: var(--mute); margin-left: auto; }

/* Transient user-suggested edge styling */
.edge.user-edge { stroke-dasharray: 6 4; }

/* Tangential edges — author flagged them tentative; render dotted so the
 * SME can spot at a glance that these are candidates pending validation. */
.edge.tangential { stroke-dasharray: 2 3; opacity: 0.55; }
.edge.tangential.highlighted { opacity: 1; }

/* SME-accepted NEW edges (drafted on the train page, then accepted into
 * the graph) — dashed green so they stand out from curated solid/dotted. */
.edge.accepted {
  stroke-dasharray: 6 4;
  filter: drop-shadow(0 0 1.5px rgba(21, 128, 61, 0.55));
}
.edge.accepted.highlighted {
  opacity: 1 !important;
  filter: drop-shadow(0 0 3px rgba(21, 128, 61, 0.8));
}

/* ===== Toast (shared) ===== */
.toast-host {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 10px 16px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  max-width: 460px;
}
.toast.ok { background: var(--ok); }
.toast.warn { background: var(--warn); color: white; }
.toast.danger { background: var(--danger); color: white; }
.toast.bump { background: var(--accent); color: var(--bg); border: 2px solid var(--gold); }

@media (max-width: 760px) {
  .panel { width: 100%; }
  header.site .row { gap: 6px; }
  .edge-legend { display: none; }
}
