@layer components {

  /* The manual (manual/pages): the contents, then a chapter beside them, its text in a readable measure. */
  .manual__lead {
    max-width: 70ch;
    margin-bottom: 20px;
    color: var(--color-ink-muted);
  }

  .manual__chapters {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 10px;
    padding: 0;
    list-style: none;
    counter-reset: chapter;
  }

  .manual__chapter {
    padding: 14px 16px;
    background: var(--color-surface);
    border: var(--hairline) solid var(--color-line);
    border-radius: 10px;
    counter-increment: chapter;
  }

  .manual__chapter-title {
    font-weight: 600;
    color: var(--color-ink);
    text-decoration: none;

    &::before {
      content: counter(chapter) ". ";
      color: var(--color-ink-muted);
    }

    &:hover {
      color: var(--color-primary);
    }
  }

  .manual__summary {
    margin-top: 6px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--color-ink-muted);
  }

  /* A chapter: the contents in a column that stays put while it scrolls, the text beside; on a narrow screen
     the contents go above it. */
  .manual {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 32px;
    align-items: start;

    @media (width <= 900px) {
      grid-template-columns: minmax(0, 1fr);
      gap: 16px;
    }
  }

  .manual__contents {
    position: sticky;
    top: 16px;
    display: grid;
    gap: 8px;
    font-size: 13px;

    & ol {
      display: grid;
      gap: 2px;
      margin: 0;
      padding: 0;
      list-style: none;
    }

    @media (width <= 900px) {
      position: static;
    }
  }

  .manual__contents-title {
    font-weight: 600;
    color: var(--color-ink);
    text-decoration: none;
  }

  .manual__contents-link {
    display: block;
    padding: 4px 8px;
    color: var(--color-ink-muted);
    text-decoration: none;
    border-radius: 6px;

    &:hover {
      color: var(--color-ink);
    }

    &.is-current {
      color: var(--color-ink);
      background: var(--color-primary-surface);
    }
  }

  .manual__article {
    max-width: 78ch;

    &>.page__title {
      margin-bottom: 16px;
      font-size: 26px;
    }
  }

  /* The chapter's own text, from Markdown: headings, paragraphs, lists, tables, notes and pictures. */
  .manual__text {
    line-height: 1.6;

    & :is(h2, h3) {
      margin: 28px 0 10px;
      font-weight: 600;
      line-height: 1.3;
      scroll-margin-top: 16px;
    }

    & h2 {
      font-size: 19px;
    }

    & h3 {
      font-size: 16px;
    }

    & :is(p, ul, ol, table, blockquote, figure) {
      margin: 0 0 12px;
    }

    & :is(ul, ol) {
      padding-left: 22px;
    }

    & li+li {
      margin-top: 4px;
    }

    & a {
      color: var(--color-primary);
    }

    & code {
      font: 0.9em ui-monospace, monospace;
    }

    & blockquote {
      padding: 10px 14px;
      color: var(--color-ink);
      background: var(--color-primary-surface);
      border-left: 3px solid var(--color-primary);
      border-radius: 6px;

      & p:last-child {
        margin-bottom: 0;
      }
    }

    & img {
      display: block;
      max-width: 100%;
      height: auto;
      margin: 8px 0;
      border: var(--hairline) solid var(--color-line);
      border-radius: 8px;

      /* One element shot by itself (a card, the tool bar), over nothing: its own edges are the frame. */
      &.manual__part {
        border: 0;
        border-radius: 0;
      }
    }

    & table {
      width: 100%;
      font-size: 14px;
      border-collapse: collapse;
    }

    & :is(th, td) {
      padding: 6px 10px;
      text-align: left;
      vertical-align: top;
      border-bottom: var(--hairline) solid var(--color-line);
    }

    & th {
      font-weight: 600;
      color: var(--color-ink-muted);
    }
  }

  /* A whole screen's picture opens over the page (manual_zoom_controller.js), as large as the window takes it. */
  .manual__zoom {
    display: block;
    cursor: zoom-in;
  }

  .manual__lightbox {
    inset: 0;
    width: 100vw;
    max-width: none;
    height: 100dvh;
    max-height: none;
    margin: 0;
    padding: 16px;
    background: transparent;
    border: 0;
    cursor: zoom-out;

    &[open] {
      display: grid;
      place-items: center;
    }

    &::backdrop {
      background: color-mix(in oklch, var(--black) 85%, transparent);
    }

    & img {
      max-width: 100%;
      max-height: 100%;
      border-radius: 8px;
    }
  }

  /* The chapters before and after, at the foot. */
  .manual__turn {
    display: flex;
    gap: 10px;
    margin-top: 32px;
  }

  .manual__turn-link {
    display: grid;
    flex: 1;
    gap: 2px;
    padding: 10px 14px;
    color: var(--color-ink);
    text-decoration: none;
    border: var(--hairline) solid var(--color-line);
    border-radius: 8px;

    &:hover {
      border-color: var(--color-primary);
    }
  }

  .manual__turn-link--next {
    margin-left: auto;
    text-align: right;
  }

  .manual__turn-label {
    font-size: 12px;
    color: var(--color-ink-muted);
  }
}
