:root {
  --parchment: #efe6d2;
  --paper: #f4efe4; /* torn white core of the scraps */
  --umber: #2b2118;
  --sepia: #6e5b45;
  --lapis: #23408e;
  --gold: #b8913a;
  --rule: rgba(43, 33, 24, 0.18);

  --display: 'IM Fell English', 'Iowan Old Style', Georgia, serif;
  --sans: 'Schibsted Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: ui-monospace, 'Cascadia Mono', Consolas, 'Courier New', monospace;
  --signal: #7fd8ff; /* the "machine" colour: detections, data, kernel */

  --gutter: clamp(16px, 2.4vw, 32px);
  --card-w: 300px;
  --content-left: calc(var(--gutter) + var(--card-w) + clamp(24px, 3vw, 56px));

  /* Fine paper fibres, multiplied over parchment and paper surfaces. */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .26 0 0 0 0 .14 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: #3a2c1f;
  color: var(--umber);
  font: 400 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

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

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

a {
  color: var(--lapis);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  text-decoration-color: rgba(35, 64, 142, 0.35);
  transition: text-decoration-color 0.15s;
}

a:hover {
  text-decoration-color: currentColor;
}

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

::selection {
  background: rgba(184, 145, 58, 0.35);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Stage: fixed paintings behind everything ----------------------------------- */

.stage {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  height: 100lvh; /* stays put while mobile browser bars show and hide */
  overflow: hidden;
  container-type: size;
  z-index: 0;
  background: var(--umber);
}

/* Soft vignette so the floating UI reads on any painting. */
.stage::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(20, 13, 6, 0.38));
  pointer-events: none;
}

.plate {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.9s ease;
}

.plate.is-active {
  opacity: 1;
}

/* The painting's credit, bottom left: text only, no plate. A soft shadow keeps it legible on
   light and dark paint alike. Kept above the mobile browser bar (svh vs lvh). */
.plate__credit {
  position: absolute;
  left: var(--gutter);
  bottom: calc(100lvh - 100svh + 10px);
  z-index: 1;
  max-width: min(60%, 520px);
  font: 400 11.5px/1.35 var(--sans);
  letter-spacing: 0.01em;
  color: rgba(250, 245, 234, 0.92);
  text-shadow: 0 1px 2px rgba(15, 10, 5, 0.75), 0 0 10px rgba(15, 10, 5, 0.5);
  pointer-events: none;
}

/* Cover-fit around a focal point (--fx, --fy), in pure CSS. Scraps inside are positioned in
   percent of this box, so they stay on the painting at any screen size. Portrait screens use
   the plate's portrait focus when it has one. */
.plate__art {
  --fx: var(--fx-wide);
  --fy: var(--fy-wide);
  --W: max(100cqw, 100cqh * var(--ar));
  --H: max(100cqh, 100cqw / var(--ar));
  position: absolute;
  width: var(--W);
  height: var(--H);
  left: clamp(100cqw - var(--W), 50cqw - var(--fx) * var(--W), 0px);
  top: clamp(100cqh - var(--H), 50cqh - var(--fy) * var(--H), 0px);
  transform-origin: calc(var(--fx) * 100%) calc(var(--fy) * 100%);
  transform: scale(var(--zoom, 1)) translateY(var(--pan, 0%));
  will-change: transform;
}

@media (orientation: portrait) {
  .plate__art {
    --fx: var(--fx-portrait, var(--fx-wide));
    --fy: var(--fy-portrait, var(--fy-wide));
  }
}

.plate__img {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  filter: saturate(0.94) contrast(1.03);
}

/* Torn paper: a white paper layer (outer tear) under a face layer (inner tear) ------- */

.torn {
  position: relative;
  filter: drop-shadow(0 10px 14px rgba(24, 14, 4, 0.34)) drop-shadow(0 1px 1px rgba(24, 14, 4, 0.35));
}

.torn__paper,
.torn__face {
  clip-path: var(--outer);
}

.torn__paper {
  position: absolute;
  inset: 0;
  background: var(--grain), var(--paper);
}

.torn__face {
  position: relative;
  clip-path: var(--inner);
}

/* The covered figure, re-drawn as a corrupted data dump by js/datamask.js. */
.datamask {
  position: absolute;
  pointer-events: none;
}

/* "A model looking at the painting" (js/vision.js) ------------------------------------ */

