/*
 * "Book" layout: no side columns.
 * The content sits in the middle at a comfortable reading width.
 * The chapter list (with the current chapter's sections nested under it)
 * is a drawer that opens from the ☰ button or the floating button.
 * On small screens Material already works this way; these rules give
 * desktop the same behavior.
 */

/* ---------- Reading width ---------- */

.md-main__inner > .md-content {
  max-width: 48rem;
  margin-inline: auto;
}

/* The home page keeps the full width for its cards */
.md-main__inner > .md-content:has(.grid.cards.books) {
  max-width: none;
}

/* ---------- Desktop: sidebar becomes a drawer ---------- */

@media screen and (min-width: 76.25em) {

  /* Show the ☰ button in the header */
  .md-header__button[for="__drawer"] {
    display: inline-block;
  }

  /* The secondary column (page TOC) is integrated into the drawer */
  .md-sidebar--secondary {
    display: none;
  }

  /* Off-canvas drawer, sliding in from the right (RTL start side) */
  .md-sidebar--primary {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 5;
    width: 18rem;
    height: 100% !important;
    padding: 0;
    background: var(--md-default-bg-color);
    transform: translateX(100%);
    transition: transform .25s cubic-bezier(.4, 0, .2, 1), box-shadow .25s;
    box-shadow: none;
  }

  [data-md-toggle="drawer"]:checked ~ .md-container .md-sidebar--primary {
    transform: translateX(0);
    box-shadow: 0 0 1.5rem rgba(0, 0, 0, .25);
  }

  .md-sidebar--primary .md-sidebar__scrollwrap {
    position: absolute;
    inset: 0;
    margin: 0;
    max-height: none !important;
    padding: 1rem .6rem 2rem;
  }

  /* Drawer title: the book name */
  .md-sidebar--primary .md-nav--primary > .md-nav__title {
    display: none;
  }

  /* Dim the page while the drawer is open; clicking it closes the drawer */
  [data-md-toggle="drawer"]:checked ~ .md-overlay {
    width: 100%;
    height: 100%;
    opacity: 1;
    transition: width 0ms, height 0ms, opacity .25s;
  }

  .md-overlay {
    position: fixed;
    top: 0;
    z-index: 5;
    width: 0;
    height: 0;
    background-color: rgba(0, 0, 0, .54);
    opacity: 0;
    transition: width 0ms .25s, height 0ms .25s, opacity .25s;
  }

  .md-sidebar--primary { z-index: 6; }
}

/* ---------- Drawer contents ---------- */

/* Sections of the current chapter: a subtle guide line */
.md-nav--integrated > .md-nav__list > .md-nav__item--active > .md-nav--secondary {
  border-inline-start: 2px solid var(--md-primary-fg-color--light);
  margin-inline-start: .4rem;
}

.md-nav__link--active {
  font-weight: 700;
}

/* ---------- Floating "contents" button ---------- */

.toc-fab {
  position: fixed;
  bottom: 1.2rem;
  left: 1.2rem;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem .9rem;
  border-radius: 2rem;
  background: var(--md-primary-fg-color);
  color: var(--md-primary-bg-color);
  font-size: .7rem;
  font-weight: 500;
  box-shadow: 0 .2rem .6rem rgba(0, 0, 0, .3);
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
}

.toc-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 .4rem 1rem rgba(0, 0, 0, .3);
}

.toc-fab svg {
  width: 1.1rem;
  height: 1.1rem;
  fill: currentColor;
}

/* Phones: icon only */
@media screen and (max-width: 44.9375em) {
  .toc-fab { padding: .7rem; }
  .toc-fab span { display: none; }
}

/* ---------- Previous / next chapter ---------- */

.md-footer__inner {
  max-width: 48rem;
  margin-inline: auto;
}

.md-footer__link {
  border-radius: .5rem;
}
