:root {
  --bg: #070b14;
  --panel: #0d1424;
  --line: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --nano: #4a90e2;
  --ok: #34d399;
  --bad: #f87171;
  --wait: #fbbf24;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; } /* class display rules must never override the hidden attribute */
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 800px at 35% 45%, #0e1a33 0%, var(--bg) 60%);
  color: var(--text);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
}
header {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: center;
  justify-content: space-between;
  padding-block: max(16px, env(safe-area-inset-top)) 8px;
}
.brand { display: flex; gap: 12px; align-items: center; max-width: 640px; }
.logo {
  width: 34px; height: 34px; flex: none; border-radius: 50%;
  background: radial-gradient(circle, var(--bg) 30%, var(--nano) 32%);
  box-shadow: 0 0 24px rgba(74, 144, 226, .55);
}
h1 { margin: 0; font-size: 20px; letter-spacing: .2px; }
header p { margin: 2px 0 0; color: var(--muted); }
header strong { color: var(--text); font-weight: 600; }
.status { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px 4px 22px;
  position: relative; color: var(--muted); font-size: 12px; background: rgba(13, 20, 36, .7);
  font-variant-numeric: tabular-nums;
}
.pill::before {
  content: ""; position: absolute; left: 9px; top: 50%; width: 7px; height: 7px; margin-top: -3.5px;
  border-radius: 50%; background: var(--wait);
}
.pill[data-state="live"]::before { background: var(--ok); box-shadow: 0 0 8px var(--ok); animation: beat 2s infinite; }
.pill[data-state="down"]::before { background: var(--bad); }
@keyframes beat { 50% { opacity: .45; } }

main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  min-height: 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.stage { position: relative; min-height: 480px; display: flex; flex-direction: column; }
canvas { flex: 1; width: 100%; min-height: 440px; display: block; }
aside {
  background: rgba(13, 20, 36, .72); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; overflow: auto;
  /* Always the full visible height next to the graph, however little the panel holds; content scrolls inside. */
  height: calc(100vh - 140px); height: calc(100dvh - 140px); min-height: 480px;
  overscroll-behavior: contain;
}
h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 16px 0 6px; }
@keyframes in { from { opacity: 0; transform: translateY(-4px); } }

/* ── keyboard focus ────────────────────────────────────────────── */
button:focus-visible, a:focus-visible, summary:focus-visible, .panel-title:focus-visible {
  outline: 2px solid var(--nano); outline-offset: 2px; border-radius: 4px;
}
/* Keyboard mirror of the graph: visually hidden until it holds focus, then the focused node is shown over the
   graph (the canvas also draws a ring around it). Items stay focusable: they are clipped, never display:none. */
