/* 达·芬奇的机械手稿 — the site around the figures: parchment, iron-gall ink, and red chalk kept for
   what can be opened. */
:root {
  --paper: #efe4cc;
  --plate: #f6eedc;
  --ink: #3b2414;
  --ink-soft: #6e5038;
  --faded: #8c6c4c;
  --rule: #cbb68f;
  --chalk: #a8401f;
  --serif-zh: "Noto Serif SC", "Songti SC", "STSong", serif;
  --serif-it: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --gutter: clamp(16px, 4vw, 48px);
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0;
  color: var(--ink);
  font: 17px/1.85 var(--serif-zh);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
img { display: block; max-width: 100%; }

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

/* ── masthead ─────────────────────────────────────────────────────────────────────── */
.masthead {
  max-width: 1240px;
  margin: 0 auto;
  padding: clamp(40px, 8vw, 96px) var(--gutter) 28px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 24px 64px;
  align-items: end;
}

h1 {
  margin: 0;
  white-space: nowrap;
  font-weight: 900;
  font-size: clamp(44px, 6.2vw, 84px);
  line-height: 1;
  letter-spacing: 0.04em;
}

/* Leonardo wrote right to left; the subtitle is in his hand's direction */
.mirror {
  margin: 14px 0 0;
  font: italic 500 clamp(20px, 2.4vw, 30px) / 1 var(--serif-it);
  color: var(--faded);
  transform: scaleX(-1);
  transform-origin: left center;
  width: max-content;
  translate: 100% 0;
  max-width: 100%;
}

.lede {
  margin: 0 0 6px;
  max-width: 24em;
  justify-self: end;
  color: var(--ink-soft);
}

/* ── the loupe ────────────────────────────────────────────────────────────────────── */
.loupe-section {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 var(--gutter) 24px;
}

.loupe {
  background: var(--plate);
  box-shadow: 0 0 0 1px var(--rule);
}

.loupe-svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 72vh;
  cursor: none;
  touch-action: pan-y;
}

