/* tangle.css: styles for tangle.js. Override the custom properties to theme. */
/* Built by `make build` from src/. Edit the files there, not this one. */

:root {
  --tangle-accent: #246bce;
  --tangle-soft: 14%; /* strength of the hover/drag highlight */
  --tangle-tint: 8%; /* strength of the resting tint behind values the reader can change */
  --tangle-surface: #fff;
  --tangle-error: #c9382b;
  --tangle-muted: 55%; /* strength of the punctuation in <t-call> and <t-tag> */
  --tangle-stale: 0.45; /* opacity of a value waiting on a new answer */
  --tangle-code-tag: #6f5cbd;
  --tangle-code-attr: #b45b1b;
  --tangle-code-string: #147a68;
  --tangle-chart-grid: 12%; /* strength of the gridlines */
  --tangle-chart-text: 60%; /* strength of the tick and axis labels */
  --tangle-chart-font: 12px ui-sans-serif, system-ui, sans-serif;
  /* <t-formula-dag>: one color per formula that feeds others, and the notes' gray. */
  --tangle-dag-1: #246bce;
  --tangle-dag-2: #b45b1b;
  --tangle-dag-3: #147a68;
  --tangle-dag-4: #a23b78;
  --tangle-dag-5: #6f5cbd;
  --tangle-dag-6: #8a6d00;
  --tangle-dag-7: #2f7d32;
  --tangle-dag-8: #b3262e;
  --tangle-dag-note: #6b6459;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --tangle-accent: #75a7ff;
    --tangle-surface: #22201d;
    --tangle-code-tag: #b9a8ff;
    --tangle-code-attr: #ffad66;
    --tangle-code-string: #5ed5bd;
    --tangle-dag-1: #75a7ff;
    --tangle-dag-2: #ffad66;
    --tangle-dag-3: #5ed5bd;
    --tangle-dag-4: #f08bc2;
    --tangle-dag-5: #b9a8ff;
    --tangle-dag-6: #e3c35a;
    --tangle-dag-7: #86d38a;
    --tangle-dag-8: #ff8a8f;
    --tangle-dag-note: #b8b0a4;
  }
}

:root[data-theme="dark"],
:root.dark {
  --tangle-accent: #75a7ff;
  --tangle-surface: #22201d;
  --tangle-code-tag: #b9a8ff;
  --tangle-code-attr: #ffad66;
  --tangle-code-string: #5ed5bd;
  --tangle-dag-1: #75a7ff;
  --tangle-dag-2: #ffad66;
  --tangle-dag-3: #5ed5bd;
  --tangle-dag-4: #f08bc2;
  --tangle-dag-5: #b9a8ff;
  --tangle-dag-6: #e3c35a;
  --tangle-dag-7: #86d38a;
  --tangle-dag-8: #ff8a8f;
  --tangle-dag-note: #b8b0a4;
}

t-var,
t-let,
t-fetch {
  display: none;
}

/* Waiting on a <t-fetch>: the old value shows, dimmed. The delay skips quick answers. */
.is-stale {
  opacity: var(--tangle-stale);
  transition: opacity 150ms 150ms;
}

@media (prefers-reduced-motion: reduce) {
  .is-stale {
    transition: none;
  }
}

/* A scope groups content without adding a box of its own. */
t-scope {
  display: contents;
}

/* A floating panel. Until tangle.js runs, its contents show in place. */
t-panel {
  display: block;
}

/* Draggable numbers, in prose, in formulas and in your own elements ------- */

t-num,
:where([data-tangle-param]) {
  --tangle-c: var(--tangle-color, var(--tangle-accent));
  color: var(--tangle-c);
  cursor: ew-resize;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  border-radius: 0.18em;
  outline: none;
  transition: background-color 120ms ease, box-shadow 120ms ease;
}

