@import "tokens.css";

.pipeline-page {
  max-width: 52rem;
}

/* The status panel (MBB-026): Second Look's role table, on the book's own
   light and dark tokens. Serif 22px title; sans 15px for steps, labels and the
   status line; mono 28px for a measured count, nothing else in mono. No card
   around each figure and no colour on a normal count: a hairline separates the
   figures from the steps, space carries the rest (ITV brand 8.1). */
/* Type roles (book_design_guidelines.yaml :: living_book_type_roles, MBB-054):
   the back matter uses the book's own families, never its own. Serif titles
   in Merriweather's real weights (400/700), sans labels in Inter, JetBrains
   Mono only for measured figures. Nothing under 14px; no italic sans. */

.pipeline-theater {
  border-top: 1px solid var(--border);
  padding-top: 24px;
  margin-bottom: 2rem;
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.pipeline-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 24px;
  margin-bottom: 24px;
}

.pipeline-theater .pipeline-subhead {
  margin: 0;
  font-family: var(--font-body);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-primary);
}

.pipeline-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text-muted);
}

.pipeline-state::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--step-done);
}

/* ---------------------------------------------------------------------------
   The pipeline explorer (MBB-053): how the book is maintained, one interactive
   drawing for every book (assets/js/pipeline-explorer.mjs). Colours are theme
   tokens only, so light and dark follow the reader's theme; labels use the panel's
   sans, the tooltip title the panel's serif, figures the panel's mono.
   --------------------------------------------------------------------------- */
.pipeline-explorer {
  margin: 0 0 32px;
}

.pe-stage {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--pipeline-bg);
  overflow: hidden;
  touch-action: pan-y;
  /* The drawing's own width picks the layout below, not the window. */
  container-type: inline-size;
  user-select: none;
  -webkit-user-select: none;
}
.pipeline-explorer.is-engaged .pe-stage,
.pipeline-explorer.is-zoomed .pe-stage { touch-action: none; }
.pipeline-explorer.is-zoomed .pe-stage { cursor: grab; }
.pipeline-explorer.is-zoomed .pe-stage:active { cursor: grabbing; }

.pe-svg {
  display: block;
  width: 100%;
  height: auto;
}
/* One drawing per width class. SVG text scales with the drawing, so each layout
   is shown only where its smallest text renders at 14px or more
   (book_design_guidelines.yaml :: living_book_type_roles):
     ring   viewBox 1000 wide, small text 18 units -> 14px from 780px of drawing
     column viewBox 420 wide,  small text 20 units -> 14px from 294px; capped at
            480px so the phone layout never balloons on a narrow tablet column. */
.pe-svg--ring { aspect-ratio: 1000 / 620; }
.pe-svg--column { display: none; aspect-ratio: 420 / 908; max-width: 480px; margin: 0 auto; }
@container (max-width: 779px) {
  .pe-svg--ring { display: none; }
  .pe-svg--column { display: block; }
}
.pe-center--column { font-size: 24px; }
.pe-svg--column .pe-verb,
.pe-svg--column .pe-num,
.pe-svg--column .pe-center-kicker,
.pe-svg--column .pe-feedback-label { font-size: 20px; }

.pe-track { fill: none; stroke: none; }

.pe-edge {
  fill: none;
  stroke: var(--ink-manuscript-sepia);
  stroke-width: 2.5;
  stroke-linecap: round;
}
.pe-arrowhead { fill: var(--ink-manuscript-sepia); }

.pe-feedback {
  fill: none;
  stroke: var(--ink-manuscript-sepia);
  stroke-width: 2;
  stroke-dasharray: 6 7;
  opacity: 0.85;
}
.pe-feedback-label {
  font-family: var(--font-body);
  font-size: 18px;
  font-style: italic;
  fill: var(--text-muted);
}
.pe-center-kicker {
  font-family: var(--font-ui);
  font-size: 18px;
  font-weight: 600;
  fill: var(--text-muted);
}
.pe-center {
  font-family: var(--font-body);
  font-size: 30px;
  font-weight: 700;
  fill: var(--text-primary);
}

