/* Base styles (feature 009 T023): reset, typography and layout primitives, focus ring,
   reduced motion, utilities. Hand-written; values come from the generated tokens.css
   (`--mb-*`). Logical properties only and no colour literals (enforced by .stylelintrc.json). */
@layer reset, tokens, base, components, utilities;

@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  * {
    margin: 0;
  }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  img,
  svg,
  video {
    display: block;
    max-inline-size: 100%;
  }

  button,
  input,
  select,
  textarea {
    font: inherit;
    color: inherit;
  }

  /* A control never pushes the page wider than the screen (200% text on a small phone: FR-031). */
  input,
  select,
  textarea {
    max-inline-size: 100%;
  }

  button {
    cursor: pointer;
  }

  ul,
  ol {
    padding: 0;
    list-style: none;
  }

  table {
    border-collapse: collapse;
  }

  [hidden] {
    display: none !important;
  }
}

@layer base {
  html {
    background-color: var(--mb-bg);
    color: var(--mb-fg);
    font-family: var(--mb-font);
    font-size: var(--mb-body-size);
    line-height: var(--mb-body-line);
    font-weight: var(--mb-body-weight);
    text-rendering: optimizeLegibility;
  }

  body {
    min-block-size: 100dvh;
    background-color: var(--mb-bg);
    color: var(--mb-fg);
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    font-size: inherit;
    font-weight: inherit;
  }

  a {
    color: var(--mb-main-text);
    text-underline-offset: 0.2em;
  }

  /* Type scale (data-model.md "Type scale"): one class per token. */
  .t-hero {
    font-size: var(--mb-hero-size);
    line-height: var(--mb-hero-line);
    font-weight: var(--mb-hero-weight);
  }

  .t-display {
    font-size: var(--mb-display-size);
    line-height: var(--mb-display-line);
    font-weight: var(--mb-display-weight);
  }

  .t-title {
    font-size: var(--mb-title-size);
    line-height: var(--mb-title-line);
    font-weight: var(--mb-title-weight);
  }

  .t-heading {
    font-size: var(--mb-heading-size);
    line-height: var(--mb-heading-line);
    font-weight: var(--mb-heading-weight);
  }

  .t-body {
    font-size: var(--mb-body-size);
    line-height: var(--mb-body-line);
    font-weight: var(--mb-body-weight);
  }

  .t-body-strong {
    font-size: var(--mb-body-strong-size);
    line-height: var(--mb-body-strong-line);
    font-weight: var(--mb-body-strong-weight);
  }

  .t-small {
    font-size: var(--mb-small-size);
    line-height: var(--mb-small-line);
    font-weight: var(--mb-small-weight);
  }

  .t-caption {
    font-size: var(--mb-caption-size);
    line-height: var(--mb-caption-line);
    font-weight: var(--mb-caption-weight);
  }

  .t-mono {
    font-family: var(--mb-font-mono);
    font-size: var(--mb-mono-size);
    line-height: var(--mb-mono-line);
    font-weight: var(--mb-mono-weight);
  }

  /* Layout primitives. The gutter follows the breakpoint (set in tokens.css). */
  .page {
    inline-size: 100%;
    max-inline-size: var(--mb-content-max);
    margin-inline: auto;
    padding-inline: var(--mb-gutter);
  }

  .page-reading {
    max-inline-size: var(--mb-reading-max);
  }

  .stack > * + * {
    margin-block-start: var(--mb-space-4);
  }

  .cluster {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--mb-space-2);
  }

  /* Icons from the inlined sprite. Directional icons carry data-mirror="true" and flip in RTL. */
  .icon {
    inline-size: var(--mb-icon-md);
    block-size: var(--mb-icon-md);
    flex: none;
    display: inline-block;
    vertical-align: middle;
  }

  .icon-sm {
    inline-size: var(--mb-icon-sm);
    block-size: var(--mb-icon-sm);
  }

  .icon-md {
    inline-size: var(--mb-icon-md);
    block-size: var(--mb-icon-md);
  }

  .icon-lg {
    inline-size: var(--mb-icon-lg);
    block-size: var(--mb-icon-lg);
  }

  .icon[data-mirror="true"]:dir(rtl) {
    transform: scaleX(-1);
  }

  /* Focus ring: 2 px, 2 px offset, visible on keyboard focus only. */
  :focus-visible {
    outline: var(--mb-focus-width) solid var(--mb-focus);
    outline-offset: 2px;
  }

  .skip-link {
    position: absolute;
    inset-block-start: var(--mb-space-2);
    inset-inline-start: var(--mb-space-2);
    z-index: var(--mb-z-toast);
    padding-block: var(--mb-space-2);
    padding-inline: var(--mb-space-4);
    background-color: var(--mb-raised);
    color: var(--mb-fg);
    border: var(--mb-hair) solid var(--mb-stone);
    border-radius: var(--mb-radius-control);
    transform: translateY(-200%);
  }

  .skip-link:focus {
    transform: none;
  }

  /* Reduced motion: every duration becomes 0 and nothing slides (spec, Motion). */
  @media (prefers-reduced-motion: reduce) {
    :root {
      --mb-dur-fast: 0ms;
      --mb-dur-base: 0ms;
    }

    *,
    *::before,
    *::after {
      animation-duration: 0s !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0s !important;
      scroll-behavior: auto !important;
    }
  }
}

@layer components {
  /* Component styles arrive with feature 009 US2 (components.css). */
}

@layer utilities {
  /* Tabular figures for columns of numbers. */
  .tnum {
    font-variant-numeric: tabular-nums;
  }

  /* Emails, phone numbers, IDs, codes and URLs stay left-to-right inside RTL text. */
  .ltr {
    direction: ltr;
    unicode-bidi: isolate;
    /* A long email or reference wraps in a narrow line (200% zoom) instead of running past it. */
    overflow-wrap: anywhere;
  }

  /* The inline icon sprite (static/icons.svg): out of the flow on screen and in print, so it never
     adds a line or a page (a style attribute would be blocked by the CSP). */
  .sprite {
    position: absolute;
    inline-size: 0;
    block-size: 0;
    overflow: hidden;
  }

  /* htmx request indicators: the library's own inline styles are off (CSP), so they live here. */
  .htmx-indicator {
    opacity: 0;
  }

  .htmx-request .htmx-indicator,
  .htmx-request.htmx-indicator {
    opacity: 1;
  }

  .visually-hidden {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }
}
