/* bayesian demo: the knowledge map (/map) and the verdict neighbourhood.
   Community colours are eight categorical slots in a fixed order (blue,
   orange, aqua, yellow, magenta, green, violet, red: validated for adjacent
   colour-vision-deficiency separation in both modes); communities past the
   eighth are grey, and every hull carries its label, so colour never
   identifies a community alone. Health is a ring outside the node, apart
   from its fill: contested (red, solid), one source (amber, dashed), stale
   (grey, dotted). */

:root {
  --c0: #2a78d6;
  --c1: #eb6834;
  --c2: #1baf7a;
  --c3: #eda100;
  --c4: #e87ba4;
  --c5: #008300;
  --c6: #6250d6;
  --c7: #e34948;
  --c-grey: #9a9ca1;
  --c-orphan: #8a8d93;
  --h-contested: #d03b3b;
  --h-single: #fab219;
  --h-stale: #898781;
  --h-healthy: #0ca30c;
  --e-rule: #7d8189;
  --e-evidence: #2f56c8;
  --e-taxonomy: #a7aab0;
  --e-def: #5c5f66;
  --e-gap: #a5650d;
  --e-alias: #1c1d21;
  --layer-pack: #1baf7a;
  --layer-tenant: #e87ba4;
  --map-bg: #fcfcfb;
  --halo: #fcfcfb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --c0: #3987e5;
    --c1: #d95926;
    --c2: #199e70;
    --c3: #c98500;
    --c4: #d55181;
    --c5: #008300;
    --c6: #9085e9;
    --c7: #e66767;
    --c-grey: #6b6f76;
    --c-orphan: #7c8087;
    --h-stale: #9a9890;
    --e-rule: #8d929b;
    --e-evidence: #8ca8ff;
    --e-taxonomy: #5b6069;
    --e-def: #a4a7ad;
    --e-gap: #e7b155;
    --e-alias: #e9e7e3;
    --layer-pack: #199e70;
    --layer-tenant: #d55181;
    --map-bg: #17181b;
    --halo: #17181b;
  }
}

/* ---- page layout ---- */
.map-main { max-width: 1440px; padding: 14px 16px 40px; }
.map-head h1 { margin: 0.1em 0 0.2em; font-size: 1.6rem; }
.map-intro { max-width: 820px; margin-bottom: 0.3em; }
#map-stats { margin-bottom: 8px; font-variant-numeric: tabular-nums; }
#map-stats code { font-size: 0.8rem; }

