.bookshelf {
  margin-block: 1rem 2.5rem;
}

.bookshelf-section {
  clear: both;
  margin: 0;
}

.bookshelf-section + .bookshelf-section {
  margin-block-start: 1.5rem;
}

.bookshelf-section__title {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-block-end: 0.55rem;
  color: var(--text-muted-color, inherit);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-decoration: none;
  text-transform: uppercase;
}

.bookshelf-section__title::after {
  flex: 1;
  height: 1px;
  background: var(--main-border-color, rgb(128 128 128 / 35%));
  content: "";
}

.bookshelf-section__title:hover {
  color: var(--link-color);
}

.bookshelf-covers .gr_grid_container,
.book-wall:not(.is-ready) .gr_grid_container {
  display: flex;
  align-items: flex-end;
  gap: 0.55rem;
  padding: 0.25rem 0.25rem 0.8rem;
  border-block-end: 4px solid var(--main-border-color, rgb(128 128 128 / 35%));
  box-shadow: 0 4px 5px -5px var(--kbd-wrap-color, rgb(0 0 0 / 30%));
}

.bookshelf-covers .gr_grid_container {
  overflow-x: auto;
  scrollbar-width: thin;
}

.book-wall:not(.is-ready) .gr_grid_container {
  flex-wrap: wrap;
}

.bookshelf-covers .gr_grid_book_container,
.book-wall:not(.is-ready) .gr_grid_book_container {
  display: flex;
  float: none;
  flex: 0 0 96px;
  width: 96px;
  height: 160px;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  overflow: hidden;
}

.bookshelf-covers .gr_grid_book_container {
  transition: transform 160ms ease;
}

.bookshelf-covers .gr_grid_book_container:hover,
.bookshelf-covers .gr_grid_book_container:focus-within {
  transform: translateY(-4px);
}

.bookshelf-covers .gr_grid_book_container img,
.book-wall:not(.is-ready) .gr_grid_book_container img {
  width: auto;
  max-width: 96px;
  height: auto;
  max-height: 156px;
  box-shadow: 2px 3px 6px var(--kbd-wrap-color, rgb(0 0 0 / 30%));
}

.book-wall {
  overflow: visible;
}

.book-wall.is-ready .gr_grid_container {
  --shelf-row-height: 196px;

  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(32px, 40px));
  grid-auto-rows: var(--shelf-row-height);
  min-height: var(--shelf-row-height);
  align-items: flex-end;
  justify-content: center;
  column-gap: 3px;
  padding-inline: 0.5rem;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(var(--shelf-row-height) - 13px),
    var(--main-border-color, rgb(128 128 128 / 35%)) calc(var(--shelf-row-height) - 13px),
    var(--main-border-color, rgb(128 128 128 / 35%)) calc(var(--shelf-row-height) - 9px),
    rgb(0 0 0 / 10%) calc(var(--shelf-row-height) - 9px),
    transparent calc(var(--shelf-row-height) - 5px),
    transparent var(--shelf-row-height)
  );
}

.book-wall.is-ready .gr_grid_book_container {
  --spine-color: #73513b;
  --spine-tone: #886a55;
  --spine-highlight: #8b705d;
  --spine-accent: #5f4433;
  --spine-shadow: #513929;
  --spine-ink: #fff;

  position: relative;
  float: none;
  width: 100%;
  height: 168px;
  margin-block-end: 13px;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgb(0 0 0 / 30%);
  border-radius: 3px 3px 1px 1px;
  background: linear-gradient(
    90deg,
    var(--spine-shadow) 0,
    var(--spine-color) 10%,
    var(--spine-tone) 34%,
    var(--spine-highlight) 56%,
    var(--spine-color) 74%,
    var(--spine-accent) 90%,
    var(--spine-shadow) 100%
  );
  box-shadow:
    inset 1px 0 rgb(255 255 255 / 12%),
    inset -1px 0 rgb(0 0 0 / 12%),
    1px 2px 3px rgb(0 0 0 / 24%);
  transition: transform 160ms ease, box-shadow 160ms ease;
}

.book-wall.is-ready .gr_grid_book_container:nth-child(3n + 1) {
  height: 176px;
}

.book-wall.is-ready .gr_grid_book_container:nth-child(4n + 2) {
  height: 158px;
}

.book-wall.is-ready .gr_grid_book_container:nth-child(5n + 3) {
  height: 181px;
}

.book-wall.is-ready .gr_grid_book_container:nth-child(6n + 4) {
  height: 164px;
}

.book-wall.is-ready .gr_grid_book_container:hover,
.book-wall.is-ready .gr_grid_book_container:focus-within {
  z-index: 1;
  box-shadow:
    inset 1px 0 rgb(255 255 255 / 16%),
    inset -1px 0 rgb(0 0 0 / 16%),
    2px 4px 6px rgb(0 0 0 / 32%);
  transform: translateY(-4px);
}

.book-wall.is-ready .gr_grid_book_container a {
  display: block;
  width: 100%;
  height: 100%;
  color: var(--spine-ink);
  text-decoration: none;
}

.book-wall.is-ready .gr_grid_book_container a:focus-visible {
  outline: 3px solid var(--link-color);
  outline-offset: -4px;
}

.book-wall.is-ready .gr_grid_book_container img {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.book-spine__label {
  box-sizing: border-box;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0.65rem 0.35rem;
  overflow: hidden;
  color: var(--spine-ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(0.62rem, 1.4vw, 0.75rem);
  line-height: 1.15;
  letter-spacing: 0.02em;
  text-align: start;
  text-shadow: 0 1px 1px rgb(0 0 0 / 28%);
  text-orientation: mixed;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.book-spine__title {
  font-weight: 600;
}

.book-spine__author {
  font-size: 0.82em;
  font-style: italic;
  opacity: 0.82;
}

@media (max-width: 480px) {
  .bookshelf-covers .gr_grid_container {
    gap: 0.4rem;
  }

  .book-wall.is-ready .gr_grid_container {
    grid-template-columns: repeat(auto-fit, minmax(30px, 36px));
    column-gap: 2px;
    padding-inline: 0.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bookshelf-covers .gr_grid_book_container,
  .book-wall.is-ready .gr_grid_book_container {
    transition: none;
  }
}
