/* style/style.css — Harrer-structured stylesheet, Hugo Coder palette */

/* ---------- Tokens: Hugo Coder light ---------- */
:root {
  --background-color: #fafafa;
  --text-color: #212121;
  --highlight-color: #1565c0;
  --highlight-hover: #0d47a1;
  --border-color: #e0e0e0;
  --grey-color: #666666;
  --line-color: #eeeeee;
  --bg-box: #f5f5f5;
  --box-border-color: #e0e0e0;
  --code-bg: #f5f5f5;
  --code-chunk-bg: linear-gradient(160deg, #f8f8f8 0%, #f1f1f1 100%);
  --code-text-color: #212121;
  --hr-border-top: 1px solid rgba(0, 0, 0, 0.1);
  --table-text-color: #212121;
  --toc-active: #e0e0e0;
}

/* ---------- Tokens: dark mode ---------- */
[data-theme="dark"] {
  --background-color: #212121;
  --text-color: #dadada;
  --highlight-color: #42a5f5;
  --highlight-hover: #90caf9;
  --border-color: #424242;
  --grey-color: #cfcfcf;
  --line-color: #424242;
  --bg-box: #2a2a2a;
  --box-border-color: #424242;
  --code-bg: #2a2a2a;
  --code-chunk-bg: linear-gradient(160deg, #2a2a2a 0%, #1f1f1f 100%);
  --code-text-color: #dadada;
  --hr-border-top: 1px solid #424242;
  --table-text-color: #dadada;
  --toc-active: #424242;
}

/* ---------- Typography ---------- */
body {
  background-color: var(--background-color);
  color: var(--text-color);
  font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.65;
  font-size: 17px;
}

h1, h2, h3, h4, h5, h6,
.book-summary {
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 600;
  color: var(--text-color);
  letter-spacing: -0.01em;
}

code, pre, kbd, samp {
  font-family: 'JetBrains Mono', 'Fira Code', SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

code {
  background-color: var(--code-bg);
  color: var(--code-text-color);
  border-radius: 4px;
  padding: 0.1em 0.3em;
}

pre {
  background-image: var(--code-chunk-bg);
  background-color: var(--code-bg);
  border-left: 3px solid var(--highlight-color);
  border-radius: 4px;
  padding: 1rem;
  overflow-x: auto;
}

a {
  color: var(--highlight-color);
  text-decoration: none;
  border-bottom: 1px dotted var(--highlight-color);
}

a:hover {
  color: var(--highlight-hover);
  border-bottom-style: solid;
}

/* ---------- Header block on landing page ---------- */
#header .title {
  font-size: 3em;
  margin-bottom: -40px;
}

#header .subtitle em {
  font-style: normal;
  font-size: 1em;
  color: var(--grey-color);
  margin-bottom: -40px;
}

#header .author em,
#header .date em {
  font-size: 0.9em;
  font-style: normal;
}

/* Landing-page floated cover */
img.cover {
  margin: 0 0 1em 1.5em;
  max-width: 250px;
  height: auto;
}

/* ---------- Figures ---------- */
p.caption,
.caption {
  color: var(--grey-color);
  margin-top: 10px;
  font-size: 0.9em;
}

.figure {
  border-top: 2px solid var(--line-color);
  border-bottom: 2px solid var(--line-color);
  padding: 0.5em 0;
  margin: 1.5em 0;
}

.inline-figure {
  border: 0;
  box-shadow: none;
}

img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

/* ---------- Horizontal rules ---------- */
hr {
  border: 0;
  border-top: var(--hr-border-top);
  margin: 2em 0;
}

/* ---------- Tables ---------- */
table {
  border-collapse: collapse;
  margin: 1.5em 0;
  color: var(--table-text-color);
}

th, td {
  border-bottom: 1px solid var(--border-color);
  padding: 0.5em 0.8em;
}

th {
  border-bottom: 2px solid var(--text-color);
  text-align: left;
}

/* ---------- Blockquotes ---------- */
blockquote {
  border-left: 3px solid var(--border-color);
  padding: 0.4em 1em;
  color: var(--text-color);
  background: var(--bg-box);
  border-radius: 0 4px 4px 0;
  position: relative;
}

