/* Unvalued — a book, in spreads.
   Each chapter is two pages: text on the left, the plate on the right.
   The plate stays in place while the text beside it is read. */

:root {
  --paper: #F7F5EF;
  --ink: #17160F;
  --ink-soft: #3B3A32;
  --grey: #6B6A62;
  --rule: rgba(23, 22, 15, 0.14);
  --gutter-shade: rgba(23, 22, 15, 0.06);

  --abyss: #2E5F7E;
  --ochre: #C9A062;
  --kelp: #5C7A5A;
  --plum: #7D5A79;

  --serif: "EB Garamond", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;

  --margin: 6.5rem;         /* left page: margin for numbers and notes */
  --measure: 31rem;         /* left page: text column, ~64 characters */
  --fold: 5rem;             /* the gutter between the two pages */
  --page-pad: 1.25rem;
  --head-h: 4.25rem;
  --book-w: 1440px;
  /* The left edge of the book, so fixed furniture stays with the pages on a wide screen. */
  --book-left: max(var(--page-pad), calc((100vw - var(--book-w)) / 2 + var(--page-pad)));
}

* { box-sizing: border-box; }
/* Smooth scrolling comes on once the page has opened at its address; the first jump is instant. */
html.is-ready { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html.is-ready { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 20px;
  line-height: 1.45;
  font-feature-settings: "onum" 1, "liga" 1, "kern" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  padding-left: max(var(--page-pad), env(safe-area-inset-left, 0px));
  padding-right: max(var(--page-pad), env(safe-area-inset-right, 0px));
  overflow-x: clip;
}

/* Paper grain */
body::before {
  content: "";
  position: fixed; inset: 0; pointer-events: none; z-index: 50;
  background-image:
    radial-gradient(rgba(23,22,15,0.045) 0.6px, transparent 0.7px),
    radial-gradient(rgba(23,22,15,0.025) 0.6px, transparent 0.7px);
  background-size: 3px 3px, 11px 11px;
  background-position: 0 0, 2px 5px;
}

a { color: inherit; text-decoration: underline; text-decoration-thickness: 0.6px; text-underline-offset: 0.16em; }
a:hover { text-decoration-thickness: 1px; }
a:focus-visible { outline: 1.5px solid var(--ink); outline-offset: 4px; }
::selection { background: rgba(46, 95, 126, 0.18); }

/* ───────────── The wordmark, top left, in the title page's caps ───────────── */
.brand {
  position: fixed; left: var(--book-left); top: 1.5rem; z-index: 40;
  font-size: 0.95rem; line-height: 1; font-weight: 600; text-transform: uppercase; letter-spacing: 0.34em; text-decoration: none; color: var(--ink);
  opacity: 0; transition: opacity 500ms ease;
}
.brand.is-visible { opacity: 1; }

/* ───────────── The rail: the chapters, down the left edge, level with the chapter heading ───────────── */
.rail {
  position: fixed; left: var(--book-left); top: calc(var(--head-h) + 2.2rem + 0.55rem); z-index: 40;
  display: flex; flex-direction: column; gap: 0.1rem;
  font-size: 14px; line-height: 1.45; color: var(--grey);
  opacity: 0; transition: opacity 500ms ease;
}
.rail.is-visible { opacity: 1; }
.rail a { text-decoration: none; display: grid; grid-template-columns: 1.6rem 1fr; column-gap: 0.4rem; align-items: baseline; white-space: nowrap; }
.rail a .r-num { font-variant-numeric: oldstyle-nums tabular-nums; text-align: right; }
.rail a .r-title { font-style: italic; }
.rail a:hover { color: var(--ink); }
.rail a.is-current { color: var(--ink); font-weight: 600; }

/* ───────────── The book ───────────── */
.book { max-width: var(--book-w); margin: 0 auto; }

/* A spread: two pages with a fold between them */
.chapter {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--fold) minmax(0, 1fr);
  padding-top: var(--head-h);
  position: relative;
}

