/* ---------- Book shelves (Views/Shared/_ShelfBook, _BookShelf; the home page, the
   Books page and a book's similar books): small covers standing on a soft shelf, a
   flat PDF or sale label, then the title and price. Like Goodreads' shelves. The
   home page sets its own number per row in home-board.css. ---------- */

.hb-shelf {
  --hb-gap: 1.1rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 0.6rem var(--hb-gap);
  padding: 0.5rem 1rem 0;
}

.hb-book {
  display: grid;
  gap: 0.3rem;
  min-width: 0;
  text-align: center;
  color: var(--blog-night-text, #1d2219);
  text-decoration: none;
}

.hb-book-cover {
  position: relative;
  display: block;
  padding-bottom: 7px;
}

/* The shelf: a soft band behind the lower half of each cover and a ledge under
   it, running into the gaps so the books stand on one shelf. */
.hb-book-cover::before {
  content: "";
  position: absolute;
  z-index: 0;
  left: calc(var(--hb-gap) / -2 - 1px);
  right: calc(var(--hb-gap) / -2 - 1px);
  top: 50%;
  bottom: 0;
  background: linear-gradient(180deg, var(--bb-sage-100) 0, var(--bb-sage-100) calc(100% - 7px), var(--bb-sage-300) calc(100% - 7px));
}

.hb-book-cover img {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  max-width: 96px;
  aspect-ratio: 2 / 3;
  margin-inline: auto;
  object-fit: cover;
  overflow: hidden;
  font-size: 0;
  color: transparent;
  background: var(--bb-sage-200);
  border-radius: 2px 5px 5px 2px;
  box-shadow: inset 3px 0 0 rgba(0, 0, 0, 0.16), 0 6px 10px -6px rgba(20, 30, 50, 0.6);
  transition: transform 0.25s ease;
}

.hb-book:hover .hb-book-cover img,
.hb-book:hover .hb-pdf,
.hb-book:hover .hb-flag { transform: translateY(-6px); }

.hb-pdf,
.hb-flag {
  position: absolute;
  z-index: 2;
  top: 4px;
  padding: 1px 3px;
  border-radius: 2px;
  font-size: 0.52rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: 0.03em;
  color: #fff;
  transition: transform 0.25s ease;
}

/* Inside the cover's own width (centred, at most 96px). */
.hb-pdf { right: max(4px, calc(50% - 48px + 4px)); background: #dc2626; }
.hb-flag { left: max(4px, calc(50% - 48px + 4px)); background: #1d4ed8; }
.hb-flag.is-free { background: #16a34a; }
.hb-flag.is-featured { background: #a9841f; }

/* Up to two lines, then "…"; always two lines tall so the prices line up. */
.hb-book-title {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  max-width: 96px;
  margin-inline: auto;
  width: 100%;
  overflow: hidden;
  overflow-wrap: anywhere;
  line-height: 1.25;
  min-height: 2.5em;
  font-size: 0.74rem;
  font-weight: 600;
}

.hb-book-price {
  font-size: 0.74rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--bb-blue-900);
}

/* The Books page's list: as many per row as fit, a little more room between rows. */
.hb-shelf.is-grid { row-gap: 1.4rem; padding-inline: 0.5rem; }

@media (max-width: 767.98px) {
  /* Phones and small tablets: always 4 per row, like the home page and the Books
     page's list (a shelf's 12 books make 3 full rows). */
  .hb-shelf { --hb-gap: 0.75rem; grid-template-columns: repeat(4, minmax(0, 1fr)); padding-inline: 0.5rem; }
  .hb-book-title { font-size: 0.72rem; }
}

/* The Books page shows 48 books a page (BooksController.CatalogPageSize), so each
   width uses a number per row that divides 48: full rows, no gaps before the page
   links. Only the last page can end with a short row. */
.hb-shelf.is-grid { grid-template-columns: repeat(var(--hb-cols), minmax(0, 1fr)); --hb-cols: 12; }
@media (max-width: 1399.98px) { .hb-shelf.is-grid { --hb-cols: 8; } }
@media (max-width: 1099.98px) { .hb-shelf.is-grid { --hb-cols: 6; } }
@media (max-width: 767.98px) { .hb-shelf.is-grid { --hb-cols: 4; } }

/* Named shelves of 12 (_BookShelf: the Books page's picks, top rated and best
   sellers, and a book's similar books): the same number per row as the list below
   them, one full row each, so a 12th book never drops to a row of its own.
   Phones show all 12 as 3 rows of 4. */
.hb-shelf.is-row { grid-template-columns: repeat(var(--hb-cols), minmax(0, 1fr)); --hb-cols: 12; padding-inline: 0.5rem; }
@media (max-width: 1399.98px) { .hb-shelf.is-row { --hb-cols: 8; } .hb-shelf.is-row > :nth-child(n + 9) { display: none; } }
@media (max-width: 1099.98px) { .hb-shelf.is-row { --hb-cols: 6; } .hb-shelf.is-row > :nth-child(n + 7) { display: none; } }
@media (max-width: 767.98px) { .hb-shelf.is-row { --hb-cols: 4; } .hb-shelf.is-row > :nth-child(n + 5) { display: grid; } }

@media (prefers-reduced-motion: reduce) {
  .hb-book-cover img, .hb-pdf, .hb-flag { transition: none; }
}

/* ---- The shelf runs the full width of every row ----
   Each book draws its own piece of shelf (above). The last one in a shelf stretches
   its piece to the right edge, so a short row (fewer books than fit) still shows one
   long shelf instead of stopping after the last book. The grid clips it at its edge. */
.hb-shelf { overflow-x: clip; }
.hb-shelf > :last-child > .hb-book-cover::before,
.hb-shelf > :last-child > .hb-deal-art::before { right: -100vw; }

/* ---- Deal colours (shelf deal tiles and the home deals strip) ---- */
:is(.hb-deal-card, .hb-dl) {
  --dl-a: #dc2626;
  --dl-b: #7f1d1d;
  --dl-on: #fff;
  --dl-soft: rgba(255, 255, 255, 0.84);
  --dl-pill: rgba(255, 255, 255, 0.2);
  color: var(--dl-on);
  background:
    radial-gradient(circle at 85% 15%, rgba(255, 255, 255, 0.22), transparent 45%),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.06) 0 10px, transparent 10px 20px),
    linear-gradient(135deg, var(--dl-a), var(--dl-b));
}

:is(.hb-deal-card, .hb-dl).is-clearance {
  --dl-a: #e8c55e;
  --dl-b: #a8841f;
  --dl-on: #231c05;
  --dl-soft: rgba(35, 28, 5, 0.8);
  --dl-pill: rgba(35, 28, 5, 0.12);
}

:is(.hb-deal-card, .hb-dl).is-bundle { --dl-a: #2563eb; --dl-b: #1e3a8a; }
:is(.hb-deal-card, .hb-dl).is-free { --dl-a: #16a34a; --dl-b: #14532d; }

/* ---- A deal on a book shelf (_ShelfDeal; home page Today's Deals) ----
   As tall as a book cover in the same shelf (--hb-cols books to a row, at most 96px
   wide, 2:3), using its own wider column, so it stands on the shelf like the books. */
.hb-shelf.is-deals { container-type: inline-size; }

.hb-deal-art {
  position: relative;
  display: block;
  padding-bottom: 7px;
}

.hb-deal-art::before {
  content: "";
  position: absolute;
  z-index: 0;
  left: calc(var(--hb-gap) / -2 - 1px);
  right: calc(var(--hb-gap) / -2 - 1px);
  top: 50%;
  bottom: 0;
  background: linear-gradient(180deg, var(--bb-sage-100) 0, var(--bb-sage-100) calc(100% - 7px), var(--bb-sage-300) calc(100% - 7px));
}

.hb-deal-card {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  width: 100%;
  max-width: 150px;
  height: calc(1.5 * min(96px, (100cqi - (var(--hb-cols, 12) - 1) * var(--hb-gap)) / var(--hb-cols, 12)));
  margin-inline: auto;
  padding: 0.4rem 0.45rem 0;
  overflow: hidden;
  text-align: left;
  border-radius: 6px;
  box-shadow: 0 8px 14px -8px rgba(20, 30, 50, 0.7);
  transition: transform 0.25s ease;
}

.hb-deal:hover .hb-deal-card { transform: translateY(-6px); }

.hb-deal-type {
  align-self: flex-start;
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  background: var(--dl-pill);
  font-size: 0.5rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.hb-deal-big {
  margin-top: 0.1rem;
  font-size: 1.45rem;
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: -0.03em;
}

.hb-deal-big.is-words { font-size: 0.85rem; letter-spacing: -0.01em; }

.hb-deal-sub {
  font-size: 0.6rem;
  line-height: 1.2;
  color: var(--dl-soft);
}

.hb-deal-fan {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  margin-top: auto;
  transform: translateY(8px);
}

.hb-deal-fan img {
  width: 34%;
  max-width: 36px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 2px 4px 4px 2px;
  background: rgba(255, 255, 255, 0.3);
  box-shadow: inset 2px 0 0 rgba(0, 0, 0, 0.18), 0 4px 8px -4px rgba(0, 0, 0, 0.7);
}

.hb-deal-fan img + img { margin-left: -12%; }
.hb-deal-fan img:nth-child(1) { transform: rotate(-7deg); }
.hb-deal-fan img:nth-child(2) { position: relative; z-index: 1; transform: rotate(-1deg) translateY(-3px); }
.hb-deal-fan img:nth-child(3) { position: relative; z-index: 2; transform: rotate(6deg); }

.hb-deal .hb-book-title { max-width: 150px; }

.hb-deal-ends {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--blog-night-muted, #59614f);
}

.hb-deal-ends.is-soon { color: #b91c1c; }

@media (prefers-reduced-motion: reduce) {
  .hb-deal-card { transition: none; }
}

/* ---------- Covers or Spines (_ShelfViewSwitch, _ShelfSpines, shelf-view.js) ----------
   Each page has its own switch. In spines view a cover's place holds a few spines with
   the same blank title and price lines under it, so the rows, the shelf line and the
   first book stay exactly where they are; only the books change. */
.sv-switch {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--bb-sage-200, #d0dbc0);
  border-radius: 10px;
  background: var(--bb-sage-100, #e5eadb);
  vertical-align: middle;
}

.sv-switch button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #3b4530;
  cursor: pointer;
}

.sv-switch button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.sv-switch button[aria-pressed="true"] { background: #2f5d3a; color: #fff; }
.sv-switch button:focus-visible { outline: 3px solid var(--bb-blue-500, #3b82f6); outline-offset: 1px; }
.sv-switch.is-busy { opacity: 0.6; pointer-events: none; }

@media (hover: none), (pointer: coarse) {
  .sv-switch button { width: 44px; height: 40px; }
}

/* One cover's place: the spines stand in a cover-sized box and run on to where the
   next cover would start (shelf-view.js sets the run's width to the place's width
   and the gap). Places must not form their own layers (no z-index, no container
   query): then every spine box (z-index 1) stands above every piece of the shelf
   band (z-index 0), even where spines run on into the next place. */
.hb-spine-place { position: relative; }

.hb-spine-box {
  position: relative;
  z-index: 1;
  display: block;
  width: min(100%, 96px);
  aspect-ratio: 2 / 3;
  margin-inline: auto;
}

.hb-spine-run {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: calc(100% + var(--hb-gap));
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 60px 3px;
  padding-right: 3px;
  box-sizing: border-box;
  /* Room above for the hover lift, and to the sides for the hover cover; spines that
     don't fit wrap below the shelf and are cut off (shelf-view.js moves them on first). */
  clip-path: inset(-48px -130px 0 -130px);
}

.hb-spine {
  position: relative;
  display: flex;
  align-items: flex-end;
  flex: 1 0 var(--sp-w);
  height: 100%;
}

/* The place where the list ends: its spines keep their own thickness. */
.hb-spine-run.is-last .hb-spine { flex-grow: 0; }

.hb-spine[hidden] { display: none; }

/* The pointed-at spine (and its box, not the whole place, whose piece of the shelf
   band would then cover the spines beside it) come to the front, so its cover lies
   over the spines next to it. */
.hb-spine-box:has(.hb-spine:hover),
.hb-spine-box:has(.hb-spine:focus-within),
.hb-spine:hover,
.hb-spine:focus-within { z-index: 5; }

/* Its cover, cover-sized and only slightly see-through, beside the spine: it starts
   exactly where the next spine starts, so no sliver of that spine shows in between;
   on the left near the end of a row (is-flip, shelf-view.js). The mouse can move
   onto it (the ::before bridge fills the gap): it holds the heart and bookmark, "For
   Members", and opens the book. Touch screens use the panel. */
.hb-spine-cover {
  position: absolute;
  z-index: 4;
  bottom: 0;
  left: calc(100% + 3px);
  width: var(--sv-cover, 96px);
  aspect-ratio: 2 / 3;
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.hb-spine-cover::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -4px;
  width: 4px;
}

.hb-spine.is-flip .hb-spine-cover { left: auto; right: calc(100% + 3px); }
.hb-spine.is-flip .hb-spine-cover::before { left: auto; right: -4px; }

.hb-spine-cover-link { display: block; width: 100%; height: 100%; }

.hb-spine-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 2px 5px 5px 2px;
  background: var(--bb-sage-200, #d0dbc0);
  box-shadow: inset 3px 0 0 rgba(0, 0, 0, 0.16), 0 10px 22px -8px rgba(20, 30, 50, 0.55);
}

.hb-spine-cover .hb-pdf { top: 4px; right: 4px; transform: none; }

.hb-spine:hover .hb-spine-cover,
.hb-spine:focus-within .hb-spine-cover { opacity: 0.95; transform: none; pointer-events: auto; }

.hb-spine-body {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  height: var(--sp-h);
  padding: 10px 0 9px;
  box-sizing: border-box;
  overflow: hidden;
  border-radius: 3px 3px 0 0;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.22), transparent 18%, rgba(255, 255, 255, 0.14) 45%, transparent 60%, rgba(0, 0, 0, 0.18)),
    var(--sp-c);
  box-shadow: 0 6px 10px -6px rgba(20, 30, 50, 0.6);
  color: #fff;
  text-decoration: none;
  transition: transform 0.25s ease;
}

.hb-spine-body::before,
.hb-spine-body::after {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  height: 2px;
  background: rgba(255, 255, 255, 0.35);
}

.hb-spine-body::before { top: 5px; }
.hb-spine-body::after { bottom: 4px; }

.hb-spine-body:hover,
.hb-spine-body:focus-visible { color: #fff; }
.hb-spine-body:focus-visible { outline: 3px solid var(--bb-blue-500, #3b82f6); outline-offset: 2px; }

.hb-spine-body .hb-pdf {
  position: static;
  flex-shrink: 0;
  padding: 1px 2px;
  font-size: 0.48rem;
  transform: none;
}

.hb-spine-place:hover .hb-pdf { transform: none; }

.hb-spine-star { flex-shrink: 0; font-size: 0.6rem; line-height: 1; color: #ffe08a; }

.hb-spine-title {
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  font-size: 0.66rem;
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
  text-overflow: ellipsis;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

/* The price reads like the title, so long prices fit; sale prices in the sale blue. */
.hb-spine-price {
  flex-shrink: 0;
  padding: 3px 1px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.92);
  color: #1f2a1b;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "dlig" 0;
  white-space: nowrap;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.hb-spine-price.is-sale { background: #1d4ed8; color: #fff; }

/* Hover: the spine lifts as a cover does; the heart, bookmark and "For Members" are
   on its hover cover, so they show only on hover, even for saved books. */
.hb-spine:hover .hb-spine-body,
.hb-spine:focus-within .hb-spine-body { transform: translateY(-6px); }

.hb-spine-save {
  position: absolute;
  z-index: 3;
  bottom: 6px;
  right: 2px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hb-spine-members {
  position: absolute;
  z-index: 3;
  top: 5px;
  left: 5px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  color: #2f5d3a;
  font-size: 0.58rem;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
}

/* Touch screens: no hover, so a tap opens the panel below instead. */
@media (hover: none), (pointer: coarse) {
  .hb-spine-save, .hb-spine-members, .hb-spine-cover { display: none; }
}

/* ---- The panel a tap on a spine opens (touch screens) ---- */
.sv-sheet-back {
  position: fixed;
  inset: 0;
  z-index: 1090;
  background: rgba(30, 28, 20, 0.35);
}

.sv-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1091;
  display: grid;
  gap: 14px;
  max-width: 560px;
  margin-inline: auto;
  padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0;
  background: var(--wl-panel, #fff);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.2);
  color: var(--wl-ink, #1f2a1b);
}

.sv-sheet-top { display: flex; justify-content: space-between; align-items: center; }
.sv-sheet-grip { width: 40px; height: 4px; margin-inline: auto; border-radius: 4px; background: var(--bb-sage-200, #d0dbc0); }

.sv-sheet-close {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: -6px -10px -6px 0;
  border: 0;
  background: none;
  color: inherit;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.sv-sheet-book { display: flex; gap: 14px; align-items: flex-start; }

.sv-sheet-book img {
  flex-shrink: 0;
  width: 80px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 2px 5px 5px 2px;
  box-shadow: inset 3px 0 0 rgba(0, 0, 0, 0.16), 0 6px 10px -6px rgba(20, 30, 50, 0.6);
}

.sv-sheet-info { display: grid; gap: 3px; min-width: 0; }
.sv-sheet-info .hb-pdf { position: static; justify-self: start; font-size: 0.62rem; transform: none; }
.sv-sheet-title { font-size: 1.02rem; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.sv-sheet-author, .sv-sheet-format { font-size: 0.86rem; color: var(--wl-muted, #66705f); }
.sv-sheet-price { font-size: 0.98rem; font-weight: 700; color: var(--bb-blue-900, #1e3a8a); }
.sv-sheet-price.is-sale { color: #1d4ed8; }

.sv-sheet-saves { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

.sv-sheet-saves button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  border: 1.5px solid var(--wl-line, #e2e6dc);
  border-radius: 12px;
  background: var(--wl-panel, #fff);
  color: inherit;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.sv-sheet-saves svg { width: 18px; height: 18px; fill: none; stroke-width: 2.2; stroke-linejoin: round; }
.sv-sheet-saves .is-fav svg { stroke: var(--wl-heart, #d6336c); }
.sv-sheet-saves .is-wish svg { stroke: var(--wl-sage, #718a56); }
.sv-sheet-saves .is-fav[aria-pressed="true"] { border-color: var(--wl-heart, #d6336c); background: var(--wl-heart-soft, #fdf0f4); }
.sv-sheet-saves .is-fav[aria-pressed="true"] svg { fill: var(--wl-heart, #d6336c); }
.sv-sheet-saves .is-wish[aria-pressed="true"] { border-color: var(--wl-sage, #718a56); background: var(--wl-sage-soft, #eef3e8); }
.sv-sheet-saves .is-wish[aria-pressed="true"] svg { fill: var(--wl-sage, #718a56); }

.sv-sheet-open {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 12px;
  background: #2f5d3a;
  color: #fff;
  font-weight: 700;
  text-decoration: none;
}

.sv-sheet-open:hover, .sv-sheet-open:focus-visible { color: #fff; background: #244a2d; }

@media (prefers-reduced-motion: reduce) {
  .hb-spine-body, .hb-spine-save, .hb-spine-members, .hb-spine-cover { transition: none; }
}

/* A heading or sentence with the switch beside it (blog posts, Book Alerts). */
.sv-switch-line { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 0.75rem; }
.sv-switch-line > h2 { margin: 0; }
p.sv-switch-line { justify-content: flex-start; margin: 0.5rem 0 0; font-size: 0.9rem; }
