/* The narrow fold, loaded last: on a phone the sidebar folds to a strip on
   top, the hero and the article tighten, and these overrides must come
   after every sheet whose rules they fold. */

/* ── Narrow screens: the sidebar folds to a horizontal strip on top ──────── */

@media (max-width: 52rem) {
  .shell {
    /* minmax(0, 1fr), not a bare 1fr: 1fr means minmax(auto, 1fr), and the
       auto minimum lets a wide code listing stretch the column past the
       viewport instead of scrolling inside its own pre. */
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .site-footer {
    grid-column: 1;
  }

  .sidebar {
    grid-row: auto;
    position: static;
    max-height: none;
    overflow: visible;
    padding: 1rem 0 0.5rem;
    border-bottom: 1px solid var(--rule);
    margin-bottom: 0.5rem;
  }

  .js .docs-nav-toggle {
    display: flex;
  }

  .js #docsNav {
    display: none;
  }

  .js #docsNav.is-open {
    display: flex;
  }

  .nav {
    flex-flow: row wrap;
    gap: 0.3rem 0.5rem;
    align-items: center;
  }

  .nav-heading {
    width: 100%;
    margin: 0.5rem 0 0;
  }

  .nav-sub {
    flex-flow: row wrap;
    margin: 0;
    border-left: none;
    padding-left: 0;
    gap: 0.3rem;
  }

  #content {
    padding-top: 1rem;
  }
}

@media (max-width: 38rem) {
  /* The links wrap under the brand on a phone, and the theme switch keeps
     the brand row's right edge instead of trailing the last link. */
  .site-header {
    flex-wrap: wrap;
    row-gap: 0.6rem;
  }

  .top-nav {
    flex-basis: 100%;
    gap: 0.9rem;
    padding-right: 2.75rem;
  }

  .theme-toggle {
    position: absolute;
    right: var(--header-inset);
    top: calc(0.7rem + var(--accent-line) - 5px);
  }

  /* The application link keeps the brand row too, beside the theme switch,
     rather than wrapping to a third header row under the links. */
  .top-nav .top-nav-app {
    position: absolute;
    right: calc(var(--header-inset) + var(--icon-button-size) + 0.6rem);
    top: calc(0.7rem + var(--accent-line) - 5px);
    box-sizing: border-box;
    height: var(--icon-button-size);
    padding: 0 0.7rem;
    display: inline-flex;
    align-items: center;
  }

  h1 {
    font-size: 2.2rem;
  }

  .hero h1 {
    font-size: 2.7rem;
  }

  /* A table scrolls inside itself here, so its value columns keep a readable
     width instead of squeezing to a word each. */
  .prose td:not(:first-child) {
    min-width: 12rem;
  }

  /* A hand-drawn diagram keeps the width its labels need and scrolls inside
     its card, as a code block does. The drawing is an img before the page
     swaps it into a .diagram. */
  .prose figure {
    overflow-x: auto;
  }

  .prose figure img[src$=".svg"],
  .prose figure .diagram {
    min-width: 34rem;
  }
}
