/* UI-D (decisions item 328; board UI-D.md part 5): a marked part of a reply, the row over the message box and the
   line at the end of a reply that offers parts (D2 in-place #pick; page-strings.md). Linked only while config fork.live
   is on, after UI-A's skin, whose --ui-* tokens and .ui-ib buttons it uses: it has no colours of its own, so light and
   dark follow the tokens. Every rule starts with body[data-fork="1"]. Nothing here changes the size or place of the
   reply's text: the mark is drawn behind it, so marking moves nothing (D1 #stray). */

/* A part the student can mark (fork-parts.js adds the class only on replies that offer parts). The pointer also makes
   iOS deliver the tap as a click. */
body[data-fork="1"] #messages .fork-part { cursor: pointer; -webkit-tap-highlight-color: transparent; }
/* A paragraph line that is only a display formula is a part of its own (fork/partscan.py): its <p> is cut into one
   block per part (fork-parts-scan.js); the <br> between them is gone, so the lines stay where they were. */
body[data-fork="1"] #messages .fork-seg { display: block; }

/* The marked part: D2 #pick's band from edge to edge (into the phone's side margins) with the 3 px rule at its left,
   behind the text; it reaches half of the 8 px between paragraphs above and below. The tint is the accent at 12 %
   (the page's own --ui-bg-2 where color-mix is missing). */
body[data-fork="1"] #messages .fork-marked { position: relative; isolation: isolate; }
body[data-fork="1"] #messages .fork-marked:not(.fork-li-split)::before,
body[data-fork="1"] #messages li.fork-marked.fork-li-split > .fork-li-own::before {
  content: ""; position: absolute; z-index: -1; pointer-events: none;
  top: calc(-1 * var(--ui-s-1)); bottom: calc(-1 * var(--ui-s-1));
  left: calc(-1 * var(--ui-gut)); right: calc(-1 * var(--ui-gut));
  background: var(--ui-bg-2); background: color-mix(in srgb, var(--ui-accent-fill) 12%, transparent);
  box-shadow: inset 3px 0 0 var(--ui-accent-fill);
}
/* A list item's band starts at the column's edge, left of its marker (coach.css indents lists by 1.5em). An item that
   holds its exchange (fork-inplace.js marks it .fork-li-split) draws the band behind its own words (.fork-li-own) only,
   not the exchange; a class, not :has(), so every browser draws it once. */
body[data-fork="1"] #messages li.fork-marked::before,
body[data-fork="1"] #messages li.fork-marked > .fork-li-own::before { left: calc(-1.5em - var(--ui-gut)); }
body[data-fork="1"] #messages li.fork-marked.fork-li-split > .fork-li-own { position: relative; isolation: isolate; }
/* A region (PA1, fork-parts-region.js): the span the student selected is drawn with the CSS Custom Highlight API, and
   its drawing block (the mark's element, .fork-region) draws no band. The highlight has colours of its own, the
   accent's at about a quarter (light) and two fifths (dark): not every engine reads a custom property inside
   ::highlight(). Where the API is missing, the browser's own selection shows it while it lasts (contract.md). */
body[data-fork="1"] #messages .fork-marked.fork-region::before,
body[data-fork="1"] #messages li.fork-marked.fork-region > .fork-li-own::before { content: none; }
body[data-fork="1"] ::highlight(fork-region) { background-color: rgba(79, 70, 229, 0.24); }
@media (prefers-color-scheme: dark) {
  body[data-fork="1"] ::highlight(fork-region) { background-color: rgba(94, 92, 230, 0.42); }
}

/* The row over the message box while a part is marked: the swatch, "About the marked part" with the heading line,
   then "?" and × (44 by 44 each, UI-A's .ui-ib); the words shrink, never the buttons (page-strings.md). */
