/* ==========================================================================
   RAG Playground "How retrieval-augmented generation works"
   Dependency-free stylesheet. Every selector is namespaced under .ragp-root
   and every class is prefixed `ragp-`, so this cannot leak into a host site.

   Colour has a job here rather than being decoration:
     emerald  the store, and anything retrieved from it
     violet   the question, and everything the question touches
     blue     a negative number in a vector
     orange   a positive number in a vector
   ========================================================================== */

.ragp-root {
  /* ---- palette: the site's dark tokens, restated so the demo stands alone -- */
  --ragp-panel: #0e1115;
  --ragp-surface: #141720;
  --ragp-surface-2: #1c2030;
  --ragp-border: rgba(255, 255, 255, 0.08);
  --ragp-border-strong: rgba(255, 255, 255, 0.16);

  --ragp-text: #e8e4d9;
  --ragp-dim: rgba(232, 228, 217, 0.62);
  --ragp-faint: rgba(232, 228, 217, 0.38);

  --ragp-accent: #3ddc97;
  --ragp-accent-soft: rgba(61, 220, 151, 0.14);
  --ragp-q: #a78bfa;
  --ragp-q-soft: rgba(167, 139, 250, 0.16);
  --ragp-blue: #4d9ee8;
  --ragp-hot: #ff9d4d;

  --ragp-radius: 14px;
  --ragp-radius-sm: 8px;

  --ragp-font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --ragp-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  position: relative;
  box-sizing: border-box;
  width: 100%;
  margin: 0 auto;
  color: var(--ragp-text);
  font-family: var(--ragp-font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-align: left;
}

.ragp-root *,
.ragp-root *::before,
.ragp-root *::after { box-sizing: border-box; }

.ragp-root button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
}

.ragp-root button:disabled { cursor: default; opacity: 0.45; }

.ragp-root input,
.ragp-root textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ==========================================================================
   Panel shell
   ========================================================================== */

.ragp-panel {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(1200px 420px at 50% -10%, rgba(61, 220, 151, 0.075), transparent 70%),
    radial-gradient(900px 500px at 100% 100%, rgba(167, 139, 250, 0.07), transparent 70%),
    var(--ragp-panel);
  border: 1px solid var(--ragp-border);
  border-radius: var(--ragp-radius);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 24px 60px -20px rgba(0, 0, 0, 0.7);
}

/* faint grid texture, so the panel reads as a surface rather than a hole */
.ragp-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.022) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(70% 60% at 50% 40%, #000 40%, transparent 100%);
  -webkit-mask-image: radial-gradient(70% 60% at 50% 40%, #000 40%, transparent 100%);
}

.ragp-panel > * { position: relative; z-index: 1; }

/* ==========================================================================
   Header
   ========================================================================== */

.ragp-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--ragp-border);
}

.ragp-title {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.ragp-title-dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--ragp-accent);
  box-shadow: 0 0 12px var(--ragp-accent);
}

.is-running .ragp-title-dot { animation: ragp-pulse 1.4s ease-in-out infinite; }

@keyframes ragp-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.ragp-title-sub {
  color: var(--ragp-faint);
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ragp-header-spacer { flex: 1 1 auto; }

.ragp-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.ragp-speed {
  display: flex;
  padding: 2px;
  border: 1px solid var(--ragp-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.02);
}

.ragp-speed-btn {
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 11.5px;
  letter-spacing: 0.03em;
  color: var(--ragp-faint);
  transition: color 0.18s, background 0.18s;
}

.ragp-speed-btn:hover { color: var(--ragp-text); }

.ragp-speed-btn.is-on {
  background: var(--ragp-accent-soft);
  color: var(--ragp-accent);
}

.ragp-icon-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--ragp-border);
  border-radius: 8px;
  color: var(--ragp-dim);
  transition: color 0.18s, border-color 0.18s;
}

.ragp-icon-btn:hover { color: var(--ragp-text); border-color: var(--ragp-border-strong); }
.ragp-icon-btn svg { width: 15px; height: 15px; fill: currentColor; }

/* ==========================================================================
   Source phase one
   ========================================================================== */

.ragp-source {
  padding: 16px 18px;
  border-bottom: 1px solid var(--ragp-border);
  transition: opacity 0.3s;
}

/* Once the store exists the big textarea folds away; the summary bar takes
   its place, so the panel is never two input areas deep. */
.ragp-root.is-built .ragp-source { display: none; }
.ragp-summary,
.ragp-query { display: none; }
.ragp-root.is-built .ragp-summary,
.ragp-root.is-built .ragp-query { display: flex; }

