/* ---------------------------------------------------------------
   My Bookshelf — styles

   Every rule is scoped under `.bookshelf-page` so that this
   page-specific stylesheet cannot leak into the rest of the site.
   The bookshelf itself is a plain CSS component: no JavaScript.
   --------------------------------------------------------------- */

.bookshelf-page *,
.bookshelf-page *::before,
.bookshelf-page *::after {
  box-sizing: border-box;
}

/* Let the bookshelf content span the full page width, between the site's
   header and footer, instead of the theme's narrow centred column. */
.page-content:has(.bookshelf-page) .wrapper {
  max-width: none;
  padding: 0;
}

.bookshelf-page {
  /* Palette and typography, scoped to the page. */
  --ink: #2b241c;
  --ink-soft: #6d5f4f;
  --rust: #9c4a29;
  --fine-print: 0.7rem;
  /* Default spine height for books that don't set their own `height`. */
  --book-height: 61cqh;

  max-width: none;
  margin: 0;
  padding: clamp(1.25rem, 3vw, 2.5rem) clamp(1rem, 4vw, 3rem) 1rem;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------------------------------------------------------------
   Shelf
   --------------------------------------------------------------- */

.bookshelf-page .shelf-section {
  margin-top: 0;
}

.bookshelf-page .shelf {
  position: relative;
  width: 75%;
  max-width: none;
  margin: 0 auto;
  aspect-ratio: 1600 / 700;
  background: url("shelf.svg") center / 100% 100% no-repeat;
  border-radius: 5px;
  container-type: size;
  isolation: isolate;
}

/*
   Books are absolutely positioned on the shelf.
   --x      left edge, % of shelf width
   --h      height, % of shelf height (cqh); falls back to --book-height
   --ar     spine image aspect ratio (width / height)
   --bottom distance from the bottom, % of shelf height
*/
.bookshelf-page .book {
  position: absolute;
  left: var(--x, 5%);
  bottom: var(--bottom, 13.5%);
  height: var(--h, var(--book-height));
  width: calc(var(--h, var(--book-height)) / var(--ar, 10));
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  overflow: visible;
  -webkit-tap-highlight-color: transparent;
  z-index: 1;
}

.bookshelf-page .book:hover,
.bookshelf-page .book:focus-visible {
  z-index: 5;
}

.bookshelf-page .book:focus-visible {
  outline: 2px solid var(--rust);
  outline-offset: 2px;
}

.bookshelf-page .book .spine-art {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 2px 2px 1px 1px;
  background: #cdbfa9;
}

.bookshelf-page .book .spine-img {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--h, 60cqh);
  height: auto;
  max-width: none;
  display: block;
  transform: translate(-50%, -50%) rotate(90deg);
  user-select: none;
  -webkit-user-drag: none;
}

/* Cover shown to the right of the spine while it is hovered or focused.
   No animation. */
.bookshelf-page .book .cover-preview {
  display: none;
  position: absolute;
  bottom: 0;
  left: calc(100% + 0.4rem);
  height: 70cqh;
  width: auto;
  max-width: none;
  z-index: 2;
  user-select: none;
  -webkit-user-drag: none;
}

.bookshelf-page .book:hover .cover-preview,
.bookshelf-page .book:focus-visible .cover-preview {
  display: block;
}

/* Kindle standing at the end of the shelf (75% of --book-height). The frame
   has a transparent screen, so the screen image shows through it. */
.bookshelf-page .kindle {
  position: absolute;
  left: 80%;
  bottom: 13.5%;
  height: calc(var(--book-height) * 0.75);
  aspect-ratio: 632 / 900;
  z-index: 1;
}

/* Frame + screen pairing, shared by the shelf and the grid card. */
.bookshelf-page .kindle-frame,
.bookshelf-page .kindle-screen {
  position: absolute;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.bookshelf-page .kindle-frame {
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
}

/* Pre-warped to sit exactly over the screen inside the frame. */
.bookshelf-page .kindle-screen {
  left: 12.82%;
  top: 8.56%;
  width: 70.1%;
  height: 72.22%;
  z-index: 1;
}

/* Every Kindle book's screen is rendered up front, stacked; only the active
   one is shown. Toggling `is-active` (by script) swaps the book. */
.bookshelf-page .kindle-screen {
  display: none;
}

.bookshelf-page .kindle-screen.is-active {
  display: block;
}

/* The Kindle is a button: click it (or press Enter/Space) for the next book. */
.bookshelf-page .kindle,
.bookshelf-page .kindle-thumb {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.bookshelf-page .kindle:focus-visible,
.bookshelf-page .kindle-thumb:focus-visible {
  outline: 2px solid var(--rust);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Visible only to assistive tech (announces the book now on screen). */
.bookshelf-page .visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------
   Cover grid
   --------------------------------------------------------------- */

.bookshelf-page .collection {
  margin-top: clamp(1.75rem, 4vw, 2.75rem);
}

.bookshelf-page .cover-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 190px));
  justify-content: start;
  gap: clamp(1.5rem, 3vw, 2.25rem) clamp(1rem, 2.2vw, 1.6rem);
  margin: 0;
  padding: 0;
  list-style: none;
}

.bookshelf-page .cover-card > img {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 2px;
  background: #e0d6c6;
}

/* The Kindle card's frame + screen fill a box matching the photo's ratio. */
.bookshelf-page .kindle-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 632 / 900;
}

/* ---------------------------------------------------------------
   Footer
   --------------------------------------------------------------- */

.bookshelf-page .page-footer {
  display: grid;
  justify-items: center;
  gap: 0.75rem;
  margin-top: clamp(1.75rem, 4vw, 2.5rem);
}

.bookshelf-page .disclaimer {
  display: grid;
  gap: 0.4rem;
  max-width: 62ch;
  text-align: center;
}

.bookshelf-page .disclaimer p {
  margin: 0;
  font-size: var(--fine-print);
  line-height: 1.5;
  color: var(--ink-soft);
}

.bookshelf-page .disclaimer strong {
  color: var(--ink);
  font-weight: 600;
}

.bookshelf-page .disclaimer code {
  padding: 0.1em 0.3em;
  border-radius: 3px;
  background: rgba(43, 36, 28, 0.06);
  font-size: 0.92em;
}

.bookshelf-page .inspired {
  margin: 0;
  font-size: var(--fine-print);
  color: var(--ink-soft);
  text-align: center;
}

.bookshelf-page .inspired a {
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, currentColor 35%, transparent);
  padding-bottom: 1px;
}

.bookshelf-page .inspired a:hover {
  border-bottom-color: currentColor;
}

/* ---------------------------------------------------------------
   Responsive
   --------------------------------------------------------------- */

@media (max-width: 640px) {
  .bookshelf-page .cover-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }

  .bookshelf-page .shelf {
    border-radius: 3px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bookshelf-page *,
  .bookshelf-page *::before,
  .bookshelf-page *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
