:root {
  --serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --ink: #111;
  --paper: #fdfdfc;
  --radius: clamp(8px, 1vw, 14px);
}

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

html,
body {
  margin: 0;
  min-height: 100%;
}

html {
  background: var(--paper);
  -webkit-tap-highlight-color: transparent; /* no grey box flashing over whatever is tapped on phones */
}

/* pixel-art cursors, with 2x files for retina */
html {
  cursor: url("../assets/cursor/arrow.png") 0 0, auto;
  cursor: -webkit-image-set(url("../assets/cursor/arrow.png") 1x, url("../assets/cursor/arrow@2x.png") 2x) 0 0, auto;
}

a,
button,
.deck-open .stage :is(.card:not(.is-center), [data-video]),
.player-video {
  cursor: url("../assets/cursor/hand.png") 10 0, pointer;
  cursor: -webkit-image-set(url("../assets/cursor/hand.png") 1x, url("../assets/cursor/hand@2x.png") 2x) 10 0, pointer;
}

body {
  font-family: var(--serif);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

/* ---------- homepage ---------- */

.home {
  min-height: 100svh;
  overflow: hidden;
}

/* centred here rather than on <body>, which browser extensions inject into */
.frame {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(1.1rem, 3vh, 1.75rem);
  padding: 2rem 1rem;
}

.stage {
  position: relative;
  touch-action: pan-y; /* horizontal swipes move the photos */
  -webkit-user-select: none;
  user-select: none;
}

.hero {
  position: relative;
  display: block;
  width: min(44vw, calc((100svh - 12rem) * 4 / 3 * 0.7));
  height: auto;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius);
  will-change: transform; /* stops a jitter when the opening animation ends */
}

/* ---------- cover flow (js/coverflow.js) ---------- */

.deck {
  position: absolute;
  inset: 0;
  display: none;
}

/* hidden until it unfolds, so it can't show before the main photo loads */
.deck-ready .deck {
  display: block;
  visibility: hidden;
}

.deck-open .deck {
  visibility: visible;
}

.card {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--w);
  height: var(--h);
  margin: calc(var(--h) / -2) 0 0 calc(var(--w) / -2);
  object-fit: cover;
  border-radius: var(--radius);
  transform: perspective(1100px) translate3d(0px, 0, -180px) rotateY(0deg); /* folded behind the main photo */
  will-change: transform;
}

.deck-opening .card {
  transition: transform 1.3s cubic-bezier(0.16, 1, 0.3, 1) calc(var(--i) * 90ms);
}

/* folded away behind the photo in focus, for its video or the about view (js/coverflow.js):
   they fade as they tuck in, outer ones first, and come back the way they opened */
.stage .is-tucked {
  opacity: 0 !important;
  pointer-events: none;
}

.deck-folding .is-tucked {
  transition: transform 0.7s cubic-bezier(0.6, 0, 0.3, 1) calc(var(--j) * 50ms), opacity 0.3s ease 0.45s;
}

.stage .is-unfolding {
  transition: transform 1.3s cubic-bezier(0.16, 1, 0.3, 1) calc(var(--i) * 90ms), opacity 0.3s ease;
}

/* the hovered photo's caption: js/coverflow.js puts it in the photo's own 3D plane */
.caption {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: 0 0;
  z-index: 20000;
  width: max-content;
  max-width: min(30rem, calc(100vw - 2rem));
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.3;
  text-align: center;
  text-wrap: balance;
  pointer-events: none;
  opacity: 0;
  filter: blur(6px);
  transition: opacity 0.18s ease, filter 0.18s ease;
}

.caption.is-shown {
  opacity: 1;
  filter: blur(0);
  transition-duration: 0.45s;
}

@media (prefers-reduced-motion: reduce) {
  .caption,
  .caption.is-shown {
    filter: none;
    transition-duration: 0.15s;
  }
}

/* ---------- the video (js/player.js) ---------- */

/* as tall as the photo, it opens out from the photo's shape (--from, width / height) to the
   video's (--to). The stage is as wide as the 4:3 selfie, so width r * 75% gives shape r. */
.player {
  position: absolute;
  left: 50%;
  top: 0;
  z-index: 15000; /* above the photos */
  height: 100%;
  width: calc(var(--from, 4 / 3) * 75%);
  translate: -50% 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--ink);
  opacity: 0;
  transition: width 0.45s cubic-bezier(0.7, 0, 0.2, 1), opacity 0.25s ease 0.4s;
}