/* Detection boxes: corner brackets, a hairline frame and a label with a confidence. */
.det {
  --c: #7fd8ff;
  position: absolute;
  pointer-events: none;
  border: 1px solid rgba(127, 216, 255, 0.35);
  background:
    linear-gradient(var(--c) 0 0) left top / 14px 2px,
    linear-gradient(var(--c) 0 0) left top / 2px 14px,
    linear-gradient(var(--c) 0 0) right top / 14px 2px,
    linear-gradient(var(--c) 0 0) right top / 2px 14px,
    linear-gradient(var(--c) 0 0) left bottom / 14px 2px,
    linear-gradient(var(--c) 0 0) left bottom / 2px 14px,
    linear-gradient(var(--c) 0 0) right bottom / 14px 2px,
    linear-gradient(var(--c) 0 0) right bottom / 2px 14px;
  background-repeat: no-repeat;
  opacity: 0;
  clip-path: inset(0 100% 100% 0);
  transition:
    opacity 0.2s ease var(--delay, 0s),
    clip-path 0.55s cubic-bezier(0.6, 0, 0.2, 1) var(--delay, 0s);
}

.plate.is-pasted .det {
  opacity: 1;
  clip-path: inset(-24px -4px -4px -4px);
}

.det__tag {
  position: absolute;
  left: -1px;
  bottom: 100%;
  padding: 3px 6px 2px;
  background: var(--c);
  color: #0b1a24;
  font: 600 11px/1.2 var(--mono);
  white-space: nowrap;
}

/* Attention trace: the painting's edge map lighting up from the detections (vision.js). */
.trace {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* A band of the painting sheared sideways for a frame or two. */
.slice {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  clip-path: inset(var(--top, 50%) 0 var(--bottom, 50%) 0);
  transform: translateX(var(--shift, 0));
  filter: saturate(1.25) contrast(1.08) hue-rotate(var(--hue, 0deg));
}

.slice.is-on {
  opacity: 1;
}

/* Cats: cut out along their silhouette, torn paper edge and print grain baked into the
   image (tools/make-scraps.mjs). The shadow follows the alpha, so it hugs the tear. */
.scrap {
  position: absolute;
  left: calc(var(--x) * 1%);
  top: calc(var(--y) * 1%);
  width: calc(var(--w) * 1%);
  height: auto;
  rotate: calc(var(--r) * 1deg);
  filter: drop-shadow(0 8px 10px rgba(24, 14, 4, 0.38)) drop-shadow(0 1px 1px rgba(24, 14, 4, 0.45));
  opacity: 0;
  transform: translateY(-14px) scale(1.08);
  transition:
    opacity 0.3s ease var(--delay, 0s),
    transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) var(--delay, 0s);
}

.plate.is-pasted .scrap {
  opacity: 1;
  transform: none;
}

/* Painting parts cut out to stay in front of a cat. Until the cat pastes in they match the
   painting exactly; then a soft shadow lands on the scrap. */
.over {
  position: absolute;
  left: calc(var(--x) * 1%);
  top: calc(var(--y) * 1%);
  width: calc(var(--w) * 1%);
  height: auto;
  pointer-events: none;
  filter: drop-shadow(-2px 5px 5px rgba(24, 14, 4, 0));
  transition: filter 0.6s ease 0.4s;
}

.plate.is-pasted .over {
  filter: drop-shadow(-2px 5px 5px rgba(24, 14, 4, 0.45));
}

/* Boot screen: the Mona Lisa assembling out of data (js/loader.js) ---------------------- */

html.is-loading {
  overflow: hidden;
}

.loader {
  position: fixed;
  inset: 0;
  z-index: 20;
}

/* The ground before the script runs; once it does, the canvas paints the ground itself (and
   decodes it away on exit), so this layer has to vanish at once when leaving. */
.loader::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 90% at 50% 40%, #241b13, #120d08);
}

.loader.is-leaving {
  pointer-events: none;
}

.loader.is-leaving::before {
  opacity: 0;
}

.loader canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Underneath, the page settles in as the loader dissolves. */
.stage,
.hero {
  transition:
    transform 1.4s cubic-bezier(0.2, 0.7, 0.2, 1),
    filter 1.2s ease,
    opacity 1s ease 0.2s,
    translate 1.2s cubic-bezier(0.2, 0.7, 0.2, 1) 0.2s;
}

