:root {
  --ink: #1c1a17;
  --paper: #fbf9f4;
  --muted: #6d675e;
  --rule: #e2dcd0;

  /* bookcase */
  --wood-light: #a9814f;
  --wood: #8a6641;
  --wood-dark: #5d4228;
  --cavity: #201a14;

  /* Everything a book is made of multiplies by this, so one value shrinks
     the whole bookcase on small screens. */
  --scale: 1;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #eae6df;
    --paper: #161513;
    --muted: #9c958a;
    --rule: #33302b;
    --wood-light: #8e6b41;
    --wood: #6f5334;
    --wood-dark: #46311d;
    --cavity: #14100c;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0 auto;
  padding: 3rem 1.5rem 4rem;
  max-width: 46rem;
  background: var(--paper);
  color: var(--ink);
  font: 1rem/1.6 ui-serif, Georgia, "Times New Roman", serif;
}

a {
  color: inherit;
}

.wordmark {
  display: inline-block;
  margin-bottom: 2rem;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-decoration: none;
}

.count,
.byline,
.status {
  color: var(--muted);
  font-size: 0.875rem;
}

/* The count lines read as one block, so no gap between them. */
.count {
  margin: 0;
}

/* ---------- the bookcase ---------- */

.bookcase {
  margin: 1.5rem 0 3rem;
  padding: 0.75rem 0.75rem 0.25rem;
  border-radius: 4px;
  background: linear-gradient(100deg, var(--wood-dark), var(--wood) 30%, var(--wood-light) 55%, var(--wood-dark));
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.18) inset,
    0 24px 40px -28px rgba(0, 0, 0, 0.7);
}

.shelf {
  position: relative;
}

/* The recess the books stand in: darker at the back, lit from above.
   A shelf that runs out of room scrolls sideways rather than clipping, the
   way you'd pan along a real one. The generous top padding leaves headroom
   for a book to lift on hover without the scroll container cutting it off. */
.shelf__books {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  min-height: calc(232px * var(--scale));
  padding: 2.25rem 1.25rem 0;
  border-radius: 2px 2px 0 0;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.12) 38%, rgba(0, 0, 0, 0.35)),
    var(--cavity);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  /* Hidden because the cut-off book at the edge is the affordance. */
  scrollbar-width: none;
}

.shelf__books::-webkit-scrollbar {
  display: none;
}

.shelf__plank {
  height: 13px;
  border-radius: 0 0 3px 3px;
  background: linear-gradient(180deg, var(--wood-light), var(--wood) 35%, var(--wood-dark));
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.25) inset,
    0 10px 16px -10px rgba(0, 0, 0, 0.75);
}

.shelf__label {
  margin: 0.4rem 0 1.1rem;
  text-align: right;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.5);
}

.shelf:last-child .shelf__label {
  margin-bottom: 0.5rem;
}

/* The top shelf gets a brass label to mark it out. */
.shelf--favorites .shelf__label {
  color: #e3c58d;
}

.shelf--favorites .shelf__label::before {
  content: "★ ";
  opacity: 0.7;
}

.shelf__empty {
  align-self: center;
  margin: auto;
  font-size: 0.8rem;
  font-style: italic;
  color: rgba(255, 255, 255, 0.3);
}

/* ---------- a book ---------- */

.book {
  position: relative;
  flex: 0 0 auto;
  width: calc(var(--w) * var(--scale));
  height: calc(var(--h) * var(--scale));
  scroll-snap-align: start;
  border-radius: 2px 3px 3px 2px;
  /* Cylindrical shading down the spine, plus the page block peeking out. */
  background-image:
    linear-gradient(
      90deg,
      rgba(0, 0, 0, 0.42) 0,
      rgba(0, 0, 0, 0.06) 7%,
      rgba(255, 255, 255, 0.16) 24%,
      rgba(255, 255, 255, 0.03) 52%,
      rgba(0, 0, 0, 0.2) 88%,
      rgba(0, 0, 0, 0.45) 100%
    );
  background-color: var(--cloth);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.35) inset,
    0 8px 12px -7px rgba(0, 0, 0, 0.8);
  /* It is a <button>, so undo the control styling. */
  appearance: none;
  border: none;
  padding: 0;
  font: inherit;
  cursor: pointer;
  transform-origin: 50% 100%;
  transition:
    transform 0.4s cubic-bezier(0.22, 0.8, 0.2, 1),
    box-shadow 0.4s ease;
}

/* Foil rules at the head and tail of the spine. */
.book::before,
.book::after {
  content: "";
  position: absolute;
  left: 5px;
  right: 5px;
  height: 1px;
  background: var(--foil);
  opacity: 0.55;
}

.book::before {
  top: 12px;
  box-shadow: 0 3px 0 var(--foil);
}

.book::after {
  bottom: 12px;
  box-shadow: 0 -3px 0 var(--foil);
}

.book__spine {
  position: absolute;
  inset: calc(26px * var(--scale)) 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3em;
  writing-mode: vertical-rl;
  text-orientation: mixed;
}

