:root {
  --bg: #fcfcf8;
  --surface: #ffffff;
  --text: #2a3140;
  --muted: #5f6878;
  --link: #1e56b6;
  --link-hover: #17479a;
  --link-visited: #5b3aa3;
  --font-body: "Charter", "Bitstream Charter", "URW Bookman", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --border: #dde2ea;
  --nav-hover: rgba(31, 36, 48, 0.08);
  --note-bg: rgba(31, 36, 48, 0.04);
  --code-bg: #f3f6fa;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #fcfcf8;
  --surface: #ffffff;
  --text: #2a3140;
  --muted: #5f6878;
  --link: #1e56b6;
  --link-hover: #17479a;
  --link-visited: #5b3aa3;
  --font-body: "Charter", "Bitstream Charter", "URW Bookman", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --border: #dde2ea;
  --nav-hover: rgba(31, 36, 48, 0.08);
  --note-bg: rgba(31, 36, 48, 0.04);
  --code-bg: #f3f6fa;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1117;
  --surface: #151a23;
  --text: #e7ecf4;
  --muted: #a8b3c7;
  --link: #8ab4ff;
  --link-hover: #abc9ff;
  --link-visited: #d7b6ff;
  --font-body: "et-book", Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", Georgia, serif;
  --border: #2a3344;
  --nav-hover: rgba(231, 236, 244, 0.12);
  --note-bg: rgba(231, 236, 244, 0.1);
  --code-bg: #18202c;
}

html,
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 400;
  text-shadow: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

a {
  color: var(--link);
  text-shadow: none !important;
  background-image: none !important;
  text-decoration: underline;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.14em;
}

a:visited {
  color: var(--link-visited);
}

a:hover,
a:focus-visible {
  color: var(--link-hover);
}

p,
li {
  color: var(--text);
}

h1,
h2,
h3,
h4 {
  color: var(--text);
}

header nav a:hover,
header nav a:focus-visible {
  background: var(--nav-hover);
}

header nav .theme-toggle {
  color: inherit;
  font-family: inherit;
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.2;
  min-width: 2.1rem;
  border: 1px solid var(--border);
  border-radius: 0.2rem;
  background: var(--surface);
  margin-top: 1em;
  padding: 0.3em 0.55em;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}

header nav .theme-toggle:hover,
header nav .theme-toggle:focus-visible {
  background: var(--nav-hover);
  outline: none;
}

.marginnote {
  color: var(--muted);
}

/* Add one blank-line of spacing between consecutive margin notes. */
.marginnote + .marginnote {
  margin-top: 1em;
}

.marginnote img {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.marginnote p {
  margin-top: 0.35rem;
  color: var(--muted);
}

pre,
code {
  background: var(--code-bg);
  border-radius: 4px;
}

pre {
  border: 1px solid var(--border);
  padding: 0.65rem 0.8rem;
}

/* Footnote hover contrast in light mode */
.footnote-ref,
.footnote-ref + .marginnote {
  --highlight-weak: var(--note-bg);
  --highlight-strong: rgba(31, 36, 48, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1117;
    --surface: #151a23;
    --text: #e7ecf4;
    --muted: #a8b3c7;
    --link: #8ab4ff;
    --border: #2a3344;
    --nav-hover: rgba(231, 236, 244, 0.12);
    --note-bg: rgba(231, 236, 244, 0.1);
    --code-bg: #18202c;
  }

  /* Keep math readable after tufted's inversion */
  :root:not([data-theme="light"]) [role="math"] {
    filter: invert(1) hue-rotate(180deg);
  }
}

/* Keep math readable when dark mode is manually selected. */
:root[data-theme="dark"] [role="math"] {
  filter: invert(1) hue-rotate(180deg);
}
