/*
 * Résumé stylesheet: one file, no build step, no framework.
 * Layer order is cascade order, so print overrides win without specificity fights.
 */
@layer reset, tokens, base, layout, components, print;

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

@layer tokens {
  :root {
    --color-bg: #fff;
    --color-text: #333;
    --color-heading: #000;
    --color-subtitle: #555;
    --color-meta: #666;
    --color-list: #444;
    --color-link: #0066cc;
    --color-focus: #0066cc;

    --font-sans: 'Helvetica Neue', Arial, sans-serif;
    --leading-body: 1.5;
    --leading-list: 1.45;
    --weight-light: 300;
    --weight-semibold: 600;

    /*
     * Fluid steps equal the original phone size up to 390px and the original desktop size
     * from 721px (the old breakpoint), so both baselines hold and nothing jumps in between.
     */
    --text-base: clamp(0.875rem, 0.7272rem + 0.606vw, 1rem);
    --text-title: clamp(1.75rem, 0.8636rem + 3.6363vw, 2.5rem);
    --text-subtitle: clamp(0.875rem, 0.4909rem + 1.5757vw, 1.2rem);
    --text-section: clamp(1.1375rem, 0.709rem + 1.7575vw, 1.5rem);
    --text-job: clamp(0.875rem, 0.609rem + 1.0909vw, 1.1rem);
    --text-contact: clamp(0.8125rem, 0.709rem + 0.4242vw, 0.9rem);

    --space-3xs: 0.3125rem;
    --space-xs: 0.625rem;
    --space-s: 0.9375rem;
    --space-m: 1.25rem;

    --gap-title: var(--space-3xs);
    --gap-masthead: var(--space-xs);
    --gap-page: var(--space-m);
    --gap-heading: var(--space-xs);
    --gap-stack: var(--space-s);
    --gap-job: var(--space-xs);
    --gap-list: var(--space-3xs);
    --gap-contact: 1em;

    --page-block: clamp(0.9375rem, 0.5681rem + 1.5151vw, 1.25rem);
    /* Tablets get wider gutters than the original 20px: 15px at 390px, 40px from 960px. */
    --page-inline: clamp(0.9375rem, 4.3859vw - 0.1316rem, 2.5rem);
    --measure: 50rem;
    --list-indent: clamp(1.3125rem, 0.5rem + 3.3333vw, 2rem);
    --list-item-indent: 0.5em;

    /* Icons step instead of scaling: whole-pixel sizes keep the 24px-grid SVGs crisp. */
    --icon-size: 1.25rem;
    --icon-gap: 0.5rem;

    --target-min: 44px;
    --focus-width: 2px;
    --focus-offset: 2px;
    --underline-offset: 0.15em;
    --duration-fast: 150ms;
  }

  @media (width >= 721px) {
    :root {
      --icon-size: 1.5rem;
      --icon-gap: 0.625rem;
    }
  }

  @media print {
    :root {
      --color-text: #000;
      --color-list: #000;
      /* The old print sheet left contact links blue; on paper they now read like the text. */
      --color-link: var(--color-text);

      --text-print: 9.5pt;
      --text-base: var(--text-print);
      --text-title: calc(var(--text-print) * 1.8);
      --text-subtitle: var(--text-print);
      --text-section: calc(var(--text-print) * 1.2);
      --text-job: calc(var(--text-print) * 0.95);
      --text-contact: calc(var(--text-print) * 0.85);
      --leading-body: 1.3;

      --gap-title: 1px;
      --gap-masthead: 2px;
      --gap-page: 6px;
      --gap-heading: 2px;
      --gap-stack: 5px;
      --gap-job: 2px;
      --gap-list: 1px;

      --page-block: 0;
      --page-inline: 0;
      --list-indent: calc(24px + 2em);
      --list-item-indent: 0.3em;
      --icon-size: 16px;
      --icon-gap: 6px;
    }
  }
}

