:root {
  --control: var(--blue);
  --signal: #9a6615;
  --media: var(--green);
  --alert: var(--orange);
}
#webgl { position: fixed; inset: 0; width: 100%; height: 100%; opacity: .12; pointer-events: none; }
.app-shell { position: relative; z-index: 1; }
.hero-tools { display: flex; flex-direction: column; align-items: flex-end; gap: 12px; flex-shrink: 0; }
.webgl-badge { font: 10px monospace; color: var(--muted); }
.mode-switch { display: flex; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--white); }
.lab .mode-button { padding: 9px 12px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: 12px; }
.mode-button.is-active { background: var(--ink); color: var(--white); }
.scenario-nav { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.stage-card, .story-card, .protocol-card, .decoder {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--shadow);
}
.stage-card { overflow: hidden; }
.stage-topline { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding: 28px 30px 20px; }
.stage-kicker { margin: 0 0 10px; color: var(--green); font: bold 11px/1.4 var(--font-body); letter-spacing: 1.4px; }
.stage-topline h2 { margin: 0; font: normal 30px/1.15 var(--font-title); }
.transport-key { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 10px; max-width: 350px; color: var(--muted); font-size: 11px; }
.key { width: 20px; height: 3px; display: inline-block; border-radius: 3px; }
.key.control { background: var(--control); }
.key.signal { background: var(--signal); }
.key.media { background: var(--media); }
.network-stage {
  position: relative;
  min-height: 660px;
  overflow: hidden;
  isolation: isolate;
  background: radial-gradient(#b7c7bf70 .7px, transparent .7px);
  background-size: 14px 14px;
  border-top: 1px solid var(--line);
}
.stage-glow { position: absolute; inset: 0; z-index: -1; background: radial-gradient(ellipse at center, #e7f0e970, transparent 70%); }
.routes { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.route { fill: none; stroke-width: 1.6; stroke-dasharray: 4 8; opacity: .4; }
.route.control { stroke: var(--control); }
.route.webrtc { stroke: var(--signal); stroke-width: 2.1; }
.route.media { stroke: var(--media); stroke-width: 2.3; }
.route.is-active { opacity: 1; animation: route-flow 1s linear infinite; }
.node {
  position: absolute;
  z-index: 3;
  width: 138px;
  min-height: 116px;
  padding: 17px 10px 12px;
  border: 1px solid #bdcfc4;
  border-radius: 12px;
  background: var(--white);
  box-shadow: 0 4px 0 #d4dfd550;
  text-align: center;
  transition: border-color .2s, box-shadow .2s;
}
.node:hover, .node.is-focused { border-color: var(--blue); box-shadow: 0 0 0 3px #245de014; }
.node.is-touched { border-color: var(--green); box-shadow: 0 0 0 3px #27724d18; }
.node-icon { display: grid; place-items: center; width: 31px; height: 31px; margin: 0 auto 8px; border: 1px solid var(--line); border-radius: 8px; color: var(--green); font-size: 19px; }
.node-label { display: block; font-size: 12px; font-weight: bold; }
.node small { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.node-orbit { position: absolute; width: 12px; height: 12px; top: -5px; right: -5px; border: 2px solid var(--white); border-radius: 50%; background: var(--green); }
.packet-layer { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.packet { position: absolute; width: 11px; height: 11px; margin: -5.5px; border-radius: 50%; background: currentColor; will-change: transform, opacity; }
.packet::after { content: ""; position: absolute; inset: 3px; border-radius: inherit; background: white; opacity: .7; }
.packet.control { color: var(--control); }
.packet.webrtc { color: var(--signal); }
.packet.media { color: var(--media); }
.packet.alert { color: var(--alert); }
.route-label { position: absolute; z-index: 2; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--white); color: var(--muted); font: 10px/1.3 monospace; }
.route-label-control { top: 31%; left: 16%; }

.fanout-board { margin: 0 22px 20px; padding: 20px; border: 1px solid var(--line); border-radius: 12px; background: var(--mint); }
.fanout-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.fanout-heading p { margin: 0 0 7px; color: var(--green); font: bold 10px/1.4 var(--font-body); letter-spacing: 1px; }
.fanout-heading h3 { margin: 0; font: normal 23px/1.2 var(--font-title); }
.fanout-egress { flex-shrink: 0; padding: 8px 10px; border: 1px solid #bdcfc4; border-radius: 8px; background: var(--white); color: var(--green); font: bold 12px monospace; }
.fanout-flow { display: grid; grid-template-columns: minmax(156px, .74fr) 92px minmax(0, 1.5fr); align-items: stretch; gap: 11px; }
.fanout-origin, .fanout-path { border: 1px solid var(--line); background: var(--white); }
.fanout-origin { display: flex; flex-direction: column; justify-content: center; min-height: 112px; padding: 15px; border-radius: 10px; }
.fanout-origin > span { color: var(--ink); font-size: 12px; }
.fanout-origin strong { margin: 7px 0; color: var(--signal); font: bold 25px monospace; letter-spacing: -1px; }
.fanout-origin small { color: var(--muted); font-size: 11px; }
.fanout-split { position: relative; display: grid; place-items: center; color: var(--green); font: bold 11px/1.2 monospace; text-align: center; }
.fanout-split::before { position: absolute; content: ""; inset: 50% 0 auto; height: 2px; background: #a8bbb0; }
.fanout-split span { position: relative; padding: 9px 5px; border: 1px solid #bdcfc4; border-radius: 50%; background: var(--white); }
.fanout-paths { display: grid; gap: 7px; }
.fanout-path { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; align-items: center; min-height: 40px; gap: 10px; padding: 9px 11px; border-radius: 8px; }
.fanout-path-pulse { width: 8px; height: 8px; border-radius: 50%; background: #94a79d; }
.fanout-path strong, .fanout-path small { display: block; }
.fanout-path strong { font-size: 12px; }
.fanout-path small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.fanout-path b { color: var(--muted); font: bold 11px monospace; white-space: nowrap; }
.fanout-path.is-active { border-color: var(--green); }
.fanout-path.is-active .fanout-path-pulse { background: var(--media); animation: fanout-pulse 1.25s ease-in-out infinite; }
.fanout-path.is-active b { color: var(--media); }
.fanout-path.is-restricted { border-color: var(--signal); background: #fff4df; }
.fanout-path.is-restricted .fanout-path-pulse { background: var(--signal); }
.fanout-path.is-restricted b { color: var(--signal); }
.fanout-policy { margin-top: 14px; padding: 10px 12px; border-left: 2px solid var(--green); background: #fff8; color: var(--green); font: bold 11px/1.5 monospace; overflow-wrap: anywhere; }
.fanout-note { margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.stage-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 13px; padding: 17px 23px; border-top: 1px solid var(--line); }
.lab .icon-button { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 8px; background: var(--white); color: var(--ink); font-size: 18px; }
.icon-button:hover { border-color: var(--blue); }
.lab .play-button { padding: 11px 18px; border: 0; border-radius: 9px; background: var(--blue); color: white; font-size: 13px; font-weight: bold; }
.play-button span { margin-right: 6px; }
.step-pills { display: flex; align-items: center; gap: 0; }
.step-pill { width: 24px; height: 36px; padding: 0; border: 0; background: transparent; position: relative; }
.step-pill::after { content: ""; display: block; margin: auto; width: 9px; height: 9px; border: 1px solid var(--muted); border-radius: 50%; }
.step-pill.is-active::after { border-color: var(--blue); background: var(--blue); }
.explain-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; margin-top: 16px; }
.story-card, .protocol-card { min-width: 0; padding: 28px; }
.card-heading { display: flex; align-items: center; gap: 10px; margin-bottom: 21px; color: var(--muted); font: bold 10px/1.4 var(--font-body); letter-spacing: 1px; }
.card-number { display: grid; place-items: center; flex-shrink: 0; width: 25px; height: 25px; border: 1px solid var(--line); border-radius: 7px; color: var(--green); }
.story-card h3 { margin-bottom: 13px; font: normal 30px/1.15 var(--font-title); }
.story-card p { color: var(--muted); font-size: 16px; line-height: 1.6; }
.takeaway { margin-top: 20px; padding: 15px; border-radius: 10px; background: var(--mint); color: var(--green); font-size: 14px; line-height: 1.5; }
.protocol-lines { min-height: 132px; padding: 0 0 12px; }
.protocol-line { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 11px; padding: 9px 0; border-bottom: 1px solid var(--line); color: var(--ink); font: 12px/1.5 monospace; overflow-wrap: anywhere; }
.protocol-line:last-child { border-bottom: 0; }
.protocol-line span { color: var(--signal); }
.protocol-line i { color: var(--muted); font-style: normal; }
.lab .details-toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 12px 0 0; border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--ink); font-size: 12px; text-align: left; }
.details-toggle span { color: var(--green); font-size: 18px; }
.technical-details { display: none; margin-top: 13px; padding: 12px; border-radius: 8px; background: var(--paper); color: var(--muted); font: 11px/1.6 monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.technical-details.is-open { display: block; }
.decoder { margin-top: 16px; padding: 28px; }
.decoder-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.decoder h2 { margin: 0; font: normal 30px/1.15 var(--font-title); }
.decoder-head > p { max-width: 330px; margin: 0; color: var(--muted); font-size: 14px; }
.decoder-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 23px; }
.lab .term { min-height: 120px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--white); color: var(--ink); text-align: left; }
.term:hover { border-color: var(--green); background: var(--mint); }
.term b { display: block; margin-bottom: 8px; color: var(--green); font-size: 13px; }
.term span { color: var(--muted); font-size: 12px; line-height: 1.5; }
footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px; margin-top: 24px; padding: 20px 0 30px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
footer a:hover { color: var(--blue); }
@keyframes route-flow { to { stroke-dashoffset: -24; } }
@keyframes fanout-pulse { 50% { opacity: .5; } }
@media (max-width: 900px) {
  .lab .hero { flex-direction: column; align-items: flex-start; }
  .hero-tools { align-items: flex-start; }
  .scenario-nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stage-topline, .decoder-head { flex-direction: column; align-items: flex-start; }
  .explain-grid { grid-template-columns: 1fr; }
  .decoder-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 650px) {
  .hero-tools { margin-top: 20px; }
  .stage-topline, .story-card, .protocol-card, .decoder { padding: 20px 16px; }
  .route-label { display: none; }
  .fanout-board { margin: 0 10px 12px; padding: 14px; }
  .fanout-heading { flex-wrap: wrap; gap: 10px; }
  .fanout-flow { grid-template-columns: 1fr; }
  .fanout-origin { min-height: 86px; }
  .fanout-split { min-height: 50px; }
  .stage-controls { gap: 8px; padding: 13px 8px; }
  .step-pills { order: -1; justify-content: center; width: 100%; }
  .decoder-grid { grid-template-columns: 1fr; }
  .term { min-height: 88px; }
}

/* Each receiver has its own server-side Subscriber and browser endpoint. */
.node-source { left: 2%; top: 46%; }
.node-control { left: 20%; top: 6%; }
.node-rtc-publisher { left: 20%; top: 46%; }
.node-translator { left: 39%; top: 46%; }
.node-rtc-subscriber { left: 60%; top: 20%; }
.node-peer { left: 82%; top: 20%; }
.node-rtc-eva { left: 60%; top: 46%; }
.node-eva { left: 82%; top: 46%; }
.node-rtc-weak { left: 60%; top: 74%; }
.node-weak { left: 82%; top: 74%; }
.node.is-idle { opacity: .55; }
.route-extra { opacity: .12; }
.route-extra.is-active { opacity: 1; }
.route-label-media { bottom: 3%; left: 35%; }
@media (max-width: 1050px) and (min-width: 901px) {
  .node { width: 120px; }
}
@media (max-width: 900px) {
  .network-stage { min-height: 1000px; }
  .node { width: 138px; }
  .node-control { left: calc(50% - 69px); top: 3%; }
  .node-source { left: 4%; top: 23%; }
  .node-rtc-publisher { left: calc(50% - 69px); top: 23%; }
  .node-translator { left: calc(50% - 69px); top: 43%; }
  .node-rtc-subscriber { left: 4%; top: 64%; }
  .node-peer { left: 4%; top: 83%; }
  .node-rtc-eva { left: calc(50% - 69px); top: 64%; }
  .node-eva { left: calc(50% - 69px); top: 83%; }
  .node-rtc-weak { left: auto; right: 4%; top: 64%; }
  .node-weak { left: auto; right: 4%; top: 83%; }
  .route-label-media { bottom: 2%; left: 20%; }
}
@media (max-width: 650px) {
  .network-stage { min-height: 1080px; }
  .node { width: 118px; }
  .node-source { left: 4%; top: 4%; }
  .node-control { left: auto; right: 4%; top: 4%; }
  .node-rtc-publisher { left: 4%; top: 22%; }
  .node-translator { left: auto; right: 4%; top: 22%; }
  .node-rtc-subscriber { left: 4%; top: 42%; }
  .node-peer { left: auto; right: 4%; top: 42%; }
  .node-rtc-eva { left: 4%; top: 61%; }
  .node-eva { left: auto; right: 4%; top: 61%; }
  .node-rtc-weak { left: 4%; right: auto; top: 80%; }
  .node-weak { left: auto; right: 4%; top: 80%; }
}
