/* The rest of the site is deliberately plain. The stack is the one thing that isn't. */
:root {
  --blank: #ddd8cc;
  --spine-shadow: 0 1px 1px rgb(0 0 0 / 0.2), 0 5px 9px -5px rgb(0 0 0 / 0.45);
  --lift-shadow: 0 2px 2px rgb(0 0 0 / 0.12), 14px 16px 24px -10px rgb(0 0 0 / 0.5);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --blank: #2e2c28;
    --spine-shadow: 0 1px 1px rgb(0 0 0 / 0.6), 0 6px 10px -5px rgb(0 0 0 / 0.9);
    --lift-shadow: 0 2px 2px rgb(0 0 0 / 0.5), 14px 16px 26px -10px rgb(0 0 0 / 0.95);
  }
}

/* Page layout */
.bookshelf {
  display: grid;
  grid-template-columns: 14rem minmax(0, 1fr);
  gap: 3rem;
  align-items: start;
}
.bookshelf-controls {
  position: sticky;
  top: 24px;
}
.bookshelf-controls .check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
}
.view-switch {
  display: flex;
  gap: 6px;
  margin: 20px 0 16px;
}
.view-switch button {
  padding: 3px 12px;
  font-size: 14px;
  background: none;
  color: var(--muted);
  border: 1px solid var(--line);
}
.view-switch [aria-pressed="true"] {
  color: var(--fg);
  border-color: var(--fg);
}
.small {
  font-size: 13px;
}
.collection {
  width: 100%;
  max-width: 520px;
  justify-self: center;
  padding: 8px 24px 0;
}

/* The stack */
.shelf {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.spine {
  position: relative;
  display: block;
  flex-shrink: 0;
  width: var(--width);
  aspect-ratio: var(--spine-ratio);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 2px 3px 3px 2px;
  background: var(--blank);
  color: var(--type);
  box-shadow: var(--spine-shadow);
  transform: translateX(var(--offset)) rotate(var(--tilt));
  transition:
    transform 0.45s var(--ease),
    box-shadow 0.45s var(--ease);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
}
/* Light falls across the rounded spine: a highlight on top, shade underneath, worn ends. */
.spine::after,
.mini-spine::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(
      to bottom,
      rgb(255 255 255 / 0.24),
      rgb(255 255 255 / 0.06) 16%,
      transparent 38%,
      transparent 68%,
      rgb(0 0 0 / 0.14) 88%,
      rgb(0 0 0 / 0.3)
    ),
    linear-gradient(
      to right,
      rgb(0 0 0 / 0.2),
      transparent 2%,
      transparent 98%,
      rgb(0 0 0 / 0.2)
    );
}
.spine-artwork {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.5s ease;
}
.spine.loaded .spine-artwork {
  opacity: 1;
}
.spine-title,
.spine-author {
  display: none;
}
.spine:hover,
.spine:focus-visible {
  z-index: 2;
  transform: translateX(calc(var(--offset) - 24px)) rotate(0deg);
  box-shadow: var(--lift-shadow);
}
.spine:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}
/* A book without artwork gets a plain cloth spine with its title. */
.spine:not(.has-artwork) {
  display: flex;
  align-items: center;
  gap: 12px;
  aspect-ratio: auto;
  min-height: var(--height);
  padding: 8px 18px 8px 22px;
  background: var(--book);
}
.spine:not(.has-artwork) .spine-title,
.spine:not(.has-artwork) .spine-author {
  display: block;
}
.spine:not(.has-artwork) .spine-title {
  flex: 1;
  font: 18px/1.15 Georgia, serif;
}
.spine:not(.has-artwork) .spine-author {
  max-width: 100px;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
/* The table the stack rests on. */
.shelf:not(.index)::after {
  content: "";
  width: 115%;
  height: 26px;
  margin-top: -10px;
  background: radial-gradient(closest-side, rgb(0 0 0 / 0.28), transparent);
  pointer-events: none;
}
.shelf.arriving .spine:nth-child(-n + 30) {
  animation: settle 0.7s var(--ease) backwards;
  animation-delay: calc(var(--i) * 28ms);
}
@keyframes settle {
  from {
    opacity: 0;
    transform: translate(var(--offset), -36px) rotate(calc(var(--tilt) * 4));
  }
}

/* List view */
.shelf.index {
  align-items: stretch;
}
.index .spine {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  width: 100%;
  aspect-ratio: auto;
  min-height: 0;
  padding: 9px 0;
  background: none;
  color: var(--fg);
  border-radius: 0;
  border-bottom: 1px solid var(--line);
  box-shadow: none;
  transform: none;
  transition: none;
  animation: none;
  overflow: visible;
}
.index .spine::after,
.index .spine-artwork {
  display: none;
}
.index .spine .spine-title,
.index .spine .spine-author {
  display: block;
  max-width: none;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.4;
  letter-spacing: 0;
  text-transform: none;
}
.index .spine .spine-author {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}
.index .spine:hover .spine-title {
  text-decoration: underline;
}

/* Homepage preview */
.stack-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(100%, 340px);
  margin: 48px 0 0;
  transition: transform 0.45s var(--ease);
}
.stack-preview:hover {
  transform: translateY(-4px);
}
.mini-spine {
  position: relative;
  display: block;
  width: var(--width);
  border-radius: 2px;
  overflow: hidden;
  background: var(--blank);
  box-shadow: var(--spine-shadow);
  transform: translateX(var(--offset)) rotate(var(--tilt));
}
.mini-spine img {
  display: block;
  width: 100%;
  height: auto;
}

