/* =========================================================================
   Data type animations
   Scoped under `.dta`. The whole box is dark, like the page's code blocks:
   a console on top, and below it the stage where the data is drawn. Two
   colors carry meaning in every scene: red marks what a command wrote, and
   blue marks what it read. Every color of the stage is a custom property.
   ========================================================================= */

.dta {
  --dta-ink: #e6edf5;
  --dta-muted: #9eaec2;
  --dta-faint: #687a92;
  --dta-line: #1e2a42;
  --dta-line-strong: #364663;
  --dta-tint: #18233b;                        /* a card's title bar */
  --dta-stage: #0b1322;                       /* behind the drawing */
  --dta-surface: #141e34;                     /* cells, cards, and labels */
  --dta-wash: rgba(255, 255, 255, .04);       /* a faint fill for a region */
  --dta-on: var(--dta-ink);                   /* a bit set to 1, a bar */
  --dta-on-text: var(--dta-stage);
  --dta-write: #ff5c50;
  --dta-write-bg: rgba(255, 68, 56, .2);
  --dta-write-ring: rgba(255, 92, 80, .2);
  --dta-write-text: var(--dta-stage);         /* text on a solid --dta-write fill */
  --dta-read: #8f97ff;
  --dta-read-bg: rgba(110, 118, 255, .26);
  --dta-read-ring: rgba(143, 151, 255, .22);
  --dta-read-wash: rgba(143, 151, 255, .13);
  --dta-read-text: var(--dta-stage);
  --dta-no: #f2b84b;
  --dta-no-bg: rgba(242, 184, 75, .14);
  --dta-str: #e6b196;                         /* JSON strings and numbers, as the console colors them */
  --dta-num: #b5cea8;
  --dta-mono: "Space Mono", "SF Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  container-type: inline-size;
  margin: 1.5rem 0;
  border: 1px solid #0f172a;
  border-radius: 8px;
  overflow: hidden;
  background: var(--dta-stage);
  color: var(--dta-ink);
}
.dta *, .dta *::before, .dta *::after { box-sizing: border-box; }

/* The room each animation needs, so the page below doesn't jump when the script draws it. These are
   the heights in the widest text column. In a narrower column a long command wraps and the box grows. */
.dta[data-dta="string"], .dta[data-dta="bitmap"], .dta[data-dta="array"] { min-height: 211px; }
.dta[data-dta="list"] { min-height: 231px; }
.dta[data-dta="bitfield"], .dta[data-dta="count-min-sketch"], .dta[data-dta="t-digest"] { min-height: 239px; }
.dta[data-dta="bloom"] { min-height: 243px; }
.dta[data-dta="hyperloglog"] { min-height: 247px; }
.dta[data-dta="cuckoo"] { min-height: 249px; }
.dta[data-dta="hash"], .dta[data-dta="json"] { min-height: 263px; }
.dta[data-dta="set"], .dta[data-dta="top-k"] { min-height: 275px; }
.dta[data-dta="sorted-set"] { min-height: 283px; }
.dta[data-dta="stream"] { min-height: 295px; }
.dta[data-dta="vector-set"] { min-height: 313px; }
.dta[data-dta="timeseries"] { min-height: 333px; }
.dta[data-dta="geospatial"] { min-height: 353px; }

