/* D2L custom styles — fonts, type scale, utilities */

@import url('https://fonts.googleapis.com/css2?family=Source+Sans+3:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Type scale ────────────────────────────────────────── */

body {
  font-family: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.65;
  color: #3A4049;
  -webkit-font-smoothing: antialiased;
}

code, pre, .sourceCode {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 12.5px;
  line-height: 1.6;
}

/* ── Nested ordered lists: letter sub-numbering ────────── */

/* Sub-problems in the exercise sections read as 1a, 1b, ... rather than
   a second level of arabic numerals. */
main ol ol {
  list-style-type: lower-alpha;
}

/* ── Cell output: wrap, never clip ─────────────────────── */

/* Bootstrap gives `pre` overflow:auto, so an output line wider than the
   article column is clipped at the right edge behind an overlay scrollbar
   that is invisible until hovered — the reader just sees a sentence that
   stops. Printed output is data, not code the reader retypes, so wrap it
   instead (matching the PDF, where static/d2l-preamble.tex makes the
   verbatim environment breakable). `anywhere` only kicks in for tokens that
   cannot fit at all (long URLs, unspaced tensor dumps). */
.cell-output pre,
.cell-output pre code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* …except column-aligned tables too wide for the column (profiler output,
   tuning-status tables, wide DataFrames). Wrapping those destroys the
   alignment that carries the meaning, so scroll them instead — with a slim
   scrollbar and a right-edge shadow so the overflow is discoverable.
   inject_outputs.py tags these blocks (`is_wide_table`). */
.d2l-output-wide pre,
.d2l-output-wide pre code {
  white-space: pre;
  overflow-wrap: normal;
}
.d2l-output-wide pre {
  overflow-x: auto;
  /* Edge shadow that shows only while there is more table off-screen: the two
     `local` layers scroll with the content and mask the shadow once that edge
     is reached; the two `scroll` layers are pinned to the box. */
  background-image:
    linear-gradient(to right, #f5f7fa, rgba(245, 247, 250, 0)),
    linear-gradient(to left, #f5f7fa, rgba(245, 247, 250, 0)),
    linear-gradient(to right, rgba(58, 64, 73, 0.16), rgba(58, 64, 73, 0)),
    linear-gradient(to left, rgba(58, 64, 73, 0.16), rgba(58, 64, 73, 0));
  background-position: left center, right center, left center, right center;
  background-repeat: no-repeat;
  background-size: 22px 100%, 22px 100%, 11px 100%, 11px 100%;
  background-attachment: local, local, scroll, scroll;
}
/* Styling ::-webkit-scrollbar opts out of Chrome/Safari overlay scrollbars, so
   the bar is permanently visible — the affordance that tells the reader there
   is more table to the right. (Don't add `scrollbar-width`: setting it makes
   Chrome ignore these rules and fall back to an overlay bar.) */
.d2l-output-wide pre::-webkit-scrollbar { height: 8px; }
.d2l-output-wide pre::-webkit-scrollbar-track { background: transparent; }
.d2l-output-wide pre::-webkit-scrollbar-thumb {
  background: #C7CCD3;
  border-radius: 4px;
}

/* ── Scrollable output ─────────────────────────────────── */

.d2l-output-scroll {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid #E7E9EC;
  border-radius: 4px;
}
.d2l-output-scroll pre {
  margin: 0;
}

/* Hide tab headers on output-only tabsets */
.d2l-output-tabs > .nav {
  display: none;
}

/* ── Inline code in headings should match heading size ─── */

h1 code, h2 code, h3 code, h4 code {
  font-size: inherit;
}

/* Long inline code spans in running text (`chebvander(x, 19)`, long calls)
   wrap on phones rather than push the page wider than the screen. Bootstrap
   sets `white-space: pre` on `code`, which forbids any break, so it becomes
   `pre-wrap` (spaces still kept). Desktop line breaking is unchanged, and
   code blocks keep their own scrolling (`pre`): only `p` and `li` match. */
@media (max-width: 600px) {
  main p code, main li code {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }
}

/* ── Wide tables on phones ──────────────────────────────── */

/* A pipe table wider than the column scrolls inside its own box on phones
   instead of widening the page. `display: block` is what makes overflow-x
   apply to a table. A captioned table's caption is a <figcaption> outside the
   <table> (Quarto float), so it stays at full column width and does not
   scroll; tables inside tabsets and cell outputs scroll the same way. */
@media (max-width: 600px) {
  main table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ── Math equations: responsive scroll & mobile scaling ── */

/* Pandoc wraps display equations in `<span id="eq-...">` + `<span class="math display">`
   (both `display: inline` by default). Promoting them to `display: block` with
   `max-width: 100%; overflow-x: auto` creates the scroll container *outside*
   MathJax 3's `<mjx-container display="true" width="full">`, which carries an
   inline `style="min-width: XXem"` to keep `<mjx-labels>` (the equation number)
   clear of the formula. Scrolling `.math.display` scrolls the formula and its
   tag together so they never collide, while vertical padding prevents
   `overflow-y: hidden` from clipping tall integrals, fractions, or underbraces. */
span[id^="eq-"] {
  display: block;
  max-width: 100%;
}

.math.display,
.katex-display {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.25rem 0;
  -webkit-overflow-scrolling: touch;
}

mjx-container[jax="CHTML"][display="true"]:not([width="full"]) {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.25rem 0;
}

@media (max-width: 600px) {
  .math.display,
  .katex-display {
    font-size: 0.92em;
    padding: 0.3rem 0;
  }

  .math.display mjx-container[jax="CHTML"][display="true"] {
    margin: 0.65em 0 !important;
  }

  .math.display::-webkit-scrollbar,
  .katex-display::-webkit-scrollbar {
    height: 5px;
  }
  .math.display::-webkit-scrollbar-track,
  .katex-display::-webkit-scrollbar-track {
    background: transparent;
  }
  .math.display::-webkit-scrollbar-thumb,
  .katex-display::-webkit-scrollbar-thumb {
    background: #C7CCD3;
    border-radius: 3px;
  }
}

/* ── Equalize tabbed and non-tabbed code blocks ────────── */

/* Bootstrap's compiled CSS applies padding:1em to both
   .tab-content and .tab-pane > *, plus borders on .tab-content.
   Override all of them so tabbed code matches standalone code. */
.panel-tabset > .tab-content {
  border: none !important;
  padding: 0 !important;
  margin-bottom: 0 !important;
}
/* Lists keep Bootstrap's indent (ol, ul { padding-left: 2rem }), so a list
   in a tab pane, such as an Exercises list with per-framework problems,
   lines up with lists elsewhere on the page. */
.panel-tabset > .tab-content > .tab-pane > :not(ol):not(ul) {
  padding: 0 !important;
}

/* ── Text-only tabs: unwrap to plain text ──────────────── */

/* JS adds this class to tabsets whose active pane has no code.
   Use !important to beat any Bootstrap/Quarto tab overrides. */
.panel-tabset.d2l-text-only > .nav.nav-tabs {
  display: none !important;
}
.panel-tabset.d2l-text-only {
  border: none !important;
  margin-top: 0;
  margin-bottom: 0;
}
.panel-tabset.d2l-text-only > .tab-content {
  border: none !important;
  padding: 0 !important;
}

/* ── TOC slides button (right-sidebar) ─────────────────── */

/* The Slides block reuses the notebook launcher's look (_d2l-notebooks.html):
   label, then HTML and PowerPoint side by side. */
.d2l-toc-slides.d2l-notebook-launcher { margin-top: 1rem; }
.d2l-toc-slides .d2l-notebook-action:last-child { grid-column: auto; }

/* ── Social share buttons ───────────────────────────────────
   Two locations, mutually exclusive:
     (A) `.d2l-share-block` — right-TOC, under the Slides button
     (C) `.d2l-share-bottom` — bottom of the article body
   (C) is hidden when (A) is present AND the viewport is wide
   enough for the right TOC to be visible (≥1200px, matching the
   theme's `body.floating #quarto-margin-sidebar` breakpoint).
   All icons are shaded book-blue regardless of network. */

.d2l-share-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6A717B;
}

.d2l-share-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #1976D2;
  background: transparent;
  text-decoration: none;
  transition: background 0.1s, color 0.1s, transform 0.1s;
}
.d2l-share-icon:hover {
  color: #2196F3;
  background: #E8F3FD;
  transform: translateY(-1px);
}
.d2l-share-icon .bi {
  display: inline-block;
  line-height: 1;
}

/* (A) — sidebar block. 4 icons in one row, sized to span the full
   width of the right-TOC column. */
.d2l-share-block {
  margin: 1rem 0 0.5rem 0;
  padding-top: 0.85rem;
  border-top: 1px solid #E7E9EC;
}
.d2l-share-block .d2l-share-label { margin-bottom: 0.55rem; }
.d2l-share-block .d2l-share-icons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}
.d2l-share-block .d2l-share-icon {
  aspect-ratio: 1 / 1;
  border-radius: 5px;
  border: 1px solid #E7E9EC;
  background: #fff;
}
.d2l-share-block .d2l-share-icon:hover {
  background: #E8F3FD;
  border-color: #BBDEFB;
}
.d2l-share-block .d2l-share-icon .bi { font-size: 1.1rem; }

/* (C) — bottom-of-article row. Roomy chip icons, generous label
   gap so "Share" doesn't collide with the icons. */
.d2l-share-bottom {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin: 2rem 0 1rem 0;
  padding-top: 1rem;
  border-top: 1px solid #E7E9EC;
}
.d2l-share-bottom .d2l-share-label {
  margin: 0 0.85rem 0 0;
  /* Tweak font-size up to match the icon scale. */
  font-size: 0.78rem;
}
.d2l-share-bottom .d2l-share-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #E8F3FD;
}
.d2l-share-bottom .d2l-share-icon .bi { font-size: 1.05rem; }

/* (C) hides when (A) is rendered AND the right TOC is showing.
   The body class `has-d2l-toc-share` is set by the share-init JS
   when `#TOC` exists and (A) was appended. The 1200px breakpoint
   matches `_d2l-theme.scss` where the right margin-sidebar becomes
   visible. */
@media (min-width: 1200px) {
  body.has-d2l-toc-share .d2l-share-bottom { display: none; }
}

@media print {
  .d2l-share-block,
  .d2l-share-bottom { display: none !important; }
}
