:root {
  --paper: #f4efe6;       /* warm paper of the page */
  --ink: #1a1712;         /* the words */
  --accent: #c8174f;      /* raspberry, the only accent: the lit word, the count, the note */
  --muted: #8b8274;       /* small type */
  --ring: #ffffff;        /* the white border of the photo frames */
  --shadow: 26 20 12;     /* rgb of the soft shadow under the frames */

  /* spring of the frames, a CSS linear() curve: copied from the site, an elastic that overshoots by 14% and settles */
  --ease-elastic: linear(0, .5737 7.6%, .8382 11.87%, .9463 14.19%, 1.0292 16.54%, 1.0886 18.97%, 1.1258 21.53%,
    1.137 22.97%, 1.1424 24.48%, 1.1423 26.1%, 1.1366 27.86%, 1.1165 31.01%, 1.0507 38.62%, 1.0219 42.57%,
    .9995 46.99%, .9872 51.63%, .9842 58.77%, 1.0011 81.26%, 1);
  --ease-bounce: cubic-bezier(.34, 1.57, .64, 1);
  --ease-smooth: cubic-bezier(.32, .72, 0, 1);

  /* set by script.js from the values at the top */
  --spring: .85s;
  --pop: .4s;
  --shift: .3;
  --wide: 125%;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: 'Mona Sans Variable', system-ui, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.page {
  position: relative;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: min(4.5vh, 4.5vw) min(5vw, 48px);
}

.bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  position: relative;
  z-index: 3;
}

.brand {
  font-size: clamp(11px, min(1.6vw, 2.6vh), 15px);
  font-weight: 650;
  font-stretch: 112%;
  letter-spacing: .01em;
}

.note {
  font-family: 'Caveat Variable', cursive;
  color: var(--accent);
  font-size: clamp(14px, min(2.4vw, 3.8vh), 24px);
  line-height: 1;
  text-align: right;
  transform: rotate(-4deg);
  transform-origin: 100% 0;
}

/* ---- the list ---- */

.wrap {
  position: relative;
  align-self: center;
  justify-self: stretch;
}

.list {
  list-style: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 2;
}

.item { display: block; }

.link {
  --size: min(11.5vw, 10vh, 124px);
  position: relative;
  display: grid;
  place-items: center;
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  font-size: var(--size);
  line-height: 1.18;
  padding: 0 .08em;
  outline: none;
  translate: 0 0;
  transition: translate .5s var(--ease-smooth), opacity .35s var(--ease-smooth);
  -webkit-tap-highlight-color: transparent;
}

.word {
  grid-area: 1 / 1;
  font-weight: 800;
  font-stretch: 100%;
  letter-spacing: -.035em;
  white-space: nowrap;
  will-change: transform, filter;
  transition: opacity .15s .05s var(--ease-smooth), scale .35s var(--ease-bounce), filter .25s .05s var(--ease-smooth);
}

.word--on {
  color: var(--accent);
  font-weight: 850;
  font-stretch: var(--wide);
  letter-spacing: -.045em;
  opacity: 0;
  scale: .75 1.25;
  filter: blur(.0625em);
}

.count {
  position: absolute;
  right: -.15em;
  bottom: calc(100% - .02em);
  font-size: max(10px, .12em);
  z-index: 3;
  font-weight: 600;
  font-stretch: 110%;
  letter-spacing: .02em;
  color: var(--accent);
  background: var(--paper);
  padding: .3em .6em .32em;
  border-radius: 999px;
  box-shadow: 0 2px 8px -3px rgb(var(--shadow) / .25);
  white-space: nowrap;
  opacity: 0;
  translate: 0 .5em;
  transition: opacity .2s var(--ease-smooth), translate .5s var(--ease-bounce);
  font-variant-numeric: tabular-nums;
}

/* the lit genre: the word swaps for the wider one in the accent colour */
.item.is-on .word--rest { opacity: 0; scale: .75 1.25; filter: blur(.0625em); transition: opacity .15s .05s var(--ease-smooth), scale .3s var(--ease-bounce), filter .25s var(--ease-smooth); }
.item.is-on .word--on { opacity: 1; scale: 1 1; filter: blur(0); transition: opacity .15s .05s var(--ease-smooth), scale .3s var(--ease-bounce), filter .25s var(--ease-smooth); }
.item.is-on .count { opacity: 1; translate: 0 0; }
.item.is-press .link { scale: .965; transition: scale .12s var(--ease-smooth); }
.item .link { scale: 1; }
.item:not(.is-press) .link { transition: translate .5s var(--ease-smooth), opacity .35s var(--ease-smooth), scale .45s var(--ease-bounce); }

