/* The page frame every screen shares: reset, navigation, screen switching, the generation overlay, toast and footer. */
@layer base {
  * {
    box-sizing: border-box;
  }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    /* The sticky navigation would otherwise cover a heading or field scrolled or focused into view (V-6). */
    scroll-padding-block-start: calc(var(--nav-height) + var(--sp-3));
  }

  body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: var(--fs-md);
    line-height: var(--lh-body);
    accent-color: var(--color-primary);
  }

  a {
    color: var(--color-primary);

    &:hover {
      color: var(--color-primary-hover);
    }
  }

  h1,
  h2,
  h3 {
    margin: 0;
    line-height: 1.4;
  }

  .skip-link {
    position: absolute;
    clip-path: inset(50%);
    overflow: hidden;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    white-space: nowrap;

    &:focus-visible {
      position: fixed;
      top: var(--sp-2);
      left: var(--sp-2);
      z-index: 100;
      clip-path: none;
      overflow: visible;
      width: auto;
      height: auto;
      margin: 0;
      padding: var(--sp-2) var(--sp-4);
      border-radius: var(--radius-md);
      background: var(--color-surface);
      color: var(--color-primary-hover);
      font-weight: 700;
      text-decoration: none;
    }
  }

  .global-nav {
    position: sticky;
    top: 0;
    z-index: 80;
    border-block-end: 1px solid var(--color-border);
    background: var(--color-surface);
  }

  .nav-inner {
    box-sizing: content-box;
    display: flex;
    align-items: center;
    gap: var(--sp-6);
    max-width: var(--content-width);
    height: var(--nav-height);
    margin: 0 auto;
    padding: 0 var(--page-gutter);
  }

  .nav-brand {
    color: var(--color-primary-hover);
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;

    &:hover {
      color: var(--color-primary);
    }
  }

  .nav-links {
    display: flex;
    gap: var(--sp-1);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .nav-link {
    display: inline-flex;
    align-items: center;
    min-height: var(--target-min);
    padding: 0 var(--sp-3);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    font-size: var(--fs-sm);
    font-weight: 700;
    text-decoration: none;
    transition:
      background-color 120ms ease-out,
      color 120ms ease-out;

    &:hover {
      background: var(--color-bg);
      color: var(--color-text);
    }

    &[aria-current="page"] {
      background: var(--status-active-bg);
      color: var(--color-primary-hover);
    }

    &[data-section-active="true"]:not([aria-current="page"]) {
      color: var(--color-primary-hover);
      box-shadow: inset 0 -2px 0 var(--color-primary);
    }
  }

  .spa-main {
    min-height: calc(100vh - var(--nav-height));
  }

  .loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--sp-4);
    background: rgb(246 247 245 / 0.88);

    & p {
      color: var(--color-primary-hover);
      font-weight: 700;
    }
  }

  .spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--status-active-bg);
    border-block-start-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }

  @keyframes spin {
    to {
      transform: rotate(360deg);
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .spinner {
      animation: none;
      border-block-start-color: var(--status-active-bg);
    }
  }

  .toast {
    position: fixed;
    inset: auto 0 var(--sp-5) 0;
    z-index: 60;
    width: fit-content;
    max-width: min(calc(100vw - 2 * var(--page-gutter)), 36rem);
    margin: 0 auto;
    padding: var(--sp-3) var(--sp-5);
    border: 0;
    border-radius: var(--radius-md);
    background: var(--color-text);
    color: var(--color-surface);
    font-size: var(--fs-sm);
    font-weight: 700;
    box-shadow: 0 4px 16px rgb(31 42 39 / 0.2);
  }

  .page-footer {
    margin-block-start: var(--sp-6);
    padding: var(--sp-5) var(--page-gutter) var(--sp-6);
    border-block-start: 1px solid var(--color-border);
    color: var(--color-text-muted);
    font-size: var(--fs-sm);
    text-align: center;

    & p {
      max-width: var(--content-width);
      margin: 0 auto;
    }
  }
}

/* Last layer: an element with the hidden attribute stays hidden whatever display a component gives it. */
@layer utilities {
  [hidden] {
    display: none;
  }
}
