/* =========================================================================
   Rajesh Dora — Photographs
   Every film on one white sheet, grouped in six parts. A film lifts off the
   sheet into a single-photo reader; the next one develops in, the way a
   print comes up in the tray; closing drops it back into its place.
   White and charcoal, small type, a lot of air. The photographs carry the
   colour; nothing else on the page does.
   ========================================================================= */

/* ---------- Faces ----------------------------------------------------- */
/* Self-hosted, SIL Open Font Licence — see fonts/*-LICENSE.txt */

@font-face {
  font-family: "Archivo";
  src: url("../fonts/archivo-300.woff2") format("woff2");
  font-weight: 300; font-style: normal; font-display: swap;
}

@font-face {
  font-family: "Archivo";
  src: url("../fonts/archivo-400.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}

@font-face {
  font-family: "Archivo";
  src: url("../fonts/archivo-500.woff2") format("woff2");
  font-weight: 500; font-style: normal; font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("../fonts/ibm-plex-mono-400.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}

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

:root {
  --sheet:    #fbfbfa;
  --charcoal: #2a2a28;
  --graphite: #63635f;
  --hair:     rgba(42, 42, 40, 0.12);
  --tray:     #ececea;

  --sans: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --gutter: clamp(1rem, 0.55rem + 2.2vw, 3rem);
  --thumb:  clamp(5.25rem, 4.1rem + 3.2vw, 8.5rem);

  --ease:      cubic-bezier(0.22, 0.61, 0.24, 1);
  --ease-lift: cubic-bezier(0.65, 0, 0.25, 1);

  color-scheme: light;
}

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

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

[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  background: var(--sheet);
}

body {
  margin: 0;
  padding-inline: var(--gutter);
  background: var(--sheet);
  color: var(--charcoal);
  font: 400 0.9375rem/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.is-reading { overflow: hidden; }

main { overflow-x: clip; }

h1, h2, p, ol { margin: 0; }
ol { padding: 0; list-style: none; }
img, video { display: block; }

a { color: inherit; text-decoration: none; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

:focus-visible { outline: 1px solid var(--charcoal); outline-offset: 4px; }

::selection { background: var(--charcoal); color: var(--sheet); }

.label {
  font: 400 0.65625rem/1.4 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.skip-link {
  position: absolute;
  top: 0.75rem; left: var(--gutter);
  z-index: 30;
  padding: 0.5rem 0.75rem;
  background: var(--charcoal);
  color: var(--sheet);
  transform: translateY(-200%);
}

.skip-link:focus-visible { transform: none; }

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

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding-top: calc(env(safe-area-inset-top, 0px) + 1.4rem);
}

.masthead__name { font-weight: 500; letter-spacing: -0.01em; }
.masthead__name:hover { color: var(--graphite); }
.masthead__meta { color: var(--graphite); }

/* ---------- Opening --------------------------------------------------- */

.opening {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--gutter);
  padding-block: clamp(6rem, 16vh, 11rem) clamp(4.5rem, 12vh, 8.75rem);
}

.opening__inner { grid-column: 4 / 11; }

.opening .label {
  margin-bottom: 1.4rem;
  color: var(--graphite);
}

.opening h1 {
  max-width: 24em;
  font-weight: 300;
  font-size: clamp(1.625rem, 1.1rem + 1.7vw, 2.5rem);
  line-height: 1.25;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

/* ---------- Parts ----------------------------------------------------- */

.part {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--gutter);
  padding-block: 2.75rem 4rem;
  border-top: 1px solid var(--hair);
}

.part__head {
  grid-column: 1 / 4;
  padding-top: 0.25rem;
}

.part__num {
  display: block;
  margin-bottom: 0.875rem;
  color: var(--graphite);
}

.part__title {
  font-weight: 400;
  font-size: 1.375rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.part__note {
  max-width: 19em;
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: var(--graphite);
}

.films {
  grid-column: 4 / 13;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 2.5rem clamp(0.875rem, 0.5rem + 1vw, 1.625rem);
}

.film { position: relative; }

.film__link { display: block; }

.film__link img {
  width: auto;
  height: var(--thumb);
  max-width: 100%;
  background: var(--tray);
  transition: opacity 0.5s var(--ease), filter 0.5s var(--ease), transform 0.6s var(--ease);
}

.film__no {
  display: block;
  margin-top: 0.55rem;
  color: var(--graphite);
  font-variant-numeric: tabular-nums;
}

.film__motion {
  position: absolute;
  top: 0.375rem; left: 0.375rem;
  padding: 0.125rem 0.3rem;
  background: var(--sheet);
  pointer-events: none;
}

.film__title {
  display: none;
  position: absolute;
  top: calc(100% + 1.6rem); left: 0;
  z-index: 2;
  font-size: 0.8125rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.35s var(--ease), transform 0.35s var(--ease);
}

/* A title that would run off the right edge sits under the film's right side */
.film--flip .film__title { left: auto; right: 0; }

/* Pointing at one film quiets the others */
@media (hover: hover) {
  .film__title { display: block; }

  .films:has(.film:hover) .film:not(:hover) img { opacity: 0.42; filter: grayscale(0.7); }
  .film:hover img { transform: translateY(-3px); }
  .film:hover .film__title,
  .film__link:focus-visible ~ .film__title { opacity: 1; transform: none; }
}

/* Arrival: films land on the sheet one after another */
@media (prefers-reduced-motion: no-preference) {
  .film {
    animation: land 0.9s var(--ease) both;
    animation-delay: calc(min(var(--i), 24) * 30ms + 150ms);
  }

  @keyframes land { from { opacity: 0; transform: translateY(10px); } }
}

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

.colophon {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem 2rem;
  padding-block: 2.25rem calc(env(safe-area-inset-bottom, 0px) + 2.5rem);
  border-top: 1px solid var(--hair);
  color: var(--graphite);
}

.colophon__links { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; }
.colophon__links a { color: var(--charcoal); }
.colophon__links a:hover { color: var(--graphite); }

/* ---------- Reader ---------------------------------------------------- */

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

.reader__veil {
  position: absolute;
  inset: 0;
  background: var(--sheet);
  opacity: 0;
  transition: opacity 0.55s var(--ease);
}

.reader.is-open .reader__veil { opacity: 1; }

.reader__ui {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.45s var(--ease);
}

.reader.is-shown .reader__ui { opacity: 1; }

.reader__top,
.reader__foot {
  position: absolute;
  left: var(--gutter);
  right: var(--gutter);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.reader__top {
  top: calc(env(safe-area-inset-top, 0px) + 1.4rem);
  align-items: baseline;
}

.reader__foot {
  bottom: calc(env(safe-area-inset-bottom, 0px) + 1.6rem);
  align-items: flex-end;
}

.reader__back,
.reader__nav button { color: var(--graphite); }

.reader__back:hover,
.reader__nav button:hover { color: var(--charcoal); }

.reader__count { color: var(--graphite); font-variant-numeric: tabular-nums; }

.reader__cap { display: grid; gap: 0.25rem; min-width: 0; }
.reader__cap > * { transition: opacity 0.5s var(--ease), transform 0.5s var(--ease); }
.reader__cap.is-swapping > * { opacity: 0; transform: translateY(6px); }

.reader__part,
.reader__place { color: var(--graphite); }

.reader__title {
  font-size: clamp(1.0625rem, 1rem + 0.35vw, 1.3125rem);
  letter-spacing: -0.01em;
}

/* Crossing into a new part: its name opens out, then settles */
.reader__part.is-new { animation: part-in 1.4s var(--ease); }

@keyframes part-in {
  from { color: var(--charcoal); letter-spacing: 0.3em; }
  to   { letter-spacing: 0.14em; }
}

.reader__nav { display: flex; gap: 1.6rem; }

.reader__zone {
  position: absolute;
  top: 4.5rem;
  bottom: 7rem;
  width: 50%;
}

.reader__zone--prev { left: 0;  cursor: w-resize; }
.reader__zone--next { right: 0; cursor: e-resize; }

.reader__media {
  position: fixed;
  top: 0; left: 0;
  margin: 0;
  background: var(--tray) center / cover no-repeat;
  transform-origin: 0 0;
  will-change: transform, opacity, filter;
}

/* The develop: from pale and flat to full depth, like a print in the tray */
.reader__media.is-developing { animation: develop 1.6s var(--ease) both; }

@keyframes develop {
  0%   { opacity: 0; filter: brightness(2) contrast(0.35) saturate(0); }
  30%  { opacity: 1; }
  100% { opacity: 1; filter: none; }
}

.reader__media.is-leaving {
  opacity: 0;
  transition: opacity 0.35s var(--ease), transform 0.5s var(--ease);
}

/* ---------- Phone ----------------------------------------------------- */

@media (max-width: 760px) {
  .opening__inner { grid-column: 1 / -1; }

  .part { display: block; padding-block: 2rem 3rem; }
  .part__head { margin-bottom: 1.6rem; }

  .films { gap: 1.9rem 0.75rem; }

  .reader__nav,
  .reader__zone { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .film__link img,
  .reader__veil,
  .reader__ui,
  .reader__cap > * { transition: none; }

  .reader__media.is-developing,
  .reader__part.is-new { animation: none; }
}
