/* ==========================================================================
   Alberto Sormani, portfolio
   One painted line carries the page: it underlines the name, turns down and
   becomes the timeline. Typeset text states facts; handwriting adds asides.
   ========================================================================== */

/* ---------- Fonts (self-hosted, SIL Open Font License) ---------- */

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

@font-face {
  font-family: "Besley";
  src: url("../fonts/besley-latin-wght-italic.woff2") format("woff2");
  font-weight: 400 900;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "Kalam";
  src: url("../fonts/kalam-latin-300-normal.woff2") format("woff2");
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Kalam";
  src: url("../fonts/kalam-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

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

:root {
  color-scheme: light;

  /* The palette. These values are only a fallback: every page sets the seven colours again
     from the palette named in content/site.json (see content/palettes.json).
     paper: the page; ink: the text; pencil: captions and small print; band: the painted line
     and everything painted with it; note: the handwriting; mist: pale fills and hairlines;
     accent: the mark for "today" on the timeline. */
  --paper: #f8f8f4;
  --ink: #161d1f;
  --pencil: #566267;
  --band: #7094a0;
  --note: #3f6373;
  --mist: #dce5e8;
  --accent: #e9a03b;

  --serif: "Besley", "Rockwell", "Clarendon", Georgia, serif;
  --hand: "Kalam", "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;

  /* --u is the size of the name. The painted line is drawn in this unit,
     so the underline, the bend and the timeline always join up. */
  --u: clamp(3rem, 15.2vw, 13.5rem);
  --pad: clamp(1.25rem, 4vw, 3.5rem);
  --gutter: 0rem;
  --spine-w: calc(var(--u) * 0.085);
  --spine-x: calc(var(--u) * 0.045);
  --indent: calc(var(--spine-x) + var(--spine-w) / 2 + 1.25rem);
  /* How far the entries of a chapter are set in from its title: little on a phone, where width is scarce. */
  --sub: 0.8rem;
  --measure: 38rem;
  --chapter-gap: clamp(4.25rem, 9vw, 8rem);

  --step--1: 0.9375rem;
  --step-0: 1.125rem;
  --step-1: 1.3125rem;
  --step-2: 1.625rem;
}

@media (min-width: 62rem) {
  :root {
    --gutter: 7.5rem;
    --indent: calc(var(--spine-x) + var(--spine-w) / 2 + 2rem);
    --step-0: 1.1875rem;
    --step-1: 1.4375rem;
    --step-2: 1.75rem;
  }
}

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

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 2rem;
}

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

body {
  position: relative;
  margin: 0;
  background-color: var(--paper);
  /* Paper grain: a faint, static noise. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .09 0 0 0 0 .11 0 0 0 0 .12 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
  color: var(--ink);
  font-family: var(--serif);
  font-size: var(--step-0);
  font-weight: 400;
  line-height: 1.55;
  font-kerning: normal;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

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

h1,
h2,
h3,
dt {
  text-wrap: balance;
}

p,
li,
dd,
figcaption {
  text-wrap: pretty;
}

/* Short hyphenated compounds (k-NN, Q-learning, Milano-Bicocca) never break at the hyphen. */
.nb {
  white-space: nowrap;
}

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

a {
  color: inherit;
  text-decoration-line: underline;
  text-decoration-color: var(--band);
  text-decoration-thickness: 0.14em;
  text-underline-offset: 0.2em;
}

a:hover {
  text-decoration-color: var(--ink);
}

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

em {
  font-style: italic;
}

/* Emoji keep their own upright shape, whatever the text around them does. */
.emoji {
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  font-style: normal;
  font-weight: 400;
}

.defs {
  position: absolute;
}

/* Read by screen readers, not shown: the "opens in a new tab" after external links. */
.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip {
  position: absolute;
  left: var(--pad);
  top: -4rem;
  z-index: 10;
  padding: 0.5rem 0.9rem;
  background: var(--ink);
  color: var(--paper);
  text-decoration: none;
}

.skip:focus {
  top: 0.75rem;
}

.wrap {
  max-width: 88rem;
  margin-inline: auto;
  padding-inline: var(--pad);
}

/* ---------- Top bar ---------- */

.top {
  /* Above the name: its letters are tall enough to reach up here, and would take the clicks. */
  position: relative;
  z-index: 2;
  max-width: 88rem;
  margin-inline: auto;
  padding: 1.1rem var(--pad) 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: flex-end;
  gap: 0.4rem 1.6rem;
  font-size: 0.875rem;
}

@media (min-width: 40rem) {
  .top {
    font-size: var(--step--1);
  }
}

.top a {
  text-decoration-color: transparent;
}

.top a:hover,
.top a[aria-current="page"] {
  text-decoration-color: var(--band);
}

.top-home {
  margin-right: auto;
  font-weight: 800;
  font-size: var(--step-0);
  letter-spacing: -0.01em;
}

.top-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem clamp(0.85rem, 3vw, 1.4rem);
}

.top-lang {
  font-weight: 700;
}

/* ---------- Hero: the name and the painted line ---------- */

.hero {
  padding-left: var(--gutter);
  padding-top: clamp(1.25rem, 2.6vw, 2.1rem);
}

.name {
  position: relative;
  z-index: 0;
  width: max-content;
  max-width: 100%;
  font-size: var(--u);
  font-weight: 900;
  line-height: 0.9;
  letter-spacing: -0.022em;
}

.name span {
  display: block;
}

.swash {
  position: absolute;
  z-index: -1;
  left: -0.03em;
  top: calc(100% - 0.6em);
  width: 5.3em;
  height: 1.5em;
  overflow: visible;
  pointer-events: none;
}

.swash path {
  fill: none;
  stroke: var(--band);
  stroke-linecap: round;
  stroke-linejoin: round;
}

.swash-band {
  stroke-width: 36;
  filter: url(#paint-band);
}

.swash-tail {
  stroke-width: 8.5;
  filter: url(#paint-tail);
}

/* The one moment of unprompted motion: the line is painted in on load. */
/* The resting state is the finished line: if the animation never runs, nothing is missing. */
@media (prefers-reduced-motion: no-preference) {
  .swash-band {
    stroke-dasharray: 1 2;
    animation: paint 0.75s 0.2s cubic-bezier(0.55, 0.1, 0.3, 1) backwards;
  }

  .swash-tail {
    stroke-dasharray: 1 2;
    animation: paint 0.5s 0.85s cubic-bezier(0.4, 0, 0.5, 1) backwards;
  }

  .spine {
    animation: grow 0.9s 1.25s cubic-bezier(0.3, 0, 0.3, 1) backwards;
  }
}

@keyframes paint {
  from {
    stroke-dashoffset: 1.03;
  }

  to {
    stroke-dashoffset: 0;
  }
}

/* Only the first screenful is revealed; the rest of the line is already below the fold. */
@keyframes grow {
  from {
    clip-path: inset(0 -3rem calc(100% - 1px) -3rem);
  }

  to {
    clip-path: inset(0 -3rem calc(100% - 130vh) -3rem);
  }
}

/* ---------- The track: everything the line runs through ---------- */

.past {
  position: relative;
  margin-left: var(--gutter);
}

.spine {
  position: absolute;
  z-index: 0;
  top: calc(var(--u) * 0.2);
  /* The paint stops on the ring that opens the last section. */
  bottom: calc(-1 * var(--chapter-gap) - 1rem);
  left: calc(var(--spine-x) - var(--spine-w) / 2);
  width: var(--spine-w);
  background: var(--band);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* The uneven edge comes from a repeating mask (static/img/spine-mask.svg), whose band
   takes 24 of its 40 units of width: the element is widened to match. A filter here
   would have to run on an element as tall as the whole page. */
@supports (mask-image: none) or (-webkit-mask-image: none) {
  .spine {
    left: calc(var(--spine-x) - var(--spine-w) * 5 / 6);
    width: calc(var(--spine-w) * 5 / 3);
    -webkit-mask: url("../img/spine-mask.svg") top center / 100% auto repeat-y;
    mask: url("../img/spine-mask.svg") top center / 100% auto repeat-y;
  }
}

/* ---------- Intro, right under the name ---------- */

.intro {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.75rem;
  padding-left: var(--indent);
  padding-top: calc(var(--u) * 0.36);
}

.lead {
  max-width: 21em;
  text-wrap: balance;
  font-size: clamp(1.45rem, 1.05rem + 1.75vw, 2.35rem);
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: -0.012em;
}

.sub {
  max-width: 34em;
  margin-top: 1rem;
}

.portrait {
  position: relative;
  width: clamp(9.5rem, 44vw, 15rem);
}

.portrait::before {
  content: "";
  position: absolute;
  inset: 7% 3% 0 3%;
  background: var(--mist);
  border-radius: 47% 53% 50% 50% / 54% 49% 51% 46%;
  filter: url(#paint-small);
}

.portrait img {
  position: relative;
  width: 100%;
  border-radius: 0 0 46% 46% / 0 0 30% 30%;
  mix-blend-mode: multiply;
}

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

.note.facts-note {
  max-width: 31rem;
  margin-bottom: 0.9rem;
}

.facts {
  display: grid;
  gap: 0.85rem;
  max-width: var(--measure);
  padding: 0;
  list-style: none;
}

.facts li {
  position: relative;
  padding-left: 1.7rem;
}

/* A small dab of paint instead of a bullet. */
.facts li::before,
.dab-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.58em;
  width: 0.9rem;
  height: 0.42rem;
  background: var(--band);
  border-radius: 60% 40% 55% 45% / 50% 60% 40% 50%;
  transform: rotate(-9deg);
}

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

.cta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 1.5rem;
}

.btn {
  position: relative;
  isolation: isolate;
  display: inline-block;
  padding: 0.5em 1.15em 0.46em;
  font-weight: 750;
  text-decoration: none;
}

.btn::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--band);
  border-radius: 0.5em 0.75em 0.55em 0.7em / 0.75em 0.5em 0.7em 0.55em;
  filter: url(#paint-small);
  transition: transform 0.18s ease;
}

.btn:hover::before {
  transform: scale(1.04, 1.12) rotate(-1.2deg);
}

/* Table of contents with dot leaders: the timeline at a glance. */
.toc {
  max-width: 25rem;
}

.toc ol {
  padding: 0;
  list-style: none;
}

.toc a {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  padding: 0.3rem 0;
  /* The underline goes on the title only, not on the dotted leader. */
  text-decoration: none;
}

.toc-year {
  position: relative;
  isolation: isolate;
  min-width: 2.9em;
  font-weight: 800;
}

.toc-dots {
  flex: 1;
  min-width: 1.5rem;
  border-bottom: 0.16em dotted var(--pencil);
  transform: translateY(-0.28em);
}

/* Each title is underlined like every other link on the site, so the list reads as links at rest. */
.toc-title {
  text-decoration: underline;
  text-decoration-color: var(--band);
  text-decoration-thickness: 0.14em;
  text-underline-offset: 0.2em;
}

/* Under the pointer, or with keyboard focus, the year is painted over like the button. */
.toc a:hover .toc-year::before,
.toc a:focus-visible .toc-year::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0.08em -0.32em -0.02em -0.32em;
  background: var(--band);
  border-radius: 0.4em 0.6em 0.45em 0.55em / 0.6em 0.4em 0.55em 0.45em;
  filter: url(#paint-small);
}

.toc a:hover .toc-title,
.toc a:focus-visible .toc-title {
  text-decoration-color: var(--ink);
}

.toc a:hover .toc-dots,
.toc a:focus-visible .toc-dots {
  border-bottom-color: var(--ink);
}

@media (min-width: 70rem) {
  .intro {
    grid-template-columns: minmax(0, 38rem) minmax(19rem, 1fr);
    grid-template-areas:
      "text portrait"
      "facts toc"
      "facts cta";
    /* The last row takes what is left, so the links stay right under the table of contents. */
    grid-template-rows: auto auto 1fr;
    column-gap: clamp(2.5rem, 6vw, 6.5rem);
    row-gap: 2.25rem;
    align-items: start;
  }

  .intro-text {
    grid-area: text;
  }

  .portrait {
    grid-area: portrait;
    width: clamp(12rem, 17vw, 16.5rem);
    margin-top: -0.75rem;
  }

  .facts-block {
    grid-area: facts;
  }

  .intro-cta {
    grid-area: cta;
  }

  .toc {
    grid-area: toc;
    width: 100%;
  }
}

/* ---------- Handwritten notes ---------- */

.note {
  max-width: 17rem;
  text-wrap: balance;
  font-family: var(--hand);
  font-size: 1.45rem;
  font-weight: 300;
  line-height: 1.22;
  color: var(--note);
  transform: rotate(-1.6deg);
  transform-origin: left center;
}

.toc-note {
  max-width: none;
  margin-bottom: 0.5rem;
  transform: rotate(-1.2deg);
}

/* ---------- Chapters ---------- */

.chapter,
.now {
  position: relative;
  padding-left: var(--indent);
  padding-top: var(--chapter-gap);
}

/* What came before the first chapter: an entry hanging on the line, with no chapter around it. */
.prologue {
  position: relative;
  padding-left: var(--indent);
  padding-top: calc(var(--chapter-gap) * 0.62);
}

.prologue .entry {
  margin-top: 0;
}

.prologue + .chapter {
  padding-top: calc(var(--chapter-gap) * 0.78);
}

.chapter-head {
  position: relative;
}

/* A ring on the line where each chapter starts. */
.chapter-head::before {
  content: "";
  position: absolute;
  left: calc(var(--spine-x) - var(--indent) - 0.72rem);
  top: 0.28rem;
  width: 1.44rem;
  height: 1.44rem;
  background: var(--paper);
  border: 0.22rem solid var(--ink);
  border-radius: 48% 52% 50% 50% / 52% 48% 52% 48%;
}

.chapter-year {
  display: flex;
  align-items: baseline;
  gap: 0.45em;
  margin-bottom: 0.55rem;
  font-size: var(--step-1);
  font-weight: 800;
  line-height: 1.2;
}

/* The year a chapter starts in is painted over: a flag on the line, easy to find while scrolling. */
.chapter-year span:first-child {
  position: relative;
  isolation: isolate;
  margin-left: 0.3em;
}

.chapter-year span:first-child::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0.04em -0.34em -0.02em -0.34em;
  background: var(--band);
  border-radius: 0.4em 0.6em 0.45em 0.55em / 0.6em 0.4em 0.55em 0.45em;
  filter: url(#paint-small);
}

.chapter-year-end {
  color: var(--pencil);
  font-weight: 500;
}

/* Chapters are the sections of the page: their titles are the largest thing after the name. */
.chapter h2,
.now h2 {
  max-width: 15em;
  font-size: clamp(2.2rem, 1.1rem + 5.2vw, 4.6rem);
  font-weight: 900;
  line-height: 0.98;
  letter-spacing: -0.024em;
}

.chapter-intro {
  max-width: 30em;
  margin-top: 1rem;
  font-size: var(--step-1);
  line-height: 1.38;
  color: var(--pencil);
}

@media (min-width: 62rem) {
  /* On wide screens the year sits in the gutter, left of the line. */
  .chapter-year {
    position: absolute;
    top: 0.1rem;
    right: calc(100% + var(--indent) - var(--spine-x) + 1.6rem);
    display: block;
    margin: 0;
    font-size: var(--step-2);
    line-height: 1.05;
    text-align: right;
    white-space: nowrap;
  }

  .chapter-year span {
    display: block;
  }

  .chapter-year span:first-child {
    width: fit-content;
    margin-left: auto;
    margin-right: 0.3em;
  }

  .chapter-year-end {
    font-size: var(--step-0);
    margin-top: 0.3rem;
  }

  .chapter-head::before {
    top: 0.6rem;
  }
}

/* ---------- Entries ---------- */

@media (min-width: 40rem) {
  :root {
    --sub: 1.25rem;
  }
}

@media (min-width: 62rem) {
  :root {
    --sub: 2rem;
  }
}

/* Entries are the subsections: set in from the chapter title, and smaller. */
.entry {
  position: relative;
  max-width: var(--measure);
  margin-top: 3rem;
  margin-left: var(--sub);
}

/* A stroke ties each entry to the line: the further in the entry, the longer the stroke. */
.entry::before {
  content: "";
  position: absolute;
  left: calc(var(--spine-x) - var(--indent) - var(--sub) + var(--spine-w) / 2 + 3px);
  top: 0.72em;
  width: calc(0.6rem + var(--sub));
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
}

.entry h3 {
  font-size: clamp(1.3rem, 1.16rem + 0.55vw, 1.5rem);
  font-weight: 760;
  line-height: 1.16;
  letter-spacing: -0.01em;
}

.project h2 {
  font-size: clamp(1.5rem, 1.22rem + 1.3vw, 2.1rem);
  font-weight: 850;
  line-height: 1.1;
  letter-spacing: -0.016em;
}

.entry-meta {
  margin-top: 0.4rem;
  margin-bottom: 0.95rem;
  font-size: var(--step--1);
  line-height: 1.4;
  color: var(--pencil);
}

.entry-meta > span {
  display: block;
}

/* Languages and technologies: the names are in ink, so that who looks for them finds them. */
.stack {
  margin-top: 0.15rem;
  color: var(--ink);
}

.stack-label {
  color: var(--pencil);
}

.entry p + p,
.entry p + ul,
.entry ul + p {
  margin-top: 0.9em;
}

/* An entry with no place and no dates: the text starts right under the title. */
.entry h3 + p {
  margin-top: 0.75rem;
}

.plain-list {
  display: grid;
  gap: 0.8em;
  padding: 0;
  list-style: none;
}

.entry-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.6rem;
  margin-top: 1.1rem !important;
  font-weight: 650;
}

.entry--minor {
  color: var(--ink);
}

.entry .note {
  margin: 0 0 1rem;
}

@media (min-width: 78rem) {
  /* With room to spare, notes move out into the right margin. */
  .entry .note {
    position: absolute;
    left: calc(100% + clamp(2.5rem, 5vw, 5.5rem));
    top: 0.35rem;
    width: 16rem;
    margin: 0;
  }

  .entry:nth-of-type(even) .note {
    transform: rotate(1.3deg);
  }
}

/* ---------- Figures ---------- */

.figure {
  margin-block: 2rem;
}

.figure img {
  width: 100%;
  /* The originals have white paper: multiplied, they sit on this page's paper. */
  mix-blend-mode: multiply;
}

.figure figcaption {
  max-width: var(--measure);
  margin-top: 0.7rem;
  font-size: var(--step--1);
  font-style: italic;
  line-height: 1.45;
  color: var(--pencil);
}

/* For ordinary photographs: no blending with the paper. */
.figure--photo img {
  mix-blend-mode: normal;
}

.figure--pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.5rem 1.5rem;
}

