/*
 * Theme guard for administrator-authored lesson HTML.
 *
 * Rich lesson blocks can contain legacy inline colours saved in the database.
 * The component theme cannot reliably predict those values, so this final
 * frontend layer maps visual cards back to the active light/dark tokens.
 */

body.ilc-ui-enhanced.ilc-ui-context-frontend :is(
    .ilc-theory-content,
    .ilc-task-text,
    .ilc-custom-code-panel,
    .ilc-practice-block__body,
    .ilc-practice-block__description,
    .ilc-simple-outcome-text,
    .ilc-lesson-video__description,
    .ilc-lesson-download__description
) :is(
    blockquote,p,div,section,article,aside,header,footer,main,nav,figure,figcaption,
    ul,ol,li,dl,dt,dd,table,thead,tbody,tfoot,tr,th,td,details,summary,fieldset
):not([role="button"])[style*="background" i],
body.ilc-ui-enhanced.ilc-ui-context-frontend :is(
    .ilc-theory-content,
    .ilc-task-text,
    .ilc-custom-code-panel,
    .ilc-practice-block__body,
    .ilc-practice-block__description,
    .ilc-simple-outcome-text,
    .ilc-lesson-video__description,
    .ilc-lesson-download__description
) [bgcolor],
body.ilc-ui-enhanced.ilc-ui-context-frontend [data-ilc-theme-normalized-surface="1"] {
    border-color: var(--ilc-theme-border-strong) !important;
    background-color: var(--ilc-theme-surface-4) !important;
    color: var(--ilc-theme-text) !important;
    -webkit-text-fill-color: var(--ilc-theme-text) !important;
    text-shadow: none !important;
}

body.ilc-ui-enhanced.ilc-ui-context-frontend [data-ilc-theme-normalized-level="3"] {
    background-color: var(--ilc-theme-surface-3) !important;
}

body.ilc-ui-enhanced.ilc-ui-context-frontend [data-ilc-theme-normalized-level="4"] {
    background-color: var(--ilc-theme-surface-4) !important;
}

body.ilc-ui-enhanced.ilc-ui-context-frontend [data-ilc-theme-normalized-surface="1"]:not([data-ilc-theme-keeps-image="1"]) {
    background-image: none !important;
}

body.ilc-ui-enhanced.ilc-ui-context-frontend [data-ilc-theme-normalized-surface="1"] :is(
    p,span,em,i,small,label,li,dt,dd,th,td
) {
    color: var(--ilc-theme-text) !important;
    -webkit-text-fill-color: var(--ilc-theme-text) !important;
    text-shadow: none !important;
}

body.ilc-ui-enhanced.ilc-ui-context-frontend [data-ilc-theme-normalized-surface="1"] :is(
    h1,h2,h3,h4,h5,h6,strong,b,summary
) {
    color: var(--ilc-theme-heading) !important;
    -webkit-text-fill-color: var(--ilc-theme-heading) !important;
    text-shadow: none !important;
}

body.ilc-ui-enhanced.ilc-ui-context-frontend [data-ilc-theme-normalized-surface="1"] a:not(.button):not([role="button"]) {
    color: var(--ilc-theme-link) !important;
    -webkit-text-fill-color: var(--ilc-theme-link) !important;
    text-shadow: none !important;
}
