/*
 * eligrubbs.com stylesheet
 *
 * Cascade layers make the order explicit, so later layers win without
 * specificity fights.
 *
 *   tokens      design decisions as custom properties (color, type, space)
 *   reset       a minimal, modern normalization
 *   base        bare HTML elements, styled only with tokens
 *   components  reusable pieces (link list, tag, section, project)
 *   layout      the page frame
 *
 * Components use only tokens, never raw values, so changing the design
 * means editing the tokens layer.
 */

@layer tokens, reset, base, components, layout;

/* ------------------------------------------------------------------ */
/* Tokens                                                              */
/* ------------------------------------------------------------------ */

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

    /* Color: a neutral ramp and one accent. light-dark() switches values
       with the user's OS theme. */
    --color-bg:     light-dark(#fdfdfc, #141414);
    --color-text:   light-dark(#1b1b1b, #e6e6e3);
    --color-muted:  light-dark(#5f5f5b, #a1a19c);
    --color-rule:   light-dark(#e3e3df, #2c2c2a);
    --color-accent: light-dark(#1f4fbf, #8fb0ff);

    /* Typography */
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
      Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono",
      monospace;

    /* Fluid type scale (about 1.2 ratio), clamped between mobile and desktop */
    --text-sm:   clamp(0.875rem, 0.85rem + 0.1vw, 0.9375rem);
    --text-base: clamp(1rem, 0.96rem + 0.2vw, 1.125rem);
    --text-lg:   clamp(1.125rem, 1.05rem + 0.35vw, 1.3125rem);
    --text-xl:   clamp(1.75rem, 1.5rem + 1.2vw, 2.5rem);

    --leading-tight: 1.2;
    --leading-body:  1.65;

    --weight-medium: 500;
    --weight-bold:   650;

    /* Spacing: a 4px-based scale */
    --space-1:  0.25rem;
    --space-2:  0.5rem;
    --space-4:  1rem;
    --space-6:  1.5rem;
    --space-8:  2rem;
    --space-12: 3rem;
    --space-16: 4rem;

    /* Layout */
    --measure: 40rem;              /* comfortable line length for reading */
    --gutter: var(--space-6);
    --region-gap: var(--space-12); /* between header, sections and footer */

    /* Borders, focus and motion */
    --rule: 1px solid var(--color-rule);
    --radius-sm: 0.25rem;
    --focus-ring: 2px solid var(--color-accent);
    --duration-fast: 120ms;
  }

  @media (min-width: 48rem) {
    :root {
      --region-gap: var(--space-16);
    }
  }
}

/* ------------------------------------------------------------------ */
/* Reset                                                               */
/* ------------------------------------------------------------------ */

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

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

  @media (prefers-reduced-motion: no-preference) {
    html {
      scroll-behavior: smooth;
    }
  }

  img,
  svg {
    display: block;
    max-width: 100%;
  }

  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }
}

/* ------------------------------------------------------------------ */
/* Base: bare elements                                                 */
/* ------------------------------------------------------------------ */

@layer base {
  body {
    background-color: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading-body);
    -webkit-font-smoothing: antialiased;
  }

  h1,
  h2,
  h3 {
    line-height: var(--leading-tight);
    text-wrap: balance;
  }

  h1 {
    font-size: var(--text-xl);
    font-weight: var(--weight-bold);
    letter-spacing: -0.02em;
  }

  /* Section headings are small caps labels, not big type */
  h2 {
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
  }

  h3 {
    font-size: var(--text-base);
    font-weight: var(--weight-medium);
  }

  /* Sections inside <main> get the same spacing as the page's regions,
     so adding a section needs no new CSS. */
  main {
    display: grid;
    gap: var(--region-gap);
  }

  p {
    text-wrap: pretty;
  }

  address {
    font-style: normal;
  }

  ul[role="list"] {
    list-style: none;
    padding: 0;
  }

  /* Links are underlined so they don't depend on color alone */
  a {
    color: var(--color-accent);
    text-decoration-thickness: 1px;
    text-underline-offset: 0.2em;
    transition: text-decoration-thickness var(--duration-fast) ease;
  }

  a:hover {
    text-decoration-thickness: 2px;
  }

  :focus-visible {
    outline: var(--focus-ring);
    outline-offset: 3px;
    border-radius: var(--radius-sm);
  }
}

/* ------------------------------------------------------------------ */
/* Components                                                          */
/* ------------------------------------------------------------------ */

@layer components {
  .skip-link {
    position: absolute;
    top: var(--space-2);
    left: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: var(--color-bg);
    border: var(--rule);
    border-radius: var(--radius-sm);
    transform: translateY(-200%);
  }

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

  /* Small monospace label, e.g. a project's language */
  .tag {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    color: var(--color-muted);
    white-space: nowrap;
  }

  /* Horizontal list of links, wraps on small screens */
  .link-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-6);
  }

  .site-header {
    display: grid;
    gap: var(--space-2);
  }

  .site-header__intro {
    font-size: var(--text-lg);
  }

  /* A titled region of the page, separated from the one above by a rule.
     Every section looks the same: rule, h2 label, then content. */
  .section {
    display: grid;
    gap: var(--space-6);
    padding-block-start: var(--space-8);
    border-block-start: var(--rule);
  }

  .project-list {
    display: grid;
    gap: var(--space-8);
  }

  /* One project: name and language on one line, description below */
  .project {
    display: grid;
    gap: var(--space-1);
  }

  .project__header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-1) var(--space-4);
  }

  .project__description {
    color: var(--color-muted);
  }

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

/* ------------------------------------------------------------------ */
/* Layout                                                              */
/* ------------------------------------------------------------------ */

@layer layout {
  /* Single centered reading column. Its regions are spaced evenly. */
  .page {
    display: grid;
    gap: var(--region-gap);
    max-width: var(--measure);
    margin-inline: auto;
    padding: var(--space-16) var(--gutter) var(--space-8);
  }

  @media (min-width: 48rem) {
    .page {
      padding-block-start: calc(var(--space-16) * 1.5);
    }
  }
}
