/* The writing pages, set as research papers on a Swiss grid.
 * Shared parts are in components.css; every value comes from tokens.css.
 *
 * The apparatus (titles, labels, section, figure and equation numbers, notes, tables, the
 * register) is set in the grotesk; titles and the reading are set in the serif.
 *
 * Grid: twelve columns, everything from one left edge. The abstract and the text run 1-7;
 * notes sit in 10-12; figures and tables run 1-9 with their captions beneath; the plate runs
 * the full width. Below 1100px it all falls into one column. */

:root {
  --ui: var(--sans);
  --gap: clamp(1rem, 1.8vw, 1.75rem);
  --read: clamp(1.1rem, 0.5vw + 0.95rem, 1.22rem);
}
:root:lang(zh) { --ui: var(--sans-zh); }
:root:lang(ar) { --ui: var(--sans-ar); }

.site {
  max-width: 92rem;
  margin-inline: auto;
  padding: max(var(--space-5), env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right)) clamp(var(--space-8), 10vw, 9rem) max(var(--gutter), env(safe-area-inset-left));
  display: grid;
  gap: clamp(var(--space-7), 7vw, 7rem);
}
main { min-width: 0; }

/* Paint in the bottom corners of the screen, behind the paper (edge.js). The words sit above it,
 * and the grain lies over both. */
.edge-paint { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.site { position: relative; z-index: 1; }
.grain { z-index: 2; }
/* On a phone the paint gathers in a band across the foot of the paper; leave it room under the last words. */
@media (max-width: 700px) { .site:has(.paper) { padding-bottom: 40vh; } }

.label {
  font-family: var(--ui);
  font-weight: 400;
  font-size: 0.7rem;
  line-height: 1.3;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--quiet);
}
:root:lang(zh) .label, :root:lang(ar) .label { text-transform: none; letter-spacing: 0; font-size: 0.78rem; }

