/* ==========================================================================
   Blank Canvas · Versa
   A scroll story in chapters on one continuous light surface. Laptop first
   (1440 x 900); iPhone adaptations live in the max-width: 759px block.
   Chapters with a .stage pin it to the screen while you scroll through
   them; js/main.js turns that scroll position into motion.
   ========================================================================== */

/* ---------- Fonts (self-hosted, SIL Open Font License) -------------------- */

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

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

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

:root {
  --bg: #f4f1ec;            /* warm off-white, the one surface */
  --ink: #2b2a28;           /* soft charcoal, 12.7:1 on --bg */
  --ink-soft: #6e6962;      /* secondary warm grey, 4.8:1 on --bg */
  --line: rgba(43, 42, 40, 0.3);

  --sans: "Jost", "Avenir Next", "Helvetica Neue", Arial, sans-serif;
  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;

  /* Type scale: label, body, heading, statement, display. */
  --size-label: 11.5px;
  --size-body: 19px;
  --size-heading: clamp(36px, 3.7vw, 64px);
  --size-statement: clamp(36px, 4.3vw, 76px);
  --size-display: clamp(110px, 15vw, 260px);
  --tracking: 0.38em;

  --ease: cubic-bezier(0.22, 0.61, 0.22, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --gutter: max(24px, 5vw);

  /* Where the open centre of the logo sculpture is (fraction of the image),
     so the portal zoom passes through it: the point deepest inside the hole. */
  --hole-x: 0.583;
  --hole-y: 0.317;
}

@media (min-width: 1800px) {
  :root {
    --size-label: 12.5px;
    --size-body: 21px;
  }
}

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

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

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

body {
  margin: 0;
  background: var(--bg);
  font-family: var(--serif);
  font-weight: 300;
  font-size: var(--size-body);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

main { position: relative; }

h1, h2, h3, p, dl, dd { margin: 0; font-weight: inherit; }

img {
  display: block;
  max-width: 100%;
  height: auto;
}

picture { display: contents; }

/* Small capitals with wide spacing: names, chapter labels, footer. */
.label {
  font-family: var(--sans);
  font-weight: 400;
  font-size: var(--size-label);
  line-height: 1.4;
  letter-spacing: var(--tracking);
  text-transform: uppercase;
  color: var(--ink-soft);
}

.heading {
  font-size: var(--size-heading);
  line-height: 1.08;
  letter-spacing: -0.012em;
  text-wrap: balance;
}

.display {
  font-size: var(--size-display);
  line-height: 0.88;
  letter-spacing: -0.03em;
}

p { color: var(--ink-soft); text-wrap: pretty; }
.heading, .display, .statement { color: var(--ink); }

/* Each piece sits in a .drift wrapper that the cursor nudges a few pixels. */
.drift { will-change: transform; }

/* A pinned chapter: the section is tall, its stage stays on screen. */
.stage {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;           /* small viewport: no jump when Safari's bar moves */
  overflow: hidden;
}

/* ---------- 1 · Through the mark ------------------------------------------ */

.portal {
  height: 320vh;
  height: 320svh;
}

.portal__macro {
  position: absolute;
  inset: 0;
  opacity: 0;               /* JS fades it in as you pass through the mark */
  will-change: opacity, transform;
}

.portal__macro img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 45%;
}

.portal__mark {
  position: absolute;
  height: 44svh;
  aspect-ratio: 991 / 1150;
  left: 50%;
  top: 50%;
  margin-left: calc(-0.5 * 44svh * 991 / 1150);
  margin-top: -22svh;
  transform-origin: calc(var(--hole-x) * 100%) calc(var(--hole-y) * 100%);
  will-change: transform, opacity;
}

/* The first-load fade sits on the inner wrapper: a CSS animation on the
   outer element would override the opacity JS sets while zooming. */
.portal__mark .drift { animation: arrive 2.4s var(--ease) 0.1s both; }

.portal__mark .drift,
.portal__mark img {
  width: 100%;
  height: 100%;
}

.portal__brand {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(9svh + var(--safe-top));
  text-align: center;
  color: var(--ink);
}

.portal__hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(6svh + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* First-load fades sit on inner elements, so JS can own the outer opacity. */
.portal__brand span { display: inline-block; animation: arrive 1.8s var(--ease) 0.9s both; }
.portal__hint span { animation: arrive 1.8s var(--ease) 1.4s both; }

/* A hairline under "Scroll" that breathes very slowly. */
.portal__hint::after {
  content: "";
  width: 1px;
  height: 34px;
  background: var(--ink);
  transform-origin: top;
  animation: breathe 3.6s var(--ease) infinite;
}

/* Re-centre tracked labels: tracking adds space after the last letter. */
.portal__brand span,
.portal__hint span { padding-left: var(--tracking); }

@keyframes arrive {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes breathe {
  0%, 100% { opacity: 0.25; transform: scaleY(0.55); }
  50%      { opacity: 0.8;  transform: scaleY(1); }
}

/* ---------- 2 · Versa ----------------------------------------------------- */

.intro {
  padding: 14svh var(--gutter) 30svh;
  text-align: center;
}

.intro .display { margin-top: 28px; }

.lede {
  margin-top: 30px;
  font-size: calc(var(--size-body) * 1.15);
}

/* ---------- 3 · Change your position -------------------------------------- */

.turn {
  height: 360vh;
  height: 360svh;
}

.turn .stage {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  align-items: center;
  padding: 0 var(--gutter);
}

.turn__text {
  position: relative;
  max-width: 30rem;
  margin-left: 4vw;
}

.turn__steps {
  position: relative;
  margin-top: 34px;
  min-height: 15em;
}

.turn__step {
  position: absolute;
  inset: 0 0 auto 0;
  opacity: 0;               /* JS shows one step at a time */
  will-change: opacity, transform;
}

.turn__step .heading { margin-bottom: 22px; }

.turn__views {
  position: relative;
  height: 100%;
}

.turn__view {
  position: absolute;
  left: 50%;
  top: 50%;
  opacity: 0;               /* JS cross-fades between the three views */
  will-change: opacity, transform;
}

/* Centred with negative margins, so JS can own `transform`. */
.turn__view[data-view="0"] { height: 58svh; width: calc(58svh * 1103 / 1105); }
.turn__view[data-view="1"] { height: 62svh; width: calc(62svh * 825 / 1189); }
.turn__view[data-view="2"] { height: 66svh; width: calc(66svh * 424 / 1464); }
.turn__view[data-view="0"] { margin: -29svh 0 0 calc(-29svh * 1103 / 1105); }
.turn__view[data-view="1"] { margin: -31svh 0 0 calc(-31svh * 825 / 1189); }
.turn__view[data-view="2"] { margin: -33svh 0 0 calc(-33svh * 424 / 1464); }

.turn__view img { width: 100%; height: 100%; }

/* ---------- 4 · Take a closer look ---------------------------------------- */

.closer {
  padding: 22svh 0 10svh;
}

.closer__head {
  text-align: center;
  padding: 0 var(--gutter);
}

.closer__head .heading { margin-top: 24px; }

.closer__image {
  width: min(84vw, 1300px);
  aspect-ratio: 3 / 2;
  margin: 8svh auto 0;
  /* Feather the edges into the page: no frame, no box. */
  -webkit-mask-image: radial-gradient(ellipse 50% 50% at 50% 50%, #000 62%, transparent 100%);
  mask-image: radial-gradient(ellipse 50% 50% at 50% 50%, #000 62%, transparent 100%);
  will-change: transform;
}

.closer__image img { width: 100%; height: 100%; object-fit: cover; }

.closer__body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8vw;
  max-width: 1040px;
  margin: 6svh auto 0;
  padding: 0 var(--gutter);
}

.specs { display: grid; gap: 22px; }
.specs div { display: grid; gap: 6px; }
.specs dd { color: var(--ink); }

/* ---------- 5 · The mark -------------------------------------------------- */

.mark {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: 4vw;
  padding: 24svh var(--gutter);
  max-width: 1320px;
  margin: 0 auto;
}

.mark__object {
  justify-self: center;
  width: min(30vw, 50vh, 460px);
  aspect-ratio: 991 / 1150;
  will-change: transform;
}

.mark__text { max-width: 26rem; }
.mark__text .heading { margin: 24px 0 22px; }

/* ---------- 6 · The idea -------------------------------------------------- */

.idea {
  height: 240vh;
  height: 240svh;
}

.idea .stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 40px;
  padding: 0 var(--gutter);
  text-align: center;
}

.statement {
  max-width: 17em;
  font-size: var(--size-statement);
  line-height: 1.18;
  letter-spacing: -0.012em;
  text-wrap: balance;
}

/* Words light up one by one (JS sets --o on each). */
.statement .w {
  opacity: var(--o, 0.14);
  transition: opacity 0.35s linear;
}

/* ---------- 7 · On the wall ----------------------------------------------- */

.wall {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16svh var(--gutter) 0;
}

.wall__piece {
  position: relative;
  width: clamp(240px, 24vw, 400px);
  aspect-ratio: 698 / 704;
  will-change: transform;
}

/* The image is larger than the piece: the real wall shadow is baked around
   it. Offsets come from tools/build_images.py. */
.wall__piece img {
  position: absolute;
  max-width: none;
  width: 112.321%;
  left: -6.447%;
  top: -0.568%;
}

.wall__line {
  margin-top: 13svh;
  text-align: center;
}

/* ---------- 8 · Inquiry --------------------------------------------------- */

.inquiry {
  padding: 30svh var(--gutter) 0;
  text-align: center;
}

.inquiry__lead { margin-top: 26px; }
.inquiry p + p { margin-top: 12px; }

.inquiry__email {
  color: var(--ink);
  font-size: calc(var(--size-body) * 1.2);
  white-space: nowrap;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--line);
  text-underline-offset: 0.32em;
  transition:
    text-decoration-color 0.7s var(--ease),
    text-underline-offset 0.7s var(--ease);
}

.inquiry__email:hover {
  text-decoration-color: var(--ink);
  text-underline-offset: 0.2em;
}

.inquiry__email:focus { outline: none; }

.inquiry__email:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 10px;
  text-decoration-color: var(--ink);
}

/* ---------- Footer -------------------------------------------------------- */

.footer {
  padding: 30svh 24px calc(7svh + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.footer__logo { width: 24px; }
.footer__text { font-size: 10px; padding-left: var(--tracking); }

/* ---------- Entrances (only when JS is running) --------------------------- */

/* Text fades and rises a few pixels as it enters, once. */
.js .reveal {
  opacity: 0;
  transform: translate3d(0, 14px, 0);
  transition:
    opacity 1.4s var(--ease),
    transform 1.6s var(--ease);
}

.js .reveal.is-visible {
  opacity: 1;
  transform: none;
}

.js .reveal + .reveal { transition-delay: 0.15s; }
.js .reveal + .reveal + .reveal { transition-delay: 0.3s; }

/* Without JS: pinned chapters show their first state and simply scroll. */
.no-js .portal,
.no-js .turn,
.no-js .idea { height: auto; }
.no-js .stage { position: relative; }
.no-js .portal__macro { display: none; }
.no-js .turn__step[data-step="0"],
.no-js .turn__view[data-view="0"] { opacity: 1; }

/* ---------- iPhone (portrait) --------------------------------------------- */

@media (max-width: 759px) {
  :root {
    --size-label: 10.5px;
    --size-body: 17px;
    --size-heading: 32px;
    --size-statement: 31px;
    --size-display: 31vw;
    --tracking: 0.34em;
    --gutter: 24px;
  }

  .portal__mark {
    height: calc(66vw * 1150 / 991);
    margin-left: -33vw;
    margin-top: calc(-33vw * 1150 / 991);
  }

  .intro { padding: 10svh var(--gutter) 22svh; }

  /* Text on top, the turning piece below. */
  .turn .stage {
    display: flex;
    flex-direction: column;
    padding: calc(11svh + var(--safe-top)) var(--gutter) 0;
  }
  .turn__text { margin: 0; text-align: center; }
  .turn__steps { min-height: 9.5em; margin-top: 22px; }
  .turn__step .heading { margin-bottom: 14px; }
  .turn__views { flex: 1; }
  .turn__view[data-view="0"] { width: 64vw; height: calc(64vw * 1105 / 1103); margin: calc(-32vw * 1105 / 1103) 0 0 -32vw; }
  .turn__view[data-view="1"] { height: 44svh; width: calc(44svh * 825 / 1189); margin: -22svh 0 0 calc(-22svh * 825 / 1189); }
  .turn__view[data-view="2"] { height: 48svh; width: calc(48svh * 424 / 1464); margin: -24svh 0 0 calc(-24svh * 424 / 1464); }

  .closer { padding-top: 16svh; }
  .closer__image { width: 118vw; margin-left: -9vw; }
  .closer__body { grid-template-columns: 1fr; gap: 40px; }

  .mark {
    grid-template-columns: 1fr;
    text-align: center;
    padding: 18svh var(--gutter);
    gap: 9svh;
  }
  .mark__object { width: 64vw; }
  .mark__text { margin: 0 auto; }

  .statement { max-width: 11em; }

  .wall { padding-top: 12svh; }
  .wall__piece { width: 60vw; }

  .inquiry { padding-top: 24svh; }
  .inquiry__email { font-size: 19px; }

  .footer { padding-top: 26svh; }
}

/* ---------- Reduced motion ------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  .portal__hint::after { animation: none; opacity: 0.5; }

  .js .reveal {
    transform: none;
    transition: opacity 1.2s linear;
  }

  .drift,
  .mark__object,
  .wall__piece,
  .closer__image { will-change: auto; }
}
