/* Shelf to book page: the shop of Vellmont Books, an independent bookshop. The shelf (.shelf) and the book's page
   (.page) sit on top of each other in the same stage; the book that travels between them is .flyer, a flat plane
   with the spine on one side and the cover on the other, placed and turned by script.js. Every spine is a button:
   .spine is the layout, .spine__body is moved by GSAP, .spine__skin is lifted by the CSS hover. */
:root {
  --page: #f5f0e7;          /* the warm paper of the page */
  --wall: #efe8dc;          /* the back of the shelf, a shade darker */
  --ink: #1f1b16;           /* the words */
  --muted: #7d7365;         /* the small words */
  --board: #cfc3b0;         /* the thin line of the shelf */
  --accent: #c8452c;        /* the one accent: the button and the shop mark */
  --button-ink: #fbf6ee;    /* the words on the button */
  --H: min(44vh, 60vw, 300px); /* the height of the tallest spine */
  --cw: min(34vw, 36vh, 290px); /* the width of the cover on the book's page */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .45 0 0 0 0 .4 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23g)'/%3E%3C/svg%3E");
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

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

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.stage {
  position: relative;
  height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(120% 70% at 50% 0%, rgba(255, 255, 255, 0.55), transparent 60%),
    var(--page);
  perspective: 1400px;
}

/* the paper grain over the whole page, very faint */
.stage::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: var(--grain);
  opacity: 0.22;
  mix-blend-mode: multiply;
  pointer-events: none;
}

/* ---- the bar ---- */
.bar {
  position: absolute;
  z-index: 5;
  top: min(4.5vh, 26px);
  left: min(6vw, 40px);
  right: min(6vw, 40px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: clamp(11px, min(1.6vw, 2.4vh), 14px);
}

.bar__mark {
  font-family: 'Fraunces Variable', Georgia, serif;
  font-size: 1.22em;
  font-variation-settings: 'opsz' 24, 'SOFT' 50;
  font-weight: 560;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.bar__mark em {
  font-style: italic;
  font-weight: 380;
}

.bar__slot {
  position: relative;
  display: grid;
  justify-items: end;
  align-items: center;
}

.bar__label,
.back {
  grid-area: 1 / 1;
}

.bar__label {
  color: var(--muted);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.back {
  visibility: hidden;
  opacity: 0;
  white-space: nowrap;
}

.back__face {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.55em 0.95em 0.55em 0.75em;
  border-radius: 999px;
  border: 1px solid rgba(31, 27, 22, 0.14);
  background: rgba(255, 255, 255, 0.5);
  font-variation-settings: 'wdth' 100;
  transition: font-variation-settings 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), border-color 0.3s, background-color 0.3s;
}

.back__icon {
  width: 1.1em;
  height: 1.1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.back:active .back__face {
  transform: scale(0.97);
}

.back:focus-visible {
  outline: none;
}

.back:focus-visible .back__face {
  border-color: var(--ink);
}

@media (hover: hover) {
  .back:hover .back__face {
    font-variation-settings: 'wdth' 112;
    background: #fff;
    border-color: rgba(31, 27, 22, 0.26);
  }

  .back:hover .back__icon {
    transform: translateX(-2px);
  }
}

/* ---- the shelf ---- */
.shelf {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding-top: min(6vh, 40px);
}

.shelf__row {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: calc(var(--H) * 0.012);
  height: calc(var(--H) + 14px);
  padding-top: 14px;
}

.shelf__note {
  position: absolute;
  left: 50%;
  top: calc(100% + min(3vh, 20px));
  translate: -50% 0;
  font-family: 'Fraunces Variable', Georgia, serif;
  font-style: italic;
  font-size: clamp(11px, min(1.5vw, 2.2vh), 14px);
  font-variation-settings: 'opsz' 14;
  color: var(--muted);
  white-space: nowrap;
}

.shelf__board {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: min(88vw, calc(100% + var(--H) * 0.5));
  height: 1px;
  margin-left: calc(min(88vw, calc(100% + var(--H) * 0.5)) / -2);
  background: var(--board);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7), 0 6px 14px -6px rgba(60, 45, 25, 0.25);
}

.spine {
  position: relative;
  flex: none;
  width: calc(var(--w) * var(--H));
  height: calc(var(--h) * var(--H));
  outline: none;
}

.spine__body {
  position: absolute;
  inset: 0;
}

.spine__skin {
  position: absolute;
  inset: 0;
  transition: transform 0.5s cubic-bezier(0.34, 1.7, 0.6, 1);
}

/* the contact shadow on the board: it stretches and softens when the spine lifts */
.spine__skin::before {
  content: '';
  position: absolute;
  left: 6%;
  right: -10%;
  bottom: -3px;
  height: 6px;
  border-radius: 50%;
  background: rgba(50, 36, 20, 0.28);
  filter: blur(2px);
  transform-origin: 30% 0;
  transition: transform 0.5s cubic-bezier(0.34, 1.4, 0.6, 1), opacity 0.4s;
}

/* the light the spine takes when it comes out */
.spine__skin::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 2px 2px 1px 1px;
  background: linear-gradient(100deg, transparent 20%, rgba(255, 248, 230, 0.55) 46%, transparent 70%);
  background-size: 100% 260%;
  background-position: 0 100%;
  opacity: 0;
  mix-blend-mode: soft-light;
  transition: opacity 0.35s, background-position 0.9s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.spine.is-hot .spine__skin,
.spine:focus-visible .spine__skin {
  transform: translateY(calc(var(--H) * -0.03 - 1px));
}

.spine.is-hot .spine__skin::before,
.spine:focus-visible .spine__skin::before {
  transform: translateY(2px) scaleY(1.8) scaleX(1.06);
  opacity: 0.75;
}

.spine.is-hot .spine__skin::after,
.spine:focus-visible .spine__skin::after {
  opacity: 1;
  background-position: 0 0;
}

@media (hover: hover) {
  .stage:not(.is-busy) .spine:hover .spine__skin {
    transform: translateY(calc(var(--H) * -0.03 - 1px));
  }

  .stage:not(.is-busy) .spine:hover .spine__skin::before {
    transform: translateY(2px) scaleY(1.8) scaleX(1.06);
    opacity: 0.75;
  }

  .stage:not(.is-busy) .spine:hover .spine__skin::after {
    opacity: 1;
    background-position: 0 0;
  }
}

/* ---- the art of a book: the spine side ---- */
.art {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background-color: var(--bg);
  color: var(--fg);
}

/* the grain of cloth and paper */
.art::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: var(--grain);
  background-size: 120px 120px;
  opacity: 0.5;
  mix-blend-mode: multiply;
  pointer-events: none;
}

.art--spine {
  border-radius: 2px 2px 1px 1px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(var(--H) * 0.05) 0 calc(var(--H) * 0.035);
}

/* the round of the spine: dark at the edges, a soft highlight a third of the way in */
.art--spine::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.16), rgba(255, 255, 255, 0.14) 28%, rgba(255, 255, 255, 0) 52%, rgba(0, 0, 0, 0.08) 80%, rgba(0, 0, 0, 0.2));
  pointer-events: none;
}

