/* Affable Dissonances reusable rich-text / literary-flow control.
   Light DOM is deliberate: existing page CSS remains authoritative. */
ad-rich-text {
  --ad-rt-measure: var(--measure-reading, 62ch);
  --ad-rt-poetry-measure: var(--measure-narrow, 44ch);
  --ad-rt-wide-measure: min(78rem, 100%);
  --ad-rt-font: var(--font-reading, Georgia, serif);
  --ad-rt-heading-font: var(--font-display, Georgia, serif);
  --ad-rt-text: var(--ink, currentColor);
  --ad-rt-muted: var(--ink-faint, currentColor);
  --ad-rt-line: var(--line, currentColor);
  --ad-rt-accent: var(--accent-gold, currentColor);
  --ad-rt-block-gap: 1.18em;
  --ad-rt-section-gap: clamp(1.8rem, 4vw, 3.4rem);
  --ad-rt-image-radius: var(--radius-md, .65rem);
  display: block;
  min-inline-size: 0;
  color: inherit;
  font: inherit;
}

ad-rich-text > .ad-rich-text__flow {
  display: flow-root;
  min-inline-size: 0;
}

/* Shared Affable reading contract.
   Both generated blocks and authored Light-DOM body copy use the same reading
   face and prose alignment. Light DOM remains deliberate so page-specific CSS
   can still control geometry while typography stays consistent site-wide. */
ad-rich-text :where(.ad-rich-text__paragraph, .ad-rich-text__heading, .ad-rich-text__quote,
  .ad-rich-text__verse, .ad-rich-text__separator) {
  inline-size: min(100%, var(--ad-rt-measure));
  margin-inline: auto;
}

ad-rich-text :where(p, .ad-rich-text__paragraph) {
  color: var(--ad-rt-text);
  font-family: var(--ad-rt-font);
  font-size: var(--editorial-body-size, 1rem);
  line-height: var(--lh-body, 1.62);
  overflow-wrap: break-word;
  text-align: justify;
  text-justify: inter-word;
  text-align-last: auto;
  text-wrap: pretty;
  hyphens: auto;
  orphans: 3;
  widows: 3;
}

ad-rich-text .ad-rich-text__paragraph { margin-block: 0; }

/* Poetry is authored lineation, never prose justification. The runtime marks
   poem hosts with data-mode="poetry"; Chamber quotations use the same mode. */
ad-rich-text[data-mode="poetry"] :where(p, .ad-rich-text__paragraph, .ad-rich-text__verse, blockquote) {
  text-align: start;
  text-justify: auto;
  hyphens: manual;
}

ad-rich-text .ad-rich-text__paragraph + .ad-rich-text__paragraph {
  margin-block-start: var(--ad-rt-block-gap);
}

ad-rich-text .ad-rich-text__heading {
  margin-block: var(--ad-rt-section-gap) .7em;
  color: inherit;
  font-family: var(--ad-rt-heading-font);
  font-weight: 500;
  line-height: 1.16;
  letter-spacing: -.015em;
  text-wrap: balance;
}

ad-rich-text h2.ad-rich-text__heading { font-size: clamp(1.65rem, 1.24rem + 1.1vw, 2.65rem); }
ad-rich-text h3.ad-rich-text__heading { font-size: clamp(1.35rem, 1.12rem + .65vw, 1.9rem); }
ad-rich-text h4.ad-rich-text__heading { font-size: clamp(1.12rem, 1rem + .32vw, 1.42rem); }
ad-rich-text :where(strong) { font-weight: 600; }
ad-rich-text :where(em) { font-style: italic; }

ad-rich-text .ad-rich-text__verse {
  max-inline-size: var(--ad-rt-poetry-measure);
  margin-block: var(--ad-rt-section-gap);
  font-family: var(--ad-rt-heading-font);
  font-size: clamp(1.08rem, 1rem + .3vw, 1.38rem);
  line-height: var(--lh-poetry, 1.48);
  overflow-wrap: anywhere;
}
ad-rich-text .ad-rich-text__line { white-space: pre-wrap; }

ad-rich-text :where(blockquote, .ad-rich-text__quote) {
  font-family: var(--ad-rt-font);
}

/* Quoted prose is still prose. Keep it on the same selected reading face and
   justification contract; poetry-mode quotations (including the Chamber) are
   explicitly restored to authored lineation by the poetry rule above. */
ad-rich-text[data-mode="prose"] :where(blockquote, .ad-rich-text__quote) {
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
}

ad-rich-text .ad-rich-text__quote {
  margin-block: var(--ad-rt-section-gap);
  padding-inline-start: clamp(1rem, 3vw, 1.6rem);
  border-inline-start: 1px solid var(--ad-rt-accent);
  color: var(--ad-rt-muted);
  font-family: var(--ad-rt-heading-font);
  font-size: 1.12em;
  font-style: italic;
}

ad-rich-text .ad-rich-text__separator {
  border: 0;
  border-block-start: 1px solid var(--ad-rt-line);
  margin-block: var(--ad-rt-section-gap);
}

