/* Rare Disease Atlas
   Layout: one input, one map, one panel.
   Type: IBM Plex Sans, 12px text / 10.5px labels / 14px title; mono for identifiers.
   Colour carries meaning only: node family on marks, evidence class on lines, accent for links and the trail. */

:root {
  color-scheme: light;
  --bg: #f7f8fa; --surface: #ffffff; --surface-2: #eef1f5; --line: #d9dee6;
  --ink: #141a22; --ink-3: #8a94a3;
  --accent: #1c5cab; --accent-soft: #dbe7f8;
  --rim: #10c8ee; --rim-soft: #cdf3fb;
  --c-disease: #2a78d6; --c-gene: #eb6834; --c-mechanism: #1baf7a; --c-phenotype: #eda100;
  --c-community: #e87ba4; --c-evidence: #008300; --c-asset: #4a3aa7; --c-place: #e34948;
  --s-good: #0ca30c; --s-warn: #fab219; --s-critical: #d03b3b;
  --font-ui: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --shadow: 0 6px 24px rgba(20, 26, 34, 0.10);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #14171c; --surface: #1c2027; --surface-2: #242a33; --line: #343b46; --ink: #eef1f5; --ink-3: #7d8795;
    --accent: #5598e7; --accent-soft: #1f3250; --rim: #22d6f5; --rim-soft: #0d3a44;
    --c-disease: #3987e5; --c-gene: #d95926; --c-mechanism: #199e70; --c-phenotype: #c98500;
    --c-community: #d55181; --c-evidence: #3fa83f; --c-asset: #9085e9; --c-place: #e66767;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14171c; --surface: #1c2027; --surface-2: #242a33; --line: #343b46; --ink: #eef1f5; --ink-3: #7d8795;
  --accent: #5598e7; --accent-soft: #1f3250; --rim: #22d6f5; --rim-soft: #0d3a44;
  --c-disease: #3987e5; --c-gene: #d95926; --c-mechanism: #199e70; --c-phenotype: #c98500;
  --c-community: #d55181; --c-evidence: #3fa83f; --c-asset: #9085e9; --c-place: #e66767;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-ui); font-size: 12px; line-height: 1.5; display: flex; flex-direction: column; overflow: hidden; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--font-mono); font-size: 11px; }
.small, .muted, .why { font-size: 11px; color: var(--ink-3); }
.ghost { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 3px 8px; font-size: 11px; color: var(--ink-3); }
.ghost:hover { color: var(--ink); }
.ghost:disabled { opacity: .4; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 2px 9px; font-size: 11px; color: var(--ink-3); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

/* ---------- layout ---------- */
.main { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 400px; min-height: 0; }
.stage { position: relative; min-width: 0; min-height: 0; }
.stage > svg#graph { width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- floating title, trail, language ---------- */
.topfloat { position: absolute; top: 10px; left: 12px; right: 12px; display: flex; gap: 12px; align-items: center; pointer-events: none; }
.topfloat > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 12px; flex: none; background: color-mix(in srgb, var(--surface) 80%, transparent); border-radius: 999px; padding: 4px 10px 4px 6px; backdrop-filter: blur(6px); }
.brand svg { width: 22px; height: 22px; }
.trail { flex: 1; min-width: 0; display: flex; gap: 6px; align-items: center; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.trail::-webkit-scrollbar { display: none; }
.trail > * { flex: none; }
.crumb { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 2px 4px 2px 9px; font-size: 11px; color: var(--ink-3); max-width: 200px; }
.crumb .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumb[aria-current="true"] { border-color: var(--accent); color: var(--ink); }
.crumb.query { font-style: italic; }
.crumb .x { border: 0; background: transparent; color: var(--ink-3); font-size: 13px; line-height: 1; padding: 0 4px; }
.crumb .x:hover { color: var(--ink); }
.lang { display: inline-flex; gap: 2px; flex: none; background: color-mix(in srgb, var(--surface) 80%, transparent); border-radius: 8px; padding: 1px; }
.lang button { border: 0; background: transparent; color: var(--ink-3); font-size: 11px; padding: 2px 6px; border-radius: 6px; }
.lang button[aria-pressed="true"] { color: var(--ink); background: var(--surface-2); }

/* ---------- tooltip (pointer devices only) ---------- */
.tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); padding: 5px 8px; border-radius: 6px; font-size: 11px; max-width: 260px; opacity: 0; transition: opacity .12s; z-index: 5; }
.tip b { display: block; }
.tip .t { opacity: .7; display: block; }