t-num {
  position: relative;
  padding-inline: 0.12em;
  background: color-mix(in srgb, var(--tangle-c) var(--tangle-tint), transparent);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

t-num.is-hot,
t-num.is-active,
t-num:focus-visible,
:where([data-tangle-param]).is-hot,
:where([data-tangle-param]).is-active,
:where([data-tangle-param]):focus-visible {
  background: color-mix(in srgb, var(--tangle-c) var(--tangle-soft), transparent);
  box-shadow: 0 0 0 0.12em color-mix(in srgb, var(--tangle-c) var(--tangle-soft), transparent);
}

t-num:focus-visible,
:where([data-tangle-param]):focus-visible {
  box-shadow: 0 0 0 0.14em color-mix(in srgb, var(--tangle-c) 45%, transparent);
}

/* The little "drag" hint from the original Tangle. */
@media (hover: hover) {
  t-num::after {
    content: "drag";
    position: absolute;
    left: 50%;
    bottom: calc(100% + 4px);
    transform: translateX(-50%);
    padding: 1px 5px 2px;
    border-radius: 3px;
    background: var(--tangle-c);
    color: var(--tangle-surface);
    font: 600 10px/1.3 ui-sans-serif, system-ui, sans-serif;
    letter-spacing: 0.04em;
    pointer-events: none;
    opacity: 0;
    transition: opacity 120ms ease 250ms;
  }
  t-num:hover:not(.is-active)::after {
    opacity: 1;
  }
}

:root.tangle-dragging,
:root.tangle-dragging * {
  cursor: ew-resize !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}

/* Choices ----------------------------------------------------------------- */

t-choice,
t-select {
  color: var(--tangle-color, var(--tangle-accent));
  padding-inline: 0.12em;
  background: color-mix(in srgb, var(--tangle-color, var(--tangle-accent)) var(--tangle-tint), transparent);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  border-radius: 0.18em;
  outline: none;
}

t-choice:hover,
t-choice:focus-visible,
t-select:hover,
t-select:focus-visible,
t-select[aria-expanded="true"] {
  background: color-mix(in srgb, var(--tangle-color, var(--tangle-accent)) var(--tangle-soft), transparent);
}

/* A caret says that a <t-select> opens a menu. */
t-select::after {
  content: "▾";
  margin-left: 0.15em;
  font-size: 0.75em;
}

/* Editable text ----------------------------------------------------------- */

t-text {
  color: var(--tangle-color, var(--tangle-accent));
  padding-inline: 0.12em;
  background: color-mix(in srgb, var(--tangle-color, var(--tangle-accent)) var(--tangle-tint), transparent);
  cursor: text;
  user-select: none;
  -webkit-user-select: none;
  border-radius: 0.18em;
  outline: none;
}

t-text:empty {
  padding-inline: 0.6em;
}

t-text:hover,
t-text:focus-visible {
  background: color-mix(in srgb, var(--tangle-color, var(--tangle-accent)) var(--tangle-soft), transparent);
}

/* Function calls ---------------------------------------------------------- */

t-call {
  display: inline-block;
  max-width: 100%;
  vertical-align: bottom;
  white-space: pre;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

t-call[display] {
  display: block;
  box-sizing: border-box;
  width: fit-content;
  margin: 1rem 0;
  padding: 0.7em 1em;
  border: 1px solid color-mix(in srgb, currentColor 15%, transparent);
  border-radius: 8px;
  background: var(--tangle-surface);
  line-height: 1.8;
}

/* Syntax highlighting, shared with <t-tag>. Values the reader can change keep the accent color. */
.t-code-punct {
  color: color-mix(in srgb, currentColor var(--tangle-muted), transparent);
}

.t-code-tag {
  color: var(--tangle-code-tag);
}

.t-code-attr {
  color: var(--tangle-code-attr);
}

.t-code-string {
  color: var(--tangle-code-string);
}

/* In code, strings get quotes and the color is enough of a hint. */
t-call t-select::after {
  content: none;
}

t-call t-text::before,
t-call t-text::after,
t-call t-choice[data-type="string"]::before,
t-call t-choice[data-type="string"]::after,
t-call t-select[data-type="string"]::before,
t-call t-select[data-type="string"]::after {
  content: "'";
  margin: 0;
  font-size: inherit;
  color: var(--tangle-code-string);
}

t-call t-num,
t-call t-choice,
t-call t-select,
t-call t-text {
  padding-inline: 0;
  background: none;
}

/* HTML tags --------------------------------------------------------------- */

t-tag {
  display: block;
  margin: 1rem 0;
  border: 1px solid color-mix(in srgb, currentColor 15%, transparent);
  border-radius: 8px;
  background: var(--tangle-surface);
  padding: 0.7em 1em 0;
  white-space: pre;
}

/* The code is everything but the preview, which keeps the page's own font. */
t-tag > :not(.t-tag-preview) {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82em;
}

.t-tag-flag {
  color: var(--tangle-accent);
  cursor: pointer;
  border-radius: 0.18em;
  outline: none;
}

.t-tag-flag:hover,
.t-tag-flag:focus-visible {
  background: color-mix(in srgb, var(--tangle-accent) var(--tangle-soft), transparent);
}

.t-tag-flag.is-off {
  text-decoration: line-through;
  opacity: 0.5;
}

t-tag t-num,
t-tag t-choice,
t-tag t-select,
t-tag t-text {
  padding-inline: 0;
  background: none;
}

.t-tag-preview {
  margin: 0.7em -1em 0;
  padding: 1em;
  border-top: 1px dashed color-mix(in srgb, currentColor 15%, transparent);
  white-space: normal;
}

/* Outputs ----------------------------------------------------------------- */

t-out {
  font-variant-numeric: tabular-nums;
}

t-out.is-error {
  color: var(--tangle-error);
  cursor: help;
}

/* Code cells -------------------------------------------------------------- */

t-codecell {
  display: block;
  margin: 1rem 0;
  border: 1px solid color-mix(in srgb, currentColor 15%, transparent);
  border-radius: 8px;
  background: var(--tangle-surface);
  font-size: 0.92em;
}

t-codecell.is-error {
  border-color: color-mix(in srgb, var(--tangle-error) 50%, transparent);
}

.t-codecell-editor {
  padding: 0.3em 0;
}

.t-codecell-editor .cm-editor,
.t-codecell-pre,
.t-codecell-textarea,
.t-codecell-output {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.t-codecell-editor .cm-scroller {
  font-family: inherit;
  line-height: 1.5;
}

/* Until CodeMirror loads, the code shows as it is. */
.t-codecell-pre {
  margin: 0;
  padding: 4px 1em;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
}

.t-codecell-textarea {
  display: block;
  box-sizing: border-box;
  width: 100%;
  padding: 4px 1em;
  border: none;
  background: transparent;
  color: inherit;
  font-size: inherit;
  line-height: 1.5;
  resize: vertical;
}

.t-codecell-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.75em;
  min-height: 1.6em;
  padding: 0 0.75em;
  font-size: 0.85em;
  color: color-mix(in srgb, currentColor var(--tangle-muted), transparent);
}

.t-codecell-bar[hidden] {
  display: none;
}

.t-codecell-reset,
.t-codecell-copy {
  padding: 0 0.5em;
  border: 1px solid color-mix(in srgb, currentColor 25%, transparent);
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.t-codecell-output {
  padding: 0.5em 1em;
  border-top: 1px solid color-mix(in srgb, currentColor 10%, transparent);
  font-size: 0.92em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 12em;
  overflow-y: auto;
}

.t-codecell-output:empty {
  display: none;
}

t-codecell.is-running .t-codecell-output {
  opacity: var(--tangle-stale);
  transition: opacity 150ms 150ms;
}

.t-codecell-log {
  color: color-mix(in srgb, currentColor var(--tangle-muted), transparent);
}

.t-codecell-log.is-warn {
  color: var(--tangle-code-attr);
}

.t-codecell-log.is-error,
.t-codecell-error {
  color: var(--tangle-error);
}

/* Syntax highlighting, in the colors <t-call> and <t-tag> use. */
t-codecell .tok-keyword,
t-codecell .tok-operatorKeyword {
  color: var(--tangle-code-tag);
}

t-codecell .tok-string,
t-codecell .tok-string2 {
  color: var(--tangle-code-string);
}

t-codecell .tok-number,
t-codecell .tok-bool,
t-codecell .tok-atom {
  color: var(--tangle-code-attr);
}

t-codecell .tok-comment {
  font-style: italic;
  color: color-mix(in srgb, currentColor var(--tangle-muted), transparent);
}

/* Names that come from the page get the tint of the values the reader changes. No
   padding, so the columns of the code stay put. */
t-codecell .t-codecell-page {
  border-radius: 0.18em;
  background: color-mix(in srgb, var(--tangle-accent) var(--tangle-soft), transparent);
}

t-codecell .tok-variableName.tok-definition,
t-codecell .tok-propertyName.tok-definition {
  color: var(--tangle-accent);
}

/* Formulas ---------------------------------------------------------------- */

t-math[display] {
  display: block;
  overflow-x: auto;
  overflow-y: hidden;
}

t-math[display] .katex-display {
  margin: 0.8em 0;
}

/* KaTeX lays struts and glyphs over each other; only markers take the pointer. */
t-math .katex-html * {
  pointer-events: none;
}

t-math .katex-html [data-tangle-param] {
  pointer-events: auto;
  position: relative;
  z-index: 1;
}

.tangle-math-error,
.tangle-vega-error,
.tangle-obsplot-error,
.tangle-graph-error,
.tangle-jsxgraph-error {
  color: var(--tangle-error);
  font: 0.85em/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
}

/* Formula DAGs ------------------------------------------------------------ */

t-formula-dag {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  margin: 1em 0;
}

/* As wide as the diagram, centered. The legend wraps to that width rather than widening it. */
.tangle-dag {
  position: relative;
  display: grid;
  grid-template-columns: minmax(min(100%, 420px), max-content);
  justify-content: safe center;
  --tangle-dag-muted: color-mix(in srgb, currentColor 55%, transparent);
}

.tangle-dag.is-loading {
  color: var(--tangle-dag-muted);
  font: 0.85em ui-sans-serif, system-ui, sans-serif;
}

.tangle-dag-board {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  gap: 72px;
  box-sizing: border-box;
  min-width: 100%;
  padding: 12px 24px;
}

.tangle-dag-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 40px;
}

/* An empty lane, kept free for an arrow that skips this row. */
.tangle-dag-lane {
  flex: 0 0 14px;
  align-self: stretch;
}

.tangle-dag-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 6px 12px 4px;
  border: 1px solid transparent;
  border-radius: 10px;
  transition: opacity 120ms ease, border-color 120ms ease, background-color 120ms ease;
}

.tangle-dag-card:hover {
  background: color-mix(in srgb, currentColor 4%, transparent);
}

.tangle-dag-card.is-pickable {
  cursor: pointer;
}

.tangle-dag-card.is-selected {
  border-color: color-mix(in srgb, var(--tangle-accent) 55%, transparent);
  background: color-mix(in srgb, var(--tangle-accent) 6%, transparent);
}

.tangle-dag-stage {
  position: relative;
}

.tangle-dag-tex {
  position: relative;
  z-index: 1;
  padding-bottom: 3px;
}

.tangle-dag-tex .katex-display {
  margin: 0;
}

/* Left-aligned, so a formula never moves with its card's width (captions and
   notes can widen it); arrows and notes measure from it. */
.tangle-dag-tex .katex-display > .katex {
  text-align: left;
}

.tangle-dag-tex .katex {
  font-size: 1.1em;
}

.tangle-dag-tex.is-error {
  color: var(--tangle-error);
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
}

.tangle-dag-caption {
  align-self: flex-end;
  margin-top: 4px;
  white-space: nowrap;
  color: var(--tangle-dag-muted);
  font: 10.5px ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* KaTeX lays struts and glyphs over each other; only the markers take the pointer. */
.tangle-dag-tex .katex-html * {
  pointer-events: none;
}

.tangle-dag-tex .katex-html [data-tangle-param],
.tangle-dag-tex .katex-html [data-note],
.tangle-dag-tex .katex-html [data-tangle-hover] {
  pointer-events: auto;
}

/* A formula's output, and every place it's used, in that formula's color. */
.tangle-dag [data-fdag-out],
.tangle-dag [data-fdag-use] {
  color: var(--tangle-dag-c, inherit);
  border-radius: 0.16em;
  transition: background-color 120ms ease, box-shadow 120ms ease;
}

.tangle-dag .katex-html [data-tangle-hover].is-hot {
  --tangle-dag-glow: color-mix(in srgb, var(--tangle-dag-c, currentColor) 18%, transparent);
  background: var(--tangle-dag-glow);
  box-shadow: 0 0 0 0.14em var(--tangle-dag-glow);
}

/* The value closing a formula without a left-hand side: there, but quieter. */
.tangle-dag .katex-html [data-fdag-value] {
  color: color-mix(in srgb, currentColor 65%, transparent);
}

/* In a DAG, color means "came from that formula", so numbers are ink unless they have a color. */
.tangle-dag [data-tangle-param] {
  --tangle-c: var(--tangle-color, currentColor);
  position: relative;
  z-index: 1;
  background: color-mix(in srgb, var(--tangle-c) var(--tangle-tint), transparent);
}

.tangle-dag .tangle-dag-gap {
  margin-left: 0.22em;
}

/* Arrows ------------------------------------------------------------------- */

.tangle-dag-edges,
.tangle-dag-tints,
.tangle-dag-note-arrows {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.tangle-dag-edge {
  fill: none;
  stroke: var(--tangle-dag-c);
  stroke-width: 1.3;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity 120ms ease;
}

.tangle-dag-head {
  fill: var(--tangle-dag-c);
  stroke: var(--tangle-dag-c);
  stroke-width: 0.8;
  stroke-linejoin: round;
  transition: opacity 120ms ease;
}

.tangle-dag .is-dim {
  opacity: 0.18;
}

/* Notes -------------------------------------------------------------------- */

.tangle-dag .katex-html .tangle-dag-term {
  color: var(--tangle-dag-c);
  outline: none;
}

.tangle-dag-note {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  width: max-content;
  max-width: 190px;
  padding: 2px 6px;
  border-radius: 6px;
  color: var(--tangle-dag-c);
  font: 500 0.78rem/1.3 ui-sans-serif, system-ui, sans-serif;
  text-align: center;
  transition: background-color 120ms ease, opacity 160ms ease;
}

.tangle-dag-note.is-left {
  max-width: 160px;
  text-align: right;
}

.tangle-dag-note strong {
  font-weight: 750;
}

.tangle-dag-note .katex {
  font-size: 1.05em;
}

.tangle-dag-tint {
  fill: color-mix(in srgb, var(--tangle-dag-c) 12%, transparent);
  transition: fill 120ms ease, opacity 160ms ease;
}

.tangle-dag-note-arrow {
  fill: none;
  stroke: var(--tangle-dag-c);
  stroke-width: 1.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity 160ms ease, stroke-width 120ms ease;
}

/* Hovering a note (or dragging the number it explains) lifts it and fades the others. */
.tangle-dag.has-note-hover .tangle-dag-note,
.tangle-dag.has-note-hover .tangle-dag-note-arrow,
.tangle-dag.has-note-hover .tangle-dag-tint {
  opacity: 0.28;
}

.tangle-dag.has-note-hover .tangle-dag-note.is-hovered,
.tangle-dag.has-note-hover .tangle-dag-note-arrow.is-hovered,
.tangle-dag.has-note-hover .tangle-dag-tint.is-hovered {
  opacity: 1;
}

.tangle-dag-note.is-hovered {
  background: color-mix(in srgb, var(--tangle-dag-c) 14%, transparent);
}

.tangle-dag-note-arrow.is-hovered {
  stroke-width: 1.8;
}

.tangle-dag-tint.is-hovered {
  fill: color-mix(in srgb, var(--tangle-dag-c) 30%, transparent);
}

/* Legend and Reset ---------------------------------------------------------- */

.tangle-dag-footer {
  contain: inline-size;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 12px;
  padding: 4px 8px;
  font: 0.8rem/1.2 ui-sans-serif, system-ui, sans-serif;
}

.tangle-dag-legend {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;
}

.tangle-dag-legend-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 8px;
}

.tangle-dag-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 3px 10px 4px;
  border: 1px solid color-mix(in srgb, currentColor 12%, transparent);
  border-radius: 999px;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.tangle-dag-chip[data-tangle-param] {
  --tangle-c: currentColor;
  background: none;
}

.tangle-dag-chip[data-tangle-param].is-hot,
.tangle-dag-chip[data-tangle-param].is-active,
.tangle-dag-chip[data-tangle-param]:focus-visible {
  border-color: color-mix(in srgb, var(--tangle-accent) 60%, transparent);
  background: color-mix(in srgb, var(--tangle-accent) var(--tangle-tint), transparent);
  box-shadow: none;
}

.tangle-dag-chip-symbol .katex {
  font-size: 1.12em;
}

.tangle-dag-chip.is-output .tangle-dag-chip-symbol {
  color: var(--tangle-dag-c, inherit);
}

.tangle-dag-chip-label {
  color: var(--tangle-dag-muted);
}

.tangle-dag-chip-label:empty {
  display: none;
}

.tangle-dag-chip-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tangle-dag-chip[data-tangle-param] .tangle-dag-chip-value {
  color: var(--tangle-color, inherit);
}

.tangle-dag-chip.is-output {
  border-style: dashed;
}

.tangle-dag-chip.is-output.is-hot {
  border-color: color-mix(in srgb, currentColor 45%, transparent);
}

.tangle-dag-chip.is-error .tangle-dag-chip-value {
  color: var(--tangle-error);
}

.tangle-dag-reset {
  padding: 4px 6px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--tangle-dag-muted);
  font: 700 0.74rem/1 ui-sans-serif, system-ui, sans-serif;
  cursor: pointer;
  opacity: 0.5;
}

.tangle-dag-reset.is-changed {
  opacity: 1;
}

.tangle-dag-reset:hover {
  color: inherit;
  text-decoration: underline;
}

.tangle-dag-error {
  color: var(--tangle-error);
  font: 0.85em/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
}

/* Flows -------------------------------------------------------------------- */

t-flow {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  margin: 1em 0;
}

/* As wide as the diagram, centered. */
.tangle-flow {
  --tangle-flow-edge: color-mix(in srgb, currentColor 42%, var(--tangle-flow-bg));
  --tangle-flow-note: color-mix(in srgb, currentColor 62%, transparent);
  --tangle-flow-rule: color-mix(in srgb, currentColor 16%, transparent);
  --tangle-flow-bg: var(--tangle-surface);
  --tangle-flow-layer-gap: 56px;
  --tangle-flow-node-gap: 40px;
  display: flex;
  justify-content: safe center;
}

.tangle-flow-board {
  position: relative;
  flex: none;
}

/* Each node is placed by the layout: the item holds the node and its note. */
.tangle-flow-item {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 26px;
  width: max-content;
}

.tangle-flow[data-direction="right"] > .tangle-flow-board > .tangle-flow-item {
  flex-direction: column;
  gap: 20px;
}

.tangle-flow.is-moving > .tangle-flow-board > .tangle-flow-item {
  transition: left 200ms cubic-bezier(0.2, 0.7, 0.2, 1), top 200ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

.tangle-flow-node {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.tangle-flow-body > * {
  margin-block: 0;
}

.tangle-flow-caption {
  color: var(--tangle-flow-note);
  font: 10.5px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: nowrap;
}

.tangle-flow-note {
  max-width: 190px;
  color: var(--tangle-flow-note);
  font-size: 0.8rem;
  line-height: 1.35;
}

.tangle-flow .is-away {
  display: none !important;
}

/* Folding: a round button on the node's corner (on hover) folds it to a pill with just its caption. */
.tangle-flow .tangle-flow-fold {
  position: absolute;
  top: -7px;
  right: -7px;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--tangle-flow-rule);
  border-radius: 999px;
  background: var(--tangle-flow-bg);
  color: var(--tangle-flow-note);
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms ease;
}

.tangle-flow-node:hover > .tangle-flow-fold,
.tangle-flow .tangle-flow-fold:focus-visible {
  opacity: 1;
}

.tangle-flow .tangle-flow-fold:hover {
  border-color: var(--tangle-flow-edge);
  color: inherit;
}

.tangle-flow-fold svg,
.tangle-flow-tab svg {
  width: 10px;
  height: 10px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tangle-flow-fold-label {
  display: none;
}

.tangle-flow-node.is-folded {
  flex-direction: row;
  gap: 6px;
  padding: 3px 4px 3px 10px;
  border: 1px dashed color-mix(in srgb, currentColor 30%, transparent);
  border-radius: 999px;
  background: var(--tangle-flow-bg);
}

.tangle-flow-node.is-folded > .tangle-flow-body {
  display: none;
}

.tangle-flow-node.is-folded > .tangle-flow-fold-label {
  display: block;
}

.tangle-flow .tangle-flow-node.is-folded > .tangle-flow-fold {
  position: static;
  border-color: transparent;
  opacity: 1;
}

.tangle-flow-node.is-folded > .tangle-flow-fold svg {
  transform: rotate(-90deg);
}

/* A folded group's pill. */
.tangle-flow-node.is-pill {
  border-style: solid;
  border-color: color-mix(in srgb, currentColor 24%, transparent);
}

.tangle-flow-node.is-pill > .tangle-flow-caption {
  color: inherit;
}

/* The arrows, edge labels and group tabs sit over the nodes, and let the pointer through. */
.tangle-flow-svg,
.tangle-flow-labels,
.tangle-flow-tabs {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  transition: opacity 110ms ease;
}

.tangle-flow-svg {
  z-index: 0;
}

.tangle-flow.is-moving > .tangle-flow-board > :is(.tangle-flow-svg, .tangle-flow-labels, .tangle-flow-tabs) {
  opacity: 0;
}

.tangle-flow-edge,
.tangle-flow-halo,
.tangle-flow-note-arrow,
.tangle-flow-frame {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tangle-flow-edge {
  stroke: var(--tangle-flow-edge);
  stroke-width: 1.3;
}

/* The gap an arrow leaves in the ones drawn before it, where it crosses them. */
.tangle-flow-halo {
  stroke: var(--tangle-flow-bg);
  stroke-width: 6;
  stroke-linecap: butt;
  stroke-dasharray: 0 4 1000000;
}

.tangle-flow-head {
  fill: var(--tangle-flow-edge);
  stroke: var(--tangle-flow-edge);
  stroke-width: 0.8;
  stroke-linejoin: round;
}

.tangle-flow-note-arrow {
  stroke: var(--tangle-flow-note);
  stroke-width: 1.2;
}

.tangle-flow-frame {
  stroke: var(--tangle-flow-rule);
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

.tangle-flow-label {
  position: absolute;
  color: var(--tangle-flow-note);
  font: 10.5px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: nowrap;
}

.tangle-flow .tangle-flow-tab {
  position: absolute;
  transform: translate(-100%, -50%);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 1px 8px 1px 5px;
  border: 1px solid var(--tangle-flow-rule);
  border-radius: 999px;
  background: var(--tangle-flow-bg);
  color: var(--tangle-flow-note);
  font: 10.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: nowrap;
  cursor: pointer;
  pointer-events: auto;
}

.tangle-flow .tangle-flow-tab:hover {
  border-color: var(--tangle-flow-edge);
  color: inherit;
}

.tangle-flow-error {
  margin: 0.5em 0;
  color: var(--tangle-error);
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
}

/* Click-to-type editor ---------------------------------------------------- */

.tangle-editor {
  --tangle-c: var(--tangle-color, var(--tangle-accent));
  position: absolute;
  z-index: 1000;
  width: 6em;
  transform: translateX(-50%);
  padding: 5px 8px;
  border: 1px solid var(--tangle-c);
  border-radius: 6px;
  background: var(--tangle-surface);
  color: var(--tangle-c);
  font: 600 0.9rem/1.2 ui-sans-serif, system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  text-align: center;
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tangle-c) 18%, transparent), 0 6px 20px rgb(0 0 0 / 0.15);
}

.tangle-editor.is-text {
  width: 12em;
  text-align: left;
}

.tangle-editor.is-invalid {
  border-color: var(--tangle-error);
  color: var(--tangle-error);
}

/* The menu of a <t-select>: a search field over the options. */
.tangle-menu {
  --tangle-c: var(--tangle-color, var(--tangle-accent));
  position: absolute;
  z-index: 1000;
  box-sizing: border-box;
  width: 14em;
  max-width: calc(100vw - 16px);
  transform: translateX(-50%);
  border: 1px solid var(--tangle-c);
  border-radius: 6px;
  background: var(--tangle-surface);
  font: 0.9rem/1.3 ui-sans-serif, system-ui, sans-serif;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tangle-c) 18%, transparent), 0 6px 20px rgb(0 0 0 / 0.15);
  overflow: hidden;
}

.tangle-menu input {
  box-sizing: border-box;
  width: 100%;
  margin: 0;
  padding: 6px 9px;
  border: 0;
  border-bottom: 1px solid color-mix(in srgb, var(--tangle-c) 30%, transparent);
  background: transparent;
  color: inherit;
  font: inherit;
  outline: none;
}

.tangle-menu ul {
  position: relative; /* the rows' offsetParent, for scrolling the highlight into view */
  max-height: 16em;
  margin: 0;
  padding: 4px 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
}

.tangle-menu li {
  margin: 0;
  padding: 3px 9px;
  cursor: pointer;
}

.tangle-menu li.is-highlighted {
  background: color-mix(in srgb, var(--tangle-c) var(--tangle-soft), transparent);
}

.tangle-menu li[aria-selected="true"] {
  color: var(--tangle-c);
  font-weight: 600;
}

.tangle-menu .tangle-menu-empty {
  cursor: default;
  opacity: 0.6;
}

/* Vega -------------------------------------------------------------------- */

t-vega,
t-obsplot,
t-graph,
t-jsxgraph {
  display: block;
  margin: 1rem 0;
}

.tangle-vega {
  width: 100%;
}

.tangle-vega.is-loading,
.tangle-obsplot.is-loading,
.tangle-graph.is-loading,
.tangle-jsxgraph.is-loading {
  display: grid;
  place-items: center;
  min-height: 8em;
  color: color-mix(in srgb, currentColor var(--tangle-chart-text), transparent);
  font: var(--tangle-chart-font);
}

/* Vega's tooltip, which lives at the end of <body>. */
#vg-tooltip-element.tangle-theme {
  padding: 6px 9px;
  border: 1px solid color-mix(in srgb, currentColor 15%, transparent);
  border-radius: 6px;
  background: var(--tangle-surface);
  color: inherit;
  font: var(--tangle-chart-font);
  font-variant-numeric: tabular-nums;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.15);
}