/* ---------- Callout boxes ---------- */
.boxinfo, .boximportant, .boxreport, .boxquestion, .boxempty {
  padding: 1em 1em 1em 3em;
  margin-bottom: 10px;
  background: var(--bg-box);
  position: relative;
  border: 1px solid var(--box-border-color);
  border-left: 3px solid var(--highlight-color);
  border-radius: 0.25rem;
}

.boxempty {
  padding: 1em 1em 1em 1.1em;
  border-left-color: var(--border-color);
}

.boxinfo::before,
.boximportant::before,
.boxreport::before,
.boxquestion::before {
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  position: absolute;
  left: 13px;
  font-size: 28px;
  color: var(--highlight-color);
  line-height: 1;
  top: 1rem;
}

.boxinfo::before      { content: "\f0eb"; }
.boximportant::before { content: "\f06a"; }
.boxreport::before    { content: "\f570"; }
.boxquestion::before  { content: "\f059"; }

/* ---------- Drop cap ---------- */
.firstcharacter {
  color: var(--highlight-color);
  float: left;
  font-size: 40px;
  line-height: 50px;
  font-weight: 700;
  padding: 2px 8px 2px 2px;
}

/* ---------- Sidebar Part dividers ---------- */
.book-toc li.part-header {
  list-style: none;
  margin: 1.4rem 0 0.35rem;
  padding: 0.4rem 0 0.25rem;
  border-top: 1px solid var(--border-color);
  pointer-events: none;
}

.book-toc li.part-header:first-child {
  margin-top: 0.6rem;
  border-top: 0;
}

.book-toc li.part-header .part-kicker {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--grey-color);
  line-height: 1;
  margin-bottom: 0.2rem;
}

.book-toc li.part-header .part-title {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-color);
  line-height: 1.2;
}

/* ---------- Right-panel Downloads block ---------- */
.book-downloads {
  margin-top: 1.5rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--border-color);
}

.book-downloads-heading {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--grey-color);
  margin: 0 0 0.4rem;
}

.book-downloads ul {
  margin: 0;
  padding: 0;
}

.book-downloads li {
  margin: 0 0 0.25rem;
}

.book-downloads a {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
}

.book-downloads a i {
  font-size: 0.9em;
  opacity: 0.75;
}

/* Hide any stray remnant of the old per-chapter button injected into h1 */
.per-chapter-pdf-btn { display: none !important; }

/* ---------- Section-numbering muted ---------- */
.header-section-number {
  color: var(--grey-color);
}

small.text-muted {
  color: var(--grey-color) !important;
}

/* ---------- Sidebar (gitbook selector; bs4_book ignores) ---------- */
.book-summary {
  background: var(--background-color);
  border-right: 1px solid var(--border-color);
}

.book-summary ul.summary li.active > a {
  color: var(--highlight-color);
  background-color: var(--toc-active);
}

.book-summary ul.summary li a:hover {
  color: var(--highlight-color);
}

/* ---------- Citation entries ---------- */
.csl-entry {
  margin-bottom: 20px;
  padding-left: 1.5em;
  text-indent: -1.5em;
}

/* ---------- Floating dark-mode toggle ---------- */
.sticky-item {
  position: fixed;
  bottom: 30px;
  right: 30px;
  z-index: 1000;
}

.btn-circle-mode {
  width: 50px;
  height: 50px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background-color: var(--bg-box);
  color: var(--text-color);
  font-size: 22px;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 120ms ease, color 120ms ease;
}

.btn-circle-mode:hover {
  background-color: var(--highlight-color);
  color: #ffffff;
}

.btn-circle-mode i { pointer-events: none; }

/* ---------- Footer attribution ---------- */
.bookdown-attribution {
  text-align: center;
  padding: 1.5rem 0;
  font-size: 0.9em;
  color: var(--grey-color);
  border-top: 1px solid var(--border-color);
  margin-top: 3rem;
}

.bookdown-attribution a {
  border-bottom-style: solid;
}

