/* Frank in action: two terminals from one session, over a stone plane that is
   page artwork, not their mount. The front window overhangs it into the paper.
   The agent window is drawn as Claude Code, Frank's as the Frank Monitor. */
.demo {
  /* Terminal geometry. back-x is a percentage of the window's own width, so
     47% right-aligns a 68%-wide window; lift drops the front window by that
     share of its height. Height-aware so the pair and its control fit a short
     laptop screen. */
  --term-h: clamp(20rem, min(30vw, 50svh), 30rem);
  --term-w: 68%;
  --back-x: 47%;
  --lift: 0.42;
  --bleed: calc(var(--gutter) * 0.6);
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(0, 30rem) minmax(0, 1fr);
  /* The empty outer rows centre the copy against the stage. */
  grid-template-rows: 1fr auto 1fr;
  grid-template-areas:
    '. stage'
    'copy stage'
    '. stage';
  column-gap: clamp(3rem, 6vw, 7rem);
  padding: var(--section-y) var(--bleed) var(--section-y) var(--gutter);
}

.demo__copy {
  grid-area: copy;
}

.demo__stop {
  color: var(--red);
}

/* ── The margin note: red pen in the open paper at the top left, above the
   front window. Its arrow starts at the note's top left and curls over to the
   window behind. The note's right edge sits just short of that window, whose
   left edge is back-x of its own width in, less the 5% it is scaled down by. ── */
.demo__control {
  position: absolute;
  z-index: 3;
  top: 0.2rem;
  right: calc(100% - var(--term-w) * (0.47 + 0.05) + 1.75rem);
  width: min(16rem, calc(var(--term-w) * (0.47 + 0.05) - 1.75rem));
}

.note {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1rem;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  font: 400 clamp(1.625rem, 1.6vw, 1.9375rem) / 1.18 var(--hand);
  letter-spacing: 0.02em;
  word-spacing: 0.06em;
  color: var(--red);
  text-align: left;
  cursor: pointer;
}

.note:focus-visible {
  outline: 1.5px dashed currentColor;
  outline-offset: 0.6rem;
  border-radius: 4px;
}

/* The note's full width, scaled whole so the drawing never distorts: it starts
   over the label's first letter and its tip lands at the window behind. */
.note__arrow {
  width: 100%;
  height: auto;
  aspect-ratio: 240 / 50;
  transition: transform var(--dur) var(--ease);
}

.note:hover .note__arrow {
  transform: translate3d(4px, -2px, 0);
}

/* Phones point straight down at the pair instead (see the phone block). */
.note__arrow--down {
  display: none;
}

/* Caveat's lightest cut is still heavier than a fine pen, so a hairline in the
   paper's colour shaves each stroke. A sub-pixel erode filter was tried and
   steps in whole pixels at 1x, shredding the letters. */
.note__text {
  position: relative;
  padding-left: 0.15rem;
  text-wrap: balance;
  -webkit-text-stroke: 0.4px var(--paper);
}

.note__underline {
  position: absolute;
  left: 0;
  bottom: -0.55rem;
  width: 100%;
  height: 0.6rem;
  opacity: 0;
}

/* While Frank has stepped in and is behind, the note says so, underlines
   itself and keeps nudging its arrow at him. */
.note[data-cue] .note__underline {
  opacity: 1;
  animation: draw 0.6s var(--ease) both;
}

.note[data-cue] .note__arrow {
  animation: nudge 2.4s var(--ease) infinite;
}

/* Redrawn once on every switch. */
.note.is-drawn .note__arrow path {
  animation: draw 0.45s var(--ease) both;
}

/* Hand strokes: every path has pathLength 1, so a dash offset draws it in. */
.note path,
.term__ring path {
  stroke-dasharray: 1;
}

@keyframes draw {
  from {
    stroke-dashoffset: 1;
  }

  to {
    stroke-dashoffset: 0;
  }
}

@keyframes nudge {
  0%,
  70%,
  100% {
    transform: none;
  }

  80% {
    transform: translate3d(6px, -2px, 0);
  }

  90% {
    transform: translate3d(1px, 0, 0);
  }
}

/* No drawing or nudging for a visitor who asked for less motion; the strokes
   simply stand drawn. */
@media (prefers-reduced-motion: reduce) {
  .note__arrow,
  .note__arrow path,
  .note__underline,
  .term__ring {
    animation: none !important;
    transition: none;
  }
}

.demo__stage {
  grid-area: stage;
  position: relative;
  align-self: center;
}