/* ---------- the input ---------- */
.ask { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); width: min(720px, calc(100% - 24px)); display: flex; flex-direction: column; gap: 8px; }
.chips { display: flex; gap: 6px; overflow-x: auto; white-space: nowrap; padding: 2px 2px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 90%, transparent); border-radius: 999px; padding: 3px 9px; font-size: 11px; color: var(--ink-3); backdrop-filter: blur(6px); }
.chip:hover { color: var(--ink); }
.askwrap { position: relative; }
.askbox { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 6px 6px 6px 14px; box-shadow: var(--shadow); }
.askbox:focus-within { border-color: var(--accent); }
.askbox input { flex: 1; border: 0; outline: none; background: transparent; font: inherit; font-size: 14px; color: var(--ink); min-width: 0; }
.askbox input::placeholder { color: var(--ink-3); }
.askbox .ai { font-size: 11px; color: var(--s-good); white-space: nowrap; }
.askbox .go { border: 0; background: var(--ink); color: var(--bg); border-radius: 10px; padding: 7px 13px; font-weight: 600; font-size: 12px; }
.suggest { position: absolute; bottom: 100%; left: 0; right: 0; margin-bottom: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); max-height: 260px; overflow-y: auto; }
.suggest div { padding: 6px 12px; display: flex; gap: 8px; align-items: center; cursor: pointer; }
.suggest div:hover, .suggest div[aria-selected="true"] { background: var(--surface-2); }
.suggest .sw { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.suggest .ty { color: var(--ink-3); font-size: 11px; margin-left: auto; }
.hero { display: none; align-items: center; justify-content: center; gap: 10px; font-size: 17px; font-weight: 600; margin-bottom: 10px; flex-wrap: wrap; text-align: center; }
.hero svg { width: 28px; height: 28px; }

/* ---------- launch state: hero + input only ---------- */
body.empty .main { grid-template-columns: 1fr; }
body.empty .panel, body.empty .topfloat { display: none; }
body.empty .ask { bottom: auto; top: 44%; transform: translate(-50%, -50%); width: min(640px, calc(100% - 32px)); flex-direction: column-reverse; gap: 14px; }
body.empty .hero { display: flex; }
body.empty .chips { justify-content: center; flex-wrap: wrap; white-space: normal; overflow: visible; }
body.empty .askbox { position: relative; padding: 10px 10px 10px 18px; border-radius: 18px; border-color: transparent; box-shadow: var(--shadow), 0 0 0 1px var(--rim-soft); }
body.empty .askbox input { font-size: 15px; }
@property --rim-angle { syntax: "<angle>"; inherits: false; initial-value: 0deg; }
body.empty .askbox::before {
  content: ""; position: absolute; inset: -3px; border-radius: 21px; padding: 3px; pointer-events: none;
  background: conic-gradient(from var(--rim-angle), transparent 0deg, var(--rim) 70deg, var(--rim) 110deg, transparent 180deg, transparent 360deg);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude;
  animation: rim 2.8s linear infinite;
}
body.empty .askbox::after {
  content: ""; position: absolute; inset: -10px; border-radius: 28px; pointer-events: none; z-index: -1; filter: blur(10px); opacity: .45;
  background: conic-gradient(from var(--rim-angle), transparent 0deg, var(--rim) 80deg, var(--rim) 100deg, transparent 180deg, transparent 360deg);
  animation: rim 2.8s linear infinite;
}
@keyframes rim { to { --rim-angle: 360deg; } }

/* ---------- panel: one face, 12px text / 10.5px labels, two inks, rules not boxes ---------- */
.panel { border-left: 1px solid var(--line); background: var(--surface); overflow-y: auto; min-height: 0; padding: 14px 18px 40px; }
.panel h1 { font-size: 14px; line-height: 1.3; margin: 6px 0; font-weight: 600; text-wrap: balance; }
.panel h2 { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); margin: 18px 0 6px; font-weight: 600; }
.panel p { margin: 6px 0; }
.badges { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 10.5px; color: var(--ink-3); }
.badge .sw { width: 7px; height: 7px; border-radius: 50%; }
.badge.ok { color: var(--s-good); }
.badge.bad { color: var(--s-critical); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 1px 12px; margin-top: 8px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.card { border-top: 1px solid var(--line); padding: 8px 0 2px; margin-top: 8px; }
.card h3 { margin: 0 0 4px; font-size: 12px; font-weight: 600; }
.card.gap h3 { color: var(--s-critical); }
.card ul { margin: 2px 0 6px; padding-left: 16px; }
.card li { margin: 2px 0; }
.persona-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 18px 0 4px; }
.persona-row .lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); font-weight: 600; }
.group-title { display: flex; justify-content: space-between; margin: 10px 0 2px; font-size: 11px; color: var(--ink-3); }
.edges { display: flex; flex-direction: column; }
.edge { display: grid; grid-template-columns: 8px 1fr 40px; gap: 8px; align-items: start; padding: 6px 0; border-top: 1px solid var(--line); cursor: pointer; }
.edge:first-child { border-top: 0; }
.edge:hover .nm { color: var(--accent); }
.edge .sw { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; }
.edge .rel, .edge .meta { font-size: 11px; color: var(--ink-3); }
.edge .nm { font-weight: 500; }
.edge.contradicts .nm, .edge.caution .nm { color: var(--s-critical); }
.conf { padding-top: 6px; }
.conf .bar { height: 3px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.conf .bar i { display: block; height: 100%; background: var(--ink-3); }
.conf .lbl { font-size: 10px; color: var(--ink-3); text-align: right; font-variant-numeric: tabular-nums; }
.ev { font-size: 10px; color: var(--ink-3); }
.ev.inferred, .ev.hypothesis { color: var(--accent); }
.ev.contradicts, .ev.caution { color: var(--s-critical); }
.results { display: flex; flex-direction: column; }
.result { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-top: 1px solid var(--line); cursor: pointer; }
.result:first-child { border-top: 0; }
.result:hover { color: var(--accent); }
.result .sw { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.result .score { margin-left: auto; font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-3); }
.path { display: flex; flex-direction: column; gap: 1px; margin-top: 4px; }
.path .step { display: grid; grid-template-columns: 14px 1fr; gap: 8px; }
.path .step .dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 6px; }
.path .step .e { color: var(--ink-3); font-size: 11px; padding-left: 22px; }
.explain { border-left: 2px solid var(--line); padding: 2px 0 2px 10px; margin-top: 8px; }
.more { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 8px; }
.more summary { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); font-weight: 600; cursor: pointer; list-style: none; }
.more summary::before { content: "▸ "; }
.more[open] summary::before { content: "▾ "; }
.explain .src { font-size: 11px; color: var(--ink-3); margin-top: 4px; }

