.transcript {
  position: relative;
  z-index: 1;
  overflow-y: auto;
  padding: 25px 0 7px;
  min-height: 0;
  scroll-behavior: smooth;
}
.turn {
  width: min(var(--content-width), calc(100% - 56px));
  margin: 0 auto 26px;
}
/*
 * Assembly reveal. The turn keeps its layout the whole time — the flying
 * glyphs are aimed at these exact character positions — so only colour and
 * the bubble surface animate:
 *   pending    → nothing visible
 *   surfacing  → the empty bubble fades in, ready to catch the glyphs
 *   (classes off) → the text itself fades in as the glyphs fade out
 */
.turn__body {
  transition: color 260ms ease, background-color 300ms ease, border-color 300ms ease;
}
.turn--pending .turn__body {
  color: transparent;
  background-color: transparent;
  border-color: transparent;
}
.turn--pending.turn--surfacing .turn__body {
  background-color: var(--bg-raised);
  border-color: var(--border-soft);
}
.turn--user {
  display: flex;
  justify-content: flex-end;
}
.turn--user .turn__body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 82%;
  padding: 10px 14px;
  background: var(--bg-raised);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-soft);
  white-space: pre-wrap;
  word-break: break-word;
}
.turn__media {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.turn__photo {
  display: block;
  max-width: 220px;
  max-height: 160px;
  border-radius: 8px;
  object-fit: cover;
}
.turn__files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.turn__file {
  padding: 2px 8px;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-muted);
}
.turn__text { white-space: pre-wrap; }
.turn--assistant .turn__body {
  color: var(--text);
  word-break: break-word;
}
.turn__meta {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  background: var(--bg-main);
  -webkit-font-smoothing: auto;
}
.turn__body p { margin: 0 0 12px; }
.turn__body p:last-child { margin-bottom: 0; }
.turn__body ul, .turn__body ol { margin: 0 0 12px; padding-left: 22px; }
.turn__body li { margin: 4px 0; }
.turn__body h1, .turn__body h2, .turn__body h3 {
  margin: 18px 0 8px;
  font-size: 16px;
  font-weight: 600;
}
.turn__body code {
  padding: 2px 5px;
  background: var(--bg-deep);
  border-radius: 5px;
  font-family: var(--font-mono);
  font-size: 13px;
}
.turn__body pre {
  margin: 0 0 12px;
  padding: 14px 16px;
  background: var(--bg-deep);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  overflow-x: auto;
  /*
   * Reserve the scrollbar's space up front. Without it the bar appears the
   * moment a streaming line outgrows the box and disappears when the next line
   * is short, which flickers along the bottom edge of a block being typed.
   */
  scrollbar-gutter: stable;
}
.turn__body pre code {
  padding: 0;
  background: none;
  font-size: 13px;
  line-height: 1.55;
}

/* Code as a file ---------------------------------------------------------- */
/*
 * A long block is capped at a preview and offered as a download instead. The
 * bar is the file: what it is called, how big it is, and the two things anyone
 * actually wants to do with it.
 */