ad-rich-text .ad-rich-text__figure {
  inline-size: min(100%, var(--ad-rt-measure));
  margin: var(--ad-rt-section-gap) auto;
}
ad-rich-text .ad-rich-text__figure[data-placement="wide"] { inline-size: var(--ad-rt-wide-measure); }
ad-rich-text .ad-rich-text__figure[data-placement="full"] { inline-size: 100%; }
ad-rich-text .ad-rich-text__image {
  display: block;
  inline-size: 100%;
  max-inline-size: 100%;
  block-size: auto;
  border-radius: var(--ad-rt-image-radius);
}
ad-rich-text .ad-rich-text__caption {
  margin-block-start: .7rem;
  color: var(--ad-rt-muted);
  font-size: .82em;
  line-height: 1.45;
  text-align: center;
  text-wrap: pretty;
}
ad-rich-text .ad-rich-text__media-slot {
  display: grid;
  min-block-size: clamp(10rem, 30vw, 18rem);
  place-items: center;
  padding: 1.25rem;
  border: 1px dashed var(--ad-rt-line);
  border-radius: var(--ad-rt-image-radius);
  background: color-mix(in srgb, var(--ad-rt-text) 3%, transparent);
  color: var(--ad-rt-muted);
  text-align: center;
}
ad-rich-text .ad-rich-text__media-slot-label {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: .72rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

ad-rich-text .ad-rich-text__figure[data-placement="float-start"],
ad-rich-text .ad-rich-text__figure[data-placement="float-end"] {
  inline-size: min(42%, 20rem);
  margin-block: .4rem 1.25rem;
}
ad-rich-text .ad-rich-text__figure[data-placement="float-start"] { float: inline-start; margin-inline-end: 1.4rem; }
ad-rich-text .ad-rich-text__figure[data-placement="float-end"] { float: inline-end; margin-inline-start: 1.4rem; }

@media (max-width: 44rem) {
  ad-rich-text { --ad-rt-block-gap: 1.05em; --ad-rt-section-gap: clamp(1.5rem, 8vw, 2.4rem); }
  ad-rich-text .ad-rich-text__figure[data-placement="float-start"],
  ad-rich-text .ad-rich-text__figure[data-placement="float-end"] {
    float: none;
    inline-size: min(100%, var(--ad-rt-measure));
    margin-inline: auto;
  }
}

@media print {
  ad-rich-text { --ad-rt-text:#111; --ad-rt-muted:#444; --ad-rt-line:#bbb; --ad-rt-measure:100%; --ad-rt-wide-measure:100%; }
  ad-rich-text .ad-rich-text__figure { break-inside: avoid; }
}

/* Adjacent quoted dialogue turns remain one semantic paragraph while each
   speaker receives an authored visual line. This applies equally to standalone
   Work readers and Book chapter streams. */
ad-rich-text .record-text__paragraph--dialogue > .record-dialogue-turn {
  display: block;
}


/* Authoritative reading contract. Page shells may choose
   placement/available width, but they do not get to redefine prose typography. */
ad-rich-text[data-mode="prose"] {
  font-family: var(--ad-rt-font) !important;
  font-size: var(--editorial-body-size, 1rem);
  line-height: var(--lh-body, 1.62);
}
ad-rich-text[data-mode="prose"] :where(p, .ad-rich-text__paragraph, li, dd) {
  font-family: var(--ad-rt-font) !important;
  font-size: var(--editorial-body-size, 1rem) !important;
  line-height: var(--lh-body, 1.62) !important;
  text-align: justify !important;
  text-justify: inter-word !important;
  hyphens: auto !important;
  text-wrap: pretty;
}
ad-rich-text[data-mode="prose"] :where(.ad-rich-text__paragraph + .ad-rich-text__paragraph, p + p) {
  margin-block-start: var(--ad-rt-block-gap) !important;
}
ad-rich-text[data-mode="poetry"] :where(p, .ad-rich-text__paragraph, .ad-rich-text__verse, blockquote, li) {
  font-family: var(--ad-rt-font) !important;
  line-height: var(--lh-poetry, 1.48) !important;
  text-align: start !important;
  text-justify: auto !important;
  hyphens: manual !important;
}
ad-rich-text .record-text__paragraph--dialogue > .record-dialogue-turn {
  display: block !important;
}

/* Authored inline colors remain exact. A tiny opposite-luminance outline is
   applied only when runtime foreground/background contrast falls below 4.5:1. */
ad-rich-text [data-adcm-color][data-adcm-contrast-guard="dark"] {
  text-shadow: -1px -1px 0 rgba(0,0,0,.88), 1px -1px 0 rgba(0,0,0,.88), -1px 1px 0 rgba(0,0,0,.88), 1px 1px 0 rgba(0,0,0,.88);
}
ad-rich-text [data-adcm-color][data-adcm-contrast-guard="light"] {
  text-shadow: -1px -1px 0 rgba(255,255,255,.9), 1px -1px 0 rgba(255,255,255,.9), -1px 1px 0 rgba(255,255,255,.9), 1px 1px 0 rgba(255,255,255,.9);
}