.player.is-open {
  width: calc(var(--to, 16 / 9) * 75%);
  opacity: 1;
  transition: opacity 0.35s ease 0.25s, width 0.7s cubic-bezier(0.7, 0, 0.2, 1) 0.35s;
}

/* the photo under the player, once the player has faded in over it */
.stage .is-behind-player {
  visibility: hidden;
  transition: visibility 0s 0.6s;
}

.player-video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* pixel-art buttons in the same style as the cursors (assets/ui) */
.player-btn {
  position: absolute;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: center no-repeat;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.player.is-open .player-btn {
  opacity: 1;
  transition: opacity 0.3s ease 1s;
}

.player-btn:active {
  filter: invert(1);
}

.player-btn:focus-visible {
  outline: 2px dotted #fff;
  outline-offset: -4px;
}

.player-toggle {
  left: 4px;
  bottom: 4px;
  background-image: url("../assets/ui/play.svg");
}

.player.is-playing .player-toggle {
  background-image: url("../assets/ui/pause.svg");
}

.player-close {
  top: 4px;
  right: 4px;
  background-image: url("../assets/ui/close.svg");
}

@media (prefers-reduced-motion: reduce) {
  .player,
  .player.is-open,
  .player-btn,
  .player.is-open .player-btn {
    transition: none;
  }
}

/* ---------- name and links ---------- */

.nav {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: clamp(1.75rem, 5vw, 4.5rem);
  font-size: clamp(1.5rem, 1.1rem + 1vw, 2.1rem);
  line-height: 1;
}

.name {
  margin: 0;
  font-size: inherit;
  font-weight: inherit;
}

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

.nav-link {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease;
}

.nav-link:hover,
.nav-link:focus-visible,
.about-open .nav-link[href="/about/"] {
  border-bottom-color: currentColor;
  outline: none;
}

/* ---------- the about view (js/pages.js) ---------- */

.about {
  display: none;
  max-width: 32rem;
  margin-top: clamp(0.25rem, 1.5vh, 1rem);
  font-size: clamp(1.15rem, 1rem + 0.4vw, 1.35rem);
  line-height: 1.45;
  text-align: center;
  text-wrap: balance;
  view-transition-name: about;
}

.about p {
  margin: 0 0 1em;
}

/* the links at the bottom: same serif and underline as the ones in the nav */
.about .links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem clamp(1.5rem, 4vw, 2.5rem);
  margin-top: 1.6em;
  font-size: 1.2em;
  line-height: 1;
}

.about-open .about {
  display: block;
}

/* the selfie shrinks and moves up to make room for the text */
.about-open .home {
  overflow-y: auto;
}

.about-open .frame {
  justify-content: flex-start;
  padding-top: clamp(1.5rem, 6vh, 4rem);
}

.about-open .hero {
  width: min(30vw, calc((100svh - 12rem) * 4 / 3 * 0.45));
}

/* the folded photos are sized for the bigger selfie: keep them from peeking out around this one */
.about-open .deck {
  visibility: hidden;
}

/* moving between views, the browser glides the selfie, the name and the text to their new places */
.stage {
  view-transition-name: selfie;
}

.nav {
  view-transition-name: nav;
}

::view-transition-group(*) {
  animation-duration: 0.9s;
  animation-timing-function: cubic-bezier(0.7, 0, 0.2, 1);
}

/* move one picture of each instead of crossfading two, so nothing dims or doubles up on the way */
::view-transition {
  background: var(--paper);
}

::view-transition-old(root),
::view-transition-old(selfie),
::view-transition-old(nav) {
  display: none;
}

::view-transition-new(root),
::view-transition-new(selfie),
::view-transition-new(nav) {
  animation: none;
}

::view-transition-new(about) {
  animation-delay: 0.45s;
  animation-duration: 0.5s;
}

::view-transition-old(about) {
  animation-duration: 0.25s;
}

/* ---------- the opening (js/intro.js) ---------- */

.intro .hero {
  z-index: 30;
  opacity: 0;
}

.intro.intro-ready .hero {
  opacity: 1;
  transition: opacity 0.25s ease;
}

.intro :is(.nav, .about) {
  opacity: 0;
}

@media (max-width: 700px) {
  .hero {
    width: min(64vw, calc((100svh - 12rem) * 4 / 3 * 0.7));
  }

  .nav {
    gap: 1.6rem;
  }

  .about-open .hero {
    width: min(48vw, calc((100svh - 12rem) * 4 / 3 * 0.45));
  }
}