body[data-fork="1"] .fork-part-row {
  display: flex; align-items: center; gap: var(--ui-s-2); min-height: var(--ui-hit); padding: 0 0 0 var(--ui-gut);
  border-bottom: 1px solid var(--ui-line); font-family: var(--ui-font); color: var(--ui-ink);
}
body[data-fork="1"] .fork-part-swatch {
  flex: none; width: 12px; height: 18px;
  background: var(--ui-bg-2); background: color-mix(in srgb, var(--ui-accent-fill) 12%, transparent);
  box-shadow: inset 3px 0 0 var(--ui-accent-fill);
}
body[data-fork="1"] .fork-part-words { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
body[data-fork="1"] .fork-part-t1 {
  font-size: var(--ui-t-sub); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* "Under “…”": the heading is cut with an ellipsis inside the quotes, so the closing ” stays. */
body[data-fork="1"] .fork-part-t2 {
  display: flex; min-width: 0; white-space: nowrap; font-size: var(--ui-t-foot); color: var(--ui-ink-2);
}
body[data-fork="1"] .fork-part-cut { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
body[data-fork="1"] .fork-part-cut .katex { font-size: 1em; }
body[data-fork="1"] .fork-part-row .fork-part-ask { font-size: var(--ui-t-head); font-weight: 700; color: var(--ui-accent); }
body[data-fork="1"] .fork-part-row .fork-part-x { font-size: var(--ui-t-head); color: var(--ui-ink-2); }

/* The line at the end of a reply that offers parts (5a, 5b): a quiet button, 44 px tall. `.quiet` hides it from sight
   (not from screen readers) until it has the focus or the student is choosing a part from it. */
body[data-fork="1"] #messages .fork-part-hint {
  display: flex; align-items: center; box-sizing: border-box; width: 100%; min-height: var(--ui-hit); margin: 0;
  padding: 0; border: 0; border-radius: var(--ui-r-1); background: none; box-shadow: none; color: var(--ui-ink-2);
  font-family: var(--ui-font); font-size: var(--ui-t-foot); font-weight: 400; line-height: 1.3; text-align: left;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
body[data-fork="1"] #messages .fork-part-hint.quiet:not(:focus):not(.choosing) {
  position: absolute; width: 1px; height: 1px; min-height: 0; overflow: hidden; clip: rect(0 0 0 0);
  clip-path: inset(50%); white-space: nowrap;
}
body[data-fork="1"] #messages .fork-part-hint:focus-visible,
body[data-fork="1"] #messages .fork-part[role="option"]:focus-visible {
  outline: 3px solid var(--ui-accent); outline-offset: 2px;
}

/* ---- The exchange under a part (fork-inplace.js; D2 in-place #answer): the 3 px rule at its left in the page's side
   margin (on a wide screen, 12 px in from the column's edge), the student's questions in UI-A's tinted bubble at the
   right, Coach's answers unboxed across the width, "Hide this answer" at the end. A list item's exchange is inside
   the item, after its own words (coach.css indents lists by 1.5em), drawn from the column's edge. ---- */
body[data-fork="1"] #messages .fork-ex {
  display: block; margin: var(--ui-s-1) 0 var(--ui-s-3) calc(-1 * var(--ui-gut));
  padding: 0 0 0 max(var(--ui-gut), var(--ui-s-3)); box-shadow: inset 3px 0 0 var(--ui-accent-fill);
  white-space: normal; font-family: var(--ui-font); color: var(--ui-ink);
}
body[data-fork="1"] #messages .markdown-content li > .fork-ex { margin-left: calc(-1.5em - var(--ui-gut)); }
body[data-fork="1"] #messages .fork-ex-body { display: flex; flex-direction: column; gap: var(--ui-s-3); padding: var(--ui-s-2) 0 0; }
body[data-fork="1"] #messages .fork-ex-body[hidden] { display: none; }
body[data-fork="1"] #messages .fork-ex-body > .bubble.user { margin: 0; }
body[data-fork="1"] #messages .fork-ex-foot { display: flex; justify-content: flex-end; }
body[data-fork="1"] #messages .fork-ex-foot[hidden] { display: none; }
/* The folded exchange: one row, "You asked: …" cut at its end, a 44 px tap target with a small triangle. */
body[data-fork="1"] #messages .fork-ex-row {
  display: flex; align-items: center; gap: var(--ui-s-2); box-sizing: border-box; width: 100%; min-height: var(--ui-hit);
  margin: 0; padding: 0; border: 0; border-radius: 0; background: none; box-shadow: none; color: var(--ui-ink-2);
  font-family: var(--ui-font); font-size: var(--ui-t-sub); font-weight: 400; line-height: 1.3; text-align: left;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
