/* YPS AI Agent — request pipeline in 3D.
   The model is drawn on a canvas by yps-ai-architecture.js; this file styles
   the card and its HTML overlays. The card stays dark in both site themes. */

.agentviz {
  --av-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --av-ink: #e8ecf1;
  --av-muted: rgba(232, 236, 241, 0.62);
  --av-soft: rgba(232, 236, 241, 0.38);
  --av-faint: rgba(232, 236, 241, 0.12);
  --av-glass: rgba(13, 15, 19, 0.82);
  --av-cyan: #6ddcff;
  --av-pass: #45dd93;
  --av-fail: #ff5a69;
  --av-warn: #ffb84d;
  /* The GitBook card's grey, so the two cards in the row read as one surface. */
  --av-base: #242426;

  position: relative;
  isolation: isolate;
  min-width: 0;
  overflow: hidden;
  border-radius: 22px;
  /* A little brighter at the centre, with a vignette drawn on the backdrop
     canvas to shade the corners. */
  background:
    radial-gradient(ellipse farthest-corner at 52% 48%, rgba(255, 255, 255, 0.075) 0%, rgba(255, 255, 255, 0.03) 30%, rgba(255, 255, 255, 0) 55%),
    var(--av-base);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
  color: var(--av-ink);
  scroll-margin-top: 110px;
}

.civic-page.site-dark .agentviz {
  --av-base: var(--civic-card-surface);
  background: var(--av-base);
}

/* Lighting and grain must not darken this card relative to its neighbors. */
.civic-page.site-dark .agentviz::before,
.civic-page.site-dark .agentviz-backdrop {
  display: none;
}

/* Fine grain over the lighting, under the model. */
.agentviz::before {
  position: absolute;
  inset: 0;
  z-index: 0;
  content: "";
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='g' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='2.4 0 0 0 -0.7 2.4 0 0 0 -0.7 2.4 0 0 0 -0.7 0 0 0 0 1'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23g)'/%3E%3C/svg%3E") 0 0 / 160px 160px;
  mix-blend-mode: overlay;
  opacity: 0.2;
  pointer-events: none;
}

.agentviz button {
  font: inherit;
}

.agentviz :focus-visible {
  outline: 1px solid var(--av-cyan);
  outline-offset: 2px;
}

/* Keyboard focus on the chips, buttons and labels is a thin cyan underline,
   in keeping with their borderless look. The stage itself gets a faint inset
   ring, since an outer one would be clipped by the card. */
.agentviz .agentviz-scenarios button:focus-visible,
.agentviz .agentviz-controls button:focus-visible {
  outline: none;
  box-shadow: inset 0 -1px 0 var(--av-cyan);
}

.agentviz .av-pin:focus-visible {
  outline: none;
}

.agentviz .av-pin:focus-visible > span {
  color: var(--av-ink);
  box-shadow: inset 0 -1px 0 var(--av-cyan);
}

.agentviz .agentviz-stage:focus-visible {
  outline: 1px solid rgba(109, 220, 255, 0.4);
  outline-offset: -1px;
}

/* ---------- stage ---------- */

