:root {
  /* Paper and ink */
  --bg: #f6efdc;
  --text: #3d4250;
  --strong: #1f2433;
  --meta: #7a7468;
  --link: #2a4fb0;
  --line: #ddd5c4;
  --code-bg: #f2ecdf;
  --code-keyword: #cf222e;
  --code-string: #0a3069;
  --code-title: #8250df;
  --code-number: #0550ae;
  --code-comment: #6e7781;
  /* Faint paper grain, drawn by the browser (no image download) */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  /* Graph paper: faint squares, darker line every 5 squares */
  --grid-rgb: 42 79 176;
  --grid-a: .06;
  --grid-major: rgb(var(--grid-rgb) / var(--grid-a));
  --grid-minor: rgb(var(--grid-rgb) / calc(var(--grid-a) / 2));
  --margin-line: rgb(214 69 69 / .35);
  --cell: 1.4rem;
  --measure: 41rem;
  --hand-font: var(--hand);
  --title-font: var(--hand);
  --heading-font: var(--hand);
  --title-color: var(--strong);
  --heading-color: var(--strong);
  --title-size: 3rem;
  --heading-size: 1.85rem;
  --title-weight: 700;
  --heading-weight: 600;
  --body-size: 1rem;
  --link-style: solid;
  --highlight: rgb(255 212 0 / .45);
  --print-bg: #fffdf7;
  --tape: rgb(224 204 140 / .6);
  --font: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", sans-serif;
  --hand: "Patrick Hand", "Segoe Print", "Bradley Hand", cursive;
  --mono: "Atkinson Hyperlegible Mono", ui-monospace, Menlo, Consolas, monospace;
}

/* Dark mode is a blueprint: deep blue paper, pale grid, white ink. Used when the toggle picks dark */
:root[data-theme="dark"] {
  --highlight: rgb(255 255 255 / .16);
  --print-bg: #e8eef6;
  --tape: rgb(214 228 247 / .45);
  --bg: #0f2c52; --text: #d3e1f2; --strong: #ffffff; --meta: #93aed0; --link: #9ad8ff; --line: #3b6191;
  --code-bg: #0a2242; --code-keyword: #ff7b72; --code-string: #a5d6ff; --code-title: #d2a8ff; --code-number: #79c0ff; --code-comment: #8b949e;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --grid-rgb: 196 220 255; --grid-a: .14;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 112.5%; }
@media (min-width: 640px) { html { font-size: 118%; } }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 3.5rem;
  padding: 1.25rem;
  background:
    var(--grain),
    linear-gradient(var(--grid-major) 1px, transparent 1px) 0 0 / 100% calc(var(--cell) * 5),
    linear-gradient(90deg, var(--grid-major) 1px, transparent 1px) 0 0 / calc(var(--cell) * 5) 100%,
    linear-gradient(var(--grid-minor) 1px, transparent 1px) 0 0 / 100% var(--cell),
    linear-gradient(90deg, var(--grid-minor) 1px, transparent 1px) 0 0 / var(--cell) 100%,
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--body-size);
  line-height: 1.65;
}

