/*
  Alegreya Sans: Juan Pablo del Peral, Huerta Tipográfica, 2013. A humanist
  sans with calligraphic roots, true small caps and oldstyle figures. The
  face of the CV. Licensed under the SIL Open Font License (OFL.txt).
*/

@font-face {
  font-family: "Alegreya Sans";
  src: url("type/regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Alegreya Sans";
  src: url("type/italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "Alegreya Sans";
  src: url("type/medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

:root {
  --face: "Alegreya Sans", "Gill Sans", Optima, system-ui, sans-serif;
  --face-scale: 1.1; /* a small x-height (.458 em): set it a size up */
  --face-measure: 30rem; /* a narrower face: about 75 characters a line */
  --face-features: normal;
  --face-title-weight: 500; /* a sans needs a little weight to anchor entries */
  --face-caps-tracking: 0.1em;
}

/*
  One stylesheet, no framework. The build prepends the chosen typeface's
  face.css, which defines the --face-* tokens used here.

  The page is set in one type family: a text face, plus its display
  companion for headings when the package has one. Hierarchy comes from
  size, italic, small caps and figure style rather than from colour. The
  one accent, an ink blue, marks section labels and interaction.

  Layout: on screens each section's label heads it, and figures stand in
  a column beside their entries when there is room. Print keeps the labels
  in a margin column, like the CV.
*/

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

/* Each colour is given for a light page and a dark one; color-scheme picks
   which, following the system unless the switch in the corner turns the
   page to the other. */
:root {
  --paper: light-dark(#fcfbf8, #121211);
  --ink: light-dark(#1c1b19, #e6e2d9);
  --ink-2: light-dark(#4f4b44, #bab4a9); /* roles, authors          8.4:1 on paper */
  --ink-3: light-dark(#6e695f, #938d82); /* dates, notes, colophon  5.3:1 */
  --rule: light-dark(#e3dfd6, #2a2925);
  --accent: light-dark(#1b229e, #a8aff2); /* ink blue              11.5:1 */
  --underline: color-mix(in oklab, var(--ink) 30%, var(--paper));

  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --measure: var(--face-measure, 35rem);
  --margin: 8.5rem;
  --gutter: 2.75rem;
  --figure: 13.5rem;
  --leading: 1.55;

  color-scheme: light dark;
}

:root:has(#scheme-dark:checked) {
  color-scheme: dark;
}

:root:has(#scheme-light:checked) {
  color-scheme: light;
}

/* The switch: a sun and a moon side by side, each a hidden radio button.
   The scheme on show is drawn in full ink, the other in a light gray. The
   page follows the system until one is chosen, which holds while the page
   is open (no JavaScript). */
.scheme {
  position: absolute;
  top: 1.1rem;
  right: 1.25rem;
  display: flex;
  gap: 0.15rem;
}

.scheme input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.scheme label {
  display: block;
  padding: 0.3rem;
  color: color-mix(in oklab, var(--ink-3) 55%, var(--paper));
  cursor: pointer;
}

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

.scheme input:focus-visible + label {
  outline: 1px solid var(--accent);
  border-radius: 50%;
}

.scheme svg {
  display: block;
  width: 1.05rem;
  height: 1.05rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:root:has(#scheme-dark:checked) label[for="scheme-dark"],
:root:has(#scheme-light:checked) label[for="scheme-light"] {
  color: var(--ink);
}

@media not (prefers-color-scheme: dark) {
  :root:not(:has(.scheme input:checked)) label[for="scheme-light"] {
    color: var(--ink);
  }
}

@media (prefers-color-scheme: dark) {
  :root:not(:has(.scheme input:checked)) label[for="scheme-dark"] {
    color: var(--ink);
  }
}

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

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

html {
  font-size: calc(clamp(1rem, 0.9rem + 0.35vw, 1.1875rem) * var(--face-scale));
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Links within the page (the tags) glide to their target, unless the
   reader has asked for less motion. */
@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--face);
  line-height: var(--leading);
  font-kerning: normal;
  font-variant-numeric: oldstyle-nums proportional-nums;
  font-feature-settings: var(--face-features);
  font-synthesis: none; /* never fake an italic or small caps */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  hanging-punctuation: first allow-end;
}

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

/* Headings take the package's display face, when it has one. */
h1,
h2,
h3,
.headline {
  font-family: var(--face-display, var(--face));
}

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

a:hover,
.cite:hover {
  color: var(--accent);
  text-decoration-color: currentColor;
}

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

::selection {
  background: color-mix(in oklab, var(--accent) 20%, var(--paper));
}

abbr {
  text-decoration: none;
}

abbr[title] {
  cursor: help;
}

code {
  font-family: var(--mono);
  font-size: 0.84em;
}

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

.page {
  position: relative;
  max-width: calc(var(--margin) + var(--gutter) + var(--measure) + 2.5rem);
  margin-inline: auto;
  padding: clamp(3rem, 11vh, 7.5rem) 1.25rem 4rem;
}

section,
.colophon {
  display: grid;
  grid-template-columns: var(--margin) minmax(0, 1fr);
  column-gap: var(--gutter);
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
}

section {
  margin-top: 3.5rem;
}

/* The label rides along in the margin while its section is on screen. */
section > h2 {
  position: sticky;
  top: 1.5rem;
  align-self: start;
  margin: 0;
  font-size: 1rem;
  font-weight: 400;
  line-height: var(--leading);
  font-variant-caps: all-small-caps;
  letter-spacing: var(--face-caps-tracking);
  color: var(--accent);
}

section > .body {
  grid-column: 2;
  max-width: var(--measure);
}

section > .body > p {
  margin: 0;
}

section > .body > p + p {
  margin-top: 0.85em;
}

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

.masthead {
  margin-bottom: clamp(3rem, 9vh, 5.5rem);
}

/* Tags: topics under the contacts, each a link to where the page covers it. */
/* One recent line under the contacts, its label in the accent. */
.news {
  margin: 0.9rem 0 0;
  color: var(--ink-2);
}

.news em {
  font-style: normal;
  color: var(--accent);
}

.tags {
  margin-top: 1.4rem;
}

/* The list is pulled left by a tag's padding, so the first word lines up
   with the text above. */
.tags ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
  margin: 0 0 0 -0.5rem;
  padding: 0;
  list-style: none;
}

/* Plain words until pointed at, fainter than any other text on the page
   (about 3:1 against the paper: below the 4.5:1 body text needs, a choice
   for a row that is a shortcut, not content); a wash appears on hover. */
.tags a {
  display: block;
  padding: 0.05rem 0.5rem 0.1rem;
  border-radius: 2px;
  font-size: 0.85rem;
  color: color-mix(in oklab, var(--ink-3) 68%, var(--paper));
  text-decoration: none;
  transition: color 0.15s, background-color 0.15s;
}

.tags a:hover,
.tags a:focus-visible {
  color: var(--accent);
  background: color-mix(in oklab, var(--accent) 9%, transparent);
}

.tags abbr {
  cursor: pointer;
}

/* Where a tag lands: a little room above, and the entry lit up briefly. */
:is(section, .entry)[id] {
  scroll-margin-top: 1.5rem;
}

@media (prefers-reduced-motion: no-preference) {
  .entry:target {
    animation: landed 2.4s ease-out;
  }
}

@keyframes landed {
  from {
    background: color-mix(in oklab, var(--accent) 9%, transparent);
    box-shadow: 0 0 0 0.75rem color-mix(in oklab, var(--accent) 9%, transparent);
  }
}

.masthead h1 {
  margin: 0;
  font-size: clamp(2.3rem, 1.4rem + 3vw, 3.4rem);
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.headline {
  margin: 0.55rem 0 0;
  font-size: 1.2rem;
  font-style: italic;
  color: var(--ink-2);
}

.contact {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 1.5rem;
  margin: 1.6rem 0 0;
  padding: 0;
  list-style: none;
  color: var(--ink-2);
}

/* With a figure the masthead reads like a title page: the name across the
   top, details on the left, the figure on the right. */
.masthead:has(> :is(.figure, .portrait)) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--figure);
  grid-template-rows: auto auto auto 1fr;
  column-gap: var(--gutter);
}

.masthead:has(> :is(.figure, .portrait)) h1 {
  grid-column: 1 / -1;
}

.masthead:has(> :is(.figure, .portrait)) > :is(.headline, .contact, .news, .tags) {
  grid-column: 1;
}

.masthead:has(> :is(.figure, .portrait)) .contact {
  flex-direction: column;
  align-content: start;
  gap: 0.15rem;
}

.masthead > :is(.figure, .portrait) {
  grid-column: 2;
  grid-row: 2 / -1;
  margin-top: 1.1rem;
}


/* Figures (sitegen/figures/) ------------------------------------------- */

.figure {
  margin: 0;
}

.figure svg {
  display: block;
  width: 100%;
  height: auto;
}

/* A point-cloud portrait in one version is a dark print: the dark scheme's
   paper and ink whatever the page's scheme, so on a dark page it is
   seamless and on a light one it is a small dark plate. */
.portrait svg.on-any {
  color-scheme: dark;
  padding: 0.6rem;
  border-radius: 2px;
  background: var(--paper);
  color: var(--ink);
}

/* Its dot count and the word joined to it stay on one line. */
.portrait figcaption .nowrap {
  white-space: nowrap;
}

/* A point-cloud portrait can come in two versions, dots in the page's ink:
   for a light page they mark where the face is in shade, for a dark one
   where it is lit. The one that suits the scheme shows, following the
   switch, and so does its dot count in the caption. Only the other one is
   hidden, so each keeps its own display. */
@media not (prefers-color-scheme: dark) {
  :root:not(:has(#scheme-dark:checked)) .portrait .on-dark,
  :root:has(#scheme-dark:checked) .portrait .on-light {
    display: none;
  }
}

@media (prefers-color-scheme: dark) {
  :root:not(:has(#scheme-light:checked)) .portrait .on-light,
  :root:has(#scheme-light:checked) .portrait .on-dark {
    display: none;
  }
}

/* Strokes keep their weight whatever the drawing's scale. */
.figure path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.figure .mask {
  fill: var(--paper);
  stroke: none;
}

.figure .hatch {
  stroke: var(--rule);
  stroke-width: 0.6px;
}

.figure .faint {
  stroke: var(--ink-3);
  stroke-width: 0.55px;
}

.figure .soft {
  stroke: var(--ink-3);
  stroke-width: 0.55px;
  opacity: 0.5;
}

.figure .ink {
  stroke: var(--ink-2);
  stroke-width: 0.8px;
}

.figure .dashed {
  stroke: var(--ink-3);
  stroke-width: 0.7px;
  stroke-dasharray: 2.5 2;
}

.figure .mark {
  stroke: var(--accent);
  stroke-width: 1px;
}

.figure .stipple {
  stroke: var(--ink-3);
  stroke-width: 1.2px;
}

.figure .dots {
  stroke: var(--accent);
  stroke-width: 2.4px;
}

.figure .light {
  stroke: var(--paper);
  stroke-width: 1.6px;
}

/* Inked lines (the portrait): tapering outlines, filled in the colour the
   style would stroke with. */
.figure .pen {
  stroke: none;
}

.figure .ink.pen {
  fill: var(--ink-2);
}

.figure :is(.faint, .soft).pen {
  fill: var(--ink-3);
}

.figure .mark.pen {
  fill: var(--accent);
}

/* Lining figures: in a drawing an old-style 0 reads as a letter o. */
.figure text {
  fill: var(--ink-3);
  font-style: italic;
  font-variant-numeric: lining-nums tabular-nums;
}

.figure figcaption {
  margin-top: 0.6rem;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--ink-3);
}


/* In an entry the figure follows the text, unless there is room beside it
   (see the two-column layout below). */
.entry > .figure {
  max-width: 20rem;
  margin-top: 1.1rem;
}

/* About ----------------------------------------------------------------- */

section > .body > .status {
  position: relative;
  margin-top: 1.4em;
  font-style: italic;
  color: var(--ink-2);
}

/* Hangs in the gutter like the list bullets, in the accent colour. */
.status::before {
  content: "";
  position: absolute;
  left: -1.05rem;
  top: 0.62em;
  width: 0.36em;
  height: 0.36em;
  background: var(--accent);
}

/* Entries: roles, papers, projects, degrees ---------------------------- */

.entry + .entry {
  margin-top: 2rem;
}

.entry > header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 1.5rem;
  align-items: baseline;
}

.entry h3 {
  grid-column: 1;
  margin: 0;
  font-size: 1.0625rem;
  font-weight: var(--face-title-weight);
  line-height: 1.4;
  text-wrap: balance;
}

.entry h3 a {
  text-decoration-color: transparent;
}

.entry h3 a:hover {
  text-decoration-color: currentColor;
}

.entry .sub {
  grid-column: 1;
  margin: 0;
  font-style: italic;
  color: var(--ink-2);
}

/* How a project placed: its own line under the subtitle, in the title's weight. */
.entry .placement {
  margin: 0.15rem 0 0;
}

.entry .placement strong {
  font-weight: var(--face-title-weight);
}

.entry .when {
  grid-column: 2;
  grid-row: 1;
  margin: 0;
  white-space: nowrap;
  color: var(--ink-3);
}

.entry ul {
  margin: 0.6rem 0 0;
  padding: 0;
  list-style: none;
}

.entry li {
  position: relative;
}

.entry li + li {
  margin-top: 0.35rem;
}

/* Bullets hang in the gutter so the text keeps one left edge. */
.entry li::before {
  content: "";
  position: absolute;
  left: -1.05rem;
  top: 0.66em;
  width: 0.28em;
  height: 0.28em;
  background: var(--ink-3);
}

.entry > p {
  margin: 0.45rem 0 0;
}

.paper .authors {
  font-size: 0.9375rem;
  color: var(--ink-2);
}

.paper .authors .me {
  color: var(--ink);
}

.links {
  font-size: 0.9375rem;
  color: var(--ink-3);
}

.links :is(a, .cite) {
  color: var(--ink-2);
}

.links :is(a, .cite):hover {
  color: var(--accent);
}

.thesis {
  color: var(--ink-2);
}

section > .body > .footnote {
  margin-top: 2rem;
  font-size: 0.875rem;
  color: var(--ink-3);
}

/* BibTeX: a native popover, so it needs no script. */
.cite {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  cursor: pointer;
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  text-decoration-color: var(--underline);
}

.bibtex {
  width: min(44rem, 100vw - 2rem);
  margin: auto;
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 1.5rem 3rem -1.5rem rgb(0 0 0 / 0.3);
}

.bibtex::backdrop {
  background: rgb(0 0 0 / 0.12);
}

.bibtex pre {
  margin: 0;
  font: 0.8rem / 1.6 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  -webkit-user-select: all; /* one click selects the whole entry */
  user-select: all;
}

/* Tools ----------------------------------------------------------------- */

.skills {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.4rem 1.75rem;
  margin: 0;
}

.skills dt {
  font-style: italic;
  color: var(--ink-2);
}

.skills dd {
  margin: 0;
}

/* Colophon -------------------------------------------------------------- */

.colophon {
  margin-top: 4.5rem;
  font-size: 0.875rem;
  color: var(--ink-3);
}

.colophon p {
  grid-column: 2;
  max-width: var(--measure);
  margin: 0 0 0.5rem;
}

/* Screens: two columns ------------------------------------------------- */

/* Each section's label heads it, so the text gets the full measure and a
   section with figures sets them in a column beside its entries, as wide
   as the page allows. Print keeps the labels in the margin (below). */
@media screen {
  :root {
    --aside: clamp(12rem, 36%, 18rem);
  }

  .page {
    max-width: calc(var(--measure) + var(--gutter) + 18rem + 2.5rem);
  }

  section,
  .colophon {
    grid-template-columns: minmax(0, 1fr);
  }

  section > h2 {
    position: static;
    margin-bottom: 0.9rem;
  }

  section > .body,
  .colophon p {
    grid-column: 1;
  }

  section:has(.entry > .figure) > .body {
    max-width: none;
  }

  .masthead:has(> :is(.figure, .portrait)) {
    grid-template-columns: minmax(0, 1fr) var(--aside);
  }

  .masthead > .portrait {
    max-width: var(--figure);
  }
}

@media screen and (width >= 46rem) {
  section:has(.entry > .figure) .entry {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--aside);
    grid-template-rows: repeat(3, auto) 1fr;
    column-gap: var(--gutter);
  }

  section:has(.entry > .figure) .entry > :not(.figure) {
    grid-column: 1;
  }

  .entry > .figure {
    grid-column: 2;
    grid-row: 1 / -1;
    max-width: none;
    margin-top: 0.35rem;
  }
}

/* Narrow screens: one column ------------------------------------------- */

@media screen and (width < 48rem) {
  .entry > header {
    grid-template-columns: minmax(0, 1fr);
  }

  .entry .when {
    grid-column: 1;
    grid-row: auto;
  }

  .entry ul,
  section > .body > .status {
    padding-left: 1.05rem;
  }

  .status::before {
    left: 0;
  }

  .skills {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .skills dd + dt {
    margin-top: 0.6rem;
  }
}

/* Phones: figures under the text ----------------------------------- */

/* A figure beside the name goes under it; the portrait stays beside the
   contacts, small, so About still starts on the first screen. */
@media screen and (width < 40rem) {
  .masthead:has(> .figure:not(.portrait)) {
    display: block;
  }

  .masthead > .figure:not(.portrait) {
    max-width: 20rem;
    margin-top: 1.75rem;
  }

  .masthead:has(> .portrait) {
    grid-template-columns: minmax(0, 1fr) 7.5rem;
    column-gap: 1.25rem;
    margin-bottom: 1.75rem;
  }

  .masthead:has(> .portrait) + main > section:first-child {
    margin-top: 0;
  }

  .masthead:has(> .portrait) > :is(.headline, .tags) {
    grid-column: 1 / -1;
  }

  .masthead > .portrait {
    grid-row: 3;
    max-width: none;
    margin-top: 0.35rem;
  }

  .masthead > .portrait figcaption {
    font-size: 0.72rem;
    line-height: 1.35;
  }
}

/* Print: the page doubles as a CV ------------------------------------- */

@media print {
  @page {
    size: A4;
    margin: 15mm 17mm;
  }

  :root {
    --paper: #fff;
    --ink: #000;
    --ink-2: #333;
    --ink-3: #555;
    --rule: #bbb;
    --accent: #1b229e;
  }

  html {
    font-size: 8.75pt;
  }

  .page {
    --margin: 7rem;
    --gutter: 1.75rem;
    max-width: none;
    padding: 0;
  }

  .masthead,
  .masthead:has(> :is(.figure, .portrait)) {
    display: block;
    margin-bottom: 1.25rem;
  }

  .masthead h1 {
    font-size: 2.4rem;
  }

  section {
    margin-top: 0.9rem;
    padding-top: 0.5rem;
  }

  .skills {
    gap: 0.1rem 1.5rem;
  }

  section > h2 {
    position: static;
  }

  section > .body,
  .colophon p {
    max-width: none;
  }

  .entry {
    break-inside: avoid;
  }

  .entry + .entry {
    margin-top: 0.9rem;
  }

  .entry ul {
    margin-top: 0.3rem;
  }

  .entry li + li {
    margin-top: 0.1rem;
  }

  .colophon {
    margin-top: 1.5rem;
  }

  .colophon p:first-child {
    display: none; /* describes the website, not the printout */
  }

  a {
    text-decoration: none;
  }

  .contact a[href^="http"]::after {
    content: " " attr(href);
    color: var(--ink-3);
  }

  .cite,
  .bibtex,
  .figure,
  .portrait,
  .scheme,
  .tags,
  .sep:has(+ .cite) {
    display: none;
  }
}