.art__bands {
  position: relative;
  width: 100%;
  height: 4px;
  border-top: 1px solid var(--foil);
  border-bottom: 1px solid var(--foil);
  opacity: 0.8;
  flex: none;
}

.art__spine-title {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: calc(var(--H) * 0.035) 0;
  writing-mode: vertical-rl;
  font-family: 'Fraunces Variable', Georgia, serif;
  font-size: calc(var(--H) * 0.054);
  font-variation-settings: 'opsz' 14, 'SOFT' var(--soft, 30), 'WONK' 0;
  font-weight: var(--wt, 520);
  letter-spacing: 0.02em;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-align: center;
}

.art__spine-mark {
  position: relative;
  flex: none;
  font-family: 'Fraunces Variable', Georgia, serif;
  font-size: calc(var(--H) * 0.045);
  font-style: italic;
  font-weight: 400;
  opacity: 0.85;
}

/* ---- the art of a book: the cover side (sized in container units, so it grows with the plane) ---- */
.art--cover {
  border-radius: 2px 4px 4px 2px;
  display: flex;
  flex-direction: column;
  padding: 9cqw 9cqw 8cqw 11cqw;
}

/* the hinge on the left and a little light falling over the paper */
.art--cover::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.2) 0, rgba(255, 255, 255, 0.16) 1.4%, rgba(0, 0, 0, 0.12) 3.2%, rgba(255, 255, 255, 0.06) 4.6%, transparent 7%),
    linear-gradient(160deg, rgba(255, 255, 255, 0.14), transparent 45%, rgba(0, 0, 0, 0.08));
  pointer-events: none;
}

.art__genre {
  position: relative;
  font-size: 3.6cqw;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0.75;
}

