/* Theme for the HTML notes; the colours follow the personal website (GitHub-like palette). */

:root {
  --bg: #ffffff;
  --surface: #f6f8fa;
  --text: #24292f;
  --muted: #57606a;
  --heading: #0f1419;
  --border: #d8dee4;
  --link: #0969da;
  --link-hover: #054da7;
  --accent: #0969da;
  --accent-soft: rgba(9, 105, 218, 0.06);
  --definition: #8250df;
  --definition-soft: rgba(130, 80, 223, 0.06);
  --example: #9a6700;
  --topbar-height: 3.25rem;
  --sidebar-width: 17rem;
  --serif: "Palatino Linotype", Palatino, "TeX Gyre Pagella", "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --body-font: var(--sans);   /* change to var(--serif) for Palatino text */
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --surface: #161b22;
    --text: #c9d1d9;
    --muted: #8b949e;
    --heading: #f0f6fc;
    --border: #30363d;
    --link: #58a6ff;
    --link-hover: #79c0ff;
    --accent: #58a6ff;
    --accent-soft: rgba(88, 166, 255, 0.08);
    --definition: #bc8cff;
    --definition-soft: rgba(188, 140, 255, 0.08);
    --example: #d29922;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --text: #c9d1d9;
  --muted: #8b949e;
  --heading: #f0f6fc;
  --border: #30363d;
  --link: #58a6ff;
  --link-hover: #79c0ff;
  --accent: #58a6ff;
  --accent-soft: rgba(88, 166, 255, 0.08);
  --definition: #bc8cff;
  --definition-soft: rgba(188, 140, 255, 0.08);
  --example: #d29922;
  color-scheme: dark;
}

/* ---- Page structure ------------------------------------------------------------- */

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-height) + 1rem);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body-font);
  font-size: 1.0625rem;
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  height: var(--topbar-height);
  padding: 0 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-family: var(--sans);
  font-size: 0.95rem;
}

.topbar .course {
  font-weight: 600;
  color: var(--heading);
  text-decoration: none;
  white-space: nowrap;
}

.topbar .pages {
  display: flex;
  gap: 1.1rem;
  margin-left: auto;
}

.topbar .pages a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.85rem 0 0.75rem;
  border-bottom: 2px solid transparent;
}

.topbar .pages a:hover { color: var(--text); }

.topbar .pages a[aria-current="page"] {
  color: var(--heading);
  border-bottom-color: var(--accent);
}

.topbar button {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 6px;
}

.topbar button:hover { background: var(--surface); color: var(--text); }

.topbar .proofs-button {
  font-family: var(--sans);
  font-size: 0.85rem;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.proofs-button[hidden] { display: none; }

.theme-button::before { content: "\263E"; font-size: 1.1rem; }        /* moon */
:root[data-theme="dark"] .theme-button::before { content: "\2600"; }  /* sun */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-button::before { content: "\2600"; }
}

.menu-button span {
  display: block;
  width: 1.15rem;
  height: 2px;
  margin: 3px 0;
  background: currentColor;
  border-radius: 1px;
}

.layout { display: flex; }

.sidebar {
  position: sticky;
  top: var(--topbar-height);
  flex: 0 0 var(--sidebar-width);
  height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
  padding: 1.25rem 0.75rem 2rem 1rem;
  border-right: 1px solid var(--border);
  font-family: var(--sans);
  font-size: 0.875rem;
  line-height: 1.4;
}

.content {
  position: relative;      /* lecture markers are placed against this */
  flex: 1 1 auto;
  min-width: 0;
  max-width: 46rem;
  margin: 0 auto;
  padding: 1.5rem 2rem 6rem 2rem;
}

@media (min-width: 60.01rem) {
  .sidebar-collapsed .sidebar { display: none; }
}

/* ---- Contents list ------------------------------------------------------------- */

.toc { list-style: none; margin: 0; padding: 0; }

.toc a {
  display: flex;
  gap: 0.5em;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
}

.toc a:hover { background: var(--surface); }
.toc a.active { background: var(--accent-soft); color: var(--accent); }