.ragp-source-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.ragp-source-label {
  font-size: 11.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ragp-faint);
}

.ragp-counter {
  font-family: var(--ragp-mono);
  font-size: 11.5px;
  color: var(--ragp-faint);
  font-variant-numeric: tabular-nums;
}

.ragp-counter.is-full { color: var(--ragp-hot); }

.ragp-textarea {
  display: block;
  width: 100%;
  min-height: 118px;
  padding: 12px 14px;
  resize: vertical;
  border: 1px solid var(--ragp-border);
  border-radius: var(--ragp-radius-sm);
  background: rgba(255, 255, 255, 0.025);
  font-size: 14px;
  line-height: 1.6;
  outline: none;
  transition: border-color 0.18s, background 0.18s;
}

.ragp-textarea::placeholder { color: var(--ragp-faint); }

.ragp-textarea:focus {
  border-color: rgba(61, 220, 151, 0.45);
  background: rgba(255, 255, 255, 0.04);
}

.ragp-source-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.ragp-source-spacer { flex: 1 1 auto; }

.ragp-chip {
  padding: 5px 11px;
  border: 1px solid var(--ragp-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.02);
  font-size: 12.5px;
  color: var(--ragp-dim);
  transition: color 0.18s, border-color 0.18s, background 0.18s;
}

.ragp-chip:hover:not(:disabled) {
  color: var(--ragp-text);
  border-color: var(--ragp-border-strong);
  background: rgba(255, 255, 255, 0.05);
}

.ragp-run {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--ragp-accent);
  color: #05231a;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  transition: filter 0.18s, transform 0.12s;
}

.ragp-run:hover:not(:disabled) { filter: brightness(1.09); }
.ragp-run:active:not(:disabled) { transform: translateY(1px); }
.ragp-run svg { width: 14px; height: 14px; fill: currentColor; }

.ragp-run-ask { background: var(--ragp-q); color: #1b0f3d; }

/* ---- built summary ---- */

.ragp-summary {
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 18px;
  border-bottom: 1px solid var(--ragp-border);
  background: rgba(61, 220, 151, 0.045);
}

.ragp-summary-text {
  flex: 1 1 auto;
  font-size: 13px;
  color: var(--ragp-dim);
}

.ragp-summary-text b { color: var(--ragp-accent); font-weight: 600; }

.ragp-summary-hint { color: var(--ragp-faint); }

.ragp-ghost-btn {
  flex: none;
  padding: 5px 12px;
  border: 1px solid var(--ragp-border);
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--ragp-dim);
  transition: color 0.18s, border-color 0.18s;
}

.ragp-ghost-btn:hover { color: var(--ragp-text); border-color: var(--ragp-border-strong); }

/* ---- query row ---- */

.ragp-query {
  flex-direction: column;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--ragp-border);
}

.ragp-query-row {
  display: flex;
  gap: 10px;
}

.ragp-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--ragp-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.025);
  font-size: 14.5px;
  outline: none;
  transition: border-color 0.18s, background 0.18s;
}

.ragp-input::placeholder { color: var(--ragp-faint); }

.ragp-input:focus {
  border-color: rgba(167, 139, 250, 0.5);
  background: rgba(255, 255, 255, 0.04);
}

.ragp-suggestions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
}

.ragp-suggestions-label {
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ragp-faint);
  margin-right: 2px;
}

/* ==========================================================================
   Stage rail
   ========================================================================== */

.ragp-rail {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 18px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--ragp-border);
}

.ragp-rail::-webkit-scrollbar { display: none; }

.ragp-rail-step {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: none;
  padding: 5px 12px 5px 6px;
  border: 1px solid var(--ragp-border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--ragp-faint);
  user-select: none;
  transition: color 0.25s, border-color 0.25s, background 0.25s, transform 0.12s;
}

/* Locked until the run that feeds it has happened. */
.ragp-rail-step[aria-disabled="true"] { cursor: default; opacity: 0.55; }

.ragp-rail-step.is-playable { cursor: pointer; }

.ragp-rail-step.is-playable:hover {
  color: var(--ragp-text);
  border-color: var(--ragp-border-strong);
  background: rgba(255, 255, 255, 0.05);
}

.ragp-rail-step.is-playable:active { transform: translateY(1px); }

.ragp-rail-step.is-playable:focus-visible {
  outline: 2px solid var(--ragp-accent);
  outline-offset: 2px;
}

/* The replay glyph only appears on a step you can actually replay, and only
   when the pointer is on it the rail is a progress indicator first. */