.book__title,
.book__author {
  max-height: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--foil);
}

.book__title {
  /* Scales with the spine so the lettering never outgrows its thickness. */
  font-size: calc(0.7rem * var(--scale));
  letter-spacing: 0.035em;
}

.book__author {
  font-size: calc(0.58rem * var(--scale));
  letter-spacing: 0.02em;
  opacity: 0.62;
}

.book:focus-visible {
  transform: translateY(-14px) rotate(-1.2deg);
  outline: 2px solid var(--foil);
  outline-offset: 3px;
}

/* Pulled out while its peek panel is open. */
.book.is-pulled {
  transform: translateY(-26px) rotate(-2.5deg);
}

/* ---------- face-out display book ---------- */

.book--face {
  /* Width comes from the cover frame, not the spine thickness. */
  width: auto;
  height: calc(206px * var(--scale));
  aspect-ratio: var(--ratio, 2 / 3);
  margin: 0 14px 0 8px;
  background-image: none;
  background-color: #14100c;
  /* Angled just off square, as if resting back against the shelf. */
  transform: perspective(900px) rotateY(-10deg);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.5) inset,
    0 12px 20px -9px rgba(0, 0, 0, 0.9);
}

.book__cover {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  /* Crops any aspect ratio into the frame without distorting the art. */
  object-fit: cover;
}

/* No foil rules on a cover; ::after becomes the page block instead. */
.book--face::before {
  display: none;
}

.book--face::after {
  top: 3px;
  right: auto;
  bottom: 3px;
  left: 100%;
  width: 8px;
  height: auto;
  border-radius: 0 2px 2px 0;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.5), #d9cfba 45%, #b5aa93);
  box-shadow: none;
  opacity: 1;
  transform: perspective(600px) rotateY(26deg);
  transform-origin: left center;
}

.book--face:focus-visible {
  transform: perspective(900px) rotateY(-10deg) translateY(-14px);
}

.book--face.is-pulled {
  transform: perspective(900px) rotateY(-4deg) translateY(-22px) scale(1.02);
}

/* Lift on hover only where there is a real pointer. On a touchscreen a tap
   leaves :hover stuck on, so the book would stay pulled out after closing. */
@media (hover: hover) {
  .book:hover {
    transform: translateY(-14px) rotate(-1.2deg);
    box-shadow:
      0 0 0 1px rgba(0, 0, 0, 0.35) inset,
      0 18px 22px -12px rgba(0, 0, 0, 0.85);
  }

  .book--face:hover {
    transform: perspective(900px) rotateY(-10deg) translateY(-14px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .book {
    transition: none;
  }
}

/* ---------- peek panel ---------- */

.peek {
  /* Fills a phone screen minus a margin, but never grows past 24rem. */
  width: calc(100vw - 2rem);
  max-width: 24rem;
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  margin: auto;
  padding: 2rem 2.25rem;
  border: none;
  border-radius: 3px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.6);
}

.peek::backdrop {
  background: rgba(16, 12, 8, 0.6);
  backdrop-filter: blur(2px);
}

.peek__cover {
  display: block;
  width: 7.5rem;
  aspect-ratio: 2 / 3;
  margin: 0 0 1.25rem;
  border-radius: 2px;
  object-fit: cover;
  box-shadow: 0 10px 18px -10px rgba(0, 0, 0, 0.7);
}

.peek__title {
  margin: 0 0 0.25rem;
  font-size: 1.4rem;
  line-height: 1.25;
}

.peek__close {
  position: absolute;
  top: 0.4rem;
  right: 0.7rem;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.notes {
  margin: 1.5rem 0;
  border-left: 2px solid var(--rule);
  padding-left: 1rem;
}

.peek .notes:last-child {
  margin-bottom: 0;
}

footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  margin-top: 3rem;
  border-top: 1px solid var(--rule);
  padding-top: 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Separator only shows when the note sits on the same line as the link. */
.footer__note::before {
  content: "·";
  margin-right: 0.75rem;
}

@media (max-width: 34rem) {
  footer {
    flex-direction: column;
  }

  .footer__note::before {
    content: none;
  }
}

/* ---------- phones ---------- */

@media (max-width: 34rem) {
  :root {
    /* Smaller books, so more of a shelf fits before it needs scrolling. */
    --scale: 0.84;
  }

  body {
    padding: 2rem 1rem 3rem;
  }

  .wordmark {
    margin-bottom: 1.5rem;
  }

  .bookcase {
    /* Bleeds to the screen edges so the shelves feel wider than the phone. */
    margin: 1.25rem -1rem 2rem;
    padding: 0.5rem 0.4rem 0.2rem;
    border-radius: 0;
  }

  .shelf__books {
    padding: 2rem 0.75rem 0;
  }

  .shelf__label {
    margin: 0.35rem 0.25rem 0.9rem;
  }

  .peek {
    padding: 1.75rem 1.4rem;
  }

  .peek__cover {
    width: 6.5rem;
  }
}