/* The painting's detail: it lays itself in from the left (writing.js adds .is-painted). */
.plate-paint {
  width: 100%;
  height: 100%;
  background: url("/assets/images/signorini-settignano.jpg") var(--plate-x) var(--plate-y) / var(--plate-zoom) auto no-repeat;
  -webkit-mask-image: linear-gradient(100deg, #000 42%, transparent 58%);
  mask-image: linear-gradient(100deg, #000 42%, transparent 58%);
  -webkit-mask-size: 260% 100%;
  mask-size: 260% 100%;
  -webkit-mask-position: 0 0;
  mask-position: 0 0;
}
.js .plate-paint { -webkit-mask-position: 100% 0; mask-position: 100% 0; }
.js .is-painted .plate-paint {
  -webkit-mask-position: 0 0;
  mask-position: 0 0;
  transition: -webkit-mask-position 1.6s var(--ease-out), mask-position 1.6s var(--ease-out);
}

/* ---------- the register: every paper, a number and a title ---------- */
/* Set like the home page: titles in the serif, in one narrow column, every rule equally faint. */
.entries { list-style: none; border-top: var(--hairline) solid var(--rule); max-width: 44rem; }
.entry { border-bottom: var(--hairline) solid var(--rule); }
.entry a {
  display: grid;
  grid-template-columns: 3rem minmax(0, max-content) auto;
  grid-template-areas: "n title sprig";
  gap: var(--space-4);
  align-items: baseline;
  padding-block: var(--space-5);
  text-decoration: none;
}
.e-n { grid-area: n; font-family: var(--ui); font-size: 0.78rem; font-variant-numeric: tabular-nums; color: var(--quiet); transition: color var(--duration-slow) var(--ease); }
.e-title {
  grid-area: title;
  font-weight: 400;
  font-size: clamp(1.4rem, 1.7vw, 1.75rem);
  line-height: 1.2;
  text-wrap: balance;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-decoration-thickness: var(--hairline);
  text-underline-offset: 0.18em;
  transition: text-decoration-color var(--duration-slow) var(--ease);
}
.entry a:hover .e-title, .entry a:focus-visible .e-title { text-decoration-color: currentColor; }
:root:lang(zh) .e-title, :root:lang(ar) .e-title { line-height: 1.3; }
.entry a:hover .e-n, .entry a:focus-visible .e-n { color: var(--ink); }
.entry a:focus-visible { outline: none; }

/* The olive sprig beside a title draws itself, stem then leaf then olive, while the title is pointed at. */
.sprig { grid-area: sprig; width: 2.4rem; height: auto; align-self: center; fill: none; stroke: currentColor; stroke-width: 1.1; stroke-linecap: round; overflow: visible; }
/* An undrawn line still shows its round end as a dot, so a drawing stays invisible until it starts. */
.sprig { opacity: 0; transition: opacity 0.2s var(--ease) 0.3s; }
.entry a:hover .sprig, .entry a:focus-visible .sprig { opacity: 1; transition: none; }
.sprig > * { stroke-dasharray: 1; stroke-dashoffset: 1; transition: stroke-dashoffset 0.35s var(--ease); }
.entry a:hover .sprig > *, .entry a:focus-visible .sprig > * { stroke-dashoffset: 0; transition: stroke-dashoffset 0.7s var(--ease-out); }
.entry a:hover .sprig > :nth-child(2), .entry a:focus-visible .sprig > :nth-child(2) { transition-delay: 0.25s; }
.entry a:hover .sprig > :nth-child(3), .entry a:focus-visible .sprig > :nth-child(3) { transition-delay: 0.45s; }
.entry a:hover .sprig > :nth-child(4), .entry a:focus-visible .sprig > :nth-child(4) { transition-delay: 0.6s; }
@media (hover: none) { .sprig { opacity: 1; } .sprig > * { stroke-dashoffset: 0; } }
.empty { color: var(--quiet); font-family: var(--ui); }

/* ---------- a paper ---------- */
.paper { display: grid; gap: clamp(var(--space-6), 5vw, 4.5rem); }
.untranslated { font-family: var(--ui); font-size: 0.8rem; color: var(--quiet); padding: var(--space-3) var(--space-4); background: var(--tint); }
.paper-head { display: grid; }
/* Who wrote it and when sits close under the title; the abstract stands further off. */
.byline { margin-top: var(--space-4); display: flex; gap: var(--space-4); font-family: var(--ui); font-size: 0.82rem; line-height: 1.4; color: var(--quiet); font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
:root:lang(ar) .byline { justify-content: flex-end; }
/* The title is set in the serif, like the home page's headline and the register. */
.paper-head h1 {
  font-weight: 400;
  font-size: clamp(2.2rem, 4.4vw, 3.9rem);
  line-height: 1.08;
  letter-spacing: -0.012em;
  text-wrap: balance;
  max-width: 16em;
}
:root:lang(zh) .paper-head h1, :root:lang(ar) .paper-head h1 { line-height: 1.3; letter-spacing: 0; }
.abstract { display: grid; gap: var(--space-2); margin-top: clamp(var(--space-6), 4vw, 3.5rem); }
.abstract p { font-size: var(--read); line-height: 1.55; color: var(--muted); text-wrap: pretty; }

.plate { display: grid; gap: var(--space-3); }
.plate .plate-paint { aspect-ratio: 16 / 7; height: auto; }
@media (max-width: 700px) { .plate .plate-paint { aspect-ratio: 4 / 3; } }
figcaption { font-family: var(--ui); font-size: 0.75rem; line-height: 1.45; color: var(--quiet); }
.fig-n { display: block; color: var(--ink); text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.68rem; margin-bottom: 0.2rem; }
:root:lang(zh) .fig-n, :root:lang(ar) .fig-n { text-transform: none; letter-spacing: 0; font-size: 0.75rem; }

/* The text. */
.prose { display: grid; row-gap: 1.05em; font-size: var(--read); line-height: 1.62; }
.prose > * { min-width: 0; }
.prose p, .prose li { text-wrap: pretty; hanging-punctuation: first; }
.prose .sec { font-family: var(--ui); font-weight: 400; font-size: 1.28rem; line-height: 1.2; margin-top: 1.5em; }
.prose h3.sec { font-size: 1.05rem; margin-top: 0.9em; }
.prose ul, .prose ol { padding-inline-start: 1.3em; display: grid; gap: 0.35em; }
.prose li::marker { color: var(--quiet); }
.prose strong { font-weight: 600; }
.prose .pull { font-family: var(--ui); font-weight: var(--light); font-size: clamp(1.6rem, 2.6vw, 2.3rem); line-height: 1.15; letter-spacing: -0.01em; text-wrap: balance; margin-block: 0.5em; }
.prose .callout { font-family: var(--ui); font-size: 0.86rem; line-height: 1.5; color: var(--muted); padding-inline-start: 0.6rem; border-inline-start: var(--hairline) solid var(--ink); }
.prose .callout strong { font-weight: 500; color: var(--ink); }
.prose code { font-family: var(--mono); font-size: 0.82em; }
.prose :not(pre) > code { background: var(--tint); padding: 0.05em 0.28em; }
.prose .code { overflow-x: auto; padding: var(--space-4); background: var(--tint); line-height: 1.55; font-size: 0.86rem; }
.prose .code code { background: none; padding: 0; }

/* An equation, numbered at the right like a paper's. */
.prose .eq { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-4); padding-block: 0.4em; font-family: var(--serif); font-style: italic; font-size: 1.15em; }
.prose .eq-n { font-family: var(--ui); font-style: normal; font-size: 0.75rem; color: var(--quiet); font-variant-numeric: tabular-nums; }

.prose .figure { display: grid; gap: var(--space-3); margin-block: 0.6em; }
.prose .figure img { display: block; width: 100%; height: auto; }

/* Diagrams: line drawings that take the page's ink and draw themselves once on screen (writing.js adds .is-drawn). */
.diagram-frame { overflow-x: auto; overflow-y: hidden; }
.diagram svg { display: block; width: 100%; min-width: 34rem; height: auto; overflow: hidden; color: var(--ink); }
/* Widths are in drawing units, never non-scaling: Chrome measures dashes in screen pixels when strokes don't scale,
 * which breaks the drawing animation. */
.diagram svg .ln { fill: none; stroke: currentColor; stroke-width: 0.9; stroke-linecap: round; stroke-linejoin: round; }
.diagram svg .fine { stroke-width: 0.55; }
.diagram svg .lead { fill: none; stroke: currentColor; stroke-width: 0.45; opacity: 0.55; }
.diagram svg .axis { fill: none; stroke: currentColor; stroke-width: 0.45; stroke-dasharray: 2 4; opacity: 0.45; }
.diagram svg .tone { fill: currentColor; opacity: 0.06; stroke: none; }
.diagram svg .dot { fill: currentColor; stroke: none; }
.diagram svg text { font-family: var(--ui); font-size: 10.5px; fill: currentColor; letter-spacing: 0.02em; }
.diagram svg text.n { font-variant-numeric: tabular-nums; }
.diagram svg text.q { opacity: 0.7; }
.js .diagram:not(.is-drawn) svg, .js .break:not(.is-drawn) svg { opacity: 0; }
.js .diagram:not(.is-drawn) .ln, .js .diagram:not(.is-drawn) .lead { stroke-dasharray: 1; stroke-dashoffset: 1; }
.js .diagram.is-drawn .ln, .js .diagram.is-drawn .lead { stroke-dasharray: 1; stroke-dashoffset: 0; transition: stroke-dashoffset 2.2s var(--ease-out); }
.js .diagram.is-drawn .lead { transition-delay: 0.9s; }
.js .diagram.is-done .ln, .js .diagram.is-done .lead { stroke-dasharray: none; }
.js .diagram:not(.is-drawn) text, .js .diagram:not(.is-drawn) .tone, .js .diagram:not(.is-drawn) .dot { opacity: 0; }
.js .diagram.is-drawn text, .js .diagram.is-drawn .dot { transition: opacity 0.8s var(--ease) 1.4s; }
.js .diagram.is-drawn .tone { transition: opacity 0.8s var(--ease) 1.1s; }

.prose .table { overflow-x: auto; margin-block: 0.3em; }
.prose .table table { border-collapse: collapse; width: 100%; font-family: var(--ui); font-size: 0.86rem; line-height: 1.4; font-variant-numeric: tabular-nums; border-top: var(--hairline) solid var(--ink); }
.prose .table th, .prose .table td { text-align: start; padding: 0.5em 1em 0.5em 0; border-bottom: var(--hairline) solid var(--rule); vertical-align: top; }
.prose .table th { font-weight: 400; color: var(--quiet); font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase; }

/* A section break: one olive leaf, drawn as the reader reaches it. */
.break { display: flex; padding-block: 0.8em; color: var(--quiet); }
.break svg { width: 2.6rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 1.1; stroke-linecap: round; overflow: visible; }
.break svg > * { stroke-dasharray: 1; stroke-dashoffset: 0; }
.js .break:not(.is-drawn) svg > * { stroke-dashoffset: 1; }
.js .break.is-drawn svg > * { transition: stroke-dashoffset 1.4s var(--ease-out); }
.js .break.is-drawn svg > :nth-child(2) { transition-delay: 0.5s; }

/* Notes: a number in the text; the note itself in the margin, or at the end on narrow screens. */
.note-ref { font-family: var(--ui); font-size: 0.66em; line-height: 0; margin-inline-start: 0.08em; }
.note-ref a { text-decoration: none; color: var(--quiet); padding: 0 0.15em; }
.note-ref a:hover, .note-ref a:focus-visible { color: var(--ink); outline: none; }
.sidenote { display: none; }
.paper-end { display: grid; gap: var(--space-6); }
.endnotes { display: grid; gap: var(--space-3); padding-top: var(--space-4); border-top: var(--hairline) solid var(--ink); }
.endnotes ol { padding-inline-start: 1.4em; display: grid; gap: var(--space-2); font-family: var(--ui); font-size: 0.82rem; line-height: 1.5; color: var(--muted); }
.endnotes li::marker { color: var(--quiet); font-variant-numeric: tabular-nums; }
.endnotes .back { color: var(--quiet); margin-inline-start: 0.3em; }

:root:lang(zh) .prose { line-height: 1.85; }
:root:lang(ar) .prose { line-height: 1.95; }

/* ---------- the twelve-column grid, where there is room for it ---------- */
@media (min-width: 1100px) {
  .register-page, .paper, .paper-head, .prose, .paper-end, .plate {
    grid-template-columns: repeat(12, minmax(0, 1fr));
    column-gap: var(--gap);
  }
  .paper { container-type: inline-size; --col: calc((100cqw - 11 * var(--gap)) / 12); }
  .register-page > *, .paper > * { grid-column: 1 / -1; }
  .paper-head, .prose, .paper-end, .plate { display: grid; grid-template-columns: subgrid; }


  .paper-head h1 { grid-column: 1 / 11; }
  .abstract, .byline { grid-column: 1 / 8; }

  .plate .plate-paint { grid-column: 1 / 13; }
  .plate figcaption { grid-column: 1 / 8; }

  .prose > * { grid-column: 1 / 8; }
  /* Figures, diagrams, tables and quotes stay inside the text column: one container, one edge on each side. */

  .sidenote {
    display: block;
    float: inline-end;
    clear: inline-end;
    width: calc(3 * var(--col) + 2 * var(--gap));
    margin-inline-end: calc(-1 * (5 * var(--col) + 5 * var(--gap)));
    margin-block: 0.25em var(--space-4);
    font-family: var(--ui);
    font-size: 0.74rem;
    line-height: 1.45;
    color: var(--quiet);
    text-wrap: pretty;
  }
  .sidenote-n { font-variant-numeric: tabular-nums; color: var(--ink); margin-inline-end: 0.5em; }
  /* Clicking a note's number in the text lights the note up in the margin for a moment. */
  .sidenote.is-lit { animation: note-lit 2.4s var(--ease-out); }
  @keyframes note-lit { 0%, 35% { color: var(--ink); } 100% { color: var(--quiet); } }
  .endnotes { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .paper-end > * { grid-column: 1 / 8; }
}

@media (prefers-reduced-motion: reduce) {
  .js .plate-paint, .js .is-painted .plate-paint { -webkit-mask-image: none; mask-image: none; transition: none; }
  .js .break:not(.is-drawn) svg > *, .js .break.is-drawn svg > * { stroke-dashoffset: 0; transition: none; }
  .js .diagram:not(.is-drawn) svg, .js .break:not(.is-drawn) svg { opacity: 1; }
  .sprig { opacity: 1; }
  .js .diagram:not(.is-drawn) .ln, .js .diagram:not(.is-drawn) .lead { stroke-dashoffset: 0; }
  .js .diagram:not(.is-drawn) text, .js .diagram:not(.is-drawn) .tone, .js .diagram:not(.is-drawn) .dot { opacity: 1; }
  .diagram *, .sprig > *, .e-n { transition: none !important; }
}
@media print {
  @page { size: A4; margin: 18mm 16mm; }
  .top, .grain, .edge-paint { display: none; }
  .plate-paint { -webkit-mask-image: none; mask-image: none; }
  .sidenote { display: none; }
  .endnotes { position: static !important; width: auto; height: auto; clip-path: none; }
}
