/* 04_VISUAL/xwui/xwui-lib/xwui-lib-basic/src/text/XWUIAnnotatedRuns/XWUIAnnotatedRuns.css */
/*
 * Tokens only. Sizes, from the ThreadAgents artboard: underline calc(var(--spacing-unit) * 0.5) with calc(var(--spacing-unit) * 0.25) of air under the text, marker a calc(var(--spacing-unit) * 4) circle
 * calc(var(--spacing-unit) * 1.25) from the phrase, calc(var(--spacing-unit) * 2.5)/700, raised calc(var(--spacing-unit) * 0.5) (vertical-align) so it sits on the x-height of calc(var(--spacing-unit) * 3.5) body text without
 * stretching the line. Every px value lives in a custom-property definition, so a page can retune one block with
 * `.page .xwui-annotated-runs { --xwui-annotated-runs-anchor-size: ... }`. Direction: logical properties only, so RTL
 * mirrors with no extra rule. No transition on purpose: the artboards swap states instantly.
 */

/* WHY :where(): zero specificity for the structural rules, so a page utility on the same element wins. The element
   inherits the font of the paragraph it replaces: the page sets size, leading and ink on the parent. */
:where(.xwui-annotated-runs) {
  --xwui-annotated-runs-underline-w: calc(var(--spacing-unit) * 0.5);
  --xwui-annotated-runs-underline-gap: calc(var(--spacing-unit) * 0.25);
  --xwui-annotated-runs-underline-color: var(--color-purple, currentcolor);
  --xwui-annotated-runs-ink: var(--text-primary, inherit);
  --xwui-annotated-runs-strong-weight: var(--font-weight-semibold);
  --xwui-annotated-runs-anchor-size: calc(var(--spacing-unit) * 4);
  --xwui-annotated-runs-anchor-gap: calc(var(--spacing-unit) * 1.25);
  --xwui-annotated-runs-anchor-raise: calc(var(--spacing-unit) * 0.5);
  --xwui-annotated-runs-anchor-font: calc(var(--font-size-base) * 0.625);
  --xwui-annotated-runs-anchor-weight: var(--font-weight-bold);
  --xwui-annotated-runs-anchor-bg: var(--color-tag-purple-bg, transparent);
  --xwui-annotated-runs-anchor-ink: var(--color-tag-purple-text, inherit);
  --xwui-annotated-runs-hover-ring: calc(var(--spacing-unit) * 0.25);
  --xwui-annotated-runs-focus-w: calc(var(--spacing-unit) * 0.5);
  --xwui-annotated-runs-focus-offset: calc(var(--spacing-unit) * 0.5);
  --xwui-annotated-runs-forced-border-w: calc(var(--spacing-unit) * 0.25);

  display: block;
  margin: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
  overflow-wrap: break-word;
}
:where(span.xwui-annotated-runs) {
  display: inline;
}

/* ---------- runs (a doubled chain: library sheets load after ours at equal specificity) ---------- */
.xwui-annotated-runs .xwui-annotated-runs__run--primary {
  color: var(--xwui-annotated-runs-ink);
}
.xwui-annotated-runs .xwui-annotated-runs__run--strong {
  color: var(--xwui-annotated-runs-ink);
  font-weight: var(--xwui-annotated-runs-strong-weight);
}
/* An underlined phrase reads in the primary ink: the underline says "look here", the ink agrees. */
.xwui-annotated-runs .xwui-annotated-runs__run--underline {
  color: var(--xwui-annotated-runs-ink);
  padding-block-end: var(--xwui-annotated-runs-underline-gap);
  border-block-end: var(--xwui-annotated-runs-underline-w) solid
    var(--xwui-annotated-runs-underline-color);
}

/* ---------- underline colour names -> tokens ---------- */
.xwui-annotated-runs .xwui-annotated-runs__run--underline-purple {
  --xwui-annotated-runs-underline-color: var(--color-purple, currentcolor);
}
.xwui-annotated-runs .xwui-annotated-runs__run--underline-accent {
  --xwui-annotated-runs-underline-color: var(--accent-primary, currentcolor);
}
.xwui-annotated-runs .xwui-annotated-runs__run--underline-info {
  --xwui-annotated-runs-underline-color: var(--control-active, currentcolor);
}
.xwui-annotated-runs .xwui-annotated-runs__run--underline-success {
  --xwui-annotated-runs-underline-color: var(--accent-success, currentcolor);
}
.xwui-annotated-runs .xwui-annotated-runs__run--underline-warning {
  --xwui-annotated-runs-underline-color: var(
    --status-before-start,
    currentcolor
  );
}
.xwui-annotated-runs .xwui-annotated-runs__run--underline-error {
  --xwui-annotated-runs-underline-color: var(--status-error, currentcolor);
}
.xwui-annotated-runs .xwui-annotated-runs__run--underline-teal {
  --xwui-annotated-runs-underline-color: var(
    --color-tag-teal-text,
    currentcolor
  );
}
.xwui-annotated-runs .xwui-annotated-runs__run--underline-orange {
  --xwui-annotated-runs-underline-color: var(
    --color-tag-orange-text,
    currentcolor
  );
}
.xwui-annotated-runs .xwui-annotated-runs__run--underline-green {
  --xwui-annotated-runs-underline-color: var(
    --color-tag-green-text,
    currentcolor
  );
}
.xwui-annotated-runs .xwui-annotated-runs__run--underline-red {
  --xwui-annotated-runs-underline-color: var(
    --color-tag-red-text,
    currentcolor
  );
}

