/*
 * Bristol Flight Lab site theme.
 *
 * Gives the Zensical site the same identity as the Flight Lab slide template:
 * the brand red header band with the edge artwork and University crest, the red
 * footer rule, Trebuchet typography, red-ruled code blocks and red table heads.
 *
 * Colours, layout and artwork are University of Bristol brand identity. The
 * artwork in assets/brand/ is copied from the slide template; keep the two in
 * step if either changes.
 *
 * The palette in zensical.toml uses the stock `default` and `slate` schemes, so
 * both inherit a complete set of theme variables. Everything below is a brand
 * override on top of them.
 */

:root {
  /* Brand palette, matching src/flightlab.css in the slide template. */
  --fl-red: #b01c2e;
  --fl-red-light: #e2394d;
  --fl-grey: #e3e6e5;
  --fl-teal: #00c0b5;
  --fl-cyan: #0cc6de;
  --fl-orange: #ee7219;
  --fl-purple: #9278d1;
  --fl-magenta: #e0249a;
  --fl-lime: #bed600;

  /* Brand furniture. The edge artwork is 204 x 76 px on a 76 px band; here it
     is scaled to the header height, so only the clear width matters. */
  --fl-header-art: 8.6rem;

  /* Typography, matching the deck. */
  --md-text-font: "Trebuchet MS", "Fira Sans", "Helvetica Neue";
  --md-code-font: "SF Mono", Menlo, Consolas, "Liberation Mono";
}

/* ---------- Colour schemes ---------- */

:root,
[data-md-color-scheme="default"] {
  --md-primary-fg-color:          #b01c2e;
  --md-primary-fg-color--light:   #c94759;
  --md-primary-fg-color--dark:    #8c1624;
  --md-primary-bg-color:          #ffffff;
  --md-primary-bg-color--light:   #ffffffb3;

  --md-accent-fg-color:           #b01c2e;
  --md-accent-fg-color--transparent: #b01c2e1a;

  --md-typeset-a-color:           #b01c2e;
  --md-code-bg-color:             #eef0ef;
  --md-code-hl-comment-color:     #00aa00;
}

[data-md-color-scheme="slate"] {
  --md-hue: 240;

  --md-primary-fg-color:          #b01c2e;
  --md-primary-fg-color--light:   #c94759;
  --md-primary-fg-color--dark:    #8c1624;
  --md-primary-bg-color:          #ffffff;
  --md-primary-bg-color--light:   #ffffffb3;

  /* Red is too dark to read as a link on a dark ground, so links and hover
     states lift to a lighter tint of the same hue. */
  --md-accent-fg-color:           #ff5f5f;
  --md-accent-fg-color--transparent: #ff5f5f1f;
  --md-typeset-a-color:           #ff5f5f;

  --md-default-bg-color:          #1e1e24;
  --md-code-bg-color:             #2e2e35;
  --md-code-fg-color:             #e0e0e0;
  --md-code-hl-comment-color:     #00aa00;
  --md-footer-bg-color:           #1e1e24;
}

/* ---------- Header: the red band ---------- */

.md-header {
  color: var(--md-primary-bg-color);
  background-color: var(--fl-red);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  background-repeat: no-repeat;
  background-position: right 0 top 0;
  background-size: auto 100%;
}

/* The edge artwork sits at the right end of the band, as on a slide. It only
   appears once the window is wide enough to clear the 61rem content column. */
@media screen and (min-width: 80em) {
  .md-header {
    background-image: url("../assets/brand/edge-header.svg");
  }
}

/* The University crest replaces the generic logo icon. */
.md-header .md-logo {
  width: 4.4rem;
  height: 1.2rem;
  background: url("../assets/brand/logo-bristol-white.svg") no-repeat center /
    contain;
}

.md-header .md-logo svg,
.md-header .md-logo img {
  display: none;
}

.md-header__title {
  font-weight: 700;
}

/* The search button's default tints are near-invisible on red. */
.md-search__button {
  color: var(--md-primary-bg-color);
  background-color: #ffffff26;
}

.md-search__button:hover {
  color: var(--md-primary-bg-color);
  background-color: #ffffff40;
}

.md-search__button::before {
  background-color: var(--md-primary-bg-color);
}

/* ---------- Navigation ---------- */

.md-nav__title {
  color: var(--md-primary-fg-color);
}

[data-md-color-scheme="slate"] .md-nav__title {
  color: var(--md-accent-fg-color);
}

/* The mobile drawer header carries the band too. The theme's own drawer rules
   are written as `.md-nav .md-nav__title[for=__drawer] ...`, so these match
   that specificity rather than losing to it. */
.md-nav .md-nav__title[for="__drawer"] {
  color: var(--md-primary-bg-color);
  background: var(--fl-red);
  border-bottom: 0;
}

.md-nav .md-nav__title[for="__drawer"] .md-logo {
  width: 5rem;
  height: 1.6rem;
  background: url("../assets/brand/logo-bristol-white.svg") no-repeat center /
    contain;
}

.md-nav .md-nav__title[for="__drawer"] .md-logo img,
.md-nav .md-nav__title[for="__drawer"] .md-logo svg {
  display: none;
}

/* ---------- Typography ---------- */

/* A red rule under the page title, echoing the band above the slide title. */
.md-typeset h1 {
  padding-bottom: 0.3em;
  margin-bottom: 0.9em;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--md-default-fg-color);
  border-bottom: 0.15rem solid var(--fl-red);
}

.md-typeset h2 {
  color: var(--md-default-fg-color);
}

/* Third-level headings are red on a slide, and red here. */
.md-typeset h3 {
  font-weight: 700;
  color: var(--fl-red);
}

