:root {
  --spine-pyramid:
    linear-gradient(315deg, transparent 75%, rgba(255, 255, 255, 0.1) 0),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.1) 0),
    linear-gradient(135deg, rgba(255, 255, 255, 0.2) 166px, transparent 0),
    linear-gradient(45deg, rgba(0, 0, 0, 0.1) 75%, transparent 0);
  background-size: 20px 20px;
  --spine-stairs:
    repeating-linear-gradient(
      63deg,
      rgba(255, 255, 255, 0.1),
      rgba(255, 255, 255, 0.1) 1px,
      transparent 3px,
      transparent 0
    ),
    linear-gradient(
      127deg,
      rgba(255, 255, 255, 0.1),
      rgba(255, 255, 255, 0.1) 90px,
      transparent 55%,
      transparent 0
    ),
    linear-gradient(transparent 51%, rgba(0, 0, 0, 0.1) 170px);
  background-size: 70px 120px;
  --spine-argyle:
    repeating-linear-gradient(
      120deg,
      rgba(255, 255, 255, 0.1),
      rgba(255, 255, 255, 0.1) 1px,
      transparent 1px,
      transparent 60px
    ),
    repeating-linear-gradient(
      60deg,
      rgba(255, 255, 255, 0.1),
      rgba(255, 255, 255, 0.1) 1px,
      transparent 1px,
      transparent 60px
    ),
    linear-gradient(
      60deg,
      rgba(0, 0, 0, 0.1) 25%,
      transparent 25%,
      transparent 75%,
      rgba(0, 0, 0, 0.1) 75%,
      rgba(0, 0, 0, 0.1)
    ),
    linear-gradient(
      120deg,
      rgba(0, 0, 0, 0.1) 25%,
      transparent 25%,
      transparent 75%,
      rgba(0, 0, 0, 0.1) 75%,
      rgba(0, 0, 0, 0.1)
    );
  background-size: 70px 120px;
  --spine-tartan:
    repeating-linear-gradient(
      transparent,
      transparent 50px,
      rgba(0, 0, 0, 0.4) 50px,
      rgba(0, 0, 0, 0.4) 53px,
      transparent 53px,
      transparent 63px,
      rgba(0, 0, 0, 0.4) 63px,
      rgba(0, 0, 0, 0.4) 66px,
      transparent 66px,
      transparent 116px,
      rgba(0, 0, 0, 0.5) 116px,
      rgba(0, 0, 0, 0.5) 166px,
      rgba(255, 255, 255, 0.2) 166px,
      rgba(255, 255, 255, 0.2) 169px,
      rgba(0, 0, 0, 0.5) 169px,
      rgba(0, 0, 0, 0.5) 179px,
      rgba(255, 255, 255, 0.2) 179px,
      rgba(255, 255, 255, 0.2) 182px,
      rgba(0, 0, 0, 0.5) 182px,
      rgba(0, 0, 0, 0.5) 232px,
      transparent 232px
    ),
    repeating-linear-gradient(
      270deg,
      transparent,
      transparent 50px,
      rgba(0, 0, 0, 0.4) 50px,
      rgba(0, 0, 0, 0.4) 53px,
      transparent 53px,
      transparent 63px,
      rgba(0, 0, 0, 0.4) 63px,
      rgba(0, 0, 0, 0.4) 66px,
      transparent 66px,
      transparent 116px,
      rgba(0, 0, 0, 0.5) 116px,
      rgba(0, 0, 0, 0.5) 166px,
      rgba(255, 255, 255, 0.2) 166px,
      rgba(255, 255, 255, 0.2) 169px,
      rgba(0, 0, 0, 0.5) 169px,
      rgba(0, 0, 0, 0.5) 179px,
      rgba(255, 255, 255, 0.2) 179px,
      rgba(255, 255, 255, 0.2) 182px,
      rgba(0, 0, 0, 0.5) 182px,
      rgba(0, 0, 0, 0.5) 232px,
      transparent 232px
    ),
    repeating-linear-gradient(
      125deg,
      transparent,
      transparent 2px,
      rgba(0, 0, 0, 0.2) 2px,
      rgba(0, 0, 0, 0.2) 3px,
      transparent 3px,
      transparent 5px,
      rgba(0, 0, 0, 0.2) 5px
    );
}

