/* The filling shelf: a bookcase niche painted deep green on a white page, an oak shelf, two brass bookends and the
   audiobooks as cloth-bound books. The books are built by script.js; their cloth, their titles and the light are
   plain CSS with these colours. */
:root {
  --page: #ffffff;          /* the page */
  --niche: #15302d;         /* the inside of the bookcase */
  --niche-lit: #24463f;     /* where the light above the shelf falls on it */
  --ink: #f4ecde;           /* the words */
  --muted: #a3b8b0;         /* the quieter words */
  --error: #ffa58f;         /* the words that say what went wrong */
  --button: #f4ecde;        /* the main button */
  --button-ink: #14302c;    /* its words */
  --ring: rgba(244, 236, 222, 0.3);   /* the ring round the quiet buttons */
  --focus: #f0d38a;         /* the keyboard's focus ring */
  --oak: #d3a468;           /* the top of the shelf */
  --oak-front: #a8743f;     /* its front edge */
  --brass-hi: #f3dc9c;      /* the bookends where the light catches them */
  --brass-lo: #94692b;      /* the bookends in shadow */
  --gilt-hi: #fff2c2;       /* the gold titles: the bright of the foil */
  --gilt: #dcb560;          /* the gold titles */
  --gilt-lo: #9c7531;       /* the gold titles: the dark of the foil */
  --lamp: rgba(255, 198, 128, 0.5);    /* the light that comes on in the bookcase when every book is in */
  --ghost: rgba(244, 236, 222, 0.1);  /* a book still to download: glass */
  --ghost-line: rgba(244, 236, 222, 0.38);   /* and its edge */
  --ghost-fail: rgba(255, 140, 112, 0.24);   /* the glass of a book that failed */
  --cloth-1: #923439;       /* the cloth of the books, from the left */
  --cloth-2: #2f4c80;
  --cloth-3: #d6a33e;
  --cloth-4: #6c4479;
  --cloth-5: #a9b79d;
  --cloth-6: #b34d36;
  --cloth-7: #e7dbc1;
  --cloth-8: #3d6c8b;
  --cloth-9: #cd8b85;
  --cloth-10: #2f5a43;
  --print: #1d1a16;         /* the dark titles on the pale cloths */
  --stripe: #a8322f;        /* the red bands on the ivory book */
}

* {
  box-sizing: border-box;
}

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

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

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Bricolage Grotesque Variable', system-ui, sans-serif;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
}

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

.stage {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}

/* ---------------------------------------------------------------- the niche */
.shelf {
  --pad: 24px;
  position: relative;
  width: min(400px, 100%);
  padding: 18px 0 16px;
  overflow: hidden;
  border-radius: 24px;
  background:
    radial-gradient(120% 70% at 50% 18%, var(--niche-lit), transparent 70%),
    var(--niche);
  box-shadow:
    inset 0 14px 22px -12px rgba(0, 0, 0, 0.55),
    inset 10px 0 18px -14px rgba(0, 0, 0, 0.5),
    inset -10px 0 18px -14px rgba(0, 0, 0, 0.5);
}

/* the light in the bookcase, off until the last book is in: it falls on the back behind the books, down to the shelf */
.shelf__light {
  position: absolute;
  top: -64px;
  right: 0;
  bottom: 18px;
  left: 0;
  background: radial-gradient(58% 80% at 50% 82%, var(--lamp), color-mix(in srgb, var(--lamp) 36%, transparent) 48%, transparent 76%);
  opacity: 0;
  pointer-events: none;
}

.shelf__head,
.shelf__case,
.shelf__foot {
  position: relative;
}

.shelf__head,
.shelf__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 var(--pad);
}

.shelf__head {
  align-items: flex-start;
}

.shelf__status,
.shelf__list {
  min-width: 0;
}

.shelf p,
.shelf h2 {
  margin: 0;
}

.shelf__phase {
  height: 20px;
  overflow: hidden;
  font-size: 15px;
  font-weight: 620;
  font-stretch: 94%;
  line-height: 20px;
  letter-spacing: -0.006em;
  white-space: nowrap;
}