html.is-loading .stage {
  transform: scale(1.06);
  filter: brightness(0.55) blur(3px);
}

html.is-loading .hero {
  opacity: 0;
  translate: 0 18px;
}

.loader__meta {
  position: absolute;
  left: 50%;
  bottom: max(28px, 6vh);
  translate: -50% 0;
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 14px 22px 12px;
  background: rgba(18, 13, 8, 0.82);
  border: 1px solid rgba(127, 216, 255, 0.28);
  border-radius: 3px;
  box-shadow: 0 0 24px rgba(127, 216, 255, 0.08);
  color: var(--parchment);
  font: 500 15px/1 var(--mono);
  letter-spacing: 0.04em;
  white-space: nowrap;
  transition: opacity 0.25s;
}

/* The status box leaves 0.25 s after the answers finish, before the page decodes in. */
.loader.is-done .loader__meta,
.loader.is-leaving .loader__meta {
  opacity: 0;
}

.loader__count {
  color: var(--signal);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.loader__bar {
  display: block;
  width: min(300px, 70vw);
  height: 4px;
  border-radius: 2px;
  background: rgba(239, 230, 210, 0.16);
  overflow: hidden;
}

.loader__bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, rgba(127, 216, 255, 0.55), var(--signal));
  box-shadow: 0 0 10px var(--signal);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.25s ease;
}

/* Floating card --------------------------------------------------------------- */

.card {
  position: fixed;
  top: var(--gutter);
  left: var(--gutter);
  z-index: 5;
  width: var(--card-w);
  padding: 22px 22px 18px;
  background: var(--grain), rgba(239, 230, 210, 0.93);
  backdrop-filter: blur(10px);
  box-shadow:
    inset 0 0 0 1px rgba(43, 33, 24, 0.22),
    inset 0 0 0 5px rgba(239, 230, 210, 0.6),
    inset 0 0 0 6px rgba(184, 145, 58, 0.45),
    0 18px 40px rgba(20, 12, 4, 0.35);
  transform-origin: 0 0;
  will-change: transform;
}

/* Creases from being crumpled, fading as the card is smoothed out (main.js sets --creases). */
.card::after,
.paperball__paper::after,
.hero__title::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(28deg, transparent 46%, rgba(70, 50, 25, 0.28) 48.5%, rgba(255, 252, 240, 0.4) 50.5%, transparent 53%),
    linear-gradient(-52deg, transparent 38%, rgba(70, 50, 25, 0.22) 40%, rgba(255, 252, 240, 0.35) 42%, transparent 44%),
    linear-gradient(104deg, transparent 60%, rgba(70, 50, 25, 0.24) 62%, rgba(255, 252, 240, 0.32) 64%, transparent 66%),
    linear-gradient(-14deg, transparent 22%, rgba(70, 50, 25, 0.2) 24%, rgba(255, 252, 240, 0.3) 26%, transparent 28%),
    linear-gradient(68deg, transparent 72%, rgba(70, 50, 25, 0.2) 74%, rgba(255, 252, 240, 0.3) 76%, transparent 78%);
  opacity: var(--creases, 0);
}

/* While the name crumples, its strips fuse into one sheet of parchment behind them. */
.hero__title {
  position: relative;
  isolation: isolate;
}

.hero__title::before {
  content: '';
  position: absolute;
  inset: 0; /* inside the crumple clip-path, which cuts at the element's own box */
  z-index: -1;
  pointer-events: none;
  background: var(--grain), var(--parchment);
  opacity: var(--sheet, 0);
}

.hero__title::after {
  z-index: 1;
}

/* The name as a ball of paper, on its way to becoming the card. */
.paperball {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 5;
  visibility: hidden;
  pointer-events: none;
  filter: drop-shadow(0 10px 12px rgba(20, 12, 4, 0.4));
  will-change: transform, opacity;
}

.paperball__paper {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 252, 240, 0.7), transparent 45%),
    radial-gradient(circle at 70% 75%, rgba(60, 42, 20, 0.35), transparent 55%),
    var(--grain),
    var(--parchment);
  --creases: 1;
}

/* Name, role and intro are one link back to the top. */
.card__home {
  display: block;
  color: inherit;
  text-decoration: none;
}

