/* Tokens. The map is drawn on cool drafting paper; yellow is reserved for agents (the duck),
   teal for Postgres, and red for anything that writes to the outside world. */
:root {
  --paper: #e8edf0;
  --paper-deep: #dde4e8;
  --card: #ffffff;
  --ink: #1c2733;
  --ink-2: #4b5967;
  --ink-3: #7d8b97;
  --rule: #c3ccd3;
  --duck: #f4c21b;
  --duck-soft: #fbe7a1;
  --duck-deep: #b98500;
  --pg: #2e7d84;
  --pg-soft: #d3e5e6;
  --gw-soft: #dfe1ee;
  --bug: #c4453b;
  --violet: #7b55b8;
  --indigo: #4d61c0;
  --slate: #6c7c89;
  --focus: #1f6feb;
  --shadow: 0 1px 2px rgba(28, 39, 51, .08), 0 8px 24px rgba(28, 39, 51, .10);
  --font: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --topbar-h: 60px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Top bar */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 16px; background: rgba(232, 237, 240, .92);
  backdrop-filter: blur(6px); border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 34px; height: 34px; flex: none; }
.brand-mark path:first-child { fill: var(--duck); stroke: var(--ink); stroke-width: 1.4; }
.brand-mark .eye { fill: var(--ink); }
.brand-mark .beak { fill: #e98a15; stroke: var(--ink); stroke-width: .8; }
.brand h1 {
  margin: 0; font-size: 19px; line-height: 1.1; font-weight: 750;
  font-stretch: 80%; font-variation-settings: "wdth" 80; letter-spacing: .005em;
}
.brand p { margin: 0; font-size: 12.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; align-items: center; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px;
  border: 1px solid var(--rule); border-radius: 8px; background: var(--card);
  font-size: 14px; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-primary:hover { background: #2d3b49; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-duck { background: var(--duck); border-color: var(--duck-deep); color: var(--ink); }
.btn-duck:hover { border-color: var(--ink); }
.btn-small { height: 30px; padding: 0 11px; font-size: 13px; }
.btn[aria-pressed="false"] { color: var(--ink-2); background: transparent; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--rule);
  background: var(--card); cursor: pointer; font-size: 18px; line-height: 1;
}
.icon-btn-wide { width: auto; padding: 0 10px; font-size: 13px; font-weight: 550; }

.search { position: relative; }
.search input {
  width: 260px; height: 34px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--rule);
  background: var(--card); font: inherit; font-size: 14px; color: var(--ink);
}
.search ul {
  position: absolute; top: 40px; left: 0; right: 0; margin: 0; padding: 4px; list-style: none;
  background: var(--card); border: 1px solid var(--rule); border-radius: 10px; box-shadow: var(--shadow);
  max-height: 60vh; overflow: auto;
}
.search li { padding: 7px 9px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.search li small { display: block; color: var(--ink-2); font-size: 12px; }
.search li[aria-selected="true"], .search li:hover { background: var(--paper); }

/* Column headers follow the map horizontally, so you always know which layer you are looking at. */
#colheads {
  position: fixed; top: var(--topbar-h); left: 0; right: 0; height: 30px; z-index: 20;
  pointer-events: none; overflow: hidden;
  background: linear-gradient(var(--paper) 55%, rgba(232, 237, 240, 0));
}
#colheads span {
  position: absolute; top: 6px; transform: translateX(-50%); white-space: nowrap;
  font-size: 12.5px; font-weight: 650; color: var(--ink-2);
  font-stretch: 85%; font-variation-settings: "wdth" 85;
}

/* Map */
#stage { position: fixed; inset: 0; }
#map { width: 100%; height: 100%; display: block; cursor: grab; }
#map:active { cursor: grabbing; }