.map-toolbar { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin: 6px 0 8px; }
.map-tabs { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; background: var(--surface); }
.map-tabs button { font: inherit; font-size: 0.88rem; border: 0; background: transparent; color: var(--muted); padding: 5px 14px; cursor: pointer; }
.map-tabs button + button { border-left: 1px solid var(--border); }
.map-tabs button[aria-selected="true"] { background: var(--text); color: var(--bg); }
.map-tabs button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.map-search { position: relative; flex: 1 1 240px; max-width: 380px; }
.map-search input { padding: 6px 10px; font-size: 0.92rem; }
.map-search ul {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px 0; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12); max-height: 320px; overflow-y: auto;
}
.map-search li { padding: 6px 10px; cursor: pointer; font-size: 0.88rem; line-height: 1.3; }
.map-search li .sid { font-family: var(--mono); font-size: 0.74rem; color: var(--faint); display: block; overflow-wrap: anywhere; }
.map-search li .sgl { color: var(--muted); font-size: 0.78rem; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-search li[aria-selected="true"], .map-search li:hover { background: var(--accent-soft); }
.map-hops, .map-switch { font-weight: 400; font-size: 0.88rem; display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }
.map-hops input { width: 64px; }
.map-hops output { min-width: 3.6em; color: var(--text); font-variant-numeric: tabular-nums; }

.map-filters { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; margin: 0 0 10px; font-size: 0.86rem; }
.map-layers { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }
.map-layers legend, .map-health-lbl { float: left; color: var(--muted); font-weight: 600; margin-right: 6px; padding: 0; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.map-layers label { font-weight: 400; display: inline-flex; gap: 4px; align-items: center; cursor: pointer; }
.map-health { display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.hchip { font: inherit; font-size: 0.82rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 2px 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; }
.hchip[aria-pressed="true"] { border-color: var(--text); box-shadow: 0 0 0 1px var(--text) inset; }
.hchip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.hk { display: inline-block; width: 11px; height: 11px; border-radius: 50%; border: 2.5px solid transparent; background: var(--surface-2); }
.hk.contested { border-color: var(--h-contested); }
.hk.single_source { border-color: var(--h-single); border-style: dashed; }
.hk.stale { border-color: var(--h-stale); border-style: dotted; }
.hk.orphan { border: 1.5px solid var(--c-orphan); background: transparent; width: 8px; height: 8px; }
.hk.alias { border: 0; border-radius: 0; width: 16px; height: 0; border-top: 2px dashed var(--e-alias); background: none; }

.map-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-items: start; }
.map-body.has-panel { grid-template-columns: minmax(0, 1fr) 380px; }
.map-stage-wrap { position: relative; min-width: 0; }
.map-stage {
  position: relative; height: min(76vh, 860px); min-height: 480px; background: var(--map-bg);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; touch-action: none;
}
.map-stage:focus { outline: none; }
.map-stage.scroll { overflow-y: auto; touch-action: auto; height: auto; max-height: min(76vh, 860px); }
.map-stage svg { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-select: none; }
.map-stage.scroll svg { height: auto; }
.map-note { margin: 6px 2px 0; color: var(--muted); max-width: 900px; }
.map-zoom { position: absolute; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 4px; }
.map-zoom button { width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 1rem; line-height: 1; cursor: pointer; }
.map-zoom button:focus-visible { outline: 2px solid var(--accent); }
.map-crumbs { display: flex; flex-wrap: wrap; gap: 2px 6px; align-items: center; font-size: 0.86rem; margin: 0 0 6px; }
.map-crumbs button { font: inherit; border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 2px; }
.map-crumbs span.sep { color: var(--faint); }
.map-crumbs b { font-weight: 600; }

/* ---- SVG marks ---- */
.map-svg text { font-family: var(--sans); fill: var(--text); pointer-events: none; }
.map-svg .lbl { font-size: 11px; paint-order: stroke; stroke: var(--halo); stroke-width: 3.5px; stroke-linejoin: round; }
.map-svg .lbl.big { font-size: 12px; font-weight: 600; }
.map-svg .hull { stroke-linejoin: round; stroke-width: 26px; fill-opacity: 0.1; stroke-opacity: 0.1; }
.map-svg .hull.loose { fill-opacity: 0.035; stroke-opacity: 0.05; stroke-dasharray: none; }
.map-svg .hull-lbl { font-size: 12.5px; font-weight: 700; paint-order: stroke; stroke: var(--halo); stroke-width: 4px; stroke-linejoin: round; letter-spacing: -0.005em; }
.map-svg .hull-lbl .n { font-weight: 400; fill: var(--muted); }
.map-svg .hull-lbl.loose { font-weight: 600; fill: var(--muted); }
.map-svg .hull-lbl.clickable { pointer-events: all; cursor: pointer; }
.map-svg .edge { fill: none; stroke-linecap: round; }
.map-svg .edge.shared_rule, .map-svg .edge.aggregate, .map-svg .edge.claim { stroke: var(--e-rule); stroke-opacity: 0.55; }
.map-svg .edge.aggregate { stroke-opacity: 0.28; }
.map-svg .edge.shared_evidence, .map-svg .edge.evidence { stroke: var(--e-evidence); stroke-opacity: 0.35; }
.map-svg .edge.taxonomy { stroke: var(--e-taxonomy); stroke-opacity: 0.7; stroke-dasharray: 5 3; }
.map-svg .edge.definition, .map-svg .edge.indicator, .map-svg .edge.predicate { stroke: var(--e-def); stroke-opacity: 0.6; }
.map-svg .edge.gap { stroke: var(--e-gap); stroke-opacity: 0.7; stroke-dasharray: 1 4; }
.map-svg .edge.alias_candidate { stroke: var(--e-alias); stroke-opacity: 0.9; stroke-dasharray: 5 3; }
.map-svg .edge.claim { stroke-dasharray: 6 3; }
.map-svg .edge.decisive { stroke-opacity: 0.9; }
.map-svg .edge.overlay { stroke: var(--layer-pack); stroke-opacity: 0.9; }
.map-svg .edge.overlay.tenant { stroke: var(--layer-tenant); }
.map-svg .edge.conflict { stroke: var(--h-contested); stroke-opacity: 1; stroke-dasharray: 2 2; }
.map-svg .edge-hit { stroke: transparent; stroke-width: 10px; fill: none; cursor: help; }
.map-svg .node { cursor: pointer; }
.map-svg .node path.shape { stroke: var(--map-bg); stroke-width: 1.2px; }
.map-svg .node path.ring { fill: none; stroke-width: 2.2px; }
.map-svg .node.st-contested path.ring { stroke: var(--h-contested); }
.map-svg .node.st-single_source path.ring { stroke: var(--h-single); stroke-dasharray: 3 2; }
.map-svg .node.st-stale path.ring { stroke: var(--h-stale); stroke-dasharray: 1.4 2; }
.map-svg .node.orphan path.shape { fill: var(--map-bg) !important; stroke: var(--c-orphan); stroke-width: 1.2px; }
.map-svg .node.missing path.shape { fill-opacity: 0.35; stroke: var(--c-orphan); stroke-dasharray: 2 2; }
.map-svg .node.outlet path.shape { fill: var(--surface-2) !important; stroke: var(--e-evidence); stroke-width: 1.4px; }
.map-svg .node.predicate path.shape { stroke-width: 1px; }
.map-svg .node.bubble path.shape { fill-opacity: 0.26; stroke-width: 2px; }
.map-svg .node.bubble.orphans path.shape { fill: none !important; stroke: var(--c-orphan) !important; stroke-dasharray: 3 3; }
.map-svg .node.overlay path.shape { stroke: var(--layer-pack); stroke-width: 2.5px; }
.map-svg .node.overlay.tenant path.shape { stroke: var(--layer-tenant); }
.map-svg .node:focus-visible path.shape { stroke: var(--accent); stroke-width: 3px; }
.map-svg .node:focus { outline: none; }
.map-svg .node.sel path.shape { stroke: var(--text); stroke-width: 2.6px; }
.map-svg .bubble-lbl { font-size: 12px; font-weight: 600; text-anchor: middle; paint-order: stroke; stroke: var(--halo); stroke-width: 3.5px; stroke-linejoin: round; }
.map-svg .bubble-lbl .n { font-weight: 400; fill: var(--muted); }
.map-svg .dim { opacity: 0.1; }
.map-svg .lbl.dim, .map-svg .hull-lbl.dim { opacity: 0.18; }
.map-svg .edge.hot { stroke-opacity: 1; }

/* circle packing */
.map-svg .pk { cursor: pointer; }
.map-svg .pk.group { fill: var(--surface-2); stroke: var(--border); stroke-width: 1px; }
.map-svg .pk.group.depth-odd { fill: var(--surface); }
.map-svg .pk.leaf.healthy { fill: var(--h-healthy); fill-opacity: 0.55; }
.map-svg .pk.leaf.contested { fill: var(--h-contested); fill-opacity: 0.8; }
.map-svg .pk.leaf.single_source { fill: var(--h-single); fill-opacity: 0.85; }
.map-svg .pk.leaf.stale { fill: var(--h-stale); fill-opacity: 0.8; }
.map-svg .pk.leaf.orphan { fill: var(--c-orphan); fill-opacity: 0.18; }
.map-svg .pk.leaf.self { stroke: var(--text); stroke-width: 0.6px; stroke-opacity: 0.4; }
.map-svg .pk.sel { stroke: var(--text); stroke-width: 2.5px; }
.map-svg .pk-lbl { font-size: 11px; text-anchor: middle; paint-order: stroke; stroke: var(--halo); stroke-width: 3px; stroke-linejoin: round; }
.map-svg .pk-lbl.group { font-weight: 700; font-size: 12px; }

/* outlets view */
.map-svg .ol-link { fill: none; stroke-opacity: 0.32; }
.map-svg .ol-link.fed { stroke-opacity: 0.95; }
.map-svg .ol-link.hot { stroke-opacity: 0.95; }
.map-svg .ol-link.cold { stroke-opacity: 0.06; }
.map-svg .ol-row { cursor: pointer; }
.map-svg .ol-row text { font-size: 12px; }
.map-svg .tag { font-size: 10px; fill: var(--muted); font-family: var(--mono); }
.map-svg .ol-row .cnt { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.map-svg .ol-row.fed text.name { font-weight: 700; }
.map-svg .ol-badge { font-size: 10.5px; fill: var(--tone-mislead); font-weight: 600; }
.map-svg .ol-bar { fill: var(--e-evidence); fill-opacity: 0.5; }
.map-svg .ol-head { font-size: 11px; font-weight: 700; fill: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

/* tooltip */
.map-tip {
  position: absolute; z-index: 20; pointer-events: none; max-width: 300px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 0.8rem; line-height: 1.35; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.14);
}
.map-tip b { display: block; font-size: 0.86rem; }
.map-tip .tk { color: var(--muted); font-size: 0.74rem; }
.map-tip .tg { color: var(--muted); margin-top: 3px; }
.map-tip .tn { margin-top: 3px; font-variant-numeric: tabular-nums; }

/* ---- the term card ---- */
.map-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: min(76vh, 860px); overflow-y: auto; position: sticky; top: 10px;
}
.map-panel-inner { padding: 14px 16px 16px; font-size: 0.9rem; }
.map-panel h2 { font-size: 1.12rem; margin: 0 0 4px; overflow-wrap: anywhere; padding-right: 30px; }
.map-panel h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 16px 0 6px; }
.map-panel .close { position: absolute; right: 10px; top: 10px; width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-size: 1rem; line-height: 1; }
.map-panel-inner { position: relative; }
.map-panel .tid { font-family: var(--mono); font-size: 0.76rem; color: var(--faint); overflow-wrap: anywhere; }
.map-panel .gloss { margin: 6px 0 8px; }
.map-panel .chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.map-panel .chip.h-contested { color: var(--h-contested); border-color: var(--h-contested); }
.map-panel .chip.h-single_source { border-color: var(--h-single); border-style: dashed; color: var(--text); }
.map-panel .chip.h-stale { border-color: var(--h-stale); border-style: dotted; }
.map-panel .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.map-panel ul { margin: 0; padding: 0; list-style: none; }
.map-panel li.rule { border-top: 1px solid var(--border); padding: 8px 0 7px; }
.map-panel li.rule code { background: none; padding: 0; font-size: 0.76rem; overflow-wrap: anywhere; display: block; margin-bottom: 4px; }
.map-panel .rmeta { color: var(--muted); font-size: 0.78rem; display: flex; flex-wrap: wrap; gap: 2px 10px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.map-panel .rmeta .flag { color: var(--text); }
.map-panel .rmeta .flag.bad { color: var(--h-contested); font-weight: 600; }
.map-panel li.plain-li { padding: 3px 0; overflow-wrap: anywhere; font-size: 0.84rem; }
.map-panel .nb { font: inherit; font-size: 0.82rem; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 999px; padding: 1px 9px; margin: 2px 3px 2px 0; cursor: pointer; }
.map-panel .nb:hover { border-color: var(--accent); }
.map-panel .muted-li { color: var(--muted); font-size: 0.84rem; }
.map-panel details > summary { font-size: 0.84rem; color: var(--muted); margin-top: 6px; }

/* ---- legend ---- */
.map-legend { margin-top: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; font-size: 0.84rem; }
.map-legend > summary { font-weight: 600; }
.legend-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 22px; margin-top: 8px; }
.legend-grid h4 { margin: 0 0 4px; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.legend-grid ul { list-style: none; margin: 0; padding: 0; }
.legend-grid li { display: flex; align-items: center; gap: 8px; margin: 3px 0; }
.legend-grid svg { flex: none; overflow: visible; }
.legend-grid .comm { font: inherit; border: 0; background: none; color: var(--text); padding: 1px 0; cursor: pointer; text-align: left; display: flex; gap: 8px; align-items: flex-start; }
.legend-grid .comm:hover .cl, .legend-grid .comm:focus-visible .cl { text-decoration: underline; }
.legend-grid .comm .sw { flex: none; width: 12px; height: 12px; border-radius: 3px; margin-top: 3px; }
.legend-grid .comm .cn { color: var(--muted); font-variant-numeric: tabular-nums; }
.legend-grid .comm-list { grid-column: span 2; }
.legend-grid .comm-list.long { max-height: 300px; overflow-y: auto; }
.legend-grid .comm-list ul { columns: 2 260px; column-gap: 22px; }
.legend-grid .comm-list li { break-inside: avoid; }

/* ---- verdict and check pages: the neighbourhood ---- */
.map-section { margin: 18px 0 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; }
.map-section > summary { font-weight: 600; }
.map-section .map-stage { height: 440px; min-height: 0; margin-top: 10px; }
.map-section .mini-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 0.8rem; color: var(--muted); margin-top: 8px; }
.map-section .mini-legend span { display: inline-flex; gap: 6px; align-items: center; }

@media (max-width: 900px) {
  .map-body.has-panel { grid-template-columns: minmax(0, 1fr); }
  .map-panel { position: static; max-height: none; }
}

@media (max-width: 640px) {
  .map-main { padding: 10px 16px 32px; }
  .map-head h1 { font-size: 1.35rem; }
  .map-intro { display: none; }
  .map-tabs { width: 100%; }
  .map-tabs button { flex: 1; padding: 6px 4px; font-size: 0.8rem; }
  .map-search { flex-basis: 100%; max-width: none; }
  .map-hops { display: none; }
  .map-stage { height: 66vh; min-height: 380px; }
  .legend-grid .comm-list { grid-column: auto; }
  .map-panel {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 40; max-height: 58vh; border-radius: 14px 14px 0 0;
    border-bottom: 0; box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.22);
  }
  .map-panel::before { content: ""; display: block; width: 44px; height: 4px; border-radius: 2px; background: var(--border); margin: 8px auto 0; }
  .map-section .map-stage { height: 360px; }
}
