:root {
  color-scheme: dark;
  --bg: #0c1014; --panel: #121820; --panel-2: #171e27; --line: #29323d; --line-2: #36414e;
  --text: #eef1f4; --muted: #a9b3be; --faint: #75808c;
  --accent: #bce77b; --accent-ink: #11160b; --info: #7cc4ff; --warn: #f2c14e; --bad: #ff7a6b; --ok: #7fdc9a;
  --planned: #b59cff;
  --radius: 8px; --gap: 16px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
a:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; }
code, .mono { font-family: var(--mono); font-size: .88em; }
:not(pre) > code { background: var(--panel-2); padding: .05rem .3rem; border-radius: 4px; overflow-wrap: anywhere; }
pre { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; overflow: auto; font-size: 12.5px; max-height: 26rem; margin: 0; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: clamp(1.6rem, 3vw, 2.3rem); letter-spacing: -.02em; }
h2 { font-size: 1.2rem; margin-top: .25rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; color: var(--muted); }
small, .small { font-size: 12.5px; color: var(--faint); }

.top { display: flex; align-items: center; gap: var(--gap); padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 1000; flex-wrap: wrap; }
.brand { display: flex; gap: 8px; align-items: center; color: var(--text); text-decoration: none; font-weight: 600; }
.brand img { width: 24px; height: 24px; }
.brand b { color: var(--accent); }
.identity { flex: 1; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; min-width: 0; font-size: 12.5px; color: var(--muted); }
.back { font-size: 13px; text-decoration: none; white-space: nowrap; }
body[data-anchor="system-overview"] .back { visibility: hidden; }
.anchors { display: flex; gap: 4px; overflow-x: auto; padding: 6px 12px; border-bottom: 1px solid var(--line); background: var(--panel); scrollbar-width: thin; }
.anchors a { white-space: nowrap; padding: 5px 10px; border-radius: 999px; color: var(--muted); text-decoration: none; font-size: 13px; border: 1px solid transparent; }
.anchors a[aria-current="page"] { color: var(--accent-ink); background: var(--accent); }
.anchors a:hover { border-color: var(--line-2); }
main { padding: 20px 16px 40px; max-width: 1440px; margin: 0 auto; outline: none; }
.foot { border-top: 1px solid var(--line); padding: 16px; font-size: 12.5px; color: var(--faint); }
.foot p { color: var(--faint); margin: 0 0 .4rem; max-width: 1440px; margin-inline: auto; }
.loading { padding: 3rem 1rem; text-align: center; color: var(--muted); }

.lede { max-width: 72ch; font-size: 1.02rem; }
.page-head { display: flex; justify-content: space-between; gap: var(--gap); align-items: flex-start; flex-wrap: wrap; margin-bottom: var(--gap); }
.page-head .meta { display: flex; gap: 6px; flex-wrap: wrap; }
.grid { display: grid; gap: var(--gap); }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.cols-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.cols-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.panel.flush { padding: 0; overflow: hidden; }
.section { margin-top: 28px; }

.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--muted); white-space: nowrap; }
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.chip.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.chip.info { color: var(--info); border-color: color-mix(in srgb, var(--info) 45%, transparent); }
.chip.planned { color: var(--planned); border-color: color-mix(in srgb, var(--planned) 45%, transparent); border-style: dashed; }
.chip.accent { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.missing { color: var(--warn); font-style: italic; }

button, .button, select, input[type="text"], input[type="number"], input[type="search"], textarea {
  font: inherit; font-size: 13.5px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 6px; padding: 6px 10px;
}
button, .button { cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .button:hover { border-color: var(--accent); }
button.primary, .button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 22%, var(--panel-2)); border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
input[type="range"] { accent-color: var(--accent); width: 100%; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar .spacer { flex: 1; }
label { font-size: 13px; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--faint); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.table-wrap { overflow-x: auto; max-width: 100%; }
tr.selected td { background: color-mix(in srgb, var(--accent) 12%, transparent); }
tbody tr[data-id] { cursor: pointer; }
tbody tr[data-id]:hover td { background: var(--panel-2); }
dl.kv { display: grid; grid-template-columns: minmax(8rem, max-content) 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
dl.kv dt { color: var(--faint); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; min-width: 0; }
li { overflow-wrap: anywhere; }

.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); }
.card { display: flex; flex-direction: column; gap: 6px; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); color: var(--text); text-decoration: none; }
.card:hover { border-color: var(--accent); }
.card .id { font-family: var(--mono); font-size: 11.5px; color: var(--faint); }
.card strong { font-size: 15px; }
.card p { font-size: 13px; margin: 0; }
.card .foot-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 6px; }

.objective { border: 1px solid color-mix(in srgb, var(--accent) 50%, var(--line)); background: color-mix(in srgb, var(--accent) 7%, var(--panel)); border-radius: var(--radius); padding: 14px 16px; }
.objective strong { color: var(--accent); }
.callout { border-left: 3px solid var(--info); padding: 8px 12px; background: var(--panel-2); border-radius: 0 6px 6px 0; font-size: 13.5px; color: var(--muted); margin: 0 0 12px; }
.callout.warn { border-color: var(--warn); }
.callout.planned { border-color: var(--planned); }