.figure--pair figcaption {
  grid-column: 1 / -1;
}

@media (min-width: 40rem) {
  .figure--pair {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* The same scene at different stages, one strip above the other. */
.figure--stack {
  display: grid;
  gap: 0.4rem;
}

.figure--stack figcaption {
  margin-top: 0.3rem;
}

@media (min-width: 62rem) {
  .figure--wide {
    width: min(58rem, calc(100vw - var(--pad) * 2 - var(--gutter) - var(--indent) - var(--sub)));
  }
}

/* ---------- Now: where the painted line stops and the pencil line starts ---------- */

.now {
  margin-left: var(--gutter);
  padding-bottom: clamp(4rem, 8vw, 7rem);
}

.future {
  position: absolute;
  left: calc(var(--spine-x) - 1.5px);
  top: calc(var(--chapter-gap) + 2.6rem);
  bottom: 0;
  border-left: 3px dashed var(--pencil);
  opacity: 0.75;
}

.chapter-head--now::before {
  background: var(--accent);
}

.now-body {
  max-width: var(--measure);
  margin-top: 1.5rem;
}

.now-body > p:not([class]) + p:not([class]) {
  margin-top: 0.9em;
}

/* The invitation to write keeps the size of the text around it and is gone over with a
   highlighter instead: the same paint as the line, behind the lower half of every row. */
.contact {
  max-width: var(--measure);
  margin-block: clamp(2.25rem, 5vw, 3.25rem);
}

.contact-call {
  font-size: var(--step-1);
  font-weight: 650;
  line-height: 1.55;
}

.contact-call span {
  padding: 0 0.2em;
  margin: 0 -0.2em;
  background-image: linear-gradient(to top, transparent 0.1em, var(--mist) 0.1em, var(--mist) 0.72em, transparent 0.72em);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

@supports (background: color-mix(in srgb, red 50%, blue)) {
  .contact-call span {
    --marker: color-mix(in srgb, var(--band) 62%, var(--paper));
    background-image: linear-gradient(to top, transparent 0.1em, var(--marker) 0.1em, var(--marker) 0.72em, transparent 0.72em);
  }
}

.cta--now {
  margin-top: 1.4rem;
}

/* The address is a long word: on the narrowest phones it is set a little smaller, to stay in one piece. */
.btn--mail {
  font-size: min(1em, 4.7vw);
}

.now-small {
  margin-top: 1.4rem;
  color: var(--pencil);
}

.now-small:first-child {
  margin-top: 0;
}

.now-note {
  margin-top: 2.25rem;
  max-width: 26rem;
  font-size: 1.6rem;
}

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

.foot {
  max-width: 88rem;
  margin-inline: auto;
  padding: 2rem var(--pad) 2.75rem calc(var(--pad) + var(--gutter));
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem 2.5rem;
  font-size: var(--step--1);
  color: var(--pencil);
}

.foot-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1.4rem;
}

.foot a {
  color: var(--ink);
}

/* ---------- Inner pages (projects, thesis) ---------- */

.wrap--inner {
  padding-left: calc(var(--pad) + var(--gutter));
  padding-top: clamp(2.5rem, 6vw, 5rem);
  padding-bottom: clamp(3rem, 6vw, 5rem);
}

.page-head h1 {
  position: relative;
  z-index: 0;
  width: fit-content;
  max-width: 12em;
  font-size: clamp(2.5rem, 1.2rem + 5.4vw, 5.75rem);
  font-weight: 900;
  line-height: 0.98;
  letter-spacing: -0.022em;
}

/* The same painted band as on the home page, behind the last word of the title. */
.hl {
  position: relative;
  z-index: 0;
  white-space: nowrap;
}

.hl::before {
  content: "";
  position: absolute;
  z-index: -1;
  left: -0.1em;
  right: -0.22em;
  top: 0.84em;
  height: 0.4em;
  background: var(--band);
  border-radius: 0.18em 0.24em 0.2em 0.22em / 0.2em 0.18em 0.22em 0.2em;
  transform: rotate(-0.7deg);
  filter: url(#paint-small);
}

.page-lead {
  max-width: 34em;
  margin-top: 1.6rem;
  font-size: var(--step-1);
  line-height: 1.4;
}

.page-lead--small {
  margin-top: 0.6rem;
  font-size: var(--step-0);
  color: var(--pencil);
}

/* How many projects there are, in handwriting: the number rolls up to its value. */
.page-count {
  /* Each number of the strip sits on a line this tall, so no stroke of the handwriting is cut off. */
  --row: 1.35;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  width: fit-content;
  margin-top: 1.1rem;
  font-family: var(--hand);
  font-size: 1.6rem;
  font-weight: 300;
  line-height: 1.2;
  color: var(--note);
  transform: rotate(-1.6deg);
  transform-origin: left center;
}

.count {
  display: flex;
  align-items: baseline;
  font-size: 3.4rem;
  font-weight: 400;
  line-height: var(--row);
  color: var(--ink);
}

.count-plus {
  margin-right: 0.04em;
}

.count-window {
  display: block;
  height: calc(var(--row) * 1em);
  overflow: hidden;
}

.count-strip {
  display: block;
  text-align: right;
  /* At rest the strip shows its last number. */
  transform: translateY(calc(var(--n) * var(--row) * -1em));
}

.page-count-note {
  max-width: var(--measure);
  margin-top: 0.5rem;
  font-size: var(--step--1);
  font-style: italic;
  color: var(--pencil);
}

@media (prefers-reduced-motion: no-preference) {
  .count-strip {
    animation: count-up 1.5s 0.35s cubic-bezier(0.25, 0.6, 0.2, 1) backwards;
  }
}

@keyframes count-up {
  from {
    transform: translateY(0);
  }
}

/* The index of the portfolio: the same dotted list as on the home page, with numbers for years. */
.toc--projects {
  max-width: 64rem;
  margin-top: clamp(2.25rem, 5vw, 3.5rem);
}

.toc--projects .toc-year,
.project-number {
  font-family: var(--hand);
  font-weight: 400;
  color: var(--note);
}

.toc--projects .toc-note {
  max-width: none;
}

.toc--projects .toc-year {
  min-width: 1.35em;
  font-size: 1.4em;
  line-height: 1;
  text-align: right;
}

@media (min-width: 46rem) {
  .toc--projects ol {
    columns: 2;
    column-gap: clamp(2.5rem, 6vw, 5rem);
  }

  .toc--projects li {
    break-inside: avoid;
  }
}

/* A pencil thread runs through the projects. It is not the painted line of the home page:
   that one is time, this one only keeps the order of the index, so it carries numbers and no years. */
.projects {
  --thread-x: 0.8rem;
  --thread-in: 2.6rem;
  position: relative;
  margin-top: clamp(3.25rem, 7vw, 5.5rem);
  padding-left: var(--thread-in);
}

.projects::before {
  content: "";
  position: absolute;
  left: var(--thread-x);
  top: 0;
  bottom: 0;
  border-left: 0.16em dotted var(--pencil);
  transform: translateX(-50%);
}

.project {
  position: relative;
  padding-top: 2.1rem;
}

.project + .project {
  margin-top: clamp(4rem, 8vw, 6.5rem);
}

/* Every project opens with a dotted rule that leaves the thread, like a line of the index. */
.project::before {
  content: "";
  position: absolute;
  left: calc(var(--thread-x) - var(--thread-in));
  right: 0;
  top: 0;
  border-top: 0.16em dotted var(--pencil);
}

.project-number {
  position: absolute;
  z-index: 1;
  left: calc(var(--thread-x) - var(--thread-in));
  top: 0;
  display: grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  padding-top: 0.12em;
  background: var(--paper);
  border: 0.11rem solid var(--pencil);
  border-radius: 48% 52% 50% 50% / 52% 48% 52% 48%;
  font-size: 1.35rem;
  line-height: 1;
  transform: translate(-50%, -50%) rotate(-4deg);
}

/* Coming from the index, the number of the project you asked for is painted. */
.project:target .project-number {
  background: var(--band);
  border-color: var(--band);
  color: var(--ink);
}

@media (min-width: 62rem) {
  /* With a margin to spare, the thread runs in it and the projects keep the full width. */
  .projects {
    --thread-x: -3.4rem;
    --thread-in: 0rem;
  }

  .project-number {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.55rem;
  }
}

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

.project .entry-meta {
  margin-top: 0.65rem;
}

.project p + p {
  margin-top: 0.9em;
}

/* The pictures of a project: the same figures the timeline uses, one under the other. */
.project-media {
  display: grid;
  gap: 1.5rem;
  max-width: var(--measure);
  margin-top: 1.4rem;
}

.project-media .figure {
  margin-block: 0;
}

.project-media .figure figcaption {
  margin-top: 0.6rem;
}

@media (min-width: 78rem) {
  /* With room to spare, the picture sits beside the text. */
  .project {
    display: grid;
    grid-template-columns: minmax(0, var(--measure)) minmax(0, 27rem);
    column-gap: clamp(2.5rem, 5vw, 4.5rem);
    align-items: start;
  }

  .project-media {
    margin-top: 0.45rem;
  }
}

.thesis-section {
  max-width: var(--measure);
  margin-top: clamp(3rem, 6vw, 4.75rem);
}

.thesis-section h2 {
  margin-bottom: 1.1rem;
  font-size: clamp(1.9rem, 1.3rem + 2.2vw, 2.9rem);
  font-weight: 850;
  line-height: 1.02;
  letter-spacing: -0.02em;
}

.thesis-section p + p,
.thesis-section p + ul,
.thesis-section p + ol,
.thesis-section p + dl,
.thesis-section ul + p,
.thesis-section ol + p,
.thesis-section figure + p {
  margin-top: 0.95em;
}

.thesis-section p + .data,
.thesis-section .data + p {
  margin-top: 1.5rem;
}

.small-print {
  font-size: var(--step--1);
  line-height: 1.45;
  color: var(--pencil);
}

.thesis-section p + .small-print {
  margin-top: 1.4rem;
}

/* The steps of a pipeline: a real sequence, numbered by hand. */
.steps {
  display: grid;
  gap: 0.85rem;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.steps li {
  position: relative;
  padding-left: 2.5rem;
  counter-increment: step;
}

.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0.15rem;
  top: -0.2rem;
  font-family: var(--hand);
  font-size: 1.75rem;
  font-weight: 400;
  line-height: 1.2;
  color: var(--note);
  transform: rotate(-4deg);
}

.data {
  width: 100%;
  border-collapse: collapse;
}

.data th,
.data td {
  padding: 0.5rem 0 0.45rem 1rem;
  border-bottom: 1px solid var(--mist);
  font-weight: 400;
  text-align: right;
}

.data th:first-child {
  padding-left: 0;
  text-align: left;
}

.data thead th {
  border-bottom: 2px solid var(--ink);
  font-size: var(--step--1);
  font-weight: 750;
}

@media (max-width: 26rem) {
  /* On the narrowest phones the table gets smaller type, so its three columns still fit. */
  .data {
    font-size: var(--step--1);
  }

  .data th,
  .data td {
    padding-left: 0.6rem;
  }

  .data thead th {
    font-size: 0.8125rem;
  }
}

.dab-list {
  display: grid;
  gap: 0.8rem;
  padding: 0;
  list-style: none;
}

.dab-list li {
  position: relative;
  padding-left: 1.7rem;
}

.questions {
  display: grid;
  gap: 1.4rem;
}

.questions dt {
  font-size: var(--step-1);
  font-weight: 800;
  line-height: 1.2;
}

.questions dd {
  margin-top: 0.25rem;
}

.page-back {
  margin-top: clamp(3rem, 6vw, 5rem);
  font-weight: 650;
}

/* ---------- Back to top ---------- */

/* On phones, tablets and narrow windows the button is pinned to the corner of the window, with a
   fixed position and a distance from the bottom edge. It is the way that holds up in mobile
   browsers, whose bars come and go: Safari on the iPhone draws its controls over the bottom of
   the page and keeps what is pinned to the bottom edge above them. (The first version, a sticky
   button placed with viewport units, did not show up on a phone.) The distance from the edge also
   keeps the middle of the button out of the strip where a tap only brings the browser bar back.
   The button is always there. Where the browser can tie an animation to the scroll it stays faint
   until there is something to go back from, and it is never hidden: should that animation ever
   misbehave, the button is still in sight and still works. */
.to-top-rail {
  pointer-events: none;
}

.to-top {
  position: fixed;
  z-index: 5;
  right: max(0.5rem, env(safe-area-inset-right));
  bottom: max(1.75rem, env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  pointer-events: auto;
  background: var(--paper);
  border: 0.11rem solid var(--pencil);
  border-radius: 48% 52% 50% 50% / 52% 48% 52% 48%;
  color: var(--ink);
  opacity: 0.9;
}

.to-top svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@supports (animation-timeline: scroll()) {
  .to-top {
    animation: to-top-in linear both;
    animation-timeline: scroll(root block);
    animation-range: 20vh 70vh;
  }
}

@keyframes to-top-in {
  from {
    opacity: 0.5;
  }

  to {
    opacity: 0.9;
  }
}

.to-top:focus-visible,
.to-top:active {
  background: var(--band);
  border-color: var(--band);
}

@media (hover: hover) {
  /* Only where a pointer can hover: on a touch screen the hover state would stay on after a tap. */
  .to-top:hover {
    background: var(--band);
    border-color: var(--band);
  }
}

/* On a wide screen with a mouse or a trackpad, and no touch screen, the button rides on a rail
   instead: the rail starts below the first screen and ends above the footer, and the button
   sticks to the bottom of the window while the rail is in view. So it shows up only after some
   scrolling, in every browser. Anything with a touch screen keeps the fixed button above. */
@media (min-width: 62rem) and (hover: hover) and (pointer: fine) and (not (any-pointer: coarse)) {
  .to-top-rail {
    position: absolute;
    z-index: 5;
    top: 190vh;
    bottom: 5.5rem;
    right: max(1.5rem, env(safe-area-inset-right));
    width: 2.75rem;
  }

  .to-top {
    position: sticky;
    right: auto;
    bottom: auto;
    top: calc(100vh - 3.6rem);
    top: calc(100dvh - 3.6rem);
    width: 2.75rem;
    height: 2.75rem;
    opacity: 0.94;
    animation: none;
  }

  .to-top:hover,
  .to-top:focus-visible {
    opacity: 1;
  }
}

/* ---------- Print ---------- */

@media print {
  body {
    background: #fff;
    font-size: 11pt;
  }

  .top,
  .skip,
  .foot-links,
  .to-top-rail,
  .future {
    display: none;
  }

  .swash path,
  .btn::before,
  .portrait::before {
    filter: none;
  }

  .entry,
  .project,
  .figure {
    break-inside: avoid;
  }

  .count-strip {
    animation: none;
  }

  .entry .note {
    position: static;
  }
}