.pe-token { fill: var(--living-pulse); opacity: 0; }

.pe-node { cursor: pointer; outline: none; }
.pe-box {
  fill: var(--bg-surface);
  stroke: var(--border);
  stroke-width: 1.5;
  transition: fill 160ms ease, stroke 160ms ease, transform 160ms ease;
}
.pe-label {
  font-family: var(--font-ui);
  font-size: 22px;
  font-weight: 600;
  fill: var(--text-primary);
}
.pe-verb {
  font-family: var(--font-ui);
  font-size: 18px;
  fill: var(--text-muted);
}
.pe-num {
  font-family: var(--font-ui);
  font-size: 18px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  fill: var(--text-muted);
}

/* Live state: done is inked, running pulses, held is amber, idle stays quiet. */
.pe-node[data-state="done"] .pe-box { stroke: var(--step-done); }
.pe-node[data-state="active"] .pe-box { stroke: var(--step-active); stroke-width: 3; }
.pe-node[data-state="held"] .pe-box { stroke: var(--step-held); stroke-width: 2.5; }
.pe-node[data-state="idle"] .pe-label { fill: var(--text-muted); }

.pe-node:hover .pe-box,
.pe-node.is-hot .pe-box {
  fill: color-mix(in srgb, var(--ink-manuscript-sepia) 16%, var(--bg-surface));
  stroke: var(--ink-manuscript-sepia);
  stroke-width: 2.5;
}
.pe-node:focus-visible .pe-box {
  stroke: var(--focus-ring);
  stroke-width: 4;
}

/* Zoom controls: inside the drawing's own corner, never a row of their own. */
.pe-zoom {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-surface);
  font-family: var(--font-ui);
}
.pe-zoom-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.pe-zoom-reset { font-size: 14px; color: var(--text-muted); }
.pe-zoom-btn:hover { background: color-mix(in srgb, var(--ink-manuscript-sepia) 14%, transparent); }
.pe-zoom-btn:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.pe-zoom-level {
  min-width: 3.4em;
  text-align: center;
  font-family: var(--font-ui);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}
.pipeline-explorer:not(.is-zoomed) .pe-zoom-reset { display: none; }

/* The tooltip card: labeled lines, number first (no info glyph anywhere). */
.pe-tip {
  position: absolute;
  z-index: 3;
  width: min(340px, calc(100% - 16px));
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-surface);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
  color: var(--text-primary);
  font-family: var(--font-ui);
  pointer-events: none;
}
.pe-tip[hidden] { display: none; }
.pe-tip p { margin: 0; }
.pe-tip-kicker {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
}
.pe-tip-title {
  margin-top: 4px !important;
  font-family: var(--font-body);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.25;
}
.pe-tip-does {
  margin-top: 8px !important;
  font-size: 15px;
  line-height: 1.5;
}
.pe-tip-stats {
  margin: 12px 0 0;
  padding: 10px 0 0;
  border-top: 1px solid var(--border);
  list-style: none;
  font-size: 14px;
  line-height: 1.6;
}
.pe-tip-stats li { font-variant-numeric: tabular-nums; }
.pe-tip-state {
  margin-top: 10px !important;
  font-size: 14px;
  color: var(--text-muted);
}
.pe-tip-state[data-state="held"] { color: var(--step-held); }

.pe-caption {
  margin-top: 12px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text-muted);
}

/* Landing: the steps rise in run order, then the loop draws itself and the run
   token starts travelling. Armed only when motion is allowed (reader.js). */
