:root {
  color-scheme: light;
  --surface-0: #f4f3ef;
  --surface-1: #fcfcfb;
  --surface-2: #ecebe6;
  --border: #dcdad3;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77756f;
  --accent: #1c5cab;
  --org: #2a78d6;
  --svc: #eb6834;
  --person: #1baf7a;
  --pillar-fill: #c9a227;
  --pillar-stroke: #7a5f0c;
  --link: #c9c7bf;
  --link-rel: #52514e;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #262624;
    --border: #383835;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #9a998f;
    --accent: #86b6ef;
    --org: #3987e5;
    --svc: #d95926;
    --person: #199e70;
    --pillar-fill: #d8b440;
    --pillar-stroke: #f2e3a6;
    --link: #3f3f3b;
    --link-rel: #9a998f;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --surface-2: #262624;
  --border: #383835;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #9a998f;
  --accent: #86b6ef;
  --org: #3987e5;
  --svc: #d95926;
  --person: #199e70;
  --pillar-fill: #d8b440;
  --pillar-stroke: #f2e3a6;
  --link: #3f3f3b;
  --link-rel: #9a998f;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--surface-0);
  color: var(--text-primary);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-underline-offset: 2px; }
.muted { color: var(--text-muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.site-header {
  display: flex; flex-wrap: wrap; gap: 16px 48px; align-items: end; justify-content: space-between;
  padding: 28px 24px 16px; max-width: 1600px; margin: 0 auto;
}
.brand h1 { margin: 0; font-size: 34px; line-height: 1; letter-spacing: -0.02em; font-weight: 700; }
.wordmark .dot { color: var(--org); }
.lede { margin: 8px 0 0; color: var(--text-secondary); max-width: 56ch; }
.stats { display: flex; gap: 28px; margin: 0; }
.stats div { display: flex; flex-direction: column-reverse; }
.stats dt { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.stats dd { margin: 0; font: 600 26px/1.1 var(--mono); }
.stats dd a { color: inherit; text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 4px; }
.stats dd a:hover { color: var(--accent); text-decoration-color: currentColor; }

/* Directory page */
.brand h1 a.home { color: inherit; text-decoration: none; }
.directory { display: grid; gap: 16px; }
.dir-section { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; scroll-margin-top: 16px; }
.dir-section h2 { font-size: 20px; margin: 0 0 12px; }
.dir-section h2 .n { font: 500 14px var(--mono); color: var(--text-muted); margin-left: 6px; }
.dir-list { margin: 0; padding-left: 28px; columns: 2 420px; column-gap: 40px; }
.dir-list li { margin-bottom: 10px; break-inside: avoid; }
.dir-list .meta { display: block; font-size: 13px; color: var(--text-secondary); }
.prose { display: grid; gap: 16px; max-width: 820px; margin: 0; }
.prose p, .prose ul { margin: 0 0 10px; color: var(--text-secondary); max-width: 70ch; }
.prose li { margin-bottom: 4px; }
.prose .table-scroll { overflow-x: auto; margin-bottom: 12px; }
.dir-list .host { display: block; font-family: var(--mono); font-size: 11px; color: var(--text-muted); }

.controls { max-width: 1600px; margin: 0 auto; padding: 0 24px 12px; display: grid; gap: 10px; }
.control-row { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; }
.search { flex: 1 1 280px; max-width: 460px; }
.search input {
  width: 100%; padding: 8px 12px; font: inherit; color: inherit;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px;
}
.search-status { display: block; margin: 4px 2px 0; font-size: 13px; color: var(--text-secondary); }
.search-status[hidden] { display: none; }
.search input:focus-visible, button:focus-visible, .pillars button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggles { display: flex; gap: 16px; color: var(--text-secondary); }
.toggles input { accent-color: var(--accent); }
.view-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-left: auto; }
.view-switch button {
  font: 500 13px var(--sans); padding: 7px 14px; border: 0; background: var(--surface-1); color: var(--text-secondary); cursor: pointer;
}
.view-switch button[aria-selected="true"] { background: var(--text-primary); color: var(--surface-1); }
.pillars { display: flex; flex-wrap: wrap; gap: 6px; }
.pillars button {
  font: 500 13px var(--sans); padding: 5px 11px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-secondary);
}
.pillars button .n { font-family: var(--mono); color: var(--text-muted); margin-left: 4px; }
.pillars button[aria-pressed="true"] { background: var(--text-primary); border-color: var(--text-primary); color: var(--surface-1); }
.pillars button[aria-pressed="true"] .n { color: inherit; opacity: 0.7; }

main { max-width: 1600px; margin: 0 auto; padding: 0 24px; }
.graph-view { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; }
.graph-view[hidden], .table-view[hidden] { display: none; }
.graph-wrap {
  position: relative; background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  height: min(78vh, 860px); min-height: 480px; overflow: hidden;
}
#graph { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#graph:active { cursor: grabbing; }

.legend {
  position: absolute; left: 12px; bottom: 10px; display: flex; flex-wrap: wrap; gap: 4px 14px;
  font-size: 12px; color: var(--text-secondary); background: color-mix(in srgb, var(--surface-1) 88%, transparent);
  padding: 6px 10px; border-radius: 8px; max-width: calc(100% - 24px);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.k-org { fill: var(--org); }
.k-svc { fill: var(--svc); }
.k-person { fill: var(--person); }
.k-pillar { fill: var(--pillar-fill); stroke: var(--pillar-stroke); stroke-width: 2; }
.k-rel { stroke: var(--link-rel); stroke-width: 1.5; stroke-dasharray: 4 3; }
.zoom-hint { position: absolute; right: 12px; top: 10px; font-size: 12px; color: var(--text-muted); }

.link { stroke: var(--link); stroke-width: 1; }
.link.pillar { stroke-opacity: 0.45; }
.graph-wrap.has-selection .link.pillar:not(.faded) { stroke-opacity: 1; stroke: var(--text-muted); }
.link.rel { stroke: var(--link-rel); stroke-dasharray: 4 3; stroke-width: 1.2; }
.node { cursor: pointer; }
.node .mark { stroke: var(--surface-1); stroke-width: 2; }
.node.org .mark { fill: var(--org); }
.node.svc .mark { fill: var(--svc); }
.node.person .mark { fill: var(--person); }
.node.pillar .mark { fill: var(--pillar-fill); stroke: var(--pillar-stroke); stroke-width: 2.5; }
.node text {
  font: 500 11px var(--sans); fill: var(--text-secondary); pointer-events: none;
  paint-order: stroke; stroke: var(--surface-1); stroke-width: 3px; stroke-linejoin: round;
}
.node.pillar text { font: 600 13px var(--sans); fill: var(--text-primary); }
.node .label { opacity: 0; }
.node.labelled .label, .node.pillar .label, .node.hover .label { opacity: 1; }
.node.selected .mark { stroke: var(--text-primary); stroke-width: 3; }
.faded { opacity: 0.12; }
.link.faded { opacity: 0.05; }

.tooltip {
  position: absolute; pointer-events: none; background: var(--text-primary); color: var(--surface-1);
  font-size: 12px; padding: 5px 9px; border-radius: 6px; max-width: 260px; z-index: 2;
}
.tooltip .kind { opacity: 0.7; display: block; font-size: 11px; }

.panel {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px;
  height: min(78vh, 860px); min-height: 480px; overflow-y: auto;
}
.panel h2 { font-size: 20px; line-height: 1.25; margin: 0 0 6px; }
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin: 18px 0 6px; font-weight: 600; }
.panel p { margin: 0 0 10px; color: var(--text-secondary); }
.panel .kind-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.panel .kind-badge i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); border: 0; font-family: var(--sans); }
button.chip { cursor: pointer; }
button.chip:hover { color: var(--text-primary); }
.conn { list-style: none; margin: 0; padding: 0; }
.conn li { padding: 3px 0; display: flex; gap: 8px; align-items: baseline; }
.conn button { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-align: left; text-decoration: underline; text-underline-offset: 2px; }
.conn .rel-type { font-size: 12px; color: var(--text-muted); }
.refs { margin: 0; padding-left: 18px; }
.refs li { margin-bottom: 8px; font-size: 13px; }
.refs .host { font-family: var(--mono); font-size: 11px; color: var(--text-muted); display: block; }
.refs .supports { color: var(--text-secondary); display: block; }
.permalink { font-size: 12px; }

