/* ==========================================================================
   Home page: site chrome

   The landing page is a website, so the documentation chrome steps back:
   the content runs full-bleed, the documentation navigation becomes a drawer
   that the "Docs" button in the header opens, and the previous/next footer
   links are replaced by the page's own closing section.

   `.xh` wraps everything under the hero and exists only on the home page, so
   `body:has(.xh)` is the page selector. Browsers without :has() keep the
   standard documentation layout.
   ========================================================================== */

body:has(.xh) {
  --xh-bg:        var(--md-default-bg-color);
  --xh-bg-raised: var(--xr-surface);
  --xh-bg-card:   var(--xr-surface-raised);
  --xh-line:      var(--xr-border);
  --xh-fg:        var(--md-default-fg-color);
  --xh-fg-2:      var(--md-default-fg-color--light);
  --xh-fg-3:      var(--md-default-fg-color--lighter);
  --xh-teal:      var(--xr-teal);
  --xh-teal-2:    var(--xr-teal-bright);
  --xh-max:       58rem;
  --xh-pad:       1.2rem;
}

[data-md-color-scheme="slate"]:has(.xh) {
  --xh-deep:      #171a20;
  --xh-teal-text: var(--xr-teal-bright);
  --xh-warn:      #ec8275;
  --xh-shadow:    rgba(0, 0, 0, 0.45);
}

/* Light: the teal of fills, glows and lit lines a shade deeper, so what reads
   as light on the dark slate still reads on the light one. */
[data-md-color-scheme="default"]:has(.xh) {
  --xh-deep:      #cad0d8;
  --xh-teal:      #2a8a84;
  --xh-teal-2:    #1e7a74;
  --xh-teal-text: var(--xr-teal-deep);
  --xh-warn:      #b23e32;
  --xh-shadow:    rgba(17, 17, 16, 0.18);
}

@media (prefers-reduced-motion: no-preference) {
  html:has(.xh) {
    scroll-behavior: smooth;
  }
}

/* Full-bleed content ------------------------------------------------------- */

body:has(.xh) .md-main__inner {
  max-width: none;
  margin-top: 0;
}

/* The theme indents the content beside a sidebar with a selector this file
   cannot outrank; on this page there is no sidebar beside it. */
body:has(.xh) .md-content > .md-content__inner {
  margin: 0 !important;
  padding: 0;
}

body:has(.xh) .md-content__inner::before {
  content: none;
}

body:has(.xh) .md-footer__inner {
  display: none;
}

/* Hero: fills the first screen, with the scroll cue resting on its lower edge */

body:has(.xh) .md-typeset .xr-hero {
  min-height: calc(100svh - 2.8rem);
  padding: 1.6rem var(--xh-pad) 1.5rem;
  margin-bottom: 0;
}

body:has(.xh) .md-typeset .xr-hero > p:first-of-type {
  margin-top: auto;
}

body:has(.xh) .md-typeset .xr-hero__cue {
  margin-top: auto;
  padding-top: 1.8rem;
}

/* Header: the logo on the left; on the right the action cluster reads palette
   toggle, search, then "Docs". Whatever the theme adds after the search (the
   repository link, once one is configured) lines up beside "Docs". ------------ */

body:has(.xh) .md-header__button.md-logo {
  display: inline-block;
}

body:has(.xh) .md-header__option {
  order: 1;
}

body:has(.xh) .md-header__button[for="__search"],
body:has(.xh) .md-header .md-search {
  order: 2;
}

/* "Docs" is the theme's own navigation toggle, shown at every width and sized
   to sit beside the search field as one of the header's options. */
body:has(.xh) .md-header__button[for="__drawer"] {
  order: 3;
  display: inline-flex;
  align-items: center;
  gap: 0.36rem;
  height: 1.6rem;
  padding: 0 0.72rem 0 0.6rem;
  margin: 0 0 0 0.5rem;
  border: 1px solid color-mix(in srgb, var(--xr-teal) 55%, var(--xr-border));
  border-radius: 0.4rem;
  background: color-mix(in srgb, var(--xr-teal) 10%, transparent);
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.01em;
  white-space: nowrap;
  transition: background-color 140ms ease, border-color 140ms ease;
}

body:has(.xh) .md-header__button[for="__drawer"]::after {
  content: "Docs";
}

body:has(.xh) .md-header__button[for="__drawer"]:hover {
  opacity: 1;
  border-color: var(--xr-teal);
  background: color-mix(in srgb, var(--xr-teal) 20%, transparent);
}

body:has(.xh) .md-header__button[for="__drawer"] svg {
  width: 0.78rem;
  height: 0.78rem;
}