.pipeline-explorer.is-armed .pe-node { opacity: 0; transform: translateY(10px); transform-box: fill-box; }
.pipeline-explorer.is-armed .pe-edge { stroke-dasharray: 400; stroke-dashoffset: 400; }
.pipeline-explorer.is-armed .pe-edge:not(.has-head),
.pipeline-explorer.is-armed .pe-feedback:not(.has-head) { marker-end: none; }
.pipeline-explorer.is-armed .pe-feedback,
.pipeline-explorer.is-armed .pe-feedback-label { opacity: 0; }
.pipeline-explorer.is-drawn .pe-node {
  opacity: 1;
  transform: none;
  transition: opacity 420ms ease calc(var(--i) * 110ms), transform 420ms ease calc(var(--i) * 110ms);
}
.pipeline-explorer.is-drawn .pe-edge {
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 520ms ease calc(300ms + var(--i) * 140ms);
}
.pipeline-explorer.is-drawn .pe-feedback,
.pipeline-explorer.is-drawn .pe-feedback-label {
  opacity: 0.85;
  transition: opacity 600ms ease 1.5s;
}
.pipeline-explorer.is-drawn .pe-token {
  opacity: 0.9;
  transition: opacity 600ms ease 1.8s;
}
@keyframes pe-pulse {
  0%, 100% { stroke-opacity: 1; }
  50% { stroke-opacity: 0.35; }
}
.pipeline-explorer.is-drawn .pe-node[data-state="active"] .pe-box { animation: pe-pulse 1.6s ease-in-out infinite; }

@media (max-width: 640px) {
  .pe-zoom { top: 8px; right: 8px; }
  .pe-zoom-level { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .pe-token { display: none; }
}

/* A figures row with no recorded figure is left out entirely (MBB-051). */
.pipeline-stats:not(:has(.stat:not([hidden]))) { display: none; }
.pipeline-stats .stat[hidden] { display: none; }

.pipeline-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px 32px;
  margin: 0;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

@media (min-width: 640px) {
  .pipeline-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.pipeline-stats .stat {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pipeline-stats dt {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text-muted);
}

.pipeline-stats dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 500;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.pipeline-status-line {
  margin: 24px 0 0;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.45;
  color: var(--text-muted);
}

/* ============================================================
   Version history (MBB-027): the status panel's language, so the back
   matter reads as one system. Serif 22px title; sans 15px labels and text;
   mono only for a measured score; hairlines between editions, no cards, no
   tinted pills; a held or blocked count is drawn like any other count (a
   normal result is never drawn like an error); nothing under 14px.
   ============================================================ */

.vh-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 24px;
  margin-top: 2.5rem;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  margin-bottom: 24px;
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
.vh-head .backmatter-subhead {
  margin: 0;
  font-family: var(--font-body);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-primary);
}
.vh-trend {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text-muted);
}
.vh-spark {
  display: block;
  overflow: visible;
}
.vh-spark polyline {
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.vh-spark circle {
  fill: var(--text-primary);
}

/* One edit, up close: no box; a label column and the text, the after line
   carrying the only rule mark. */
.featured-change {
  margin: 0 0 32px;
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
.fc-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.fc-title {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text-muted);
}
.fc-ver,
.edition-v {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text-muted);
}
.fc-row {
  display: grid;
  grid-template-columns: 4rem minmax(0, 1fr);
  gap: 16px;
  padding: 8px 0;
}
.fc-label {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text-muted);
}
.fc-text {
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.55;
}
.fc-before .fc-text {
  color: var(--text-muted);
  text-decoration: line-through;
  text-decoration-color: color-mix(in srgb, var(--text-muted) 60%, transparent);
}
.fc-after .fc-text { color: var(--text-primary); }
.fc-note {
  margin: 12px 0 0;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text-muted);
}

/* The list: one hairline per edition, space carries the rest. */
.editions {
  list-style: none;
  padding: 0;
  margin: 0;
  border-top: 1px solid var(--border);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
.edition {
  position: relative;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
/* The summary row is the button (the open card holds links); it carries the ring. */
.edition-top:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--focus-ring);
}
.edition-top {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
}
.edition-top .edition-v {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
}
.edition-bump,
.edition-live,
.edition-date,
.edition-edits,
.edition-flag {
  font-size: 15px;
  font-weight: 400;
  line-height: 1.4;
  color: var(--text-muted);
}
.edition-live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  color: var(--text-primary);
}
.edition-live::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--step-done);
}
.edition-date { margin-left: auto; }
.edition-bot {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 20px;
}
.edition-scorewrap {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}
.edition-score {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}
/* A non-text mark (3:1, WCAG 1.4.11): the score's place on the 75-90 band. */
.edition-meter {
  display: block;
  width: 5.5rem;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
}
.edition-fill {
  display: block;
  height: 100%;
  width: var(--fill, 0%);
  border-radius: 2px;
  background: var(--text-muted);
}
.edition-run {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text-muted);
}