.table-view { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; vertical-align: top; padding: 9px 12px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-weight: 600; position: sticky; top: 0; background: var(--surface-1); }
td.name { font-weight: 600; }
td.name button { all: unset; cursor: pointer; color: var(--accent); }
td ol { margin: 0; padding-left: 16px; }
td .kind-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }

.site-footer { max-width: 1600px; margin: 0 auto; padding: 20px 24px 36px; font-size: 13px; color: var(--text-secondary); }
.site-footer p { margin: 4px 0; }
.linklike {
  background: none; border: 0; padding: 0; font: inherit; color: var(--text-secondary); cursor: pointer;
  text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 2px;
}
.linklike:hover { color: var(--accent); text-decoration-color: currentColor; }
.linklike[hidden] { display: none; }

/* Cookie banner (vanilla-cookieconsent), themed with the site tokens */
:root #cc-main {
  --cc-font-family: var(--sans);
  --cc-modal-border-radius: 12px;
  --cc-btn-border-radius: 8px;
  --cc-bg: var(--surface-1);
  --cc-primary-color: var(--text-primary);
  --cc-secondary-color: var(--text-secondary);
  --cc-link-color: var(--accent);
  --cc-btn-primary-bg: var(--text-primary);
  --cc-btn-primary-color: var(--surface-1);
  --cc-btn-primary-border-color: var(--text-primary);
  --cc-btn-primary-hover-bg: var(--text-secondary);
  --cc-btn-primary-hover-color: var(--surface-1);
  --cc-btn-primary-hover-border-color: var(--text-secondary);
  --cc-btn-secondary-bg: var(--text-primary);
  --cc-btn-secondary-color: var(--surface-1);
  --cc-btn-secondary-border-color: var(--text-primary);
  --cc-btn-secondary-hover-bg: var(--text-secondary);
  --cc-btn-secondary-hover-color: var(--surface-1);
  --cc-btn-secondary-hover-border-color: var(--text-secondary);
  --cc-separator-border-color: var(--border);
  --cc-toggle-on-bg: var(--accent);
  --cc-toggle-off-bg: var(--text-muted);
  --cc-toggle-on-knob-bg: var(--surface-1);
  --cc-toggle-off-knob-bg: var(--surface-1);
  --cc-toggle-readonly-bg: var(--surface-2);
  --cc-toggle-readonly-knob-bg: var(--surface-1);
  --cc-cookie-category-block-bg: var(--surface-2);
  --cc-cookie-category-block-border: var(--border);
  --cc-cookie-category-block-hover-bg: var(--surface-0);
  --cc-cookie-category-block-hover-border: var(--border);
  --cc-cookie-category-expanded-block-bg: var(--surface-1);
  --cc-cookie-category-expanded-block-hover-bg: var(--surface-0);
  --cc-footer-bg: var(--surface-2);
  --cc-footer-color: var(--text-muted);
  --cc-footer-border-color: var(--border);
  --cc-overlay-bg: rgb(20 19 18 / 60%);
}

