/* ============================================================
   Transcript player
   ------------------------------------------------------------
   Neutral chat look. Nothing here imitates any one product.
   The model is named in the label only. Tokens are prefixed
   --tp- and fall back to the site's shared tokens, so the
   player works whether or not a page inherits /style.css.
   ============================================================ */

/* .tp-scope gives the same tokens to controls that live outside a player,
   such as the bar above a side-by-side comparison. */
.tp, .tp-scope {
  --tp-bg: var(--surface, #fff);
  --tp-bg-2: var(--surface-2, #f0f2f4);
  --tp-border: var(--border, #dde1e6);
  --tp-text: var(--text, #111418);
  --tp-muted: var(--muted, #64748b);
  --tp-accent: var(--accent, #1a5cb8);
  --tp-accent-bg: var(--accent-bg, #eef3fb);
  --tp-user-bg: var(--accent-bg, #eef3fb);
  --tp-ai-bg: var(--surface-2, #f0f2f4);
  --tp-note-bg: var(--check-bg, #fef3c7);
  --tp-note-text: var(--check, #92400e);
  --tp-fab: var(--fab, #b91c1c);            /* fabricated: red */
  --tp-fab-bg: var(--fab-bg, #fee2e2);
  --tp-check: var(--check, #92400e);        /* worth checking: amber */
  --tp-check-bg: var(--check-bg, #fef3c7);
  --tp-good: var(--good, #166534);          /* correct, or well handled: green */
  --tp-good-bg: var(--good-bg, #dcfce7);
  --tp-radius: var(--radius, 14px);
  --tp-radius-sm: var(--radius-sm, 8px);
  --tp-font: var(--font-sans, var(--font-body, system-ui, sans-serif));
  --tp-mono: var(--font-mono, ui-monospace, monospace);
}
.tp {
  font-family: var(--tp-font);
  color: var(--tp-text);
  background: var(--tp-bg);
  border: 1px solid var(--tp-border);
  border-radius: var(--tp-radius);
  display: flex;
  flex-direction: column;
  max-width: 100%;
  overflow: hidden;
}

/* ---------- header ---------- */
.tp-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--tp-border);
  background: var(--tp-bg-2);
}
.tp-title { font-weight: 600; font-size: 0.95rem; }
.tp-label {
  font-family: var(--tp-mono);
  font-size: 0.78rem;
  color: var(--tp-muted);
}

/* ---------- log ---------- */
.tp-log {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  min-height: 120px;
}

.tp-msg {
  display: grid;
  grid-template-columns: 3.2rem 1fr;
  gap: 10px;
  align-items: start;
  animation: tp-arrive 240ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes tp-arrive {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.tp-who {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--tp-muted);
  padding-top: 10px;
  text-align: right;
}

.tp-body {
  position: relative;   /* annotation notes are positioned within the body */
  border-radius: var(--tp-radius-sm);
  padding: 10px 14px;
  line-height: 1.55;
  font-size: 0.95rem;
  min-width: 0;
  overflow-wrap: anywhere;
}
.tp-msg--user .tp-body { background: var(--tp-user-bg); }
.tp-msg--assistant .tp-body { background: var(--tp-ai-bg); }
.tp-msg--note .tp-body {
  background: var(--tp-note-bg);
  color: var(--tp-note-text);
  font-size: 0.9rem;
}
.tp-msg--note .tp-who { color: var(--tp-note-text); }

.tp-body p + p,
.tp-body p + ol, .tp-body p + ul,
.tp-body ol + p, .tp-body ul + p { margin-top: 0.6em; }
.tp-body ol, .tp-body ul { padding-left: 1.4em; }
.tp-body li + li { margin-top: 0.25em; }
.tp-body .tp-h { font-weight: 700; margin-top: 0.9em; }
.tp-body .tp-h:first-child { margin-top: 0; }
.tp-body blockquote {
  margin: 0.6em 0;
  padding: 4px 12px;
  border-left: 3px solid var(--tp-border);
  color: var(--tp-muted);
}
.tp-body .tp-link { color: var(--tp-accent); text-decoration: underline; text-underline-offset: 2px; }
.tp-body .tp-img {
  display: inline-block;
  padding: 2px 10px;
  margin: 2px 4px 2px 0;
  font-size: 0.78rem;
  color: var(--tp-muted);
  border: 1px dashed var(--tp-border);
  border-radius: 6px;
}
.tp-table { overflow-x: auto; margin: 0.6em 0; }
.tp-table table { border-collapse: collapse; font-size: 0.88em; min-width: 100%; }
.tp-table th, .tp-table td { border: 1px solid var(--tp-border); padding: 5px 9px; text-align: left; vertical-align: top; }
.tp-table th { background: color-mix(in srgb, currentColor 5%, transparent); }
.tp-refs { margin-top: 0.8em; font-size: 0.82em; color: var(--tp-muted); }
.tp-refs-title { font-weight: 700; margin-bottom: 0.2em; }
.tp-refs ol { list-style: none; padding-left: 0; }
.tp-body code {
  font-family: var(--tp-mono);
  font-size: 0.88em;
  background: color-mix(in srgb, currentColor 8%, transparent);
  padding: 0.05em 0.35em;
  border-radius: 4px;
}

/* Blocks the stream has not reached yet. */
.tp-body [data-empty] { display: none; }

/* A blinking cursor that follows the writing point while it streams. */
.tp-cursor {
  display: inline-block;
  width: 0.55em;
  height: 1em;
  margin-left: 2px;
  vertical-align: -0.15em;
  background: currentColor;
  opacity: 0.7;
  animation: tp-blink 900ms steps(2, start) infinite;
}
@keyframes tp-blink { to { visibility: hidden; } }

/* ---------- annotations ---------- */
/* Rendered as <mark>. Invisible until the stream reaches them, then
   underlined in their kind's colour. The note shows on hover or focus
   and is also available to the page through the tp:annotation event. */
.tp-ann {
  background: transparent;
  color: inherit;
  text-decoration: none;
  border-radius: 2px;
  transition: background 320ms ease;
}
.tp-ann.is-revealed {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
  text-decoration-color: var(--tp-ann-color);
  background: var(--tp-ann-bg);
}
.tp-ann--fabricated { --tp-ann-color: var(--tp-fab); --tp-ann-bg: var(--tp-fab-bg); }
.tp-ann--check { --tp-ann-color: var(--tp-check); --tp-ann-bg: var(--tp-check-bg); }
.tp-ann--good { --tp-ann-color: var(--tp-good); --tp-ann-bg: var(--tp-good-bg); }
.tp-ann--note { --tp-ann-color: var(--note, var(--tp-accent)); --tp-ann-bg: var(--note-bg, var(--tp-accent-bg)); }

.tp-ann.is-revealed[data-note] { cursor: help; }
.tp-ann.is-revealed[data-note]:hover::after,
.tp-ann.is-revealed[data-note]:focus-visible::after,
.tp-ann.is-revealed[data-note].is-open::after {
  content: attr(data-note);
  position: absolute;
  left: var(--tp-note-x, 0);
  top: var(--tp-note-y, 100%);
  z-index: 2;
  width: max-content;
  max-width: min(28rem, 100%);
  padding: 8px 10px;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--tp-text);
  background: var(--tp-bg);
  border: 1px solid var(--tp-ann-color);
  border-radius: var(--tp-radius-sm);
  box-shadow: var(--shadow-md, 0 6px 18px rgba(0, 0, 0, 0.12));
  text-decoration: none;
  font-weight: 400;
}
@media (max-width: 600px) {
  /* On a phone the note becomes a sheet at the bottom of the screen. */
  .tp-ann.is-revealed[data-note]:hover::after,
  .tp-ann.is-revealed[data-note]:focus-visible::after,
  .tp-ann.is-revealed[data-note].is-open::after {
    position: fixed;
    left: 12px;
    right: 12px;
    top: auto;
    bottom: 12px;
    min-width: 0;
    max-width: none;
    font-size: 0.9rem;
  }
}

/* ---------- choice ---------- */
.tp-choice {
  border: 1px dashed var(--tp-border);
  border-radius: var(--tp-radius-sm);
  padding: 12px 14px;
  animation: tp-arrive 240ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
.tp-choice-prompt { font-weight: 600; margin-bottom: 8px; font-size: 0.92rem; }
.tp-choice-options { display: flex; flex-wrap: wrap; gap: 8px; }
.tp-choice.is-chosen { opacity: 0.75; }

/* ---------- controls ---------- */
.tp-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--tp-border);
  background: var(--tp-bg-2);
}
.tp-speed { display: inline-flex; gap: 2px; margin-left: auto; }

.tp-btn {
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--tp-text);
  background: var(--tp-bg);
  border: 1px solid var(--tp-border);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  min-height: 36px;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}
.tp-btn:hover:not(:disabled) { border-color: var(--tp-accent); }
.tp-btn:active:not(:disabled) { transform: translateY(1px); }
.tp-btn:disabled { opacity: 0.45; cursor: default; }
.tp-btn:focus-visible { outline: 2px solid var(--tp-accent); outline-offset: 2px; }
.tp-btn--play { background: var(--tp-accent); color: #fff; border-color: var(--tp-accent); }
.tp-btn--speed { padding: 6px 10px; font-weight: 500; }
.tp-btn--speed.is-active { background: var(--tp-accent-bg); border-color: var(--tp-accent); color: var(--tp-accent); }
.tp-btn--option { background: var(--tp-bg); text-align: left; }
.tp-btn--option.is-picked { background: var(--tp-accent-bg); border-color: var(--tp-accent); opacity: 1; }

/* ---------- footer ---------- */
.tp-footer:empty { display: none; }
.tp-footer {
  padding: 8px 16px 12px;
  font-size: 0.75rem;
  color: var(--tp-muted);
  background: var(--tp-bg-2);
}
.tp-placeholder {
  color: var(--tp-fab);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tp--placeholder { border-style: dashed; }

/* ---------- small screens ---------- */
@media (max-width: 480px) {
  .tp-msg { grid-template-columns: 1fr; gap: 2px; }
  .tp-who { text-align: left; padding-top: 0; }
  .tp-log, .tp-header, .tp-controls { padding-left: 12px; padding-right: 12px; }
  .tp-speed { margin-left: 0; }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .tp-msg, .tp-choice { animation: none; }
  .tp-cursor { animation: none; }
  .tp-ann { transition: none; }
}
