@layer layouts {
  html, body {
    scroll-padding-top: calc(var(--nav-height) + 4rem);
  }
  body {
    background: top left / 100vw max(30vw, 24rem) no-repeat linear-gradient(
      -10deg,
      transparent 50%,
      var(--hero-accent-color)
    );
  }

  #hero {
    padding-block: 8rem 0;
    .backlink {
      display: flex;
      align-items: center;
      gap: .5em;
      padding: .2rem .8rem;
      margin: 0 0 1rem;
      color: black;
      text-decoration: none;
      font-size: 1.1rem;
      font-weight: 500;
      &:hover {
        text-decoration: underline;
        text-underline-offset: .4em;
      }
      svg {
        width: 1rem;
        height: 1rem;
      }
    }
    h1 {
      margin: 0;
      font-size: clamp(2rem, 3.4vw + 1rem, 3.7rem);
    }
    .byline {
      margin: 1rem 0 0;
      font-size: .95rem;
      color: #555;
    }
  }

  #content {
    display: grid;
    padding: 4rem max((100% - 1200px) / 2 + 2rem, 2rem) 0;
    margin: 0 auto;
    grid-template: "article sidebar" auto / 740px 1fr;
    gap: 4rem;
    place-items: start stretch;
    @media (width < 1200px){
      grid-template: "article sidebar" auto / minmax(0, auto) 25%;
    }
    @media (width < 900px){
      grid-template: "article" auto / minmax(auto, 100%);
    }
  }

  #sidebar {
    grid-area: sidebar;
    max-height: calc(100vh - var(--nav-height) - 4rem);
    position: sticky;
    top: calc(var(--nav-height) + 2rem);
    overflow: auto;
    @media (width < 900px){
      display: none;
    }
  }

  article {
    grid-area: article;
    min-width: 0;
    & > :first-child {
      margin-top: 0;
    }
    & > h2 {
      font-size: 2rem;
      margin: 2.5em 0 1em;
    }
    & > h3 {
      font-size: 1.4rem;
      margin: 2em 0 1em;
    }
    & > h4 {
      font-size: 1.2rem;
      margin: 2em 0 1em;
    }
    & > p { margin: 1.4em auto; }
    & > p:not(h2 ~ p){ font-size: 1.1rem; }
    & > img, & > .captioned-image img {
      display: block;
      max-width: 100%;
      height: auto;
      margin: 4rem auto;
      border-radius: .5rem;
    }
    & > .captioned-image {
      margin: 4rem auto;
      text-align: center;
      img { margin: .5rem auto; }
      figcaption {
        font-style: italic;
      }
    }
    & > .chart {
      margin: 3rem 0;
    }
    & > .cta-strip {
      margin: 3rem 0;
      background-size: 100% 100%;
      border-radius: .5rem;
    }
    & > .callout {
      padding: 1rem 1rem 1rem 3.6rem;
      margin: 2rem 0;
      position: relative;
      border-radius: .5rem;
      .callout-title {
        margin: 0;
        position: absolute;
        inset: clamp(1rem, .8rem + 6%, 1.2rem) auto auto 1.2rem;
        svg {
          width: 1.4rem;
          height: 1.4rem;
        }
      }
      &.callout-tip {
        background-color: #e0f3ff;
        .callout-title svg { fill: #0580ce; }
      }
      &.callout-answer {
        padding: 1.2rem 1.5rem;
        font-size: 1.15rem;
        font-weight: 500;
        background-color: #eef1ff;
        border-left: .3rem solid #245aff;
        border-radius: .2rem .5rem .5rem .2rem;
      }
      .callout-title + * { margin-top: 0; }
      & > :last-child { margin-bottom: 0; }
    }
    :is(p, cite, figcaption, li) a {
      color: #245aff;
      text-decoration: none;
      &:hover { text-decoration: underline; }
    }
    .katex {
      display: block;
      margin: 2rem clamp(0rem, 10vw - 3rem, 2rem);
      overflow-x: auto;
    }
    math {
      min-width: 100%;
      width: max-content;
      padding: 1.5rem 1rem;
      box-sizing: border-box;
      background-color: #f7f8ff;
      border-radius: .4rem;
      letter-spacing: -.04ch;
      font-size: clamp(1rem, 2vw + .4rem, 1.2rem);
    }
    .blockquote {
      display: grid;
      grid: auto / 5rem 1fr;
      gap: 1rem;
      margin: 3rem 0;
      &:not(:has(img)){
        grid: auto / 1fr;
        blockquote { border-top-left-radius: 1rem; }
      }
      img {
        display: block;
        max-width: 100%;
        height: auto;
        margin: 0;
        border-radius: 50%;
      }
      blockquote {
        display: flex;
        flex-direction: column;
        gap: .6rem;
        padding: 1.3rem;
        margin: 0;
        background: linear-gradient(-40deg, #ffeae0, #d3f5ff 70%);
        border-radius: 2rem 1rem 1rem 1rem;
      }
      cite {
        font-weight: 600;
      }
      @media(width < 500px){
        grid: auto auto / 4rem 1fr;
        gap: .5rem;
      }
    }
    @media(width < 500px){
      .chart { margin-inline: -1.5rem; }
    }
  }

  /* Shared table styling for both the main article body and FAQ answers
     (FAQ answer HTML — e.g. disambiguation tables — renders inside #faq,
     a sibling of article, so it needs its own selector here). */
  article table, #faq table {
    width: 100%;
    max-width: 100%;
    margin: 2rem 0;
    border-collapse: collapse;
    table-layout: fixed;
    font-size: 1rem;
    th, td {
      padding: .7rem 1rem;
      text-align: left;
      border-bottom: 1px solid #e2e4f0;
      overflow-wrap: break-word;
    }
    th {
      background-color: #f7f8ff;
      font-weight: 600;
    }
    /* Comparison tables conventionally lead with a blank corner header
       cell above the row labels. table-layout: fixed sizes columns off
       that header row, so without an explicit width the empty cell (and
       the label column below it) collapses to near-zero and the row
       labels overflow on top of the next column. */
    th:first-child, td:first-child {
      width: 25%;
    }
    @media (width < 600px){
      display: block;
      overflow-x: auto;
    }
  }
}