/* ---------- model dialog (console: atlas.showModel()) ---------- */
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); max-width: min(680px, calc(100% - 32px)); padding: 20px 22px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10, 14, 20, 0.45); }
dialog h2 { margin: 0 0 4px; font-size: 14px; }
dialog h3 { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); margin: 16px 0 6px; }
dialog table { border-collapse: collapse; width: 100%; }
dialog td { padding: 3px 6px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
dialog td:first-child { color: var(--ink-3); }
.loss { width: 100%; height: 110px; display: block; }
.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.stat { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; min-width: 90px; }
.stat b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--ink-3); }

/* ---------- map marks ---------- */
.link { fill: none; stroke: var(--ink-3); stroke-opacity: .55; stroke-linecap: round; }
.link.anchor { stroke-opacity: .22; }
.link.bridge { stroke-opacity: .7; }
.link.inferred { stroke-dasharray: 5 4; stroke: var(--accent); stroke-opacity: .7; }
.link.hypothesis { stroke-dasharray: 1.5 4; stroke: var(--accent); stroke-opacity: .85; }
.link.contradicts, .link.caution { stroke: var(--s-critical); stroke-opacity: .8; }
.link.query { stroke-dasharray: 3 3; stroke: var(--ink-3); }
.mark path { stroke: var(--s-critical); stroke-width: 1.8px; fill: none; }
.mark.caution path { stroke: var(--s-warn); }
.mark circle { fill: var(--surface); stroke: var(--accent); stroke-width: 1.5px; }
.node circle { stroke: var(--surface); stroke-width: 2px; }
.node circle.hb { fill: none; stroke: var(--accent); stroke-width: 2px; }
.node.focal circle { stroke: var(--ink); stroke-width: 3px; }
/* hover: hovered node and its neighbours in front and labelled; nothing fades out */
.node.hover circle:not(.hb) { stroke: var(--ink); stroke-width: 3px; }
.node.hover text { font-weight: 600; font-size: 11.5px; }
.node.near circle:not(.hb) { stroke: var(--ink-3); }
.node.near text { opacity: 1; }
.node text { font-size: 10.5px; fill: var(--ink); paint-order: stroke; stroke: var(--bg); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }
/* hover preview: the hovered node's connections that are not on the map, faded in translucent around it */
.preview { pointer-events: none; }
.preview circle { stroke: var(--surface); stroke-width: 1.5px; }
.preview text { font-size: 10px; fill: var(--ink); paint-order: stroke; stroke: var(--bg); stroke-width: 3px; stroke-linejoin: round; }
.trailpath { fill: none; stroke: var(--accent); stroke-width: 2.5px; stroke-opacity: .55; stroke-dasharray: 1 6; stroke-linecap: round; }

/* ---------- phones ---------- */
@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; grid-template-rows: minmax(55vh, 1fr) auto; }
  .panel { border-left: 0; border-top: 1px solid var(--line); max-height: 45vh; }
  .persona-row, .tip, .askbox .ai, .brand span { display: none !important; }
  .askbox input, body.empty .askbox input { font-size: 16px; }   /* 16px stops iOS Safari zooming on focus */
  .hero { font-size: 15px; }
  .hero .lang { flex-basis: 100%; justify-content: center; margin: 0; background: transparent; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  body.empty .askbox::before, body.empty .askbox::after { animation: none; background: var(--rim); }
  body.empty .askbox::after { opacity: .18; }
}