/* Book detail */
#book-dialog {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  border: 0;
  padding: 96px max(6%, calc((100vw - 960px) / 2)) 32px;
  background: rgb(16 16 16 / 0.9);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: #eee;
  overflow-y: auto;
}
#book-dialog::backdrop {
  background: transparent;
}
#book-dialog[open] {
  animation: fade 0.25s ease-out;
}
#book-dialog[open] .cover-wrap {
  animation: pull 0.5s var(--ease);
}
#book-dialog .close {
  position: fixed;
  top: 24px;
  right: 5%;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgb(255 255 255 / 0.25);
  border-radius: 50%;
  background: none;
  color: inherit;
  font-size: 28px;
  line-height: 1;
}
.detail {
  display: grid;
  grid-template-columns: 2fr 3fr;
  gap: 56px;
  align-items: center;
  margin: 16px 0 56px;
}
.cover-wrap {
  position: relative;
  width: 100%;
  max-width: 300px;
  aspect-ratio: 2 / 3;
  margin: auto;
  background: var(--book, #ddd8cc);
  color: var(--type, #222);
  border-radius: 2px 5px 5px 2px;
  box-shadow:
    0 2px 4px rgb(0 0 0 / 0.4),
    16px 26px 50px rgb(0 0 0 / 0.55);
  overflow: hidden;
}
.cover-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    to right,
    rgb(0 0 0 / 0.25),
    rgb(255 255 255 / 0.12) 2.5%,
    transparent 6%
  );
}
.cover-fallback {
  height: 100%;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}
.cover-fallback span {
  font: 32px/1.1 Georgia, serif;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 7;
  overflow: hidden;
}
.cover-fallback small {
  margin-top: 16px;
  font-size: 13px;
  color: inherit;
}
#cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #222;
}
.book-copy {
  min-width: 0;
}
.position {
  font-size: 13px;
  color: #999;
}
#book-title {
  margin: 0 0 8px;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.1;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
}
.author {
  margin: 0 0 24px;
  font-size: 19px;
  color: #ccc;
}
#metadata {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 20px;
  margin: 0 0 20px;
  padding: 20px 0;
  border-top: 1px solid rgb(255 255 255 / 0.15);
}
#metadata dt {
  margin-bottom: 2px;
  font-size: 12px;
  color: #999;
}
#metadata dd {
  margin: 0;
  font-size: 15px;
}
.artwork-credit {
  font-size: 12px;
  color: #999;
}
.book-navigation {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 16px;
  border-top: 1px solid rgb(255 255 255 / 0.15);
}
.book-navigation button {
  padding: 10px 0;
  background: none;
  color: inherit;
}
.book-navigation button:disabled {
  opacity: 0.3;
  cursor: default;
}
.book-navigation span {
  font-size: 12px;
  color: #999;
}
body.modal-open {
  overflow: hidden;
}
@keyframes fade {
  from {
    opacity: 0;
  }
}
@keyframes pull {
  from {
    opacity: 0;
    transform: translateY(16px) rotate(-1.5deg);
  }
}

@media (max-width: 760px) {
  .bookshelf {
    display: block;
  }
  .bookshelf-controls {
    position: static;
    margin-bottom: 32px;
  }
  .collection {
    padding: 0 8px;
  }
  .shelf:not(.index) .spine {
    transform: translateX(calc(var(--offset) / 2)) rotate(var(--tilt));
  }
  #book-dialog {
    padding: 80px 7% 24px;
  }
  .detail {
    display: block;
    margin-bottom: 32px;
  }
  .cover-wrap {
    width: 150px;
    margin: 0 auto 28px;
  }
  .cover-fallback span {
    font-size: 20px;
  }
  .book-navigation span {
    display: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  .spine,
  .spine-artwork,
  .stack-preview,
  #book-dialog,
  #book-dialog .cover-wrap {
    animation: none !important;
    transition: none !important;
  }
}