.district-bg { fill: var(--paper); }
.district-bg.alt { fill: var(--paper-deep); }
.district-title {
  font-size: 58px; font-weight: 800; fill: var(--ink); opacity: .13;
  font-stretch: 70%; font-variation-settings: "wdth" 70; letter-spacing: .01em;
}
.district-sub { font-size: 15px; fill: var(--ink-2); }
.band-gw { fill: var(--gw-soft); }
.band-pg { fill: var(--pg-soft); }
.band-label { font-size: 13px; font-weight: 650; fill: var(--ink-2); }

.edge { fill: none; opacity: .34; transition: opacity .2s; }
.edge.hidden-mech { opacity: 0; }
.edge-hit { fill: none; stroke: transparent; stroke-width: 12; cursor: pointer; }
.edge-hit.hidden-mech { pointer-events: none; }

.focus-mode .edge { opacity: .06; }
.focus-mode .edge.on { opacity: .95; }
.focus-mode .edge.hidden-mech.on { opacity: .8; }
.focus-mode .edge.route { opacity: .5; }
.focus-mode .edge.hidden-mech.route { opacity: .4; }
/* During a use case or story the route keeps its on-screen thickness at any zoom, so the whole
   route stays visible in the zoomed-out overview. */
.story-mode .edge.on, .story-mode .edge.route { vector-effect: non-scaling-stroke; }
.story-mode .edge.on { stroke-width: 3.4px; }
.story-mode .edge.route { stroke-width: 2.4px; }
.story-mode .node.on .box, .story-mode .node.route .box { vector-effect: non-scaling-stroke; stroke: var(--bug); stroke-width: 2.2px; }
.story-mode .node.story-on .box { stroke-width: 3.6px; }
.focus-mode .edge-hit.hidden-mech.on { pointer-events: stroke; }
.edge.hover { opacity: 1 !important; stroke-width: 3; }
.edge.filtered, .edge-hit.filtered, .particle.filtered { display: none; }

.particle { display: none; }
.traffic-all .particle { display: block; }
.focus-mode .particle { display: none; }
.focus-mode .particle.on { display: block; }
.traffic-all .particle.hidden-mech { display: none; }
.focus-mode .particle.hidden-mech.on { display: block; }
.story-particle { filter: drop-shadow(0 0 4px rgba(244, 194, 27, .9)); }