.code-block {
  position: relative;
  margin: 0 0 12px;
}
.code-block__bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px 7px 12px;
  background: var(--bg-raised);
  border: 1px solid var(--border-soft);
  border-bottom: none;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  font-size: 12px;
}
.code-block__name {
  font-family: var(--font-mono);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.code-block__meta {
  flex: 1;
  min-width: 0;
  color: var(--text-faint);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.code-block__actions {
  flex: none;
  display: flex;
  gap: 4px;
}
.code-block__btn {
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
  transition: background 120ms ease, color 120ms ease;
}
.code-block__btn:hover:not(:disabled) { background: var(--bg-hover-solid); color: var(--text); }
.code-block__btn:disabled { color: var(--accent); cursor: default; }

.code-block pre {
  margin: 0;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/*
 * Clipped, not hidden: enough of the file to recognise it, with the rest one
 * click away. `overflow-y` is what does the capping — `overflow-x` has to stay
 * scrollable so long lines are still reachable.
 */
.code-block.is-clipped pre {
  max-height: 320px;
  overflow-y: hidden;
}
.code-block.is-clipped::after {
  content: '';
  position: absolute;
  left: 1px;
  right: 1px;
  bottom: 1px;
  height: 90px;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  background: linear-gradient(to bottom, transparent, var(--bg-deep));
  pointer-events: none;
}
.turn__body a { color: var(--accent); }
@keyframes blink { to { visibility: hidden; } }
.turn--status .turn__body {
  color: var(--text-faint);
  font-size: 13px;
  font-style: italic;
}
.turn--error .turn__body {
  padding: 12px 16px;
  background: rgba(236, 106, 94, 0.08);
  border: 1px solid rgba(236, 106, 94, 0.35);
  border-radius: var(--radius-md);
  color: #f0b1a9;
  font-size: 14px;
}
/* Tool approval --------------------------------------------------------- */

/* The model is parked here until the user answers, so it has to be obvious. */
.approval {
  margin: 8px 0;
  padding: 12px 14px;
  border: 1px solid var(--star);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
}
.approval__question {
  color: var(--text);
  font-size: 13px;
}
.approval__detail {
  margin: 8px 0 0;
  padding: 8px 10px;
  overflow-x: auto;
  border-radius: 6px;
  background: var(--bg-deep);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.approval__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.approval__btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 12px;
}
.approval__btn:hover { background: var(--bg-hover-solid); color: var(--text); }
.approval__btn--primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--on-accent);
}
.approval__btn--danger:hover { border-color: hsl(5 60% 45%); color: hsl(5 70% 74%); }
.approval.is-allowed,
.approval.is-denied {
  padding: 8px 12px;
  border-color: var(--border-soft);
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 12px;
}
.approval.is-denied { color: hsl(5 60% 70%); }
/* Marks where older turns were summarised away. */
.compact-marker {
  margin: 14px auto;
  padding: 4px 12px;
  width: fit-content;
  border: 1px dashed var(--border);
  border-radius: 999px;
  color: var(--text-faint);
  font-size: 11px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
/* Working indicator ----------------------------------------------------- */

/* Cycling code punctuation while the model thinks. */
.thinking {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 10px 0 0;
  padding: 16px 0 8px;
  color: var(--accent);
  font-weight: 400;
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg-main);
  -webkit-font-smoothing: auto;
}
.thinking__glyphs {
  display: inline-flex;
  gap: 2px;
  min-width: 46px;
  color: var(--accent);
}
.thinking__llama {
  display: inline-block;
  width: 1em;
  height: 1em;
  flex: none;
  background-color: var(--accent);
  -webkit-mask: url('../assets/dio-thinking.png') center / contain no-repeat;
  mask: url('../assets/dio-thinking.png') center / contain no-repeat;
}
.thinking__glyph {
  display: inline-block;
  width: 10px;
  text-align: center;
  animation: glyph-pulse 1.1s ease-in-out infinite;
}
.thinking__glyph:nth-child(2) { animation-delay: 0.12s; }
.thinking__glyph:nth-child(3) { animation-delay: 0.24s; }
.thinking__glyph:nth-child(4) { animation-delay: 0.36s; }
@keyframes glyph-pulse {
  0%, 100% { opacity: 0.7; transform: translateY(0); }
  50%      { opacity: 1;   transform: translateY(-2px); }
}
.thinking__label {
  letter-spacing: 0.02em;
  color: var(--text-muted);
  font-weight: 400;
}
@media (prefers-reduced-motion: reduce) {
  .thinking__glyph { animation: none; opacity: 0.8; }
}

/* In-chat browser ------------------------------------------------------- */

/*
 * Progress rows normally live inside an assistant turn and inherit that
 * column's width. When one is created before the turn exists, or restored
 * after a repaint cleared it, it lands as a direct child of the transcript
 * instead, which has no width of its own. These rules give those rows the
 * same column so they never end up flush against the window edge.
 */
.transcript > .browser,
.transcript > .thinking,
.transcript > .approval,
.transcript > .image-grid,
.transcript > .compact-marker {
  width: min(var(--content-width), calc(100% - 56px));
  margin-left: auto;
  margin-right: auto;
}

.browser {
  display: flex;
  flex-direction: column;
  margin: 10px 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-deep);
}

.browser__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-raised);
}

.browser__url {
  flex: 1;
  min-width: 0;
  padding: 5px 10px;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  background: var(--bg-deep);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
}

.browser__url:focus { border-color: var(--accent); color: var(--text); }

.browser__btn {
  flex: none;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 12px;
}

.browser__btn:hover { background: var(--bg-hover-solid); color: var(--text); }

