/* bookshelf.css — styles for the "vanity" cover-wall view.
   Kept in its own file and namespaced under .shelf-* / .bd-* so it
   cannot collide with the .book-card rules used by index.php. */

/* ============================================================
   Layout shell
   ============================================================ */
.shelf-wrap {
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 18px 60px;
}

.shelf-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 0 0 6px;
}

.shelf-controls input[type="text"] {
  min-width: 280px;
  padding: 9px 12px;
  font: inherit;
  font-size: 14px;
  border: 1px solid #cfc7d8;
  border-radius: 6px;
  background: #fff;
}

.shelf-controls input[type="text"]:focus {
  outline: 2px solid #7e57c2;
  outline-offset: 1px;
  border-color: #7e57c2;
}

.shelf-controls select {
  padding: 9px 10px;
  font: inherit;
  font-size: 14px;
  border: 1px solid #cfc7d8;
  border-radius: 6px;
  background: #fff;
}

.shelf-counter {
  margin: 4px 0 18px;
  font-size: 13px;
  color: #7a7285;
  text-align: center;
}

.shelf-empty {
  text-align: center;
  padding: 60px 20px;
  color: #8d8698;
  font-style: italic;
}

/* ============================================================
   The cover wall
   ============================================================ */
.shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 34px 24px;
  padding: 10px 0 30px;
}

/* Each book is a real <button> so keyboard + screen readers work. */
.shelf-book {
  display: block;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.shelf-book:focus {
  outline: none;
}

.shelf-book:focus-visible .book-object {
  outline: 3px solid #7e57c2;
  outline-offset: 3px;
}

/* The physical-looking book object */
.book-object {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 2px 6px 6px 2px;
  overflow: hidden;
  background: #e8e3ef;
  transform-origin: center left;
  transition: transform .28s cubic-bezier(.2, .8, .2, 1),
              box-shadow .28s ease;
  /* page block on the right edge + drop shadow underneath */
  box-shadow:
    inset -2px 0 0 rgba(255, 255, 255, .55),
    inset -4px 0 0 rgba(0, 0, 0, .06),
    inset -6px 0 0 rgba(255, 255, 255, .45),
    inset -8px 0 0 rgba(0, 0, 0, .05),
    0 6px 14px rgba(30, 20, 45, .22),
    0 1px 3px rgba(30, 20, 45, .18);
}

/* Spine: dark gutter with a highlight, down the left edge */
.book-object::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 11px;
  z-index: 3;
  pointer-events: none;
  background: linear-gradient(
    90deg,
    rgba(0, 0, 0, .40) 0%,
    rgba(0, 0, 0, .22) 28%,
    rgba(255, 255, 255, .20) 62%,
    rgba(0, 0, 0, .14) 88%,
    rgba(0, 0, 0, .04) 100%
  );
}

/* Soft sheen across the cover */
.book-object::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(
    105deg,
    rgba(255, 255, 255, .16) 0%,
    rgba(255, 255, 255, 0) 38%,
    rgba(255, 255, 255, 0) 100%
  );
}

.shelf-book:hover .book-object {
  transform: perspective(1000px) rotateY(-7deg) translateY(-5px);
  box-shadow:
    inset -2px 0 0 rgba(255, 255, 255, .55),
    inset -4px 0 0 rgba(0, 0, 0, .06),
    inset -6px 0 0 rgba(255, 255, 255, .45),
    inset -8px 0 0 rgba(0, 0, 0, .05),
    0 16px 30px rgba(30, 20, 45, .30),
    0 2px 6px rgba(30, 20, 45, .20);
}