/* ---------- marker: the control IS the circle (button or a) ---------- */
.xwui-annotated-runs .xwui-annotated-runs__anchor,
.xwui-annotated-runs a.xwui-annotated-runs__anchor:link,
.xwui-annotated-runs a.xwui-annotated-runs__anchor:visited {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: var(--xwui-annotated-runs-anchor-size);
  block-size: var(--xwui-annotated-runs-anchor-size);
  margin: 0;
  margin-inline-start: var(--xwui-annotated-runs-anchor-gap);
  padding: 0;
  border: 0;
  border-radius: var(--radius-full, 50%);
  background: var(--xwui-annotated-runs-anchor-bg);
  color: var(--xwui-annotated-runs-anchor-ink);
  font-family: inherit;
  font-size: var(--xwui-annotated-runs-anchor-font);
  font-weight: var(--xwui-annotated-runs-anchor-weight);
  font-variant-numeric: tabular-nums;
  /* WHY inherit and not 1: the artboard marker is a span that inherits the paragraph's leading, and its baseline (and
     so its calc(var(--spacing-unit) * 0.1875) of vertical position against the phrase) depends on it; the calc(var(--spacing-unit) * 4) box itself fixes the line height. */
  line-height: inherit;
  letter-spacing: normal;
  text-decoration: none;
  vertical-align: var(--xwui-annotated-runs-anchor-raise);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.xwui-annotated-runs .xwui-annotated-runs__anchor:hover {
  box-shadow: 0 0 0 var(--xwui-annotated-runs-hover-ring)
    var(--xwui-annotated-runs-anchor-ink);
}
.xwui-annotated-runs .xwui-annotated-runs__anchor:focus-visible {
  outline: var(--xwui-annotated-runs-focus-w) solid
    var(--control-active, currentcolor);
  outline-offset: var(--xwui-annotated-runs-focus-offset);
}

/* ---------- marker tones: bg + ink pairs, all from tokens ---------- */
.xwui-annotated-runs .xwui-annotated-runs__anchor--purple {
  --xwui-annotated-runs-anchor-bg: var(--color-tag-purple-bg, transparent);
  --xwui-annotated-runs-anchor-ink: var(--color-tag-purple-text, inherit);
}
.xwui-annotated-runs .xwui-annotated-runs__anchor--teal {
  --xwui-annotated-runs-anchor-bg: var(--color-tag-teal-bg, transparent);
  --xwui-annotated-runs-anchor-ink: var(--color-tag-teal-text, inherit);
}
.xwui-annotated-runs .xwui-annotated-runs__anchor--orange {
  --xwui-annotated-runs-anchor-bg: var(--color-tag-orange-bg, transparent);
  --xwui-annotated-runs-anchor-ink: var(--color-tag-orange-text, inherit);
}
.xwui-annotated-runs .xwui-annotated-runs__anchor--green {
  --xwui-annotated-runs-anchor-bg: var(--color-tag-green-bg, transparent);
  --xwui-annotated-runs-anchor-ink: var(--color-tag-green-text, inherit);
}
.xwui-annotated-runs .xwui-annotated-runs__anchor--red {
  --xwui-annotated-runs-anchor-bg: var(--color-tag-red-bg, transparent);
  --xwui-annotated-runs-anchor-ink: var(--color-tag-red-text, inherit);
}
.xwui-annotated-runs .xwui-annotated-runs__anchor--accent {
  --xwui-annotated-runs-anchor-bg: var(--accent-primary, currentcolor);
  --xwui-annotated-runs-anchor-ink: var(--accent-primary-ink, inherit);
}
.xwui-annotated-runs .xwui-annotated-runs__anchor--neutral {
  --xwui-annotated-runs-anchor-bg: var(--bg-active, transparent);
  --xwui-annotated-runs-anchor-ink: var(--text-secondary, inherit);
}

/* High-contrast mode drops author fills and underline colours: keep the marker a visible ring and the phrase underlined. */
@media (forced-colors: active) {
  .xwui-annotated-runs .xwui-annotated-runs__anchor {
    border: var(--xwui-annotated-runs-forced-border-w) solid ButtonText;
  }
  .xwui-annotated-runs .xwui-annotated-runs__run--underline {
    border-block-end-color: LinkText;
  }
}