.card__home:hover .card__name,
.card__home:focus-visible .card__name {
  color: var(--lapis);
}

.card__home:focus-visible {
  outline: 2px solid var(--lapis);
  outline-offset: 4px;
}

.card__name {
  font: 400 38px/0.98 var(--display);
  letter-spacing: -0.01em;
  transition: color 0.15s;
}

.card__name i {
  color: var(--sepia);
}

.card__role {
  margin-top: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--lapis);
}

.card__intro {
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--sepia);
}

.card__index {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
}

.card__index a {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 2px 0;
  color: var(--umber);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
}

.card__index a::after {
  content: '';
  order: 2;
  flex: 1;
  border-bottom: 1px dotted rgba(43, 33, 24, 0.35);
  transform: translateY(-4px);
}

.card__index .num {
  order: 3;
  min-width: 2.2em;
  text-align: right;
  font: 400 15px/1 var(--display);
  color: var(--gold);
}

.card__index a:hover,
.card__index a[aria-current='true'] {
  color: var(--lapis);
}

.card__index a[aria-current='true'] {
  font-weight: 700;
}

.card__bar {
  display: none;
}

/* Page sections ---------------------------------------------------------------- */

main {
  position: relative;
  z-index: 1;
}

/* Hero: the name on torn strips (left) and a notebook pasted on the fresco (right). */
.hero {
  position: relative;
  height: 100vh;
  height: 100svh;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  padding: 0 var(--gutter) clamp(24px, 6vh, 64px);
}

.hero__title {
  /* Lets the name give way to the notebook, not the other way round past the screen edge. */
  min-width: 0;
  transform-origin: 0 100%;
  will-change: opacity, transform;
}

.hero__name {
  font: 400 min(8.4vw, 14vh) / 0.92 var(--display);
  letter-spacing: -0.01em;
}

.hero__line {
  display: block;
  width: fit-content;
}

.hero__line + .hero__line {
  margin: -0.04em 0 0 0.9em;
}

.strip .torn__face {
  padding: 0.14em 0.32em 0.04em;
  background: var(--grain), var(--parchment);
  white-space: nowrap;
}

/* The name needs room for its ascenders and the descender of the italic J, plus the bite
   the torn edge takes out of the paper. */
.hero__name .strip .torn__face {
  padding: 0.2em 0.36em 0.22em;
  line-height: 1.04;
}

.hero__line:first-child .strip {
  rotate: -2deg;
}

.hero__line:nth-child(2) .strip {
  rotate: 1.4deg;
}

.hero__name i {
  color: var(--sepia);
}

.ch {
  display: inline-block;
}

/* A letter that has flipped into data for a moment. */
.ch.is-data {
  font: 600 0.78em/1 var(--mono);
  color: var(--lapis);
  text-align: center;
  vertical-align: 0.06em;
}

.hero__role {
  margin: 0 0 12px 0.3em;
}

.hero__role .strip {
  width: fit-content;
  rotate: -1deg;
}

.strip--ink .torn__face {
  padding: 0.6em 0.85em 0.5em;
  background: #1d1813;
  color: var(--parchment);
  font: 500 clamp(13px, 1.05vw, 17px) / 1 var(--mono);
  letter-spacing: 0.02em;
}

/* Notebook: a dark terminal scrap that types out the highlights. */
.nb {
  flex: none;
  width: min(540px, 40vw);
  /* Sits just above the palette in the corner: its offset and measured height (main.js) plus a
     small gap, less the hero's own bottom padding, which the palette doesn't have. */
  margin-bottom: max(0px, calc(var(--palette-h, 170px) + clamp(12px, 2vw, 28px) + 16px - clamp(24px, 6vh, 64px)));
  rotate: 1.2deg;
  will-change: opacity;
}

.nb__paper .torn__face {
  padding: 14px 18px 18px;
  background: #1d1813;
  color: #e9dfc8;
  font: 400 13px/1.6 var(--mono);
}

.nb__bar {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(233, 223, 200, 0.15);
  color: #8f8268;
  font-size: 11px;
}

.nb__kernel::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--signal);
}

.nb__cell {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 8px;
}

.nb__out {
  display: grid;
  grid-template-columns: 4.6em minmax(0, 1fr);
  gap: 8px;
  margin-top: 2px;
}

.nb__prompt {
  flex: none;
  width: 4.6em;
  color: var(--gold);
}