.demo__plane {
  position: absolute;
  z-index: -1;
  top: -14%;
  bottom: -18%;
  left: 9%;
  right: calc(-1 * var(--bleed));
  background: var(--stone);
  clip-path: polygon(17% 8%, 100% 0, 100% 100%, 0 88%);
  transform: translate3d(0, calc(var(--drift, 0) * -26px), 0);
}

.demo__caption {
  margin-top: 1.4rem;
  font-size: 0.6875rem;
  color: var(--ink-mute);
}

/* ── The pair ── */
.duo {
  position: relative;
  height: calc(var(--term-h) * (1 + var(--lift)));
}

/* Lines wait here until the session clock reaches them. */
.duo [data-at][hidden] {
  display: none;
}

/* Without the clock (reduced motion) only the finished session shows, so
   nothing that lasts a while: a spinner, a wait, a thread a newer one replaced. */
.duo:not(.is-live) [data-until] {
  display: none;
}

.term {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--term-w);
  height: var(--term-h);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 10px;
  background: var(--screen);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.07),
    0 2.25rem 3.5rem -1.75rem rgba(24, 18, 10, 0.55);
  transform-origin: 100% 0;
  transition:
    transform var(--dur-swap) var(--ease),
    filter var(--dur-swap) var(--ease);
}

/* Front and back are states of the pair, so a switch never touches the transcript. */
.duo[data-front='agent'] .term--agent,
.duo[data-front='frank'] .term--frank {
  z-index: 2;
  transform: translate3d(0, calc(var(--term-h) * var(--lift)), 0);
}

.duo[data-front='agent'] .term--frank,
.duo[data-front='frank'] .term--agent {
  z-index: 1;
  transform: translate3d(var(--back-x), 0, 0) scale(0.95);
  filter: brightness(0.78) saturate(0.8);
  cursor: pointer;
}

.term__bar {
  position: relative;
  display: flex;
  flex: none;
  align-items: center;
  gap: 1.1rem;
  height: 2.6rem;
  padding: 0 1rem;
  background: var(--screen-bar);
  font: 500 0.75rem/1 var(--mono);
  color: var(--screen-text);
}

.term__lights {
  display: flex;
  gap: 0.45rem;
}

.term__lights i {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: #ff5f57;
}

.term__lights i:nth-child(2) {
  background: #febc2e;
}

.term__lights i:nth-child(3) {
  background: #28c840;
}

.term__title {
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.term__app {
  color: var(--screen-mute);
}

/* Lit while the window is behind and something new has landed in it. */
.term__ping {
  width: 0.5rem;
  height: 0.5rem;
  margin-left: auto;
  border-radius: 50%;
  background: var(--mon-block);
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}

.term[data-unread] .term__ping {
  opacity: 1;
  animation: ping 1.8s ease-in-out infinite;
}

/* The same red pen circles Frank's dot while he has stepped in behind. */
.term__ring {
  position: absolute;
  top: 50%;
  /* Centred on the dot, which sits 1.25rem in from the bar's right edge. */
  right: 0.2rem;
  width: 2.1rem;
  height: 1.6rem;
  color: var(--mon-block);
  opacity: 0;
  pointer-events: none;
  translate: 0 -50%;
}

.duo[data-cue][data-front='agent'] .term--frank .term__ring {
  opacity: 1;
  animation: draw 0.6s var(--ease) both;
}

@keyframes ping {
  50% {
    box-shadow: 0 0 0 0.35rem rgba(255, 95, 95, 0.18);
  }
}

.term__body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  font: 400 0.75rem/1.55 var(--mono);
}

[data-scroll] {
  overflow-y: auto;
  scrollbar-width: none;
}

[data-scroll]::-webkit-scrollbar {
  display: none;
}

/* ── Claude Code ── */
.cc {
  padding: 0.9rem 1.1rem 0.8rem;
  color: var(--cc-text);
}

.cc__log {
  flex: 1;
  min-height: 0;
}

.cc__log > * + * {
  margin-top: 0.6rem;
}

.cc__prompt {
  padding: 0.15rem 0.55rem;
  background: rgba(255, 255, 255, 0.07);
}

/* Hanging indent, not flex: the tool name and its arguments wrap as one run. */
.cc__line {
  padding-left: 1.3rem;
  text-indent: -1.3rem;
}

.cc__line b {
  font-weight: 600;
}

.cc__dot {
  display: inline-block;
  width: 1.3rem;
  text-indent: 0;
}

.cc__dot--ok {
  color: var(--cc-ok);
}

