/* RichContentTone: readable author-colored rich content on any theme.

   Owner pair:
   - attributes: course_engine/rich_content_tone.py (read-path decoration after
     sanitize_rich_html; nothing persists to stored content);
   - editor parity: static/cabinet/tinymce-content-tone.js + editor_styles.css
     apply the same decisions inside the TinyMCE iframe via data-mce-rich-bg-tone.

   The system is deliberately theme-INDEPENDENT for backgrounds (like
   ContentColor): text over an author-picked background depends only on that
   background's luminance, so a light-yellow highlight keeps dark text on the
   midnight theme instead of inheriting unreadable near-white page text.

   Fixed text pair mirrors CONTENT_COLOR_DARK_TEXT / CONTENT_COLOR_LIGHT_TEXT
   in static/js/content_color.js: --ui-primitive-content-ink carries the same
   ink value (see primitives.css). Primitives on purpose, not semantic tokens,
   because semantic tokens flip with the theme and these must not. No :root
   here — tokens live in ui/tokens (VIS-GLOBAL-001).

   !important is required: author colors are inline styles, and forced-text
   rules must also beat utility classes that may ride on pasted markup. The
   decorator only marks elements where the author did NOT set the property the
   rule overrides, so author intent is never fought, except the two fg-extreme
   remaps below which exist precisely to keep such text visible. */

/* Author background, no author text color: pick the readable fixed color. */
[data-rich-bg-tone="light"] { color: var(--ui-primitive-content-ink) !important; }
[data-rich-bg-tone="dark"] { color: var(--ui-primitive-white) !important; }

/* Author text color at the luminance extremes (usually a paste artifact like
   pure black/white) with no author background: it disappears when the canvas
   tone matches it, so remap it onto the theme's primary text token. Mid-range
   author hues are intentionally untouched.

   The :not([data-rich-bg-scope] *) guard keeps the remap OFF inside author
   backgrounds ("author canvas"): near-black text on an author light-yellow
   div was chosen against that div, not against the page theme. */
[data-bs-theme="dark"] [data-rich-fg-tone="near-black"]:not([data-rich-bg-scope] *) { color: var(--ui-text-primary) !important; }
[data-bs-theme="light"] [data-rich-fg-tone="near-white"]:not([data-rich-bg-scope] *) { color: var(--ui-text-primary) !important; }
