/* ==========================================================================
   ricardomoreira.ch — GLOBAL DESIGN SYSTEM — MASTER GRID
   One grid, many compositions.

   The single source of the composition constants of the site: page margins,
   grid columns, gutters, content width, index margin, spacing scale,
   section spacing, typography scale, breakpoints.
   Documentation: shared/design-system/README.md

   Geometry of a page (desktop):

     | margin | index |  1  2  3  4  5  6  7  8  9 10 11 12 | margin |
              ^       ^                                      ^
              |       column 1 (axis of every title)         content edge
              section index (A, B, 01 + planet …) — outside the 12 columns

   Every editorial element spans a whole number of columns; empty columns
   (negative space) are columns too. Any nested grid that spans the full
   content width with var(--mg-template) and var(--mg-gutter) has exactly
   the same tracks as the master grid.

   Breakpoints (CSS media queries cannot read custom properties — keep these
   numbers in sync with the media queries below and in every stylesheet):
     mobile   < 768 px    4 columns
     tablet   768–1023 px 8 columns
     desktop  ≥ 1024 px   12 columns
   ========================================================================== */

:root {
  /* ---- Master grid (mobile first) ---- */
  --mg-columns: 4;
  --mg-gutter: 16px;
  --mg-margin: 40px;          /* outer page margin, both sides */
  --mg-index: 0px;            /* section index margin, left of column 1 (desktop only) */
  --mg-max: 1280px;           /* maximum width of the content columns */
  --mg-template: repeat(var(--mg-columns), minmax(0, 1fr));

  /* ---- Spacing scale: multiples of 8 px (4 px subdivision) ---- */
  --space-0-5: 4px;
  --space-1: 8px;
  --space-1-5: 12px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-5: 40px;
  --space-6: 48px;
  --space-7: 56px;
  --space-8: 64px;
  --space-10: 80px;
  --space-12: 96px;
  --space-16: 128px;
  --space-20: 160px;
  --space-24: 192px;

  /* ---- Section spacing (vertical rhythm of editorial pages) ---- */
  --section-gap: clamp(96px, 16vh, 192px);   /* between two sections (A, B, C …) */
  --block-gap: clamp(56px, 8vh, 96px);        /* between two blocks inside a section */
  --head-gap: var(--space-5);                  /* section head -> section body */

  /* ---- Typography scale (the existing sizes, named) ---- */
  --font-sans: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --type-micro: 10px;
  --type-label: 11px;        /* small uppercase labels, letter-spacing .08em */
  --type-small: 12px;
  --type-caption: 13px;
  --type-body-s: 14px;
  --type-body: 15px;
  --type-lead: 18px;
  --type-sub: 20px;
  --type-statement: clamp(20px, 2vw, 28px);
  --type-h3-l: clamp(22px, 2.5vw, 36px);
  --type-h2: clamp(30px, 3.4vw, 48px);
  --type-display-s: clamp(44px, 6vw, 100px);
  --type-display: clamp(64px, 12.5vw, 200px);
  --measure: 58ch;           /* maximum reading width inside a column */
}

@media (min-width: 768px) {
  :root {
    --mg-columns: 8;
    --mg-gutter: 24px;
    --mg-margin: 56px;
  }
}
@media (min-width: 1024px) {
  :root {
    --mg-columns: 12;
    --mg-gutter: 24px;
    --mg-margin: 64px;
    --mg-index: 112px;
  }
}

/* ---- Primitives ---- */

/* The page frame: margins, index margin, content width. Every editorial page
   uses it (or reproduces exactly this formula). */
.mg-page {
  box-sizing: border-box;
  width: 100%;
  max-width: calc(var(--mg-max) + var(--mg-index) + 2 * var(--mg-margin));
  margin-left: auto;
  margin-right: auto;
  padding-left: calc(var(--mg-margin) + var(--mg-index));
  padding-right: var(--mg-margin);
}

/* A composition on the master grid. */
.mg-grid {
  display: grid;
  grid-template-columns: var(--mg-template);
  column-gap: var(--mg-gutter);
}

/* A nested composition spanning the full width, on the same tracks. */
.mg-sub {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: subgrid;
  column-gap: var(--mg-gutter);
}

/* An element hung in the index margin, left of column 1 (desktop). */
.mg-hang {
  position: absolute;
  left: calc(-1 * var(--mg-index));
}