/* The tooltip is a <table>: undo the page's table styles. */
#vg-tooltip-element.tangle-theme table {
  width: auto;
  margin: 0;
  border-collapse: collapse;
  font: inherit;
}

#vg-tooltip-element.tangle-theme td {
  padding: 1px 0;
  border: 0;
  vertical-align: baseline;
}

#vg-tooltip-element.tangle-theme td.key {
  padding-right: 10px;
  color: inherit;
  opacity: 0.6;
}

/* Observable Plot --------------------------------------------------------- */

/* Plot draws in currentColor, so only its background (behind tips and halos) needs the theme. */
t-obsplot svg,
t-obsplot figure {
  --plot-background: var(--tangle-surface);
}

t-obsplot g[aria-label$="tick label"],
t-obsplot g[aria-label$="axis label"] {
  opacity: var(--tangle-chart-text);
}

/* Plot wraps a chart with a legend or title in a <figure>. */
t-obsplot figure {
  margin: 0;
}

/* <t-graph> --------------------------------------------------------------- */

/* The svg is as wide as the element: hidden overflow keeps it from widening the page while it resizes. */
.tangle-graph {
  position: relative;
  overflow: hidden;
  font: var(--tangle-chart-font);
  user-select: none;
  -webkit-user-select: none;
}

