/*
 * The hero, beat streaming-agent: Relay, an agent's terminal with Pip beside it
 * (web/landing/sections/streaming-agent.html). Linked in the page head by lib/landing.ts
 * while the beat is enabled; the shells' sheets it builds on are linked by the page
 * itself, once each and before every section sheet. Every class here starts with the
 * beat id, and every rule is scoped by [data-beat]: the frame's variant
 * (streaming-agent-relay) is styled here and nowhere else.
 *
 * Layout: the serif copy and the dozen lines on the left, the Relay window on the right;
 * inside it the terminal (prompt, scripted text stream) on the left and Pip on the right,
 * the wire rail under both when shown. One column below 1024 px; inside the window, Pip
 * first and the terminal below once the window is narrower than 600 px.
 */

.use-case[data-beat="streaming-agent"] {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 8fr);
  grid-template-areas:
    "copy frame"
    "code frame";
  grid-template-rows: auto 1fr;
  align-content: center;
  align-items: start;
  gap: 28px clamp(28px, 4vw, 56px);
}

/* The section's server markup joins the grid beside the copy. */
.use-case[data-beat="streaming-agent"] .use-case-mount { display: contents; }
.use-case[data-beat="streaming-agent"] .use-case-copy { grid-area: copy; }
.use-case[data-beat="streaming-agent"] .use-case-title { font-size: clamp(34px, 3.7vw, 50px); }
.use-case[data-beat="streaming-agent"] .demo-frame { grid-area: frame; }

/* ── Inside the window ─────────────────────────────────────────────────── */

@container demo-frame (min-width: 600px) {
  [data-beat="streaming-agent"] .demo-frame-body {
    grid-template-columns: minmax(0, 1fr) minmax(240px, 1.25fr);
    grid-template-areas:
      "main stage"
      "aside aside";
  }
}

[data-beat="streaming-agent"] .demo-frame-slot[data-slot="main"] { display: flex; }

[data-beat="streaming-agent"] .streaming-agent-terminal {
  flex: 1;
  min-width: 0;
  min-height: 150px; /* room for the whole stream: its arrival moves nothing below */
  padding: 12px 14px 16px;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.65;
}

[data-beat="streaming-agent"] .streaming-agent-feed-label {
  margin: 0 0 12px;
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}

[data-beat="streaming-agent"] .streaming-agent-prompt { margin: 0 0 10px; }
[data-beat="streaming-agent"] .streaming-agent-caret { color: var(--accent); }

[data-beat="streaming-agent"] .streaming-agent-stream {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
}

/* The cursor while the text is still arriving: a block, not a blink. */
[data-beat="streaming-agent"] .streaming-agent-stream[data-live]::after {
  content: "";
  display: inline-block;
  width: .55em;
  height: 1.15em;
  margin-left: 1px;
  vertical-align: text-bottom;
  background: var(--muted);
}

/* With the wire open, each sent fragment is marked, so a "send text" row has its text. */
[data-beat="streaming-agent"] .demo-frame[data-wire="open"] .streaming-agent-chunk:nth-child(even) {
  background: rgba(180, 142, 255, .16);
  border-radius: 3px;
}

/* ── Pip and the caption under him ─────────────────────────────────────── */

[data-beat="streaming-agent"] .streaming-agent-caption {
  margin: 10px 2px 0;
  min-height: 2.9em; /* two lines, held: the caption arriving moves nothing */
  font-size: 15px;
  line-height: 1.45;
  color: var(--muted);
  text-wrap: pretty;
}

[data-beat="streaming-agent"] .streaming-agent-caption .w.said,
[data-beat="streaming-agent"] .streaming-agent-caption .w.on { color: var(--text); }

[data-beat="streaming-agent"] .streaming-agent-caption .w.on {
  text-decoration: underline 2px var(--accent);
  text-underline-offset: 4px;
}

/* ── The wire rail ─────────────────────────────────────────────────────── */

[data-beat="streaming-agent"] .streaming-agent-wire {
  list-style: none;
  margin: 0;
  padding: 8px 0;
  max-height: 236px;
  overflow: auto;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
}

[data-beat="streaming-agent"] .streaming-agent-wire li {
  display: grid;
  grid-template-columns: 5.4em 2.8em 7.6em minmax(0, 1fr);
  gap: 0 10px;
  padding: 2px 12px;
}

[data-beat="streaming-agent"] .streaming-agent-wire .t {
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

[data-beat="streaming-agent"] .streaming-agent-wire .d { color: var(--muted); }
[data-beat="streaming-agent"] .streaming-agent-wire li[data-dir="send"] .d { color: var(--accent); }
[data-beat="streaming-agent"] .streaming-agent-wire .k { color: var(--text); }

[data-beat="streaming-agent"] .streaming-agent-wire .v {
  min-width: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

@container demo-frame (max-width: 480px) {
  [data-beat="streaming-agent"] .streaming-agent-wire li { grid-template-columns: 4.8em 2.6em minmax(0, 1fr); }
  [data-beat="streaming-agent"] .streaming-agent-wire .v { grid-column: 2 / -1; }
}

/* ── The toolbar ───────────────────────────────────────────────────────── */

[data-beat="streaming-agent"] .streaming-agent-icon { width: 12px; height: 12px; flex: none; }
[data-beat="streaming-agent"] .streaming-agent-icon[hidden] { display: none; }
[data-beat="streaming-agent"] .streaming-agent-motion { margin-left: auto; }

/* ── The dozen lines ───────────────────────────────────────────────────── */

.streaming-agent-code {
  grid-area: code;
  min-width: 0;
  margin: 0;
}

.streaming-agent-code figcaption {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 8px;
}

/* The lines wrap inside the box at every width: a scrolling box hides its scrollbar on
   macOS and reads as cut off, and every one of the dozen lines should stay in view. */
.streaming-agent-code pre {
  margin: 0;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  color: var(--text);
  tab-size: 2;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 1023px) {
  .use-case[data-beat="streaming-agent"] {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "copy"
      "frame"
      "code";
    grid-template-rows: none;
    gap: 24px;
  }

  .streaming-agent-code pre {
    font-size: 11.5px;
    padding: 14px;
  }
}
