/* ==========================================================================
   Home page: foundation

   Sections, type, spacing, the section rule and the reveal-on-scroll states.
   Every selector that styles a paragraph or heading starts with `.xh` and a
   class, which outranks the documentation typography (`.md-typeset p`,
   `.md-typeset h2`) without `!important`.
   ========================================================================== */

.xh {
  position: relative;
  font-size: 0.84rem;
  line-height: 1.7;
  letter-spacing: -0.006em;
  color: var(--xh-fg);
}

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

.xh p {
  margin: 0;
}

.xh h2,
.xh h3,
.xh h4 {
  margin: 0;
  padding: 0;
  color: var(--xh-fg);
}

.xh h2::before {
  content: none;
}

.xh .headerlink {
  display: none;
}

/* Sections ----------------------------------------------------------------- */

.xh-sec {
  --xh-sec-bg: var(--xh-bg);
  position: relative;
  padding: 5.6rem 0;
  background: var(--xh-sec-bg);
  scroll-margin-top: 2.6rem;
}

.xh-sec--tight {
  padding: 3.6rem 0;
}

.xh-sec--join {
  padding-top: 0;
}

.xh-sec--raised {
  --xh-sec-bg: var(--xh-bg-raised);
  border-block: 1px solid var(--xh-line);
}

.xh-sec--deep {
  --xh-sec-bg: var(--xh-deep);
  border-block: 1px solid var(--xh-line);
  overflow: hidden;
  /* Clip without becoming a scroll container, so that a drawing inside the
     section can still be held in the window while it plays. */
  overflow: clip;
}

/* Two bands in a row share the one rule between them. */
.xh-sec--raised + .xh-sec--raised,
.xh-sec--raised + .xh-sec--deep,
.xh-sec--deep + .xh-sec--raised,
.xh-sec--deep + .xh-sec--deep {
  border-top: 0;
}

/* A faint drafting grid behind the deep bands, fading towards the edges. */
.xh-sec--deep::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--xh-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--xh-line) 1px, transparent 1px);
  background-size: 2.6rem 2.6rem;
  background-position: center top;
  opacity: 0.38;
  -webkit-mask-image: radial-gradient(ellipse 75% 70% at 50% 40%, #000 0, transparent 100%);
  mask-image: radial-gradient(ellipse 75% 70% at 50% 40%, #000 0, transparent 100%);
  pointer-events: none;
}

/* A soft teal glow, placed by --gx / --gy per section. */
.xh-sec--glow::after {
  content: "";
  position: absolute;
  top: var(--gy, 20%);
  left: var(--gx, 70%);
  width: 46rem;
  height: 46rem;
  margin: -23rem 0 0 -23rem;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--xh-teal) 15%, transparent) 0, transparent 62%);
  pointer-events: none;
}

/* On the light slate the drafting grid and the glow need more strength to
   read as they do on the dark one. */
[data-md-color-scheme="default"] .xh-sec--deep::before {
  opacity: 0.62;
}

[data-md-color-scheme="default"] .xh-sec--glow::after {
  background: radial-gradient(circle, color-mix(in srgb, var(--xh-teal) 24%, transparent) 0, transparent 62%);
}

.xh-wrap {
  position: relative;
  z-index: 1;
  max-width: var(--xh-max);
  margin: 0 auto;
  padding: 0 var(--xh-pad);
}

.xh-wrap--narrow {
  max-width: 44rem;
}

.xh-center {
  text-align: center;
}

.xh .xh-center > * {
  margin-left: auto;
  margin-right: auto;
}

/* Spacing ------------------------------------------------------------------ */

.xh .xh-mt-xs { margin-top: 0.7rem; }
.xh .xh-mt-s  { margin-top: 1.2rem; }
.xh .xh-mt-m  { margin-top: 2rem; }
.xh .xh-mt-l  { margin-top: 3.2rem; }
.xh .xh-mt-xl { margin-top: 4.8rem; }

/* Layout ------------------------------------------------------------------- */

.xh .xh-cols {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 3rem;
  align-items: start;
}