/* ---- console ---- */
.dta-console {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 12px 12px 12px 16px;
  background: #0f172a; color: #fafafa;
  font: 13px/20px var(--dta-mono);
}
.dta-term { flex: 1 1 0; min-width: 0; }
.dta-cmd { min-height: 20px; padding-left: 2ch; text-indent: -2ch; white-space: pre-wrap; overflow-wrap: anywhere; }
.dta-prompt { color: #64748b; user-select: none; }
.dta-reply { min-height: 20px; color: #cbd5e1; white-space: pre-wrap; overflow-wrap: anywhere; }
/* The caret takes no room in the line, so it can't wrap to a line of its own after a command that fills one. */
.dta-caret { position: relative; display: inline-block; width: 0; height: 1em; vertical-align: -.15em; }
.dta-caret::after {
  content: ""; position: absolute; left: 2px; top: 0; width: .55em; height: 100%;
  background: #cbd5e1; animation: dta-blink 1.1s steps(1) infinite;
}
.dta.is-typing .dta-caret::after, .dta.is-paused .dta-caret::after { animation: none; }
@keyframes dta-blink { 50% { opacity: 0; } }
.dta .hl-cmd { color: #c4a7ff; }
.dta .hl-str { color: #e6b196; }
.dta .hl-num { color: #b5cea8; }
.dta .hl-faint { color: #8493a8; }
.dta .hl-ok { color: #8cd7b9; }

.dta-ctl { flex: none; display: flex; align-items: center; gap: 10px; height: 20px; }
.dta-dots { display: flex; gap: 4px; }
.dta-dot { position: relative; width: 14px; height: 4px; padding: 0; border: 0; border-radius: 2px; background: #334155; cursor: pointer; }
.dta-dot::after { content: ""; position: absolute; inset: -9px -2px; }   /* a taller target than the bar */
.dta-dot.is-done { background: #64748b; }
.dta-dot.is-on { background: #fafafa; }
.dta-play {
  display: grid; place-items: center; width: 24px; height: 24px; padding: 0;
  border: 1px solid #334155; border-radius: 6px; background: transparent; color: #cbd5e1; cursor: pointer;
}
.dta-play svg { fill: currentColor; }
.dta-play:hover { border-color: #64748b; color: #fff; }
.dta-dot:focus-visible, .dta-play:focus-visible { outline: 2px solid #8b93ff; outline-offset: 2px; }
@container (max-width: 520px) {
  .dta-console { flex-direction: column-reverse; align-items: stretch; gap: 8px; padding-top: 10px; }
  .dta-ctl { justify-content: flex-end; }
}

/* ---- stage ---- */
.dta-stage { padding: 14px 14px 12px; border-top: 1px solid #1e293b; }
.dta-canvas { position: relative; display: flex; align-items: center; justify-content: center; height: 140px; }
.dta-note {
  margin-top: 10px; min-height: 20px; text-align: center;
  font-size: 13.5px; line-height: 20px; color: var(--dta-muted);
  opacity: 0; transition: opacity .25s;
}
.dta-note.is-on { opacity: 1; }

/* ---- marks: what a step wrote, read, or looked for and didn't find ---- */
.dta .is-write { border-color: var(--dta-write); background-color: var(--dta-write-bg); box-shadow: 0 0 0 2px var(--dta-write-ring); }
.dta .is-read { border-color: var(--dta-read); background-color: var(--dta-read-bg); box-shadow: 0 0 0 2px var(--dta-read-ring); }
.dta .is-no { border-color: var(--dta-no); border-style: dashed; background-color: var(--dta-no-bg); }
.dta .is-dim { opacity: .35; }

/* ---- shared pieces ---- */
.dta-col { display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 100%; }
.dta-wide { width: 100%; }
.dta-key { font: 11.5px/16px var(--dta-mono); color: var(--dta-muted); white-space: nowrap; }
.dta-cell {
  padding: 5px 9px; border: 1px solid var(--dta-line-strong); border-radius: 6px; background: var(--dta-surface);
  font: 12.5px/18px var(--dta-mono); text-align: center; white-space: nowrap;
  transition: background-color .3s, border-color .3s, box-shadow .3s;
}
.dta-slot { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.dta-idx { font: 10px/12px var(--dta-mono); color: var(--dta-faint); white-space: nowrap; }

.dta-card { max-width: 100%; border: 1px solid var(--dta-line-strong); border-radius: 8px; overflow: hidden; background: var(--dta-surface); }
.dta-card-h { padding: 4px 10px; border-bottom: 1px solid var(--dta-line-strong); background: var(--dta-tint); font: 11.5px/16px var(--dta-mono); color: var(--dta-muted); }
.dta-r {
  display: grid; grid-template-columns: var(--dta-cols); align-items: center; column-gap: 10px;
  height: 27px; padding: 0 10px; border: solid transparent; border-width: 0 0 1px 2px; border-bottom-color: var(--dta-line);
  font: 12.5px/18px var(--dta-mono); white-space: nowrap;
  transition: background-color .3s, border-color .3s;
}
.dta-r.is-write, .dta-r.is-read, .dta-r.is-no { box-shadow: none; border-style: solid; }
.dta-r.is-write { border-color: transparent transparent var(--dta-line) var(--dta-write); }
.dta-r.is-read { border-color: transparent transparent var(--dta-line) var(--dta-read); }
.dta-r.is-no { border-color: transparent transparent var(--dta-line) var(--dta-no); }
.dta-f, .dta-rank { color: var(--dta-faint); }
.dta-m, .dta-v { display: inline-block; overflow: hidden; text-overflow: ellipsis; }

/* ---- string ---- */
.dta-kv { display: grid; grid-template-columns: auto auto auto; align-items: center; justify-items: start; gap: 12px 10px; }
.dta-kv .dta-key { justify-self: end; font-size: 12.5px; color: var(--dta-ink); }
.dta-arrow { color: var(--dta-faint); }

/* ---- list ---- */
.dta-ends { display: flex; align-items: flex-start; gap: 10px; }
.dta-end { font: 10px/30px var(--dta-mono); letter-spacing: .5px; text-transform: uppercase; color: var(--dta-faint); }
.dta-list { display: flex; justify-content: center; gap: 6px; width: 204px; min-height: 46px; }
.dta-list .dta-cell { width: 64px; padding-left: 0; padding-right: 0; }

/* ---- stream ---- */
.dta-stream .dta-id { color: var(--dta-muted); }
@container (max-width: 520px) {
  .dta-stream .dta-r { font-size: 11px; column-gap: 8px; padding: 0 8px; }
  .dta-id-start { display: none; }
  .dta-id::before { content: "\2026"; }
}

/* ---- bitmap ---- */
.dta-bits { display: flex; justify-content: center; gap: 3px; width: 100%; }
.dta-bitslot { flex: 1 1 0; max-width: 30px; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.dta-bitslot:nth-child(9) { margin-left: 8px; }   /* a gap between the two bytes */
.dta-bit {
  width: 100%; height: 30px; border: 1px solid var(--dta-line-strong); border-radius: 5px; background: var(--dta-surface);
  font: 12.5px/28px var(--dta-mono); text-align: center; color: var(--dta-faint);
  transition: background-color .3s, border-color .3s, box-shadow .3s, color .3s;
}
.dta-bit.is-on { background: var(--dta-on); border-color: var(--dta-on); color: var(--dta-on-text); }
.dta-bit.is-on.is-write { background: var(--dta-write); border-color: var(--dta-write); color: var(--dta-write-text); }
.dta-bit.is-on.is-read { background: var(--dta-read); border-color: var(--dta-read); color: var(--dta-read-text); }

/* ---- bitfield ---- */
.dta-bfs { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px 16px; }
.dta-bf {
  display: grid; grid-template-columns: auto 1fr; align-items: baseline; gap: 6px 10px;
  padding: 8px 10px; border: 1px solid var(--dta-line-strong); border-radius: 8px; background: var(--dta-surface);
  transition: background-color .3s, border-color .3s, box-shadow .3s;
}
.dta-bf-l { font: 11.5px/16px var(--dta-mono); color: var(--dta-muted); }
.dta-bf-v { font: 700 15px/18px var(--dta-mono); text-align: right; }
.dta-bf-bits { grid-column: 1 / -1; display: flex; gap: 1px; }
.dta-bf-bits i { width: 4px; height: 12px; border-radius: 1px; background: var(--dta-line); }
.dta-bf-bits i:nth-child(8n + 1):not(:first-child) { margin-left: 3px; }
.dta-bf-bits i.is-on { background: var(--dta-on); }

/* ---- JSON ---- */
.dta-json { width: 300px; }
.dta-json-b { min-height: 106px; padding: 6px 10px; font: 12px/19px var(--dta-mono); white-space: pre; }
.dta-js, .dta-jn { display: inline-block; border-radius: 3px; transition: background-color .3s, box-shadow .3s; }
.dta-js { color: var(--dta-str); }
.dta-jn { color: var(--dta-num); }
@container (max-width: 400px) { .dta-json-b { font-size: 11px; } }

/* ---- array ---- */
.dta-arr { display: flex; justify-content: center; gap: 6px; min-height: 46px; }
.dta-gap { border-style: dashed; color: var(--dta-faint); }
@container (max-width: 400px) {
  .dta-arr { gap: 4px; }
  .dta-arr .dta-cell { padding: 5px 6px; font-size: 11.5px; }
}

/* ---- HyperLogLog ---- */
.dta-hll { display: flex; justify-content: center; gap: 12px; width: 100%; }
.dta-sk { flex: 1 1 0; min-width: 0; max-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.dta-sk-in { position: relative; align-self: stretch; height: 22px; }
.dta-sk-item {
  position: absolute; left: 50%; top: 0; transform: translate(-50%, 0); opacity: 0;
  padding: 1px 7px; border: 1px solid var(--dta-line-strong); border-radius: 6px; background: var(--dta-surface);
  font: 11.5px/18px var(--dta-mono); white-space: nowrap;
}
.dta-sk-box {
  display: flex; align-items: flex-end; justify-content: center; gap: 2px; width: 100%; max-width: 104px; height: 50px; padding: 5px;
  border: 1px solid var(--dta-line-strong); border-radius: 8px; background: var(--dta-surface);
  transition: background-color .3s, border-color .3s, box-shadow .3s;
}
.dta-sk-box i { flex: 1 1 0; height: 3px; border-radius: 1px; background: var(--dta-on); transition: height .35s cubic-bezier(.2, .7, .2, 1); }
.dta-sk .dta-key { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.dta-sk-n { font: 700 13px/16px var(--dta-mono); color: var(--dta-read); }
@container (max-width: 400px) {
  .dta-hll { gap: 8px; }
  .dta-sk .dta-key { font-size: 10px; }
}

/* ---- count-min sketch ---- */
.dta-cms { display: grid; grid-template-columns: repeat(8, minmax(0, 40px)); gap: 3px; max-width: 100%; }
.dta-ctr {
  height: 26px; border: 1px solid var(--dta-line-strong); border-radius: 5px; background: var(--dta-surface);
  font: 11.5px/24px var(--dta-mono); text-align: center;
  transition: background-color .3s, border-color .3s, box-shadow .3s;
}
.dta-ctr.is-zero { color: var(--dta-faint); }
/* The smallest of the counters a query read, which is the estimate it returns. */
.dta-ctr.is-read.is-least { background-color: var(--dta-read); color: var(--dta-read-text); transition: background-color .3s, border-color .3s, box-shadow .3s, color .3s; }

/* ---- SVG scenes ---- */
.dta-svg { display: block; overflow: visible; }
.dta-svg * { transform-box: fill-box; transform-origin: center; }
.dta-svg text { font: 11px var(--dta-mono); fill: var(--dta-muted); }
.dta-grid { stroke: var(--dta-line); }
.dta-axis { fill: none; stroke: var(--dta-line-strong); }

.dta-chip rect { fill: var(--dta-surface); stroke: var(--dta-line-strong); transition: fill .3s, stroke .3s; }
.dta-chip text { fill: var(--dta-ink); }
.dta-chip.is-write rect { fill: var(--dta-write-bg); stroke: var(--dta-write); }
.dta-chip.is-read rect { fill: var(--dta-read-bg); stroke: var(--dta-read); }
.dta-chip.is-no rect { fill: var(--dta-no-bg); stroke: var(--dta-no); stroke-dasharray: 3 2; }

/* set */
.dta-ring { fill: var(--dta-wash); stroke: var(--dta-line-strong); stroke-width: 1.5; }
.dta-lens { fill: transparent; stroke: transparent; stroke-width: 1.5; transition: fill .3s, stroke .3s; }
.dta-lens.is-read { fill: var(--dta-read-bg); stroke: var(--dta-read); }

/* geospatial */
.dta-pin circle { fill: var(--dta-ink); stroke: var(--dta-stage); stroke-width: 1.5; transition: fill .3s; }
.dta-place text { fill: var(--dta-ink); transition: fill .3s; paint-order: stroke; stroke: var(--dta-stage); stroke-width: 3px; stroke-linejoin: round; }
.dta-place.is-write .dta-pin circle { fill: var(--dta-write); }
.dta-place.is-read .dta-pin circle, .dta-place.is-read text { fill: var(--dta-read); }
.dta-place { transition: opacity .3s; }
.dta-range { fill: var(--dta-read-wash); stroke: var(--dta-read); stroke-width: 1.5; stroke-dasharray: 4 3; }
.dta-center circle { fill: var(--dta-read); }
.dta-center path { stroke: var(--dta-read); stroke-width: 1.5; }

/* time series */
.dta-ts-line { fill: none; stroke: var(--dta-ink); stroke-width: 1.5; stroke-linejoin: round; }
.dta-ts-dot { fill: var(--dta-ink); stroke: var(--dta-stage); stroke-width: 1.5; transition: fill .3s; }
.dta-ts-dot.is-write { fill: var(--dta-write); }
.dta-ts-bucket rect { fill: var(--dta-read-wash); }
.dta-ts-bucket line { stroke: var(--dta-read); stroke-width: 2; stroke-dasharray: 5 3; }
.dta-ts-bucket text { fill: var(--dta-read); }

/* vector set */
.dta-vec { transition: opacity .3s; }
.dta-vec line { stroke: var(--dta-line-strong); stroke-width: 1.5; transition: stroke .3s; }
.dta-vec circle { fill: var(--dta-ink); transition: fill .3s; }
.dta-vec text { fill: var(--dta-ink); transition: fill .3s; }
.dta-vec.is-write circle { fill: var(--dta-write); }
.dta-vec.is-read line { stroke: var(--dta-read); }
.dta-vec.is-read circle, .dta-vec.is-read text { fill: var(--dta-read); }
/* An element's attributes keep their own color until a search reads them. */
.dta-vec .dta-attr, .dta-vec.is-read .dta-attr { fill: var(--dta-str); font-size: 10px; }
.dta-vec .dta-attr.is-read { fill: var(--dta-read); }
.dta-query line, .dta-vec.is-query line { stroke: var(--dta-read); stroke-width: 1.5; stroke-dasharray: 4 3; }
.dta-query text { fill: var(--dta-read); }
/* An element's place in a search reply, drawn over the tip of its vector. */
.dta-vrank circle { fill: var(--dta-read); }
.dta-vrank text { fill: var(--dta-read-text); font-size: 10px; font-weight: 700; }

/* Bloom and cuckoo filters */
.dta-box rect { fill: var(--dta-surface); stroke: var(--dta-line-strong); transition: fill .3s, stroke .3s; }
.dta-box text { fill: var(--dta-ink); transition: fill .3s; }
.dta-bloom .dta-box text { fill: var(--dta-faint); }
.dta-box.is-on rect { fill: var(--dta-on); stroke: var(--dta-on); }
.dta-bloom .dta-box.is-on text { fill: var(--dta-on-text); }
.dta-box.is-write rect { stroke: var(--dta-write); fill: var(--dta-write-bg); }
.dta-box.is-read rect { stroke: var(--dta-read); fill: var(--dta-read-bg); }
.dta-box.is-on.is-write rect { fill: var(--dta-write); }
.dta-bloom .dta-box.is-on.is-write text { fill: var(--dta-write-text); }
.dta-box.is-on.is-read rect { fill: var(--dta-read); }
.dta-bloom .dta-box.is-on.is-read text { fill: var(--dta-read-text); }
.dta-box.is-no rect { stroke: var(--dta-no); fill: var(--dta-no-bg); stroke-dasharray: 3 2; }
.dta-probe path { fill: none; stroke-width: 1.5; stroke-dasharray: 1; }
.dta-probe.is-write path { stroke: var(--dta-write); }
.dta-probe.is-read path { stroke: var(--dta-read); }

/* t-digest */
.dta-td-dot { fill: var(--dta-ink); stroke: var(--dta-stage); stroke-width: 1; transition: fill .3s; }
.dta-td-dot.is-read { fill: var(--dta-read); }
.dta-td-split rect { fill: var(--dta-read-wash); }
.dta-td-split line { stroke: var(--dta-read); stroke-width: 1.5; stroke-dasharray: 4 3; }
.dta-td-split text { fill: var(--dta-read); }

@media (prefers-reduced-motion: reduce) {
  .dta-caret::after { animation: none; }
}
