/* Page chrome shared by every page: header, footer and the page container.
   Loaded by the "head" include. Colours, type and spacing come from Designsystemet tokens only. */
@layer pp.layout {
  /* One frame for every page. Its left edge, the end of the body and the right rail are in the same place on
     every page; only what is inside the body differs.
     - body: the main content. On a playground from 80rem it holds two tracks, the contents (rail) and the
       article (main); on the other pages the body is the main column.
     - aside: the right rail, from 62rem (the landing page's side card, a playground's margin notes).
     The header spans the body: the brand at its start, the navigation and the colour-scheme toggle at its end.
     At full width: rail + gap + main = body, and body + gap + aside = the page width inside the gutters. */
  :root {
    --pp-page-width: 76rem;
    --pp-gutter: var(--ds-size-4);
    --pp-rail: 12rem;
    --pp-main: 42rem;
    --pp-aside: 15rem;
    --pp-column-gap: var(--ds-size-10);
    scrollbar-gutter: stable;
  }

  body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }

  body > main {
    flex: 1 0 auto;
  }

  .pp-bar {
    box-sizing: border-box;
    width: 100%;
    max-width: var(--pp-page-width);
    margin-inline: auto;
    padding-inline: var(--pp-gutter);
  }

  /* <main class="pp-bar pp-grid">, or "pp-bar pp-grid pp-grid-rail" on a playground. Children go in `main`;
     place one in `aside` or `rail` inside a media query from the width where that track exists. */
  .pp-grid {
    display: grid;
    grid-template-columns: [body-start main-start] minmax(0, 1fr) [main-end body-end];
  }

  .pp-grid > * {
    grid-column: main;
  }

  @media (min-width: 62rem) {
    .pp-grid {
      grid-template-columns: [body-start main-start] minmax(0, 1fr) [main-end body-end aside-start] var(--pp-aside) [aside-end];
      column-gap: var(--pp-column-gap);
    }
  }

  @media (min-width: 80rem) {
    .pp-grid-rail {
      grid-template-columns:
        [body-start rail-start] var(--pp-rail) [rail-end main-start] minmax(0, 1fr)
        [main-end body-end aside-start] var(--pp-aside) [aside-end];
    }
  }

  /* ---- header ----
     <div class="pp-header-body"> brand <div class="pp-header-end"> nav, toggle </div></div>, across the body.
     On phones the navigation and the toggle take a second row, still at the body's two edges. */
  .pp-header {
    border-block-end: var(--ds-border-width-default) solid var(--ds-color-neutral-border-subtle);
  }

  .pp-header .pp-bar {
    padding-block: var(--ds-size-3);
  }

  .pp-header .pp-header-body {
    grid-column: body;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--ds-size-2) var(--ds-size-6);
  }

  /* The navigation and the toggle are one group at the body's end, at every width; where it does not fit
     beside the brand it wraps to its own row, still at the end. The toggle is an icon button: its negative
     margin puts the icon on the body's edge, and the group's gap leaves the same space between the last
     link and the icon as between two links (--pp-nav-gap). */
  .pp-header {
    --pp-nav-gap: var(--ds-size-5);
    --pp-icon-inset: var(--ds-size-3); /* the icon button's padding */
  }

  .pp-header-end {
    display: flex;
    align-items: center;
    gap: calc(var(--pp-nav-gap) - var(--pp-icon-inset));
    margin-inline-start: auto;
  }

  .pp-header-end pp-color-scheme-toggle {
    margin-inline-end: calc(-1 * var(--pp-icon-inset));
  }

  /* "Paper Playground" over "by SweatStack": the endorsement is part of the name, one step quieter. */
  .pp-brand {
    display: inline-flex;
    align-items: center;
    gap: var(--ds-size-2);
    color: var(--ds-color-neutral-text-default);
    font-weight: var(--ds-font-weight-semibold);
    line-height: var(--ds-line-height-sm);
    text-decoration: none;
  }

  .pp-brand img {
    border-radius: var(--ds-border-radius-md);
  }

  .pp-brand > span {
    display: flex;
    flex-direction: column;
  }

  .pp-brand-by {
    color: var(--ds-color-neutral-text-subtle);
    font-size: var(--ds-font-size-1);
    font-weight: var(--ds-font-weight-regular);
  }

  .pp-nav ul {
    display: flex;
    flex-wrap: wrap;
    gap: var(--ds-size-1) var(--pp-nav-gap);
    list-style: none;
    margin: 0;
    padding: 0;
  }

  .pp-nav a {
    display: inline-block;
    padding-block: var(--ds-size-1);
    color: var(--ds-color-neutral-text-subtle);
    font-size: var(--ds-font-size-3);
    text-decoration: none;
    border-block-end: var(--ds-border-width-focus) solid transparent;
  }

  .pp-nav a:hover {
    color: var(--ds-color-neutral-text-default);
  }

  .pp-nav a[aria-current='page'] {
    color: var(--ds-color-neutral-text-default);
    border-block-end-color: var(--ds-color-brand-base-default);
  }

  .pp-nav a:focus-visible {
    outline: var(--dsc-focus-outline);
    box-shadow: var(--dsc-focus-boxShadow);
  }


  /* Phones: short labels ("Researchers"), so the links and the toggle share one row. */
  .pp-nav-short {
    display: none;
  }

  @media (max-width: 30rem) {
    .pp-header {
      --pp-nav-gap: var(--ds-size-4);
    }

    .pp-nav a {
      font-size: var(--ds-font-size-2);
    }

    .pp-nav-full {
      display: none;
    }

    .pp-nav-short {
      display: inline;
    }
  }

  /* ---- footer ---- */
  .pp-footer {
    margin-block-start: var(--ds-size-12);
    border-block-start: var(--ds-border-width-default) solid var(--ds-color-neutral-border-subtle);
    color: var(--ds-color-neutral-text-subtle);
  }

  .pp-footer .pp-bar {
    padding-block: var(--ds-size-6);
  }

  .pp-footer .pp-bar > * {
    grid-column: body;
  }

  .pp-count {
    color: var(--ds-color-neutral-text-subtle);
    font-weight: var(--ds-font-weight-regular);
  }

  /* Colour rule "brand marks selection" (CLAUDE.md): in a brand toggle group only the selected item takes
     the brand colour; the group itself stays neutral. */
  .ds-toggle-group[data-color='brand'] {
    --dsc-togglegroup-color: var(--ds-color-neutral-text-default);
    --dsc-togglegroup-border-color: var(--ds-color-neutral-border-default);
  }

  /* Unselected items hover and press in neutral, like any other neutral control. */
  .ds-toggle-group[data-color='brand'] > label:not(:has(input:checked)) {
    --dsc-button-background--hover: var(--ds-color-neutral-surface-hover);
    --dsc-button-background--active: var(--ds-color-neutral-surface-active);
    --dsc-button-color--hover: var(--ds-color-neutral-text-default);
    --dsc-button-color--active: var(--ds-color-neutral-text-default);
  }

  .ds-toggle-group .pp-count {
    color: inherit;
    opacity: 0.75;
  }
}