.ragp-rail-step.is-playable::after {
  content: "BA";
  width: 0;
  overflow: hidden;
  font-size: 12px;
  opacity: 0;
  transition: width 0.2s, opacity 0.2s, margin 0.2s;
}

.ragp-rail-step.is-playable:hover::after,
.ragp-rail-step.is-playable:focus-visible::after {
  width: 11px;
  margin-left: 1px;
  opacity: 0.8;
}

.ragp-rail-hint {
  flex: none;
  margin-left: 4px;
  font-size: 11px;
  color: var(--ragp-faint);
  opacity: 0;
  transition: opacity 0.4s;
  pointer-events: none;
  white-space: nowrap;
}

.ragp-rail-hint.is-on { opacity: 1; }

/* Query stages are the visitor's half of the pipeline, and are tinted violet
   to say so before they are ever reached. */
.ragp-rail-step[data-phase="query"] .ragp-rail-num { background: rgba(167, 139, 250, 0.1); }

.ragp-rail-num {
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  font-family: var(--ragp-mono);
  font-size: 10.5px;
  transition: background 0.25s, color 0.25s;
}

.ragp-rail-step.is-done {
  color: var(--ragp-dim);
  border-color: rgba(61, 220, 151, 0.28);
}

.ragp-rail-step.is-done .ragp-rail-num {
  background: var(--ragp-accent-soft);
  color: var(--ragp-accent);
}

.ragp-rail-step.is-active {
  color: var(--ragp-text);
  border-color: rgba(61, 220, 151, 0.6);
  background: var(--ragp-accent-soft);
}

.ragp-rail-step.is-active .ragp-rail-num {
  background: var(--ragp-accent);
  color: #05231a;
}

.ragp-rail-step[data-phase="query"].is-active {
  border-color: rgba(167, 139, 250, 0.6);
  background: var(--ragp-q-soft);
}

.ragp-rail-step[data-phase="query"].is-active .ragp-rail-num {
  background: var(--ragp-q);
  color: #1b0f3d;
}

.ragp-rail-step[data-phase="query"].is-done { border-color: rgba(167, 139, 250, 0.28); }
.ragp-rail-step[data-phase="query"].is-done .ragp-rail-num {
  background: var(--ragp-q-soft);
  color: var(--ragp-q);
}

/* ==========================================================================
   Stage viewport and scene shell
   ========================================================================== */

.ragp-stage {
  position: relative;
  min-height: 420px;
  padding: 20px 18px 22px;
}

.ragp-scene {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.34s ease, transform 0.34s ease;
}

.ragp-scene.is-in { opacity: 1; transform: none; }

.ragp-scene-head { margin-bottom: 16px; }

.ragp-scene-title {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.005em;
}

.ragp-scene-note {
  margin: 0;
  max-width: 78ch;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ragp-dim);
}

.ragp-scene-body { position: relative; }

.ragp-mini-label {
  margin: 16px 0 8px;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ragp-faint);
}

.ragp-scene-body > .ragp-mini-label:first-child { margin-top: 0; }

/* ==========================================================================
   Footer
   ========================================================================== */

.ragp-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 11px 18px;
  border-top: 1px solid var(--ragp-border);
  font-size: 11.5px;
  color: var(--ragp-faint);
}

.ragp-status {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ragp-dim);
  font-family: var(--ragp-mono);
  letter-spacing: 0.02em;
}

.ragp-credit {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ragp-status:not(:empty)::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ragp-accent);
}

/* ==========================================================================
   Idle scene
   ========================================================================== */

.ragp-idle {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1px;
  background: var(--ragp-border);
  border: 1px solid var(--ragp-border);
  border-radius: var(--ragp-radius-sm);
  overflow: hidden;
}

.ragp-idle-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 14px 15px 16px;
  background: var(--ragp-panel);
}

.ragp-idle-num {
  font-family: var(--ragp-mono);
  font-size: 10.5px;
  color: var(--ragp-accent);
}

.ragp-idle-k { font-size: 14px; font-weight: 600; }

.ragp-idle-v {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ragp-dim);
}

.ragp-empty {
  margin-top: 18px;
  text-align: center;
  font-size: 22px;
  color: var(--ragp-faint);
}

/* ==========================================================================
   Stage 1 the document and its chunks
   ========================================================================== */

.ragp-doc {
  max-height: 190px;
  overflow-y: auto;
  padding: 14px 16px;
  border: 1px solid var(--ragp-border);
  border-radius: var(--ragp-radius-sm);
  background: rgba(255, 255, 255, 0.02);
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--ragp-faint);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ragp-doc-part { transition: color 0.4s, background 0.4s; border-radius: 3px; }