.toc-number { color: var(--muted); min-width: 1.6em; }
.toc a.active .toc-number { color: inherit; }

.toc-section { margin-top: 0.2rem; font-weight: 600; }
.toc-section:first-child { margin-top: 0; }
.toc-sub { list-style: none; margin: 0 0 0.4rem; padding: 0; font-weight: 400; }
.toc li:not(.open) > .toc-sub { display: none; }

.toc-row { display: flex; align-items: flex-start; }
.toc-row > a { flex: 1 1 auto; min-width: 0; }
.toc-toggle {
  flex: 0 0 auto;
  width: 1.75rem;
  height: 1.75rem;
  margin-left: 0.15rem;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.toc-toggle:hover { background: var(--surface); color: var(--text); }
.toc-toggle::before {
  content: "\25B8";
  display: inline-block;
  transition: transform 0.15s ease;
}
.toc li.open > .toc-row .toc-toggle::before { transform: rotate(90deg); }

.toc-subsection a { padding-left: 1.4rem; color: var(--muted); }
.toc-subsection .toc-number { min-width: 2.2em; }

/* ---- Text --------------------------------------------------------------------- */

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }

h1, h2, h3, h4, h5 {
  font-family: var(--sans);
  color: var(--heading);
  line-height: 1.25;
}

.maketitle { margin: 1rem 0 2.5rem; }
.maketitle h1, .titleHead {
  font-size: 2rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
}
.maketitle .author, .maketitle .date {
  font-family: var(--sans);
  font-size: 1rem;
  color: var(--muted);
}
.maketitle .author br, .maketitle .date:empty { display: none; }

