/* ---------------------------------------------------------------
   jacobsanford.com
   Hand-written CSS on a 12-column grid; no framework.
   --------------------------------------------------------------- */

@font-face {
  font-family: "Schibsted Grotesk";
  src: url("../fonts/schibsted-grotesk-latin-wght-normal.woff2") format("woff2");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

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

:root {
  color-scheme: light dark;

  --paper: #f6f6f3;
  --ink: #111110;
  --muted: #56564f;
  --hair: #d9d9d2;
  --accent: #a3201a;
  --on-accent: #ffffff;

  --sans: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --step--1: 0.875rem;
  --step-0: 1.0625rem;
  --step-1: 1.375rem;
  --step-2: clamp(1.125rem, 0.95rem + 0.6vw, 1.375rem);
  --step-3: clamp(2rem, 1.1rem + 2.6vw, 3.5rem);

  --gutter: 1rem;
  --col-gap: 1.25rem;
  --max: 90rem;
  --measure: 75ch;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f0f0e;
    --ink: #edede8;
    --muted: #a3a39b;
    --hair: #2a2a26;
    --accent: #f0786c;
    --on-accent: #0f0f0e;
  }
}

/* ---- Base ---------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-color: var(--muted) var(--paper);
}

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--step-0);
  line-height: 1.6;
  font-kerning: normal;
  caret-color: var(--accent);
}

::selection {
  background: var(--accent);
  color: var(--on-accent);
}

h1, h2, h3, p, ul, dl, dd, figure {
  margin: 0;
}

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

img {
  display: block;
  max-width: 100%;
  height: auto;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

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

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

main:focus {
  outline: none;
}

.skip-link {
  position: absolute;
  left: var(--gutter);
  top: -100px;
  z-index: 20;
  padding: 0.5rem 0.75rem;
  background: var(--ink);
  color: var(--paper);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  top: 0.75rem;
}

/* ---- Grid ---------------------------------------------------- */

.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--col-gap);
  max-width: var(--max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.grid > * {
  grid-column: 1 / -1;
}

@media (min-width: 48rem) {
  :root {
    --gutter: 2rem;
  }
}

@media (min-width: 64rem) {
  :root {
    --gutter: 3rem;
    --col-gap: 1.5rem;
  }
}

/* ---- Masthead ------------------------------------------------ */

.masthead {
  z-index: 10;
  background: var(--paper);
  border-bottom: 1px solid var(--hair);
}

.masthead .grid {
  align-items: baseline;
  row-gap: 0.25rem;
  padding-block: 1rem;
}

.wordmark {
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
}

.wordmark:hover {
  color: var(--accent);
}

.site-nav {
  position: relative;
}

.site-nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
}

