/* Page frame and breakpoints: phone < 560px, tablet 560–1099px, desktop >= 1100px. */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--c-bg);
  border-bottom: 1px solid var(--c-border);
}

/* Below 560px the header may wrap to two rows; keep it in the flow so it does not eat the screen. */
@media (max-width: 559px) {
  .site-header {
    position: relative;
  }
}

.site-header__inner {
  max-width: var(--maxw-page);
  min-height: var(--header-h);
  margin: 0 auto;
  padding: var(--space-2) var(--gutter);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  min-width: 0;
}
.header-left {
  gap: var(--space-3);
}
.header-right {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2) var(--space-4);
  margin-left: auto;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.2;
  color: var(--c-text);
  text-decoration: none;
  white-space: nowrap;
}

.chapter-menu {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  max-height: calc(100vh - var(--header-h));
  overflow-y: auto;
  background: var(--c-bg);
  border-bottom: 1px solid var(--c-border);
  box-shadow: 0 8px 16px rgb(31 35 40 / 0.08);
}
.chapter-menu[hidden] {
  display: none;
}
.chapter-menu > nav {
  max-width: var(--maxw-page);
  margin: 0 auto;
  padding: var(--space-3) var(--gutter) var(--space-4);
}

.page {
  max-width: var(--maxw-page);
  margin: 0 auto;
  padding: var(--space-4) var(--gutter) var(--space-6);
}

.page--chapter {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-6);
}

.toc {
  display: none;
}

main {
  min-width: 0;
}
main:focus {
  outline: none;
}

.prose {
  max-width: var(--maxw-text);
}

@media (min-width: 1100px) {
  /* Chapter pages use the whole viewport: sidebar at the left edge, text column fills the rest.
     The header follows the same edges so the site name lines up with the sidebar. */
  .page--chapter {
    max-width: none;
    margin: 0;
    padding-left: var(--page-pad-wide);
    padding-right: var(--page-pad-wide);
    grid-template-columns: 220px minmax(0, 1fr);
    column-gap: var(--space-7);
  }
  body:has(> .page--chapter) .site-header__inner {
    max-width: none;
    padding-left: var(--page-pad-wide);
    padding-right: var(--page-pad-wide);
  }
  .toc {
    display: block;
    position: sticky;
    top: calc(var(--header-h) + var(--space-4));
    align-self: start;
    max-height: calc(100vh - var(--header-h) - var(--space-6));
    overflow-y: auto;
  }
}
