/* Self-hosted: no request ever leaves this site */
@font-face {
  font-family: "Instrument Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/instrument-sans-400.woff2") format("woff2");
}
@font-face {
  font-family: "Instrument Sans";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/instrument-sans-500.woff2") format("woff2");
}

/* Black and white in both modes, by design */
:root {
  --bg: #000000;
  --ink: #FFFFFF;
  color-scheme: dark;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #000000; --ink: #FFFFFF; }
}
:root[data-theme="dark"] { --bg: #000000; --ink: #FFFFFF; }

*, *::before, *::after { box-sizing: inherit; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.page {
  height: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto 1fr auto;
  padding: clamp(1.25rem, 3vw, 2rem);
}

.small { font-size: .875rem; line-height: 1.4; margin: 0; }
.home {
  color: inherit;
  text-decoration: none;
  font-weight: 500;
  justify-self: start;
}
.home:hover { text-decoration: underline; text-underline-offset: .2em; }

.statement {
  align-self: center;
  grid-column: 1 / -1;
  grid-row: 2;
  margin: 0;
  font-weight: 400;
  font-size: clamp(1.75rem, 4.2vw, 3.75rem);
  line-height: 1.1;
  letter-spacing: -0.025em;
}

footer { grid-column: 1 / -1; grid-row: 3; }
footer a { color: inherit; text-decoration: none; text-underline-offset: .2em; }
footer a:hover, footer a:focus-visible { text-decoration: underline; }

a:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 4px;
  border-radius: 2px;
}

/* ---------- Hanzo: five letters that can leave the word ---------- */
.hanzo { color: inherit; text-decoration: none; white-space: nowrap; }
.hanzo .l {
  display: inline-block;
  position: relative;
  z-index: 2;                      /* above the image */
  color: var(--ink);
  will-change: transform;
  text-decoration: underline;
  text-decoration-thickness: .06em;
  text-underline-offset: .15em;
  text-decoration-color: currentColor;
  transition: text-decoration-color .25s ease .4s;
}
/* The underline belongs to the word, so it goes when the letters do */
.hanzo.open .l { text-decoration-color: transparent; transition-delay: 0s; }

/* ---------- Image ---------- */
/* Laid out once at its final size; only revealed with a clip and a transform, so nothing re-flows while it moves */
.frame {
  position: fixed;
  left: 0; top: 0;
  z-index: 1;
  pointer-events: none;
  visibility: hidden;
  clip-path: inset(50%);
  will-change: transform;
}
.frame img { display: block; width: 100%; height: 100%; object-fit: cover; will-change: transform; }

/* ---------- Illustration gallery ---------- */
/* The top-right corner never moves: "Contact" on the homepage and the illustration index,
   "Close" while an illustration is open. The gallery starts below it, so tiles never slide underneath. */
.corner { grid-column: 2; grid-row: 1; justify-self: end; display: grid; position: relative; z-index: 20; color: var(--vink, var(--ink)); transition: color .3s ease; }
.home { position: relative; z-index: 20; color: var(--vink, var(--ink)); transition: color .3s ease; }
.nav, .count { transition: color .3s ease; }
.corner > * { grid-area: 1 / 1; justify-self: end; }
.contact { color: inherit; font-weight: 500; text-decoration: none; white-space: nowrap; transition: opacity .3s ease, visibility 0s linear 0s; }
.contact:hover, .contact:focus-visible { text-decoration: underline; text-underline-offset: .2em; }
.topclose {
  padding: 0; margin: 0; border: 0; background: none;
  color: inherit; font: inherit; font-weight: 500;
  cursor: pointer;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .3s ease, visibility 0s linear .3s;
}
.topclose:hover, .topclose:focus-visible { text-decoration: underline; text-underline-offset: .2em; }
.view-viewer .contact { opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .25s ease, visibility 0s linear .25s; }
.view-viewer .topclose { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity .4s ease .3s, visibility 0s; }

.gallery {
  --gap: 12px;
  position: fixed;
  inset: calc(4.25rem + env(safe-area-inset-top, 0px)) 0 0 0;   /* starts below the two words */
  z-index: 10;
  visibility: hidden;
  overflow-x: hidden;
  overflow-y: hidden;               /* locked while tiles are moving, so transforms can't add scroll height */
  scrollbar-width: none;            /* hidden, so the right margin lines up with Contact exactly */
  overscroll-behavior: contain;
  padding: 0 clamp(1.25rem, 3vw, 2rem) calc(var(--gap) + env(safe-area-inset-bottom, 0px));   /* same side margins as the two words */
  outline: none;
}
.gallery.on { visibility: visible; }
.gallery.ready { overflow-y: auto; }
.gallery::-webkit-scrollbar { display: none; }
.grid {
  display: grid;
  grid-template-columns: repeat(var(--n, 3), minmax(0, 1fr));
  gap: var(--gap);
  align-items: start;
}
.col { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
.tile { margin: 0; will-change: transform; cursor: pointer; }
.tile:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
.tile img { display: block; width: 100%; height: auto; opacity: 0; transition: opacity .6s ease; }
.tile img.loaded { opacity: 1; }
@media (max-width: 559px) { .gallery { --gap: 8px; } }

/* ---------- Illustration viewer ---------- */
.viewer {
  --pad: clamp(1.25rem, 3vw, 2rem);
  position: fixed;
  inset: calc(4.25rem + env(safe-area-inset-top, 0px)) 0 0 0;   /* below the two words, like the gallery */
  z-index: 12;
  display: none;
  outline: none;
  touch-action: pan-y;
  color: var(--vink, var(--ink));   /* arrows and counter follow the colour behind them */
  transition: color .6s ease;
}
.viewer.on { display: block; }
/* The full-screen colour behind an illustration. When you move to the next one, a second layer sweeps across. */
.vfill, .vwipe { position: fixed; inset: 0; z-index: 11; pointer-events: none; }
.vfill { background: var(--bg); opacity: 0; }
.vwipe { clip-path: inset(0 0 0 100%); }
/* The box the illustration is fitted into: clear of the arrows and the bottom bar */
.stage {
  position: absolute;
  left: calc(var(--pad) + 72px);
  right: calc(var(--pad) + 72px);
  top: 0;
  bottom: 56px;
  pointer-events: none;
}
.slide {
  position: fixed;
  left: 0; top: 0;
  z-index: 2;
  display: block;
  cursor: pointer;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform, opacity;
}
.nav {
  position: absolute;
  z-index: 3;
  top: calc((100% - 56px) / 2);
  transform: translateY(-50%);
  width: 48px; height: 48px;
  display: grid; place-items: center;
  padding: 0; border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  opacity: 0;
}
.prev { left: var(--pad); }
.next { right: var(--pad); }
.nav svg { transition: transform .35s cubic-bezier(.16, 1, .3, 1); }
.prev:hover svg, .prev:focus-visible svg { transform: translateX(-5px); }
.next:hover svg, .next:focus-visible svg { transform: translateX(5px); }
.vbar {
  position: absolute;
  z-index: 3;
  left: 0; right: 0; bottom: 0;
  height: 56px;
  padding: 0 var(--pad);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  pointer-events: none;
  opacity: 0;
}
@media (max-width: 699px) {
  .stage { left: var(--pad); right: var(--pad); }
  .nav { background: rgba(0, 0, 0, .55); color: #fff; border-radius: 50%; }   /* arrows sit over the illustration on a phone */
}

/* While the letters are away, the rest of the sentence steps back */
.statement .lead { transition: opacity .6s ease; }
.statement.dim .lead { opacity: .2; }

/* ---------- Entrance ---------- */
/* Each word of the sentence sits in a mask and rises into view from below it */
.w {
  display: inline-block;
  overflow: hidden;
  vertical-align: top;
  padding: .12em 0 .2em;           /* room for ascenders and descenders inside the mask... */
  margin: -.12em 0 -.2em;          /* ...without changing the line's height */
}
.wi { display: inline-block; transform-origin: 0 100%; }
.intro .wi { transform: translateY(115%) rotate(4deg); }
.intro .reveal { opacity: 0; }
/* Once it has landed the masks open up, so the Hanzo letters can fly out of the sentence */
.intro-done .w { overflow: visible; }
