/* Learning content uses real dark surfaces, never a full-page inversion.
   Screen-only: original mathematical colors and exported/printed ink survive. */
@media screen and (forced-colors: none) {
  html[data-wm-theme="dark"] :is([data-content-authoring-surface], .worksheet-question-list,
    .official-annotation-stage, .pni-notes, .pni-editor-viewport, .calculation-learning-scratchpad) {
    color-scheme: dark;
    color: var(--wm-theme-ink);
    background-color: var(--wm-theme-surface);
    --pni-ink: #e8ecff;
    --pni-muted: #acb7d1;
    --pni-line: #35425f;
    --pni-personal: #b5a0ff;
    --pni-personal-strong: #cec0ff;
    --pni-personal-pale: #2a2448;
  }
  html[data-wm-theme="dark"] .worksheet-question-list { background: transparent; }
  html[data-wm-theme="dark"] .worksheet-question {
    background-color: var(--wm-theme-surface);
    border-color: var(--wm-theme-line);
  }
  html[data-wm-theme="dark"] :is(.pni-editor-viewport--workspace,
    .pni-editor-viewport--workspace .pni-editor-stage, .pni-editor-stage,
    .worksheet-scratchpad-canvas, .calculation-learning-scratchpad .worksheet-scratchpad-canvas) {
    background: transparent;
  }
  html[data-wm-theme="dark"] .pni-memo-boundary__label { color: var(--wm-theme-primary); }
  html[data-wm-theme="dark"] [data-content-authoring-surface] :is(cpn, ar, ar-reversed, ar-downward) {
    color: var(--wm-theme-primary-dark);
    -webkit-text-fill-color: currentColor;
    background: none;
    filter: none;
  }
  html[data-wm-theme="dark"] [data-content-authoring-surface] .background01 {
    background: var(--wm-mode-amber-soft);
  }
  html[data-wm-theme="dark"] [data-content-authoring-surface] concept-plus-contents {
    box-shadow: inset 0 1px 0 #b5a0ff30;
  }
  /* Change blank surfaces, not answer colors: inline transparent text and
     hidden source nodes must still obey the learning/test reveal controls. */
  html[data-wm-theme="dark"] :is(.learn-element, .quiz-review-element) {
    --blank-state-fill: var(--wm-theme-surface);
    --blank-state-border-color: var(--wm-theme-success);
  }
  html[data-wm-theme="dark"] .learn-element:hover {
    --blank-state-fill: var(--wm-mode-green-soft);
  }
  html[data-wm-theme="dark"] .quiz-review-correct {
    --blank-state-border-color: var(--wm-theme-success);
  }
  html[data-wm-theme="dark"] .quiz-review-correct:hover {
    --blank-state-fill: var(--wm-mode-green-soft);
  }
  html[data-wm-theme="dark"] .quiz-review-wrong {
    --blank-state-border-color: var(--wm-theme-danger);
  }
  html[data-wm-theme="dark"] .quiz-review-wrong:hover {
    --blank-state-fill: var(--wm-mode-red-soft);
  }
  html[data-wm-theme="dark"] .quiz-review-element[data-review-state="correct"] {
    --blank-state-border-color: var(--wm-theme-primary);
    --blank-state-fill: transparent;
  }
  html[data-wm-theme="dark"] .quiz-element {
    /* The blank controller also writes a white inline background. */
    background-color: var(--wm-theme-surface) !important;
    --wm-blank-inline-text-caret-color: var(--wm-theme-primary);
  }
  /* Only the rendered user answer gets ink; concealed source answers retain
     the controller's transparent color and visibility. */
  html[data-wm-theme="dark"] .quiz-element > .insert-element {
    color: var(--wm-theme-ink) !important;
  }
  html[data-wm-theme="dark"] .quiz-review-element {
    /* Input-mode inline white backgrounds survive the transition to review. */
    background-color: var(--blank-state-fill) !important;
  }
  html[data-wm-theme="dark"] .quiz-review-correct {
    --blank-state-border-color: var(--wm-theme-success) !important;
  }
  html[data-wm-theme="dark"] .quiz-review-wrong {
    --blank-state-border-color: var(--wm-theme-danger) !important;
  }
  html[data-wm-theme="dark"] .quiz-review-correct[data-review-state="user"] > .insert-element {
    color: var(--wm-theme-success) !important;
  }
  html[data-wm-theme="dark"] .quiz-review-wrong[data-review-state="user"] > .insert-element {
    color: var(--wm-theme-danger) !important;
  }
  html[data-wm-theme="dark"] .quiz-review-element[data-review-state="correct"] {
    --blank-state-border-color: var(--wm-theme-primary) !important;
  }
  /* Artwork has authored black strokes and meaningful colors. Keep only the
     artwork's own rectangle light, not the surrounding explanation or card. */
  html[data-wm-theme="dark"] :is([data-content-authoring-surface] img,
    [data-content-authoring-surface] svg[data-fit], .question-prompt-image) {
    color-scheme: light;
    color: #202238;
    background-color: #fff;
  }
  /* Lift only transparent ink layers, not photographs, SVG figures or math.
     Alpha and stored RGB remain intact. Theme switches require no canvas replay. */
  html[data-wm-theme="dark"] :is(.official-annotation-canvas, .pni-ink__canvas,
    .pni-ink__shape-draft, .pni-ink__trail,
    .worksheet-scratchpad-canvas, canvas[data-content-drawing-canvas]) {
    /* Two inversions cancel: RGB becomes 0.4 * original + 0.6, alpha unchanged.
       Native filters also work when static CSS is served from a separate CDN. */
    filter: invert(1) brightness(.4) invert(1);
  }
  html[data-wm-theme="dark"] [data-wm-theme-paper] :is(canvas, .pni-ink__canvas) { filter: none; }
}