.bookshelf-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 7rem 4rem 5.5rem;
}

.bookshelf-page .about-heading {
  margin-top: 0.5rem;
}

.bookshelf {
  width: 100%;
  margin-top: 2.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  row-gap: 3rem;
}

.book {
  width: 50px;
  height: 280px;
  position: relative;
  margin-left: 5px;
  cursor: pointer;
  transform-style: preserve-3d;
  transform-origin: bottom left;
  transform: translateZ(0) rotateY(0);
  transition: transform 0.3s ease;
}

.side {
  position: absolute;
  border: 2px solid black;
  border-radius: 3px;
  font-weight: bold;
  color: black;
  text-align: center;
  transform-origin: center left;
}

.spine {
  position: relative;
  width: 50px;
  height: 280px;
  /* Patterns from: https://projects.verou.me/css3patterns/ — overridden per-book by bookshelf.js */
  background-image: var(--spine-tartan);
  transform: rotateY(0deg) translateZ(0px);
}

.spine-title {
  margin: 2px;
  position: absolute;
  top: 0px;
  left: 0px;
  font-size: 12px;
  color: gold;
  writing-mode: vertical-rl;
  text-orientation: mixed;
}

.spine-author {
  position: absolute;
  color: goldenrod;
  bottom: 0px;
  left: 20%; /* no idea why 20% centers it */
}

.top {
  width: 50px;
  height: 190px;
  top: -2px; /* hmm, why -2 and not 0? */
  background-image: linear-gradient(90deg, white 90%, gray 10%);
  background-size: 5px 5px;
  transform: rotateX(90deg) translateZ(95px) translateY(-95px);
}

.cover {
  width: 190px;
  height: 280px;
  top: 0px;
  background-image: url("https://picsum.photos/190/280");
  background-size: contain;
  background-repeat: round;
  left: 50px;
  transform: rotateY(90deg) translateZ(0);
  transition: transform 1s;
}

.book:hover,
.book:focus-visible {
  z-index: 1;
  transform: translateZ(0) rotateY(-12deg) translateY(-6px);
}

.book:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 6px;
}

.slanted-book {
  --lean-lift: 2px;
  transform: translateZ(0) rotateY(0) rotateZ(var(--lean-angle))
    translateY(var(--lean-lift));
}

/* ── Book detail modal ── */
.book-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.book-modal.is-open {
  opacity: 1;
  pointer-events: auto;
}

.book-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 20, 24, 0.6);
}

.book-modal-content {
  position: relative;
  display: flex;
  gap: 2rem;
  width: 100%;
  max-width: 640px;
  background: var(--bg);
  border-radius: 4px;
  padding: 2.5rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  transform: translateY(12px) scale(0.97);
  transition: transform 0.25s ease;
}

.book-modal.is-open .book-modal-content {
  transform: translateY(0) scale(1);
}

.book-modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 2rem;
  height: 2rem;
  border: none;
  background: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--mid);
  cursor: pointer;
  transition: color 0.2s;
}

.book-modal-close:hover {
  color: var(--accent);
}

.book-modal-cover {
  flex: 0 0 160px;
  height: 240px;
  border-radius: 3px;
  background-size: cover;
  background-position: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}

.book-modal-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.book-modal-author {
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mid);
  margin-bottom: 0.5rem;
}

.book-modal-title {
  font-family: var(--serif);
  font-size: 1.75rem;
  line-height: 1.2;
  color: var(--ink);
  margin-bottom: 1rem;
}

.book-modal-rating {
  color: var(--accent);
  font-size: 1.1rem;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
}

.book-modal-thought {
  font-size: 0.9375rem;
  font-weight: 300;
  color: var(--mid);
  line-height: 1.7;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .bookshelf-page {
    padding: 5.5rem 1.5rem 3.5rem;
  }

  .bookshelf {
    row-gap: 2rem;
    justify-content: center;
  }

  .book-modal-content {
    flex-direction: column;
    padding: 2rem;
  }

  .book-modal-cover {
    flex-basis: auto;
    width: 100%;
    max-width: 200px;
    align-self: center;
  }
}