.ragp-doc-part.is-lit {
  color: var(--ragp-text);
  background: rgba(61, 220, 151, 0.1);
}

.ragp-metabar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--ragp-faint);
}

.ragp-metaitem b {
  color: var(--ragp-accent);
  font-family: var(--ragp-mono);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.ragp-chunkstrip {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  padding-bottom: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.ragp-chunkcard {
  flex: none;
  width: 214px;
  padding: 10px 12px 12px;
  border: 1px solid var(--ragp-border);
  border-radius: var(--ragp-radius-sm);
  background: var(--ragp-surface);
  opacity: 0;
  transform: translateY(10px) scale(0.97);
  transition: opacity 0.34s ease, transform 0.34s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.ragp-chunkcard.is-in { opacity: 1; transform: none; }

.ragp-chunkcard-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.ragp-chunkcard-id {
  font-family: var(--ragp-mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ragp-accent);
}

.ragp-chunkcard-len {
  font-family: var(--ragp-mono);
  font-size: 10.5px;
  color: var(--ragp-faint);
}

.ragp-chunkcard-text {
  max-height: 104px;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.55;
  color: var(--ragp-dim);
  mask-image: linear-gradient(#000 70%, transparent 100%);
  -webkit-mask-image: linear-gradient(#000 70%, transparent 100%);
}

/* The slice carried over from the previous chunk. */
.ragp-ov {
  color: var(--ragp-q);
  background: var(--ragp-q-soft);
  border-radius: 2px;
}

/* ==========================================================================
   Stage 2 weighing
   ========================================================================== */

.ragp-weigh-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

@media (min-width: 800px) {
  .ragp-weigh-grid { grid-template-columns: 1fr 1fr; gap: 24px; }
}

.ragp-weigh-left .ragp-mini-label,
.ragp-weigh-right .ragp-mini-label { margin-top: 0; }

.ragp-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-content: flex-start;
  min-height: 60px;
  padding: 12px;
  border: 1px solid var(--ragp-border);
  border-radius: var(--ragp-radius-sm);
  background: rgba(255, 255, 255, 0.02);
}

.ragp-tokchip {
  display: inline-block;
  padding: 3px 8px;
  border: 1px solid var(--ragp-border);
  border-radius: 5px;
  background: var(--ragp-surface-2);
  font-family: var(--ragp-mono);
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--ragp-dim);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.24s, transform 0.24s, color 0.24s, background 0.24s,
    border-color 0.24s, max-width 0.34s, padding 0.34s, margin 0.34s;
}

.ragp-tokchip.is-in { opacity: 1; transform: none; }

/* A stopword, before it collapses out of the cloud. */
.ragp-tokchip.is-drop { color: var(--ragp-faint); background: rgba(255, 255, 255, 0.02); }

.ragp-tokchip.is-hot {
  color: var(--ragp-accent);
  border-color: rgba(61, 220, 151, 0.4);
  background: var(--ragp-accent-soft);
}

.ragp-cloud-q .ragp-tokchip.is-hot {
  color: var(--ragp-q);
  border-color: rgba(167, 139, 250, 0.45);
  background: var(--ragp-q-soft);
}

/* Stopwords do not vanish; they grey out and collapse, so the visitor sees
   that a decision was made about them. */
.ragp-tokchip.is-gone {
  opacity: 0.16;
  max-width: 0;
  padding-left: 0;
  padding-right: 0;
  margin-left: -5px;
  border-width: 0;
  overflow: hidden;
}

.ragp-wtable {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ragp-wrow {
  display: grid;
  grid-template-columns: minmax(70px, 1.1fr) 52px 42px minmax(90px, 2fr);
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.02);
  font-family: var(--ragp-mono);
  font-size: 11.5px;
  opacity: 0;
  transform: translateX(-6px);
  transition: opacity 0.26s, transform 0.26s;
}

.ragp-wrow.is-in { opacity: 1; transform: none; }

.ragp-wrow-head {
  opacity: 1;
  transform: none;
  background: none;
  color: var(--ragp-faint);
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.ragp-wterm {
  color: var(--ragp-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ragp-wnum { color: var(--ragp-faint); font-variant-numeric: tabular-nums; }

.ragp-wbar {
  position: relative;
  display: flex;
  align-items: center;
  height: 16px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.05);
  overflow: hidden;
}

.ragp-wbar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: 3px;
  background: linear-gradient(90deg, rgba(61, 220, 151, 0.35), var(--ragp-accent));
  transition: width 0.5s cubic-bezier(0.2, 0.8, 0.3, 1);
}

.ragp-wbar-val {
  position: relative;
  margin-left: auto;
  padding-right: 6px;
  font-size: 10.5px;
  color: var(--ragp-text);
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   Stage 3 hashing into buckets, and the matrix
   ========================================================================== */

.ragp-embed-wrap {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

@media (min-width: 860px) {
  .ragp-embed-wrap { grid-template-columns: 220px 1fr; gap: 24px; align-items: start; }
}

.ragp-hash-terms {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ragp-hash-line {
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transform: translateX(-6px);
  transition: opacity 0.26s, transform 0.26s;
}

.ragp-hash-line.is-in { opacity: 1; transform: none; }

.ragp-hash-arrow {
  font-family: var(--ragp-mono);
  font-size: 11px;
  color: var(--ragp-faint);
  white-space: nowrap;
}

.ragp-hash-arrow b { color: var(--ragp-hot); font-weight: 600; }

.ragp-bucketwrap .ragp-mini-label { margin-top: 0; }

/* ---- the vector strip: 64 cells, one per dimension ---- */

/* The column count is set inline it is the store's dimension count, which
   depends on the visitor's text. */
.ragp-strip {
  display: grid;
  gap: 1px;
  padding: 3px;
  border: 1px solid var(--ragp-border);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.03);
  transition: border-color 0.4s, box-shadow 0.4s;
}

.ragp-cell {
  height: 14px;
  border-radius: 1px;
  background: rgba(255, 255, 255, 0.05);
  transition: background 0.3s, transform 0.2s, box-shadow 0.2s;
}

.ragp-strip-big .ragp-cell { height: 30px; }

/* Past a couple of hundred dimensions the gaps would be wider than the cells,
   so the strip closes up and reads as one band. */
.ragp-strip.is-dense { gap: 0; }
.ragp-strip.is-dense .ragp-cell { border-radius: 0; }

.ragp-cell.is-hit {
  transform: scaleY(1.22);
  box-shadow: 0 0 10px rgba(255, 157, 77, 0.6);
}

/* The dimension currently being multiplied in the dot-product march. */
.ragp-cell.is-scan {
  box-shadow: 0 0 0 1.5px var(--ragp-q);
  transform: scaleY(1.15);
}

.ragp-strip.is-normalised {
  border-color: rgba(61, 220, 151, 0.4);
  box-shadow: 0 0 22px -8px var(--ragp-accent);
}

.ragp-strip-q.is-normalised {
  border-color: rgba(167, 139, 250, 0.45);
  box-shadow: 0 0 22px -8px var(--ragp-q);
}

.ragp-formula {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.ragp-formula code {
  padding: 4px 9px;
  border: 1px solid var(--ragp-border);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.025);
  font-family: var(--ragp-mono);
  font-size: 11px;
  color: var(--ragp-dim);
}

.ragp-formula code b { color: var(--ragp-accent); font-weight: 600; }
.ragp-formula.is-norm code { border-color: rgba(61, 220, 151, 0.3); }

/* the ghost that flies from a term to its bucket */
.ragp-ghost {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  opacity: 1;
  transform: none;
  transition-property: transform, opacity;
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- the store as a matrix ----
   A canvas rather than a grid of elements: forty chunks by several hundred
   dimensions is tens of thousands of cells, which is far too much DOM for one
   picture that never needs to be interactive. */

.ragp-matrixwrap {
  padding: 3px;
  border: 1px solid var(--ragp-border);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.03);
}

.ragp-matrix-canvas {
  display: block;
  width: 100%;
  image-rendering: pixelated;
  border-radius: 2px;
}

.ragp-hash-more {
  margin-top: 4px;
  font-family: var(--ragp-mono);
  font-size: 11px;
  color: var(--ragp-faint);
  opacity: 0;
  transition: opacity 0.3s;
}

.ragp-hash-more.is-in { opacity: 1; }

/* ==========================================================================
   Stage 4 the map
   ========================================================================== */

.ragp-index-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

@media (min-width: 860px) {
  .ragp-index-layout { grid-template-columns: 1fr 250px; gap: 24px; align-items: start; }
}

.ragp-mapwrap {
  border: 1px solid var(--ragp-border);
  border-radius: var(--ragp-radius-sm);
  background:
    radial-gradient(60% 60% at 50% 50%, rgba(61, 220, 151, 0.05), transparent 70%),
    rgba(255, 255, 255, 0.015);
  overflow: hidden;
}

.ragp-map { display: block; width: 100%; height: auto; }

.ragp-map-ring {
  fill: none;
  stroke: rgba(255, 255, 255, 0.055);
  stroke-width: 1;
}

.ragp-map-axis {
  stroke: rgba(255, 255, 255, 0.06);
  stroke-width: 1;
  stroke-dasharray: 3 5;
}

.ragp-pt {
  opacity: 0;
  transition: opacity 0.4s ease;
}

.ragp-pt.is-in { opacity: 1; }

.ragp-pt-halo {
  fill: rgba(61, 220, 151, 0.1);
  transition: fill 0.3s, r 0.3s;
}

.ragp-pt-dot {
  fill: var(--ragp-accent);
  transition: fill 0.3s, r 0.3s;
}

.ragp-pt-label {
  fill: var(--ragp-faint);
  font-family: var(--ragp-mono);
  font-size: 9px;
  text-anchor: middle;
}

.ragp-pt:hover .ragp-pt-halo { fill: rgba(61, 220, 151, 0.24); }
.ragp-pt:hover .ragp-pt-label { fill: var(--ragp-text); }

/* The question, on the same plane as the chunks. Violet and larger, because it
   is the one point that did not come out of the document. */
.ragp-pt-q .ragp-pt-dot { fill: var(--ragp-q); }
.ragp-pt-q .ragp-pt-halo { fill: rgba(167, 139, 250, 0.18); }
.ragp-pt-q .ragp-pt-label {
  fill: var(--ragp-q);
  font-size: 10px;
  font-weight: 600;
}

.ragp-pt-q-pulse {
  fill: none;
  stroke: var(--ragp-q);
  stroke-width: 1.5;
  opacity: 0;
}

.ragp-pt-q.is-in .ragp-pt-q-pulse { animation: ragp-ping 1.9s ease-out 3; }

@keyframes ragp-ping {
  0%   { opacity: 0.7; transform: scale(0.35); }
  70%  { opacity: 0;   transform: scale(1.15); }
  100% { opacity: 0;   transform: scale(1.15); }
}

.ragp-index-side { display: flex; flex-direction: column; gap: 1px; }

.ragp-stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--ragp-border);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.02);
}

.ragp-stat-k {
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ragp-faint);
}

.ragp-stat-v {
  font-family: var(--ragp-mono);
  font-size: 12.5px;
  color: var(--ragp-accent);
}

.ragp-side-note {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--ragp-dim);
}

/* ==========================================================================
   Stage 5 the question
   ========================================================================== */

.ragp-qbox {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 15px;
  border: 1px solid rgba(167, 139, 250, 0.3);
  border-radius: var(--ragp-radius-sm);
  background: var(--ragp-q-soft);
}

.ragp-qbox-label {
  flex: none;
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ragp-q);
}