.node { cursor: pointer; transition: opacity .2s; }
.node .box { fill: var(--card); stroke: var(--ink); stroke-width: 1.3; }
.node .title {
  font-size: var(--fs, 15px); font-weight: 680; fill: var(--ink);
  font-stretch: 78%; font-variation-settings: "wdth" 78;
}
.node .sub { font-size: 11.5px; fill: var(--ink-2); }
.node .sub.code { font-family: var(--mono); font-size: 10.5px; }
.node .glyph { fill: none; stroke: var(--ink); stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.node .strip { fill: var(--ink); }
.node .strip-text { font-family: var(--mono); font-size: 9.5px; fill: #fff; }

.k-agent .box { fill: var(--duck); stroke-width: 1.6; }
.k-agent .sub { fill: #4a3a00; }
.k-model .box { fill: #fffaf0; stroke: var(--duck-deep); stroke-width: 2; stroke-dasharray: 5 3; }
.k-model .glyph { stroke: var(--duck-deep); }
.k-queue .box { fill: #f3fafa; stroke: var(--pg); stroke-width: 1.6; }
.k-queue .glyph { stroke: var(--pg); }
.k-table .box { fill: #f3fafa; stroke: var(--pg); stroke-width: 1.1; stroke-dasharray: 2 2; }
.k-table .glyph { stroke: var(--pg); }
.k-route .box { fill: #f6f6fb; stroke: var(--indigo); }
.k-route .glyph { stroke: var(--indigo); }
.k-gate .box { fill: #eceefa; stroke: var(--indigo); stroke-width: 1.3; }
.k-gate .glyph { stroke: var(--indigo); }
.k-tool .box { fill: #f5f0fb; stroke: var(--violet); }
.k-tool .glyph { stroke: var(--violet); }
.k-external .box { fill: var(--card); stroke: var(--ink-3); stroke-width: 1.1; }
.k-ui .box { fill: var(--card); stroke: var(--ink-2); }
.k-timer .box { fill: #f2f4f6; stroke: var(--slate); stroke-dasharray: 3 2; }
.k-timer .glyph { stroke: var(--slate); }
.k-infra .box { fill: #f2f4f6; stroke: var(--ink-2); stroke-dasharray: 6 3; }

.node:hover .box { stroke-width: 2.4; }
.node.selected .box { stroke: var(--focus); stroke-width: 3; }
.node.lit .box { stroke-width: 2.6; }
.node.story-on .box { stroke: var(--bug); stroke-width: 3.2; }
.focus-mode .node { opacity: .28; }
.focus-mode .node.on { opacity: 1; }
.focus-mode .node.route { opacity: .9; }
.node:focus-visible { outline: none; }
.node:focus-visible .box { stroke: var(--focus); stroke-width: 3; }

.lod-far .node .sub, .lod-far .node .strip-text { display: none; }
.lod-far .node .title { font-size: var(--far, 15px); transform: translateY(var(--far-dy, 0)); }
.lod-far .district-title { opacity: .3; }

/* Tooltip */
#tip {
  position: fixed; z-index: 60; max-width: 340px; pointer-events: none;
  background: var(--ink); color: #fff; padding: 9px 11px; border-radius: 8px; box-shadow: var(--shadow);
  font-size: 13px; line-height: 1.4;
}
#tip b { font-weight: 650; }
#tip .tip-kind { display: block; color: var(--duck-soft); font-size: 12px; margin-bottom: 2px; }
#tip code { background: rgba(255, 255, 255, .14); color: #fff; }

/* Side panel with component details */
.panel {
  position: fixed; top: calc(var(--topbar-h) + 10px); right: 10px; bottom: 10px; z-index: 40;
  width: 420px; max-width: calc(100vw - 20px); overflow: auto;
  background: var(--card); border: 1px solid var(--rule); border-radius: 14px; box-shadow: var(--shadow);
  padding: 22px 24px 28px;
}
.panel-close { position: sticky; top: 0; float: right; margin: -6px -8px 0 8px; }
.panel h2 {
  margin: 4px 0 6px; font-size: 26px; line-height: 1.12; font-weight: 750;
  font-stretch: 82%; font-variation-settings: "wdth" 82;
}
.panel h3 { margin: 22px 0 6px; font-size: 14px; font-weight: 700; color: var(--ink); }
.panel p { margin: 0 0 10px; }
.panel ul { margin: 0; padding-left: 18px; }
.panel li { margin: 3px 0; }
.panel .summary { font-size: 16px; color: var(--ink); }
.kind-badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px;
  font-size: 12.5px; font-weight: 650; background: var(--paper); border: 1px solid var(--rule);
}
.kind-badge.k-agent { background: var(--duck); border-color: var(--ink); }
.kind-badge.k-model { background: #fffaf0; border: 1.5px dashed var(--duck-deep); }
.kind-badge.k-queue, .kind-badge.k-table { background: var(--pg-soft); border-color: var(--pg); }
.kind-explain { margin: 8px 0 14px; color: var(--ink-2); font-size: 13.5px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; margin: 0; font-size: 13.5px; }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
code, .code { font-family: var(--mono); font-size: .86em; background: var(--paper); padding: 1px 4px; border-radius: 4px; }
.lesson-box { margin-top: 18px; padding: 12px 14px; border-left: 4px solid var(--duck); background: #fffbea; border-radius: 0 8px 8px 0; }
.lesson-box h3 { margin-top: 0; }
.links { list-style: none; padding: 0 !important; }
.links li { display: flex; gap: 8px; align-items: baseline; margin: 5px 0; }
.links button {
  border: 0; background: none; padding: 0; cursor: pointer; text-align: left;
  color: var(--ink); font-weight: 600; text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 3px;
}
.links button:hover { text-decoration-color: var(--ink); }
.links .why { color: var(--ink-2); font-size: 13px; }
.swatch { flex: none; width: 18px; height: 0; border-top: 3px solid currentColor; transform: translateY(-3px); }
.swatch.dashed { border-top-style: dashed; }
.swatch.dotted { border-top-style: dotted; }
.files li { font-family: var(--mono); font-size: 12px; }
.story-links button { margin: 0 6px 6px 0; }

/* Drawer with lessons and stories */
.drawer {
  position: fixed; top: calc(var(--topbar-h) + 10px); left: 10px; bottom: 10px; z-index: 45;
  width: 360px; max-width: calc(100vw - 20px); overflow: auto;
  background: var(--card); border: 1px solid var(--rule); border-radius: 14px; box-shadow: var(--shadow);
}
.drawer-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 8px; background: var(--card); }
.drawer-head h2 { margin: 0; font-size: 22px; font-weight: 750; font-stretch: 82%; font-variation-settings: "wdth" 82; }
.drawer-body { padding: 0 18px 22px; }
.drawer-intro { color: var(--ink-2); font-size: 14px; margin: 0 0 6px; }
.drawer h3 { font-size: 14px; margin: 18px 0 6px; }
.track-list { margin: 0; padding: 0; list-style: none; counter-reset: track; }
ol.track-list li { counter-increment: track; }
.track-list button {
  display: grid; grid-template-columns: 28px 1fr; gap: 0 8px; width: 100%; text-align: left;
  border: 1px solid transparent; background: none; border-radius: 10px; padding: 8px 8px; cursor: pointer;
}
.track-list button:hover { background: var(--paper); }
.track-list button.active { border-color: var(--ink); background: var(--paper); }
ol.track-list button::before {
  content: counter(track); grid-row: span 2; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; font-weight: 700; background: var(--duck);
}
ul.track-list button::before {
  content: ""; grid-row: span 2; width: 12px; height: 12px; margin: 6px; border-radius: 50%;
  background: var(--bug); box-shadow: 0 0 0 4px #f5d6d3;
}
.track-list b { font-weight: 650; font-size: 14.5px; }
ul.usecase-list button::before { background: var(--duck); box-shadow: 0 0 0 4px var(--duck-soft); }
.track-list .route-line { color: var(--ink); font-size: 12.5px; }
.track-list span { color: var(--ink-2); font-size: 13px; line-height: 1.35; }

/* Use case menu */
.menu {
  position: fixed; top: calc(var(--topbar-h) + 10px); right: 10px; z-index: 50;
  width: 460px; max-width: calc(100vw - 20px); max-height: calc(100vh - var(--topbar-h) - 20px); overflow: auto;
  background: var(--card); border: 1px solid var(--rule); border-radius: 14px; box-shadow: var(--shadow); padding: 16px 16px 12px;
}
.menu h2 { margin: 0 0 6px; padding: 0 8px; font-size: 15px; }
.menu .legend-hint { padding: 0 8px; }

/* Legend */
.legend {
  position: fixed; top: calc(var(--topbar-h) + 10px); right: 10px; z-index: 50;
  display: grid; grid-template-columns: 1fr 1fr; gap: 22px; width: 720px; max-width: calc(100vw - 20px);
  max-height: calc(100vh - var(--topbar-h) - 20px); overflow: auto;
  background: var(--card); border: 1px solid var(--rule); border-radius: 14px; box-shadow: var(--shadow); padding: 18px 20px;
}
.legend h2 { margin: 0 0 8px; font-size: 15px; }
.legend ul { list-style: none; margin: 0; padding: 0; }
.legend li { display: grid; grid-template-columns: 44px 1fr; gap: 10px; align-items: center; margin: 6px 0; font-size: 13px; line-height: 1.35; }
.legend li b { display: block; font-size: 13.5px; }
.legend label { display: contents; cursor: pointer; }
.legend input { margin: 0 4px 0 0; }
.legend-hint { margin: -4px 0 6px; font-size: 12.5px; color: var(--ink-2); }
.legend-presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.legend svg { overflow: visible; }

/* Player for lessons and stories */
.player {
  position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 45;
  width: 640px; max-width: calc(100vw - 20px);
  background: var(--ink); color: #fff; border-radius: 14px; box-shadow: var(--shadow); padding: 14px 18px 12px;
}
.player-meta { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--duck-soft); }
.player h2 { margin: 2px 0 6px; font-size: 20px; font-weight: 720; font-stretch: 85%; font-variation-settings: "wdth" 85; }
#player-text { font-size: 15px; line-height: 1.5; min-height: 46px; max-height: 32vh; overflow: auto; }
#player-text p { margin: 0 0 6px; }
#player-text code { background: rgba(255, 255, 255, .12); color: #fff; }
#player-text b { color: var(--duck); font-weight: 650; }
.player-steps { display: flex; flex-wrap: wrap; gap: 4px; margin: 10px 0; }
.player-steps button {
  min-width: 26px; height: 22px; padding: 0 6px; border-radius: 6px; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, .25); background: transparent; color: #fff; font-size: 11.5px;
}
.player-steps button.done { border-color: rgba(244, 194, 27, .55); }
.player-steps button.cur { background: var(--duck); border-color: var(--duck); color: var(--ink); font-weight: 700; }
.player-controls { display: flex; gap: 6px; justify-content: flex-end; }
.player .btn { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .3); }
.player .btn-primary { background: var(--duck); color: var(--ink); border-color: var(--duck); }

/* Zoom and minimap */
.zoombar { position: fixed; left: 14px; bottom: 154px; z-index: 25; display: flex; gap: 6px; }
#minimap {
  position: fixed; left: 14px; bottom: 14px; z-index: 25; width: 220px; height: 130px;
  background: rgba(255, 255, 255, .85); border: 1px solid var(--rule); border-radius: 10px; cursor: pointer;
}
#minimap .mm-node { fill: var(--ink-3); }
#minimap .mm-node.k-agent { fill: var(--duck-deep); }
#minimap .mm-node.k-queue, #minimap .mm-node.k-table { fill: var(--pg); }
#minimap .mm-district.alt { fill: var(--paper-deep); }
#minimap .mm-district { fill: var(--paper); }
#minimap .mm-view { fill: rgba(31, 111, 235, .08); stroke: var(--focus); stroke-width: 1.5; }

/* Intro */
.intro { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; background: rgba(28, 39, 51, .38); padding: 16px; }
.intro-card { width: 600px; max-width: 100%; max-height: calc(100vh - 32px); overflow: auto; background: var(--card); border-radius: 16px; box-shadow: var(--shadow); padding: 28px 30px 24px; }
.intro-card h2 { margin: 0 0 10px; font-size: 32px; line-height: 1.05; font-weight: 780; font-stretch: 75%; font-variation-settings: "wdth" 75; }
.intro-card p { margin: 0 0 12px; font-size: 16px; }
.intro-points { margin: 0 0 18px; padding-left: 18px; }
.intro-points li { margin: 6px 0; }
.intro-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.intro-sub { margin: 20px 0 4px; font-size: 14px; }

@media (max-width: 860px) {
  .brand p { display: none; }
  .search input { width: 170px; }
  #btn-traffic { display: none; }
  .legend { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .brand > div { display: none; }
  #btn-legend { display: none; }
  .search { display: none; }
  #minimap { display: none; }
  .zoombar { bottom: 14px; }
  .panel, .drawer { top: auto; left: 8px; right: 8px; width: auto; height: 62vh; bottom: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .node, .edge { transition: none; }
}