.xh .xh-cols--center { align-items: center; }
.xh .xh-cols--5-7 { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }
.xh .xh-cols--4-8 { grid-template-columns: minmax(0, 4fr) minmax(0, 8fr); }

.xh .xh-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr));
  gap: 0.9rem;
}

.xh .xh-sticky {
  position: sticky;
  top: 4.6rem;
}

/* Chapter heading: number, name, and the rule that fills from the origin ---- */

.xh .xh-chap {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  margin-bottom: 2.3rem;
}

.xh .xh-chap__k {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  font-family: var(--md-code-font);
  font-size: 0.62rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--xh-teal-text);
}

.xh .xh-chap__n {
  color: var(--xh-fg-3);
}

.xh .xh-rule {
  position: relative;
  flex: 1;
  display: block;
  height: 1px;
  background: var(--xh-line);
}

.xh .xh-rule::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
              var(--xr-teal) 0,
              var(--xr-teal-bright) 35%,
              transparent 100%);
  transform: scaleX(1);
  transform-origin: 0 50%;
}

/* The centred variant grows from the middle to both edges, as under the hero. */
.xh .xh-rule--center {
  flex: none;
  width: 100%;
}

.xh .xh-rule--center::after {
  background: linear-gradient(90deg,
              transparent 0,
              var(--xr-teal) 22%,
              var(--xr-teal-bright) 50%,
              var(--xr-teal) 78%,
              transparent 100%);
  transform-origin: center;
}

.xh-js .xh .xh-rule::after {
  transform: scaleX(0);
  transition: transform 1.7s cubic-bezier(0.45, 0, 0.2, 1) 0.15s;
}

.xh-js .xh .is-in .xh-rule::after,
.xh-js .xh .xh-rule.is-in::after {
  transform: scaleX(1);
}

/* Type --------------------------------------------------------------------- */

.xh .xh-h {
  max-width: 22ch;
  font-size: 2.2rem;
  font-weight: 680;
  line-height: 1.08;
  letter-spacing: -0.036em;
  text-wrap: balance;
}

.xh .xh-h--wide { max-width: 28ch; }
.xh .xh-h--xl { font-size: 2.75rem; max-width: 20ch; }

.xh .xh-h em,
.xh .xh-h3 em,
.xh .xh-say em {
  font-style: normal;
  color: var(--xh-teal-text);
}

.xh .xh-h3 {
  max-width: 30ch;
  font-size: 1.36rem;
  font-weight: 660;
  line-height: 1.2;
  letter-spacing: -0.026em;
  text-wrap: balance;
}

.xh .xh-h4 {
  font-size: 0.94rem;
  font-weight: 640;
  line-height: 1.3;
  letter-spacing: -0.014em;
}

.xh .xh-lead {
  max-width: 41rem;
  margin-top: 1.2rem;
  font-size: 1rem;
  line-height: 1.62;
  color: var(--xh-fg-2);
}

/* A lead that opens onto a centred figure stands on the same axis. Where the
   figure folds to the left edge on a narrow screen, so does the lead. */
.xh .xh-lead--center {
  margin-right: auto;
  margin-left: auto;
  text-align: center;
}

@media screen and (max-width: 50em) {
  .xh .xh-lead--center {
    margin-left: 0;
    text-align: left;
  }
}

.xh .xh-p {
  max-width: 39rem;
  margin-top: 0.95rem;
  color: var(--xh-fg-2);
}

.xh .xh-lead strong,
.xh .xh-p strong {
  font-weight: 620;
  color: var(--xh-fg);
}

.xh .xh-p code,
.xh .xh-lead code {
  font-size: 0.86em;
}

.xh .xh-kicker {
  display: block;
  margin-bottom: 0.95rem;
  font-family: var(--md-code-font);
  font-size: 0.6rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--xh-teal-text);
}

.xh .xh-kicker--mute { color: var(--xh-fg-3); }
.xh .xh-kicker--warn { color: var(--xh-warn); }