.page { min-width: 0; }
.page-text {
  grid-column: 1;
  display: grid; grid-template-columns: var(--margin) minmax(0, var(--measure));
  padding: 2.2rem 0 4rem 0;
  align-content: start;
}
.page-text > * { grid-column: 2; min-width: 0; }
.page-plate {
  grid-column: 3;
  height: 100%; min-height: 0;
  padding: 2.2rem 0 2rem 0;
  display: flex; flex-direction: column; justify-content: flex-start;   /* the plate's top sits level with the text's */
}
/* A right-hand page of text, on spreads that have no plate */
.page-right { grid-column: 3; }

/* Running text, set like the reference spreads */
.page-text p {
  margin: 0;
  text-align: justify;
  hyphens: auto; -webkit-hyphens: auto;
  text-indent: 1.5em;
  text-wrap: pretty;
}
.page-text p.first, .page-text h3 + p, .page-text figure + p, .chapter-head + p, .page-text aside + p { text-indent: 0; }
.page-text p.first::first-letter {
  float: left; font-style: normal;
  font-size: 3.55em; line-height: 0.8;
  padding: 0.08em 0.1em 0 0;
}
.page-text p em { font-style: italic; }

.cont .page-text { padding-top: 2.6rem; }
.chapter-head {
  grid-column: 1 / 3;
  display: grid; grid-template-columns: var(--margin) 1fr; align-items: baseline;
  margin-bottom: 2.4rem;
}
.ch-num { font-size: 1.1rem; font-style: italic; color: var(--ink-soft); padding-left: 0.1rem; }
.page-text h2 { grid-column: 2; margin: 0; font-size: 2.1rem; font-weight: 400; letter-spacing: -0.005em; line-height: 1.1; }
/* Each project is its own block; as a card it gets a hairline frame and the tag sits inside it. */
.project { margin-top: 2rem; }
.project:first-of-type { margin-top: 1.6rem; }
.project h3 { margin-top: 0; }
.cards .project { position: relative; border: 1px solid var(--rule); border-radius: 3px; padding: 0.65rem 0.9rem 0.65rem; margin-top: 0.6rem; }
.cards .project:first-of-type { margin-top: 0.8rem; }
.cards .project h3 { margin-bottom: 0.6rem; }
.cards .project p:has(> em:first-child) { margin-top: 0.4em; }
/* Each label carries its own drawn mark: a ring for the question, a bead with its tail for what was built, a starburst for what it unlocked. */
.cards .project p[data-mark]::before {
  content: ""; display: inline-block; width: 1.25em; height: 1.25em; margin-right: 0.4em; vertical-align: -0.22em;
  background-position: center; background-repeat: no-repeat; background-size: contain; mix-blend-mode: multiply; opacity: 0.85;
}
.cards .project p[data-mark="question"]::before { background-image: url("img/marks/question.png"); }
.cards .project p[data-mark="built"]::before { background-image: url("img/marks/built.png"); }
.cards .project p[data-mark="unlocked"]::before { background-image: url("img/marks/unlocked.png"); }
.cards .project p { text-align: left; }
/* Project titles are tags: spaced sans capitals in paper on an ink chip. */
.page-text h3 {
  display: inline-block; margin: 2.4rem 0 0.9rem; padding: 0.5em 0.75em 0.42em;
  background: var(--ink); color: var(--paper); border-radius: 2px;
  font-family: var(--sans); font-size: 12.5px; font-weight: 500; line-height: 1; letter-spacing: 0.1em; text-transform: uppercase;
}
/* Paragraphs that open with a label ("The question.", "Show the work.") start flush and carry the label in bold. */
.page-text p:has(> em:first-child) { text-indent: 0; margin-top: 0.55em; }
.page-text h3 + p:has(> em:first-child), .chapter-head + p:has(> em:first-child) { margin-top: 0; }
.page-text p > em:first-child { font-style: normal; font-weight: 600; }
.page-text h3:first-of-type { margin-top: 2.2rem; }

