/*
 * The site's own styles, loaded after brand.css.
 *
 * brand.css is copied unchanged from the omamori lab brand repository
 * (diagrams/out/brand.css), so it can be copied again when the brand changes.
 * It sets the primary, accent and link colours of both schemes. This
 * file adds the rest of the custom palette, the header's lower edge in dark
 * mode, the logo size, the contents box that a page's [TOC] marker renders,
 * the section numbers, the links that open each diagram at full size, the gap
 * between neighbouring citations, and unbroken code names in tables.
 */

/* The rest of the custom palette -----------------------------------------
 *
 * mkdocs.yml sets `primary: custom` and `accent: custom`, so Material leaves
 * these shades to the site. They come from the brand tokens, some with an
 * alpha: line for the light primary shade, paper and ink for faded text on the
 * header, seal (vermilion) for the accent and on-seal for text on it. The dark
 * primary shade is black, one step below the sumi header, which no token
 * defines; Material paints only the repository link in the phone's navigation
 * drawer with it.
 */
[data-md-color-scheme="default"] {
  --md-primary-fg-color--light: #2B2B2B;
  --md-primary-fg-color--dark: #000000;
  --md-primary-bg-color--light: #FFFFFFB3;
  --md-accent-fg-color--transparent: #BF3A221A;
  --md-accent-bg-color: #FFFFFF;
  --md-accent-bg-color--light: #FFFFFFB3;
}

[data-md-color-scheme="slate"] {
  --md-primary-fg-color--light: #2B2B2B;
  --md-primary-fg-color--dark: #000000;
  --md-primary-bg-color--light: #ECEBE6B3;
  --md-accent-fg-color--transparent: #E0563B1A;
  --md-accent-bg-color: #111111;
  --md-accent-bg-color--light: #111111B3;
}

/* The header in dark mode: the sumi header (#111111) and the dark page (paper,
 * #141414) are nearly the same shade, so a line in the rule token (#6A6A66)
 * marks the header's lower edge. An inset shadow draws it inside the header,
 * so nothing moves; it replaces Material's scroll shadow, which does not show
 * on a dark page. */
[data-md-color-scheme="slate"] .md-header {
  box-shadow: inset 0 -1px 0 #6A6A66;
}

/* The logo: the mark's white charm reads on the sumi header in both schemes,
 * so it is shown a little larger than Material's default. */
.md-header__button.md-logo {
  padding: 0.2rem;
}

.md-header__button.md-logo img {
  height: 1.6rem;
}

/* The contents box ---------------------------------------------------------
 *
 * `[TOC]` on its own line, right after a page's opening lines, renders the
 * page's h2 and h3 sections as <div class="toc">. mkdocs.yml limits the
 * toc extension to those two levels and titles the list "Contents".
 */
.md-typeset .toc {
  width: fit-content;
  max-width: 100%;
  margin: 1em 0 1.6em;
  padding: 0.6rem 1.2rem 0.7rem 0.9rem;
  border-left: 0.2rem solid var(--md-default-fg-color);
  background-color: var(--md-code-bg-color);
  font-size: 0.7rem;
  line-height: 1.5;
}

.md-typeset .toc .toctitle {
  display: block;
  margin-bottom: 0.3rem;
  font-weight: 700;
}

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

.md-typeset .toc li {
  margin: 0.15rem 0 0;
}

.md-typeset .toc li li {
  margin-left: 1.3rem;
}

.md-typeset .toc a {
  color: var(--md-typeset-color);
}

.md-typeset .toc a:hover,
.md-typeset .toc a:focus {
  color: var(--md-accent-fg-color);
}

/* Section numbers ----------------------------------------------------------
 *
 * CSS counters number the h2 and h3 sections as 1. and 1.1, in three places
 * that count the same headings: the page's content, its [TOC] contents box
 * and the right-hand contents list (which the mobile drawer also shows). The
 * site navigation and the page title (h1) are not numbered.
 *
 * Never type a number into a Markdown heading: lanorme's DOCS-008 flags it,
 * and the site adds the numbers.
 *
 * The content counters count only the h2 and h3 that are direct children of
 * the article. A heading inside an admonition, a tab or a details block would
 * show in the contents lists but not be counted here, and the numbers would
 * drift apart; tests/unit/test_docs_standard.py reports any such heading.
 */