/* ---------- Dark mode: the two surfaces the tokens did not reach ---------- */
/*
 * The token block at the top of this file recolours the page. It does not reach
 * two things bs4_book paints with literals, and both were left half-dark:
 *
 *   the search dropdown   `.aa-dropdown-menu` is `background-color: #fff`, so
 *                         the suggestions rendered as --text-color #dadada on
 *                         white: 1.40:1, which is not readable by anyone.
 *
 *   the syntax colours    bs4_book ships the a11y LIGHT palette, tuned for a
 *                         light background. On --code-bg #2a2a2a the comment
 *                         colour #545454 is 1.90:1 and the variable colour
 *                         #19177c is worse.
 *
 * Both are replaced with the a11y DARK palette, which is the same source's
 * companion and is designed for exactly this background.
 * scripts/check-contrast.R computes every pair below and fails under 4.5:1, so
 * this comment is checked rather than believed.
 */

[data-theme="dark"] {
  --hl-comment: #d4d0ab;   /* comments, annotations, operators */
  --hl-blue:    #00e0e0;   /* keywords, control flow, imports, built-ins */
  --hl-green:   #abe338;   /* strings, characters, attributes */
  --hl-orange:  #f5ab35;   /* numbers, preprocessor */
  --hl-yellow:  #ffd700;   /* data types */
  --hl-purple:  #dcc6e0;   /* functions, variables */
  --hl-red:     #ffa07a;   /* constants, errors, warnings */
}

[data-theme="dark"] .algolia-autocomplete .aa-dropdown-menu {
  background-color: var(--bg-box);
  border-color: var(--border-color);
  color: var(--text-color);
}
[data-theme="dark"] .algolia-autocomplete .aa-dropdown-menu .aa-suggestion {
  border-bottom-color: var(--border-color);
}
[data-theme="dark"] .algolia-autocomplete .aa-dropdown-menu .aa-suggestion.aa-cursor {
  background-color: #1e3a5f;
}
[data-theme="dark"] .algolia-autocomplete .aa-hint {
  color: var(--grey-color);
}

[data-theme="dark"] code span.co,
[data-theme="dark"] code span.cv,
[data-theme="dark"] code span.an,
[data-theme="dark"] code span.in,
[data-theme="dark"] code span.wa,
[data-theme="dark"] code span.op { color: var(--hl-comment); }

[data-theme="dark"] code span.kw,
[data-theme="dark"] code span.cf,
[data-theme="dark"] code span.im,
[data-theme="dark"] code span.bu,
[data-theme="dark"] code span.ot { color: var(--hl-blue); }

[data-theme="dark"] code span.st,
[data-theme="dark"] code span.vs,
[data-theme="dark"] code span.ch,
[data-theme="dark"] code span.sc,
[data-theme="dark"] code span.at { color: var(--hl-green); }

[data-theme="dark"] code span.dv,
[data-theme="dark"] code span.bn,
[data-theme="dark"] code span.fl,
[data-theme="dark"] code span.pp { color: var(--hl-orange); }

[data-theme="dark"] code span.dt { color: var(--hl-yellow); }

[data-theme="dark"] code span.fu,
[data-theme="dark"] code span.va,
[data-theme="dark"] code span.ss { color: var(--hl-purple); }

[data-theme="dark"] code span.cn,
[data-theme="dark"] code span.er,
[data-theme="dark"] code span.al,
[data-theme="dark"] code span.do { color: var(--hl-red); }

.page-provenance { font-size: 0.8rem; margin: 0.5rem 0 1rem; }

/* Keep wide teaching material usable on narrow screens. */
main { min-width: 0; }
main .figure, main figure { max-width: 100%; }
main .figure img, main figure img { max-width: 100%; height: auto; }
main .MJXc-display, main .MathJax_Display, main mjx-container[display="true"] { max-width: 100%; overflow-x: auto; overflow-y: hidden; }
@media (max-width: 767px) {
  main table { display: block; max-width: 100%; overflow-x: auto; }
  main .quarto-xref { white-space: normal; }
  main p, main li, main .csl-entry { overflow-wrap: anywhere; }
}

/* Long inline formulas remain readable without widening the whole page. */
main .math.inline {
  display: inline-block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  vertical-align: middle;
  padding-block: 0.15em;
}
