/* The leporello carousel: the books of a pocket series on one strip of folded paper, alone on a white page. Titles in
   Fraunces (a variable serif: weight, softness and optical size), the small words in Archivo. The script folds the
   paper every frame; this file only dresses the cards. */
:root {
  --page: #ffffff;                  /* the page */
  --paper: #fbfaf6;                 /* the printed side of the paper */
  --paper-back: #f2efe7;            /* the blank back of the paper */
  --ink: #141414;                   /* the titles, the arrows */
  --grey: #8a857b;                  /* the small words */
  --edge: rgba(20, 20, 20, 0.13);   /* the edges of the paper */
  --crease: rgba(20, 20, 20, 0.3);  /* the hairline on every fold */
  --shade: #2e2820;                 /* the colour of a card turned away from the light */
  --accent: #e2432a;                /* the year of the book lying open */
  --card-w: 232px;                  /* the width of a card */
  --card-h: 318px;                  /* the height of a card */
}

* {
  box-sizing: border-box;
}

/* a tap is a click at once: no wait for a double tap */
html {
  touch-action: manipulation;
}

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

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Archivo Variable', 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* the component stands alone in the middle of the page */
.stage {
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: 32px 16px;
  overflow: hidden;
}

.lep {
  width: min(920px, 100%);
}

/* ---------------------------------------------------------------- the head: the series and the arrows */
.lep__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(600px, 100%);
  margin: 0 auto;
}

.lep__title {
  margin: 0;
  font-family: 'Fraunces Variable', Georgia, serif;
  font-size: 21px;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: -0.01em;
  font-variation-settings: 'opsz' 36, 'SOFT' 0, 'WONK' 0;
}

.lep__arrows {
  display: flex;
  gap: 8px;
}

.arrow {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--edge);
  cursor: pointer;
  transition: box-shadow 0.25s, opacity 0.25s, transform 0.16s cubic-bezier(0.23, 1, 0.32, 1);
  -webkit-tap-highlight-color: transparent;
}

.arrow svg {
  width: 20px;
  height: 20px;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@media (hover: hover) {
  .arrow:hover {
    box-shadow: inset 0 0 0 1px var(--ink);
  }

  [data-next]:hover svg {
    transform: translateX(2px);
  }

  [data-prev]:hover svg {
    transform: translateX(-2px);
  }
}

.arrow:active {
  transform: scale(0.93);
}

/* at the two ends of the strip there is nowhere to go */
.arrow[aria-disabled='true'] {
  opacity: 0.3;
  cursor: default;
}

.arrow[aria-disabled='true'] svg {
  transform: none;
}

.arrow:focus {
  outline: none;
}

.arrow:focus-visible {
  box-shadow: inset 0 0 0 1px var(--ink), 0 0 0 3px var(--page), 0 0 0 4px var(--ink);
}

/* ---------------------------------------------------------------- the strip */
.lep__view {
  --pad: 34px;
  --pad-low: 84px;
  --fade: 56px;
  position: relative;
  height: calc(var(--card-h) + var(--pad) + var(--pad-low));
  margin-top: 10px;
  overflow: hidden;
  outline: none;
  cursor: grab;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  perspective: calc(var(--card-w) * 9);
  perspective-origin: 50% -30%;
  /* the stacks at the two ends fade out at the edges */
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 var(--fade), #000 calc(100% - var(--fade)), transparent);
  mask-image: linear-gradient(90deg, transparent, #000 var(--fade), #000 calc(100% - var(--fade)), transparent);
}

.lep__view.is-held {
  cursor: grabbing;
}

/* the keys: a thin frame round the card lying open */
.lep__view::after {
  content: '';
  position: absolute;
  left: 50%;
  top: calc(var(--pad) - 8px);
  width: calc(var(--card-w) + 16px);
  height: calc(var(--card-h) + 16px);
  margin-left: calc(var(--card-w) / -2 - 8px);
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px var(--ink);
  opacity: 0;
  pointer-events: none;
}

.lep__view:focus-visible::after {
  opacity: 1;
}

html[data-using='pointer'] .lep__view:focus-visible::after {
  opacity: 0;
}

/* a point in the middle of the strip: the script places every card from here */
.lep__strip {
  position: absolute;
  left: 50%;
  top: var(--pad);
  width: 0;
  height: 0;
  transform-style: preserve-3d;
}

/* the soft shadow the paper casts on the table */
.lep__shadow {
  position: absolute;
  left: 50%;
  top: calc(var(--pad) + var(--card-h) - 14px);
  width: 100px;
  height: 30px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(40, 32, 20, 0.16), rgba(40, 32, 20, 0));
  transform-origin: 0 50%;
  pointer-events: none;
  will-change: transform;
}

/* ---------------------------------------------------------------- a card: one panel of the leporello */
/* every card turns on its left edge, the fold it shares with the card before */
.leaf {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--card-w);
  height: var(--card-h);
  transform-origin: 0 50%;
  transform-style: preserve-3d;
  will-change: transform;
}