/* Statements: the lines the page is built around. */
.xh .xh-say {
  max-width: 26ch;
  font-size: 1.75rem;
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: -0.032em;
  text-wrap: balance;
  color: var(--xh-fg);
}

.xh .xh-say--xl { font-size: 2.7rem; line-height: 1.1; max-width: 20ch; }
.xh .xh-say--m  { font-size: 1.32rem; line-height: 1.3; max-width: 34ch; }
.xh .xh-say--wide { max-width: 34ch; }

/* A closing line under a centred or symmetric drawing stands on the drawing's
   axis. Where the page folds to one column, it folds to the left edge with
   the leads, so a long line never runs centred down a phone. */
.xh .xh-say--center {
  margin-right: auto;
  margin-left: auto;
  text-align: center;
}

@media screen and (max-width: 50em) {
  .xh .xh-say--center {
    margin-left: 0;
    text-align: left;
  }
}

.xh .xh-say span.xh-dim {
  color: var(--xh-fg-3);
}

.xh .xh-quote {
  max-width: 38rem;
  padding: 0.25rem 0 0.25rem 1.35rem;
  border-left: 2px solid var(--xh-teal);
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1.38;
  letter-spacing: -0.02em;
  color: var(--xh-fg);
}

.xh .xh-quote code {
  font-size: 0.82em;
  font-weight: 500;
}

.xh .xh-note {
  font-size: 0.72rem;
  line-height: 1.55;
  color: var(--xh-fg-3);
}

.xh .xh-mono {
  font-family: var(--md-code-font);
  font-size: 0.92em;
  letter-spacing: 0;
}

.xh .xh-teal { color: var(--xh-teal-text); }
.xh .xh-warn { color: var(--xh-warn); }

/* Reveal on scroll ---------------------------------------------------------
   Content is visible by default. The inline flag at the top of the page adds
   `xh-js` to <html>, which arms the hidden state; the observer in home.js
   then releases each block as it enters the viewport. */

.xh-js .xh [data-xh] {
  opacity: 0;
  transform: translate3d(0, 18px, 0);
  transition: opacity 0.85s cubic-bezier(0.2, 0.65, 0.2, 1),
              transform 0.85s cubic-bezier(0.2, 0.65, 0.2, 1);
  transition-delay: calc(var(--i, 0) * 75ms);
}

.xh-js .xh [data-xh].is-in {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .xh-js .xh [data-xh] {
    opacity: 1;
    transform: none;
    transition: none;
  }

  .xh-js .xh .xh-rule::after {
    transform: scaleX(1);
    transition: none;
  }
}

/* Narrow screens ----------------------------------------------------------- */

@media screen and (max-width: 60em) {
  .xh-sec { padding: 4rem 0; }
  .xh-sec--tight { padding: 2.8rem 0; }
  .xh-sec--join { padding-top: 0; }

  .xh .xh-cols,
  .xh .xh-cols--5-7,
  .xh .xh-cols--4-8 {
    grid-template-columns: minmax(0, 1fr);
    gap: 2.2rem;
  }

  .xh .xh-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .xh .xh-sticky { position: static; }

  .xh .xh-h { font-size: 1.85rem; }
  .xh .xh-h--xl { font-size: 2.15rem; }
  .xh .xh-say { font-size: 1.45rem; }
  .xh .xh-say--xl { font-size: 2.05rem; }
  .xh .xh-say--m { font-size: 1.16rem; }
  .xh .xh-mt-xl { margin-top: 3.4rem; }
  .xh .xh-mt-l { margin-top: 2.4rem; }
}

@media screen and (max-width: 38em) {
  .xh .xh-grid { grid-template-columns: minmax(0, 1fr); }
  .xh .xh-h { font-size: 1.6rem; }
  .xh .xh-h--xl { font-size: 1.8rem; }
  .xh .xh-h3 { font-size: 1.18rem; }
  .xh .xh-say { font-size: 1.28rem; }
  .xh .xh-say--xl { font-size: 1.72rem; }
  .xh .xh-lead { font-size: 0.92rem; }
  .xh .xh-quote { font-size: 1.04rem; }
}