/* Tall enough to actually browse in, capped so it never eats the transcript. */
.browser__screen {
  display: block;
  width: 100%;
  background: #fff;
  cursor: pointer;
  outline: none;
  user-select: none;
}

.browser__status {
  flex: none;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-faint);
  font-size: 11px;
}

/*
 * Deliberately no dimming while a frame is in flight: at scroll cadence it
 * strobed. The status text carries the loading state instead.
 */
.browser.is-busy .browser__status { opacity: 0.5; }

/* Image results --------------------------------------------------------- */

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 6px;
  margin: 8px 0 14px;
}

.image-grid__item {
  display: block;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
}

.image-grid__item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 160ms ease;
}

.image-grid__item:hover img { transform: scale(1.04); }

/* Artifacts: a file, previewed ------------------------------------------- */
/*
 * A document gets a pane that runs it rather than a box that spells it out.
 * The bar names the file and holds the two views — source and preview — with
 * the active one filled in, so the pane always says which it is showing.
 */
.artifact-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 0 14px;
}

.artifact {
  background: var(--bg-deep);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.artifact__bar {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px 9px 14px;
  border-bottom: 1px solid var(--border-soft);
}

.artifact__glyph {
  flex: none;
  display: flex;
  color: var(--text-muted);
}

.artifact__title {
  flex: 1;
  min-width: 0;
  color: var(--text);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.artifact__actions {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
}

.artifact__btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--text-muted);
  transition: background 120ms ease, color 120ms ease;
}
.artifact__btn:hover { background: var(--bg-hover-solid); color: var(--text); }

/* Whichever view is on screen is the filled one. */
.artifact.is-running .artifact__btn--play,
.artifact.is-previewable:not(.is-running) .artifact__btn--code {
  background: var(--text);
  color: var(--bg-deep);
}
.artifact.is-running .artifact__btn--play:hover,
.artifact.is-previewable:not(.is-running) .artifact__btn--code:hover {
  background: var(--text);
  filter: brightness(0.92);
}

.artifact__stage { position: relative; }

.artifact__frame {
  display: block;
  width: 100%;
  height: 420px;
  border: 0;
  background: var(--bg-deep);
}
.artifact:not(.is-running) .artifact__frame { display: none; }
.artifact.is-running .artifact__source { display: none; }

.artifact__source {
  position: relative;
  max-height: 420px;
  overflow: auto;
}
.artifact__source pre {
  margin: 0;
  border: 0;
  border-radius: 0;
}

.artifact__copy {
  position: absolute;
  top: 10px;
  right: 14px;
  padding: 4px 10px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 11px;
}
.artifact__copy:hover:not(:disabled) { color: var(--text); }
.artifact__copy:disabled { color: var(--accent); cursor: default; }

/*
 * Full screen. The transcript is its own stacking context at z-index 1, and so
 * is the composer, so nothing inside the transcript can paint above the
 * composer no matter how high its own z-index goes. Raising the transcript for
 * the duration is what lets the pane cover the window — and it avoids moving
 * the artifact in the DOM, which would reload the iframe and restart whatever
 * is running inside it.
 */
body.has-artifact-full { overflow: hidden; }
body.has-artifact-full .transcript { z-index: 70; }
.artifact.is-full {
  position: fixed;
  inset: 18px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.5),
    0 10px 24px rgba(0, 0, 0, 0.4),
    0 24px 48px rgba(0, 0, 0, 0.3);
}
.artifact.is-full .artifact__stage { flex: 1; min-height: 0; }
.artifact.is-full .artifact__frame { height: 100%; }
.artifact.is-full .artifact__source { max-height: none; height: 100%; }

/* The file itself: what it is called, and the two ways to take it. */
.file-card {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  background: var(--bg-raised);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
}

.file-card__open {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  text-align: left;
  transition: background 120ms ease;
}
.file-card__open:hover { background: var(--bg-hover-solid); }

.file-card__icon {
  flex: none;
  display: flex;
  color: var(--text-muted);
}

.file-card__text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.file-card__name {
  color: var(--text);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-card__sub {
  color: var(--text-faint);
  font-size: 12px;
}

.file-card__download {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  transition: background 120ms ease, color 120ms ease;
}
.file-card__download:hover { background: var(--bg-hover-solid); color: var(--text); }