.nb__prompt--out {
  color: #c97b5f;
}

.nb__code {
  color: #f6eedb;
  font: inherit;
  overflow-wrap: anywhere;
}

.nb__table {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 1px 14px;
}

.nb__table dt {
  color: var(--signal);
}

.nb__table dd {
  color: #e9dfc8;
}

.nb .is-pending {
  visibility: hidden;
}

.nb__caret {
  flex: none;
  width: 0.55em;
  height: 1.1em;
  align-self: center;
  background: var(--signal);
  animation: caret 1s steps(1) infinite;
}

@keyframes caret {
  50% {
    opacity: 0;
  }
}

/* Palette: a torn parchment scrap, like the chapter labels, with three dabs of oil paint
   (the paintings' own vermilion, lapis and umber) that link to Joanna's profiles. */
.palette {
  position: fixed;
  right: clamp(12px, 2vw, 28px);
  bottom: clamp(12px, 2vw, 28px);
  z-index: 6;
  rotate: -2.5deg;
  transition: opacity 0.3s, translate 0.3s;
}

.palette__paper .torn__face {
  display: grid;
  gap: 6px;
  padding: 12px 16px 12px 14px;
  background: var(--grain), var(--parchment);
}

.palette__title {
  margin-bottom: 2px;
  font: italic 400 19px/1 var(--display);
  color: var(--sepia);
}

.swatch {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--umber);
  text-decoration: none;
}

/* A thick oil stroke: uneven blob, grain in the paint, a highlight where it catches light. */
.swatch__paint {
  flex: none;
  width: 30px;
  height: 20px;
  border-radius: 58% 42% 62% 38% / 54% 62% 38% 46%;
  background:
    radial-gradient(ellipse at 30% 28%, rgba(255, 248, 230, 0.6), transparent 38%),
    var(--grain),
    var(--paint);
  box-shadow:
    inset -2px -2px 0 rgba(0, 0, 0, 0.22),
    0 1px 1px rgba(43, 33, 24, 0.35);
  transition: transform 0.2s cubic-bezier(0.3, 1.6, 0.5, 1);
}

.swatch--1 .swatch__paint {
  --paint: #b5452c;
}

.swatch--2 .swatch__paint {
  --paint: var(--lapis);
  border-radius: 46% 54% 40% 60% / 60% 44% 56% 40%;
}

.swatch--3 .swatch__paint {
  --paint: var(--umber);
  border-radius: 62% 38% 52% 48% / 42% 58% 42% 58%;
}

/* Back to top: a gold dab, set off from the links by a hairline. */
.swatch--top {
  margin-top: 2px;
  padding-top: 7px;
  border-top: 1px solid var(--rule);
}

.swatch--top .swatch__paint {
  --paint: var(--gold);
  border-radius: 50% 50% 44% 56% / 58% 46% 54% 42%;
}

.swatch__label {
  font: 500 12px/1 var(--mono);
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s, color 0.15s;
}

.swatch:hover .swatch__paint,
.swatch:focus-visible .swatch__paint {
  transform: scale(1.18) rotate(-6deg);
}

.swatch:hover .swatch__label,
.swatch:focus-visible .swatch__label {
  color: var(--lapis);
  border-color: currentColor;
}

/* Figures in the resume, set like data readouts. */
.metric {
  padding: 0 0.12em;
  background: linear-gradient(transparent 60%, rgba(127, 216, 255, 0.4) 0);
  color: var(--lapis);
  font: 600 0.92em var(--mono);
}

/* Each chapter opens on its painting, titled by a strip of torn paper. */
.opener {
  position: relative;
  height: 88vh;
  height: 88svh;
}

/* The first chapter follows straight on from the hero, which has already shown a full screen
   of painting: its opener is shorter, so the title arrives sooner. */
.chapter:first-child .opener {
  height: 58vh;
  height: 58svh;
}

/* The label sits low in the opener, below where the cat scraps are pasted. */
.label {
  position: absolute;
  right: clamp(16px, 5vw, 80px);
  bottom: 3vh;
  max-width: calc(100% - 2 * clamp(16px, 5vw, 80px));
  rotate: -1.6deg;
}

.label .torn__face {
  padding: 0.18em 0.42em 0.12em;
  background: var(--grain), var(--parchment);
  font: 400 clamp(44px, 6.4vw, 116px) / 1 var(--display);
  letter-spacing: -0.01em;
}