.cc__dot--error {
  color: var(--cc-error);
}

/* A call still waiting on its result blinks grey, then takes its outcome's colour. */
.cc__tool:has(> .cc__out[hidden]) .cc__dot {
  color: var(--cc-dim);
  animation: cc-blink 1s step-end infinite;
}

@keyframes cc-blink {
  50% {
    opacity: 0.25;
  }
}

/* A result wraps under its text, not under the ⎿. */
.cc__out {
  padding-left: calc(1.25rem + 3ch);
  text-indent: -3ch;
  color: var(--cc-dim);
}

.cc__out--error {
  color: var(--cc-error);
}

/* Frank in the agent's window, as Claude Code shows him, less the hook
   plumbing (the PreToolUse error line, the instruction to the agent, the
   rule). Every notice refuses a call, so its dot is red; the result is the
   block's marker in red, then Frank's reason as plain result text. A message
   to Frank is an ordinary MCP call with the message in its arguments, and his
   reply is its plain result, a release included. */
.cc__marker {
  color: var(--cc-error);
}

.cc__out--hook > p + p {
  text-indent: 0;
}

/* The spinner over the input box, its verb changing as the turn wears on. It
   carries no timer, since the replay compresses the clock. The row keeps its
   height between turns, so the input box never jumps. */
.cc__status {
  flex: none;
  min-height: calc(0.6rem + 1.55em);
}

.cc__spin {
  margin-top: 0.6rem;
  color: var(--cc-accent);
}

.cc__spin [data-spin] {
  display: inline-block;
  width: 1.3rem;
}

.cc__spin-meta {
  color: var(--cc-dim);
}

.cc__input {
  flex: none;
  margin-top: 0.75rem;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--cc-rule);
  border-radius: 6px;
  color: var(--cc-dim);
}

.cc__hint {
  flex: none;
  margin-top: 0.3rem;
  padding-left: 0.7rem;
  font-size: 0.6875rem;
  color: var(--cc-dim);
}

/* ── Frank Monitor: header bar, verdict feed, conversation panel, footer bar ── */
.mon {
  color: var(--cc-text);
}

.mon__bar {
  flex: none;
  overflow: hidden;
  padding: 0.25rem 0.6rem;
  background: var(--mon-chrome);
  color: var(--mon-chrome-text);
  white-space: pre;
  text-overflow: ellipsis;
}

/* The blank row the monitor keeps under its header. */
.mon__bar:first-child {
  margin-bottom: 1.55em;
}

.mon__title {
  font-weight: 700;
  color: var(--white);
}

/* Once there is a conversation, the focused pane's title is bracketed. */
.mon:has(.mon__panel:not([hidden])) .mon__title::before {
  content: '[';
}

.mon:has(.mon__panel:not([hidden])) .mon__title::after {
  content: ']';
}

/* Followed into a conversation, the focus moves to the panel, so the brackets
   and the bright title move with it, as monitor.py draws a focused pane. */
.duo[data-focus] .term--frank .mon__title {
  font-weight: 400;
  color: var(--mon-muted);
}

.duo[data-focus] .term--frank .mon__title::before,
.duo[data-focus] .term--frank .mon__title::after,
.mon__pane-title::before,
.mon__pane-title::after {
  content: ' ';
}

.mon__pane-title {
  color: var(--mon-muted);
}

.duo[data-focus] .term--frank .mon__pane-title {
  font-weight: 700;
  color: var(--white);
}

.duo[data-focus] .term--frank .mon__pane-title::before {
  content: '[';
}

.duo[data-focus] .term--frank .mon__pane-title::after {
  content: ']';
}

.mon__mute {
  color: var(--mon-muted);
}

.mon__flag {
  display: none;
  font-weight: 700;
  color: var(--mon-block);
}

.mon__flag--gated {
  color: var(--mon-gate);
}

.term.is-blocked .mon__flag--blocked,
.term.is-gated .mon__flag--gated {
  display: inline;
}

/* Every row is `HH:MM:SS  [TAG]  text`, the text wrapped back to its own column. */
.mon__feed {
  flex: 3 1 0;
  min-height: 0;
  padding: 0 0.6rem;
  transition: flex-grow var(--dur-swap) var(--ease);
}

.mon__row {
  display: grid;
  grid-template-columns: 10ch 17ch minmax(0, 1fr);
}

.mon__row > span:first-child {
  color: var(--mon-dim);
}

/* A plain pass is the one quiet line: dim tag, plain text. Anything else is
   coloured across tag and text together. */