/* score delta vs the previous edition: the arrow carries the direction */
.edition-delta,
.edition-detail-delta {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
}
.edition-delta:empty { display: none; }

/* expand chevron */
.edition-toggle {
  width: 0.5rem;
  height: 0.5rem;
  border-right: 1.5px solid var(--text-muted);
  border-bottom: 1.5px solid var(--text-muted);
  transform: rotate(45deg);
  transition: transform 0.2s ease;
}
.edition.is-open .edition-toggle { transform: rotate(-135deg); }

/* detail, revealed on click */
.edition-detail {
  display: none;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-top: 16px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text-muted);
}
.edition.is-open .edition-detail { display: flex; }
.edition-detail-run {
  font-family: var(--font-mono);
  font-size: 14px;
}

/* per-edition before and after */
.edition-fc {
  flex-basis: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.edition-fc-label {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-muted);
}
.edition-fc-before,
.edition-fc-after {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
}
.edition-fc-before {
  color: var(--text-muted);
  text-decoration: line-through;
  text-decoration-color: color-mix(in srgb, var(--text-muted) 60%, transparent);
}
.edition-fc-after { color: var(--text-primary); }

/* load-more: the site's plain text control, sharing the list's last line */
/* One load-more style for both back-matter lists (collapseWithMore, MBB-055). */
.editions-more,
.sources-more {
  display: inline-block;
  margin: 16px 0 0;
  padding: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  background: none;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-color: var(--border);
  cursor: pointer;
}
.editions-more:hover,
.sources-more:hover { text-decoration-color: currentColor; }
.editions-more:focus-visible,
.sources-more:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--focus-ring);
}

/* ============================================================
   Sources (MBB-051): every web source research used to change a paragraph,
   with its link and a link to the paragraph it changed. Same language as the
   version history above: serif heading, sans 15px, hairlines, no cards.
   ============================================================ */
.vh-sources {
  margin-top: 2.5rem;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
.vh-sources-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 24px;
  margin-bottom: 16px;
}
.vh-sources-head .backmatter-subhead {
  margin: 0;
  font-family: var(--font-body);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-primary);
}
.vh-sources-count {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text-muted);
}
.src-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.src-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
.src-item:first-child { border-top: 1px solid var(--border); }
/* display:flex above beats the hidden attribute; collapseWithMore hides with it. */
.src-item[hidden] { display: none; }
.src-link {
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.4;
  color: var(--text-primary);
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-color: var(--border);
  overflow-wrap: anywhere;
}
.src-link:hover { text-decoration-color: currentColor; }
.src-meta {
  font-size: 15px;
  line-height: 1.4;
  color: var(--text-muted);
}
.src-para {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  margin-top: 2px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text-muted);
  text-decoration: none;
}
.src-where {
  font-weight: 500;
  color: var(--text-primary);
}
.src-ver { font-family: var(--font-mono); font-size: 14px; }
.src-quote {
  flex-basis: 100%;
  font-family: var(--font-body);
  font-size: 16px;
  font-style: italic;
}
/* A source behind several paragraphs lists each one; space separates them. */
.src-para + .src-para { margin-top: 10px; }
.src-para:hover .src-where {
  text-decoration: underline;
  text-underline-offset: 4px;
}
.src-link:focus-visible,
.src-para:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--focus-ring);
  border-radius: 2px;
}

/* inside an open edition: the same rows, tighter */
.edition-sources {
  flex-basis: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.edition-sources-label {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-muted);
}
.src-list--compact .src-item { padding: 12px 0; }
.src-list--compact .src-link { font-size: 16px; }