.leaf__face {
  position: absolute;
  inset: 0 -0.5px 0 0;
  overflow: hidden;
  background: var(--paper);
  box-shadow: inset 0 1px 0 var(--edge), inset 0 -1px 0 var(--edge);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.leaf__face--back {
  background: var(--paper-back);
  transform: rotateY(180deg);
}

/* the folds: a hairline on the left edge of every card but the first, on both sides of the paper */
.leaf__face::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 1px;
  background: var(--crease);
  z-index: 2;
}

.leaf__face--back::before {
  left: auto;
  right: 0.5px;
}

/* the two ends of the strip: the outer edges of the paper */
.leaf--first .leaf__face--front::before,
.leaf--first .leaf__face--back::before,
.leaf--last .leaf__face--front::after,
.leaf--last .leaf__face--back::after {
  background: var(--edge);
}

.leaf--last .leaf__face::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0.5px;
  width: 1px;
  z-index: 2;
}

.leaf--last .leaf__face--back::after {
  right: auto;
  left: 0;
}

/* the light: a card turned away from it gets darker (the script sets how much) */
.leaf__shade {
  position: absolute;
  inset: 0;
  background: var(--shade);
  opacity: 0;
  z-index: 1;
  pointer-events: none;
}

/* ---------------------------------------------------------------- what is printed on a card */
.book {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 20px 20px 18px;
}

.book__author {
  margin: 0;
  color: var(--grey);
  font-size: 10.5px;
  font-weight: 560;
  line-height: 1.3;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-variation-settings: 'wdth' 100;
  white-space: nowrap;
}

.book__title {
  margin: 16px 0 0;
  font-family: 'Fraunces Variable', Georgia, serif;
  font-size: 32px;
  font-weight: 400;
  line-height: 1.02;
  letter-spacing: -0.02em;
  font-optical-sizing: auto;
  font-variation-settings: 'SOFT' 50, 'WONK' 0;
}

/* the lines of a title are set by hand: they never wrap again while the weight changes */
.book__line {
  display: block;
  white-space: nowrap;
}

.book__words {
  margin: auto 0 0;
  max-width: 17em;
  color: var(--grey);
  font-size: 12.5px;
  font-weight: 430;
  line-height: 1.42;
  font-variation-settings: 'wdth' 96;
}

.book__foot {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--edge);
  font-size: 11.5px;
  font-weight: 560;
  letter-spacing: 0.04em;
  font-variation-settings: 'wdth' 100;
}

/* the year turns to the accent as its card comes to lie open (--lit, from the script) */
.book__year {
  --lit: 0;
  color: color-mix(in srgb, var(--accent) calc(var(--lit) * 100%), var(--grey));
  font-variant-numeric: tabular-nums;
}

.book__kind {
  color: var(--grey);
}

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

/* ---------------------------------------------------------------- a phone */
@media (max-width: 560px) {
  :root {
    --card-w: 196px;
    --card-h: 276px;
  }

  .stage {
    padding: 24px 16px;
  }

  .lep__title {
    font-size: 19px;
  }

  .arrow {
    width: 42px;
    height: 42px;
  }

  /* the strip runs to the edges of the screen, the stacks fading only in the margins */
  .lep__view {
    --pad: 28px;
    --pad-low: 70px;
    --fade: 18px;
    margin-left: -16px;
    margin-right: -16px;
  }

  .book {
    padding: 17px 16px 15px;
  }

  .book__title {
    margin-top: 13px;
    font-size: 27px;
  }

  .book__words {
    font-size: 11.5px;
  }

  .book__foot {
    margin-top: 10px;
    padding-top: 8px;
    font-size: 10.5px;
  }
}