.art__cover-title {
  position: relative;
  margin-top: auto;
  font-family: 'Fraunces Variable', Georgia, serif;
  font-size: 13.5cqw;
  font-variation-settings: 'opsz' 72, 'SOFT' var(--soft, 30), 'WONK' 1;
  font-weight: var(--wt, 520);
  line-height: 0.98;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.art__cover-author {
  position: relative;
  margin-top: 5cqw;
  font-size: 4.2cqw;
  letter-spacing: 0.04em;
  opacity: 0.85;
}

.art__sign {
  position: relative;
  width: 38cqw;
  height: 38cqw;
  margin-top: 4cqw;
  fill: none;
  stroke: var(--foil);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.art__sign * {
  vector-effect: non-scaling-stroke;
}

/* ---- the book's page ---- */
.page {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: min(5vw, 56px);
  padding: min(12vh, 80px) min(6vw, 40px) min(5vh, 30px);
  visibility: hidden;
}

.page__cover {
  flex: none;
  width: var(--cw);
  height: calc(var(--cw) * 1.48);
}

.page__info {
  width: min(46vw, 340px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.m {
  display: block;
  margin: 0;
  overflow: hidden;
  padding-bottom: 0.08em;
}

.m__in {
  display: inline-block;
}

.page__genre {
  font-size: clamp(9px, min(1.3vw, 1.9vh), 12px);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.page__title {
  margin-top: min(1.6vh, 12px);
  font-family: 'Fraunces Variable', Georgia, serif;
  font-size: clamp(19px, min(5.4vw, 7vh), 56px);
  font-variation-settings: 'opsz' 96, 'SOFT' 40, 'WONK' 1;
  font-weight: 480;
  line-height: 1;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

.page__author {
  margin-top: min(1.2vh, 10px);
  font-family: 'Fraunces Variable', Georgia, serif;
  font-style: italic;
  font-size: clamp(12px, min(1.8vw, 2.6vh), 19px);
  font-variation-settings: 'opsz' 18;
}

.page__meta {
  margin-top: min(0.8vh, 6px);
  font-size: clamp(10px, min(1.3vw, 1.9vh), 13px);
  color: var(--muted);
}

.page__price {
  margin-top: min(2.6vh, 20px);
  font-size: clamp(15px, min(2.4vw, 3.6vh), 26px);
  font-weight: 560;
  letter-spacing: -0.01em;
}

.page__rule {
  display: block;
  width: 100%;
  height: 1px;
  margin: min(1.8vh, 14px) 0;
  background: rgba(31, 27, 22, 0.14);
  transform-origin: 0 50%;
}

.page__stock {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-size: clamp(10.5px, min(1.4vw, 2vh), 13px);
}

.page__shop {
  width: 1.25em;
  height: 1.25em;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.m--btn {
  margin: calc(min(2.4vh, 18px) - 6px) -24px -24px -24px;
  padding: 6px 24px 24px;
}

.reserve {
  position: relative;
  outline: none;
}

.reserve__face {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0;
  height: clamp(32px, min(5vw, 6.4vh), 46px);
  padding: 0 1.35em;
  border-radius: 999px;
  color: var(--button-ink);
  font-size: clamp(11px, min(1.5vw, 2.2vh), 14px);
  font-weight: 560;
  font-variation-settings: 'wdth' 100;
  transition: font-variation-settings 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* the body of the pill: it swells with a bounce on hover */
.reserve__face::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 55%), var(--accent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 1px 1px rgba(90, 30, 15, 0.25), 0 8px 18px -8px rgba(160, 50, 25, 0.55);
  transition: transform 0.55s cubic-bezier(0.34, 1.8, 0.6, 1);
}

.reserve__icon {
  width: 0;
  height: 1.15em;
  margin-left: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  overflow: visible;
  transition: width 0.45s cubic-bezier(0.34, 1.4, 0.6, 1), margin-left 0.45s cubic-bezier(0.34, 1.4, 0.6, 1);
}

.reserve.is-done .reserve__icon {
  width: 1.15em;
  margin-left: 0.5em;
}

.reserve:active .reserve__face::before {
  transform: scale(0.96);
}

.reserve:focus-visible .reserve__face::before {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

@media (hover: hover) {
  .reserve:hover .reserve__face {
    font-variation-settings: 'wdth' 114;
  }

  .reserve:hover .reserve__face::before {
    transform: scale(1.04, 1.08);
  }

  .reserve:active .reserve__face::before {
    transform: scale(0.97);
  }
}

/* ---- the book that travels ---- */
.flyer {
  position: absolute;
  z-index: 4;
  left: 0;
  top: 0;
  width: 10px;
  height: 10px;
  visibility: hidden;
  pointer-events: none;
}

.flyer__turn {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 2px 4px 4px 2px;
}

.face--cover {
  container-type: size;
  transform: rotateY(180deg);
}

.face--cover .art,
.face--spine .art {
  border-radius: inherit;
}

/* reduced motion: the cover is already in its place, the shelf and the page swap with a fade */
@media (prefers-reduced-motion: reduce) {
  .spine__skin,
  .spine__skin::before,
  .spine__skin::after,
  .back__face,
  .back__icon,
  .reserve__face,
  .reserve__face::before {
    transition: opacity 0.3s;
  }

  .spine.is-hot .spine__skin,
  .spine:focus-visible .spine__skin {
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) and (hover: hover) {
  .stage:not(.is-busy) .spine:hover .spine__skin,
  .back:hover .back__icon,
  .reserve:hover .reserve__face::before {
    transform: none;
  }
}