h3.sectionHead, h3.likesectionHead {
  font-size: 1.6rem;
  font-weight: 700;
  margin: 3.5rem 0 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

h4.subsectionHead, h4.likesubsectionHead {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 2.25rem 0 0.75rem;
}

.titlemark { color: var(--muted); font-weight: 500; margin-right: 0.35em; }

p { margin: 0 0 0.9em; }
.noindent, .indent { text-indent: 0; }

/* tex4ht marks font changes with spans; keep the weight and style but not the family. */
span[class^="ec-"], span[class^="pplr"], span[class^="pplb"], span[class^="ppl"],
span[class*="lmr"], span[class*="lmss"], span[class*="lmtt"] {
  font-family: inherit;
}
code, .verb, span[class*="lmtt"] { font-family: ui-monospace, Consolas, monospace; font-size: 0.9em; }

ol, ul { padding-left: 1.6rem; }
li { margin-bottom: 0.35em; }
dl.enumerate, dl.enumerate-enumitem { display: grid; grid-template-columns: auto 1fr; column-gap: 0.6em; }
dl.enumerate dt, dl.enumerate-enumitem dt { text-align: right; }
dl.enumerate dd, dl.enumerate-enumitem dd { margin: 0 0 0.5em; }

blockquote, .quote { margin: 1rem 0; padding-left: 1rem; border-left: 3px solid var(--border); color: var(--muted); }

hr { border: 0; border-top: 1px solid var(--border); }

/* ---- Theorems and friends --------------------------------------------------------- */

.thm { margin: 1.5rem 0; }
.thm > :last-child, .thm .newtheorem > :last-child { margin-bottom: 0; }
.thm .head { font-family: var(--sans); font-size: 0.95em; }
.thm .head span { font-family: inherit; }

.thm-theorem {
  padding: 0.9rem 1.1rem;
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
}
.thm-theorem .head { color: var(--accent); }

.thm-definition {
  padding: 0.9rem 1.1rem;
  background: var(--definition-soft);
  border-left: 3px solid var(--definition);
  border-radius: 0 6px 6px 0;
}
.thm-definition .head { color: var(--definition); }

.thm-example, .thm-exercise {
  padding: 0.1rem 0 0.1rem 1.1rem;
  border-left: 3px solid var(--border);
}
.thm-exercise { border-left-color: var(--example); }
.thm-exercise .head { color: var(--example); }

.thm-remark .head { color: var(--muted); }

/* Proofs and released solutions fold up (see fold() in build.py). */
details.fold > summary {
  cursor: pointer;
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  list-style: none;
  user-select: none;
}
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::before {
  content: "\25B8";
  display: inline-block;
  width: 1.1em;
  transition: transform 0.15s ease;
}
details.fold[open] > summary::before { transform: rotate(90deg); }
details.fold > summary:hover { color: var(--text); }

details.proof { margin: -0.5rem 0 1.5rem; }
details.proof > summary { padding: 0.2rem 0; font-style: italic; font-weight: 500; }
details.proof[open] > summary { margin-bottom: 0.35rem; }
details.proof > .proof { padding-left: 1.1rem; border-left: 2px solid var(--border); }
details.proof > .proof > :last-child { margin-bottom: 0; }

details.solution {
  margin: 0.75rem 0 1.25rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}
details.solution > summary { padding: 0.45rem 0.9rem; }
details.solution[open] > summary { border-bottom: 1px solid var(--border); }
details.solution > :not(summary) { margin-left: 0.9rem; margin-right: 0.9rem; }
details.solution > :not(summary):last-child { margin-bottom: 0.9rem; }
details.solution > :nth-child(2) { margin-top: 0.75rem; }

/* ---- Lecture markers ---------------------------------------------------------------- */

.lecture-mark {
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

@media (min-width: 72rem) {
  .lecture-mark {
    position: absolute;
    left: -5.5rem;
    width: 6rem;
    margin-top: 0.3rem;
    text-align: right;
    padding-right: 0.6rem;
    border-right: 2px solid var(--border);
  }
  div.lecture-mark { margin-top: 0.3rem; height: 1.2rem; line-height: 1.2rem; }
}

@media (max-width: 71.99rem) {
  .lecture-mark {
    display: block;
    margin: 1.5rem 0 0.75rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px dashed var(--border);
  }
}

/* ---- Maths, figures and tables ---------------------------------------------------------- */

mjx-container[display="true"] { margin: 1em 0 !important; }
mjx-container { font-size: 105%; }
.mathjax-block, .mathjax-env { display: block; overflow-x: auto; overflow-y: hidden; }

.figure, figure { margin: 2rem 0; text-align: center; }
.figure img, figure img, .center img { max-width: 100%; height: auto; }
.caption { font-family: var(--sans); font-size: 0.9rem; color: var(--muted); margin-top: 0.5rem; }
.center { text-align: center; }

:root[data-theme="dark"] img.diagram { filter: invert(0.88) hue-rotate(180deg); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) img.diagram { filter: invert(0.88) hue-rotate(180deg); }
}

table.tabular { border-collapse: collapse; margin: 1rem auto; }
table.tabular td { padding: 0.25rem 0.75rem; }

.footnote-mark { font-size: 0.75em; vertical-align: super; line-height: 0; }
.footnotes, .footnote { font-size: 0.9rem; color: var(--muted); }

/* ---- Previews of cross-references and footnotes ------------------------------------- */

.preview {
  position: fixed;
  z-index: 30;
  width: max-content;
  max-width: min(38rem, calc(100vw - 16px));
  max-height: 45vh;
  overflow: auto;
  padding: 0.8rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  font-size: 0.95rem;
}
.preview[hidden] { display: none; }
.preview > * { margin: 0 !important; }
.preview .lecture-mark { display: none; }
.preview aside.footnotetext { color: var(--text); }
.preview .mathjax-env, .preview .mathjax-block { overflow: visible; }

/* ---- Narrow screens -------------------------------------------------------------------- */

@media (max-width: 60rem) {
  .sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar-height);
    z-index: 15;
    width: min(20rem, 85vw);
    background: var(--bg);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 0 0 2rem rgba(0, 0, 0, 0.15);
  }
  body.sidebar-open .sidebar { transform: none; }
  .content { padding: 1rem 1rem 4rem; }
  body { font-size: 1rem; }
}

@media (max-width: 30rem) {
  .topbar { gap: 0.75rem; }
  .topbar .course { display: none; }
  .topbar .pages { margin-left: 0; }
}

@media print {
  .topbar, .sidebar { display: none; }
  .content { max-width: none; padding: 0; }
}
