/* Starling's trial passage told as one panel (agent-story.js): where each version comes from along the top, the quick
   draft turning into Starling's version note by note, and one player for the recording and both versions. Every note's
   colour, place and opacity comes from its animation. It is laid out for the story's layout (data-layout): wide, four
   bars a line and the words beside the bird; narrow, two bars a line and the story compact. */

.agent-story-block {
  display: grid;
  gap: var(--space-4);
}
.agent-story {
  position: relative;
  display: grid;
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-radius: 16px;
  background: var(--layer-1);
  scroll-margin-top: calc(var(--agent-head, 0px) + var(--space-4));
}
/* Until the story is there, its room is kept (agent-transcription.js shows this placeholder while it is read). */
.agent-story[data-story="loading"] {
  min-height: 420px;
}
.agent-story[data-story="loading"]::before {
  content: "";
  align-self: stretch;
  border-radius: 12px;
  background: linear-gradient(90deg, var(--layer-1), var(--layer-2, var(--layer-1)), var(--layer-1));
  background-size: 200% 100%;
  animation: agent-shimmer 1.4s linear infinite;
}

/* Where each version comes from: the quick draft's one step, then Starling's. Each step fills as the loop passes it;
   pressing one goes on from there. */
.agent-story-strip {
  position: relative;
  display: grid;
  grid-template-columns: minmax(max-content, 1fr) minmax(0, 5fr);
  grid-template-rows: auto auto;
  gap: 6px var(--space-4);
  margin-bottom: var(--space-4);
}
/* Each group's name and steps on the strip's two rows: however its name wraps, every bar is on the same line. */
.agent-story-group {
  display: grid;
  grid-row: span 2;
  grid-template-rows: subgrid;
  gap: 6px;
  min-width: 0;
}
.agent-story-group-name {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.agent-story-group-name span {
  overflow: hidden;
  text-overflow: ellipsis;
}
.agent-story-group-name b {
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}
.agent-story-steps {
  display: grid;
  grid-auto-columns: minmax(max-content, 1fr);
  grid-auto-flow: column;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}
.agent-story-steps button {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.agent-story-bar {
  position: relative;
  height: 2px;
  overflow: hidden;
  border-radius: 1px;
  background: var(--hair-strong);
}
.agent-story-bar i {
  position: absolute;
  inset: 0;
  background: var(--ink);
  transform-origin: left;
}
.agent-story-step-name {
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
/* Listening, or resting on the end frame, shows a finished version: its steps read done, not stopped partway. */
.agent-story:not([data-mode="loop"]) .agent-story-steps [data-done] .agent-story-bar i {
  transform: scaleX(1) !important;
}
/* While the pill shows, Starling's line ends before it. */
.agent-story:not([data-mode="loop"]) [data-group="agent"] .agent-story-group-name {
  padding-inline-end: var(--resume-room, 0px);
}
/* Only while the animation is held or you are listening: at the story's top right, by the steps it moves along. */
.agent-story-resume {
  position: absolute;
  z-index: 3;
  top: -5px;
  right: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px 0 10px;
  border: 0;
  border-radius: 999px;
  background: var(--white);
  box-shadow: inset 0 0 0 1px var(--hair-strong);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.agent-story-resume[hidden] {
  display: none;
}
/* A 44px target around the small pill. */
.agent-story-resume::before {
  content: "";
  position: absolute;
  inset: -8px -6px;
}
.agent-story-resume svg {
  flex: none;
  width: 14px;
  height: 14px;
}

/* What Starling says it is doing, what it read, and the bird standing on the sheet's top edge. */
.agent-story-head {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 64px;
  align-items: end;
  gap: var(--space-3);
  min-height: 72px;
  margin-top: var(--say-room, 0px);
}
.agent-story-say {
  display: grid;
  align-self: stretch;
  padding-bottom: var(--space-3);
}
.agent-story-cap {
  grid-area: 1 / 1;
  display: grid;
  align-content: end;
  gap: 4px;
  margin: 0;
  opacity: 0;
}
.agent-story-cap-end {
  opacity: 1;
}
.agent-story-step {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.agent-story-n {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--page-paper, #fff);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.agent-story-words {
  display: -webkit-box;
  overflow: hidden;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.35;
  text-wrap: pretty;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.agent-story-words b {
  color: var(--danger);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
/* The notes' blue, deepened a touch so the word reads at 4.5:1 on the panel (the notes sit on the paper). */
.agent-story-words em {
  color: color-mix(in srgb, var(--ai-mark) 88%, var(--ink));
  font-style: normal;
}
/* What it read, as a note on the panel: its picture and name. */
.agent-story-source {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 220px;
  min-width: 0;
  margin-bottom: var(--space-3);
  opacity: 0;
}
.agent-story-source img {
  flex: none;
  width: 56px;
  height: 30px;
  border-radius: 3px;
  background: var(--white);
  object-fit: cover;
  object-position: left top;
  box-shadow: 0 0 0 1px var(--hair);
}
.agent-story-source span {
  display: grid;
  min-width: 0;
  line-height: 1.3;
}
.agent-story-source b {
  display: -webkit-box;
  overflow: hidden;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.agent-story-source small {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Held up for a moment before it shrinks into its place beside the words. */
.agent-story-card {
  position: absolute;
  z-index: 3;
  top: -4px;
  right: 92px;
  width: 232px;
  padding: 6px;
  border-radius: 8px;
  background: var(--white);
  box-shadow:
    0 12px 32px -14px rgba(15, 14, 18, 0.3),
    0 0 0 1px rgba(15, 14, 18, 0.08);
  opacity: 0;
  transform-origin: 0 0;
  pointer-events: none;
}
.agent-story-card img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 3px;
}

/* Every pose leaves 17 of its 160px empty under the feet; the negative margin stands the feet on the sheet. Pressed,
   the bird opens how Agent Transcription works; it asks once by itself, and when pointed at or focused, the way Starling
   speaks on its working page (.agent-bubble: white, a turned-square tail toward the bird). */
.agent-story-bird {
  position: relative;
  z-index: 2;
  display: block;
  width: 64px;
  height: 76px;
  margin-bottom: -8px;
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}
.agent-story-bird img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom;
  opacity: 0;
}
.agent-story-bird img[data-pose="present"] {
  opacity: 1;
}
/* Over its cocked head while it is unsure, in the poster face and ink: the head sits 58% across, a quarter down. */
.agent-story-wonder {
  position: absolute;
  top: -9px;
  right: 21px;
  color: var(--ink);
  font: 700 26px / 1 var(--poster-face);
  font-style: normal;
  opacity: 0;
  transform-origin: 30% 100%;
  pointer-events: none;
}
/* Over the bird, its tail toward the bird's head, clear of the steps above it and of the words, the end's caption
   included: placeSay (agent-story.js) sets how high it sits, how wide it may wrap and the room the head makes for it.
   Leaving, it waits a moment, so the pointer can cross over to it; it is part of the link. */
.agent-story-hint {
  position: absolute;
  right: 0;
  bottom: var(--say-bottom, calc(100% + 4px));
  display: flex;
  align-items: center;
  gap: 6px;
  width: max-content;
  max-width: var(--say-width, 360px);
  padding: 7px 12px;
  border-radius: 12px;
  background: var(--white);
  box-shadow:
    0 12px 32px -14px rgba(15, 14, 18, 0.3),
    0 0 0 1px rgba(15, 14, 18, 0.08);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
  text-wrap: balance;
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition:
    opacity 0.18s 0.3s,
    transform 0.18s 0.3s,
    visibility 0s linear 0.48s;
}
/* A bridge down to the bird, so the pointer never leaves the link on its way to the bubble. */
.agent-story-hint::before {
  content: "";
  position: absolute;
  top: 100%;
  right: 0;
  width: 64px;
  height: var(--say-gap, 12px);
}
/* The tail on its lower edge, over the bird's head. */
.agent-story-hint::after {
  content: "";
  position: absolute;
  right: 20px;
  bottom: -6px;
  width: 12px;
  height: 12px;
  background: inherit;
  box-shadow: 1px 1px 0 rgba(15, 14, 18, 0.08);
  transform: rotate(45deg);
}
.agent-story-hint svg {
  flex: none;
  width: 12px;
  height: 12px;
  color: var(--muted);
}
.agent-story-bird:is(:focus-visible, [data-say]) {
  z-index: 4;
}
.agent-story-bird:is(:focus-visible, [data-say]) .agent-story-hint {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition:
    opacity 0.18s,
    transform 0.18s,
    visibility 0s;
}
/* Pointing at it asks too, where there is a pointer to hover with (a tap opens the walkthrough). */
@media (hover: hover) {
  .agent-story-bird:hover {
    z-index: 4;
  }
  .agent-story-bird:hover .agent-story-hint {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition:
      opacity 0.18s,
      transform 0.18s,
      visibility 0s;
  }
}

/* The sheet: Starling's drawing below, the quick draft's laid on its staff lines. Pressing it pauses the animation. */
.agent-story-stage {
  position: relative;
}
.agent-story-sheet {
  position: relative;
  isolation: isolate;
  padding: var(--space-3) var(--space-3) var(--space-2) 18px;
  border-radius: 12px;
  background: var(--paper, var(--page-paper));
  box-shadow: inset 0 0 0 1px var(--hair);
  cursor: pointer;
}
.agent-story-sheet:focus-visible {
  outline: 2px solid var(--focus, var(--accent));
  outline-offset: 2px;
}
.agent-story-lines {
  display: grid;
  gap: var(--space-1);
}
/* Each line is drawn as the score's pages are (.score-pages, ui.css: the engraving's ink and text faces), never as an
   icon; what the pages add for a page of their own (its paper, shadow, padding, panning, a note's hover) is undone. */
.agent-story-line.score-pages {
  position: relative;
  display: block;
  gap: 0;
  margin: 0;
  padding: 0;
}
.agent-story-line.score-pages > svg {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  max-width: none;
  height: auto;
  margin: 0;
  overflow: visible;
  background: none;
  color: var(--ink);
  fill: currentColor;
  stroke: none;
  stroke-width: 1;
  stroke-linecap: butt;
  stroke-linejoin: miter;
  border-radius: 0;
  box-shadow: none;
  translate: none;
}
.agent-story-line.score-pages > svg + svg {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
}
.agent-story-line.score-pages :is(g.note, g.rest, g.mRest) {
  cursor: inherit;
  transition: none;
}
@media (hover: hover) {
  .agent-story-line.score-pages :is(g.note, g.rest, g.mRest):hover {
    color: inherit;
  }
}
.agent-story-line g.note {
  transform-box: fill-box;
  transform-origin: center;
}
/* What changes staff travels in the drawing's own units, from the drawing's corner. */
.agent-story-line .is-travelling {
  transform-box: view-box;
  transform-origin: 0 0;
}
/* The marks Starling changed (tempo, dynamics) in its blue, as its notes. */
.agent-story-line > svg:first-of-type .is-changed {
  color: var(--ai-mark);
}
/* What is sounding while you listen, in the workspace player's colour; it outranks the animation's colours. */
.agent-story-line g.note.playing-note {
  color: var(--play) !important;
}
/* The hand the notes go to, lit while they go there (placed by agent-story.js on Starling's staff). */
.agent-story-hand {
  position: absolute;
  z-index: 0;
  right: -6px;
  left: -10px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--ai-mark) 8%, transparent);
  opacity: 0;
  pointer-events: none;
}

/* One player for the recording and both versions, the workspace's own (ui.css .player): what you choose to hear is
   what the sheet shows. */
.agent-story-player {
  padding: 0;
  margin-top: var(--space-3);
}
.agent-story-player .timeline {
  flex-basis: 260px;
}
.agent-story-listen {
  margin-left: auto;
}
.agent-story-time {
  font-variant-numeric: tabular-nums;
}

/* Below: each kind of fix, pressing one shows it; what Starling is unsure of, in its words. */
.agent-story-title {
  margin: 0 0 var(--space-2);
  font-size: 15px;
  font-weight: 600;
}
.agent-story-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}
.agent-story-tile {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  height: 100%;
  min-height: 52px;
  padding: var(--space-3) var(--space-4) var(--space-3) var(--space-3);
  border: 0;
  border-radius: 12px;
  background: var(--layer-1);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.agent-story-tile:hover {
  background: var(--layer-2, var(--layer-1));
}
.agent-story-tile .agent-story-n {
  width: 24px;
  height: 24px;
  font-size: 12px;
}
.agent-story-tile-text strong {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
}
.agent-story-tile-count {
  color: var(--ink-soft);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.agent-story-doubts .agent-unsure {
  margin: 0;
}

/* A narrow panel (the story's narrow layout, two bars a line, which agent-transcription.js picks by the panel's
   width): where each version comes from on a line under its name, the steps as wide as their words, the words
   beside a smaller bird, and what Starling read rising over the score's top. */
.agent-story[data-layout="narrow"] .agent-story-strip {
  column-gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.agent-story[data-layout="narrow"] .agent-story-strip {
  grid-template-columns: minmax(min-content, 1fr) minmax(0, 3fr);
}
/* Names wrap rather than run off the panel: each takes the room its words need, down to its longest word. */
.agent-story[data-layout="narrow"] .agent-story-group-name {
  flex-direction: column;
  gap: 0;
  white-space: normal;
}
.agent-story[data-layout="narrow"] .agent-story-group-name span {
  overflow: visible;
  font-size: 11px;
  line-height: 1.3;
  text-overflow: clip;
  text-wrap: balance;
}
.agent-story[data-layout="narrow"] .agent-story-steps {
  grid-auto-columns: auto;
  gap: 6px;
}
.agent-story[data-layout="narrow"] .agent-story-steps button {
  min-height: 44px;
  align-content: start;
}
.agent-story[data-layout="narrow"] .agent-story-step-name {
  font-size: 11px;
  line-height: 1.25;
  white-space: normal;
  overflow-wrap: break-word;
  text-wrap: balance;
}
/* On a phone, and wherever its words would cut Starling's line, the pill is its icon alone (its name stays its
   label), a 44px target around it. */
.agent-story :is(.agent-story-resume.is-compact),
.agent-story[data-layout="narrow"] .agent-story-resume {
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
}
.agent-story :is(.agent-story-resume.is-compact) span,
.agent-story[data-layout="narrow"] .agent-story-resume span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.agent-story :is(.agent-story-resume.is-compact)::before,
.agent-story[data-layout="narrow"] .agent-story-resume::before {
  inset: -6px;
}
.agent-story[data-layout="narrow"] .agent-story-head {
  grid-template-columns: minmax(0, 1fr) 48px;
  min-height: 60px;
}
.agent-story[data-layout="narrow"] .agent-story-source {
  display: none;
}
.agent-story[data-layout="narrow"] .agent-story-card {
  top: calc(100% + 10px);
  right: 8px;
  width: 204px;
}
.agent-story[data-layout="narrow"] .agent-story-bird {
  width: 48px;
  height: 57px;
  margin-bottom: -6px;
}
.agent-story[data-layout="narrow"] .agent-story-wonder {
  top: -7px;
  right: 15px;
  font-size: 20px;
}
.agent-story[data-layout="narrow"] .agent-story-hint {
  max-width: min(var(--say-width, 272px), 272px);
  padding: 6px 11px;
  font-size: 13px;
}
.agent-story[data-layout="narrow"] .agent-story-hint::before {
  width: 48px;
}
.agent-story[data-layout="narrow"] .agent-story-hint::after {
  right: 14px;
}
.agent-story[data-layout="narrow"] .agent-story-words {
  font-size: 16px;
}
.agent-story[data-layout="narrow"] .agent-story-sheet {
  padding: var(--space-3) var(--space-2) var(--space-2) 16px;
}
.agent-story[data-layout="narrow"] .agent-story-play {
  width: 44px;
  height: 44px;
}
.agent-story[data-layout="narrow"] .agent-story-listen {
  display: grid;
  flex: 1 1 100%;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-left: 0;
}
.agent-story[data-layout="narrow"] .agent-story-listen button {
  height: 44px;
}
@media (max-width: 760px) {
  .agent-story {
    padding: var(--space-3) var(--space-3) var(--space-2);
    border-radius: 12px;
  }
  .agent-story-tiles {
    grid-template-columns: 1fr;
  }
}
@media (prefers-reduced-motion: reduce) {
  .agent-story-hint {
    transform: none;
  }
  .agent-story[data-story="loading"]::before {
    animation: none;
  }
}

/* ── Dark: the reduced weights, the paper a layer up as the sheet's other papers ── */
:root[data-theme="dark"] .agent-story-sheet {
  background: var(--layer-2, var(--layer-1));
}
:root[data-theme="dark"] .agent-story-bird {
  margin-bottom: 0;
}
:root[data-theme="dark"] .agent-story-bird::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--sl-paper, #f1efe8);
  transform: translateX(-50%);
}
:root[data-theme="dark"] .agent-story-bird img {
  transform: scale(0.84);
}
:root[data-theme="dark"]
  :is(
    .agent-story-group-name b,
    .agent-story-words,
    .agent-story-words b,
    .agent-story-source b,
    .agent-story-title,
    .agent-story-tile-text strong,
    .agent-story-n
  ) {
  font-weight: 560;
}
:root[data-theme="dark"] :is(.agent-story-step-name, .agent-story-step, .agent-story-resume, .agent-story-hint) {
  font-weight: 460;
}