.md-content__inner {
  counter-reset: section-h2;
}

.md-content__inner > h2 {
  counter-increment: section-h2;
  counter-reset: section-h3;
}

.md-content__inner > h3 {
  counter-increment: section-h3;
}

.md-content__inner > h2::before {
  content: counter(section-h2) ". ";
  color: var(--md-default-fg-color--light);
}

.md-content__inner > h3::before {
  content: counter(section-h2) "." counter(section-h3) " ";
  color: var(--md-default-fg-color--light);
}

/* The [TOC] contents box. */
.md-typeset .toc > ul {
  counter-reset: contents-h2;
}

.md-typeset .toc > ul > li {
  counter-increment: contents-h2;
}

.md-typeset .toc > ul > li > ul {
  counter-reset: contents-h3;
}

.md-typeset .toc > ul > li > ul > li {
  counter-increment: contents-h3;
}

.md-typeset .toc > ul > li > a::before {
  content: counter(contents-h2) ". ";
  color: var(--md-default-fg-color--light);
}

.md-typeset .toc > ul > li > ul > li > a::before {
  content: counter(contents-h2) "." counter(contents-h3) " ";
  color: var(--md-default-fg-color--light);
}

/* The right-hand contents list. */
.md-nav--secondary > .md-nav__list {
  counter-reset: sidebar-h2;
}

.md-nav--secondary > .md-nav__list > .md-nav__item {
  counter-increment: sidebar-h2;
}

.md-nav--secondary > .md-nav__list > .md-nav__item > .md-nav > .md-nav__list {
  counter-reset: sidebar-h3;
}

.md-nav--secondary > .md-nav__list > .md-nav__item > .md-nav > .md-nav__list > .md-nav__item {
  counter-increment: sidebar-h3;
}

.md-nav--secondary > .md-nav__list > .md-nav__item > .md-nav__link .md-ellipsis::before {
  content: counter(sidebar-h2) ". ";
}

.md-nav--secondary
  > .md-nav__list
  > .md-nav__item
  > .md-nav
  > .md-nav__list
  > .md-nav__item
  > .md-nav__link
  .md-ellipsis::before {
  content: counter(sidebar-h2) "." counter(sidebar-h3) " ";
}

/* Pages without numbers --------------------------------------------------
 *
 * The home page and the API reference set `heading_numbers: false` in their
 * front matter: the home page is a map, and the API page's sections are
 * generated from the code. overrides/main.html then puts a hidden
 * .md-heading-numbers-off marker in the article, and this rule removes the
 * numbers from the content, the contents box and the right-hand contents list.
 * !important lets one short rule outrank the longer numbering selectors above.
 */
.md-main__inner:has(.md-heading-numbers-off) .md-content__inner > :is(h2, h3)::before,
.md-main__inner:has(.md-heading-numbers-off) .toc a::before,
.md-main__inner:has(.md-heading-numbers-off) .md-nav--secondary .md-ellipsis::before {
  content: none !important;
}

/* Diagrams -----------------------------------------------------------------
 *
 * Each diagram on a page links to its own SVG, so a reader can open it at full
 * size. Material hides the image drawn for the other colour scheme; these
 * rules hide its link too, so it leaves no empty link to tab to.
 */
[data-md-color-scheme="default"] a:has(> img[src$="#only-dark"]),
[data-md-color-scheme="slate"] a:has(> img[src$="#only-light"]) {
  display: none;
}

/* Citations ----------------------------------------------------------------
 *
 * mkdocs-bibtex renders a group such as [@a; @b] as neighbouring footnote
 * superscripts, which run together, so 2, 3 and 4 read as 234. A gap sets each
 * number apart. It is a gap, not a comma, because a sibling selector skips
 * text: the rule also matches two citations with words between them, where a
 * comma would be wrong and a slightly wider space does no harm.
 */
.md-typeset sup[id^="fnref"] + sup[id^="fnref"] {
  margin-left: 0.3em;
}

/* Code in tables -----------------------------------------------------------
 *
 * Material lets inline code break anywhere (word-break: break-word), so a
 * narrow column splits a name mid-token, as in LOG_PROBABI|LITIES. In a table
 * cell, code breaks only at its spaces; a table too wide for the page scrolls
 * inside the wrapper Material gives every table.
 */
.md-typeset td code,
.md-typeset th code {
  word-break: normal;
}