.node-list {
  list-style: none; margin: 0; padding: 0; position: absolute; left: 8px; right: 8px; bottom: 8px; z-index: 5;
  width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.node-list:focus-within { width: auto; height: auto; overflow: visible; clip-path: none; white-space: normal; }
.node-list li { margin: 0; }
.node-list:focus-within li:not(:focus-within) {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.node-list button.node {
  display: block; width: 100%; text-align: left; background: var(--panel); color: var(--text);
  border: 1px solid var(--nano); border-radius: 8px; padding: 8px 10px; font-family: inherit; font-size: 13px; cursor: pointer;
}

/* ── results panel ─────────────────────────────────────────────── */
main { grid-template-columns: minmax(0, 1fr) 420px; }
aside { padding: 16px; }
.panel-head { margin-bottom: 12px; }
.back {
  background: none; border: 0; color: var(--nano); font-weight: 600; font-size: 12px; line-height: 1.4; font-family: inherit;
  padding: 0; cursor: pointer;
}
.panel-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; min-height: 18px; flex-wrap: wrap; }
/* Slide navigation: « previous branch · ‹ previous item · where you are · next item › · next branch » */
.panel-steps { flex-basis: 100%; display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.step {
  flex: none; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255, 255, 255, .04);
  color: var(--text); font: 600 18px/1 ui-sans-serif, system-ui, sans-serif; cursor: pointer; display: inline-flex;
  align-items: center; justify-content: center; padding: 0 0 2px; transition: background .15s, border-color .15s, transform .1s;
}
.step:hover, .step:focus-visible { border-color: var(--nano); background: rgba(74, 144, 226, .18); }
.step:active { transform: scale(.94); }
.step-cat { font-size: 15px; color: var(--muted); }
.step-where { flex: 1; min-width: 0; text-align: center; font-size: 12px; font-weight: 600; color: var(--text); overflow-wrap: anywhere; line-height: 1.2; }
.step-where small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; }
.to-map { display: none; }
.panel-refresh {
  display: block; width: 100%; margin-bottom: 10px; padding: 6px 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--wait); background: rgba(251, 191, 36, .1); color: var(--text); font-family: inherit; font-size: 12px; font-weight: 600;
}
.panel-sec details.more { margin-top: 6px; }
.panel-sec details.more summary { cursor: pointer; color: var(--nano); font-size: 12px; padding: 4px 0; }
.panel-sec details.more .panel-list { margin-top: 6px; }
.panel-title { font-size: 18px; margin: 0; text-transform: none; letter-spacing: 0; color: var(--text); }
.panel-sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.panel-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; margin: 12px 0 4px; }
.pstat {
  background: var(--panel); border: 1px solid var(--line); border-left-width: 3px; border-radius: 10px;
  padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.pstat span { font-size: 11px; color: var(--muted); line-height: 1.25; }
.pstat b { font-size: 18px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.panel-sec { margin-top: 16px; }
.panel-sec h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 6px; }
.panel-note { color: var(--muted); font-size: 12px; margin: 0 0 6px; }
.panel-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.panel-list li {
  background: rgba(13, 20, 36, .9); border: 1px solid var(--line); border-left: 3px solid var(--line);
  border-radius: 8px; padding: 8px 10px;
}
.panel-list li.empty { color: var(--muted); font-size: 12px; }
.panel-list .row { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; }
.panel-list .text, .panel-list .link { overflow-wrap: anywhere; text-align: left; }
.panel-list .sub { margin: 4px 0 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
button.link, a.link {
  background: none; border: 0; padding: 0; color: var(--text); font: inherit; cursor: pointer; text-decoration: none;
}
button.link:hover, a.link:hover { color: var(--nano); text-decoration: underline; }
a.link::after { content: " ↗"; color: var(--muted); }
.badge {
  flex: none; font-size: 11px; line-height: 1.2; padding: 3px 7px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--line); color: var(--muted); max-width: 55%; overflow: hidden; text-overflow: ellipsis;
}
.tone-good { border-left-color: var(--ok) !important; }
.tone-warn { border-left-color: var(--wait) !important; }
.tone-bad { border-left-color: var(--bad) !important; }
.badge.tone-good { color: var(--ok); border-color: rgba(52, 211, 153, .4); }
.badge.tone-warn { color: var(--wait); border-color: rgba(251, 191, 36, .4); }
.badge.tone-bad { color: var(--bad); border-color: rgba(248, 113, 113, .4); }
.pstat.tone-good b { color: var(--ok); }
.pstat.tone-bad b { color: var(--bad); }
.pstat.tone-warn b { color: var(--wait); }
.panel-list code.addr {
  display: block; margin-top: 6px; padding: 6px 8px; border-radius: 6px; background: #0b1220; border: 1px solid var(--line);
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; color: var(--text);
}
.panel-list .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.panel-list .action {
  border: 1px solid var(--nano); background: rgba(74, 144, 226, .12); color: var(--text); border-radius: 6px;
  padding: 5px 10px; font-size: 12px; font-weight: 600; font-family: inherit; cursor: pointer; text-decoration: none;
}
.panel-list .action:hover { background: rgba(74, 144, 226, .25); }
.results-title { margin-top: 22px; }
.results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.results li {
  display: grid; grid-template-columns: 92px 1fr; gap: 8px; padding: 6px 0 6px 10px;
  border-left: 3px solid var(--line); border-bottom: 1px solid rgba(30, 41, 59, .6); font-size: 13px;
}
.results time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.results .link, .results span { overflow-wrap: anywhere; text-align: left; }

.install {
  border: 1px solid var(--nano); background: rgba(74, 144, 226, .12); color: var(--text);
  border-radius: 999px; padding: 4px 12px; font-weight: 600; font-size: 12px; line-height: 1.45; font-family: inherit; cursor: pointer;
}
.install:hover { background: rgba(74, 144, 226, .25); }
.install-banner {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(560px, calc(100% - 32px)); display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5); z-index: 10; animation: in .3s ease-out;
}
.install-banner img { border-radius: 10px; flex: none; }
.install-copy { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.install-copy span { color: var(--muted); font-size: 12px; }
.install-banner button {
  border: 0; border-radius: 8px; padding: 7px 12px; font-weight: 600; font-size: 13px; line-height: 1; font-family: inherit; cursor: pointer;
  background: var(--nano); color: #fff;
}
.install-banner button.ghost { background: transparent; color: var(--muted); }
.update-banner { bottom: auto; top: max(16px, env(safe-area-inset-top)); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (max-width: 900px) {
  main { grid-template-columns: 1fr; }
  .step { width: 40px; height: 40px; font-size: 20px; }
  /* Stacked under the graph: when a node is tapped the page scrolls here, so the panel fills the whole screen. */
  aside { height: 100vh; height: 100dvh; min-height: 0; scroll-margin-top: 0; border-radius: 12px 12px 0 0; }
  /* The panel covers the screen here, so its navigation sticks to the top and offers a way home to the map. */
  .panel-nav {
    position: sticky; top: -16px; z-index: 3; margin: -16px -16px 8px; padding: 12px 16px 10px;
    background: var(--panel); border-bottom: 1px solid var(--line);
  }
  .to-map {
    display: inline-block; margin-left: auto; background: rgba(74, 144, 226, .12); color: var(--text);
    border: 1px solid var(--nano); border-radius: 999px; padding: 6px 14px; font: 600 13px/1 inherit; cursor: pointer;
  }
  .back { font-size: 14px; padding: 6px 0; }
  /* Taller on phones: the top band under the Now box must never shrink the map into a crowded ring. */
  .stage { min-height: 560px; }
  canvas { min-height: 540px; }
}

/* Newsletter link in the header */
.nl-link {
  border: 1px solid var(--nano); border-radius: 999px; padding: 4px 12px; color: var(--text);
  font-size: 12px; font-weight: 600; text-decoration: none; background: rgba(74, 144, 226, .12);
}
.nl-link:hover, .nl-link:focus-visible { background: rgba(74, 144, 226, .25); }
/* GitHub icon: Rai's account (the one Hermes pushes to) */
.gh-link {
  display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--line); color: var(--text); background: rgba(255, 255, 255, .04);
}
.gh-link:hover, .gh-link:focus-visible { border-color: var(--nano); background: rgba(74, 144, 226, .18); }

/* "Now" mini map: what Rai is doing at this moment, over the top-left corner of the graph */
.now-map {
  position: absolute; top: 8px; left: 8px; z-index: 4; width: min(340px, calc(100% - 16px));
  background: rgba(13, 20, 36, .88); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  font-size: 12px; line-height: 1.35; backdrop-filter: blur(4px);
  /* Never in the layout flow and never in the way: taps pass through to the graph, except on its own buttons. */
  pointer-events: none;
}
.now-map button { pointer-events: auto; }
.now-toggle {
  background: rgba(74, 144, 226, .12); border: 1px solid var(--line); border-radius: 8px; color: var(--text);
  font: 600 11px/1.3 inherit; padding: 3px 8px; margin: 2px 0 3px; cursor: pointer; text-align: left;
}
.now-time { color: var(--muted); font-variant-numeric: tabular-nums; }
/* Expanded: the latest 100 results in a scrollable box that takes taps and scrolling. */
.now-map.expanded { pointer-events: auto; max-height: min(70vh, 560px); overflow-y: auto; overscroll-behavior: contain; }
.now-map.expanded .now-results li { display: flex; gap: 4px; align-items: baseline; }
.now-map:empty { display: none; }
.now-head { margin: 0 0 6px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--text); }
.now-meta { color: var(--muted); }
.now-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.state-working .now-dot { background: #3ecf8e; box-shadow: 0 0 0 0 rgba(62, 207, 142, .6); animation: now-pulse 1.6s infinite; }
@keyframes now-pulse { 70% { box-shadow: 0 0 0 7px rgba(62, 207, 142, 0); } 100% { box-shadow: 0 0 0 0 rgba(62, 207, 142, 0); } }
@media (prefers-reduced-motion: reduce) { .state-working .now-dot { animation: none; } }
.now-flow { list-style: none; margin: 0; padding: 0 0 0 10px; border-left: 2px solid var(--line); display: flex; flex-direction: column; gap: 5px; }
.now-step { position: relative; overflow-wrap: anywhere; white-space: normal; }
.now-doing .now-text { color: var(--text); font-weight: 600; }
.now-step::before { content: ""; position: absolute; left: -15px; top: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--nano); }
.now-label { color: var(--muted); margin-right: 6px; text-transform: uppercase; font-size: 10px; letter-spacing: .06em; }
.now-results { list-style: none; margin: 3px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.now-results .link { background: none; border: 0; padding: 0; color: var(--text); text-align: left; font: inherit; cursor: pointer; text-decoration: underline dotted; }
@media (max-width: 900px) {
  /* Phones: a compact overlay (status + last tools) so updates never resize the graph under the user's finger. */
  .now-map { top: 6px; left: 6px; right: 6px; width: auto; padding: 6px 10px; background: rgba(13, 20, 36, .78); max-height: 116px; overflow: hidden; }
  .now-map .now-head { margin: 0; }
  .now-map .now-flow { border-left: 0; padding: 0; }
  .now-map .now-step { display: none; }
  /* Phones show what is being done (full sentence, wrapped) instead of tool names. */
  .now-map .now-doing { display: block; overflow-wrap: anywhere; }
  /* The newest result stays visible (one tappable line), so phones always see the latest. */
  .now-map .now-latest { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
  .now-map .now-latest .now-text { display: none; }
  .now-map .now-latest .now-results { margin: 0; min-width: 0; flex: 1; }
  .now-map .now-latest .now-results li:not(:first-child) { display: none; }
  .now-map .now-latest .link { display: block; max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
  .now-map .now-latest-box { min-width: 0; flex: 1; }
  .now-map.expanded .now-latest { display: block; }
  .now-map.expanded .now-latest .now-results li:not(:first-child) { display: flex; }
  .now-map.expanded .now-latest .link { white-space: normal; }
  .now-map .now-step::before { display: none; }
}