.tangle-graph-svg {
  display: block;
}

/* An edge is a line, and an arrowhead when the graph is directed. --edge is its color. */
.tangle-graph-line {
  fill: none;
  vector-effect: non-scaling-stroke; /* the same width however much the graph is scaled to fit */
  stroke: var(--edge, color-mix(in srgb, currentColor 35%, transparent));
}

.tangle-graph-head {
  fill: var(--edge, color-mix(in srgb, currentColor 35%, transparent));
}

.tangle-graph-edge-label {
  fill: color-mix(in srgb, currentColor var(--tangle-chart-text), transparent);
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--tangle-surface);
  stroke-width: 3px;
  stroke-linejoin: round;
  pointer-events: none;
}

/* A node is a circle with its name underneath. --node is its color. */
.tangle-graph-node {
  cursor: grab;
  outline: none;
}

.tangle-graph-node:active {
  cursor: grabbing;
}

.tangle-graph-node circle {
  fill: var(--node, var(--tangle-accent));
  vector-effect: non-scaling-stroke;
  stroke: var(--tangle-surface);
  stroke-width: 1.5px;
}

.tangle-graph-label {
  fill: currentColor;
  text-anchor: middle;
  paint-order: stroke;
  stroke: var(--tangle-surface);
  stroke-width: 3px;
  stroke-linejoin: round;
  pointer-events: none;
}

