/* These notebook SVGs supply their own light/dark foreground colors. */
.image-box img[src$="/newton_example_function.svg"],
.image-box img[src$="/newton_step.svg"],
.image-box img[src$="/newton_steps.svg"],
.image-box img[src$="/newton_chaos.svg"],
.image-box img[src$="/real_newton_cosine.svg"],
.image-box img[src$="/real_newton_guess_hw.svg"],
.image-box img[src$="/intro_cobwebs.svg"] {
  background: transparent;
}

/* Switch only this PNG when PreTeXt activates dark mode.
   URLs are relative to this stylesheet in external/styles/. */
@media screen {
  :root.dark-mode .image-box img[src$="/logistic_bifurcation.png"] {
    content: url("../images/logistic_bifurcation_dark.png");
  }
}

/* Both bifurcation variants use the page background. */
.image-box img[src$="/logistic_bifurcation.png"] {
  background: transparent;
}

/* Remaining raster images from intro_pics.ipynb. */
.image-box img[src$="/quadratic_newton_coloring.png"],
.image-box img[src$="/x3m1_coloring.png"],
.image-box img[src$="/complex_cosine_zoom.png"],
.image-box img[src$="/complex_cosine.png"],
.image-box img[src$="/intro_julia_sets.png"],
.image-box img[src$="/intro_mandelbrot_set.png"] {
  background: transparent;
}
@media screen {
  :root.dark-mode .image-box img[src$="/quadratic_newton_coloring.png"] {
    content: url("../images/quadratic_newton_coloring_dark.png");
  }
  :root.dark-mode .image-box img[src$="/x3m1_coloring.png"] {
    content: url("../images/x3m1_coloring_dark.png");
  }
  :root.dark-mode .image-box img[src$="/complex_cosine_zoom.png"] {
    content: url("../images/complex_cosine_zoom_dark.png");
  }
  :root.dark-mode .image-box img[src$="/complex_cosine.png"] {
    content: url("../images/complex_cosine_dark.png");
  }
  :root.dark-mode .image-box img[src$="/intro_julia_sets.png"] {
    content: url("../images/intro_julia_sets_dark.png");
  }
  :root.dark-mode .image-box img[src$="/intro_mandelbrot_set.png"] {
    content: url("../images/intro_mandelbrot_set_dark.png");
  }
}

/* Mathematica exports from intro_pics.nb. PDFs use the print palette. */
.image-box img[src$="/geometric_iteration.svg"],
.image-box img[src$="/geometric_iteration.png"],
.image-box img[src$="/intro_sierpinski_triangle.png"],
.image-box img[src$="/intro_barnsley_fern.png"] {
  background: transparent;
}
@media screen {
  :root.dark-mode .image-box img[src$="/geometric_iteration.svg"] {
    content: url("../images/geometric_iteration_dark.svg");
  }
  :root.dark-mode .image-box img[src$="/geometric_iteration.png"] {
    content: url("../images/geometric_iteration_dark.png");
  }
  :root.dark-mode .image-box img[src$="/intro_sierpinski_triangle.png"] {
    content: url("../images/intro_sierpinski_triangle_dark.png");
  }
  :root.dark-mode .image-box img[src$="/intro_barnsley_fern.png"] {
    content: url("../images/intro_barnsley_fern_dark.png");
  }
}

/* Sage Cell: adapt the Quarto palette to PreTeXt's live theme switch. */
:root.dark-mode {
  --sage-editor-background: #23272e;
}
:root.dark-mode .sagecell,
:root.dark-mode .sagecell .sagecell_input,
:root.dark-mode .sagecell .sagecell_sessionOutput,
:root.dark-mode .sagecell .sagecell_output {
    background: var(--content-background);
    color: var(--body-text-color);
    border-color: var(--page-border-color);
}

:root.dark-mode .sagecell .CodeMirror {
    background: var(--sage-editor-background);
    color: var(--body-text-color);
    border-color: var(--page-border-color);
}

:root.dark-mode .sagecell .CodeMirror-gutters {
    background: #292e34;
    border-right-color: #49515b;
}

:root.dark-mode .sagecell .CodeMirror-linenumber {
    color: #a6adb7;
    background: transparent;
}

:root.dark-mode .sagecell .CodeMirror-cursor {
    border-left-color: var(--body-text-color);
}

:root.dark-mode .sagecell .CodeMirror-selected,
:root.dark-mode .sagecell .CodeMirror-focused .CodeMirror-selected {
    background: rgba(125, 162, 255, 0.28);
}

:root.dark-mode .sagecell .CodeMirror-matchingbracket,
:root.dark-mode .sagecell .CodeMirror-nonmatchingbracket {
    color: var(--body-text-color);
}

:root.dark-mode .sagecell .cm-comment {
    color: #8fb996;
}

:root.dark-mode .sagecell .cm-keyword,
:root.dark-mode .sagecell .cm-builtin {
    color: #ffb86c;
}