.loupe-svg .lens-ground { fill: var(--plate); }
.loupe-svg .loupe-scan { filter: drop-shadow(0 4px 10px #5b433033); }
.loupe-svg .rim-outer { fill: none; stroke: var(--ink); stroke-width: 2.2; }
.loupe-svg .rim-inner { fill: none; stroke: var(--plate); stroke-width: 1.2; }

.loupe-caption {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 24px;
  margin: 12px 0 0;
  font-size: 15px;
  color: var(--faded);
}

.go {
  color: var(--chalk);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

/* ── catalogue ────────────────────────────────────────────────────────────────────── */
.catalogue {
  max-width: 1240px;
  margin: 0 auto;
  padding: clamp(48px, 7vw, 88px) var(--gutter) 24px;
}

.catalogue-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 24px;
  border-bottom: 1px solid var(--ink);
  padding-bottom: 10px;
}

.catalogue-head h2 {
  margin: 0;
  font-size: clamp(28px, 3.4vw, 40px);
  font-weight: 900;
  letter-spacing: 0.06em;
}

.count { margin: 0; color: var(--faded); font-size: 15px; }

.collection {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 24px 48px;
  padding: 36px 0 40px;
  border-bottom: 1px solid var(--rule);
}

.collection-head { min-width: 0; align-self: start; position: sticky; top: 24px; }
.collection-head h3 { margin: 0; font-size: 22px; font-weight: 900; letter-spacing: 0.04em; line-height: 1.4; }
.collection-head .place { margin: 4px 0 0; font-size: 14px; color: var(--ink-soft); }
.collection-head .about { margin: 12px 0 0; font-size: 14px; line-height: 1.75; color: var(--faded); }

/* sheets are mounted at their own proportions in justified rows */
.sheets {
  min-width: 0;
  --row: 230px;
  display: flex;
  flex-wrap: wrap;
  gap: 28px 24px;
  align-items: flex-start;
}

/* every sheet hangs at the same height, as on a gallery wall; wide strips may shrink to fit */
.sheet {
  flex: 0 1 auto;
  width: calc(var(--row) * var(--ar));
  min-width: 150px;
  max-width: 100%;
  text-decoration: none;
  display: block;
}

.sheet figure { margin: 0; }

.plate {
  position: relative;
  aspect-ratio: var(--ar);
  background: var(--plate);
  box-shadow: 0 0 0 1px var(--rule);
  overflow: hidden;
}

.plate img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.plate .scan { object-fit: cover; }

.plate .iso {
  object-fit: contain;
  background: var(--plate);
  opacity: 0;
  transition: opacity 0.5s ease;
}

.sheet figcaption {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 12px;
  padding-top: 10px;
  line-height: 1.5;
}

.sheet .name { font-size: 17px; font-weight: 600; }
.sheet .it { grid-column: 1; font: italic 500 16px/1.4 var(--serif-it); color: var(--ink-soft); }
.sheet .meta { grid-column: 1; font-size: 13px; color: var(--faded); }
.sheet .nb { white-space: nowrap; }
.sheet .go,
.sheet .soon { grid-column: 2; grid-row: 1; font-size: 14px; white-space: nowrap; align-self: baseline; }
.sheet .soon { color: var(--faded); }

.sheet.is-live:hover .iso,
.sheet.is-live:focus-visible .iso { opacity: 1; }
.sheet.is-live:hover .plate,
.sheet.is-live:focus-visible .plate { box-shadow: 0 0 0 1px var(--chalk); }

.sheet.is-soon .plate img { filter: sepia(0.35) contrast(0.85); opacity: 0.62; }
.sheet.is-soon { cursor: default; }

/* ── colophon ─────────────────────────────────────────────────────────────────────── */
.colophon {
  max-width: 1240px;
  margin: 0 auto;
  padding: 32px var(--gutter) 72px;
  font-size: 13px;
  line-height: 1.8;
  color: var(--faded);
}
.colophon p { max-width: 52em; margin: 0; }

/* ── the viewer page ──────────────────────────────────────────────────────────────── */
.viewer-bar {
  max-width: 1000px;
  margin: 0 auto;
  padding: 28px var(--gutter) 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 24px;
  font-size: 15px;
}
.viewer-bar a { color: var(--ink-soft); text-underline-offset: 4px; }
.viewer-bar .here { color: var(--faded); }
.viewer-frame {
  display: block;
  width: 100%;
  max-width: 860px;
  height: 1100px;
  margin: 8px auto 0;
  border: 0;
}
.viewer-nav {
  max-width: 860px;
  margin: 0 auto;
  padding: 8px var(--gutter) 64px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 15px;
}
.viewer-nav a { color: var(--ink-soft); text-underline-offset: 4px; }
.viewer-nav .label { display: block; font-size: 13px; color: var(--faded); }

@media (max-width: 860px) {
  .masthead { grid-template-columns: 1fr; }
  .collection { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .collection-head { position: static; }
  .sheets { --row: 150px; gap: 22px 16px; }
  .sheet { min-width: 0; }
  .sheet figcaption { grid-template-columns: 1fr; }
  .sheet .go,
  .sheet .soon { grid-column: 1; grid-row: auto; margin-top: 2px; justify-self: start; }
  .loupe-svg { cursor: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .plate .iso { transition: none; }
}

/* Language controls use the same ink and parchment as the manuscript catalogue. */
.language-bar { max-width: 1240px; margin: 0 auto; padding: 20px var(--gutter) 0; display: flex; justify-content: flex-end; }
.language-switch { display: inline-flex; gap: 4px; flex-shrink: 0; }
.language-switch button { font-family: inherit; font-size: 14px; line-height: 1.4; padding: 6px 10px; border: 1px solid transparent; border-radius: 3px; background: transparent; color: var(--ink-soft, #6e5038); cursor: pointer; }
.language-switch button[aria-pressed="true"] { border-color: var(--rule, #cbb68f); color: var(--chalk, #a8401f); background: var(--plate, #f6eedc); }
.language-switch button:hover { color: var(--chalk, #a8401f); }
.language-switch button:focus-visible { outline: 2px solid #a8401f; outline-offset: 3px; }
html:lang(en) .home { font-family: "Iowan Old Style", Georgia, serif; }
html:lang(en) .masthead { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
html:lang(en) h1 { font-size: clamp(48px, 6vw, 80px); white-space: normal; letter-spacing: 0; }
html:lang(en) .sheet figcaption { grid-template-columns: 1fr; }
html:lang(en) .sheet .go, html:lang(en) .sheet .soon { grid-column: 1; grid-row: auto; margin-top: 2px; justify-self: start; }
@media (max-width: 860px) {
  html:lang(en) .masthead { grid-template-columns: 1fr; }
  html:lang(en) h1 { font-size: clamp(40px, 12vw, 72px); }
}