@media (max-width: 960px) {
  .graph-view { grid-template-columns: 1fr; }
  .panel { height: auto; min-height: 0; }
  .graph-wrap { height: 70vh; min-height: 420px; }
}
@media (max-width: 600px) {
  .site-header, .controls, main, .site-footer { padding-left: 16px; padding-right: 16px; }
  .stats { gap: 18px; }
  .stats dd { font-size: 20px; }
  .view-switch { margin-left: 0; }
  .zoom-hint { display: none; }
  .legend { font-size: 11px; }
}
@media (forced-colors: active) {
  .node .mark { stroke: CanvasText; }
}

/* ---------- map view ---------- */
.map { position: absolute; inset: 0; background: var(--surface-1); }
.map[hidden], .legend[hidden], .offmap[hidden], #graph[hidden] { display: none; }
.map-legend, .offmap { z-index: 500; }
.k-approx { fill: var(--surface-1); stroke: var(--org); stroke-width: 2; stroke-dasharray: 3 2; }
.k-cluster { fill: var(--surface-1); stroke: var(--org); stroke-width: 2; }
.k-cluster-n { font: 600 9px var(--mono); fill: var(--text-primary); }
.leaflet-container { font: 13px/1.4 var(--sans); background: var(--surface-1); }
.leaflet-container a { color: var(--accent); }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface-1) 85%, transparent) !important; color: var(--text-muted); }
.leaflet-bar a { background: var(--surface-1); color: var(--text-primary); border-color: var(--border); }
.leaflet-bar a:hover { background: var(--surface-2); }
.leaflet-tooltip { background: var(--text-primary); color: var(--surface-1); border: 0; border-radius: 6px; font-size: 12px; box-shadow: none; padding: 5px 9px; }
.leaflet-tooltip::before { display: none; }
.leaflet-tooltip .kind { opacity: 0.7; display: block; font-size: 11px; }
.site-cluster {
  display: grid; place-items: center; border-radius: 50%;
  background: var(--surface-1); border: 2px solid var(--org); color: var(--text-primary);
  font: 600 12px var(--mono); box-shadow: 0 0 0 2px var(--surface-1);
}
.offmap {
  position: absolute; right: 12px; top: 12px; max-width: 260px; font-size: 12px; color: var(--text-secondary);
  background: color-mix(in srgb, var(--surface-1) 92%, transparent); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
.offmap summary { font-weight: 600; color: var(--text-primary); cursor: pointer; }
.offmap details[open] summary { margin-bottom: 4px; }
.offmap details { max-height: 40vh; overflow-y: auto; }
.tiles-light { filter: grayscale(0.85) contrast(0.95) brightness(1.04); }
.tiles-dark { filter: invert(1) hue-rotate(180deg) grayscale(0.85) brightness(0.85) contrast(0.9); }
.offmap button { all: unset; cursor: pointer; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.sites { list-style: none; margin: 0; padding: 0; }
.sites li { margin-bottom: 8px; font-size: 13px; }
.sites .addr { display: block; color: var(--text-secondary); }
.sites .meta { display: block; font-size: 11px; color: var(--text-muted); }