/* Marginalia: notes in the left margin, italic */
.marginalia { grid-column: 1; align-self: start; padding-right: 1.2rem; margin-top: 0.2rem; }
.marginalia p { margin: 0; text-indent: 0; text-align: left; hyphens: manual; font-size: 14.5px; line-height: 1.4; font-style: italic; color: var(--grey); }

/* ───────────── Figures ───────────── */
figure { margin: 0; min-width: 0; }
.plate .frame, .plate svg, .plate .empty-frame { display: block; width: 100%; }
figcaption {
  font-family: var(--sans);
  font-size: 12px; line-height: 1.5; color: var(--grey);
  margin-top: 0.75rem; text-align: left; hyphens: manual; text-indent: 0;
  max-width: 40rem;
}
/* On the plate page the figure takes the top of the page, no taller than about two-thirds of the screen, with its caption directly beneath */
.page-plate figure { display: flex; flex-direction: column; align-items: center; height: auto; max-height: 100%; min-height: 0; }
.page-plate figure svg { flex: 0 1 auto; min-height: 0; width: 100%; height: auto; max-height: min(68svh, 100%); }
.page-plate figure .empty-frame { flex: 0 0 auto; width: auto; height: 68svh; max-width: 100%; }
.page-plate figcaption { flex: 0 0 auto; align-self: stretch; margin-top: 1.1rem; }

/* Insets sit in the text column, small, like the reference spreads */
.inset { margin: 1.6rem 0 1.8rem; max-width: 24rem; }
.inset svg { border: 1px solid var(--rule); }

.empty-frame { border: 1px dashed var(--grey); position: relative; aspect-ratio: 4 / 5; overflow: hidden; cursor: crosshair; }
.empty-label {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  font-family: var(--serif); font-style: italic; font-size: 1.15rem; color: var(--grey);
  transition: opacity 300ms ease;
}

