/* Stylesheet for the BATT documentation (pages generated by pandoc, see the
   Makefile). */

:root {
  --bg: #ffffff;
  --fg: #1f2328;
  --muted: #59636e;
  --accent: #2f5fb3;
  --accent-hover: #1d4489;
  --border: #d8dee4;
  --code-bg: #f5f7f9;
  --inline-code-bg: #eff2f5;
  --row-alt: #f8f9fa;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    "Noto Sans", Arial, sans-serif;
  /* Fonts with a good coverage of the mathematical symbols used by BATT. */
  --mono: "JuliaMono", "Fira Code", "DejaVu Sans Mono", "Cascadia Code",
    Menlo, Consolas, "Noto Sans Mono", "Noto Sans Math", monospace;
  --width: 46rem;
  --toc-width: 16rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181c;
    --fg: #e1e4e8;
    --muted: #9aa4af;
    --accent: #7aa7f0;
    --accent-hover: #a5c4f7;
    --border: #30363d;
    --code-bg: #1d2127;
    --inline-code-bg: #262b32;
    --row-alt: #1a1e23;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: 1.5rem;
}

body {
  margin: 0 auto;
  padding: 3rem 1.5rem 5rem;
  max-width: var(--width);
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
}

/* Headings */

#title-block-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}

h1, h2, h3, h4 {
  line-height: 1.25;
  font-weight: 650;
  letter-spacing: -0.01em;
}

h1.title {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

h1 {
  margin: 3rem 0 1rem;
  padding-bottom: 0.3rem;
  font-size: 1.65rem;
  border-bottom: 1px solid var(--border);
}

h2 { margin: 2.25rem 0 0.75rem; font-size: 1.3rem; }
h3 { margin: 1.75rem 0 0.5rem; font-size: 1.1rem; }

h1 code, h2 code, h3 code { font-size: 0.9em; }

/* Text */

p, ul, ol, table, pre, blockquote { margin: 0 0 1.1rem; }

p, li, blockquote {
  text-align: justify;
  hyphens: auto;
}

nav#TOC li, td, th { text-align: left; hyphens: manual; }

ul, ol { padding-left: 1.5rem; }
li { margin: 0.25rem 0; }
li > ul, li > ol { margin: 0.25rem 0; }

a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: 0.15em;
}
a:hover { color: var(--accent-hover); text-decoration: underline; }

strong { font-weight: 650; }

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

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

/* Code */

code, pre {
  font-family: var(--mono);
  font-size: 0.9em;
  font-variant-ligatures: none;
}

code {
  padding: 0.1em 0.35em;
  background: var(--inline-code-bg);
  border-radius: 4px;
}

pre {
  padding: 0.9rem 1.1rem;
  overflow-x: auto;
  line-height: 1.5;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

pre code, pre > code.sourceCode {
  padding: 0;
  font-size: inherit;
  background: none;
  border-radius: 0;
}

div.sourceCode { margin: 0 0 1.1rem; background: none; }
div.sourceCode pre { margin: 0; }
pre > code.sourceCode > span { line-height: inherit; }
pre > code.sourceCode > span > a:first-child::before { text-decoration: none; }

/* Discreet syntax highlighting, readable in both color schemes. */
code span.co { color: var(--muted); font-style: italic; }
code span.kw, code span.cf { color: var(--accent); font-weight: normal; }
code span.at, code span.ex { color: inherit; }
code span.st, code span.dv { color: #2a7f62; }
@media (prefers-color-scheme: dark) {
  code span.st, code span.dv { color: #7fcfa9; }
}

/* Tables */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

/* On narrow screens, wide tables scroll horizontally. */
@media (max-width: 40rem) {
  table { display: block; overflow-x: auto; }
}

th, td {
  padding: 0.45rem 0.8rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

th {
  font-weight: 600;
  border-bottom-width: 2px;
}

tbody tr:nth-child(even) { background: var(--row-alt); }

td code { white-space: nowrap; }

/* Table of contents */

nav#TOC {
  margin: 0 0 2.5rem;
  padding: 1rem 1.25rem;
  font-size: 0.95rem;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

nav#TOC::before {
  content: "Contents";
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

nav#TOC ul { margin: 0; padding-left: 1rem; list-style: none; }
nav#TOC > ul { padding-left: 0; }
nav#TOC li { margin: 0.15rem 0; }
nav#TOC a { color: var(--fg); }
nav#TOC a:hover { color: var(--accent); }

/* On wide screens, the table of contents is a sidebar. */
@media (min-width: 76rem) {
  body {
    max-width: calc(var(--width) + 2 * var(--toc-width) + 6rem);
    padding-left: calc(var(--toc-width) + 3rem);
    padding-right: calc(var(--toc-width) + 3rem);
  }

  nav#TOC {
    position: fixed;
    top: 3rem;
    bottom: 3rem;
    left: max(1.5rem, calc((100vw - var(--width)) / 2 - var(--toc-width) - 3rem));
    width: var(--toc-width);
    margin: 0;
    padding: 0 0.5rem 0 0;
    overflow-y: auto;
    font-size: 0.875rem;
    background: none;
    border: 0;
    border-radius: 0;
  }

  nav#TOC > ul > li { margin-top: 0.5rem; }
  nav#TOC > ul > li > a { font-weight: 550; }
  nav#TOC ul ul a { color: var(--muted); }
  nav#TOC ul ul a:hover { color: var(--accent); }
}

/* Print */

@media print {
  body { max-width: none; padding: 0; font-size: 11pt; }
  nav#TOC { display: none; }
  a { color: inherit; }
  pre { white-space: pre-wrap; }
  h1, h2, h3 { break-after: avoid; }
  pre, table { break-inside: avoid; }
}