.agentviz-stage {
  position: relative;
  height: 380px;
  overflow: hidden;
  cursor: grab;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.agentviz-stage.is-dragging {
  cursor: grabbing;
}

.agentviz-stage.is-pointing {
  cursor: pointer;
}

.agentviz-stage.is-panning {
  cursor: move;
}

/* the contour map and vignette (drawn once per size) and the model above them */
.agentviz-backdrop,
.agentviz-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.agentviz-backdrop {
  pointer-events: none;
}

/* ---------- labels pinned to the model ---------- */

.agentviz-labels {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.agentviz .av-pin {
  position: absolute;
  top: 0;
  left: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--av-soft);
  font-family: var(--av-mono);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
  will-change: transform;
  transition: color 240ms ease, opacity 260ms ease;
}

button.av-pin {
  pointer-events: auto;
  cursor: pointer;
}

.av-pin > span {
  display: block;
  padding: 3px 4px;
  transform: translate(-50%, -100%);
}

.av-pin:hover,
.av-pin.is-hover {
  color: var(--av-ink);
}

.av-pin.is-current {
  color: var(--av-ink);
}

.av-pin.is-done {
  color: var(--av-muted);
}

.av-pin-kb {
  color: var(--av-muted);
}

.agentviz .av-pin-end > span {
  transform: translate(12px, -50%);
}

.av-pin-stack.is-target {
  color: var(--av-cyan);
}

/* A pin steps back while it would touch the HUD, the tag or a nearer pin. */
.agentviz .agentviz-labels .av-pin.is-yielding {
  opacity: 0;
  pointer-events: none;
}

/* One tag, text only: the active layer's name above its code, or the outcome
   above the output, led by a glowing dot in its tone (the chips' own
   language). A soft dark halo keeps it legible over the model's lines. */
.av-callout {
  position: absolute;
  top: 0;
  left: 0;
  color: var(--av-ink);
  font-family: var(--av-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 240ms ease;
}

.av-callout.is-shown {
  opacity: 1;
}

.av-callout > span {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 2px;
  text-shadow: 0 0 10px rgba(10, 10, 12, 0.9), 0 0 3px rgba(10, 10, 12, 0.9);
  transform: translate(calc(-100% + 12px), -100%);
}

.av-callout.is-flipped > span {
  transform: translate(-12px, -100%);
}

.agentviz .av-callout.is-centred > span {
  transform: translate(-50%, -100%);
}

.av-callout b {
  color: var(--av-callout-tone, var(--av-ink));
  font-weight: 400;
}

.av-callout i {
  display: none;
}

.av-callout.is-outcome i {
  display: block;
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--av-callout-tone);
  box-shadow: 0 0 8px var(--av-callout-tone);
}

/* ---------- HUD ---------- */

.agentviz-top {
  position: absolute;
  top: 18px;
  left: 22px;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  max-width: calc(100% - 44px);
}

.agentviz-kicker {
  margin: 0;
  color: var(--av-ink);
  font-family: var(--av-mono);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.agentviz-scenarios {
  display: flex;
  gap: 5px;
}

.agentviz-scenarios button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--av-soft);
  font-family: var(--av-mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 200ms ease, background 200ms ease;
}

.agentviz-scenarios button i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.agentviz-scenarios button[data-tone="pass"] i { background: var(--av-pass); }
.agentviz-scenarios button[data-tone="fail"] i { background: var(--av-fail); }
.agentviz-scenarios button[data-tone="warn"] i { background: var(--av-warn); }

.agentviz-scenarios button:hover {
  color: var(--av-ink);
}

.agentviz-scenarios button[aria-checked="true"] {
  background: rgba(255, 255, 255, 0.06);
  color: var(--av-ink);
}

.agentviz-scenarios button[aria-checked="true"][data-tone="pass"] i { box-shadow: 0 0 8px var(--av-pass); }
.agentviz-scenarios button[aria-checked="true"][data-tone="fail"] i { box-shadow: 0 0 8px var(--av-fail); }
.agentviz-scenarios button[aria-checked="true"][data-tone="warn"] i { box-shadow: 0 0 8px var(--av-warn); }

/* How to handle the model, bottom left, level with the controls. */
.agentviz-hint {
  position: absolute;
  bottom: 16px;
  left: 22px;
  z-index: 2;
  display: flex;
  align-items: center;
  height: 28px;
  margin: 0;
  color: var(--av-soft);
  font-family: var(--av-mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
  text-shadow: 0 0 8px rgba(10, 10, 12, 0.95), 0 0 2px rgba(10, 10, 12, 0.95);
  pointer-events: none;
}

.agentviz-hint span + span::before {
  margin: 0 9px;
  content: "·";
}

.agentviz-hint span[hidden] {
  display: none;
}

.agentviz-controls {
  position: absolute;
  right: 18px;
  bottom: 16px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 4px;
}

.agentviz-view-readout {
  margin-right: 8px;
  text-shadow: 0 0 8px rgba(10, 10, 12, 0.95);
  color: var(--av-soft);
  font-family: var(--av-mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  font-variant-numeric: tabular-nums;
}

.agentviz-controls button {
  display: grid;
  flex: none;
  place-items: center;
  height: 28px;
  min-width: 28px;
  padding: 0 8px;
  border: 0;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.07);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: var(--av-muted);
  font-family: var(--av-mono);
  font-size: 9.5px;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: color 200ms ease, background 200ms ease;
}

.agentviz-controls button:hover {
  background: rgba(255, 255, 255, 0.11);
  color: var(--av-ink);
}

/* 360° is a switch: tinted cyan while the model keeps turning. */
.agentviz-controls .agentviz-spin[aria-pressed="true"] {
  background: rgba(109, 220, 255, 0.14);
  color: var(--av-cyan);
}

.agentviz-controls svg {
  width: 11px;
  height: 11px;
}

.agentviz-play svg {
  fill: currentColor;
}

.agentviz-controls [data-av-reset] svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.agentviz-play[aria-pressed="true"] .av-icon-play,
.agentviz-play[aria-pressed="false"] .av-icon-pause {
  display: none;
}

.agentviz-tip {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 3;
  width: 220px;
  padding: 9px 11px 10px;
  border-radius: 8px;
  background: var(--av-glass);
  box-shadow: inset 0 0 0 1px var(--av-faint), 0 10px 30px rgba(0, 0, 0, 0.4);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  pointer-events: none;
}

.agentviz-tip[hidden] {
  display: none;
}

.agentviz-tip b {
  display: block;
  color: var(--av-ink);
  font-family: var(--av-mono);
  font-size: 9.5px;
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.agentviz-tip span {
  display: block;
  margin-top: 5px;
  color: var(--av-muted);
  font-size: 11.5px;
  line-height: 1.45;
}

@media (prefers-reduced-motion: reduce) {
  .agentviz *,
  .agentviz *::before,
  .agentviz *::after {
    transition: none !important;
    animation: none !important;
  }
}

/* ---------- narrow cards (set by the script from the card's own width) ---------- */

.agentviz.is-compact .agentviz-top {
  top: 12px;
  left: 14px;
  right: 14px;
  max-width: none;
}

.agentviz.is-compact .agentviz-kicker {
  display: none;
}

.agentviz.is-compact .agentviz-scenarios {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: 100%;
  gap: 4px;
}

.agentviz.is-compact .agentviz-scenarios button {
  justify-content: center;
  min-width: 0;
  height: 40px;
  padding: 0 6px;
  font-size: 10px;
}

.agentviz.is-compact .agentviz-controls {
  right: 14px;
  bottom: 14px;
}

.agentviz.is-compact .agentviz-controls button {
  min-width: 40px;
  height: 40px;
}

.agentviz.is-compact .agentviz-hint {
  bottom: 14px;
  left: 14px;
  right: 156px;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 5px;
  height: auto;
  min-height: 40px;
  font-size: 8px;
  line-height: 1.2;
  white-space: normal;
}

.agentviz.is-compact .agentviz-hint [data-av-hint-pan] {
  display: none;
}

.agentviz.is-compact .agentviz-hint span + span::before {
  content: none;
}

.agentviz.is-compact .agentviz-view-readout {
  display: none;
}