/* ───────────── Title page ───────────── */
.title-page {
  /* The title page is the one dark page: ink ground, paper type, the ocean in light lines. */
  background: var(--ink); color: var(--paper);
  position: relative; height: 100svh;
  width: 100vw; margin-left: calc(50% - 50vw);   /* bleeds past the book's margins to the edges of the screen */
  display: grid; align-content: end;
  padding: 0 0 5rem clamp(1.25rem, 12vw, 16rem);
  overflow: hidden;
}
.ocean { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.half-title { position: relative; max-width: 44rem; padding: 2rem 2.5rem 1.5rem 0; }
.half-title::before {
  /* a wash of paper so the title reads over the tracks */
  content: ""; position: absolute; inset: -4rem -14rem -3rem -10rem; z-index: -1;
  background: radial-gradient(ellipse at 45% 55%, var(--ink) 52%, rgba(23,22,15,0.88) 68%, rgba(23,22,15,0) 92%);
}
/* The title and byline are set as spaced capitals, the way a title page is; the subtitle is the italic line beneath. */
.half-title h1 {
  margin: 0 0 0 0.05em; font-size: clamp(2.4rem, 6vw, 5.4rem); font-weight: 400; line-height: 1;
  text-transform: uppercase; letter-spacing: 0.34em; white-space: nowrap;
}
.half-title .subtitle { margin: 2.2rem 0 0 0.15rem; font-style: italic; color: rgba(247,245,239,0.9); font-size: 1.3rem; }
.edition { font-size: 15px; color: var(--grey); margin: 0.4rem 0 0; }
.colophon p.first::first-letter, .page-text p.first:has(> em:first-child)::first-letter { float: none; font-size: inherit; line-height: inherit; padding: 0; }
.contents {
  margin: 2.2rem 0 0 0.15rem;
  display: flex; flex-direction: column; gap: 0.15rem; align-items: flex-start;
  font-size: 17px; line-height: 1.5; font-style: italic; color: rgba(247,245,239,0.78);
}
.contents a { text-decoration: none; display: grid; grid-template-columns: 1.6rem 1fr; }
.contents a:hover { color: var(--paper); }
.half-title > * { opacity: 0; transform: translateY(6px); }
.half-title.is-in > * { opacity: 1; transform: none; transition: opacity 900ms cubic-bezier(.2,.7,.2,1), transform 900ms cubic-bezier(.2,.7,.2,1); }
.half-title.is-in > :nth-child(2) { transition-delay: 160ms; }
.half-title.is-in > :nth-child(3) { transition-delay: 320ms; }

/* The one character that beats */
.xin { display: inline-block; cursor: default; transition: color 300ms ease; font-family: "Songti SC", "Noto Serif CJK SC", "Noto Serif SC", serif; line-height: 1; }
.xin.is-beating { color: var(--plum); animation: beat 1s ease-in-out infinite; }
@keyframes beat {
  0%, 100% { transform: scale(1); } 12% { transform: scale(1.14); } 24% { transform: scale(1); } 36% { transform: scale(1.09); } 48% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .half-title > * { opacity: 1; transform: none; transition: none; }
  .xin.is-beating { animation: none; }
}

/* ───────────── Wide: one spread per screen, and the scroll snaps to it ───────────── */
@media (min-width: 1101px) {
  html { scroll-snap-type: y mandatory; }
  body { font-size: clamp(14px, 2.05vh, 20px); }
  .spread { scroll-snap-align: start; scroll-snap-stop: always; }
  .chapter { height: 100svh; overflow: hidden; }
  /* If a page runs long for the screen, it scrolls inside its own edges rather than cutting off. */
  .page-text { height: 100%; min-height: 0; overflow: hidden; padding-bottom: 1.25rem; }
  .page-text.is-long { overflow-y: auto; scrollbar-width: none; }
  .cont .page-text { padding-top: 1.3rem; }
  .page-text h3 { margin-top: 1.8rem; }
  .page-text h3:first-of-type { margin-top: 1.5rem; }
  .page-text.is-long::-webkit-scrollbar { display: none; }
  .chapter { margin-left: 10.5rem; }   /* room for the rail; the title page bleeds past it */
  :root { --margin: 2.5rem; }
  .marginalia { grid-column: 2; margin: 0.6rem 0 1rem; padding: 0 0 0 1rem; border-left: 1px solid var(--rule); max-width: 26rem; }
  /* The rail already numbers the chapter; the margin need not say it again. */
  .ch-num { visibility: hidden; }
}

/* ───────────── Narrower: one page at a time ───────────── */
@media (max-width: 1100px) {
  :root { --margin: 5rem; }
  .chapter { grid-template-columns: 1fr; }
  .page-text { grid-column: 1; }
  .page-plate { grid-column: 1; order: -1; position: static; height: auto; padding: 0.5rem 0 3.5rem var(--margin); max-width: 44rem; }
  .page-plate figure { height: auto; }
  .page-text { padding-bottom: 2.5rem; }
  .page-plate figure svg { height: auto; }
  .page-plate figure .empty-frame { width: 100%; height: auto; max-width: 20rem; }
  .page-plate figure svg { max-height: none; }
  .rail, .brand { display: none; }
}
@media (max-width: 640px) {
  :root { --margin: 0rem; --measure: 100%; }
  body { font-size: 18px; }
  .page-text { grid-template-columns: 0 1fr; padding-top: 1.4rem; }
  .page-text p { text-align: left; hyphens: manual; }
  .chapter-head { grid-template-columns: 2.2rem 1fr; }
  .marginalia { grid-column: 2; margin: 0.8rem 0 0.9rem; padding-left: 0.9rem; border-left: 1px solid var(--rule); }
  .page-plate { padding-left: 0; }
  .title-page { padding-bottom: 7rem; }
  .half-title h1 { font-size: 2.05rem; letter-spacing: 0.24em; }
}
