:root {
  color-scheme: dark;
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #242836;
  --border: #2e3344;
  --text: #e4e6ed;
  --muted: #8b8fa3;
  --accent: #4f8ff7;
  --green: #34d399;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: radial-gradient(1200px 700px at 70% 10%, rgba(79,143,247,.08), transparent 60%),
              radial-gradient(900px 600px at 10% 90%, rgba(52,211,153,.05), transparent 60%), var(--bg);
  color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.55;
  display: flex; flex-direction: column; overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }

/* top bar */
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; border-bottom: 1px solid var(--border); background: rgba(15,17,23,.85);
  backdrop-filter: blur(8px); flex: none; }
.bar-left { display: flex; align-items: center; gap: 12px; color: var(--text); min-width: 0; }
.bar-left:hover { text-decoration: none; }
.bar-left > span { display: flex; flex-direction: column; min-width: 0; }
.bar-title { font-weight: 700; font-size: 17px; }
.bar-sub { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-right { display: flex; align-items: center; gap: 14px; flex: none; }
.bar-link { color: var(--muted); font-size: 14px; }
.bar-cta { background: var(--accent); color: #fff; font-weight: 600; font-size: 14px;
  padding: 8px 14px; border-radius: 9px; }
.bar-cta:hover { background: #3a7de6; text-decoration: none; }

/* layout */
.layout { flex: 1; display: grid; grid-template-columns: 360px 1fr; min-height: 0; }
.side { border-right: 1px solid var(--border); background: rgba(26,29,39,.6); overflow-y: auto;
  padding: 18px 18px 24px; display: flex; flex-direction: column; gap: 18px; }
.intro p { font-size: 14px; color: #c9ccd6; }
.intro strong { color: var(--text); font-weight: 600; }
.play { margin-top: 12px; display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  background: rgba(52,211,153,.12); color: var(--green); border: 1px solid rgba(52,211,153,.4);
  font: 600 14px var(--font); padding: 8px 14px; border-radius: 9px; }
.play svg { width: 16px; height: 16px; fill: currentColor; }
.play:hover { background: rgba(52,211,153,.2); }
.play.playing { color: #fbbf24; border-color: rgba(251,191,36,.45); background: rgba(251,191,36,.1); }

.legend-title { font: 600 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; background: var(--surface2);
  border: 1px solid var(--border); color: var(--text); font: 500 13px var(--font); padding: 5px 10px; border-radius: 999px; }
.chip i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.chip[aria-pressed="true"] { border-color: var(--accent); background: rgba(79,143,247,.15); }
.chip:hover { border-color: #46506a; }

.detail { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; min-height: 140px; }
.detail-empty p { font-size: 14px; }
.detail-group { font: 600 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.detail h2 { font-size: 19px; margin: 4px 0 6px; line-height: 1.3; }
.detail-summary { color: var(--text); font-weight: 500; margin-bottom: 8px; }
#dText { color: #c9ccd6; font-size: 14px; }
.detail-links { margin-top: 12px; display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; }
.detail-links .rel { color: var(--muted); }
.detail-links button { background: none; border: none; color: var(--accent); font: inherit; cursor: pointer; padding: 0; text-align: left; }
.detail-links button:hover { text-decoration: underline; }
.ask { display: block; margin-top: 14px; padding: 10px 12px; border-radius: 9px; font-size: 14px;
  background: rgba(79,143,247,.12); border: 1px solid rgba(79,143,247,.35); color: #cfe0ff; }
.ask:hover { background: rgba(79,143,247,.2); text-decoration: none; }

.listview summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.listview h3 { font: 600 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; margin: 14px 0 6px; }
.listview ul { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.listview li { font-size: 13.5px; color: #c9ccd6; }
.listview li strong { color: var(--text); }
.footnote { font-size: 12.5px; color: var(--muted); margin-top: auto; }

/* graph stage */
.stage { position: relative; min-width: 0; min-height: 0; }
#graph { width: 100%; height: 100%; display: block; cursor: grab; }
#graph:active { cursor: grabbing; }
.link { stroke: #3a4157; stroke-opacity: .7; fill: none; }
.link.hi { stroke: #8fb6ff; stroke-opacity: 1; stroke-width: 1.8; }
.link-label { font: 500 10px var(--font); fill: #9aa3bd; pointer-events: none; opacity: 0; }
.link-label.hi { opacity: 1; }
.node { cursor: pointer; }
.node circle.body { stroke: #0f1117; stroke-width: 2; }
.node circle.halo { fill: none; stroke-width: 2; opacity: 0; }
.node text { font: 500 12px var(--font); fill: var(--text); paint-order: stroke; stroke: #0f1117; stroke-width: 4px; stroke-linejoin: round; pointer-events: none; }
.node.core text { font-weight: 700; font-size: 14px; }
.node.dim, .link.dim { opacity: .14; }
.link-label.dim { opacity: 0; }
.node.sel circle.halo, .node.hot circle.halo { opacity: 1; }
.node.hot circle.halo { animation: pulse 1s ease-out infinite; }
@keyframes pulse { 0% { stroke-opacity: 1; r: var(--r0); } 100% { stroke-opacity: 0; r: var(--r1); } }
.node.visited circle.body { stroke: var(--green); }

.flow-caption { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); max-width: min(620px, calc(100% - 32px));
  background: rgba(26,29,39,.95); border: 1px solid rgba(52,211,153,.45); border-radius: 12px; padding: 10px 14px;
  font-size: 14px; display: flex; gap: 10px; align-items: baseline; box-shadow: 0 8px 30px rgba(0,0,0,.4); }
.flow-step { font: 600 12px var(--mono); color: var(--green); white-space: nowrap; }
.stage-tools { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; }
.stage-tools button { background: var(--surface); border: 1px solid var(--border); color: var(--muted);
  font: 500 13px var(--font); padding: 5px 10px; border-radius: 8px; cursor: pointer; }
.stage-tools button:hover { color: var(--text); }
.noscript { padding: 40px; }

/* narrow screens: graph on top, panel below, page scrolls */
@media (max-width: 900px) {
  body { overflow: auto; height: auto; }
  .bar { padding: 10px 16px; position: sticky; top: 0; z-index: 5; }
  .bar-sub, .bar-link { display: none; }
  .layout { display: flex; flex-direction: column-reverse; }
  .stage { height: 62vh; min-height: 380px; border-bottom: 1px solid var(--border); }
  .side { border-right: none; overflow: visible; padding: 16px; }
  .flow-caption { bottom: 12px; font-size: 13px; }
}
.flow-caption[hidden] { display: none; }
.group-label { font: 600 11px var(--mono); letter-spacing: .1em; opacity: .75; pointer-events: none; }
#graph.portrait .node text { font-size: 15px; }
#graph.portrait .group-label { font-size: 13px; }
.side > * { flex: none; }
.node:focus { outline: none; }
.node:focus-visible circle.halo { opacity: 1; }
@media (max-width: 900px) {
  .layout { display: flex; flex-direction: column; }
  .side { display: contents; }
  .side > section, .side > details, .side > p { margin: 0 16px; }
  .intro { order: 1; padding-top: 14px; }
  .stage { order: 2; margin: 14px 0; border-top: 1px solid var(--border); }
  .legend { order: 3; }
  .detail { order: 4; margin-top: 14px !important; }
  .listview { order: 5; margin-top: 16px !important; }
  .footnote { order: 6; margin: 16px 16px 24px !important; }
}
#graph.portrait .group-label { display: none; }

/* mobile: keep site links visible as a second row */
@media (max-width: 900px) {
  .bar { flex-wrap: wrap; row-gap: 8px; }
  .bar-right { flex-basis: 100%; justify-content: flex-start; gap: 18px; padding-left: 44px; overflow-x: auto; }
  .bar-link { display: inline; font-size: 13px; white-space: nowrap; }
  .bar-cta { margin-left: auto; font-size: 13px; padding: 6px 12px; white-space: nowrap; }
}