a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-style: var(--link-style);
  text-decoration-color: var(--line);
  text-decoration-thickness: .1rem;
  text-underline-offset: .2rem;
}
a:hover { text-decoration-color: var(--meta); text-decoration-thickness: .15rem; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

/* Header and footer */
.site-header, .site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: .5rem 1.5rem;
  font-size: .85rem;
}
.site-name { color: var(--title-color); font-family: var(--hand-font); font-size: 1.5rem; font-weight: 700; line-height: 1; text-decoration: none; }
.site-header { align-items: center; }
.site-header .site-name { margin-right: auto; }
.site-header nav { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem; }
/* Small screens: Dark/Light sits top right next to the name, menu on its own line below */
@media (max-width: 640px) {
  .site-header .theme-toggle { order: 2; }
  .site-header nav { order: 3; flex-basis: 100%; }
}
.site-header nav a { color: var(--text); text-decoration: none; }
.site-header nav a:hover { color: var(--strong); }
/* Current page is circled in pencil */
.site-header nav a[aria-current="page"] { position: relative; color: var(--strong); }
.site-header nav a[aria-current="page"]::after {
  content: "";
  position: absolute;
  inset: -.5rem -.85rem;
  background: var(--link);
  opacity: .6;
  pointer-events: none;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 40' preserveAspectRatio='none'%3E%3Cpath d='M12 30 C 2 22, 10 7, 42 5 S 97 9, 95 21 S 64 37, 40 35 S 5 27, 14 13 S 44 3, 62 6' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E") no-repeat center / 100% 100%;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 40' preserveAspectRatio='none'%3E%3Cpath d='M12 30 C 2 22, 10 7, 42 5 S 97 9, 95 21 S 64 37, 40 35 S 5 27, 14 13 S 44 3, 62 6' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E") no-repeat center / 100% 100%;
}
.theme-toggle {
  font: inherit;
  color: var(--meta);
  background: none;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 .5rem;
  cursor: pointer;
}
.site-footer {
  width: min(var(--measure), 100%);
  margin: auto auto 0;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  color: var(--meta);
}
.site-footer div { display: flex; flex-wrap: wrap; gap: .25rem .9rem; }
.site-footer a { color: var(--meta); }

/* Page content */
.page { width: min(var(--measure), 100%); margin-inline: auto; overflow-wrap: break-word; }
h1, h2, h3, h4 { color: var(--strong); line-height: 1.25; text-wrap: balance; }
/* Handwritten headings; body text stays in the readable font */
h1, h2 { line-height: 1.1; }
h1 { font-family: var(--title-font); color: var(--title-color); font-size: var(--title-size); font-weight: var(--title-weight); margin: 0 0 1.25rem; }
h2 { font-family: var(--heading-font); color: var(--heading-color); font-size: var(--heading-size); font-weight: var(--heading-weight); margin: 2.5rem 0 .75rem; }
h3 { font-size: 1.1rem; font-weight: 600; margin: 2rem 0 .5rem; }
p { margin: 0 0 1.25rem; }
.lead { color: var(--strong); font-size: 1.1rem; font-style: italic; }
/* Tagline sits right under the name */
h1 + .lead { margin-top: -1rem; }
.intro { display: grid; gap: .5rem; }
.intro p { margin: 0; }
.strong { color: var(--strong); }
.meta { color: var(--meta); font-size: .875rem; }
time { margin-left: .35rem; color: var(--meta); font-size: .75rem; font-weight: 300; font-variant-numeric: tabular-nums; white-space: nowrap; }

.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: .75rem; margin: 2.75rem 0 .75rem; }
.section-head h2 { margin: 0; }
.section-head a { font-size: .8rem; }

ul.dated { margin: 0; padding-left: 1.1rem; display: grid; gap: .4rem; }
ul.dated li::marker { color: var(--meta); }
ul.items { list-style: none; margin: 0; padding: 0; display: grid; gap: .9rem; }
ul.items .meta { display: block; }

.entry { padding-bottom: .5rem; border-bottom: 1px solid var(--line); }
.entry:last-of-type { border-bottom: 0; }
.entry h2 { font-size: 1.6rem; margin-top: 2rem; }
.entry ul { padding-left: 1.1rem; margin: 0 0 1.25rem; }
.entry .links { display: flex; flex-wrap: wrap; gap: .25rem 1rem; font-size: .875rem; }


/* Margin notes: on wide screens, dates move into the left margin like notes beside the text */
@media (min-width: 1180px) {
  ul.dated li, ul.items li, .entry { position: relative; }
  .note {
    position: absolute;
    top: 0;
    right: calc(100% + 1.5rem);
    width: 7.5rem;
    margin: 0;
    text-align: right;
    white-space: normal;
    font-family: var(--hand);
    font-size: .95rem;
    font-weight: 400;
    line-height: 1.3;
    color: var(--meta);
    transform: rotate(-2deg);
  }
  ul.dated .note { right: calc(100% + 2.6rem); }
  /* Level with the job title on the Experience page */
  .entry .note { top: .45rem; }
  .note-sep { display: none; }
}