.site-nav a {
  display: inline-block;
  padding: 0.15rem 0 0.15rem 0.9rem;
  color: var(--muted);
  font-size: var(--step--1);
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a[aria-current="true"] {
  color: var(--ink);
}

/* One red square that slides to the section in view. */
.nav-marker {
  position: absolute;
  left: 0;
  top: 0;
  width: 0.5rem;
  height: 0.5rem;
  background: var(--accent);
  opacity: 0;
  pointer-events: none;
}

.nav-marker.is-placed {
  opacity: 1;
}

@media (prefers-reduced-motion: no-preference) {
  .nav-marker.is-placed {
    transition: transform 450ms var(--ease-out), opacity 200ms linear;
  }
}

/* Sticky only where the masthead is a single short row. On narrow or short
   screens the wrapped nav would cover keyboard focus and much of the
   viewport (WCAG 2.4.11, 1.4.10). scroll-padding offsets both anchor jumps
   and focus scrolling. */
@media (min-width: 48rem) and (min-height: 30rem) {
  .masthead {
    position: sticky;
    top: 0;
  }

  html {
    scroll-padding-top: 5rem;
  }
}

@media (min-width: 48rem) {
  .wordmark {
    grid-column: 1 / 4;
  }

  .site-nav {
    grid-column: 4 / -1;
  }
}

/* ---- Intro --------------------------------------------------- */

.intro {
  padding-block: 2.5rem 4rem;
  row-gap: 1.25rem;
  align-items: start;
}

/* A 4:5 photograph. From 48rem it fills the title columns (1 to 3), so its
   edges sit on the same lines as the section rules and titles below. */
.portrait img {
  display: block;
  width: 8rem;
  height: auto;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  background: var(--hair);
}

.lede-display {
  max-width: 22ch;
  font-size: var(--step-3);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.lede-rest {
  max-width: 40ch;
  color: var(--muted);
  font-size: var(--step-2);
  line-height: 1.5;
  text-wrap: pretty;
}

.lede-meta {
  color: var(--muted);
  font-size: var(--step--1);
}

/* Narrow screens: the side block dissolves so the meta line follows the lede
   instead of sitting above the heading. */
.intro-side {
  display: contents;
}

.intro-side > * {
  grid-column: 1 / -1;
}

.portrait { order: 0; }
.lede-display { order: 1; }
.lede-rest { order: 2; }
.lede-meta { order: 3; }
.lede-action { order: 4; }

.lede-action {
  margin-top: 0.75rem;
}

.button {
  display: inline-block;
  padding: 0.75rem 1.15rem;
  background: var(--ink);
  color: var(--paper);
  font-weight: 600;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.button:hover {
  background: var(--accent);
  color: var(--on-accent);
}

@media (prefers-reduced-motion: no-preference) {
  .button {
    transition: background-color 200ms var(--ease-out), color 200ms var(--ease-out);
  }
}

@media (min-width: 48rem) {
  /* The side block spans all four rows. The last row is flexible, so a
     portrait taller than the text takes its extra height there instead of
     opening gaps between the heading, lede and button. */
  .intro {
    padding-block: 4.5rem 5rem;
    grid-template-rows: auto auto auto 1fr;
  }

  .intro > * {
    grid-column: 4 / -1;
  }

  .intro > .intro-side {
    display: block;
    grid-column: 1 / 4;
    grid-row: 1 / span 4;
    align-self: start;
  }

  .portrait img {
    width: 100%;
  }

  .intro-side .lede-meta {
    margin-top: 0.9rem;
  }
}

@media (min-width: 64rem) {
  .intro {
    padding-block: 6rem 6.5rem;
  }

  .intro > * {
    grid-column: 4 / 12;
  }

  .intro > .intro-side {
    grid-column: 1 / 4;
  }
}

/* ---- Sections ------------------------------------------------ */

.section {
  padding-block: 0 4rem;
  row-gap: 1.5rem;
}

@media (min-width: 48rem) {
  .section-title {
    grid-column: 1 / 4;
  }

  .section-body {
    grid-column: 4 / -1;
  }
}

/* The ink rule that opens each section, drawn across the grid as it enters. */
.section::before {
  content: "";
  grid-column: 1 / -1;
  height: 2px;
  background: var(--ink);
  transform-origin: left center;
}

@media (prefers-reduced-motion: no-preference) {
  .js .section::before {
    transform: scaleX(0);
    transition: transform 900ms var(--ease-out);
  }

  .js .section.is-in::before {
    transform: scaleX(1);
  }
}

.section--first {
  padding-top: 3rem;
}

.section-title {
  font-size: var(--step-1);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.section-desc {
  max-width: var(--measure);
  margin-bottom: 1.5rem;
  color: var(--muted);
}

.group + .group,
.prose + .group {
  margin-top: 2.5rem;
}

.group-title {
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--ink);
  color: var(--muted);
  font-size: var(--step--1);
  font-weight: 600;
}

/* Index rows: name, description, aside. */
.index-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.2rem 1.5rem;
  padding-block: 0.9rem;
  border-bottom: 1px solid var(--hair);
}

.index-list li:last-child {
  border-bottom: 0;
}

.index-name {
  color: var(--ink);
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* Linked names keep a graphite underline at rest so they read as links
   beside unlinked names that share the row style. */
a.index-name {
  text-decoration-color: var(--muted);
}

a.index-name:hover,
a.index-name:focus-visible {
  color: var(--accent);
  text-decoration-color: currentColor;
}

.index-desc {
  grid-column: 1 / -1;
  max-width: var(--measure);
  color: var(--muted);
  text-wrap: pretty;
}

.index-aside {
  grid-column: 2;
  grid-row: 1;
  color: var(--muted);
  font-size: var(--step--1);
  font-variant-numeric: tabular-nums;
  line-height: 1.9;
  text-align: right;
}

/* Definition rows: term, description. */
.defs > div {
  display: grid;
  gap: 0.2rem 1.5rem;
  padding-block: 0.9rem;
  border-bottom: 1px solid var(--hair);
}

.defs > div:last-child {
  border-bottom: 0;
}

.defs dt {
  font-weight: 600;
}

.defs dt a {
  color: inherit;
  text-decoration-color: var(--muted);
}

.defs dt a:hover,
.defs dt a:focus-visible {
  color: var(--accent);
  text-decoration-color: currentColor;
}

.defs dd {
  max-width: var(--measure);
  color: var(--muted);
  text-wrap: pretty;
}

/* Disclosure: a row title that opens to a short explanation. Native
   details/summary, so it works without scripting. */
.disclosure summary {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  cursor: pointer;
  list-style: none;
}

.disclosure summary::-webkit-details-marker {
  display: none;
}

.disclosure summary::after {
  flex: none;
  color: var(--muted);
  content: "+";
  content: "+" / "";
}

.disclosure[open] summary::after {
  content: "−";
  content: "−" / "";
}

.disclosure summary:hover,
.disclosure summary:hover::after {
  color: var(--accent);
}

.disclosure-body {
  padding-top: 0.6rem;
}

.disclosure-body > * + * {
  margin-top: 0.75em;
}

@media (prefers-reduced-motion: no-preference) {
  .disclosure summary,
  .disclosure summary::after {
    transition: color 200ms var(--ease-out);
  }
}

.contact dd {
  color: var(--ink);
  overflow-wrap: anywhere;
}

.prose {
  max-width: var(--measure);
}

.prose > * + * {
  margin-top: 1em;
}

.prose p {
  text-wrap: pretty;
}

.more {
  margin-top: 1.25rem;
  font-size: var(--step--1);
}

/* Wide screens: title in columns 1-3, body on columns 4-12, rows on a subgrid
   so every name, term and description lines up with the page grid. */
@media (min-width: 64rem) {
  .section {
    padding-bottom: 5.5rem;
    row-gap: 2rem;
  }

  @supports (grid-template-columns: subgrid) {
    .section-body,
    .section-body > .group,
    .section-body .index-list,
    .section-body .defs,
    .index-list li,
    .defs > div {
      display: grid;
      grid-template-columns: subgrid;
      grid-column: 1 / -1;
      column-gap: var(--col-gap);
    }

    .section-body {
      grid-column: 4 / -1;
      align-content: start;
    }

    .section-body > *,
    .group > * {
      grid-column: 1 / -1;
    }

    .index-name,
    .defs dt {
      grid-column: 1 / 4;
    }

    .index-desc,
    .defs dd {
      grid-column: 4 / 9;
      grid-row: 1;
    }

    .index-aside {
      grid-column: 9 / -1;
      grid-row: 1;
    }

    .section-body > .prose {
      grid-column: 1 / 8;
    }

    .section-body > .group,
    .section-body > .prose + .group {
      margin-top: 0;
    }

    .section-body {
      row-gap: 2.5rem;
    }

    /* A list that is itself the section body keeps its rows tight. */
    .section-body.defs {
      row-gap: 0;
    }
  }
}

/* ---- Articles (case studies, writing) ------------------------ */

.article {
  padding-block: 3rem 5rem;
  row-gap: 2rem;
}

.article-title {
  max-width: 28ch;
  font-size: var(--step-3);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.article-meta {
  margin-top: 0.75rem;
  color: var(--muted);
  font-size: var(--step--1);
}

.article-body h2 {
  margin-top: 2.25em;
  font-size: var(--step-1);
  line-height: 1.3;
}

.article-body h3 {
  margin-top: 1.75em;
  font-size: var(--step-0);
}

@media (min-width: 64rem) {
  .article-head,
  .article-body {
    grid-column: 4 / 11;
  }
}

/* ---- Footer -------------------------------------------------- */

.site-footer {
  border-top: 1px solid var(--hair);
  color: var(--muted);
  font-size: var(--step--1);
}

.site-footer .grid {
  padding-block: 2rem 3rem;
}

@media (min-width: 64rem) {
  .site-footer p {
    grid-column: 4 / -1;
  }
}

/* ---- Forced colours ------------------------------------------ */

/* System colours flatten the marker into the page and the current nav link
   into the others; restore both cues and give the button an edge. */
@media (forced-colors: active) {
  .nav-marker {
    forced-color-adjust: none;
    background: Highlight;
  }

  .site-nav a[aria-current="true"] {
    text-decoration: underline;
  }

  .button {
    border: 1px solid ButtonText;
  }
}