/* The picked node, and the one with keyboard focus, get a ring. */
.tangle-graph-node.is-picked circle,
.tangle-graph-node:focus-visible circle {
  stroke: currentColor;
  stroke-width: 2.5px;
}

.tangle-graph-node.is-picked .tangle-graph-label {
  font-weight: 600;
}

.tangle-graph-tooltip {
  position: absolute;
  z-index: 1;
  padding: 6px 9px;
  border: 1px solid color-mix(in srgb, currentColor 15%, transparent);
  border-radius: 6px;
  background: var(--tangle-surface);
  pointer-events: none;
  white-space: nowrap;
}

.tangle-graph-tooltip[hidden] {
  display: none;
}

.tangle-graph-tooltip .key {
  opacity: 0.6;
}

/* With zoom: the background pans, there's a reset button, and a plain scroll shows a hint. */
t-graph[zoom] .tangle-graph-svg {
  cursor: grab;
}

t-graph[zoom] .tangle-graph-svg:active {
  cursor: grabbing;
}

.tangle-graph-reset {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 2px 8px;
  border: 1px solid color-mix(in srgb, currentColor 20%, transparent);
  border-radius: 6px;
  background: var(--tangle-surface);
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.tangle-graph-reset:hover {
  border-color: color-mix(in srgb, currentColor 45%, transparent);
}

.tangle-graph-reset[hidden],
.tangle-graph-hint[hidden] {
  display: none;
}

.tangle-graph-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--tangle-surface) 70%, transparent);
  pointer-events: none;
}