.ragp-qbox-text { font-size: 15px; color: var(--ragp-text); }

.ragp-cloud-q { margin-top: 14px; }

/* A word the store has never seen. Kept visible and struck through rather than
   dropped, because "your question used a word your document never uses" is the
   commonest reason a word-based search comes back empty. */
.ragp-tokchip.is-oov {
  color: var(--ragp-faint);
  border-style: dashed;
  border-color: rgba(255, 157, 77, 0.4);
  text-decoration: line-through;
  text-decoration-color: rgba(255, 157, 77, 0.6);
}

.ragp-oov-note {
  margin: 12px 0 0;
  padding: 10px 13px;
  border-left: 2px solid var(--ragp-hot);
  border-radius: 0 5px 5px 0;
  background: rgba(255, 157, 77, 0.07);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ragp-dim);
  opacity: 0;
  transition: opacity 0.4s;
}

.ragp-oov-note.is-in { opacity: 1; }
.ragp-oov-note b { color: var(--ragp-hot); font-weight: 600; }

/* ==========================================================================
   Stage 6 cosine similarity
   ========================================================================== */

.ragp-ledger {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.ragp-ledger-row {
  display: grid;
  grid-template-columns: 74px 1fr;
  align-items: center;
  gap: 10px;
}

.ragp-ledger-label {
  font-family: var(--ragp-mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  color: var(--ragp-faint);
  text-align: right;
}

.ragp-strip-p { border-style: dashed; }

/* The dimensions where both vectors are non-zero that is, the words the
   question and the chunk have in common. Everything else multiplies to zero,
   so this list IS the similarity, itemised. */
.ragp-shared {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 30px;
  margin-top: 12px;
}

.ragp-shared-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 10px;
  border: 1px solid rgba(61, 220, 151, 0.3);
  border-radius: 6px;
  background: var(--ragp-accent-soft);
  opacity: 0;
  transform: translateY(5px) scale(0.96);
  transition: opacity 0.26s, transform 0.26s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.ragp-shared-item.is-in { opacity: 1; transform: none; }

.ragp-shared-term {
  font-family: var(--ragp-mono);
  font-size: 12px;
  color: var(--ragp-accent);
}

.ragp-shared-math {
  font-family: var(--ragp-mono);
  font-size: 11px;
  color: var(--ragp-faint);
  font-variant-numeric: tabular-nums;
}

.ragp-shared-math b { color: var(--ragp-text); font-weight: 600; }

.ragp-shared-empty {
  padding: 9px 12px;
  border: 1px dashed rgba(255, 157, 77, 0.4);
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--ragp-dim);
}

.ragp-sumwrap {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding: 12px 16px;
  border: 1px solid var(--ragp-border);
  border-radius: var(--ragp-radius-sm);
  background: rgba(255, 255, 255, 0.02);
}

.ragp-sumformula {
  flex: 1 1 220px;
  font-family: var(--ragp-mono);
  font-size: 15px;
  color: var(--ragp-dim);
}

.ragp-sum-sigma { color: var(--ragp-q); font-size: 19px; }

.ragp-sumval {
  color: var(--ragp-text);
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  transition: color 0.3s;
}

.ragp-sumformula.is-done .ragp-sumval {
  color: var(--ragp-accent);
  text-shadow: 0 0 18px rgba(61, 220, 151, 0.5);
}

.ragp-gauge { flex: none; width: 132px; height: 132px; }

.ragp-gauge-quad {
  fill: none;
  stroke: rgba(255, 255, 255, 0.07);
  stroke-width: 1;
  stroke-dasharray: 3 5;
}

.ragp-gauge-q {
  stroke: var(--ragp-q);
  stroke-width: 2.5;
  stroke-linecap: round;
}

.ragp-gauge-c {
  stroke: var(--ragp-accent);
  stroke-width: 2.5;
  stroke-linecap: round;
  transition: all 0.24s ease;
}

.ragp-gauge-arc {
  fill: rgba(167, 139, 250, 0.18);
  stroke: none;
  transition: all 0.24s ease;
}

.ragp-gauge-label {
  fill: var(--ragp-dim);
  font-family: var(--ragp-mono);
  font-size: 11px;
}

/* ---- leaderboard ---- */

.ragp-board {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ragp-boardrow {
  display: grid;
  grid-template-columns: 20px minmax(60px, 1fr) 48px minmax(0, 1.6fr);
  align-items: center;
  gap: 9px;
  padding: 4px 8px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.02);
  opacity: 0;
  transition: opacity 0.26s, background 0.4s, opacity 0.4s;
}

.ragp-boardrow.is-in { opacity: 1; }

.ragp-board-id {
  font-family: var(--ragp-mono);
  font-size: 10.5px;
  color: var(--ragp-faint);
  text-align: right;
}

.ragp-board-track {
  position: relative;
  height: 14px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.05);
  overflow: hidden;
}

