/* ============================================================
   A post's contents list, as a sheet along the bottom
   ------------------------------------------------------------
   Deliberately the same shape as the blog page's sidebar sheet
   (assets/css/blog-v2.css) — same handle height, same corner,
   same easing — so the two read as one idea. Phone only; the
   list is left exactly where it was above the breakpoint.
   See assets/js/post-toc.js.
   ============================================================ */

@media (max-width: 1023px) {

  .msk-toc-sheet {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 300;

    background: #0d3b3e;
    border-radius: 22px 22px 0 0;
    box-shadow: 0 -8px 40px rgb(0 0 0 / 35%);

    /* Collapsed, only the handle shows. */
    transform: translateY(calc(100% - 62px));
    transition: transform .4s cubic-bezier(.32, 0, .15, 1);
  }

  .msk-toc-sheet.is-open {
    transform: translateY(0);
    transition-timing-function: cubic-bezier(.22, 1, .36, 1);
  }

  .msk-toc-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;

    width: 100%;
    height: 62px;
    padding: 0 20px;

    border: 0;
    background: transparent;
    color: #fff;
    font: inherit;
    font-size: 16px;
    cursor: pointer;
  }

  /* The chevron turns over when the sheet is up, so the handle says which way
     it will go rather than only what it holds. */
  .msk-toc-handle::after {
    content: "";
    width: 10px;
    height: 10px;
    border-inline-end: 2px solid rgb(255 255 255 / 70%);
    border-block-start: 2px solid rgb(255 255 255 / 70%);
    transform: rotate(-45deg);
    transition: transform .3s ease;
  }

  .msk-toc-sheet.is-open .msk-toc-handle::after {
    transform: rotate(135deg);
  }

  .msk-toc-body {
    max-height: 65vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* A flick that reaches the end of this list stops there rather than
       carrying on into the page behind it. */
    overscroll-behavior: contain;
    padding: 0 20px 20px;
    padding-block-end: max(20px, env(safe-area-inset-bottom, 20px));
  }

  /* The list's own styling assumes a light page; inside the sheet it is on
     dark. */
  .msk-toc-body .simpletoc {
    padding: 0;
    background: transparent;
    /* The list is drawn as a bordered box for the article page, where it has to
       hold itself apart from the prose around it. Inside the sheet the sheet is
       already the box, and a second frame drawn in copper inside a dark panel
       only looks like something has gone wrong. */
    border: 0;
  }

  .msk-toc-body .simpletoc-title {
    display: none;         /* the handle is the title now */
  }

  .msk-toc-body .simpletoc-list {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .msk-toc-body .simpletoc-list li {
    border-block-end: 1px solid rgb(255 255 255 / 8%);
  }

  .msk-toc-body .simpletoc-list li:last-child {
    border-block-end: 0;
  }

  .msk-toc-body .simpletoc-list a {
    display: block;
    padding: 14px 0;
    color: rgb(255 255 255 / 82%);
    font-size: 15px;
    line-height: 1.6;
    text-decoration: none;
  }

  .msk-toc-backdrop {
    position: fixed;
    inset: 0;
    z-index: 290;

    background: rgb(13 59 62 / 55%);
    opacity: 0;
    visibility: hidden;
    transition: opacity .3s ease, visibility .3s ease;
  }

  .msk-toc-backdrop.is-open {
    opacity: 1;
    visibility: visible;
  }

  /* Room at the end of the article so the last of it is not left under the
     handle. */
  .msk-toc-sheet ~ * .wp-block-post-content,
  body:has(.msk-toc-sheet) .site-footer {
    padding-block-end: 62px;
  }

}

@media (prefers-reduced-motion: reduce) {

  .msk-toc-sheet,
  .msk-toc-backdrop,
  .msk-toc-handle::after {
    transition: none;
  }

}
