/* Figure 1: the animated loop diagram (sources -> learner-1 -> memory db -> your agent).
   Nodes are placed with --wx/--wy on the 640x360 canvas and --sx/--sy on the 320x484 phone canvas. */

.loop {
  --drift: 5;
  --spring-30: var(--spring-36);
  margin-block: 16px;
}

.canvas {
  position: relative;
  width: 640px;
  max-width: 100%;
  height: 360px;
  overflow: hidden;
  border: 1px solid var(--rule);
  background:
    radial-gradient(#0b10151a 1px, #0000 1.25px) 8px 8px / 16px 16px,
    #fff;
}

.loop figcaption {
  max-width: 600px;
  margin-top: 12px;
  color: var(--ink-60);
  font-size: 14px;
  line-height: 1.5;
  text-wrap: pretty;
}

/* ---------- wires ---------- */

.edges {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  fill: none;
}
.edges-s {
  display: none;
}
.track {
  stroke: #0b101547;
  stroke-width: 1px;
  stroke-dasharray: 3 3;
  stroke-linejoin: miter;
  shape-rendering: crispEdges;
  animation: drift calc(6s / max(var(--drift), 0.01)) linear infinite;
}
@keyframes drift {
  to {
    stroke-dashoffset: -6px;
  }
}
/* a comet is three overlapping dashes (tail, mid, head) run along a copy of the wire */
.comet {
  visibility: hidden;
  stroke: var(--accent-text);
  stroke-width: 2px;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.comet-tail {
  stroke-opacity: 0.22;
}
.comet-mid {
  stroke-opacity: 0.5;
}
.comet-head {
  stroke-opacity: 1;
}
.comet.is-faint {
  opacity: 0.5;
}

/* ---------- the AIVC frame ---------- */

.frame,
.node,
.tag,
.verb,
.fleet {
  z-index: 2;
}
.frame {
  position: absolute;
  top: 76px;
  left: 152px;
  width: 288px;
  height: 160px;
  border: 1px solid var(--rule);
}
.frame-name {
  position: absolute;
  top: -8px;
  left: 15px;
  padding: 0 6px;
  background: #fff;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  line-height: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ---------- nodes ---------- */

.node {
  position: absolute;
  top: var(--wy);
  left: var(--wx);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  scale: 1;
  transition:
    border-color 0.3s var(--ease-out),
    background-color 0.3s var(--ease-out),
    scale 0.58s var(--spring-30);
}
.node.is-hot {
  border-color: var(--accent-text);
  scale: 0.985;
  transition-duration: 0.12s, 0.12s, 0.12s;
}
.node.is-warm {
  border-color: var(--accent-text-50);
  transition-duration: 0.12s, 0.12s, 0.58s;
}
/* a ring that pulses out when a comet lands */
.node::after {
  content: "";
  position: absolute;
  inset: -1px;
  border: 1px solid var(--accent-text);
  opacity: 0;
  pointer-events: none;
}
.node.is-hot::after {
  animation: ring 0.7s var(--ease-out) both;
}
@keyframes ring {
  from {
    opacity: 0.55;
    scale: 1;
  }
  to {
    opacity: 0;
    scale: 1.4;
  }
}

.loop .tile {
  width: 56px;
  height: 56px;
}
.loop .tile-lg {
  width: 64px;
  height: 64px;
}
/* the MCP mark in its source tile, set in ink like the drawn icons */
.loop .tile img {
  display: block;
  width: 22px;
  height: 22px;
  object-fit: contain;
  filter: brightness(0);
}
.loop .tile svg {
  display: block;
  width: 24px;
  height: 24px;
}

/* learner-1: the mark on a green tile, which dissolves into a 3x3 pixel grid while it works.
   Everything on the green is Black 100; a hit darkens the tile's edge rather than its face. */
.hub {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}
.hub.is-hot {
  border-color: var(--accent-text);
}
.hub.is-warm {
  border-color: var(--accent-text-50);
}
.hub .mark,
.hub .grid {
  grid-area: 1 / 1;
  transition:
    opacity 0.24s var(--ease-out),
    scale 0.58s var(--spring-30),
    filter 0.24s var(--ease-out);
}
.hub .mark {
  display: block;
}
.hub .mark svg {
  display: block;
  width: 20px;
  height: 19px;
}
.hub .grid {
  display: grid;
  grid-template-columns: repeat(3, 6px);
  gap: 2px;
  opacity: 0;
  filter: blur(4px);
  scale: 0.6;
}
.hub .grid i {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 1px;
  background: var(--on-accent);
  opacity: 0.15;
}
.hub.is-working .mark {
  opacity: 0;
  filter: blur(4px);
  scale: 0.6;
}
.hub.is-working .grid {
  opacity: 1;
  filter: none;
  scale: 1;
}
.hub.is-working .grid i {
  animation: pixel-on 0.65s ease-in-out infinite;
}

/* one pixel pattern per verb */
.hub[data-pattern="drive"] .grid i:nth-child(1),
.hub[data-pattern="drive"] .grid i:nth-child(5),
.hub[data-pattern="drive"] .grid i:nth-child(7) {
  animation-delay: 90ms;
}
.hub[data-pattern="drive"] .grid i:nth-child(2),
.hub[data-pattern="drive"] .grid i:nth-child(6),
.hub[data-pattern="drive"] .grid i:nth-child(8) {
  animation-delay: 0.18s;
}
.hub[data-pattern="drive"] .grid i:nth-child(3),
.hub[data-pattern="drive"] .grid i:nth-child(9) {
  animation-delay: 0.27s;
}
.hub[data-pattern="drive"] .grid i:nth-child(4) {
  animation-delay: 0s;
}

.hub[data-pattern="focus"] .grid i:nth-child(odd) {
  animation-delay: 0s;
}
.hub[data-pattern="focus"] .grid i:nth-child(even) {
  animation-delay: 0.15s;
}
.hub[data-pattern="focus"] .grid i:nth-child(5) {
  animation-delay: 0.3s;
}

/* orbit runs clockwise around the edge, centre dark */
.hub[data-pattern="orbit"] .grid i {
  animation-duration: 0.95s;
}
.hub[data-pattern="orbit"] .grid i:nth-child(1) {
  animation-delay: 0s;
}
.hub[data-pattern="orbit"] .grid i:nth-child(2) {
  animation-delay: 0.11s;
}
.hub[data-pattern="orbit"] .grid i:nth-child(3) {
  animation-delay: 0.22s;
}
.hub[data-pattern="orbit"] .grid i:nth-child(6) {
  animation-delay: 0.33s;
}
.hub[data-pattern="orbit"] .grid i:nth-child(9) {
  animation-delay: 0.44s;
}
.hub[data-pattern="orbit"] .grid i:nth-child(8) {
  animation-delay: 0.55s;
}
.hub[data-pattern="orbit"] .grid i:nth-child(7) {
  animation-delay: 0.66s;
}
.hub[data-pattern="orbit"] .grid i:nth-child(4) {
  animation-delay: 0.77s;
}
.hub[data-pattern="orbit"] .grid i:nth-child(5) {
  opacity: 0.07;
  animation: none;
}

/* fade switches the pixels off one after another */
.hub[data-pattern="fade"] .grid i {
  opacity: 1;
  animation: pixel-off 0.36s var(--ease-out) forwards;
  animation-delay: calc((var(--n) - 1) * 60ms);
}
.hub .grid i:nth-child(1) { --n: 1; }
.hub .grid i:nth-child(2) { --n: 2; }
.hub .grid i:nth-child(3) { --n: 3; }
.hub .grid i:nth-child(4) { --n: 4; }
.hub .grid i:nth-child(5) { --n: 5; }
.hub .grid i:nth-child(6) { --n: 6; }
.hub .grid i:nth-child(7) { --n: 7; }
.hub .grid i:nth-child(8) { --n: 8; }
.hub .grid i:nth-child(9) { --n: 9; }

@keyframes pixel-on {
  0%,
  100% {
    opacity: 0.15;
  }
  50% {
    opacity: 1;
  }
}
@keyframes pixel-off {
  from {
    opacity: 1;
  }
  to {
    opacity: 0.15;
  }
}

/* ---------- labels ---------- */

.tag,
.verb {
  position: absolute;
  top: var(--wy);
  left: var(--wx);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  line-height: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  translate: -50%;
}
.tag {
  color: var(--ink-60);
  white-space: nowrap;
}
.tag-accent {
  color: var(--accent-text);
}
.tag-or {
  color: var(--ink-45);
}
.tag-narrow {
  display: none;
}

/* the db's version number rolls up each time it is written */
.ver {
  display: grid;
  height: 14px;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}
.ver > span {
  grid-area: 1 / 1;
  transition: translate 0.58s var(--spring-30);
}
.ver-b {
  translate: 0 100%;
}
.ver.is-rolling .ver-a {
  translate: 0 -100%;
}
.ver.is-rolling .ver-b {
  translate: 0;
}
.ver.no-t > span {
  transition: none;
}
.ver.is-fresh {
  animation: status-pulse 1.2s ease-in-out;
}
@keyframes status-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

/* the verb learner-1 is applying: one word at a time, with a shimmer running through it */
.verb {
  width: 96px;
  height: 14px;
  color: var(--ink);
  text-align: center;
}
.verb span {
  position: absolute;
  inset: 0;
  opacity: 0;
  filter: blur(2px);
  translate: 0 4px;
  background: linear-gradient(90deg, var(--ink-45) 35%, var(--ink) 50%, var(--ink-45) 65%) 0 0 / 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer-text 1.8s linear infinite;
  transition:
    opacity 0.24s var(--ease-out),
    filter 0.24s var(--ease-out),
    translate 0.58s var(--spring-30);
}
.verb span.is-on {
  opacity: 1;
  filter: none;
  translate: 0;
}
@keyframes shimmer-text {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: -100% 0;
  }
}

/* ---------- harness chips under the agent ---------- */

.fleet {
  position: absolute;
  top: var(--wy);
  left: var(--wx);
  display: flex;
  gap: 12px;
}
.chip {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--rule);
  background: var(--paper);
  transition: border-color 0.3s var(--ease-out);
}
.chip:hover,
.chip:focus-visible {
  border-color: var(--accent-text);
}
.chip img {
  width: 16px;
  height: 16px;
  object-fit: contain;
  filter: brightness(0);
  opacity: 0.75;
}
.chip img[src$="claude-code.svg"] {
  width: 19px;
}

/* ---------- arrival ---------- */

html.js .loop:not(.is-in) .node,
html.js .loop:not(.is-in) .tag,
html.js .loop:not(.is-in) .fleet,
html.js .loop:not(.is-in) .frame,
html.js .loop:not(.is-in) .edges {
  opacity: 0;
}
.loop.is-in .node {
  animation: float-in 0.6s var(--ease-out) both;
  animation-delay: calc(var(--k, 0) * 50ms);
}
.loop.is-in .tag,
.loop.is-in .fleet,
.loop.is-in .frame,
.loop.is-in .edges {
  animation: fade-in 0.5s var(--ease-out) 0.32s both;
}
@keyframes float-in {
  from {
    opacity: 0;
    translate: 0 8px;
    scale: 0.98;
  }
  to {
    opacity: 1;
    translate: 0;
    scale: 1;
  }
}

/* ---------- phone layout: the diagram turns vertical ---------- */

@media (width <= 700px) {
  .canvas {
    width: 320px;
    height: 484px;
    margin-inline: auto;
  }
  .edges-w {
    display: none;
  }
  .edges-s {
    display: block;
  }
  .frame {
    top: 152px;
    left: 32px;
    width: 256px;
    height: 156px;
  }
  .node,
  .tag,
  .verb,
  .fleet {
    top: var(--sy);
    left: var(--sx);
  }
  .verb {
    width: 60px;
  }
  .tag[data-wide-only],
  .tag-wide {
    display: none;
  }
  .tag-narrow {
    display: inline;
  }
  .fleet {
    gap: 10px;
  }
  .chip {
    width: 20px;
    height: 20px;
  }
  .chip img {
    width: 13px;
    height: 13px;
  }
  .chip img[src$="claude-code.svg"] {
    width: 15px;
  }
}
@media (width <= 367px) {
  .canvas {
    zoom: 0.92;
  }
}
@media (width <= 342px) {
  .canvas {
    zoom: 0.83;
  }
}

@media (prefers-reduced-motion: reduce) {
  .track,
  .verb span,
  .ver.is-fresh,
  .hub .grid i,
  .node::after {
    animation: none;
  }
  .comet {
    display: none;
  }
  .node,
  .ver > span,
  .verb span,
  .hub .mark,
  .hub .grid {
    transition: none;
  }
  /* all four verbs shown at once, in a 2x2 */
  .verb {
    top: 126px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 6px;
    width: 104px;
    height: 28px;
  }
  .verb span {
    position: static;
    opacity: 1;
    filter: none;
    translate: 0;
    background: none;
    -webkit-text-fill-color: currentColor;
    animation: none;
  }
  html.js .loop:not(.is-in) .node,
  html.js .loop:not(.is-in) .tag,
  html.js .loop:not(.is-in) .frame,
  html.js .loop:not(.is-in) .edges {
    opacity: 1;
  }
  .loop.is-in .node,
  .loop.is-in .tag,
  .loop.is-in .frame,
  .loop.is-in .edges {
    animation: none;
  }
  @media (width <= 700px) {
    .verb {
      top: 200px;
      grid-template-columns: 1fr;
      width: 60px;
      height: 56px;
    }
  }
}
