/*
Site-wide styles for futureancestors.dev.

This stylesheet is loaded by every page. It names the colours of the logo,
sets the typeface used for text and colours the links, menus and
admonitions.
*/

/*
The colours of the rose window logo.

The logo is an image, so it cannot read these names: the same values are
also written in docs/assets/img/logo.svg and docs/assets/img/icon.svg. If a
colour changes, change it in all three files.
*/
:root {
  --logo-stone: #403e3b;
  --logo-blue: #3a78dc;
  --logo-red: #c8323c;
  --logo-green: #35a362;
  --logo-yellow: #f0b429;
}

/*
Coelacanth, by Ben Whitmore, is the typeface used for text. It is served
from this site under the SIL Open Font License: see
docs/assets/fonts/OFL.txt.

The files are the author's own, compressed into the WOFF2 format so they
are quicker to fetch. Nothing else about them is changed, which is what
lets them keep the name Coelacanth under that licence.

Coelacanth has an italic at regular weight only. Where text is both bold
and italic, the browser thickens the italic.

Coelacanth's letters are smaller than those of the theme's own typeface at
the same font size. Each size-adjust below enlarges them to the height the
theme's sizes were chosen for. It applies wherever Coelacanth is used,
including the search window, which rules in this stylesheet cannot reach.
*/
@font-face {
  font-family: "Coelacanth";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  size-adjust: 128%;
  src: url("../fonts/Coelacanth.woff2") format("woff2");
}

@font-face {
  font-family: "Coelacanth";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  size-adjust: 128%;
  src: url("../fonts/CoelacanthIt.woff2") format("woff2");
}

@font-face {
  font-family: "Coelacanth";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  size-adjust: 128%;
  src: url("../fonts/CoelacanthBold.woff2") format("woff2");
}

/* The theme reads the name of its text typeface from this variable. */
:root {
  --md-text-font: "Coelacanth";
}

/*
The theme tightens the space between letters to suit its own typeface,
which Coelacanth does not need.
*/
.md-typeset {
  letter-spacing: 0;
}

/*
Links are the blue of the logo, in light and dark mode. The theme sets the
colour of links from the two attributes named here, so this rule names both
to take their place.
*/
:root,
[data-md-color-scheme][data-md-color-primary] {
  --md-typeset-a-color: var(--logo-blue);
}

/*
The theme has an accent colour for the selected page in the side menu, and
for links and menu items under the pointer or with keyboard focus. Here it
is the blue of the logo, with a pale tint of the same blue behind the
selected page in the side menu.
*/
[data-md-color-accent] {
  --md-accent-fg-color: var(--logo-blue);
  --md-accent-fg-color--transparent: color-mix(
    in srgb,
    var(--logo-blue) 10%,
    transparent
  );
}

/*
Admonitions take their colours from the logo. Each kind of admonition is
given one colour, which tints its background and colours its icon:

- blue for note, abstract and info, and for any kind not named here;
- green for tip and success;
- yellow for question and warning;
- red for failure, danger and bug;
- stone for example and quote.
*/
.md-typeset :is(.admonition, details) {
  --admonition-colour: var(--logo-blue);
}

.md-typeset :is(.tip, .success) {
  --admonition-colour: var(--logo-green);
}

.md-typeset :is(.question, .warning) {
  --admonition-colour: var(--logo-yellow);
}

.md-typeset :is(.failure, .danger, .bug) {
  --admonition-colour: var(--logo-red);
}

.md-typeset :is(.example, .quote) {
  --admonition-colour: var(--logo-stone);
}

/* Stone is too dark to see in dark mode, so a paler stone is used there. */
[data-md-color-scheme="slate"] .md-typeset :is(.example, .quote) {
  --admonition-colour: color-mix(in srgb, var(--logo-stone) 50%, white);
}

/*
The theme has its own rule for each kind of admonition. The rules below
start from :root so that they take the place of all of them.

The text of an admonition is the same size as the text around it: the theme
sets it smaller.
*/
:root .md-typeset :is(.admonition, details) {
  font-size: 1em;
  background-color: color-mix(
    in srgb,
    var(--admonition-colour) 10%,
    transparent
  );
}

/* The icon before the title of an admonition. */
:root .md-typeset :is(.admonition-title, summary)::before {
  background-color: var(--admonition-colour);
}

/* The arrow that opens and closes an admonition which can be folded. */
:root .md-typeset summary::after {
  color: var(--admonition-colour);
}

/*
The theme hides any part of a menu item that falls outside its line, so
that a long item can be cut short. Coelacanth's enlarged letters are taller
than that line, which cut the tails off letters such as g, p and y.

The padding gives the letters room above and below. The margin takes the
same amount away again, so the menu items stay where they were.
*/
.md-nav__link .md-ellipsis {
  padding-block: 0.2em;
  margin-block: -0.2em;
}

/*
The search button shows the keys that open the search window. The theme
places this hint a fixed distance from the top of the button, which suited
the height of its own typeface but leaves Coelacanth sitting low. Here the
hint is centred in the button instead, whatever its height.

A line of text keeps room beneath it for the tails of letters such as g,
and neither the hint nor the word "Search" has such letters. So both are
given more padding above than below to make up for that room. This leaves
the same space above and below the letters, and keeps the word and the
hint on the same line.
*/
.md-search__button {
  padding-block-start: 0.2em;
}

.md-search__button::after {
  top: 50%;
  padding-block: 0.38em 0.12em;
  line-height: 1.2;
  transform: translateY(-50%);
}
