/* The page frame at every width, from the signed-off sketches: a centred column,
   the guide's chapter list beside it on wide screens, and below 760px one menu
   that holds the header's links and, on guide pages, the chapters. */

/* the header's 1120px column plus this 16px padding each side, so both align */
.shell {
  max-width: 1152px;
  margin: 48px auto 0;
  padding-inline: 16px;
}
.shell > main {
  max-width: 880px;
  margin: 0 auto;
}
.shell.with-side {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  gap: 56px;
}
.shell.with-side > main {
  max-width: 720px;
  margin: 0;
}

.drawer {
  display: none;
}
.with-side .drawer {
  display: block;
  position: sticky;
  top: 94px;
  align-self: start;
  max-height: calc(100vh - 110px);
  overflow: auto;
  font-size: 1.044rem;
}
.drawer-label {
  margin: 0 0 6px;
  font-size: .835rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.drawer-label a {
  color: var(--label);
  text-decoration: none;
}
/* the search box heads the sidebar; its results, hidden or not, come next */
.search-results + .drawer-label {
  margin-top: 20px;
}
.chapters {
  list-style: none;
  padding: 0;
  margin: 0;
}
.chapters li {
  margin: 0;
}
.chapters a {
  display: flex;
  gap: 10px;
  padding: 5px 8px;
  margin-inline: -8px;
  border-radius: 6px;
  color: var(--ink-2);
  text-decoration: none;
}
.chapters a:hover {
  color: var(--link);
  background: var(--surface);
}
.chapters a[aria-current] {
  color: var(--heading);
  background: var(--surface);
  font-weight: 500;
}
.chapters .n {
  font-family: var(--mono-font);
  font-size: .93rem;
  color: var(--accent);
  min-width: 1.4em;
  padding-top: 2px;
}
.drawer-site {
  display: none;
}

/* the current chapter's sections, nested under it in the guide sidebar */
.toc-guide {
  list-style: none;
  margin: 2px 0 6px calc(1.4em + 2px);
  padding: 0 0 0 10px;
  border-left: 1px solid var(--line);
}
.toc-guide li {
  margin: 0;
}
.toc-guide a {
  display: block;
  padding: 4px 8px;
  margin-inline: -8px 0;
  border-radius: 6px;
  font-size: .93em;
  color: var(--ink-2);
  text-decoration: none;
}
.toc-guide a:hover {
  color: var(--link);
  background: var(--surface);
}
.toc-guide a.on {
  color: var(--heading);
  background: var(--surface);
}

/* a sidebar taller than the window shows a thin scrollbar and fades the edge
   that has more behind it. The fade is an overlay in the page colour, not a
   mask: a mask would turn the phone menu's own background transparent. */
.with-side .drawer {
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.drawer::before, .drawer::after {
  content: "";
  position: sticky;
  z-index: 1;
  display: block;
  height: 48px;
  margin-inline: -8px;
  pointer-events: none;
  opacity: 0;
}
/* sticky pins inside the scroll box's padding; offset by it to reach the edge */
.drawer::before {
  top: calc(-1 * var(--pad-top, 0px));
  margin-bottom: -48px;
  background: linear-gradient(var(--bg), transparent);
}
.drawer::after {
  bottom: calc(-1 * var(--pad-bottom, 0px));
  margin-top: -48px;
  background: linear-gradient(transparent, var(--bg));
}
.drawer.more-above::before, .drawer.more-below::after {
  opacity: 1;
}
/* the scrolling sidebar clips past its edges, where its links' and its search
   box's rings would fall */
.drawer a:focus-visible, .drawer .search input:focus-visible {
  outline-offset: -2px;
}

.menu-btn {
  display: none;
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  width: 40px;
  height: 40px;
  padding: 8px;
  cursor: pointer;
  color: var(--ink);
}
.menu-btn svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}
.menu-btn .i-close, .menu-open .menu-btn .i-open {
  display: none;
}
.menu-open .menu-btn .i-close {
  display: block;
}

@media (max-width: 760px) {
  .site-nav, .site-head .theme-btn {
    display: none;
  }
  .menu-btn {
    display: block;
  }
  .shell {
    margin-top: 32px;
  }
  .shell.with-side {
    display: block;
  }
  .with-side .drawer, .drawer {
    display: none;
  }
  .menu-open .drawer {
    display: block;
    position: fixed;
    inset: 71px 0 0 0;
    z-index: 4;
    max-height: none;
    /* the wide-screen sticky list aligns to start, which would shrink this box */
    align-self: auto;
    background: var(--bg);
    overflow: auto;
    padding: 16px 16px 40px;
    font-size: 1rem;
    --pad-top: 16px;
    --pad-bottom: 40px;
  }
  .menu-open body {
    overflow: hidden;
  }
  .drawer-site {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  .drawer .chapters + .drawer-site {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
  }
  .drawer-site a {
    color: var(--ink);
    text-decoration: none;
    padding: 6px 0;
    font-size: 1.05rem;
  }
  .drawer-site .theme-btn {
    margin-top: 10px;
  }

  /* wide tables scroll inside themselves rather than widening the page */
  main table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
  }
}
