/* Styleguide page only. Not part of site.css. Uses the utilities layer so the layer order stays intact. */
@layer utilities {
  .sg { padding-block: var(--space-8) var(--space-24); }

  .sg-intro {
    display: grid;
    gap: var(--space-4);
    margin-bottom: var(--space-12);

    h1 {
      font-size: var(--step-4);
      font-weight: 800;
      letter-spacing: -0.035em;
    }
    p { max-width: var(--measure); }
  }

  .sg-contents {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-4);
    padding: 0;
    list-style: none;
    font-size: var(--step--1);

    a {
      display: inline-block;
      min-height: 24px;
      line-height: 24px;
    }
  }

  .sg-section {
    display: grid;
    gap: var(--space-4);
    padding-block: var(--space-6) var(--space-12);
    border-top: 1px solid var(--color-rule-strong);
    scroll-margin-top: var(--space-4);

    > h2 {
      font-family: var(--font-mono);
      font-size: var(--step--1);
      font-weight: 500;
      letter-spacing: 0.08em;
      text-transform: uppercase;
    }
  }

  .sg-note {
    max-width: var(--measure);
    font-size: var(--step--1);
    color: var(--color-text-muted);
  }

  .sg code {
    font-family: var(--font-mono);
    font-size: var(--step--2);
    color: var(--color-text-muted);
  }

  .sg-sample {
    min-width: 0;

    /* Samples sit inside the page wrapper already. */
    .wrapper {
      max-width: none;
      padding-inline: 0;
    }
    /* A sample's own fixed spacing, so the page rhythm stays even. */
    .case-header { margin-bottom: 0; }
    .now, .site-footer { padding-bottom: 0; }
  }

  .sg-narrow { max-width: 530px; }

  .sg-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-5);
  }

  .sg-back {
    font-family: var(--font-mono);
    font-size: var(--step--2);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text-muted);

    a {
      display: inline-flex;
      align-items: center;
      gap: var(--space-2);
      text-decoration: none;
    }
  }

  .sg-contents [aria-current="page"] {
    font-weight: 700;
    color: var(--color-accent);
  }

  .sg-panels + .sg-contract { margin-top: var(--space-6); }

  .sg-contract {
    font-size: var(--step--1);

    summary {
      width: fit-content;
      color: var(--color-text-muted);
      cursor: pointer;
    }
    pre {
      margin-top: var(--space-2);
      padding: var(--space-3);
      overflow-x: auto;
      background: var(--color-surface);
      border: 1px solid var(--color-border);
    }
  }

  .sg-swatches {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
    gap: var(--space-4);
    padding: 0;
    list-style: none;

    li { display: grid; gap: var(--space-2); }
  }

  .sg-swatch {
    height: var(--space-16);
    border: 1px solid var(--color-border);
  }

  .sg-list {
    display: grid;
    gap: var(--space-3);
    padding: 0;
    list-style: none;

    li {
      display: grid;
      grid-template-columns: 7rem minmax(0, 1fr);
      align-items: center;
      gap: var(--space-3);
    }
    li:has(.sg-bar, .sg-radius) { grid-template-columns: 7rem auto minmax(0, 1fr); }
  }

  .sg-bar {
    height: var(--space-3);
    background: var(--color-accent);
  }

  .sg-radius {
    width: var(--space-10);
    height: var(--space-10);
    background: var(--color-plate);
    border: 1px solid var(--color-border);
  }

  .sg-icons {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
    gap: var(--space-4);
    padding: 0;
    list-style: none;

    li { display: grid; justify-items: start; gap: var(--space-2); }
    .icon { width: var(--space-6); height: var(--space-6); }
  }

  /* Side-by-side panels: each is its own [data-theme], with its own colour scheme. */
  .sg-panels {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-4);

    @media (min-width: 720px) {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }

  .sg-panel {
    display: grid;
    align-content: start;
    gap: var(--space-4);
    min-width: 0;
    padding: var(--space-4);
    border: 1px solid var(--color-border);
  }

  .sg-panel__label {
    font-family: var(--font-mono);
    font-size: var(--step--2);
    color: var(--color-text-muted);
  }
}