@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);
    overflow-wrap: break-word;
  }

  h2 {
    color: var(--color-heading);
    font-size: var(--text-section);
  }

  a {
    color: var(--color-link);
    text-underline-offset: var(--underline-offset);

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

  /* Desktop keeps the original line breaks; narrower columns avoid one-word last lines. */
  @media screen and (width < 1024px) {
    p,
    li {
      text-wrap: pretty;
    }
  }
}

@layer layout {
  body {
    display: grid;
    grid-template-columns: minmax(0, var(--measure));
    justify-content: center;
    row-gap: var(--gap-page);
    padding-block: var(--page-block);
    padding-inline: var(--page-inline);
  }

  main {
    display: grid;
    row-gap: var(--gap-page);
  }

  section {
    --section-gap: var(--gap-heading);

    display: grid;
    row-gap: var(--section-gap);

    &:has(> .job) {
      --section-gap: var(--gap-stack);
    }
  }
}

@layer components {
  .masthead {
    display: grid;
    row-gap: var(--gap-masthead);
    text-align: center;

    & hgroup {
      display: grid;
      row-gap: var(--gap-title);
    }

    & h1 {
      color: var(--color-heading);
      font-size: var(--text-title);
      font-weight: var(--weight-light);
    }

    & hgroup p {
      color: var(--color-subtitle);
      font-size: var(--text-subtitle);
    }
  }

  .contact {
    font-size: var(--text-contact);
    font-style: normal;

    & a {
      position: relative;
      display: inline-block;
      text-decoration-color: transparent;

      /* Invisible 44px-tall hit area; it leaves the line box, and so the layout, untouched. */
      &::before {
        content: '';
        position: absolute;
        inset-block: calc((var(--target-min) - 1lh) / -2);
        inset-inline: 0;
      }

      &:focus-visible {
        text-decoration-color: currentColor;
      }

      @media (hover: hover) {
        &:hover {
          text-decoration-color: currentColor;
        }
      }

      @media (prefers-reduced-motion: no-preference) {
        transition: text-decoration-color var(--duration-fast) ease-out;
      }
    }

    /* Phones: separators would dangle at wrapped line ends, so links get their own rows. */
    @media (width < 600px) {
      display: flex;
      flex-direction: column;
      align-items: center;
      /* Keeps link hit areas off the phone number, which iOS may turn into a tel: link. */
      row-gap: calc((var(--target-min) - 1lh) / 2);

      & .links {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        column-gap: var(--gap-contact);
        /* Wrapped link rows sit 44px apart, so their hit areas tile without overlapping. */
        row-gap: calc(var(--target-min) - 1lh);
      }

      & .sep {
        display: none;
      }
    }
  }

  .job {
    display: grid;
    row-gap: var(--gap-job);

    & h3 {
      display: flex;
      align-items: start;
      column-gap: var(--icon-gap);
      font-size: var(--text-job);
      font-weight: var(--weight-semibold);
      text-wrap: balance;
    }

    & .org,
    & .degree,
    & .place,
    & .meta span {
      white-space: nowrap;
    }

    & .meta {
      color: var(--color-meta);
      font-style: italic;
    }

    & ul {
      display: grid;
      row-gap: var(--gap-list);
      padding-inline-start: var(--list-indent);
    }

    & li {
      padding-inline-start: var(--list-item-indent);
      color: var(--color-list);
      line-height: var(--leading-list);
    }
  }

  .company-icon {
    flex: none;
    inline-size: var(--icon-size);
    block-size: var(--icon-size);
    object-fit: contain;
    /* Centres the icon on the first line, so a wrapped title keeps it beside line one. */
    margin-block-start: max(0px, (1lh - var(--icon-size)) / 2);
  }
}

@layer print {
  @media print {
    /* Block flow paginates the same in every engine; grid fragmentation still varies. */
    body,
    main,
    section {
      display: block;
    }

    main,
    main > * + * {
      margin-block-start: var(--gap-page);
    }

    section > * + * {
      margin-block-start: var(--section-gap);
    }

    h2 {
      break-after: avoid;
    }

    .job {
      break-inside: avoid;
    }

    .company-icon {
      filter: grayscale(1);
    }
  }
}

/* Outside the layers: page-margin boxes take no custom properties. */
@page {
  margin: 0.35in 0.45in;
}
