/* The new arrivals shelf: the spines are cloth over board, the covers glossy paper, the pages cream.
   Every book is a small CSS 3D box (spine, cover on a hinge, page block, back) inside its own slot with its own
   perspective; GSAP turns it. Sizes come from the script as custom properties, measured on the height too. */
:root {
  --page: #f1ede6;          /* the page */
  --page-deep: #e4ded3;     /* its darker corners */
  --ink: #1b1916;           /* the words */
  --muted: #827a6f;         /* the small words */
  --line: rgba(27, 25, 22, 0.14);
  --plank: #d9d1c3;         /* the top of the shelf */
  --plank-edge: #c3b9a8;    /* its front edge */
  --paper: #f6f1e6;         /* the pages inside */
  --gilt: #dcc48e;          /* the gold stamped on the spines */
  --accent: #c8492b;        /* the one accent: the price and Add to bag */
  --serif: 'Fraunces Variable', Georgia, serif;
  --sans: 'Mona Sans Variable', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
html { touch-action: manipulation; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.stage {
  position: relative;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: clamp(12px, 3.4vmin, 34px) clamp(14px, 4vw, 48px);
  background:
    radial-gradient(110% 80% at 50% 46%, transparent 52%, var(--page-deep) 135%),
    var(--page);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}
/* the grain of the paper page */
.stage::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.32;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' 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 .22 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

.head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  font-size: clamp(10px, min(1.3vw, 2.7vh), 13px);
  position: relative;
  z-index: 3;
}
.brand { display: flex; align-items: center; gap: 0.55em; font-weight: 560; font-variation-settings: 'wdth' 92; white-space: nowrap; }
.brand__mark { width: 1.55em; height: 1.55em; fill: none; stroke: currentColor; stroke-width: 1.15; stroke-linejoin: round; }
.head__label { font-family: var(--serif); font-style: normal; font-size: 1.12em; font-variation-settings: 'opsz' 24, 'SOFT' 60; color: var(--muted); white-space: nowrap; }
.bag { justify-self: end; position: relative; display: inline-flex; align-items: center; gap: 0.35em; font-weight: 600; font-variant-numeric: tabular-nums; }
.bag__icon { width: 1.7em; height: 1.7em; fill: none; stroke: currentColor; stroke-width: 1.2; stroke-linejoin: round; stroke-linecap: round; }
.bag__count { display: inline-block; min-width: 1.6em; height: 1.6em; line-height: 1.6em; text-align: center; border-radius: 999px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.4); overflow: hidden; }
.bag__count span { display: block; }
.bag.is-full .bag__count { background: var(--accent); color: #fff; border-color: transparent; }

@media (max-width: 520px) {
  .head { grid-template-columns: 1fr auto; }
  .head__label { display: none; }
}

/* ---------------------------------------------------------------- the shelf */
.shelf {
  position: relative;
  align-self: center;
  justify-self: center;
  width: var(--shelf-w, 600px);
  height: calc(var(--shelf-h, 280px) + 14px);
}
.shelf__row {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 14px;
  height: var(--shelf-h, 280px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: var(--gap, 2px);
}
.shelf__plank {
  position: absolute;
  left: -6%;
  right: -6%;
  bottom: 0;
  height: 14px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--plank) 0 42%, var(--plank-edge) 42% 100%);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset, 0 14px 22px -12px rgba(60, 44, 24, 0.35), 0 3px 4px -2px rgba(60, 44, 24, 0.25);
}
.shelf__plank::before {
  content: '';
  position: absolute;
  inset: 42% 0 0;
  background: repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.07) 0 1px, transparent 1px 9px);
}