.shelf__phase .is-error {
  color: var(--error);
}

.shelf__note {
  height: 18px;
  margin-top: 1px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  font-weight: 450;
  line-height: 18px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* the words that change slide in by themselves; a long one ends in an ellipsis */
.shelf__swap {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: top;
}

/* the big figure: the size, the percentage, and the tick at the end */
.shelf__big {
  position: relative;
  flex: none;
  min-width: 64px;
  height: 39px;
  font-size: 32px;
  font-weight: 700;
  font-stretch: 80%;
  line-height: 39px;
  letter-spacing: -0.02em;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.shelf__big .shelf__swap {
  overflow: visible;
}

.shelf__big small {
  margin-left: 1px;
  font-size: 0.5em;
  font-weight: 620;
  font-stretch: 100%;
  letter-spacing: 0;
  vertical-align: 0.66em;
}

.shelf__big.is-quiet {
  color: var(--muted);
}

.shelf__tick {
  position: absolute;
  top: 2px;
  right: -3px;
  width: 36px;
  height: 36px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  visibility: hidden;
}

/* ---------------------------------------------------------------- the shelf */
.shelf__case {
  position: relative;
  margin-top: 6px;
}

/* the books stand on the shelf between the bookends; x = 0 is the face of the bookend on the left */
.shelf__row {
  --sx: -200px;
  position: relative;
  height: 92px;
  margin: 0 calc(var(--pad) + 9px);
}

.bookend {
  position: absolute;
  bottom: 0;
  width: 5px;
  height: 46px;
  border-radius: 3px 3px 0 0;
  background: linear-gradient(90deg, var(--brass-lo), var(--brass-hi) 45%, var(--brass-lo));
  box-shadow: 0 -1px 0 rgba(255, 255, 255, 0.35) inset;
}

/* the foot of each bookend runs under the books */
.bookend::after {
  content: '';
  position: absolute;
  bottom: 0;
  width: 30px;
  height: 3px;
  border-radius: 1px;
  background: linear-gradient(180deg, var(--brass-hi), var(--brass-lo));
}

.bookend--start {
  left: -5px;
}

.bookend--start::after {
  left: 0;
}

.bookend--end::after {
  right: 0;
}

/* the oak board: its top seen from just above, and its front edge with the grain */
.shelf__board {
  position: relative;
  height: 18px;
  background:
    linear-gradient(180deg, var(--oak) 0 5px, transparent 5px),
    linear-gradient(180deg, transparent 8px, rgba(255, 255, 255, 0.07) 8px 9px, transparent 9px 12px, rgba(0, 0, 0, 0.08) 12px 13px, transparent 13px),
    linear-gradient(97deg, transparent 18%, rgba(0, 0, 0, 0.06) 30%, transparent 44%, rgba(255, 255, 255, 0.05) 63%, transparent 80%),
    linear-gradient(180deg, var(--oak-front), color-mix(in srgb, var(--oak-front) 70%, #000) 100%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.18) inset,
    0 6px 0 -5px rgba(255, 255, 255, 0.28) inset,
    0 12px 18px -6px rgba(0, 0, 0, 0.5);
}

/* ---------------------------------------------------------------- a book */
.book {
  position: absolute;
  bottom: 0;
  left: 0;
  width: var(--t);
  height: var(--h);
  border-radius: 2px 2px 1px 1px;
  transform-origin: 0 100%;
  opacity: 0;
  will-change: transform, opacity;
}

.book__ghost,
.book__cloth,
.book__shade,
.book__sheen {
  position: absolute;
  inset: 0;
  border-radius: inherit;
}

/* still to download: a book of glass with its title pressed in blind */
.book__ghost {
  background: var(--ghost);
  box-shadow: inset 0 0 0 1px var(--ghost-line);
  transition: background-color 0.4s ease;
}

.book.is-failed .book__ghost {
  background: var(--ghost-fail);
  box-shadow: inset 0 0 0 1px var(--error);
}

/* the cloth comes up from the bottom as the bytes arrive (the clip reaches past the sides for its shadow) */
.book__cloth {
  background: var(--cloth);
  clip-path: inset(calc((1 - var(--f, 0)) * 100%) -12px -12px -12px);
  box-shadow: 3px 0 6px -2px rgba(0, 0, 0, 0.45);
}

/* the edge of the cloth while it comes up */
.book__cloth::after {
  content: '';
  position: absolute;
  top: calc((1 - var(--f, 0)) * 100%);
  left: 0;
  right: 0;
  height: 1px;
  background: rgba(255, 255, 255, 0.55);
  opacity: calc(min(var(--f, 0), 1 - var(--f, 0)) * 40);
}

/* the round of the spine, and the light from above */
.book__shade {
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent 22%),
    linear-gradient(90deg, rgba(0, 0, 0, 0.32), rgba(255, 255, 255, 0.14) 28%, rgba(255, 255, 255, 0.02) 56%, rgba(0, 0, 0, 0.34));
  clip-path: inset(calc((1 - var(--f, 0)) * 100%) 0 0 0);
}

/* at the end one light runs over all the spines: the same band on every book, shifted by where the book stands */
.book__sheen {
  pointer-events: none;
  background: linear-gradient(90deg,
    transparent calc(var(--sx) - var(--bx, 0px) - 30px),
    rgba(255, 240, 200, 0.75) calc(var(--sx) - var(--bx, 0px)),
    transparent calc(var(--sx) - var(--bx, 0px) + 30px));
  mix-blend-mode: overlay;
}

/* the title runs down the spine */
.book__title {
  position: absolute;
  top: 50%;
  left: 50%;
  margin: 0;
  font-family: var(--face, 'Fraunces Variable'), Georgia, serif;
  font-size: var(--fs, 9px);
  font-weight: var(--fw, 600);
  font-stretch: var(--fx, 100%);
  line-height: 1;
  letter-spacing: var(--ls, 0.08em);
  text-transform: var(--case, uppercase);
  white-space: nowrap;
  writing-mode: vertical-rl;
  transform: translate(-50%, -50%);
}

/* two lines, side by side down the spine */
.book__title.is-two {
  line-height: 1.12;
  text-align: center;
}

.book__ghost .book__title {
  color: rgba(244, 236, 222, 0.32);
}

.book__cloth .book__title {
  color: var(--print);
}

/* gold foil: a gradient across the letters */
.is-gilt .book__cloth .book__title,
.is-gilt .book__cloth .book__band {
  color: transparent;
  background: linear-gradient(90deg, var(--gilt-lo), var(--gilt-hi) 48%, var(--gilt) 70%, var(--gilt-lo));
  -webkit-background-clip: text;
  background-clip: text;
}

/* the bands across the head and the tail of the spine */
.book__band {
  position: absolute;
  left: 3px;
  right: 3px;
  height: var(--bh, 2px);
  border-radius: 1px;
}

.book__band--head {
  top: 5px;
}

.book__band--tail {
  bottom: 5px;
}

.book__ghost .book__band {
  box-shadow: inset 0 0 0 1px rgba(244, 236, 222, 0.22);
}

.book__cloth .book__band {
  background: var(--band, var(--print));
}

.is-gilt .book__cloth .book__band {
  background: linear-gradient(90deg, var(--gilt-lo), var(--gilt-hi) 48%, var(--gilt));
  -webkit-background-clip: border-box;
  background-clip: border-box;
}

/* a label panel on the spine, for the books that have one */
.book__label {
  position: absolute;
  top: 18%;
  bottom: 18%;
  left: 4px;
  right: 4px;
  border-radius: 1px;
}

.book__cloth .book__label {
  background: var(--label);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.book__ghost .book__label {
  box-shadow: inset 0 0 0 1px rgba(244, 236, 222, 0.2);
}

/* the soft shadow of a book on the oak */
.book-shadow {
  position: absolute;
  bottom: -3px;
  left: 0;
  height: 6px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.45), transparent);
  opacity: 0;
  pointer-events: none;
}

/* ---------------------------------------------------------------- the spines, one by one */
.book[data-k='0'] { --cloth: var(--cloth-1); --bh: 3px; }
.book[data-k='1'] { --cloth: var(--cloth-2); --face: 'Bricolage Grotesque Variable'; --fw: 700; --fx: 78%; --ls: 0.12em; --bh: 4px; }
.book[data-k='2'] { --cloth: var(--cloth-3); --label: #22201c; --ls: 0.1em; }
.book[data-k='3'] { --cloth: var(--cloth-4); --case: none; --fs: 10.5px; --fw: 560; --ls: 0.01em; --bh: 1.5px; }
.book[data-k='4'] { --cloth: var(--cloth-5); --face: 'Bricolage Grotesque Variable'; --fw: 680; --fx: 80%; --ls: 0.14em; --bh: 1.5px; }
.book[data-k='5'] { --cloth: var(--cloth-6); --bh: 3px; }
.book[data-k='6'] { --cloth: var(--cloth-7); --band: var(--stripe); --case: none; --fs: 10.5px; --fw: 640; --ls: 0.01em; --bh: 5px; }
.book[data-k='7'] { --cloth: var(--cloth-8); --face: 'Bricolage Grotesque Variable'; --fw: 640; --fx: 76%; --ls: 0.16em; --bh: 1.5px; }
.book[data-k='8'] { --cloth: var(--cloth-9); --face: 'Bricolage Grotesque Variable'; --fw: 720; --fx: 84%; --ls: 0.1em; --bh: 0px; }
.book[data-k='9'] { --cloth: var(--cloth-10); --case: none; --fs: 10.5px; --fw: 600; --ls: 0.02em; --bh: 2px; }

/* the label on the mustard book carries a gold title */
.book[data-k='2'] .book__cloth .book__title {
  color: transparent;
  background: linear-gradient(90deg, var(--gilt-lo), var(--gilt-hi) 48%, var(--gilt) 70%, var(--gilt-lo));
  -webkit-background-clip: text;
  background-clip: text;
}

@media (max-width: 420px) {
  .shelf {
    --pad: 20px;
  }
}

/* ---------------------------------------------------------------- the list and the buttons */
.shelf__foot {
  margin-top: 14px;
}

.shelf__title {
  overflow: hidden;
  font-size: 14px;
  font-weight: 640;
  line-height: 18px;
  letter-spacing: -0.004em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shelf__meta {
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  font-weight: 450;
  line-height: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.shelf__buttons {
  display: flex;
  flex: none;
  gap: 8px;
}

/* the pills: the fill is a layer of its own that swells past the edge with a bounce, and the words widen on the
   width axis of the font; pressed, they squash a little */
.pill {
  position: relative;
  display: inline-grid;
  place-items: center;
  height: 44px;
  min-width: 44px;
  padding: 0 19px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--button-ink);
  font: inherit;
  font-size: 14px;
  font-weight: 640;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  transition: color 0.25s ease, opacity 0.25s ease;
}

.pill[hidden] {
  display: none;
}

.pill::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--button);
  transition: inset 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.25s ease, box-shadow 0.25s ease;
}

.pill__label {
  display: inline-block;
  font-stretch: 88%;
  transition: font-stretch 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* the quiet ones: while the download runs the main button only pauses it */
.pill.is-quiet,
.pill--icon {
  color: var(--ink);
}

.pill.is-quiet::before,
.pill--icon::before {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--ring);
}

.pill--icon {
  width: 44px;
  padding: 0;
}

.pill--icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

/* while the books are being put away there is nothing to press */
.pill[aria-disabled='true'] {
  cursor: default;
  opacity: 0.45;
}

@media (hover: hover) and (pointer: fine) {
  .pill:not([aria-disabled='true']):hover::before {
    inset: -2px -5px;
  }

  .pill:not([aria-disabled='true']):hover .pill__label {
    font-stretch: 100%;
  }

  .pill.is-quiet:not([aria-disabled='true']):hover::before,
  .pill--icon:not([aria-disabled='true']):hover::before {
    background: rgba(244, 236, 222, 0.1);
  }

  .pill--icon:not([aria-disabled='true']):hover::before {
    inset: -3px;
  }
}

.pill:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .pill::before,
  .pill__label {
    transition: none;
  }
}
