/* Book collection chrome. Tokens come from main.css.
   Linked as /assets/css/book.css on layout: book only — do not inline. */

html.layout-book {
  /* Sticky .book-toolbar sits at top: 0. Keep hash targets (H2/H3) below it (#275).
     Fallback covers the 44px toggle, toolbar padding, border, and one wrapped
     crumb line. book-nav.js overwrites --book-sticky-offset from measured height. */
  --book-sticky-offset: calc(44px + (var(--space-2) * 2) + 1px + var(--space-4));
  scroll-padding-top: var(--book-sticky-offset);
}

html.layout-book body {
  scroll-padding-top: var(--book-sticky-offset);
}

.book-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.book-toolbar {
  position: sticky;
  top: 0;
  z-index: 21;
  background: var(--color-header-bg);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-2) var(--space-4);
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-ui);
  font-size: var(--type-sm);
}

.book-toc-panel {
  position: relative;
  flex: 0 0 auto;
}

.book-toc-toggle {
  list-style: none;
  cursor: pointer;
  color: var(--color-fg);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0;
  width: 44px;
  height: 44px;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.book-toc-toggle::-webkit-details-marker,
.book-toc-toggle::marker {
  display: none;
  content: "";
}

.book-toc-toggle__icon {
  width: 1.25rem;
  height: 1.25rem;
  display: block;
}

.book-toc-toggle__icon--close {
  display: none;
}

.book-toc-panel[open] .book-toc-toggle {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.book-toc-panel[open] .book-toc-toggle__icon--menu {
  display: none;
}

.book-toc-panel[open] .book-toc-toggle__icon--close {
  display: block;
}

.book-toc-backdrop {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  top: var(--book-overlay-top, 0px);
  z-index: 19;
  background: color-mix(in srgb, var(--brand-ink) 35%, transparent);
}

html.book-nav-open .book-toc-backdrop {
  display: block;
}

html.book-nav-open {
  overflow: hidden;
}

.book-toc--panel {
  position: fixed;
  z-index: 20;
  left: 0;
  right: auto;
  width: min(32em, 100%);
  top: var(--book-overlay-top, 0px);
  bottom: 0;
  overflow: auto;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: var(--space-4);
  box-shadow: 0.5em 0 1.5em color-mix(in srgb, var(--brand-ink) 12%, transparent);
}

.book-crumb {
  margin: 0;
  min-width: 0;
  flex: 1 1 0;
  color: var(--color-muted);
  overflow: visible;
  white-space: normal;
}

.book-crumb__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: block;
}

.book-crumb__item {
  display: inline;
}

.book-crumb a,
.book-crumb [aria-current="page"] {
  color: var(--color-muted);
  text-decoration: none;
}

.book-crumb a:hover,
.book-crumb a:focus-visible {
  color: var(--color-accent);
  text-decoration: underline;
}

.book-crumb [aria-current="page"] {
  color: var(--color-fg);
}

.book-crumb__sep {
  margin-inline: -0.35em;
}

.book-main {
  flex: 1;
  padding-block: var(--space-8);
}

.book-article {
  width: 100%;
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

.book-article .post-header {
  margin-bottom: var(--space-6);
}

.book-meta {
  margin-top: var(--space-6);
  margin-bottom: 0;
}

.book-toc__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.book-toc__list ol {
  list-style: none;
  margin: 0.35em 0 0;
  padding-left: var(--space-3);
}

.book-toc__list a,
.book-toc__chapter summary {
  color: var(--color-fg);
  text-decoration: none;
  display: block;
  padding: 0.35em 0;
  line-height: var(--leading-tight);
}

.book-toc__list a:hover,
.book-toc__list a:focus-visible {
  color: var(--color-accent);
  text-decoration: underline;
}

.book-toc__list a[aria-current="page"] {
  color: var(--color-accent);
  font-weight: 600;
}

.book-toc__num {
  font-variant-numeric: tabular-nums;
  color: var(--color-muted);
  margin-right: 0.35em;
}

.book-toc__chapter summary {
  cursor: pointer;
  font-weight: 600;
}

.book-toc__status {
  margin: 0;
  color: var(--color-muted);
}

.book-toc--article {
  margin-top: var(--space-8);
  padding-top: var(--space-6);
  border-top: 1px solid var(--color-border);
}

.book-toc--article .book-toc__list {
  font-family: var(--font-ui);
  font-size: var(--type-sm);
}

.book-pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  align-items: start;
  margin-top: var(--space-8);
  padding-top: var(--space-6);
  border-top: 1px solid var(--color-border);
  font-family: var(--font-ui);
  font-size: var(--type-sm);
}

.book-pager__link {
  display: flex;
  flex-direction: column;
  gap: 0.2em;
  text-decoration: none;
  color: var(--color-fg);
  min-height: 44px;
}

.book-pager__link--next {
  text-align: right;
}

.book-pager__dir {
  color: var(--color-muted);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-size: 0.8em;
}

.book-pager__link:hover,
.book-pager__link:focus-visible {
  color: var(--color-accent);
}

.book-pager__link--empty {
  pointer-events: none;
}

@media (max-width: 40em) {
  .book-toc--panel {
    width: 100%;
    left: 0;
    right: 0;
    border-right: 0;
    box-shadow: none;
  }

  .book-pager {
    grid-template-columns: 1fr;
  }

  .book-pager__link--next {
    text-align: left;
  }
}