.book-object img.cover {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ---------- Generated fallback cover (50 books + any 404s) ---------- */
.cover-fallback {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding: 18px 14px 18px 20px;
  text-align: center;
  background:
    linear-gradient(160deg,
      hsl(var(--hue) 34% 40%) 0%,
      hsl(var(--hue) 38% 26%) 100%);
  color: #fff;
}

.book-object.no-cover .cover-fallback,
.book-object.cover-error .cover-fallback {
  display: flex;
}

.book-object.cover-error img.cover {
  display: none;
}

.cover-fallback .cf-title {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cover-fallback .cf-author {
  font-size: 11px;
  opacity: .82;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cover-fallback .cf-rule {
  height: 1px;
  background: rgba(255, 255, 255, .35);
  margin: 0 auto;
  width: 46%;
}

/* ---------- "Read" ribbon (corner banner, top-right) ---------- */
.read-ribbon {
  position: absolute;
  top: 0;
  right: 0;
  width: 78px;
  height: 78px;
  overflow: hidden;
  z-index: 4;
  pointer-events: none;
}

.read-ribbon span {
  position: absolute;
  top: 15px;
  right: -26px;
  width: 108px;
  transform: rotate(45deg);
  background: linear-gradient(180deg, #6a3fa8, #4e2d80);
  color: #fff;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  text-align: center;
  padding: 3px 0;
  box-shadow: 0 2px 5px rgba(0, 0, 0, .35);
}

/* ---------- "Donated" ribbon (corner banner, bottom-left) ---------- */
.donated-ribbon {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 78px;
  height: 78px;
  overflow: hidden;
  z-index: 4;
  pointer-events: none;
}

.donated-ribbon span {
  position: absolute;
  bottom: 15px;
  left: -26px;
  width: 108px;
  transform: rotate(-45deg);
  background: linear-gradient(180deg, #2a2a2a, #000);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  text-align: center;
  padding: 3px 0;
  box-shadow: 0 -2px 5px rgba(0, 0, 0, .35);
}

/* ---------- Hover title/author overlay ---------- */
.hover-label {
  position: absolute;
  inset: auto 0 0 0;
  z-index: 5;
  padding: 26px 12px 12px 18px;
  background: linear-gradient(
    to top,
    rgba(20, 14, 30, .94) 0%,
    rgba(20, 14, 30, .80) 55%,
    rgba(20, 14, 30, 0) 100%
  );
  color: #fff;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease;
}

.shelf-book:hover .hover-label,
.shelf-book:focus-visible .hover-label {
  opacity: 1;
  transform: none;
}

.hover-label .hl-title {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.28;
}

.hover-label .hl-author {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 3px;
  font-size: 11px;
  opacity: .85;
}

/* ============================================================
   Load more
   ============================================================ */
.shelf-more {
  display: flex;
  justify-content: center;
  padding: 10px 0 40px;
}

.shelf-more button {
  padding: 12px 26px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: #6a3fa8;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  transition: background .18s ease;
}

.shelf-more button:hover { background: #562f8d; }
.shelf-more button:disabled { opacity: .55; cursor: default; }

.shelf-loading {
  display: none;
  text-align: center;
  padding: 24px;
  color: #9a93a6;
  font-style: italic;
}

.shelf-loading.on { display: block; }

/* ============================================================
   The opened book (dialog)
   ============================================================ */
.book-dialog {
  padding: 0;
  border: 0;
  background: transparent;
  max-width: 96vw;
  max-height: 94vh;
  overflow: visible;
}

.book-dialog::backdrop {
  background: rgba(16, 11, 24, .70);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity .3s ease;
}

.book-dialog.is-open::backdrop { opacity: 1; }

.bd-spread {
  position: relative;
  display: flex;
  align-items: stretch;
  perspective: 2400px;
  opacity: 0;
  transform: scale(.94);
  transition: opacity .26s ease, transform .3s cubic-bezier(.2, .8, .2, 1);
  filter: drop-shadow(0 26px 50px rgba(0, 0, 0, .45));
}

.book-dialog.is-open .bd-spread {
  opacity: 1;
  transform: none;
}

/* ---------- Left page: the cover ---------- */
.bd-page-left {
  position: relative;
  flex: 0 0 auto;
  width: clamp(230px, 27vw, 330px);
  padding: 22px;
  background:
    linear-gradient(135deg, #f7f4fb 0%, #ece6f4 100%);
  border-radius: 4px 0 0 4px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  box-shadow: inset -14px 0 22px -14px rgba(40, 26, 60, .38);
}

.bd-cover-holder {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 2px 5px 5px 2px;
  overflow: hidden;
  background: #e2dcea;
  box-shadow: 0 8px 18px rgba(40, 26, 60, .28);
}

.bd-cover-holder img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.bd-cover-holder .cover-fallback { padding: 22px 18px; }

.bd-left-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 34px;
}

.bd-left-meta img { display: block; }

.bd-left-meta .bd-format-label {
  font-size: 12px;
  color: #6b6377;
  letter-spacing: .3px;
}

.bd-read-chip {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  background: #6a3fa8;
  color: #fff;
}

.bd-read-chip.on { display: inline-flex; }

/* ---------- The spine / gutter ---------- */
.bd-gutter {
  flex: 0 0 auto;
  width: 16px;
  background: linear-gradient(
    90deg,
    rgba(70, 48, 100, .30) 0%,
    rgba(70, 48, 100, .16) 22%,
    rgba(255, 255, 255, .55) 50%,
    rgba(70, 48, 100, .16) 78%,
    rgba(70, 48, 100, .30) 100%
  );
}

/* ---------- Right page: the information, swings open ---------- */
.bd-page-right {
  flex: 0 0 auto;
  width: 0;
  opacity: 0;
  overflow: hidden;
  transform: rotateY(-102deg);
  transform-origin: left center;
  background: linear-gradient(90deg, #fffdf8 0%, #fdfaf2 65%, #f6f1e6 100%);
  border-radius: 0 5px 5px 0;
  transition:
    width .46s cubic-bezier(.2, .8, .2, 1),
    transform .52s cubic-bezier(.2, .8, .2, 1),
    opacity .3s ease .10s;
  box-shadow: inset 16px 0 24px -16px rgba(40, 26, 60, .30);
}

.book-dialog.is-open .bd-page-right {
  width: clamp(300px, 44vw, 560px);
  opacity: 1;
  transform: rotateY(0deg);
}

/* Fixed inner width so text doesn't reflow while the page swings */
.bd-page-right-inner {
  position: relative;
  width: clamp(300px, 44vw, 560px);
  max-height: min(78vh, 760px);
  overflow-y: auto;
  padding: 26px 30px 30px;
  box-sizing: border-box;
}

.bd-page-right-inner::-webkit-scrollbar { width: 9px; }
.bd-page-right-inner::-webkit-scrollbar-thumb {
  background: rgba(106, 63, 168, .30);
  border-radius: 9px;
}

/* ---------- Right page typography ---------- */
.bd-title {
  margin: 0 0 4px;
  font-size: 21px;
  line-height: 1.26;
  font-weight: 700;
  color: #241a33;
  padding-right: 34px;
}

.bd-authors {
  margin: 0 0 12px;
  font-size: 14px;
  color: #6b6377;
}

.bd-authors a {
  color: #56348c;
  text-decoration: none;
  border-bottom: 1px solid rgba(86, 52, 140, .28);
}

.bd-authors a:hover { border-bottom-color: #56348c; }

.bd-rating {
  min-height: 24px;
  margin-bottom: 16px;
}

.bd-rating .stars {
  color: #000;
  font-size: 19px;
  letter-spacing: 3px;
  line-height: 1;
}

.bd-rating .stars .off { color: #ccc4d6; }

.bd-rating .unrated {
  font-size: 12px;
  font-style: italic;
  color: #a09aad;
}

.bd-facts {
  margin: 0 0 18px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 14px;
  font-size: 13px;
}

.bd-facts dt {
  color: #9a93a6;
  font-size: 11px;
  letter-spacing: .9px;
  text-transform: uppercase;
  padding-top: 1px;
}

.bd-facts dd {
  margin: 0;
  color: #3a3148;
  overflow-wrap: anywhere;
}

.bd-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 20px;
}

.bd-tags .chip {
  display: inline-block;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 11.5px;
  background: rgba(106, 63, 168, .10);
  color: #56348c;
  border: 1px solid rgba(106, 63, 168, .20);
  text-decoration: none;
}

.bd-tags a.chip:hover { background: rgba(106, 63, 168, .20); }

.bd-section {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid rgba(70, 48, 100, .14);
}

.bd-section[hidden] { display: none; }

.bd-section h3 {
  margin: 0 0 9px;
  font-size: 11px;
  letter-spacing: 1.3px;
  text-transform: uppercase;
  color: #9a93a6;
  font-weight: 700;
}

.bd-prose {
  font-size: 13.5px;
  line-height: 1.66;
  color: #342c42;
}

.bd-prose p { margin: 0 0 .85em; }
.bd-prose p:last-child { margin-bottom: 0; }

/* Collapsed long prose with fade + toggle */
.bd-prose.clamped {
  position: relative;
  max-height: 190px;
  overflow: hidden;
  mask-image: linear-gradient(to bottom, #000 66%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, #000 66%, transparent 100%);
}

.bd-toggle {
  margin-top: 8px;
  padding: 5px 13px;
  font: inherit;
  font-size: 11.5px;
  font-weight: 700;
  color: #56348c;
  background: rgba(106, 63, 168, .09);
  border: 1px solid rgba(106, 63, 168, .22);
  border-radius: 999px;
  cursor: pointer;
}

.bd-toggle:hover { background: rgba(106, 63, 168, .18); }
.bd-toggle[hidden] { display: none; }

.bd-ai-note {
  margin-top: 8px;
  font-size: 10.5px;
  font-style: italic;
  color: #a09aad;
}

/* ---------- Skeleton shimmer while fetching ---------- */
.bd-skeleton { padding-top: 4px; }

.bd-skeleton i {
  display: block;
  height: 11px;
  margin-bottom: 9px;
  border-radius: 4px;
  background: linear-gradient(90deg, #eee8f2 25%, #f7f3fa 50%, #eee8f2 75%);
  background-size: 200% 100%;
  animation: bdShimmer 1.25s ease-in-out infinite;
}

.bd-skeleton i:nth-child(2) { width: 92%; }
.bd-skeleton i:nth-child(3) { width: 78%; }
.bd-skeleton i:nth-child(4) { width: 86%; }
.bd-skeleton i:last-child   { width: 54%; }

@keyframes bdShimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.bd-error {
  font-size: 12.5px;
  color: #a8443c;
  font-style: italic;
}

/* ---------- Close button ---------- */
.bd-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 10;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  color: #4f4460;
  background: rgba(255, 255, 255, .86);
  border: 1px solid rgba(70, 48, 100, .18);
  border-radius: 50%;
  cursor: pointer;
  opacity: 0;
  transition: opacity .25s ease .2s, background .15s ease;
}

.book-dialog.is-open .bd-close { opacity: 1; }
.bd-close:hover { background: #fff; }

/* ============================================================
   Narrow screens: stack it, drop the 3D
   ============================================================ */
@media (max-width: 760px) {
  .shelf-grid {
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
    gap: 22px 14px;
  }

  /* No hover on touch — show labels permanently beneath the covers */
  .hover-label {
    position: static;
    opacity: 1;
    transform: none;
    padding: 7px 2px 0;
    background: none;
    color: #2e2740;
  }

  .hover-label .hl-title { font-size: 11.5px; -webkit-line-clamp: 2; }
  .hover-label .hl-author { font-size: 10px; color: #7a7285; opacity: 1; }

  .shelf-book:hover .book-object { transform: none; }

  .read-ribbon { width: 58px; height: 58px; }
  .read-ribbon span { top: 10px; right: -22px; width: 84px; font-size: 8px; }

  .donated-ribbon { width: 58px; height: 58px; }
  .donated-ribbon span { bottom: 10px; left: -22px; width: 84px; font-size: 7.5px; }

  .book-dialog { max-width: 100vw; max-height: 100vh; width: 100vw; }

  .bd-spread {
    flex-direction: column;
    perspective: none;
    width: 100vw;
    max-height: 100vh;
    overflow-y: auto;
    border-radius: 0;
  }

  .bd-page-left {
    width: auto;
    border-radius: 0;
    box-shadow: none;
    padding: 20px 20px 14px;
  }

  .bd-cover-holder { width: min(58vw, 230px); }

  .bd-gutter {
    width: auto;
    height: 1px;
    background: rgba(70, 48, 100, .18);
  }

  .bd-page-right,
  .book-dialog.is-open .bd-page-right {
    width: 100%;
    transform: none;
    opacity: 1;
    border-radius: 0;
    box-shadow: none;
    transition: opacity .2s ease;
  }

  .bd-page-right-inner {
    width: 100%;
    max-height: none;
    overflow: visible;
    padding: 20px 20px 40px;
  }
}

/* ============================================================
   Respect reduced-motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .book-object,
  .hover-label,
  .bd-spread,
  .bd-page-right,
  .bd-close,
  .book-dialog::backdrop {
    transition: none !important;
  }

  .shelf-book:hover .book-object { transform: translateY(-3px); }

  .bd-page-right,
  .book-dialog.is-open .bd-page-right {
    transform: none;
    width: clamp(300px, 44vw, 560px);
    opacity: 1;
  }

  .bd-skeleton i { animation: none; }
}
.donated-ribbon {
  z-index: 6 !important;
}