[data-md-color-scheme="slate"] .md-typeset h3 {
  color: var(--md-accent-fg-color);
}

/* ---------- Code, tables, quotes ---------- */

/* The deck rules its code blocks down the left in red. */
.md-typeset pre > code {
  border-left: 0.2rem solid var(--fl-red);
  border-radius: 0 0.2rem 0.2rem 0;
}

.md-typeset table:not([class]) th {
  font-weight: 700;
  color: var(--md-primary-bg-color);
  background-color: var(--fl-red);
}

.md-typeset table:not([class]) tr:nth-child(even) td {
  background-color: var(--md-typeset-table-color--light);
}

.md-typeset blockquote {
  padding: 0.6rem 0.8rem;
  color: var(--md-default-fg-color);
  background-color: var(--md-default-fg-color--lightest);
  border-left: 0.2rem solid var(--fl-red);
}

/* Brand furniture is square-cornered; soften the theme's rounding to match. */
.md-typeset .admonition,
.md-typeset details {
  border-radius: 0.1rem;
}

/* Language tabs pick up the brand red rather than the default ink. */
.md-typeset .tabbed-labels::before {
  background: var(--fl-red);
}

.md-typeset .tabbed-set > input:checked + label {
  font-weight: 700;
  color: var(--fl-red);
}

.md-typeset .tabbed-labels > label:hover {
  color: var(--fl-red);
}

[data-md-color-scheme="slate"] .md-typeset .tabbed-labels::before,
[data-md-color-scheme="slate"] .md-typeset .tabbed-set > input:checked + label,
[data-md-color-scheme="slate"] .md-typeset .tabbed-labels > label:hover {
  color: var(--md-accent-fg-color);
  background-color: initial;
}

[data-md-color-scheme="slate"] .md-typeset .tabbed-labels::before {
  background: var(--md-accent-fg-color);
}

/* ---------- Footer: the red rule ---------- */

.md-footer-meta {
  color: var(--md-primary-bg-color);
  background-color: var(--fl-red);
}

/* The `html` here is load-bearing. Zensical's own rule is
   `html .md-footer-meta.md-typeset a:not(:focus, :hover)`, and that leading
   type selector outspecifies a bare class selector, so without it the links
   keep the stock near-black colour and are unreadable on the red band.
   Underlined in every state: white on red is not, by itself, a link. */
html .md-footer-meta.md-typeset a,
html .md-footer-meta.md-typeset a:not(:focus, :hover) {
  color: var(--md-primary-bg-color);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

html .md-footer-meta.md-typeset a:focus,
html .md-footer-meta.md-typeset a:hover {
  color: var(--md-primary-bg-color);
  text-decoration-thickness: 0.15em;
}

/* The copyright line sets its own muted grey, which on the red band is neither
   readable nor brand. Both halves of it go white. */
.md-copyright,
.md-copyright__highlight {
  color: var(--md-primary-bg-color);
}

/* ---------- Accent text, matching the deck's utility classes ---------- */

.md-typeset .red { color: var(--fl-red); }
.md-typeset .teal { color: var(--fl-teal); }
.md-typeset .cyan { color: var(--fl-cyan); }
.md-typeset .orange { color: var(--fl-orange); }
.md-typeset .purple { color: var(--fl-purple); }
.md-typeset .magenta { color: var(--fl-magenta); }
.md-typeset .lime { color: var(--fl-lime); }

@media print {
  .md-typeset h1 {
    border-bottom-color: var(--fl-red);
  }
}

/* ---------- Footer: the bits Material leaves too small or invisible ---------- */

/* Material's copyright line is small enough to be hard work at the foot of a
   long page. */
html .md-footer-meta .md-copyright {
  font-size: 0.7rem;
  line-height: 1.5;
}

/* A visible keyboard focus ring on the red band. It has to be white: the accent
   colour is itself this red, so an accent outline disappears into the band.
   Never rely on colour alone for state. */
html .md-footer-meta.md-typeset a:focus-visible {
  outline: 2px solid var(--md-primary-bg-color);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------- A unit's own mark on the Home entry ---------- */

/* Zensical puts a stock plane icon beside Home. A unit that has its own mark
   sets --fl-nav-mark to an SVG data URI and it is swapped in, as a mask so it
   follows the nav's colour in both schemes. A unit that sets nothing keeps the
   stock icon, so this is inert until asked for. */
:root {
  --fl-nav-mark: none;
}

/* The guard is a container style query, and its polarity is deliberate: the
   mark is emitted only *inside* the query, so a browser without style-query
   support ignores the whole block and keeps the stock icon. Guarding the other
   way round — emit always, switch off in the query — would show a bare
   currentColor square everywhere the query did not apply, which is what the
   `:not([style*=…])` guard this replaces did on every site: it tested the
   inline style attribute, which a nav link never has, so it matched always.
   Custom properties inherit, so the query is answered by the nav item's parent
   carrying the value down from :root. */
@container style(not (--fl-nav-mark: none)) {
  .md-nav__link:has(svg.lucide-plane)::before {
    content: "";
    flex-shrink: 0;
    width: 1.2em;
    height: 1.2em;
    margin-right: 0.3em;
    background-color: currentColor;
    mask: var(--fl-nav-mark) no-repeat center / contain;
    -webkit-mask: var(--fl-nav-mark) no-repeat center / contain;
  }

  /* The theme hides the stock icon itself, so setting the one variable is the
     whole of the change a unit makes. A unit that also carries its own
     `display: none` for the plane from before is simply redundant now. */
  .md-nav__link svg.lucide-plane {
    display: none;
  }
}