/* workspace */
.workspace { display: grid; gap: 12px; grid-template-columns: minmax(240px, 300px) minmax(0, 1fr) minmax(280px, 380px); grid-template-areas: "list map detail" "time time time"; }
.workspace .list { grid-area: list; } .workspace .map-panel { grid-area: map; } .workspace .detail { grid-area: detail; } .workspace .timeline { grid-area: time; }
@media (max-width: 1100px) { .workspace { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "map map" "time time" "list detail"; } }
@media (max-width: 700px) { .workspace { grid-template-columns: minmax(0, 1fr); grid-template-areas: "map" "time" "detail" "list"; } }
.records { max-height: 560px; overflow: auto; margin: 8px -14px -14px; border-top: 1px solid var(--line); }
.records button { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; padding: 7px 12px; }
.records button[aria-current="true"] { background: color-mix(in srgb, var(--accent) 16%, transparent); box-shadow: inset 3px 0 0 var(--accent); }
.records .t { font-family: var(--mono); font-size: 12px; color: var(--faint); }
.records .l { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.records .s { grid-column: 2; font-size: 11.5px; color: var(--faint); }
.map { height: 520px; border-radius: var(--radius); background: #0a0e12; }
.map.short { height: 360px; }
.leaflet-container { font: inherit; background: #0a0e12; }
.leaflet-tile-pane .basemap { filter: invert(1) hue-rotate(180deg) brightness(.75) contrast(.9) saturate(.4); }
.leaflet-control-attribution { background: rgba(12,16,20,.8) !important; color: var(--faint) !important; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.map-fallback { display: grid; place-items: center; height: 100%; color: var(--faint); font-size: 13px; padding: 1rem; text-align: center; }
.media { display: grid; gap: 8px; }
.media figure { margin: 0; background: #07090c; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.media img { display: block; width: 100%; height: auto; max-height: 340px; object-fit: contain; background: #07090c; }
.media figcaption span { min-width: 0; }
.media figcaption { font-size: 12px; color: var(--faint); padding: 4px 8px; display: flex; justify-content: space-between; gap: 8px; }
.media .absent { padding: 2rem 1rem; text-align: center; color: var(--faint); font-size: 13px; }
.triple { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.timeline-bar { position: relative; height: 34px; background: var(--panel-2); border-radius: 6px; overflow: hidden; border: 1px solid var(--line); cursor: pointer; }
.timeline-bar .seg { position: absolute; top: 0; bottom: 0; }
.timeline-bar .tick { position: absolute; top: 4px; bottom: 4px; width: 2px; background: var(--info); opacity: .65; }
.timeline-bar .cursor { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--accent); box-shadow: 0 0 0 1px #000; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; font-size: 13px; max-height: 240px; overflow: auto; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 2rem 4.5rem 1fr; gap: 6px; color: var(--muted); }
.steps li::before { content: counter(s); color: var(--faint); font-family: var(--mono); text-align: right; }
.steps .when { font-family: var(--mono); font-size: 12px; color: var(--faint); }

/* architecture */
.arch { width: 100%; height: auto; display: block; }
.arch a { cursor: pointer; }
.arch .box rect { fill: var(--panel-2); stroke: var(--line-2); stroke-width: 1.2; }
.arch .box.impl rect { stroke: color-mix(in srgb, var(--accent) 70%, transparent); }
.arch .box.demo rect { stroke: var(--info); }
.arch .box.planned rect { stroke: var(--planned); stroke-dasharray: 5 4; fill: transparent; }
.arch .box:hover rect { fill: color-mix(in srgb, var(--accent) 12%, var(--panel-2)); }
.arch text { fill: var(--text); font-size: 13px; font-family: system-ui, sans-serif; }
.arch text.sub { fill: var(--faint); font-size: 11px; }
.arch .flow { stroke: var(--faint); stroke-width: 1.4; fill: none; marker-end: url(#arrow); }
.arch .flow.planned { stroke: var(--planned); stroke-dasharray: 5 4; }
details.layer { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); margin-bottom: 8px; }
details.layer > summary { padding: 10px 14px; cursor: pointer; font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
details.layer > div { padding: 0 14px 14px; }

.exchange { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 860px) { .exchange { grid-template-columns: minmax(0, 1fr); } }
.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); margin-right: 6px; }
.status-dot.warn { background: var(--warn); } .status-dot.bad { background: var(--bad); } .status-dot.info { background: var(--info); }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; background: var(--panel-2); border-radius: 6px; border: 1px solid var(--line); min-width: 0; }
.stat .v { font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12px; color: var(--faint); }
.stats { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: 6px; font-weight: 600; z-index: 2000; }
.drop { border: 1.5px dashed var(--line-2); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); }
.drop.over { border-color: var(--accent); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