.mon__row--quiet > span:nth-child(2) {
  color: var(--mon-dim);
}

/* Aged plain passes fold into one dim row per run. */
.mon__row.is-folded {
  display: none;
}

.mon__row--fold {
  color: var(--mon-dim);
}

.mon__row--gate {
  font-weight: 700;
  color: var(--mon-gate);
}

.mon__row--block {
  font-weight: 700;
  color: var(--mon-block);
}

.mon__row--release {
  font-weight: 700;
  color: var(--mon-release);
}

.mon__row--frank {
  color: var(--mon-frank);
}

.mon__row--agent {
  color: var(--mon-agent);
}

.mon__row--you {
  color: var(--mon-you);
}

/* ── The conversation panel ──
   A conversation arrives as monitor.py draws a new one: a full-width rule
   draws across, the tab strip appears, and the body rises from the bottom as
   the feed gives way. When the episode ends the body folds back to its strip.
   The panel is always laid out; only its share of the window moves, so the
   rise and the fold are one transition each way. */
.mon__panel {
  position: relative;
  display: flex;
  flex: 0 1 0;
  flex-direction: column;
  /* Folded, it keeps exactly the tab strip's height. */
  min-height: calc(1.55em + 0.5rem + 1px);
  margin-top: 0.4rem;
  padding-top: 1px;
  overflow: hidden;
  transition: flex-grow var(--dur-swap) var(--ease);
}

.mon__panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--mon-dim);
  transform-origin: 0 50%;
}

.mon__panel:not([hidden])::before {
  animation: rule-in 0.4s var(--ease) both;
}

@keyframes rule-in {
  from {
    transform: scaleX(0);
  }
}

/* While a conversation is open it is the thing to read, so it takes the
   larger share of a short window. */
.term.is-talking .mon__feed {
  flex-grow: 2;
}

.term.is-talking .mon__panel {
  flex-grow: 3;
}

/* The panel's first appearance is in the same frame as its first message, so
   it rises from nothing rather than appearing already open. */
@starting-style {
  .term.is-talking .mon__panel {
    flex-grow: 0;
  }
}

/* Followed in, it takes the whole monitor, as the panel's maximized size
   does. Before the conversation opens the feed is what to read, so it stays. */
.duo[data-focus] .term--frank.is-talking .mon__feed {
  flex-grow: 0;
}

.mon__tabs {
  flex: none;
  padding: 0.25rem 0.6rem;
  white-space: pre;
}

/* Tabs are the agent's colour. Only the newest, while it is open, carries the
   monitor's open-tab background. */
.mon__tab {
  padding: 0 1ch;
  font-weight: 700;
  background: #444444;
  color: var(--mon-agent);
}

.mon__tab:has(~ .mon__tab:not([hidden])),
.term:not(.is-talking) .mon__tab {
  font-weight: 400;
  background: none;
}

/* News the visitor hasn't followed: the monitor's own unread mark, a bold tab
   and a red dot, on the conversation it landed in. */
.mon__unread {
  display: none;
  font-weight: 700;
  color: var(--mon-block);
}

.term.is-news .mon__tab:not(:has(~ .mon__tab:not([hidden]))) {
  font-weight: 700;
}

.term.is-news .mon__tab:not(:has(~ .mon__tab:not([hidden]))) .mon__unread {
  display: inline;
  animation: unread 1.6s ease-in-out infinite;
}

@keyframes unread {
  50% {
    opacity: 0.35;
  }
}

/* The strip names its key: open a folded panel, or, while Frank has stepped
   in and the visitor hasn't followed, maximize to follow him. Then the strip
   itself is the way in. */
.mon__hint {
  display: none;
  color: var(--mon-dim);
}

.term:not(.is-talking) .mon__hint--open {
  display: inline;
}

.duo[data-cue]:not([data-focus]) .term--frank .mon__hint--open {
  display: none;
}

.duo[data-cue]:not([data-focus]) .term--frank .mon__hint--follow {
  display: inline;
  color: var(--mon-muted);
}

.duo[data-cue][data-front='frank']:not([data-focus]) .mon__tabs {
  cursor: pointer;
}

.duo[data-cue][data-front='frank']:not([data-focus]) .mon__tabs:hover .mon__hint--follow {
  color: var(--white);
}

.mon__thread {
  flex: 1;
  min-height: 0;
  padding: 0.55rem 0.6rem;
}

.mon__thread > * + * {
  margin-top: 1.55em;
}