/* Highlighter stroke, used on a few key numbers */
mark {
  color: inherit;
  padding: 0 .25em;
  margin: 0 -.1em;
  border-radius: .3em .7em .4em .6em;
  background: linear-gradient(100deg, transparent .15em, var(--highlight) .35em, var(--highlight) calc(100% - .35em), transparent calc(100% - .15em));
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

/* Blog post */
.back { font-size: .85rem; margin-bottom: 1.5rem; }
/* Cover image looks like a print taped onto the page */
.taped {
  position: relative;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 2.5rem;
  padding: .6rem;
  background: var(--print-bg);
  box-shadow: 0 1px 2px rgb(0 0 0 / .08), 0 8px 18px rgb(0 0 0 / .1);
}
.taped::before, .taped::after {
  content: "";
  position: absolute;
  top: .1rem;
  width: 5rem;
  height: 1.4rem;
  background: var(--tape);
  box-shadow: 0 1px 1px rgb(0 0 0 / .06);
  /* Torn tape ends */
  clip-path: polygon(0 10%, 4% 0, 8% 12%, 12% 2%, 88% 2%, 92% 14%, 96% 0, 100% 10%, 100% 90%, 96% 100%, 92% 88%, 88% 98%, 12% 98%, 8% 86%, 4% 100%, 0 90%);
}
.taped::before { left: -1.4rem; transform: rotate(-35deg); }
.taped::after { right: -1.4rem; transform: rotate(35deg); }
@media (max-width: 640px) {
  .taped::before { left: -.6rem; }
  .taped::after { right: -.6rem; }
}
.post-image { display: block; max-width: 100%; height: auto; }
.taped-small { padding: .4rem; }
.taped-small::before, .taped-small::after { width: 3rem; height: 1rem; top: 0; }
.taped-small::before { left: -.9rem; }
.taped-small::after { right: -.9rem; }

/* Name and tagline, with a small photo taped in beside them */
.hello { display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; margin-bottom: 1.25rem; }
.hello h1 { margin-bottom: 1.25rem; }
.hello .lead { margin-bottom: 0; }
.photo { flex: none; width: 9.5rem; margin: 0; transform: rotate(2.5deg); }
.photo img { display: block; width: 100%; height: auto; }
/* Phones: photo sits above the name instead of beside it */
@media (max-width: 520px) {
  .hello { flex-direction: column-reverse; align-items: flex-start; gap: 1.75rem; margin-top: .75rem; }
  .photo { width: 9rem; align-self: center; transform: rotate(-2deg); }
}
.post img { max-width: 100%; height: auto; }
.post img.center { display: block; width: auto; margin-inline: auto; }
.post img.w-500 { width: min(500px, 100%); }
.post blockquote { margin: 0 0 1.25rem; padding-left: 1rem; border-left: 3px solid var(--line); color: var(--meta); }
.post table { display: block; overflow-x: auto; border-collapse: collapse; margin-bottom: 1.25rem; font-size: .875rem; }
.post th, .post td { border: 1px solid var(--line); padding: .3rem .6rem; }

code { font-family: var(--mono); font-size: .85em; background: var(--code-bg); padding: .1em .3em; border-radius: 4px; }
pre { background: var(--code-bg); padding: 1rem; border-radius: 6px; overflow-x: auto; line-height: 1.5; margin: 0 0 1.25rem; }
pre code { padding: 0; background: none; font-size: .8rem; }

/* highlight.js tokens */
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-meta { color: var(--code-keyword); }
.hljs-string, .hljs-regexp, .hljs-attr { color: var(--code-string); }
.hljs-title, .hljs-section, .hljs-function .hljs-title { color: var(--code-title); }
.hljs-number, .hljs-literal, .hljs-variable, .hljs-attribute { color: var(--code-number); }
.hljs-comment, .hljs-quote { color: var(--code-comment); font-style: italic; }