.ragp-board-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: 3px;
  background: linear-gradient(90deg, rgba(77, 158, 232, 0.4), var(--ragp-blue));
  transition: width 0.55s cubic-bezier(0.2, 0.8, 0.3, 1), background 0.4s;
}

.ragp-board-num {
  font-family: var(--ragp-mono);
  font-size: 11.5px;
  color: var(--ragp-dim);
  font-variant-numeric: tabular-nums;
}

.ragp-board-text {
  font-size: 11.5px;
  color: var(--ragp-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ragp-boardrow.is-top { background: rgba(61, 220, 151, 0.09); }
.ragp-boardrow.is-top .ragp-board-fill {
  background: linear-gradient(90deg, rgba(61, 220, 151, 0.45), var(--ragp-accent));
}
.ragp-boardrow.is-top .ragp-board-num { color: var(--ragp-accent); }
.ragp-boardrow.is-top .ragp-board-text { color: var(--ragp-dim); }
.ragp-boardrow.is-out { opacity: 0.4; }

/* Rows are re-ordered by flex `order` rather than moved in the DOM, so the
   reorder is a paint rather than a reflow and nothing jumps. */
.ragp-board.is-sorted .ragp-boardrow { transition: opacity 0.4s, background 0.4s; }

/* ==========================================================================
   Stage 7 augment and answer
   ========================================================================== */

.ragp-doc-result { max-height: 150px; }

.ragp-doc-hit {
  color: var(--ragp-text);
  background: rgba(61, 220, 151, 0.15);
  box-shadow: inset 0 -1px 0 rgba(61, 220, 151, 0.5);
  border-radius: 3px;
}

/* How good the win actually was. Always shown, because there is always a
   winner; tinted amber only when the retrieval found little of the question. */
.ragp-quality {
  margin: 4px 0 14px;
  padding: 11px 14px;
  border: 1px solid rgba(61, 220, 151, 0.28);
  border-left-width: 2px;
  border-radius: 0 6px 6px 0;
  background: rgba(61, 220, 151, 0.06);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ragp-dim);
}

.ragp-quality b { color: var(--ragp-accent); font-weight: 600; }

.ragp-quality.is-thin {
  border-color: rgba(255, 157, 77, 0.45);
  background: rgba(255, 157, 77, 0.08);
}

.ragp-quality.is-thin b { color: var(--ragp-hot); }

.ragp-answer-cols {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  margin-top: 16px;
}

@media (min-width: 860px) {
  .ragp-answer-cols { grid-template-columns: 1fr 1fr; gap: 22px; align-items: start; }
}

.ragp-prompt-col .ragp-mini-label,
.ragp-answer-col .ragp-mini-label { margin-top: 0; }

.ragp-prompt {
  max-height: 300px;
  overflow-y: auto;
  scrollbar-width: thin;
  padding: 13px 15px;
  border: 1px solid var(--ragp-border);
  border-radius: var(--ragp-radius-sm);
  background: rgba(255, 255, 255, 0.02);
  font-family: var(--ragp-mono);
  font-size: 11.5px;
  line-height: 1.65;
}

.ragp-p-line {
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.3s, transform 0.3s;
}

.ragp-p-line.is-in { opacity: 1; transform: none; }
.ragp-p-blank { height: 9px; }
.ragp-p-sys { color: var(--ragp-faint); }

.ragp-p-ctx {
  position: relative;
  margin: 2px 0;
  padding: 8px 10px;
  border-left: 2px solid var(--ragp-accent);
  border-radius: 0 4px 4px 0;
  background: rgba(61, 220, 151, 0.07);
  color: var(--ragp-dim);
}

.ragp-p-ctx.is-empty { border-left-color: var(--ragp-faint); background: rgba(255,255,255,0.02); }

.ragp-p-badge {
  display: block;
  margin-bottom: 4px;
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ragp-accent);
}