/* JSXGraph ---------------------------------------------------------------- */

/* The board takes its size from this box. Set a different aspect-ratio or height to change it. */
.tangle-jsxgraph {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  overflow: hidden;
  font: var(--tangle-chart-font);
  font-variant-numeric: tabular-nums;
  touch-action: none;
  user-select: none;
}

.tangle-jsxgraph .JXGtext {
  margin: 0;
  padding: 0;
  font-family: inherit;
  white-space: nowrap;
}

/* While a point is held, the hand stays closed wherever the pointer goes. */
:root.tangle-grabbing,
:root.tangle-grabbing * {
  cursor: grabbing !important;
}

/* Debugging --------------------------------------------------------------- */

t-debug {
  display: block;
  overflow-x: auto;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.t-debug-scope {
  margin: 10px 0 4px;
  font-weight: 600;
}

.t-debug-graph {
  display: block;
  overflow: visible;
  margin: 4px 0 8px;
}

.t-debug-edge {
  fill: none;
  stroke: color-mix(in srgb, currentColor 30%, transparent);
  stroke-width: 1.5;
  transition: opacity 120ms;
}

.t-debug-edge.is-hot {
  stroke: var(--tangle-accent);
  stroke-width: 2;
}

.t-debug-edge.is-faded {
  opacity: 0.35;
}

.t-debug-node {
  cursor: pointer;
}

.t-debug-node rect {
  fill: var(--tangle-surface);
  stroke: color-mix(in srgb, currentColor 30%, transparent);
  stroke-width: 1.5;
}

/* Values the reader sets have the color of their variable; formulas are plain. */
.t-debug-node.is-value rect {
  stroke: var(--tangle-color, var(--tangle-accent));
}

.t-debug-node.is-fetch rect,
.t-debug-node.is-codecell rect,
.t-debug-node.is-loading rect {
  stroke: var(--tangle-accent);
  stroke-dasharray: 4 3;
}

.t-debug-node.is-loading {
  opacity: var(--tangle-stale);
}

.t-debug-node.is-unset rect,
.t-debug-node.is-error rect {
  stroke: var(--tangle-error);
}

.t-debug-node.is-hot rect {
  fill: color-mix(in srgb, var(--tangle-accent) var(--tangle-soft), var(--tangle-surface));
  stroke-width: 2;
}

.t-debug-node.is-changed rect {
  animation: t-debug-pulse 700ms ease-out;
}

@keyframes t-debug-pulse {
  from {
    fill: color-mix(in srgb, var(--tangle-accent) 35%, var(--tangle-surface));
  }
}

.t-debug-node text {
  fill: currentColor;
  font: inherit;
}

.t-debug-node .t-debug-node-name {
  font-weight: 600;
}

.t-debug-node.is-value .t-debug-node-name {
  fill: var(--tangle-color, var(--tangle-accent));
}

.t-debug-node .t-debug-node-value {
  font-size: 11px;
  fill-opacity: 0.65;
}

.t-debug-node.is-unset .t-debug-node-value,
.t-debug-node.is-error .t-debug-node-value {
  fill: var(--tangle-error);
  fill-opacity: 1;
}

.t-debug-details summary {
  cursor: pointer;
  opacity: 0.6;
}

.t-debug-table {
  width: 100%;
  margin-top: 4px;
  border-collapse: collapse;
}

.t-debug-table :is(th, td) {
  padding: 3px 10px 3px 0;
  border-bottom: 1px solid color-mix(in srgb, currentColor 10%, transparent);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.t-debug-table thead th {
  font-weight: 600;
  opacity: 0.6;
}

.t-debug-table .t-debug-scope {
  padding-top: 10px;
  font-weight: 600;
}

.t-debug-table tr.is-hot td {
  background: color-mix(in srgb, var(--tangle-accent) var(--tangle-soft), transparent);
}

.t-debug-name {
  color: var(--tangle-color, inherit);
}

.t-debug-kind {
  margin-left: 6px;
  color: color-mix(in srgb, currentColor var(--tangle-muted), transparent);
}

.t-debug-kind.is-unset,
.t-debug-value.is-error {
  color: var(--tangle-error);
}

.t-debug-kind.is-loading {
  color: var(--tangle-accent);
}

.t-debug-value {
  max-width: 32ch;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.t-debug-table tr.is-changed .t-debug-value {
  animation: t-debug-flash 700ms ease-out;
}

@keyframes t-debug-flash {
  from {
    background: color-mix(in srgb, var(--tangle-accent) 30%, transparent);
  }
}

/* The elements that show the variable under the pointer in a <t-debug>. */
.t-debug-target {
  outline: 2px dashed var(--tangle-accent);
  outline-offset: 2px;
  border-radius: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .t-debug-table tr.is-changed .t-debug-value,
  .t-debug-node.is-changed rect {
    animation: none;
  }
}