/* Each message settles in as the body finishes rising. */
.mon__msg,
.mon__wait {
  animation: settle 0.35s var(--ease) 0.3s both;
}

@keyframes settle {
  from {
    opacity: 0;
    transform: translate3d(0, 0.4rem, 0);
  }
}

.mon__wait {
  white-space: pre-wrap;
  color: var(--mon-dim);
}

.mon__msg p {
  white-space: pre-wrap;
}

.mon__msg p + p {
  padding-left: 2ch;
}

.mon__msg b {
  font-weight: 700;
}

.mon__msg--agent {
  color: var(--mon-agent);
}

.mon__msg--frank {
  color: var(--mon-frank);
}

.mon__release {
  font-weight: 700;
  color: var(--mon-release);
}

.mon__bar--foot {
  color: var(--mon-muted);
}

/* The footer lists the conversation keys once there is a conversation, and the
   maximized panel's keys while the visitor follows one. */
.mon__keys--talk,
.mon__keys--max {
  display: none;
}

.mon:has(.mon__panel:not([hidden])) .mon__keys {
  display: none;
}

.mon:has(.mon__panel:not([hidden])) .mon__keys--talk {
  display: inline;
}

.duo[data-focus] .term--frank .mon__keys--talk {
  display: none;
}

.duo[data-focus] .term--frank .mon__keys--max {
  display: inline;
}

@media (prefers-reduced-motion: reduce) {
  .mon__panel,
  .mon__feed {
    transition: none;
  }

  .mon__panel::before,
  .mon__msg,
  .mon__wait,
  .mon__unread {
    animation: none !important;
  }
}

/* ── Stacked: copy, then the pair, with the note right under it ── */
@media (max-width: 960px) {
  .demo {
    --term-h: 23rem;
    --term-w: 90%;
    --back-x: 11.1%;
    --lift: 0.14;
    --bleed: var(--gutter);
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-template-areas:
      'copy'
      'stage';
    padding: var(--section-y) var(--gutter);
  }

  /* Room above the pair for the note, which is positioned out of the flow. */
  .demo__stage {
    margin-top: 9.5rem;
  }

  .demo__plane {
    top: -2.25rem;
    bottom: -2.25rem;
    left: 22%;
    transform: none;
  }

  /* Above the pair at its left, the text first and the arrow under it,
     flipped to curl down into the window behind. */
  .demo__control {
    top: auto;
    bottom: calc(100% + 0.4rem);
    left: 0;
    right: auto;
    width: min(16rem, 70%);
  }

  .note {
    flex-direction: column-reverse;
    gap: 0.1rem;
  }

  .note__arrow {
    scale: 1 -1;
  }
}

@media (max-width: 600px) {
  .term__body {
    font-size: 0.6875rem;
  }

  .term__app,
  .cc__spin-meta {
    display: none;
  }

  /* Too narrow for the grid: time and tag share a row, the text runs under. */
  .mon__row {
    grid-template-columns: 10ch auto;
  }

  .mon__row > span:last-child {
    grid-column: 1 / -1;
  }

  .mon__row + .mon__row {
    margin-top: 0.3rem;
  }
}

/* ── Phones: heading, then the pair as one composition, then the text. The
   agent's window takes the column; Frank's sits just behind, showing only its
   bar's top and right edge, enough for its red dot to call. ── */
@media (max-width: 767px) {
  .demo {
    --term-w: 100%;
    --back-x: 4%;
    --lift: 0.08;
    display: flex;
    flex-direction: column;
    padding-bottom: 3.5rem;
  }

  .demo__copy {
    display: contents;
  }

  /* Stretched: in the column the stage's centring would shrink the pair to
     its caption's width. */
  .demo__stage {
    order: 1;
    align-self: stretch;
  }

  .demo .prose {
    order: 2;
    margin-top: 2.5rem;
  }

  .demo .prose p + p {
    margin-top: 1rem;
  }

  /* The note sits right over the pair, so its arrow hooks off the label and
     points straight down into the window behind, and nudges downwards. */
  .note__arrow {
    display: none;
  }

  .note__arrow--down {
    display: block;
    width: 3.25rem;
    aspect-ratio: 1;
    margin-left: 0.4rem;
    scale: none;
  }

  .note[data-cue] .note__arrow--down {
    animation-name: nudge-down;
  }
}

@keyframes nudge-down {
  0%,
  70%,
  100% {
    transform: none;
  }

  80% {
    transform: translate3d(0, 5px, 0);
  }

  90% {
    transform: translate3d(0, 1px, 0);
  }
}
