/* =========================================================================
   Layout primitives (after Every Layout). Each one does one job and handles
   its own responsiveness, so pages are built by combining them instead of
   tuning numbers per window size.

   .center    page frame: fluid side margins, content stops growing at --page-max
   .sidebar   a fixed-width side column + content; wraps to stacked by itself
              when the content would get narrower than 55% of the page
   .stack     vertical rhythm: even space between children (--stack-space)
   .cover     .cover__bottom sits at the bottom; one window tall when also .pinned
   .columns   equal columns that drop to one when each would be under --column-min
   ========================================================================= */

/* ---- Center ---- */
.center {
  box-sizing: content-box;
  max-inline-size: var(--page-max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* ---- Sidebar ---- */
.sidebar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-64);
}
.sidebar > :first-child {
  flex-basis: var(--rail-width);
  flex-grow: 1;
}
.sidebar > :last-child {
  flex-basis: 0;
  flex-grow: 999;
  min-inline-size: 55%;
}

/* ---- Stack ---- */
.stack {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}
.stack > * { margin-block: 0; }
.stack > * + * { margin-block-start: var(--stack-space, var(--space-16)); }

/* ---- Cover ---- */
.cover { display: flex; flex-direction: column; }
.cover > .cover__bottom { margin-block-start: auto; }

/* ---- Columns ---- */
.columns {
  display: flex;
  flex-wrap: wrap;
  gap: var(--columns-gap, var(--space-24));
}
.columns > * {
  flex: 1 1 var(--column-min, 18rem);
  min-inline-size: 0;
}

/* ---- Pinning: a column that stays in view while the page scrolls ----
   Only when it sits beside the content (wide enough) and the window is tall
   enough to show it whole; otherwise it simply scrolls with the page.
   .pinned.cover also makes it exactly one window tall (menu at the bottom). */
@media (min-width: 64rem) and (min-height: 32rem) {
  .pinned { position: sticky; top: 0; align-self: flex-start; }
  .pinned.cover { min-block-size: 100vh; min-block-size: 100dvh; }
}
