/* Base stylesheet, organized with cascade layers (weakest first); the
   components layer lives in components.css. Naming: kebab-case BEM
   (block__element--modifier). Components use semantic tokens only. */
@layer reset, tokens, base, layout, components, utilities;

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

  body,
  h1,
  h2,
  p,
  dl,
  dd {
    margin: 0;
  }

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

  input,
  button {
    font: inherit;
  }

  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      transition-duration: 0.01ms !important; /* honor the user's preference over component transitions */
      animation-duration: 0.01ms !important; /* same reason */
    }
  }
}

@layer tokens {
  :root {
    color-scheme: light dark;

    /* Primitives */
    --gray-50: oklch(98.5% 0.002 260deg);
    --gray-200: oklch(90% 0.005 260deg);
    --gray-500: oklch(55% 0.01 260deg);
    --gray-700: oklch(37% 0.012 260deg);
    --gray-900: oklch(21% 0.015 260deg);
    --gray-950: oklch(16% 0.012 260deg);
    --blue-300: oklch(78% 0.1 255deg);
    --blue-600: oklch(50% 0.17 255deg);
    --red-300: oklch(78% 0.11 25deg);
    --red-700: oklch(48% 0.17 25deg);
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --font-size-sm: 0.875rem;
    --font-size-md: 1rem;
    --font-size-xl: clamp(1.5rem, 1.2rem + 1.5vw, 2rem);
    --radius-control: 0.375rem;
    --duration-fast: 120ms;

    /* Semantic tokens: light and dark values */
    --color-text: light-dark(var(--gray-900), var(--gray-50));
    --color-text-muted: light-dark(var(--gray-700), var(--gray-200));
    --color-surface: light-dark(var(--gray-50), var(--gray-950));
    --color-border: light-dark(var(--gray-500), var(--gray-500));
    --color-accent: light-dark(var(--blue-600), var(--blue-300));
    --color-on-accent: light-dark(var(--gray-50), var(--gray-950));
    --color-danger: light-dark(var(--red-700), var(--red-300));
    --color-focus: var(--color-accent);
    --font-body: system-ui, -apple-system, "Segoe UI", roboto, sans-serif;
    --font-mono: ui-monospace, "SF Mono", menlo, consolas, monospace;
    --measure: 42rem;
  }
}

@layer base {
  body {
    min-block-size: 100vh;
    min-block-size: 100dvh;
    font-family: var(--font-body);
    font-size: var(--font-size-md);
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-surface);
  }

  h1 {
    font-size: var(--font-size-xl);
    line-height: 1.2;
    text-wrap: balance;
  }

  a {
    color: var(--color-accent);
    text-underline-offset: 0.15em;
  }

  code {
    font-family: var(--font-mono);
    overflow-wrap: anywhere;
  }

  :focus-visible {
    outline: 3px solid var(--color-focus);
    outline-offset: 2px;
  }
}

@layer layout {
  body {
    display: grid;
    grid-template-rows: auto 1fr auto;
  }

  .site-header,
  .site-main,
  .site-footer {
    inline-size: 100%;
    max-inline-size: calc(var(--measure) + 2 * var(--space-4));
    margin-inline: auto;
    padding-inline: var(--space-4);
  }

  .site-header {
    padding-block: var(--space-4);
    border-block-end: 1px solid var(--color-border);
  }

  .site-main {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding-block: var(--space-8);
  }

  .site-footer {
    padding-block: var(--space-6);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
  }
}

@layer utilities {
  /* Hidden visually but read by screen readers. */
  .visually-hidden {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}
