/* Figures for the residual stream post. Colors follow the console theme tokens. */
.rs-fig {
  --rs-fg: var(--text-color, #202124);
  --rs-muted: var(--console-muted, #66645d);
  --rs-accent: var(--console-accent, #d95f02);
  --rs-rule: var(--console-rule, rgba(32, 33, 36, 0.16));
  --rs-alt: #2f6fb0;
  --rs-panel: rgba(255, 255, 255, 0.55);
  --rs-soft: rgba(217, 95, 2, 0.12);
  margin: 2.2em 0;
  padding: 1em 1.1em 0.9em;
  border: 1px solid var(--rs-rule);
  background: var(--rs-panel);
  border-radius: 3px;
}

html[data-theme="dark"] .rs-fig {
  --rs-alt: #7fb2ff;
  --rs-panel: rgba(255, 255, 255, 0.03);
  --rs-soft: rgba(255, 159, 69, 0.14);
}

.rs-fig svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.rs-fig figcaption {
  margin-top: 0.8em;
  color: var(--rs-muted);
  font-size: 0.82em;
  line-height: 1.5;
}

.rs-fig .rs-title {
  margin: 0 0 0.6em;
  color: var(--rs-muted);
  font-size: 0.78em;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.rs-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5em 1em;
  margin-bottom: 0.8em;
  font-size: 0.85em;
}

.rs-controls label {
  display: flex;
  flex: 1 1 220px;
  align-items: center;
  gap: 0.6em;
  margin: 0;
  font-weight: normal;
}

.rs-controls input[type="range"] {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  accent-color: var(--rs-accent);
}

.rs-btn {
  padding: 0.35em 0.8em;
  border: 1px solid var(--rs-rule);
  border-radius: 3px;
  background: transparent;
  color: var(--rs-fg);
  font: inherit;
  font-size: 0.85em;
  line-height: 1.3;
  cursor: pointer;
}

.rs-btn:hover,
.rs-btn:focus-visible {
  border-color: var(--rs-accent);
}

.rs-btn[aria-pressed="true"],
.rs-btn[aria-selected="true"] {
  border-color: var(--rs-accent);
  background: var(--rs-soft);
  color: var(--rs-fg);
}

.rs-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4em;
  margin-bottom: 0.9em;
}

.rs-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4em 1.6em;
  margin-top: 0.6em;
  font-size: 0.85em;
  font-variant-numeric: tabular-nums;
}

.rs-stats b {
  color: var(--rs-accent);
  font-weight: 600;
}

.rs-eq {
  margin: 0.6em 0 0;
  overflow-x: auto;
  font-size: 0.9em;
}

.rs-note {
  color: var(--rs-muted);
  font-size: 0.82em;
}

/* SVG primitives */
.rs-fig .t { fill: var(--rs-fg); font-family: inherit; font-size: 13px; }
.rs-fig .tm { fill: var(--rs-muted); font-family: inherit; font-size: 11px; }
.rs-fig .talt { fill: var(--rs-alt); font-family: inherit; font-size: 12px; font-weight: 600; }
.rs-fig .ta { fill: var(--rs-accent); font-family: inherit; font-size: 13px; font-weight: 600; }
.rs-fig .s { stroke: var(--rs-fg); fill: none; stroke-width: 1.4; }
.rs-fig .sm { stroke: var(--rs-muted); fill: none; stroke-width: 1; }
.rs-fig .sr { stroke: var(--rs-rule); fill: none; stroke-width: 1; }
.rs-fig .sa { stroke: var(--rs-accent); fill: none; stroke-width: 2; }
.rs-fig .salt { stroke: var(--rs-alt); fill: none; stroke-width: 1.6; }
.rs-fig .stream { stroke: var(--rs-accent); fill: none; stroke-width: 6; stroke-linecap: round; opacity: 0.85; }
.rs-fig .box { fill: var(--body-bg, #fbfaf6); stroke: var(--rs-fg); stroke-width: 1.3; }
.rs-fig .box-off { fill: none; stroke: var(--rs-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.rs-fig .fa { fill: var(--rs-accent); }
.rs-fig .falt { fill: var(--rs-alt); }
.rs-fig .fm { fill: var(--rs-muted); }
.rs-fig .fsoft { fill: var(--rs-soft); }
.rs-fig .dash { stroke-dasharray: 4 4; }

/* Long display equations scroll inside their own box instead of widening the page. */
.post-content mjx-container[display="true"] {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.2em 0;
}

@media (max-width: 760px) {
  .rs-fig {
    margin-left: -0.4em;
    margin-right: -0.4em;
    padding: 0.8em 0.7em;
  }

  /* Keep SVG labels legible on phones: figures keep a minimum width and scroll sideways. */
  .rs-fig > div {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .rs-fig svg {
    min-width: 520px;
  }
}

/* Scroll companion: schematic in the left margin (wide screens) or a slim strip (narrow screens). */
.rs-fig.rs-rail,
.rs-fig.rs-strip {
  display: none;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.rs-fig.rs-rail {
  position: fixed;
  top: 84px;
  --rs-rail-w: clamp(190px, calc((100vw - 900px) / 2 - 100px), 270px);
  left: calc((100vw - 900px) / 2 - var(--rs-rail-w) - 28px);
  z-index: 5;
  width: var(--rs-rail-w);
  height: min(920px, calc(100vh - 104px));
  padding: 0;
  flex-direction: column;
  pointer-events: none;
}

.rs-rail svg {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}

.rs-rail-cap {
  flex: 0 0 auto;
  min-height: 5.6em;
  margin-top: 0.4em;
  color: var(--rs-muted);
  font-size: 0.8em;
  line-height: 1.45;
}

.rs-rail-cap b {
  color: var(--rs-accent);
  font-weight: 600;
}

.rs-fig.rs-strip {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  align-items: center;
  gap: 0.8em;
  padding: 0.35em 1em calc(0.35em + env(safe-area-inset-bottom));
  border-top: 1px solid var(--rs-rule);
  background: var(--body-bg, #fbfaf6);
  pointer-events: none;
}

.rs-strip svg {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 420px;
  height: 30px;
}

.rs-strip-cap {
  flex: 0 0 auto;
  max-width: 55%;
  color: var(--rs-muted);
  font-size: 0.72em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (min-width: 1440px) and (min-height: 620px) {
  .rs-fig.rs-rail { display: flex; }
}

@media (max-width: 1439px), (max-height: 619px) {
  .rs-fig.rs-strip { display: flex; }
  body.rs-companion { padding-bottom: 3.2em; }
}

@media print {
  .rs-fig.rs-rail,
  .rs-fig.rs-strip { display: none !important; }
}