:root.dark-mode .sagecell .cm-string {
    color: #a5d6ff;
}

:root.dark-mode .sagecell .cm-number,
:root.dark-mode .sagecell .cm-atom {
    color: #d2a8ff;
}

:root.dark-mode .sagecell .cm-def,
:root.dark-mode .sagecell .cm-variable,
:root.dark-mode .sagecell .cm-variable-2,
:root.dark-mode .sagecell .cm-property {
    color: var(--body-text-color);
}

:root.dark-mode .sagecell .cm-operator {
    color: #ff7b72;
}

:root.dark-mode .sagecell button,
:root.dark-mode .sagecell select,
:root.dark-mode .sagecell textarea,
:root.dark-mode .sagecell input {
    background-color: var(--sage-editor-background);
    color: var(--body-text-color);
    border-color: var(--page-border-color);
}

:root.dark-mode .sagecell button:hover,
:root.dark-mode .sagecell button:focus {
    background-color: #343a40;
    border-color: #6c757d;
    color: var(--body-text-color);
    box-shadow: 0 0 0 0.12rem rgba(173, 181, 189, 0.12);
}

:root.dark-mode .sagecell pre,
:root.dark-mode .sagecell .sagecell_stdout,
:root.dark-mode .sagecell .sagecell_stderr {
    background: var(--sage-editor-background);
    color: var(--body-text-color);
    border-color: var(--page-border-color);
}

:root.dark-mode .sagecell .sagecell_stderr {
    color: #ffb4ab;
}


/* Override PreTeXt's light button gradient as well as its background color. */
:root.dark-mode .sagecell .sagecell_evalButton {
  background-image: none;
}

/* Pass the selected book theme into the responsive orbit SVG. */
:root:not(.dark-mode) .image-box img[src$="/rotational_picture.svg"],
:root:not(.dark-mode) .image-box img[src$="/z_squared_dynamics.svg"],
:root:not(.dark-mode) .image-box img[src$="/exterior_conjugacy_for_disk.svg"] {
  color-scheme: light;
  background: transparent;
}
:root.dark-mode .image-box img[src$="/rotational_picture.svg"],
:root.dark-mode .image-box img[src$="/z_squared_dynamics.svg"],
:root.dark-mode .image-box img[src$="/exterior_conjugacy_for_disk.svg"] {
  color-scheme: dark;
  background: transparent;
}

/* Transparent boundary scans from the Collapsing loops notebook section. */
.image-box img[src$="/collapsing_loops.png"] {
  background: transparent;
}
@media screen {
  :root.dark-mode .image-box img[src$="/collapsing_loops.png"] {
    content: url("../images/collapsing_loops_dark.png");
  }
}

/* Mandelbrot figures: preserve the fractal colors and adapt labels/overlays. */
.image-box img[src$="/mandelbrot_set.png"],
.image-box img[src$="/mandelbrot_farey.png"] {
  background: transparent;
}
@media screen {
  :root.dark-mode .image-box img[src$="/mandelbrot_set.png"] {
    content: url("../images/mandelbrot_set_dark.png");
  }
  :root.dark-mode .image-box img[src$="/mandelbrot_farey.png"] {
    content: url("../images/mandelbrot_farey_dark.png");
  }
}

/* Main-cardioid overlay from quadratic_family.ipynb. */
.image-box img[src$="/mandelbrot_cardioid.png"] {
  background: transparent;
}
@media screen {
  :root.dark-mode .image-box img[src$="/mandelbrot_cardioid.png"] {
    content: url("../images/mandelbrot_cardioid_dark.png");
  }
}

/* Real bifurcation diagram above the Mandelbrot set. */
.image-box img[src$="/mandelbrot_bifurcation.png"] {
  background: transparent;
}
@media screen {
  :root.dark-mode .image-box img[src$="/mandelbrot_bifurcation.png"] {
    content: url("../images/mandelbrot_bifurcation_dark.png");
  }
}

