/* Keep the 3D books out of whole-page blur/fade snapshots as well. Only the
   headings, navigation and captions animate; covers/spines simply rotate. */
@view-transition { navigation: none; }

.books-main {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  gap: 32px;
  min-width: 0;
  padding: calc(var(--nav-height) + var(--content-top)) var(--page-gutter) 24px;
}
.books-layout { flex: 1; display: grid; grid-template-columns: clamp(280px, 38vw, 560px) minmax(0, 1fr); grid-template-rows: minmax(min-content, 1fr); align-items: start; gap: 32px clamp(24px, 3vw, 48px); width: 100%; min-width: 0; }
.book-names { grid-column: 1; grid-row: 1; min-width: 0; }
.book-names[hidden] { display: none; }
.book-name { display: block; justify-self: start; max-width: 100%; text-align: left; font-size: var(--display-size); line-height: var(--display-leading); letter-spacing: var(--display-tracking); }
.book-name:hover, .book-name:focus-visible { text-decoration: underline; }
.books-scene { grid-column: 2; grid-row: 1; position: sticky; top: calc(var(--nav-height) + var(--content-top)); display: flex; align-items: center; height: var(--page-fill); container-type: inline-size; min-width: 0; }
.bookshelf {
  --scene-padding: 12px;
  --book-height: max(140px, min(840px, calc(var(--page-fill) - 64px), calc((100cqw - var(--scene-padding) * 2 - (var(--book-count) - 1) * (var(--book-depth) + var(--book-gap)) - var(--book-depth) * .6) / var(--max-cover-ratio))));
  --book-depth: 38px;
  --book-gap: clamp(16px, 2.5cqw, 32px);
  --book-count: 4;
  --max-cover-ratio: .664;
  --open-width: calc(var(--book-height) * var(--max-cover-ratio) + var(--book-depth) * .6);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--book-gap);
  width: 100%;
  padding: 12px var(--scene-padding);
  isolation: isolate;
}
.book {
  --book-width: calc(var(--book-height) * var(--cover-ratio));
  position: relative;
  flex: 0 0 auto;
  width: var(--book-depth);
  height: var(--book-height);
  perspective: 1400px;
  transition: width 760ms cubic-bezier(.22,.8,.2,1);
  -webkit-touch-callout: none;
}
/* Reserve the same open width for every title, so swapping covers keeps
   the row bounded even though their actual cover ratios differ slightly. */
.book.is-open { width: var(--open-width); }
.book:focus-visible { outline-offset: 12px; }
.book-object {
  position: absolute;
  left: 50%;
  top: 0;
  width: var(--book-width);
  height: 100%;
  transform-origin: 0 50%;
  transform-style: preserve-3d;
  transform: rotateY(90deg);
  transition: transform 760ms cubic-bezier(.22,.8,.2,1), left 760ms cubic-bezier(.22,.8,.2,1);
  pointer-events: none;
}
.book.is-open .book-object { left: calc((100% - var(--book-width)) / 2); transform: rotateY(12deg); }
.book-front, .book-back, .book-spine, .book-pages, .book-top {
  position: absolute;
  display: block;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.book-front, .book-back { inset: 0; }
.book-front { transform: translateZ(calc(var(--book-depth) / 2)); background: var(--spine-color); }
.book-front::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, #0002, transparent 6%, transparent 96%, #0001); }
.book-front img { display: block; width: 100%; height: 100%; object-fit: fill; user-select: none; -webkit-user-drag: none; -webkit-touch-callout: none; }
.book-back { transform: rotateY(180deg) translateZ(calc(var(--book-depth) / 2)); background: var(--spine-color); }
.book-spine {
  left: 0;
  top: 0;
  width: var(--book-depth);
  height: 100%;
  transform: translateX(-50%) rotateY(-90deg);
  background: linear-gradient(90deg, #0002, transparent 15%, #ffffff10 45%, #0001), var(--spine-color);
  color: var(--spine-ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 18px 0;
  font-size: 14px;
  line-height: 1.2;
}
.book-spine > span { writing-mode: vertical-rl; text-align: left; }
.book-spine .spine-author { font-size: 10px; }
.book-pages {
  right: 0;
  top: 3px;
  width: calc(var(--book-depth) - 3px);
  height: calc(100% - 6px);
  transform: translateX(50%) rotateY(90deg);
  background: repeating-linear-gradient(90deg, #e7e3da 0 1px, #f6f3eb 1px 3px);
}
.book-top {
  top: 0;
  left: 1px;
  width: calc(100% - 2px);
  height: var(--book-depth);
  transform: translateY(-50%) rotateX(90deg);
  background: repeating-linear-gradient(#e5e0d6 0 1px, #f3efe5 1px 3px);
}
.book-details { grid-column: 1; grid-row: 1; min-width: 0; width: 100%; text-align: left; font-size: var(--display-size); line-height: var(--display-leading); scroll-margin-top: calc(var(--nav-height) + var(--content-top)); }
.book-details h2, .book-fallback h2 { margin: 0 0 24px; font-size: inherit; font-weight: inherit; line-height: inherit; letter-spacing: var(--display-tracking); }
.book-details p { margin: 0 0 24px; color: var(--ink); }
#book-description { overflow-wrap: anywhere; }
#book-description p { text-align: justify; hyphens: auto; }
.book-details a, .book-fallback a { display: inline-flex; align-items: center; min-height: 44px; font-weight: inherit; text-underline-offset: 4px; }
.book-actions { display: flex; flex-wrap: wrap; gap: 12px 24px; }
#book-close { min-height: 44px; text-decoration: underline; text-underline-offset: 4px; }
.book-fallback article { margin-top: 48px; }
@media (max-width: 600px), (max-width: 900px) and (pointer: coarse) {
  .books-main { gap: 28px; }
  .bookshelf {
    --scene-padding: 8px;
    --book-depth: 24px;
    --book-gap: 16px;
  }
  .book-spine { font-size: 10px; padding: 10px 0; }
  .book-spine .spine-author { font-size: 7px; }
}
@media (max-width: 700px) {
  .books-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: min-content min-content; grid-auto-rows: min-content; gap: 28px; }
  .books-scene { grid-column: 1; grid-row: 2; position: static; align-self: stretch; height: auto; }
  .book-details { grid-column: 1; grid-row: 1; }
}
@media (max-height: 560px) {
  .books-main { gap: 16px; }
}
@media (forced-colors: active) {
  .book-spine { outline: 1px solid CanvasText; }
}
