.writing-shelf {
  max-width: 1040px;
  margin: 0 auto;
  padding: clamp(24px, 4.5vw, 56px) 0 clamp(44px, 7vw, 80px);
}

.shelf-hero {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: end;
  gap: 16px 36px;
  margin-bottom: clamp(18px, 3vw, 32px);
}

.shelf-hero p {
  max-width: 38ch;
  color: var(--muted);
  font: 17px/1.5 var(--serif);
}

.shelf-hero div p {
  margin-bottom: 9px;
  font-size: 15px;
  font-style: italic;
}

.shelf-hero h1 {
  font: 400 clamp(3.2rem, 7vw, 5rem)/1 var(--serif);
  letter-spacing: -.04em;
}

.shelf-hero em { color: var(--accent); }

.shelf-toolbar, .shelf-filters, .shelf-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  font: 15px/1.4 var(--serif);
  color: var(--muted);
}

.shelf-toolbar {
  justify-content: space-between;
  align-items: start;
  gap: 8px 20px;
  margin-bottom: 26px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.shelf-filters { flex: 1 1 560px; }
.shelf-toolbar > a { white-space: nowrap; padding: 5px 0; }

.shelf-filters[hidden], .writing-cover[hidden] { display: none; }

.shelf-filters button {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 5px 0;
  border: 0;
  border-bottom: 1px solid transparent;
  background: transparent;
  cursor: pointer;
}

.shelf-filters button:not([data-filter="all"])::before {
  content: "";
  width: 9px;
  height: 9px;
  border: 1px solid rgb(255 255 255 / .25);
  border-radius: 2px;
  background: var(--cover);
}

.shelf-filters button:hover, .shelf-filters [aria-pressed="true"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.shelf-toolbar a, .shelf-links a {
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 4px;
}

.shelf-status {
  color: var(--muted);
  font: italic 14px/1.4 var(--serif);
}

.shelf-status:not(:empty) { margin: -5px 0 12px; }

.shelf-books {
  --shelf-gap: clamp(16px, 2.4vw, 26px);
  --ledge: 12px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: calc(var(--ledge) + clamp(34px, 5vw, 56px)) var(--shelf-gap);
  padding: 8px 0 calc(var(--ledge) + 14px);
  overflow-x: clip;
  list-style: none;
}

/* A wooden ledge under each row: every book draws its own slice, and the
   slices meet across the gaps so each row reads as one continuous shelf. */
.writing-cover {
  position: relative;
}

.writing-cover::after {
  position: absolute;
  top: 100%;
  left: calc(var(--shelf-gap) / -2 - 1px);
  right: calc(var(--shelf-gap) / -2 - 1px);
  height: var(--ledge);
  border-bottom: 3px solid color-mix(in srgb, #5a4128 70%, var(--paper));
  background:
    linear-gradient(rgb(255 255 255 / .30), transparent 3px),
    linear-gradient(color-mix(in srgb, #9a7650 42%, var(--paper)), color-mix(in srgb, #7d5c3b 58%, var(--paper)));
  box-shadow: 0 12px 16px -9px rgb(0 0 0 / .40);
  content: "";
  pointer-events: none;
  z-index: 2; /* in front of an opening cover, so it tucks behind the lip */
}

/* Run the last, partly filled row's ledge out to the shelf edge. */
.writing-cover:last-child::after { right: -100vw; }

.writing-cover-featured {
  grid-column: span 2;
}

.writing-cover-featured .writing-cover-card {
  padding-right: clamp(21px, 12%, 120px);
}

.writing-cover-featured h2 {
  max-width: 18ch;
  font-size: clamp(2rem, 3.6vw, 2.75rem);
}

.writing-cover-featured p {
  max-width: 46ch;
  font-size: 16.5px;
}

.shelf-kicker {
  position: absolute;
  top: 22px;
  left: clamp(21px, 3vw, 32px);
  padding: 3px 8px;
  border: 1px solid rgb(255 255 255 / .45);
  border-radius: 999px;
  font: 500 10.5px/1.3 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.writing-cover-card {
  position: relative;
  display: flex;
  min-height: clamp(310px, 36vw, 365px);
  height: 100%;
  flex-direction: column;
  padding: clamp(62px, 7.5vw, 92px) clamp(21px, 3vw, 32px) 20px;
  border-radius: 4px 9px 9px 4px;
  background: linear-gradient(135deg, rgb(255 255 255 / .09), transparent 48%, rgb(0 0 0 / .14)), var(--cover, #343330);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / .14), 0 2px 4px rgb(0 0 0 / .12), 3px 8px 20px rgb(0 0 0 / .10);
}

a.writing-cover-card::before {
  position: absolute;
  inset: 1px auto 1px 1px;
  width: 10px;
  border-right: 1px solid rgb(255 255 255 / .22);
  border-radius: 3px 0 0 3px;
  background: linear-gradient(90deg, rgb(0 0 0 / .21), rgb(255 255 255 / .06));
  content: "";
}

.shelf-mark {
  position: absolute;
  top: 18px;
  right: clamp(21px, 3vw, 32px);
  width: 25px;
  height: 25px;
  border: 1px solid rgb(255 255 255 / .50);
  border-radius: 50%;
}

.shelf-mark::after {
  position: absolute;
  inset: 4px;
  border: 1px solid rgb(255 255 255 / .50);
  border-radius: 50%;
  content: "";
}

.writing-cover h2 {
  font: 450 clamp(1.55rem, 2.5vw, 1.9rem)/1.1 var(--serif);
  letter-spacing: -.02em;
  text-wrap: balance;
}

.writing-cover p {
  margin-top: 12px;
  font: 400 15px/1.45 var(--serif);
}

a.writing-cover-card:is(:hover, :focus-visible) h2 { font-weight: 550; }
a.writing-cover-card:is(:hover, :focus-visible) p { font-weight: 470; }
a.writing-cover-card:is(:hover, :focus-visible) .shelf-foot { font-weight: 500; }

@media (prefers-reduced-motion: no-preference) {
  .writing-cover-card :is(h2, p) { transition: font-weight .16s ease; }
}

/* Opening animation: the cover hinges on its spine and swings toward the
   reader, revealing a block of pages underneath. The vanishing point sits
   past the fore-edge so the opening cover narrows instead of growing over
   the pages. */
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .writing-cover {
    position: relative;
    perspective: 1200px;
    perspective-origin: 150% 50%;
  }

  .writing-cover::before {
    position: absolute;
    inset: 4px 3px 4px 8px;
    border-radius: 2px 7px 7px 2px;
    background:
      linear-gradient(90deg, rgb(0 0 0 / .18), transparent 12%),
      repeating-linear-gradient(90deg, #f6f1e6 0 2px, #e2dacb 2px 3px) right / 14px 100% no-repeat,
      #f8f4ec;
    box-shadow: 0 2px 4px rgb(0 0 0 / .12), 3px 8px 20px rgb(0 0 0 / .10);
    content: "";
  }

  a.writing-cover-card {
    transform-origin: left center;
    transform: rotateY(0deg);
    transition: transform .5s cubic-bezier(.2, .7, .2, 1), box-shadow .5s ease;
  }

  .writing-cover:hover > a.writing-cover-card,
  a.writing-cover-card:focus-visible {
    transform: rotateY(-26deg);
    box-shadow: inset 0 0 0 1px rgb(255 255 255 / .14), 0 3px 4px rgb(0 0 0 / .18), 14px 12px 26px rgb(0 0 0 / .24);
  }

  /* The wide featured cover swings less, or it would sweep across the row. */
  .writing-cover-featured:hover > a.writing-cover-card,
  .writing-cover-featured a.writing-cover-card:focus-visible {
    transform: rotateY(-14deg);
  }
}

/* Books slide onto the shelf one after another when the page loads. */
@media (prefers-reduced-motion: no-preference) {
  .writing-cover {
    animation: shelve .6s cubic-bezier(.2, .7, .2, 1) both;
    animation-delay: calc(min(var(--i, 0), 8) * 55ms);
  }

  @keyframes shelve {
    from { opacity: 0; translate: 0 18px; }
  }
}

.shelf-foot {
  --cover-rule: rgb(255 255 255 / .30);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
  padding-top: 28px;
  background: linear-gradient(var(--cover-rule), var(--cover-rule)) 0 18px / 100% 1px no-repeat;
  font: 11px/1.4 var(--mono);
}

.shelf-foot > :last-child { white-space: nowrap; }

.shelf-links { margin-top: 18px; }

@media (max-width: 760px) {
  .shelf-books { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .shelf-hero { gap: 12px; }
  .shelf-filters { gap: 2px 12px; font-size: 14px; }
  .shelf-books { grid-template-columns: minmax(0, 1fr); }
  .writing-cover-card { min-height: 245px; padding: 58px 24px 18px; }
  .writing-cover-featured { grid-column: auto; }
  .writing-cover-featured h2 { font-size: 1.9rem; }
}