.label .num {
  margin-right: 0.3em;
  font-size: 0.5em;
  color: var(--gold);
}

.sheet {
  margin: 0 clamp(16px, 5vw, 80px) 0 var(--content-left);
  max-width: 880px;
}

.sheet > .torn__face {
  padding: clamp(40px, 5vw, 72px) clamp(24px, 4vw, 64px);
  background: var(--grain), var(--parchment);
}

.sheet-lead {
  font: 400 clamp(22px, 2.1vw, 28px) / 1.4 var(--display);
  max-width: 36em;
}

.sub {
  margin: clamp(36px, 4vw, 56px) 0 18px;
  font: 600 13px/1.4 var(--sans);
  color: var(--sepia);
  letter-spacing: 0.02em;
}

.entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 24px;
  padding: 22px 0 24px;
  border-top: 1px solid var(--rule);
}

.entry:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.sub + .entry {
  border-top: 1px solid var(--rule);
  padding-top: 22px;
}

.entry__title {
  font: 400 clamp(24px, 2.3vw, 30px) / 1.15 var(--display);
}

.entry__dates {
  font-size: 13px;
  color: var(--sepia);
  white-space: nowrap;
  padding-top: 0.5em;
}

.entry__context {
  grid-column: 1 / -1;
  font-size: 14px;
  color: var(--sepia);
  max-width: 44em;
}

.entry__body {
  grid-column: 1 / -1;
  margin-top: 10px;
}

.entry__body li,
.role__note {
  max-width: 44em;
}

.entry__body li {
  position: relative;
  padding-left: 1.2em;
  margin-top: 6px;
}

.entry__body li::before {
  content: '';
  position: absolute;
  left: 0.1em;
  top: 0.72em;
  width: 0.45em;
  height: 1px;
  background: var(--gold);
}

.role + .role {
  margin-top: 18px;
}

.role__head {
  display: flex;
  justify-content: space-between;
  gap: 4px 24px;
  flex-wrap: wrap;
  font-weight: 600;
}

.role__note {
  font-size: 14px;
  color: var(--sepia);
}

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

.skills dt,
.skills dd {
  padding: 14px 0;
  border-top: 1px solid var(--rule);
}

.skills dt {
  font-weight: 600;
  padding-right: 16px;
}

.contact-list {
  display: grid;
  grid-template-columns: 7rem minmax(0, 1fr);
  margin-top: clamp(28px, 3vw, 40px);
}

.contact-list dt,
.contact-list dd {
  padding: 16px 0;
  border-top: 1px solid var(--rule);
}

.contact-list dt {
  font-size: 14px;
  color: var(--sepia);
  padding-top: 24px;
}

.contact-list dd {
  font: 400 clamp(24px, 3vw, 38px) / 1.2 var(--display);
  overflow-wrap: anywhere;
}

.credits {
  margin-top: clamp(48px, 6vw, 80px);
  padding-top: 18px;
  border-top: 1px solid var(--rule);
  font-size: 13px;
  color: var(--sepia);
}

.credits li {
  margin-top: 2px;
}

/* Ends on the painting, not on bare page background. */
main {
  padding-bottom: 14vh;
}

/* Phones, portrait tablets, landscape phones --------------------------------------
   Below this width a side card would cover the content column, so the card turns into
   a top bar. Keep in sync with `phone` in js/main.js. */