.slot {
  position: relative;
  flex: none;
  width: var(--d);
  height: var(--h);
  perspective: var(--persp, 1200px);
  perspective-origin: 50% 30%;
  cursor: pointer;
}
.tilt {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}
.shadow {
  position: absolute;
  left: -30%;
  right: -30%;
  bottom: -3px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(40, 28, 14, 0.38), transparent);
  pointer-events: none;
}
.book {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: var(--w);
  height: var(--h);
  transform-style: preserve-3d;
  transform-origin: 0 50% 0;
  transform: rotateY(90deg);
}
.face {
  position: absolute;
  top: 0;
  left: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* the spine: cloth with its weave, rounded by light, gold stamped */
.spine {
  width: var(--d);
  height: var(--h);
  left: calc(var(--d) / -2);
  transform: rotateY(-90deg);
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.28), rgba(255, 255, 255, 0.13) 26%, rgba(255, 255, 255, 0.02) 52%, rgba(0, 0, 0, 0.22) 92%, rgba(0, 0, 0, 0.36)),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.045) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.06) 0 1px, transparent 1px 3px),
    var(--c);
  border-radius: 2px 2px 1px 1px;
  color: var(--g, var(--gilt));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--h) * 0.06) 0 calc(var(--h) * 0.045);
  overflow: hidden;
}
.spine::after {
  /* the light that rises on the spine while it is pointed at */
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.28) 40%, transparent 70%);
  opacity: var(--lit, 0);
}
.spine__band { width: 72%; height: 0; border-top: 1px solid currentColor; border-bottom: 1px solid currentColor; padding-top: 2px; opacity: 0.75; }
.spine__title {
  writing-mode: vertical-rl;
  font-family: var(--serif);
  font-size: var(--fs, 11px);
  font-variation-settings: 'opsz' 14, 'SOFT' 30;
  font-weight: 560;
  letter-spacing: 0.04em;
  white-space: nowrap;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.spine__author { writing-mode: vertical-rl; font-size: calc(var(--fs, 11px) * 0.62); letter-spacing: 0.14em; text-transform: uppercase; font-weight: 600; font-variation-settings: 'wdth' 85; opacity: 0.85; margin: 0.6em 0; }
.spine__mark { width: calc(var(--d) * 0.42); height: calc(var(--d) * 0.42); fill: none; stroke: currentColor; stroke-width: 1.4; opacity: 0.8; }

/* the page block, seen on the fore edge and the first page */
.edge {
  width: calc(var(--d) - 5px);
  height: calc(var(--h) - 6px);
  top: 3px;
  left: calc(var(--w) - 3px - (var(--d) - 5px) / 2);
  transform: rotateY(90deg);
  background:
    repeating-linear-gradient(90deg, rgba(120, 100, 70, 0.14) 0 1px, transparent 1px 2px),
    linear-gradient(90deg, #e9e0cc, var(--paper) 40%, #ece3cf);
}
.back {
  width: var(--w);
  height: var(--h);
  transform: translateZ(calc(var(--d) / -2)) rotateY(180deg);
  background: var(--c);
  border-radius: 2px 4px 4px 2px;
}
.page {
  width: calc(var(--w) - 4px);
  height: calc(var(--h) - 6px);
  top: 3px;
  transform: translateZ(calc(var(--d) / 2 - 1.5px));
  background:
    linear-gradient(90deg, rgba(90, 70, 40, 0.16), transparent 9%),
    var(--paper);
  border-radius: 0 3px 3px 0;
  padding: calc(var(--u) * 9) calc(var(--u) * 7) calc(var(--u) * 7) calc(var(--u) * 9);
  display: flex;
  flex-direction: column;
  font-size: calc(var(--u) * 4.4);
  visibility: hidden;
}
.page::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(40, 28, 14, 0.5), rgba(40, 28, 14, 0.12) 45%, transparent 80%);
  opacity: var(--ps, 0);
  z-index: 2;
}
/* the ribbon bookmark hanging from the page block, in the colour of the endpaper */
.ribbon {
  position: absolute;
  left: 62%;
  top: 90%;
  width: calc(var(--u) * 3.4);
  height: 15%;
  transform-origin: 50% 0;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.18), transparent 40%, rgba(0, 0, 0, 0.12)), var(--c);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%);
}
.page__kind { color: var(--muted); letter-spacing: 0.12em; text-transform: uppercase; font-size: 0.78em; font-weight: 600; font-variation-settings: 'wdth' 88; }
.page__title { font-family: var(--serif); font-size: 1.7em; line-height: 1.02; margin-top: 0.5em; font-variation-settings: 'opsz' 48, 'SOFT' 50; font-weight: 520; letter-spacing: -0.01em; }
.page__author { margin-top: 0.45em; color: var(--muted); }
.page__rule { margin: auto 0 0.9em; height: 1px; background: var(--line); transform-origin: 0 50%; }
.page__price { font-family: var(--serif); font-size: 2.4em; line-height: 1; color: var(--accent); font-variation-settings: 'opsz' 72, 'SOFT' 0; font-weight: 600; font-variant-numeric: tabular-nums; display: flex; align-items: baseline; gap: 0.25em; }
.page__price small { font-family: var(--sans); font-size: 0.32em; color: var(--muted); font-weight: 500; }
.add {
  margin-top: 0.8em;
  position: relative;
  align-self: stretch;
  border: 0;
  font: inherit;
  font-weight: 600;
  font-size: 1.02em;
  color: #fff;
  background: none;
  padding: 0.72em 0;
  cursor: pointer;
  display: flex;
  justify-content: center;
}
.add__fill { position: absolute; inset: 0; border-radius: 999px; background: var(--accent); box-shadow: 0 1px 0 rgba(255, 255, 255, 0.28) inset, 0 6px 14px -6px rgba(140, 40, 18, 0.55); }
.add__face { position: relative; display: inline-flex; align-items: center; gap: 0.45em; font-variation-settings: 'wdth' 100; }
.add__check { width: 1.05em; height: 1.05em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* the cover on its hinge */
.cover {
  width: var(--w);
  height: var(--h);
  position: absolute;
  top: 0;
  left: 0;
  transform-style: preserve-3d;
  transform-origin: 0 50%;
  transform: translateZ(calc(var(--d) / 2));
}
.cover__out,
.cover__in {
  width: var(--w);
  height: var(--h);
  border-radius: 1px 4px 4px 1px;
  overflow: hidden;
}
.cover__out {
  background: var(--c);
  color: var(--ci);
  box-shadow: inset 1px 0 0 rgba(255, 255, 255, 0.12);
}
.cover__art { position: absolute; inset: 0; width: 100%; height: 100%; }
.cover__hinge { position: absolute; top: 0; bottom: 0; left: 6%; width: 1px; background: rgba(0, 0, 0, 0.16); box-shadow: 1px 0 0 rgba(255, 255, 255, 0.1); }
.cover__words { position: absolute; inset: 0; padding: calc(var(--u) * 9) calc(var(--u) * 7) calc(var(--u) * 7) calc(var(--u) * 10); display: flex; flex-direction: column; }
.cover__title { font-family: var(--serif); font-size: calc(var(--u) * 9.6); line-height: 0.96; font-weight: 600; font-variation-settings: 'opsz' 96, 'SOFT' 100, 'WONK' 1; letter-spacing: -0.02em; }
.cover__author { margin-top: auto; font-size: calc(var(--u) * 3.6); letter-spacing: 0.16em; text-transform: uppercase; font-weight: 600; font-variation-settings: 'wdth' 90; opacity: 0.9; }
/* the light on the glossy paper: a band that sweeps across when the book turns, and follows the pointer after */
.cover__gloss {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(105deg, transparent calc(var(--gx, -40) * 1% - 22%), rgba(255, 255, 255, 0.5) calc(var(--gx, -40) * 1%), transparent calc(var(--gx, -40) * 1% + 22%)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), transparent 30%, rgba(0, 0, 0, 0.08));
  mix-blend-mode: soft-light;
  pointer-events: none;
}
.cover__shade { position: absolute; inset: 0; background: #000; opacity: var(--shade, 0); pointer-events: none; }
.cover__in {
  transform: rotateY(180deg);
  background:
    repeating-linear-gradient(135deg, rgba(0, 0, 0, 0.05) 0 1px, transparent 1px 7px),
    var(--ce);
  visibility: hidden;
}
.cover__in::after { content: ''; position: absolute; inset: 0; background: linear-gradient(270deg, rgba(0, 0, 0, 0.2), transparent 10%); }

/* ---------------------------------------------------------------- under the shelf */
.info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2em;
  font-size: clamp(10px, min(1.4vw, 2.8vh), 14px);
  text-align: center;
  position: relative;
  z-index: 3;
}
.info__window { display: block; overflow: hidden; padding: 0.06em 0; }
.info__title { display: block; font-family: var(--serif); font-size: 1.5em; font-variation-settings: 'opsz' 36, 'SOFT' 50; font-weight: 520; letter-spacing: -0.005em; white-space: nowrap; }
.info__meta { display: block; color: var(--muted); white-space: nowrap; }
.info__meta b { color: var(--accent); font-weight: 600; }

@media (hover: hover) {
  .add:hover .add__fill { filter: brightness(1.06); }
}