.ragp-p-q {
  padding: 8px 10px;
  border-left: 2px solid var(--ragp-q);
  border-radius: 0 4px 4px 0;
  background: var(--ragp-q-soft);
  color: var(--ragp-text);
}

.ragp-answer {
  min-height: 96px;
  padding: 14px 16px;
  border: 1px solid rgba(61, 220, 151, 0.28);
  border-radius: var(--ragp-radius-sm);
  background: rgba(61, 220, 151, 0.05);
  font-size: 14.5px;
  line-height: 1.65;
}

.ragp-answer.is-waiting { opacity: 0.6; }

.ragp-caret {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--ragp-accent);
  animation: ragp-blink 1s steps(2) infinite;
}

@keyframes ragp-blink { 50% { opacity: 0; } }

.ragp-answer-note {
  margin: 10px 0 0;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--ragp-faint);
  opacity: 0;
  transition: opacity 0.4s;
}

.ragp-answer-note.is-in { opacity: 1; }
.ragp-answer-note b { color: var(--ragp-dim); font-weight: 600; }

/* ==========================================================================
   Narrow screens
   ========================================================================== */

@media (max-width: 620px) {
  .ragp-root { font-size: 14px; }
  .ragp-header { flex-wrap: wrap; gap: 8px; }
  .ragp-title-sub { display: none; }
  .ragp-header-spacer { display: none; }
  .ragp-stage { padding: 16px 14px 18px; min-height: 380px; }
  .ragp-source, .ragp-query, .ragp-summary, .ragp-rail, .ragp-foot { padding-left: 14px; padding-right: 14px; }
  .ragp-query-row { flex-wrap: wrap; }
  .ragp-input { flex-basis: 100%; }
  .ragp-run { width: 100%; justify-content: center; }
  .ragp-ledger-row { grid-template-columns: 56px 1fr; gap: 7px; }
  .ragp-boardrow { grid-template-columns: 18px 1fr 44px; }
  .ragp-board-text { display: none; }
  .ragp-strip-big .ragp-cell { height: 22px; }
  .ragp-chunkcard { width: 176px; }
  .ragp-wrow { grid-template-columns: minmax(56px, 1fr) 44px 36px minmax(60px, 1.4fr); }
}

/* ==========================================================================
   Reduced motion the demo still runs, it just stops moving about
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .ragp-root *,
  .ragp-root *::before,
  .ragp-root *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