@media (max-width: 860px) {
  :root {
    --content-left: clamp(12px, 4vw, 40px);
  }

  /* On phones the bottom of the screen is nearly always the notebook or a text panel, so the
     caption moves to the top left, just under the docked bar, where the painting shows. */
  .plate__credit {
    top: 92px;
    bottom: auto;
    left: 14px;
    max-width: calc(100% - 28px);
    font-size: 10.5px;
  }

  .sheet {
    margin-right: clamp(12px, 4vw, 40px);
  }

  .card {
    right: 8px;
    left: 8px;
    top: 8px;
    width: auto;
    padding: 18px 18px 14px;
  }

  .card__name {
    font-size: 32px;
  }

  /* Docked on phones: a slim bar with the name and current chapter; tap Index to expand. */
  .card.is-docked:not(.is-open) {
    padding: 10px 14px;
  }

  .card.is-docked:not(.is-open) .card__name {
    font-size: 22px;
  }

  .card.is-docked:not(.is-open) :is(.card__role, .card__intro, .card__index) {
    display: none;
  }

  /* Hero on narrow screens: name, then the notebook, stacked at the bottom of the painting. */
  .hero {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-end;
    gap: 16px;
    padding-bottom: 16px;
  }

  .hero__name {
    font-size: min(12.5vw, 9vh);
  }

  .nb {
    width: auto;
    margin-bottom: 0;
    rotate: 0.6deg;
  }

  .nb__paper .torn__face {
    padding: 10px 14px 14px;
    font-size: 11.5px;
  }

  /* Phones: only the last cell (the top results), so the painting keeps the upper half. */
  .nb__cell:not(:nth-last-child(2)),
  .nb__out:not(:last-child) {
    display: none;
  }

  /* The palette would sit on the notebook, so it waits until the hero has scrolled away. */
  html.at-hero .palette {
    opacity: 0;
    translate: 0 12px;
    pointer-events: none;
  }

  /* Compact on phones: paint dabs in a row, labels under them. */
  .palette__paper .torn__face {
    grid-auto-flow: column;
    gap: 12px;
    padding: 9px 12px;
  }

  .palette__title {
    display: none;
  }

  .swatch {
    flex-direction: column;
    gap: 5px;
  }

  /* In the row, the hairline goes on the left instead. */
  .swatch--top {
    margin: 0;
    padding: 0 0 0 10px;
    border-top: 0;
    border-left: 1px solid var(--rule);
  }

  .swatch__paint {
    width: 26px;
    height: 18px;
  }

  .swatch__label {
    font-size: 10px;
  }

  .card.is-docked .card__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 4px;
    font-size: 13px;
    color: var(--sepia);
  }

  .card.is-docked.is-open .card__bar {
    margin-top: 12px;
  }

  .card__toggle {
    padding: 4px 10px;
    border: 1px solid var(--rule);
    border-radius: 3px;
    background: transparent;
    color: var(--umber);
    font: 600 13px/1.4 var(--sans);
  }

  .opener {
    height: 80vh;
    height: 80svh;
  }

  .chapter:first-child .opener {
    height: 52vh;
    height: 52svh;
  }

  .label {
    right: 12px;
    max-width: calc(100% - 24px);
  }

  .label .torn__face {
    font-size: clamp(36px, 11vw, 56px);
  }

  .entry {
    grid-template-columns: 1fr;
  }

  .entry__dates {
    padding-top: 0;
  }

  .skills,
  .contact-list {
    grid-template-columns: 1fr;
  }

  .skills dd,
  .contact-list dd {
    border-top: 0;
    padding-top: 0;
  }

  .contact-list dt {
    padding-top: 16px;
  }
}

/* Shorter wide screens (13–14" laptops, landscape tablets): the notebook drops its first
   cell and tightens up, so it stays clear of the cats pasted on the fresco above it. */
@media (min-width: 861px) and (max-height: 920px) {
  .nb__bar + .nb__cell {
    display: none;
  }

  /* A touch wider so rows don't wrap, kept off the right edge despite its tilt. */
  .nb {
    width: min(500px, 40vw);
    margin-right: 6px;
  }

  .nb__paper .torn__face {
    padding: 12px 16px 14px;
    font-size: 12px;
    line-height: 1.5;
  }
}

/* Short screens (landscape phones): the name alone carries the hero, and the chapter labels
   shrink so they don't cover the painting. */
@media (max-height: 520px) {
  .nb {
    display: none;
  }

  .label .torn__face {
    font-size: clamp(30px, 11vh, 52px);
  }

  .loader__meta {
    gap: 6px;
    padding: 8px 16px 7px;
    font-size: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  /* The name and the card swap with a short fade instead of the crumple; the card is hidden
     only once it has faded out. */
  .card,
  .hero__title,
  .nb {
    transition: opacity 0.3s ease;
  }

  .card {
    transition: opacity 0.3s ease, visibility 0s linear 0.3s;
  }

  .card.is-docked {
    transition: opacity 0.3s ease, visibility 0s;
  }

  .plate {
    transition: none;
  }

  .scrap,
  .det {
    transition: none;
  }

  .trace,
  .slice {
    display: none;
  }
}