body[data-fork="1"] #messages .fork-ex-row[hidden] { display: none; }
body[data-fork="1"] #messages .fork-ex-row:focus-visible { outline: 3px solid var(--ui-accent); outline-offset: -3px; border-radius: var(--ui-r-1); }
body[data-fork="1"] #messages .fork-ex-tri {
  flex: none; width: 0; height: 0; border-style: solid; border-width: 5px 0 5px 7px;
  border-color: transparent transparent transparent currentColor;
}
body[data-fork="1"] #messages .fork-ex-t { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body[data-fork="1"] #messages .fork-ex-t b { font-weight: 600; color: var(--ui-ink); }

/* A question drawn in time order with the part it is about quoted above it (P2): the label, then Coach's words under
   a rule. */
body[data-fork="1"] #messages .fork-quote { margin: 0; font-family: var(--ui-font); color: var(--ui-ink-2); white-space: normal; }
body[data-fork="1"] #messages .fork-quote-label { margin: 0; font-size: var(--ui-t-foot); }
body[data-fork="1"] #messages .fork-quote-text {
  margin: var(--ui-s-1) 0 0; padding: 0 0 0 var(--ui-s-3); border-left: 3px solid var(--ui-line-2);
  color: var(--ui-ink-2); font-size: var(--ui-t-sub);
}
/* A turn held until the reply it is about is on the page (history paging, P3). */
body[data-fork="1"] #messages .fork-wait { display: none !important; }
/* The exchange's first question takes the focus when the folded row opens (page-strings.md build notes); it is not a
   control, so it shows no ring. */
body[data-fork="1"] #messages .fork-ex-body > .bubble.user[tabindex="-1"]:focus { outline: none; }

/* ---- Scrolling (fork-scroll.js; brief part 9) ---- */
/* c) The page holds the text being read still itself, on every browser (iOS Safari has no scroll anchoring), so the
   browser's own anchoring is off on the fork's scroller: #messages in the app shell, the root otherwise (the one rule
   here that cannot start with body[data-fork="1"]). coach.css switched it off only during a turn (body.reading-reply). */
body[data-fork="1"] #messages { overflow-anchor: none; }
html:has(> body[data-fork="1"]) { overflow-anchor: none; }
/* d) Latest in the message box's row, between the box and the microphone (D2 change 3): a quiet button 44 px high that
   takes no height of its own; fork-scroll.js shows it ("Latest", "Answer above / below", "Back"), and hides it while a
   part is marked unless it reads "Answer above / below" (D1; page-strings build notes). Its side padding is the
   smallest step, so the box keeps what room it can at 360 and 390 px with the microphone shown (browser check S8). */
body[data-fork="1"] #compose .compose-row > #latest {
  position: static; left: auto; bottom: auto; transform: none; z-index: auto; flex: none;
  display: inline-flex; align-items: center; justify-content: center; box-sizing: border-box;
  min-width: var(--ui-hit); height: var(--ui-hit); min-height: var(--ui-hit); margin: 0; padding: 0 var(--ui-s-1);
  border: 0; border-radius: var(--ui-r-2); background: none; box-shadow: none; color: var(--ui-ink);
  font: 600 var(--ui-t-sub)/1.2 var(--ui-font); white-space: nowrap;
}
body[data-fork="1"] #compose .compose-row > #latest:active { background: var(--ui-bg-3); filter: none; }
body[data-fork="1"] #compose .compose-row > #latest:focus-visible { outline: 3px solid var(--ui-accent); outline-offset: -3px; }
@media (hover: hover) and (pointer: fine) {
  body[data-fork="1"] #compose .compose-row > #latest:hover { background: var(--ui-bg-2); }
}
/* a) "↑ Back to where you were reading" under a reply (10c): one line at the start of the column. */
body[data-fork="1"] #messages .fork-back { align-self: flex-start; gap: var(--ui-s-1); margin: 0; text-align: left; }
