/* "On this page": the headings of the open file, in the right margin of c-page, level with the text as it scrolls. Below --bp-toc
   a panel at the right, shown when it has .is-open. The entry for the section in view has .is-current (a Stimulus controller, M5):
   italic and a darker rule, so not by colour alone. <aside class="c-toc" id="toc" aria-label="Contents of this document"><p
   class="c-toc__heading">On this page</p><a class="c-toc__link c-toc__link--level-2" href="#slug">Heading</a></aside>

   c-toc--book: the contents of a public page in the book layout (pages/<name>.md, stories/_book), with no rules: from
   --bp-book-toc up fixed at the right edge of the window in small muted type, the current entry in the ink, italic, with a short
   hairline hanging before it; below --bp-book-toc the same panel as "On this page", opened with Contents in c-running-head.
   <nav class="c-toc c-toc--book" id="toc" aria-label="Contents"><p class="c-toc__heading">Contents</p><a class="c-toc__link
   c-toc__link--level-2 is-current" aria-current="location" href="#slug">Heading</a></nav> */

.c-toc {
  position: sticky;
  top: calc(var(--topbar-height) + var(--space-6));
  align-self: start;
  max-height: calc(100vh - var(--topbar-height) - var(--space-7) - var(--space-4));
  overflow-y: auto;
  line-height: 1.25;
}

.c-toc__heading { margin-bottom: var(--space-3); color: var(--color-ink-muted); font-variant-caps: all-small-caps; letter-spacing: var(--tracking-caps-wide); }
.c-toc__link { display: block; padding: 0.22rem 0 0.22rem var(--space-3); border-left: var(--stroke-hair) solid var(--color-rule); color: var(--color-ink-muted); text-decoration: none; }
.c-toc__link:hover { color: var(--color-ink); }
.c-toc__link--level-3 { padding-left: var(--space-6); font-size: 0.92em; }
.c-toc__link.is-current { border-left-color: var(--color-ink); color: var(--color-ink); font-style: italic; }

@media (max-width: 88rem) {
  .c-toc {
    position: fixed;
    top: var(--topbar-height);
    right: 0;
    bottom: 0;
    z-index: var(--z-panel);
    display: none;
    align-self: auto; /* "start" would keep a fixed box at its content height instead of stretching it from top to bottom */
    width: min(20rem, 85vw);
    max-height: none;
    padding: var(--space-5);
    border-left: var(--stroke-hair) solid var(--color-rule);
    background-color: var(--color-paper);
    background-image: var(--paper-grain);
  }
  .c-toc.is-open { display: block; }
}

.c-toc--book .c-toc__link { padding-left: var(--space-4); border-left: 0; }
.c-toc--book .c-toc__link--level-3 { padding-left: var(--space-6); }
.c-toc--book .c-toc__link.is-current::before { content: ""; display: inline-block; width: 0.6em; margin: 0 0.35em 0 -0.95em; border-top: var(--stroke-hair) solid currentColor; vertical-align: 0.3em; }

/* From --bp-book-toc the text block, centred at its full measure, leaves room at the right for the list. The rules after the
   max-width: 88rem block above win over the panel's for the same specificity. */
@media (width >= 80rem) {
  .c-toc--book {
    position: fixed;
    top: var(--space-7);
    right: var(--space-5);
    bottom: auto;
    display: block;
    width: 13rem;
    max-height: calc(100vh - 2 * var(--space-7));
    padding: 0;
    border-left: 0;
    background: none;
    font-size: 0.95rem;
  }
}

@media print {
  .c-toc { display: none; }
}
