@font-face { font-family: "CMU Serif"; font-style: normal; font-weight: 400; src: url("fonts/cmu-serif-500-roman.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "CMU Serif"; font-style: italic; font-weight: 400; src: url("fonts/cmu-serif-500-italic.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "CMU Serif"; font-style: normal; font-weight: 700; src: url("fonts/cmu-serif-700-roman.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "CMU Serif"; font-style: italic; font-weight: 700; src: url("fonts/cmu-serif-700-italic.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "CMU Sans"; font-style: normal; font-weight: 400; src: url("fonts/cmu-sans-serif-500-roman.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "CMU Sans"; font-style: italic; font-weight: 400; src: url("fonts/cmu-sans-serif-500-italic.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "CMU Sans"; font-style: normal; font-weight: 700; src: url("fonts/cmu-sans-serif-700-roman.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "CMU Sans"; font-style: italic; font-weight: 700; src: url("fonts/cmu-sans-serif-700-italic.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "CMU Typewriter"; font-style: normal; font-weight: 400; src: url("fonts/cmu-typewriter-text-500-roman.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "CMU Typewriter"; font-style: normal; font-weight: 700; src: url("fonts/cmu-typewriter-text-700-roman.woff2") format("woff2"); font-display: swap; }

/* Colours follow preamble/general/colors.tex of the LaTeX template */
:root {
  --bg: #ffffff;
  --paper: #ffffff;
  --text: #1a1a1a;
  --muted: #595959;
  --rule: #bfbfbf;
  --header: #595959;
  --chapnum: #e0e0e0;
  --side-bg: #f6f6f6;
  --side-text: #262626;
  --side-hover: #e9e9e9;
  --side-active: #dcdcdc;
  --ref-frame: rgba(0, 0, 0, 0.30);
  --ref-back: rgba(0, 0, 0, 0.03);
  --cite-rgb: 127, 230, 252;
  --link-rgb: 255, 127, 100;
  --cite-frame: rgb(112, 207, 227);
  --cite-back: rgba(127, 230, 252, 0.20);
  --href-frame: rgb(209, 105, 83);
  --href-back: rgba(255, 127, 100, 0.15);
  --code-bg: #f3f3f3;
  --fig-bg: transparent;
  --target: #fff3b0;
  --serif: "CMU Serif", "Latin Modern Roman", "STIX Two Text", "Times New Roman", serif;
  --sans: "CMU Sans", "Latin Modern Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: "CMU Typewriter", "Latin Modern Mono", ui-monospace, Menlo, Consolas, monospace;
  --side-w: 330px;
}
:root[data-theme="dark"] {
  --bg: #16181b;
  --paper: #1c1f23;
  --text: #dedede;
  --muted: #a3a3a3;
  --rule: #4a4d52;
  --header: #a3a3a3;
  --chapnum: #2c3035;
  --side-bg: #111316;
  --side-text: #d4d4d4;
  --side-hover: #1d2024;
  --side-active: #2a2e33;
  --ref-frame: rgba(255, 255, 255, 0.28);
  --ref-back: rgba(255, 255, 255, 0.06);
  --cite-frame: rgb(70, 150, 170);
  --cite-back: rgba(127, 230, 252, 0.13);
  --href-frame: rgb(180, 95, 78);
  --href-back: rgba(255, 127, 100, 0.14);
  --code-bg: #24272c;
  --fig-bg: #f4f4f4;
  --target: #4a4320;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 1.2rem; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--serif); font-size: 19px; line-height: 1.55;
  text-rendering: optimizeLegibility;
}

/* ---------- sidebar ---------- */
#sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w);
  background: var(--side-bg); color: var(--side-text);
  border-right: 1px solid var(--rule);
  display: flex; flex-direction: column; z-index: 30;
  font-family: var(--sans); font-size: 14px; line-height: 1.35;
}
.side-head { padding: 16px 16px 10px; border-bottom: 1px solid var(--rule); }
.side-title { display: block; color: inherit; text-decoration: none; font-weight: 700; font-size: 15px; line-height: 1.3; }
.side-author { color: var(--muted); margin-top: 4px; font-size: 13px; }
.side-tools { display: flex; gap: 8px; margin: 10px 0 8px; }
.tool {
  font: inherit; font-size: 12px; color: var(--side-text); text-decoration: none; cursor: pointer;
  background: transparent; border: 1px solid var(--ref-frame); border-radius: 4px; padding: 2px 10px;
}
.tool:hover { background: var(--side-hover); }
#toc-filter {
  width: 100%; font: inherit; font-size: 13px; padding: 5px 8px; color: var(--side-text);
  background: var(--paper); border: 1px solid var(--ref-frame); border-radius: 4px;
}
.side-scroll { overflow-y: auto; padding: 8px 8px 40px; flex: 1; overscroll-behavior: contain; }
.toc, .toc ul { list-style: none; margin: 0; padding: 0; }
.toc a {
  display: flex; gap: 8px; padding: 4px 8px; color: inherit; text-decoration: none; border-radius: 4px;
}
.toc a:hover { background: var(--side-hover); }
.toc a.active { background: var(--side-active); font-weight: 700; }
.toc .tnum { flex: none; min-width: 2.3em; color: var(--muted); font-variant-numeric: tabular-nums; }
.toc-ch > a { font-weight: 700; margin-top: 6px; }
.toc-ch > ul { display: none; margin-left: 6px; border-left: 1px solid var(--rule); }
.toc-ch.open > ul { display: block; }
.toc-l1 a { font-size: 13.5px; }
.toc-l2 a { font-size: 12.5px; padding-left: 20px; color: var(--muted); }
.toc-l2 { display: none; }
.toc-ch.open .toc-l2.show { display: block; }
.toc-label { margin: 14px 8px 2px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.toc-front a, .toc-back a { font-weight: 400; }
.toc-back { margin-top: 8px; }
.toc li.hide { display: none; }

#menu-btn {
  display: none; position: fixed; top: 10px; left: 10px; z-index: 40; font-size: 20px; line-height: 1;
  background: var(--side-bg); color: var(--side-text); border: 1px solid var(--ref-frame); border-radius: 6px; padding: 7px 11px;
}
#scrim { display: none; }
#progress { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: rgb(var(--link-rgb)); z-index: 50; }

/* ---------- content ---------- */
#content { margin-left: var(--side-w); padding: 0 32px 80px; }
.chapter, .titlepage { max-width: 780px; margin: 0 auto; }
.chapter { padding-top: 56px; }
.chapter + .chapter { border-top: 1px solid var(--rule); margin-top: 56px; }
p { margin: 0 0 .9em; text-align: justify; hyphens: auto; }
a { color: inherit; }
img { max-width: 100%; height: auto; }

h1, h2, h3, h4, h5 { font-family: var(--sans); font-weight: 700; line-height: 1.2; color: var(--text); }
h1 { position: relative; font-size: 2.15rem; margin: 1.4rem 0 2rem; padding-left: 0; }
h1 .chapnum {
  position: absolute; left: -.08em; top: -.38em; z-index: 0; font-size: 4.2em; line-height: 1;
  color: var(--chapnum); font-weight: 700; pointer-events: none;
}
h1 .chaplabel { position: absolute; left: 0; top: -2.1em; font-size: .5em; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
h1 .chapnum, h1 .chaplabel { user-select: none; }
h1 .chaptitle { position: relative; z-index: 1; }
.chapter:has(h1 .chaplabel) h1 { margin-top: 2.6rem; }
h2 { font-size: 1.5rem; margin: 2.2rem 0 .8rem; }
h3 { font-size: 1.22rem; margin: 1.8rem 0 .6rem; }
h4 { font-size: 1.05rem; margin: 1.4rem 0 .5rem; }
h2 .secnum, h3 .secnum { display: inline-block; min-width: 2.6em; margin-right: .2em; }
h4 .secnum { display: inline-block; min-width: 3.9em; margin-right: .2em; }
h2:target, h3:target, h4:target { background: var(--target); }

/* LaTeX-style reference boxes */
.refbox, .pagebox, .hrefbox, .citebox, .citebox a {
  text-decoration: none; border-radius: .2em; box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
.refbox, .pagebox {
  border: 1px solid var(--ref-frame); background: var(--ref-back); padding: 0 .22em; white-space: nowrap;
}
.refbox:hover, .pagebox:hover { background: rgba(127, 127, 127, .18); }
.pagebox { font-family: var(--mono); font-size: .8em; padding: 0 .3em; }
.hrefbox { border: 1px solid var(--href-frame); background: var(--href-back); padding: 0 .22em; word-break: break-word; }
.hrefbox:hover { background: rgba(var(--link-rgb), .3); }
.citebox {
  font-family: var(--mono); font-size: .86em; border: 1px solid var(--cite-frame); background: var(--cite-back);
  padding: 0 .12em; white-space: nowrap;
}
.citebox a { padding: 0 .02em; }
.citebox a:hover { background: rgba(var(--cite-rgb), .55); }
abbr { text-decoration: none; cursor: help; }
abbr[title]:hover { text-decoration: underline dotted; }

/* equations */
.eqblock { margin: 1.1em 0; overflow-x: auto; overflow-y: hidden; padding: .2em 0; }
.eqblock p { margin: 0; text-align: center; }
.eq-anchor { position: absolute; }
mjx-container[display="true"] { margin: .2em 0 !important; }
.eqblock:target { background: var(--target); }
.eqblock + p { margin-top: 0; }

/* figures */
figure { margin: 1.6em 0; text-align: center; }
figure img { background: var(--fig-bg); border-radius: 3px; }
figure:target, .tablewrap:target { background: var(--target); outline: 6px solid var(--target); }
figcaption, .tabcaption { font-family: var(--sans); font-size: .78em; line-height: 1.45; text-align: justify; margin-top: .8em; hyphens: auto; }
.caplabel { font-weight: 700; margin-right: .2em; }
div.center { text-align: center; margin: 1.2em 0; }
div.center img { display: block; margin: 0 auto .4em; background: var(--fig-bg); }
.tablewrap { overflow-x: auto; margin: 1.5em 0; text-align: center; }
.tablewrap table { margin: 0 auto; border-collapse: collapse; font-size: .85em; }
.tablewrap td, .tablewrap th { padding: .28em .7em; border: none; text-align: center; }
.tablewrap thead { border-top: 2px solid var(--text); border-bottom: 1px solid var(--text); }
.tablewrap tbody { border-bottom: 2px solid var(--text); }
.tablewrap tbody tr:first-child td { border-top: 0; }
.tabcaption { text-align: center; max-width: 95%; margin-left: auto; margin-right: auto; }

/* chapter note (the boxed "based on the article" paragraph) */
.chapnote {
  border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); margin: 0 0 1.6em; padding: .7em 0;
  font-size: .9em; color: var(--muted);
}
.chapnote p { margin: 0; text-align: left; }

/* algorithms */
.algbox { border-top: 2px solid var(--text); border-bottom: 2px solid var(--text); margin: 1.6em 0; font-size: .92em; counter-reset: alg; }
.algcaption { font-family: var(--sans); font-size: .85em; padding: .35em .2em; border-bottom: 1px solid var(--text); }
.algbox .algline { counter-increment: alg; padding: .12em 0 .12em 2.4em; position: relative; }
.algbox .algline::before { content: counter(alg); position: absolute; left: .4em; color: var(--muted); font-size: .8em; top: .3em; }
.algline p, .algbox p { margin: 0; text-align: left; }
.algblock { margin-left: 1.3em; border-left: 1px solid var(--rule); }
.algblock .eqblock { margin: .3em 0; }

/* code */
pre, code { font-family: var(--mono); }
code { font-size: .88em; }
div.sourceCode, pre { background: var(--code-bg); border-radius: 5px; }
pre { padding: .8em 1em; overflow-x: auto; font-size: .78em; line-height: 1.45; margin: 1.1em 0; }
pre code { font-size: 1em; background: none; }
div.sourceCode { margin: 1.1em 0; position: relative; }
div.sourceCode pre { margin: 0; }

/* footnotes */
.fn { position: relative; }
.fnmark { color: rgb(var(--link-rgb)); font-family: var(--sans); font-weight: 700; cursor: pointer; padding: 0 .1em; font-size: .7em; }
.fnmark:hover, .fnmark:focus { outline: none; text-decoration: underline; }
.fnbody { display: none; }
.fnpara { display: inline; }

/* popover (citations, footnotes) */
#popover {
  position: absolute; z-index: 60; max-width: min(520px, 92vw); padding: 10px 13px; font-size: 14px; line-height: 1.45;
  font-family: var(--serif); background: var(--paper); color: var(--text); text-align: left;
  border: 1px solid var(--ref-frame); border-radius: 6px; box-shadow: 0 6px 24px rgba(0, 0, 0, .22);
}
#popover[hidden] { display: none; }
#popover .backrefs, #popover .bibnum { display: none; }
#popover a { overflow-wrap: anywhere; }

/* bibliography */
.bibliography { list-style: none; margin: 0; padding: 0; font-size: .86em; }
.bibliography li { display: flex; gap: .7em; padding: .45em 0; text-align: left; }
.bibnum { font-family: var(--mono); flex: none; min-width: 3em; text-align: right; }
.bibbody { flex: 1; min-width: 0; }
.bibliography li:target { background: var(--target); }
.bibtext { overflow-wrap: anywhere; }
.backrefs { margin-left: .4em; white-space: normal; }
.bibnote { text-align: right; font-size: .8em; color: var(--muted); }
.abbr { border-collapse: collapse; width: 100%; font-size: .92em; }
.abbr td { padding: .3em .6em; border-bottom: 1px solid var(--rule); }
.abbr td:first-child { width: 8em; font-family: var(--sans); font-weight: 700; }

/* title page */
.titlepage { text-align: center; padding: 56px 0 40px; }
.titlepage .logo { width: min(380px, 70%); margin: 0 auto 1.2rem; display: block; }
.tp-type { font-family: var(--sans); font-size: 1.5rem; font-variant: small-caps; letter-spacing: .05em; }
.titlepage hr { border: 0; border-top: 1.5px solid var(--text); margin: .8rem 0; }
.tp-title { font-size: 2.1rem; font-variant: small-caps; margin: .6rem 0; font-weight: 700; }
.tp-author { font-size: 2rem; margin-top: 1.4rem; }
.tp-id { font-size: 1.2rem; color: var(--muted); }
.tp-inst { margin: 2rem 0 1.4rem; font-size: 1.2rem; }
.tp-sup { margin: 0 auto; font-size: 1.1rem; }
.tp-sup td { padding: .15em .5em; text-align: left; }
.tp-sup td:first-child { text-align: right; }
.tp-sup td:first-child::after { content: ":"; }
.tp-actions { text-align: center; margin: 1.6rem 0 0; }
.shlok { margin: 3.5rem 0 0; padding-top: 2rem; border-top: 1px solid var(--rule); }
.shlok-sa { font-size: 1.5rem; margin-bottom: .6rem; font-family: "Noto Sans Devanagari", "Nirmala UI", "Mangal", sans-serif; }
.shlok-en { font-size: 1.1rem; }

.site-foot { max-width: 780px; margin: 60px auto 0; padding-top: 1.2rem; border-top: 1px solid var(--rule); color: var(--muted); font-size: .8rem; font-family: var(--sans); }

#totop {
  position: fixed; right: 18px; bottom: 18px; z-index: 35; width: 40px; height: 40px; font-size: 18px; cursor: pointer;
  background: var(--paper); color: var(--text); border: 1px solid var(--ref-frame); border-radius: 50%;
}
body:not(.math-loaded) mjx-container { visibility: visible; }

.frontmatter ul { padding-left: 1.4em; }
.frontmatter li { margin-bottom: .6em; }
ul, ol { padding-left: 1.6em; }
li > p { margin-bottom: .4em; }
blockquote { margin: 1em 0; padding-left: 1em; border-left: 3px solid var(--rule); color: var(--muted); }

/* ---------- small screens ---------- */
@media (max-width: 980px) {
  :root { --side-w: min(86vw, 340px); }
  #sidebar { transform: translateX(-102%); transition: transform .22s ease; box-shadow: 4px 0 24px rgba(0, 0, 0, .25); }
  body.menu-open #sidebar { transform: none; }
  #menu-btn { display: block; }
  body.menu-open #scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 25; }
  #content { margin-left: 0; padding: 40px 16px 60px; }
  .side-head { padding-top: 60px; }
  body { font-size: 17px; }
  h1 { font-size: 1.7rem; }
  h1 .chapnum { font-size: 3.4em; }
  .chapter { padding-top: 64px; }
  .titlepage { padding-top: 64px; }
  .tp-title { font-size: 1.6rem; }
}
@media print {
  #sidebar, #menu-btn, #progress, #totop, #scrim { display: none !important; }
  #content { margin: 0; padding: 0; }
  .fnbody { display: inline; font-size: .85em; }
  .fnbody::before { content: " ["; } .fnbody::after { content: "]"; }
}

.tablewrap table.wide { font-size: .72em; }
.tablewrap table.wide td, .tablewrap table.wide th { padding: .25em .4em; }
