/*
 * Tin's one stylesheet: the shell around every page, and the look of rendered Markdown.
 *
 * Plain CSS, served as written: there is no build. Rules (~/.claude/standards/css.md): every
 * value comes from a token below; sizes are rem so they follow the reader's text size; layout
 * uses logical properties; shell parts are BEM blocks. Rendered Markdown carries no classes, so
 * it is styled by element inside .page__body and nowhere else.
 *
 * Contrast ratios are WCAG 2.x, computed 2026-12-01. AA needs 4.5:1 for body text and 3:1 for
 * the edge of a control or a focus ring.
 *
 * Cascade layers put the four parts in a fixed order, so a later part always wins over an
 * earlier one whatever the selectors: tokens, then base, then the shell, then the page.
 */

@layer tokens, base, shell, page;

/* ============================================================================
   Tokens
   ========================================================================= */
@layer tokens {
  :root {
    /* The page follows the visitor's light or dark setting. */
    color-scheme: light dark;

    /* Light. Ratios are on --color-surface / --color-surface-raised. */
    --color-surface: #ffffff; /* Page background. */
    --color-surface-raised: #f8f9fa; /* Code, table headings. */
    --color-text: #212529; /* 15.43:1 / 14.63:1. Body text. */
    --color-text-muted: #5c656d; /* 5.94:1 / 5.63:1. Dates, footer. */
    --color-link: #0b5cad; /* 6.67:1 / 6.33:1. Link text. */
    --color-focus: var(--color-link); /* Focus ring: 6.67:1 on the surface. */
    --color-border: #dee2e6; /* Decorative only: dividers, table lines. */

    /* Spacing: 4px steps. Names are the step number. */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;

    /* Type. System fonts only: nothing to load, nothing to license. */
    --font-family-system:
      system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-family-mono:
      ui-monospace, 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.5rem;
    --font-size-2xl: 2rem;
    --line-height-tight: 1.25;
    --line-height-relaxed: 1.75;
    --font-weight-normal: 400;
    --font-weight-semibold: 600;

    /* Shape and layout. */
    --radius-sm: 0.25rem;
    --border-width: 1px;
    --quote-bar-width: 0.25rem;
    --width-prose: 40rem; /* Long-form reading. */
    --touch-target: 2.75rem; /* 44px: the smallest a control may be (WCAG 2.5.5). */

    /* Focus ring. */
    --focus-ring-width: 2px;
    --focus-ring-offset: 2px;
  }

  @media (prefers-color-scheme: dark) {
    :root {
      --color-surface: #16181b;
      --color-surface-raised: #212529;
      --color-text: #e9ecef; /* 15.00:1 / 13.01:1. */
      --color-text-muted: #adb5bd; /* 8.57:1 / 7.43:1. */
      --color-link: #8ab4f8; /* 8.44:1 / 7.32:1. */
      --color-border: #343a40;
    }
  }
}

/* ============================================================================
   Base
   ========================================================================= */
@layer base {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  body {
    margin: 0;
    background: var(--color-surface);
    color: var(--color-text);
    font-family: var(--font-family-system);
    font-size: var(--font-size-lg);
    line-height: var(--line-height-relaxed);
  }

  a {
    color: var(--color-link);
  }

  a:focus-visible {
    outline: var(--focus-ring-width) solid var(--color-focus);
    outline-offset: var(--focus-ring-offset);
  }
}

/* ============================================================================
   Shell: header, footer
   ========================================================================= */
@layer shell {
  .site-header,
  .site-footer,
  .page {
    max-inline-size: var(--width-prose);
    margin-inline: auto;
    padding-inline: var(--space-4);
  }

  .site-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    column-gap: var(--space-5);
    padding-block: var(--space-3);
    border-block-end: var(--border-width) solid var(--color-border);
  }

  .site-header__name {
    display: inline-flex;
    align-items: center;
    min-block-size: var(--touch-target);
    color: var(--color-text);
    font-weight: var(--font-weight-semibold);
    text-decoration: none;
  }

  .site-nav {
    display: flex;
    column-gap: var(--space-5);
  }

  .site-nav__link {
    display: inline-flex;
    align-items: center;
    min-block-size: var(--touch-target);
    font-size: var(--font-size-base);
  }

  .site-footer {
    display: flex;
    flex-wrap: wrap;
    column-gap: var(--space-5);
    margin-block-start: var(--space-7);
    padding-block: var(--space-3);
    border-block-start: var(--border-width) solid var(--color-border);
    font-size: var(--font-size-sm);
  }

  .site-footer__link {
    display: inline-flex;
    align-items: center;
    min-block-size: var(--touch-target);
    color: var(--color-text-muted);
  }

  /* The source link stays out of sight until a page is drawn; `display` above would show it. */
  .site-footer__link[hidden] {
    display: none;
  }
}

/* ============================================================================
   The page: rendered Markdown
   ========================================================================= */
@layer page {
  .page {
    padding-block-start: var(--space-6);
  }

  .page__meta {
    margin-block: 0 var(--space-5);
    color: var(--color-text-muted);
    font-size: var(--font-size-base);
  }

  .page__body h1,
  .page__body h2,
  .page__body h3 {
    line-height: var(--line-height-tight);
    font-weight: var(--font-weight-semibold);
  }

  .page__body h1 {
    margin-block: 0 var(--space-3);
    font-size: var(--font-size-2xl);
  }

  .page__body h2 {
    margin-block: var(--space-6) var(--space-3);
    font-size: var(--font-size-xl);
  }

  .page__body h3 {
    margin-block: var(--space-5) var(--space-2);
    font-size: var(--font-size-lg);
  }

  .page__body p,
  .page__body ul,
  .page__body ol,
  .page__body blockquote,
  .page__body pre,
  .page__body table {
    margin-block: 0 var(--space-4);
  }

  .page__body ul,
  .page__body ol {
    padding-inline-start: var(--space-5);
  }

  .page__body li + li {
    margin-block-start: var(--space-1);
  }

  .page__body blockquote {
    margin-inline: 0;
    padding-inline-start: var(--space-4);
    border-inline-start: var(--quote-bar-width) solid var(--color-border);
    color: var(--color-text-muted);
  }

  .page__body code {
    padding: var(--space-1);
    border-radius: var(--radius-sm);
    background: var(--color-surface-raised);
    font-family: var(--font-family-mono);
    font-size: var(--font-size-sm);
  }

  .page__body pre {
    padding: var(--space-4);
    border-radius: var(--radius-sm);
    background: var(--color-surface-raised);
    overflow-x: auto;
  }

  .page__body pre code {
    padding: 0;
    background: none;
  }

  /* A wide table scrolls sideways inside the page instead of pushing the page wider. */
  .page__body table {
    display: block;
    max-inline-size: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-base);
    overflow-x: auto;
  }

  .page__body th,
  .page__body td {
    padding: var(--space-2) var(--space-3);
    border-block-end: var(--border-width) solid var(--color-border);
    text-align: start;
    vertical-align: top;
  }

  .page__body th {
    background: var(--color-surface-raised);
    font-weight: var(--font-weight-semibold);
  }

  .page__body img {
    max-inline-size: 100%;
    block-size: auto;
  }

  .page__body hr {
    margin-block: var(--space-6);
    border: 0;
    border-block-start: var(--border-width) solid var(--color-border);
  }
}