/* Responsive exports from real_iteration_pics.ipynb. */
.image-box img[src$="/logistic_cobwebs.svg"],
.image-box img[src$="/linear_cobwebs.svg"],
.image-box img[src$="/three_fixed.svg"],
.image-box img[src$="/period_two.svg"],
.image-box img[src$="/attractive_period_two.svg"],
.image-box img[src$="/quadratic_cobwebs.svg"],
.image-box img[src$="/cascading_cobwebs.svg"],
.image-box img[src$="/conjugate_cobwebs.svg"],
.image-box img[src$="/doubling_map.svg"],
.image-box img[src$="/dyadic_intervals.svg"],
.image-box img[src$="/distance_one_fourth.svg"],
.image-box img[src$="/doubling_map_cubed.svg"],
.image-box img[src$="/bad_doubling_cobweb.svg"],
.image-box img[src$="/quadratic_bifurcation.png"],
.image-box img[src$="/quadratic_bifurcation_with_critical_curves.png"],
.image-box img[src$="/quadratic_bifurcation_density.png"] {
  background: transparent;
}
:root:not(.dark-mode) .image-box img[src$="/logistic_cobwebs.svg"],
:root:not(.dark-mode) .image-box img[src$="/linear_cobwebs.svg"],
:root:not(.dark-mode) .image-box img[src$="/three_fixed.svg"],
:root:not(.dark-mode) .image-box img[src$="/period_two.svg"],
:root:not(.dark-mode) .image-box img[src$="/attractive_period_two.svg"],
:root:not(.dark-mode) .image-box img[src$="/quadratic_cobwebs.svg"],
:root:not(.dark-mode) .image-box img[src$="/cascading_cobwebs.svg"],
:root:not(.dark-mode) .image-box img[src$="/conjugate_cobwebs.svg"],
:root:not(.dark-mode) .image-box img[src$="/doubling_map.svg"],
:root:not(.dark-mode) .image-box img[src$="/dyadic_intervals.svg"],
:root:not(.dark-mode) .image-box img[src$="/distance_one_fourth.svg"],
:root:not(.dark-mode) .image-box img[src$="/doubling_map_cubed.svg"],
:root:not(.dark-mode) .image-box img[src$="/bad_doubling_cobweb.svg"] {
  color-scheme: light;
}
:root.dark-mode .image-box img[src$="/logistic_cobwebs.svg"],
:root.dark-mode .image-box img[src$="/linear_cobwebs.svg"],
:root.dark-mode .image-box img[src$="/three_fixed.svg"],
:root.dark-mode .image-box img[src$="/period_two.svg"],
:root.dark-mode .image-box img[src$="/attractive_period_two.svg"],
:root.dark-mode .image-box img[src$="/quadratic_cobwebs.svg"],
:root.dark-mode .image-box img[src$="/cascading_cobwebs.svg"],
:root.dark-mode .image-box img[src$="/conjugate_cobwebs.svg"],
:root.dark-mode .image-box img[src$="/doubling_map.svg"],
:root.dark-mode .image-box img[src$="/dyadic_intervals.svg"],
:root.dark-mode .image-box img[src$="/distance_one_fourth.svg"],
:root.dark-mode .image-box img[src$="/doubling_map_cubed.svg"],
:root.dark-mode .image-box img[src$="/bad_doubling_cobweb.svg"] {
  color-scheme: dark;
}
@media screen {
  :root.dark-mode .image-box img[src$="/quadratic_bifurcation.png"] {
    content: url("../images/quadratic_bifurcation_dark.png");
  }
  :root.dark-mode .image-box img[src$="/quadratic_bifurcation_with_critical_curves.png"] {
    content: url("../images/quadratic_bifurcation_with_critical_curves_dark.png");
  }
  :root.dark-mode .image-box img[src$="/quadratic_bifurcation_density.png"] {
    content: url("../images/quadratic_bifurcation_density_dark.png");
  }
}

/* Extensionless PreTeXt references select these responsive SVGs. */
.image-box img[src$="/quadratic_bifurcation_density.svg"],
.image-box img[src$="/period3_occurrence.svg"] {
  background: transparent;
}
:root:not(.dark-mode) .image-box img[src$="/quadratic_bifurcation_density.svg"],
:root:not(.dark-mode) .image-box img[src$="/period3_occurrence.svg"] {
  color-scheme: light;
}
:root.dark-mode .image-box img[src$="/quadratic_bifurcation_density.svg"],
:root.dark-mode .image-box img[src$="/period3_occurrence.svg"] {
  color-scheme: dark;
}

/* Tent-map vector figures use their own responsive foreground palettes. */
.image-box img[src$="/tent_maps.svg"],
.image-box img[src$="/tent_map_cobwebs.svg"],
.image-box img[src$="/doubleTent.svg"] {
  background: transparent;
}
:root:not(.dark-mode) .image-box img[src$="/tent_maps.svg"],
:root:not(.dark-mode) .image-box img[src$="/tent_map_cobwebs.svg"],
:root:not(.dark-mode) .image-box img[src$="/doubleTent.svg"] {
  color-scheme: light;
}
:root.dark-mode .image-box img[src$="/tent_maps.svg"],
:root.dark-mode .image-box img[src$="/tent_map_cobwebs.svg"],
:root.dark-mode .image-box img[src$="/doubleTent.svg"] {
  color-scheme: dark;
}

/* Tall-tent escape intervals and their inverse images. */
.image-box img[src$="/tallTent.svg"],
.image-box img[src$="/escapingTent.svg"] {
  background: transparent;
}
:root:not(.dark-mode) .image-box img[src$="/tallTent.svg"],
:root:not(.dark-mode) .image-box img[src$="/escapingTent.svg"] {
  color-scheme: light;
}
:root.dark-mode .image-box img[src$="/tallTent.svg"],
:root.dark-mode .image-box img[src$="/escapingTent.svg"] {
  color-scheme: dark;
}
