/* Frame, column grid and bleed rule (D-18, D-19)

   .frame-grid tracks, outside in:
     [full-start] 1fr [bleed-start] ≤120px [frame-start] frame [frame-end] ≤120px [bleed-end] 1fr [full-end]

   The frame is min(--frame-max, 100% − 2 × --margin). The leftover width goes
   first to the two bleed tracks (capped at --bleed-max, 120px) and only then
   to the 1fr outer tracks. So:
     ≤ 1600px  outer margin ≤ 120px → the 1fr tracks are 0 and bleed-start/end
               sit on the viewport edges (bleeds reach the edge);
     > 1600px  outer margin > 120px → bleed tracks stop at 120px and the
               1fr tracks absorb the rest (bleeds end 120px outside the frame).
   No 100vw anywhere, so the scrollbar never causes horizontal overflow. */

.frame-grid {
  container-type: inline-size;
  display: grid;
  grid-template-columns:
    [full-start] minmax(0, 1fr)
    [bleed-start] minmax(0, var(--bleed-max))
    [frame-start] min(var(--frame-max), 100% - 2 * var(--margin))
    [frame-end] minmax(0, var(--bleed-max))
    [bleed-end] minmax(0, 1fr)
    [full-end];
}

.frame-grid > * {
  grid-column: frame-start / frame-end;
}

/* Background surfaces that run edge to edge, e.g. --niebla sections.
   Nest a .frame-grid inside (or make the element one) to keep content framed. */
.frame-grid > .full {
  grid-column: full-start / full-end;
}

/* Bleed utilities. Below 720px every bleed goes full-bleed on both sides
   (D-19 mobile fallback); text inside returns to the margin via .bleed-inner. */
.frame-grid > .bleed-left,
.frame-grid > .bleed-right,
.frame-grid > .bleed-both {
  grid-column: bleed-start / bleed-end;
}

@media (min-width: 720px) {
  .frame-grid > .bleed-left {
    grid-column: bleed-start / frame-end;
  }

  .frame-grid > .bleed-right {
    grid-column: frame-start / bleed-end;
  }
}

/* Padding that puts text inside a bleed back on the frame edge.
   --bleed-w is the real width of one bleed track, resolved against the
   nearest .frame-grid (a size container), so it is right at every width,
   including 1488–1600px where the margin exceeds --margin. */
.frame-grid > * {
  --bleed-w: min(
    (100cqw - min(var(--frame-max), 100cqw - 2 * var(--margin))) / 2,
    var(--bleed-max)
  );
}

.bleed-inner {
  padding-inline: var(--bleed-w);
}

@media (min-width: 720px) {
  .bleed-left > .bleed-inner,
  .bleed-left.bleed-inner {
    padding-inline: var(--bleed-w) 0;
  }

  .bleed-right > .bleed-inner,
  .bleed-right.bleed-inner {
    padding-inline: 0 var(--bleed-w);
  }
}

/* Column grid inside the frame: 4 / 8 / 12 columns (tokens.css) */
.cols {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  column-gap: var(--gap);
}

.cols > * {
  grid-column: 1 / -1;
}

/* Page skeleton: footer sits at the bottom on short pages */
.page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.page > main {
  flex: 1 0 auto;
}