/* The repository slot follows "Docs". While it is empty it takes no room, so
   the cluster ends flush with the edge of the header. */
body:has(.xh) .md-header__source {
  order: 4;
}

body:has(.xh) .md-header__source:not(:has(*)) {
  display: none;
}

/* Documentation navigation: a drawer at every width ------------------------- */

@media screen and (min-width: 76.25em) {
  body:has(.xh) .md-sidebar--primary {
    position: fixed;
    top: 0.4rem !important;
    left: -14.6rem;
    z-index: 5;
    display: block;
    width: 14rem;
    height: calc(100% - 0.8rem) !important;
    padding: 0;
    background-color: var(--md-default-bg-color--light);
    border: 1px solid var(--xr-border);
    border-radius: 0.8rem;
    transition: transform 0.2s cubic-bezier(0.5, 0, 0.5, 0), box-shadow 0.2s;
    transform: translateX(0);
  }

  body:has(.xh) [data-md-toggle="drawer"]:checked ~ .md-container .md-sidebar--primary {
    box-shadow: 0 24px 80px -12px var(--xh-shadow);
    transition: transform 0.25s cubic-bezier(0.7, 0.7, 0.1, 1), box-shadow 0.25s;
    transform: translateX(15rem);
  }

  body:has(.xh) .md-sidebar--primary .md-sidebar__scrollwrap {
    position: absolute;
    inset: 0;
    height: auto !important;
    margin: 0;
    padding: 0.9rem 0.7rem;
    overscroll-behavior-y: contain;
  }

  body:has(.xh) .md-overlay {
    position: fixed;
    top: 0;
    z-index: 5;
    width: 0;
    height: 0;
    opacity: 0;
    transition: width 0s 0.5s, height 0s 0.5s, opacity 0.25s 125ms;
  }

  body:has(.xh) [data-md-toggle="drawer"]:checked ~ .md-overlay {
    width: 100%;
    height: 100%;
    opacity: 1;
    transition: width 0s, height 0s, opacity 0.25s;
  }
}

body:has(.xh) .md-overlay {
  background-color: color-mix(in srgb, var(--md-default-bg-color) 68%, transparent);
  -webkit-backdrop-filter: blur(0.3rem);
  backdrop-filter: blur(0.3rem);
}

/* Reading progress: the teal line, filling as the page is read -------------- */

.xh-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 4;
  height: 2px;
  pointer-events: none;
}

.xh-progress > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--xr-teal-deep), var(--xr-teal-bright));
  transform: scaleX(var(--xh-scroll, 0));
  transform-origin: 0 50%;
}

/* Chapter rail: where the reader is in a long page -------------------------- */

.xh-toc {
  position: fixed;
  top: 50%;
  left: 1.1rem;
  z-index: 3;
  display: none;
  flex-direction: column;
  padding-left: 0.55rem;
  opacity: 0;
  transform: translateY(-50%);
  transition: opacity 300ms ease;
  pointer-events: none;
}

.xh-toc.is-on {
  opacity: 1;
  pointer-events: auto;
}

.xh-toc::before,
.xh-toc::after {
  content: "";
  position: absolute;
  top: 0.55rem;
  bottom: 0.55rem;
  left: 0;
  width: 1px;
  background: var(--xh-line);
}

.xh-toc::after {
  background: var(--xh-teal);
  transform: scaleY(var(--xh-toc, 0));
  transform-origin: 50% 0;
}

.md-typeset .xh-toc a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.35rem;
  font-family: var(--md-code-font);
  font-size: 0.54rem;
  font-weight: 600;
  line-height: 1;
  color: var(--xh-fg-3);
  text-decoration: none;
  transition: color 160ms ease;
}

.md-typeset .xh-toc a b {
  padding: 0.28rem 0.5rem;
  border: 1px solid var(--xh-line);
  border-radius: 6px;
  background: var(--xh-bg-raised);
  font-family: var(--md-text-font);
  font-size: 0.6rem;
  font-weight: 560;
  color: var(--xh-fg);
  white-space: nowrap;
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

.md-typeset .xh-toc a:hover b,
.md-typeset .xh-toc a:focus-visible b {
  opacity: 1;
  transform: none;
}

.md-typeset .xh-toc a:hover,
.md-typeset .xh-toc a.is-active {
  color: var(--xh-teal-text);
}

@media screen and (min-width: 87.5em) {
  .xh-toc {
    display: flex;
  }
}

@media print {
  .xh-progress,
  .xh-toc {
    display: none;
  }
}