/* the others fade a little (ours) */
.list:has(.is-on) .item:not(.is-on) .link { opacity: .3; }

/* the neighbours step aside, as on the site: one row away a lot, two rows away a little */
.item.is-on + .item .link { translate: 0 calc(var(--shift) * 1em); }
.item.is-on + .item + .item .link { translate: 0 calc(var(--shift) * .375em); }
.item:has(+ .item.is-on) .link { translate: 0 calc(var(--shift) * -1em); }
.item:has(+ .item + .item.is-on) .link { translate: 0 calc(var(--shift) * -.375em); }

.link:focus-visible .word--rest { text-decoration: underline; text-decoration-thickness: .04em; text-underline-offset: .12em; }

/* ---- the photo frames ---- */

.holding {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 0;
  z-index: 1;
  pointer-events: none;
  translate: 0 var(--sy, 0px);
  transition: translate var(--ts, 0s) var(--ease-smooth);
}

.holder {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--bw, 120px);
  aspect-ratio: 272 / 419;
  translate: var(--hx, 0px) var(--hy, 0px);
  transition: translate var(--spring) var(--ease-elastic);
}

.box {
  position: absolute;
  inset: 0;
  border-radius: min(10px, 6%);
  box-shadow: 0 0 0 max(3px, .04 * var(--bwn, 120px)) var(--ring),
    0 18px 34px -14px rgb(var(--shadow) / .38), 0 4px 10px -4px rgb(var(--shadow) / .22);
  background: var(--ring);
  overflow: hidden;
  scale: 0;
  transform: translate(calc(var(--x, 0) * 1%), calc(var(--y, 0) * 1%)) rotate(calc(var(--r, 0) * 1deg))
    translate(calc(var(--px, 0) * var(--prx, 0%)), calc(var(--py, 0) * var(--pry, 0%)));
  transition: scale var(--pop) var(--ease-bounce), transform var(--spring) var(--ease-elastic);
}

.holder:nth-of-type(1) .box { --prx: calc(var(--par) * 1%); --pry: calc(var(--par) * .66%); }
.holder:nth-of-type(2) .box { --prx: calc(var(--par) * -1%); --pry: calc(var(--par) * -.66%); }
.holder:nth-of-type(3) .box { --prx: calc(var(--par) * .66%); --pry: calc(var(--par) * .83%); }
.holder:nth-of-type(4) .box { --prx: calc(var(--par) * -.66%); --pry: calc(var(--par) * -.83%); }

.wrap.is-open .box { scale: 1; }
.wrap.is-open .holder:nth-of-type(2) .box { transition-delay: .03s, 0s; }
.wrap.is-open .holder:nth-of-type(3) .box { transition-delay: .06s, 0s; }
.wrap.is-open .holder:nth-of-type(4) .box { transition-delay: .09s, 0s; }
.wrap.is-press .box { scale: .94; transition: scale .12s var(--ease-smooth), transform var(--spring) var(--ease-elastic); }

.box img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--fx, 50%) 50%;
  opacity: 0;
  transition: opacity .2s;
}

/* the photo of the lit genre, picked with :has() as on the site */
.wrap:has(.item:nth-of-type(1).is-on) .box img:nth-of-type(1),
.wrap:has(.item:nth-of-type(2).is-on) .box img:nth-of-type(2),
.wrap:has(.item:nth-of-type(3).is-on) .box img:nth-of-type(3),
.wrap:has(.item:nth-of-type(4).is-on) .box img:nth-of-type(4) {
  opacity: 1;
  z-index: 2;
  transition: opacity 0s;
}

/* the photo of the genre just left stays under the new one while the frames close */
.box img.is-last { opacity: 1; z-index: 1; transition: opacity 0s; }

.hint {
  justify-self: center;
  font-size: clamp(10px, min(1.4vw, 2.3vh), 13px);
  font-weight: 550;
  font-stretch: 112%;
  letter-spacing: .04em;
  color: var(--muted);
  position: relative;
  z-index: 3;
  transition: opacity .4s var(--ease-smooth);
}

.page.has-touched .hint { opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  .link, .word, .count, .holder, .holding { transition: opacity .3s ease !important; }
  .word--on, .item.is-on .word--rest { scale: 1 1; filter: none; }
  .item .link, .item.is-on + .item .link, .item.is-on + .item + .item .link,
  .item:has(+ .item.is-on) .link, .item:has(+ .item + .item.is-on) .link { translate: 0 0; }
  .count { translate: 0 0; }
  .box { scale: 1; opacity: 0; transition: opacity .3s ease !important; transform: rotate(calc(var(--r, 0) * .5deg)); }
  .wrap.is-open .box, .wrap.is-press .box { scale: 1; opacity: 1; }
}
