.books-list {
  display: block;
  font-size: inherit;
  /* inherit global body size so theme.json changes take effect */
  line-height: 1.8;
}

/* Synopsis paragraphs: indent first line */
.books-list .book-synopsis p {
  text-indent: 2rem;
}

/* Synopsis fade: gradient mask to tease more content on list page.
   The min-height ensures the fade happens at or below the cover bottom. */
.books-list .book-synopsis.has-fade {
  position: relative;
  /* Minimum height scales with viewport to roughly align with cover */
  min-height: max(10em, 20vh);
  max-height: max(14em, 28vh);
  overflow: hidden;
}

.books-list .book-synopsis.has-fade::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4em;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.18s ease;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    var(--wp--preset--color--surface, #fff) 75%
  );
}

/* Progressive enhancement: Read more expands synopsis in-place (JS toggles classes + max-height) */
.books-list .book-synopsis.has-fade.is-animating {
  transition: max-height 0.32s ease;
}

.books-list .book-synopsis.has-fade.is-expanded {
  min-height: 0;
  max-height: none;
  overflow: visible;
}

.books-list .book-synopsis.has-fade.is-expanded::after {
  opacity: 0;
}

.books-list .book-synopsis.has-fade.is-expanded + .book-read-more {
  display: none;
}

/* Reviews preview reveal (progressive enhancement) */
.books-list .book-reviews-preview {
  margin-top: 1.5rem;
  opacity: 1;
}

.books-list .book-reviews-preview.is-animating {
  transition: max-height 0.32s ease, opacity 0.18s ease;
  will-change: max-height;
}

/* Read more link: positioned below the fade with separator */
.books-list .book-read-more {
  position: relative;
  margin-top: 0.5rem;
  padding-top: 1rem;
  z-index: 1;
  text-align: center;
  border-top: 1px solid color-mix(in srgb, var(--wp--preset--color--contrast) 12%, transparent);
}

.books-list .book-read-more .read-more-link {
  display: inline-block;
  font-size: var(--wp--preset--font-size--medium-plus);
  font-weight: 600;
  color: var(--wp--preset--color--primary);
  text-decoration: none;
  transition: color 0.15s ease;
}

.books-list .book-read-more .read-more-link:hover,
.books-list .book-read-more .read-more-link:focus-visible {
  color: var(--wp--preset--color--tertiary);
}

/* Excerpt hero on list: larger emphasized text as dramatic hook */
.books-list .book-excerpt-inline.is-hero {
  font-size: var(--wp--preset--font-size--large);
  font-weight: 500;
  font-style: normal;
  line-height: 1.4;
  margin-top: 1.25rem;
  margin-bottom: 0.75rem;
  padding: 1rem 2rem;
  border-width: 1px;
  border-style: solid;
  border-color: color-mix(in srgb, var(--wp--preset--color--contrast) 8%, transparent);
  border-radius: 10px;
  border-top-style: none;
  border-bottom-style: none;
}

.books-list .book-excerpt-inline.is-hero p {
  margin: 0 0 0.5em;
  text-indent: 2rem;
}

.books-list .book-excerpt-inline.is-hero p:last-child {
  margin-bottom: 0;
}

.books-list .books-list-items>.single-book {
  margin-bottom: 7rem;
}

@media (max-width: 50em) {
  /* More spacing between books on mobile for clearer separation */
  .books-list .books-list-items>.single-book {
    margin-bottom: 8rem;
  }
}

.books-list .books-list-items>.single-book:last-child {
  margin-bottom: 0;
}

.books-list.has-book-separators .books-list-items>.single-book {
  margin-bottom: 4.25rem;
}

.books-list.has-book-separators .books-list-items>.single-book:not(:first-of-type) {
  border-top: var(--literary-separator-thickness, 1px) solid var(--literary-separator-color, color-mix(in srgb, var(--wp--preset--color--contrast) 30%, transparent));
  padding-top: 4.25rem;
  margin-top: 0;
}

@media (max-width: 50em) {
  /* Increased spacing between books with separators on mobile */
  .books-list.has-book-separators .books-list-items>.single-book {
    margin-bottom: 4.75rem;
  }

  .books-list.has-book-separators .books-list-items>.single-book:not(:first-of-type) {
    padding-top: 4.75rem;
  }
}

.books-list .single-book .entry-title {
  font-size: var(--title-size);
  line-height: 1.15;
  margin: .25rem 0;
}

.books-list .single-book .entry-title a {
  color: inherit;
  text-decoration: none;
}

.books-list .single-book .entry-title a:hover,
.books-list .single-book .entry-title a:focus-visible {
  color: var(--wp--preset--color--primary);
  text-decoration: underline;
  text-underline-offset: .15em;
}

.books-list .single-book .book-hero {
  display: block;
  position: relative;
}

.books-list .single-book .book-hero::after {
  content: "";
  display: block;
  clear: both;
}

.books-list {
  --books-rail-thumb-radius: var(--literary-rail-thumb-radius, 2px);
}

.books-list.has-square-rail {
  --books-rail-thumb-radius: 0px;
}

.books-list .single-book {
  --book-cover-max: clamp(240px, 26vw, 340px);
}

/* Ease the no-wrap grid → float switch at 80em by keeping cover sizing closer
   to the ≥80em grid column width in the immediately-narrower range. */
@media (min-width: 70em) and (max-width: 80em) {
  .books-list.no-wrap-at-full-width .single-book {
    --book-cover-max: clamp(240px, 30vw, 420px);
  }
}

.books-list .single-book .book-cover {
  width: min(var(--book-cover-max, 320px), 40%);
  max-width: min(var(--book-cover-max, 320px), 40%);
  min-width: var(--book-cover-min, 240px);
  /* avoid tiny covers on short viewports */
  aspect-ratio: var(--book-cover-aspect, 2 / 3);
  border-radius: var(--book-cover-radius, var(--literary-cover-radius, 8px));
  overflow: hidden;
}

.books-list.books-list--left .single-book .book-cover {
  float: left;
  margin: 0 2rem 0.75rem 0;
}

.books-list.books-list--right .single-book .book-cover {
  float: right;
  margin: 0 0 0.75rem 2rem;
}

.books-list .single-book .book-cover img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: inherit;
}

.books-list .single-book .book-overview {
  /* Prevent borders/backgrounds (e.g., excerpt box + read-more separator)
     from spanning underneath the floated cover at mid widths. */
  display: flow-root;
  min-width: 0;
}

/* Ensure no extra bottom margin from last paragraph breaks vertical centering */
.books-list .single-book .book-overview > :last-child,
.books-list .single-book .book-overview > :last-child > :last-child {
  margin-bottom: 0;
}

/* Up to mid widths (container-driven): collapse in stages for readability.
   Stage 1: move synopsis below the cover for a comfortable measure.
   Stage 2: move excerpt below once the content column is narrower still.
   Uses the usable content column width (accounts for side rail), not viewport width. */
@container books-list-items (max-width: 70rem) {
  .books-list .single-book .book-overview {
    /* Allow clear: both on child sections to take effect vs the floated cover. */
    display: block;
  }

  .books-list .single-book .book-synopsis {
    clear: both;
  }

  /* Prevent the excerpt callout border/background from painting under the floated cover */
  .books-list .single-book .book-excerpt-inline.is-hero {
    display: flow-root;
  }

  /* Synopsis preview no longer needs cover-driven minimum height when cleared */
  .books-list .single-book .book-synopsis.has-fade {
    min-height: 0;
  }
}

@container books-list-items (max-width: 56.25rem) {
  /* Stage 2: when excerpt becomes full-width, cap measure for readability */
  .books-list .single-book .book-excerpt-inline.is-hero {
    clear: both;
    max-width: 70ch;
    margin-inline: auto;
  }
}

@media (max-width: 50em) {
  .books-list .single-book .book-cover {
    float: none !important;
    margin: 0 auto 3rem !important;
    max-width: 360px;
    width: 100%;
  }
}

@media (min-width: 80em) {
  .books-list.no-wrap-at-full-width .single-book .book-hero {
    display: grid;
    column-gap: 2rem;
    row-gap: 0;
    align-items: start;
  }

  .books-list.no-wrap-at-full-width .single-book .book-cover {
    float: none;
    margin: 0;
    width: 100%;
    max-width: none;
    min-width: 260px;
  }

  .books-list.no-wrap-at-full-width.books-list--left .single-book .book-hero {
    grid-template-columns: minmax(260px, min(49dvh, 420px)) 1fr;
  }

  .books-list.no-wrap-at-full-width.books-list--left .single-book .book-cover {
    grid-column: 1;
  }

  .books-list.no-wrap-at-full-width.books-list--right .single-book .book-hero {
    grid-template-columns: 1fr minmax(260px, min(49dvh, 420px));
  }

  .books-list.no-wrap-at-full-width.books-list--right .single-book .book-cover {
    grid-column: 2;
  }
}

/* Widescreen tuning: enlarge cover column and rail density on list view */
@media (min-width: 80em) {

  /* Only affect the float layout (not the optional grid variant) */
  .books-list:not(.no-wrap-at-full-width) .single-book .book-cover {
    /* Size the cover by viewport height so at least one fits on screen */
    width: 49dvh;
    max-width: 46%;
    min-width: 260px;
  }

  /* Side rails: set thumbnail height to 96px; width follows aspect (0.647) */
  .books-rail.rail-right,
  .books-rail.rail-left {
    --books-rail-thumb-h: 96px;
  }

  /* Slightly larger thumbnails in the rail to balance the composition */
  .books-list.has-rail {
    --books-rail-thumb-h: 72px;
  }

  /* Synopsis paragraphs inherit the site default font size at widescreen */
  .books-list .single-book .book-overview .book-synopsis p {
    font-size: inherit;
  }

  /* Excerpt hero: bump up further on wide screens */
  .books-list .book-excerpt-inline.is-hero {
    font-size: var(--wp--preset--font-size--x-large);
  }

  /* Awards/featured reviews: slightly emphasized size on list page */
  .books-list .single-book .book-overview .book-awards-inline,
  .books-list .single-book .book-overview .book-featured-reviews,
  .books-list .single-book .book-overview .book-featured-reviews .book-review-quote,
  .books-list .single-book .book-overview .book-highlight-review .book-review-quote,
  .books-list .single-book .book-overview .book-awards-inline .book-review-quote {
    font-size: var(--wp--preset--font-size--medium-plus);
  }

  /* Attribution/source text uses smaller configurable size */
  .books-list .single-book .book-overview .book-featured-reviews .book-review-source,
  .books-list .single-book .book-overview .book-awards-inline .book-review-source {
    font-size: var(--literary-attribution-size, 0.8em);
  }

  /* Ensure any lingering list-page review quotes scale as requested */
  .books-list .book-review-quote {
    font-size: inherit;
  }
}

/* Books Rail (scroll indicator + jump navigation) */
.books-list.has-rail {
  position: relative;
}

.books-rail {
  position: sticky;
  top: var(--books-rail-top, 72px);
  z-index: 1;
  align-self: flex-start;
  height: calc(100vh - var(--books-rail-top, 72px) - 16px);
  display: flex;
}

.books-rail {
  --books-rail-cal-top: 0px;
  --books-rail-cal-bottom: 0px;
}

.books-rail.rail-right {
  float: right;
  margin-left: 2.5rem;
}

.books-rail.rail-left {
  float: left;
  margin-right: 2.5rem;
}

.books-rail-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--books-rail-gap, 14px);
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.books-rail-item {
  line-height: 0;
}

.books-rail-link {
  display: block;
  height: var(--books-rail-thumb-h, 64px);
  width: calc(var(--books-rail-thumb-h, 64px) * var(--books-rail-aspect, 0.647));
  border-radius: var(--books-rail-thumb-radius, var(--literary-rail-thumb-radius, 2px));
  opacity: .6;
  filter: grayscale(25%);
  transition: opacity .16s linear, filter .16s linear, outline-color .16s linear;
  outline: 2px solid transparent;
  outline-offset: 2px;
  overflow: visible;
}

.books-rail-link:hover,
.books-rail-link:focus-visible {
  opacity: .9;
  filter: grayscale(8%);
}

/* Suppress old static highlight box; moving cursor provides the visual affordance */
.books-rail-link[aria-current="true"] {
  opacity: 1;
  filter: none;
  outline: 2px solid var(--wp--preset--color--primary, currentColor);
  outline-offset: 2px;
}

/* Pointer navigation mode suppresses :focus outlines globally.
   Ensure the selected rail item remains visibly selected after click focus. */
body.literary-pointer-navigation .books-rail-link[aria-current="true"] {
  outline: 2px solid var(--wp--preset--color--primary, currentColor);
  outline-offset: 2px;
}

/* Ensure only the current item shows the red border even if another link retains focus */
.books-rail-link:focus-visible:not([aria-current="true"]) {
  /* Ensure keyboard users see focus, without forcing primary unless current */
  outline: 2px solid var(--wp--preset--color--gunmetal, currentColor);
  outline-offset: 2px;
}

.books-rail-link img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  border-radius: var(--books-rail-thumb-radius, var(--literary-rail-thumb-radius, 2px)) !important;
  background: transparent;
}

.books-rail-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, .05);
  color: rgba(0, 0, 0, .6);
  font-weight: 600;
  border-radius: var(--books-rail-thumb-radius, var(--literary-rail-thumb-radius, 2px));
}

/* Remove custom marker; rely on native scrollbar and aria-current outline */
.books-list {
  --books-rail-side-offset: calc(calc(var(--books-rail-thumb-h, 64px) * var(--books-rail-aspect, 0.647)) + 28px);
}

.books-list .books-list-items {
  display: flow-root;
  container-type: inline-size;
  container-name: books-list-items;
}

/* Enable container queries for content-driven layout switches */
.books-list {
  container-type: inline-size;
}

/* Bottom rail default: reserve bottom space for filmstrip */
.books-list.has-rail.rail-bottom .books-list-items {
  margin-bottom: calc(var(--books-rail-thumb-h, 64px) + 22px);
}

.books-list.has-rail.rail-top .books-list-items {
  margin-top: calc(var(--books-rail-thumb-h, 64px) + 22px);
}

.books-list-anchor {
  display: block;
  height: 0;
  margin: 0;
  padding: 0;
  /* Ensure anchor offsets account for sticky rail offset */
  scroll-margin-top: calc(var(--books-rail-top, 72px) + 8px);
}

/* Removed unused direct-child selectors; anchors carry scroll-margin instead */

/* Horizontal filmstrip variants */
.books-rail.rail-bottom {
  --books-rail-height: calc(var(--books-rail-thumb-h, 84px) + var(--books-rail-progress-gap, 10px) + var(--books-rail-progress-w, 2px) + 16px);
  position: sticky;
  top: calc(100svh - var(--books-rail-height));
  bottom: auto;
  float: none;
  width: 100%;
  margin: 0;
  padding: .5rem 0;
  background: var(--wp--preset--color--surface);
  border-top: 1px solid rgba(0, 0, 0, .06);
  height: auto;
}

.books-rail.rail-top {
  --books-rail-thumb-h: 6rem;
  position: sticky;
  top: 0;
  bottom: auto;
  float: none;
  width: 100%;
  margin: 0;
  padding: .5rem 0;
  background: var(--wp--preset--color--surface);
  border-bottom: 1px solid rgba(0, 0, 0, .06);
  height: auto;
  z-index: 1;
}

.books-rail.rail-bottom .books-rail-list,
.books-rail.rail-top .books-rail-list {
  flex-direction: row;
  max-height: none;
  overflow-x: hidden;
  overflow-y: hidden;
  padding: 8px .75rem;
  justify-content: space-evenly;
  align-items: center;
  width: 100%;
}

/* Content-based switch: when container is too narrow for side rail, convert left/right to bottom filmstrip */
:root {
  --rail-switch-text-min: 45ch;
  --rail-switch-img-min: 22rem;
  --rail-switch-gap: 1.25rem;
}

@container (max-width: calc(var(--rail-switch-text-min) + var(--rail-switch-img-min) + var(--rail-switch-gap))) {

  .books-rail.rail-right,
  .books-rail.rail-left {
    --books-rail-height: calc(var(--books-rail-thumb-h, 84px) + var(--books-rail-progress-gap, 10px) + var(--books-rail-progress-w, 2px) + 16px);
    position: sticky;
    top: calc(100svh - var(--books-rail-height));
    bottom: auto;
    float: none;
    width: 100%;
    margin: 0;
    /* Cancel normal-flow height so content isn't pushed down when rail converts */
    margin-bottom: calc(var(--books-rail-height) * -1);
    padding: .5rem 0;
    background: var(--wp--preset--color--surface);
    border-top: 1px solid rgba(0, 0, 0, .06);
    height: auto;
  }

  .books-rail.rail-right .books-rail-list,
  .books-rail.rail-left .books-rail-list {
    flex-direction: row;
    max-height: none;
    overflow-x: hidden;
    overflow-y: hidden;
    padding: 8px .75rem;
    justify-content: space-evenly;
    align-items: center;
    width: 100%;
  }

  /* Horizontal progress bar for converted side rails (default to top) */
  .books-rail.rail-right .books-rail-hscrollbar,
  .books-rail.rail-left .books-rail-hscrollbar {
    top: 0;
    bottom: auto;
  }

  .books-rail.rail-right.sb-bottom .books-rail-hscrollbar,
  .books-rail.rail-left.sb-bottom .books-rail-hscrollbar {
    bottom: 0;
    top: auto;
  }

  .books-rail.rail-right .books-rail-hscrollbar-thumb,
  .books-rail.rail-left .books-rail-hscrollbar-thumb {
    position: absolute;
    left: 0;
    top: 0;
    height: var(--literary-rail-thumb-width, 3px);
    width: 24px;
    background: var(--wp--preset--color--primary);
    border-radius: var(--books-rail-thumb-radius, var(--literary-rail-thumb-radius, 2px));
    transform: translateX(0);
    transition: transform .08s linear, width .12s ease;
  }

  /* Add horizontal gap when converted (default to top) */
  .books-rail.rail-right .books-rail-list,
  .books-rail.rail-left .books-rail-list {
    padding-top: calc(var(--books-rail-progress-gap, 10px) + var(--books-rail-progress-w, 2px));
    padding-bottom: 0;
  }

  .books-rail.rail-right.sb-bottom .books-rail-list,
  .books-rail.rail-left.sb-bottom .books-rail-list {
    padding-bottom: calc(var(--books-rail-progress-gap, 10px) + var(--books-rail-progress-w, 2px));
    padding-top: 0;
  }

  .books-list.has-rail.rail-right .books-list-items,
  .books-list.has-rail.rail-left .books-list-items {
    margin-bottom: calc(var(--books-rail-thumb-h, 64px) + 22px);
  }
}

/* Fallback for browsers without container queries: use em-based viewport MQ */
@supports not (container-type: inline-size) {
  /* Mid widths (viewport fallback): approximate the container-driven collapse behavior. */
  @media (max-width: 70em) {
    .books-list .single-book .book-overview {
      display: block;
    }

    .books-list .single-book .book-synopsis {
      clear: both;
    }

    .books-list .single-book .book-excerpt-inline.is-hero {
      display: flow-root;
    }

    .books-list .single-book .book-synopsis.has-fade {
      min-height: 0;
    }
  }

  @media (max-width: 56.25em) {
    .books-list .single-book .book-excerpt-inline.is-hero {
      clear: both;
      max-width: 70ch;
      margin-inline: auto;
    }
  }

  @media (max-width: 60em) {

    .books-rail.rail-right,
    .books-rail.rail-left {
      --books-rail-height: calc(var(--books-rail-thumb-h, 84px) + var(--books-rail-progress-gap, 10px) + var(--books-rail-progress-w, 2px) + 16px);
      position: sticky;
      top: calc(100svh - var(--books-rail-height));
      bottom: auto;
      float: none;
      width: 100%;
      /* Cancel normal-flow height so content isn't pushed down when rail converts */
      margin-bottom: calc(var(--books-rail-height) * -1);
    }

    .books-rail.rail-right .books-rail-list,
    .books-rail.rail-left .books-rail-list {
      flex-direction: row;
      justify-content: space-evenly;
      overflow-y: hidden;
    }

    .books-rail.rail-right .books-rail-hscrollbar,
    .books-rail.rail-left .books-rail-hscrollbar {
      position: absolute;
      left: 0;
      right: 0;
      height: var(--books-rail-progress-w, 2px);
      background: transparent;
      z-index: 2;
      top: 0;
      bottom: auto;
    }

    .books-rail.rail-right.sb-bottom .books-rail-hscrollbar,
    .books-rail.rail-left.sb-bottom .books-rail-hscrollbar {
      bottom: 0;
      top: auto;
    }

    .books-rail.rail-right .books-rail-hscrollbar-thumb,
    .books-rail.rail-left .books-rail-hscrollbar-thumb {
      position: absolute;
      left: 0;
      top: 0;
      height: var(--literary-rail-thumb-width, 3px);
      width: 24px;
      background: var(--wp--preset--color--primary);
      border-radius: var(--books-rail-thumb-radius, var(--literary-rail-thumb-radius, 2px));
      transform: translateX(0);
      transition: transform .08s linear, width .12s ease;
    }

    .books-rail.rail-right .books-rail-list,
    .books-rail.rail-left .books-rail-list {
      padding-top: calc(var(--books-rail-progress-gap, 10px) + var(--books-rail-progress-w, 2px));
      padding-bottom: 0;
    }

    .books-rail.rail-right.sb-bottom .books-rail-list,
    .books-rail.rail-left.sb-bottom .books-rail-list {
      padding-bottom: calc(var(--books-rail-progress-gap, 10px) + var(--books-rail-progress-w, 2px));
      padding-top: 0;
    }

    .books-list.has-rail.rail-right .books-list-items,
    .books-list.has-rail.rail-left .books-list-items {
      margin-bottom: calc(var(--books-rail-thumb-h, 64px) + 22px);
    }
  }
}

/* Additional viewport fallback: force side rails to bottom on narrow viewports */
@media (max-width: 56em) {

  .books-rail.rail-right,
  .books-rail.rail-left {
    --books-rail-height: calc(var(--books-rail-thumb-h, 84px) + var(--books-rail-progress-gap, 10px) + var(--books-rail-progress-w, 2px) + 16px);
    position: sticky;
    top: calc(100svh - var(--books-rail-height));
    bottom: auto;
    float: none;
    width: 100%;
    margin: 0;
    /* Cancel normal-flow height so content isn't pushed down when rail converts */
    margin-bottom: calc(var(--books-rail-height) * -1);
    padding: .5rem 0;
    background: var(--wp--preset--color--surface);
    border-top: 1px solid rgba(0, 0, 0, .06);
    height: auto;
  }

  .books-rail.rail-right .books-rail-list,
  .books-rail.rail-left .books-rail-list {
    flex-direction: row;
    max-height: none;
    overflow-x: hidden;
    overflow-y: hidden;
    padding: 8px .75rem;
    justify-content: space-evenly;
    align-items: center;
    width: 100%;
  }

  .books-rail.rail-right .books-rail-hscrollbar,
  .books-rail.rail-left .books-rail-hscrollbar {
    position: absolute;
    left: 0;
    right: 0;
    height: var(--books-rail-progress-w, 2px);
    background: transparent;
    z-index: 2;
    top: 0;
    bottom: auto;
  }

  .books-rail.rail-right.sb-bottom .books-rail-hscrollbar,
  .books-rail.rail-left.sb-bottom .books-rail-hscrollbar {
    bottom: 0;
    top: auto;
  }

  .books-rail.rail-right .books-rail-hscrollbar-thumb,
  .books-rail.rail-left .books-rail-hscrollbar-thumb {
    position: absolute;
    left: 0;
    top: 0;
    height: var(--literary-rail-thumb-width, 3px);
    width: 24px;
    background: var(--wp--preset--color--primary);
    border-radius: var(--books-rail-thumb-radius, var(--literary-rail-thumb-radius, 2px));
    transform: translateX(0);
    transition: transform .08s linear, width .12s ease;
  }

  .books-list.has-rail.rail-right .books-list-items,
  .books-list.has-rail.rail-left .books-list-items {
    margin-bottom: calc(var(--books-rail-thumb-h, 64px) + 22px);
  }
}

/* Styled scrollbar for rail list (native scrollbar) */
/* Applies to all rails (top/bottom/left/right) to ensure editor visibility */
.books-rail-list {
  scrollbar-width: thin;
  scrollbar-color: var(--wp--preset--color--primary) transparent;
}

.books-rail-list::-webkit-scrollbar {
  height: 9px;
  width: 9px;
}

.books-rail-list::-webkit-scrollbar-track {
  background: transparent;
  border-radius: var(--books-rail-thumb-radius, var(--literary-rail-thumb-radius, 2px));
}

.books-rail-list::-webkit-scrollbar-thumb {
  background: var(--wp--preset--color--primary);
  border-radius: var(--books-rail-thumb-radius, var(--literary-rail-thumb-radius, 2px));
}

/* Inline custom horizontal progress bar inside the rail */
.books-rail.rail-bottom .books-rail-hscrollbar,
.books-rail.rail-top .books-rail-hscrollbar {
  position: absolute;
  left: 0;
  right: 0;
  height: var(--literary-rail-track-width, 1px); /* Faint track */
  background: color-mix(in srgb, var(--wp--preset--color--contrast) 8%, transparent);
  z-index: 2;
  overflow: visible;
  pointer-events: auto;
  cursor: pointer;
}

.books-rail.rail-bottom.sb-bottom .books-rail-hscrollbar,
.books-rail.rail-top.sb-bottom .books-rail-hscrollbar {
  bottom: 0;
  top: auto;
}

.books-rail.rail-bottom.sb-top .books-rail-hscrollbar,
.books-rail.rail-top.sb-top .books-rail-hscrollbar {
  top: 0;
  bottom: auto;
}

.books-rail.rail-bottom .books-rail-hscrollbar-thumb,
.books-rail.rail-top .books-rail-hscrollbar-thumb {
  position: absolute;
  left: 0;
  top: 0; /* Align thumb top with track top */
  height: var(--literary-rail-thumb-width, 3px);
  width: 24px;
  background: var(--wp--preset--color--primary);
  border-radius: 999px;
  transform: translateX(0);
  transition: transform .08s linear, width .12s ease;
  cursor: grab;
}

.books-rail.rail-bottom .books-rail-hscrollbar-thumb:active,
.books-rail.rail-top .books-rail-hscrollbar-thumb:active {
  cursor: grabbing;
}

/* Add gap between horizontal scrollbar and covers */
.books-rail.rail-bottom.sb-bottom .books-rail-list,
.books-rail.rail-top.sb-bottom .books-rail-list {
  padding-bottom: calc(var(--books-rail-progress-gap, 10px) + var(--books-rail-progress-w, 2px));
}

.books-rail.rail-bottom.sb-top .books-rail-list,
.books-rail.rail-top.sb-top .books-rail-list {
  padding-top: calc(var(--books-rail-progress-gap, 10px) + var(--books-rail-progress-w, 2px));
}

/* Inline custom vertical progress bar for side rails */
.books-rail.rail-right .books-rail-vscrollbar,
.books-rail.rail-left .books-rail-vscrollbar {
  position: absolute;
  top: 0;
  bottom: 0;
  width: var(--literary-rail-track-width, 1px); /* Faint track */
  background: color-mix(in srgb, var(--wp--preset--color--contrast) 8%, transparent);
  z-index: 2;
  pointer-events: auto;
  overflow: visible;
  cursor: pointer;
}

.books-rail.rail-right.sb-right .books-rail-vscrollbar {
  right: 0;
  left: auto;
}

.books-rail.rail-right.sb-left .books-rail-vscrollbar {
  left: 0;
  right: auto;
}

.books-rail.rail-left.sb-left .books-rail-vscrollbar {
  left: 0;
  right: auto;
}

.books-rail.rail-left.sb-right .books-rail-vscrollbar {
  right: 0;
  left: auto;
}

.books-rail.rail-right .books-rail-vscrollbar-thumb,
.books-rail.rail-left .books-rail-vscrollbar-thumb {
  position: absolute;
  left: 50%; /* Center relative to track */
  top: 0;
  width: var(--literary-rail-thumb-width, 3px); /* Scrollbar thumb */
  height: 24px;
  background: var(--wp--preset--color--primary);
  border-radius: 999px;
  margin-left: calc(var(--literary-rail-thumb-width, 3px) / -2); /* Half of thumb width */
  transform: translateY(0);
  transition: transform .08s linear, height .12s ease;
  cursor: grab;
}

.books-rail.rail-right .books-rail-vscrollbar-thumb:active,
.books-rail.rail-left .books-rail-vscrollbar-thumb:active {
  cursor: grabbing;
}

/* Reduced motion: neutralize non-essential transitions in rail */
@media (prefers-reduced-motion: reduce) {

  .books-list .book-synopsis.has-fade.is-animating,
  .books-list .book-reviews-preview.is-animating,
  .books-list .book-synopsis.has-fade::after {
    transition: none !important;
  }

  .books-rail-link,
  .books-rail .books-rail-hscrollbar-thumb,
  .books-rail .books-rail-vscrollbar-thumb {
    transition: none !important;
  }
}

/* Reserve space so the vertical progress bar does not overlap thumbnails */
.books-rail {
  --books-rail-progress-w: 1px; /* Faint track width */
  --books-rail-progress-gap: 10px;
}

/* Side rails: set vertical scrollbar width to 1px */
.books-rail.rail-right,
.books-rail.rail-left {
  --books-rail-progress-w: 1px;
  --books-rail-gap: 10px;
  /* tighten vertical spacing */
}

/* Padding for outward-facing scrollbar (balanced) */
.books-rail.rail-right.sb-right .books-rail-list {
  padding-right: calc(var(--books-rail-progress-gap, 8px) + var(--books-rail-progress-w, 2px));
}

.books-rail.rail-left.sb-left .books-rail-list {
  padding-left: calc(var(--books-rail-progress-gap, 8px) + var(--books-rail-progress-w, 2px));
}

/* Padding for inward-facing scrollbar (default "auto" setting, unbalanced as requested) */
.books-rail.rail-right.sb-left .books-rail-list {
  padding-left: calc(8px + var(--books-rail-progress-gap, 8px) + var(--books-rail-progress-w, 2px));
  padding-right: 4px;
}

.books-rail.rail-left.sb-right .books-rail-list {
  padding-right: calc(8px + var(--books-rail-progress-gap, 8px) + var(--books-rail-progress-w, 2px));
  padding-left: 4px;
}

/* Even spacing for vertical rails, similar to top/bottom */
.books-rail.rail-right .books-rail-list,
.books-rail.rail-left .books-rail-list {
  justify-content: space-evenly;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Match progress bar width to variable */
.books-rail.rail-right .books-rail-vscrollbar,
.books-rail.rail-left .books-rail-vscrollbar {
  width: var(--books-rail-progress-w, 9px);
}

/* When rail is on a side, force the cover to the opposite side to avoid float collisions/gaps */
/* Preserve user-chosen cover float; rail is isolated by the inner wrapper */

/* Mobile/narrow view: thicker scrollbar and stronger visual delineation */
@media (max-width: 56em) {
  /* Use thicker scrollbar dimensions for touch-friendly interaction */
  .books-rail.rail-bottom,
  .books-rail.rail-top,
  .books-rail.rail-right,
  .books-rail.rail-left {
    --literary-rail-track-width: var(--literary-rail-track-width-mobile, 2px);
    --literary-rail-thumb-width: var(--literary-rail-thumb-width-mobile, 6px);
  }

  /* Stronger visual border/separator between rail and content */
  .books-rail.rail-bottom,
  .books-rail.rail-right,
  .books-rail.rail-left {
    border-top: var(--literary-rail-thumb-width-mobile, 6px) solid color-mix(in srgb, var(--wp--preset--color--contrast) 15%, transparent);
    box-shadow: 0 -4px 12px -4px rgba(0, 0, 0, 0.08);
  }

  /* Position scrollbar thumb to overlap the border-top (the visual track) */
  .books-rail.rail-bottom .books-rail-hscrollbar-thumb,
  .books-rail.rail-right .books-rail-hscrollbar-thumb,
  .books-rail.rail-left .books-rail-hscrollbar-thumb {
    top: calc(var(--literary-rail-thumb-width-mobile, 6px) * -1);
  }

  .books-rail.rail-top {
    border-bottom: 2px solid color-mix(in srgb, var(--wp--preset--color--contrast) 15%, transparent);
    box-shadow: 0 4px 12px -4px rgba(0, 0, 0, 0.08);
  }

  /* Ensure horizontal scrollbar thumb uses mobile thickness */
  .books-rail .books-rail-hscrollbar-thumb {
    height: var(--literary-rail-thumb-width-mobile, 6px);
  }

  /* Ensure the track also updates */
  .books-rail .books-rail-hscrollbar {
    height: var(--literary-rail-track-width-mobile, 2px);
  }

  /* Add bottom padding to books-list container so footer isn't hidden behind sticky rail */
  .books-list.has-rail {
    padding-bottom: calc(var(--books-rail-thumb-h, 84px) + 32px);
  }
}

/* Ensure footer is never hidden behind the sticky rail */
.books-list.has-rail + footer,
.single-book-page + footer,
main:has(.books-list.has-rail) ~ footer {
  position: relative;
  z-index: 2;
}

/* ============================================
   Outside Rail Mode
   ============================================
   When rail-layout-outside is set and viewport is wide enough,
   position the rail fixed to the browser window edge.
   Breakpoint set to 105em (~1680px) to ensure scrollbar clears
   content area before switching to outside mode.
   ============================================ */

@media (min-width: 105em) {

  /* Content constraints and centering for outside rail mode */
  .books-list.rail-layout-outside .books-list-items {
    max-width: calc(420px + 85ch + 2rem);
    margin-inline: auto;
  }

  .books-list.rail-layout-outside .single-book .book-cover {
    max-width: 420px;
  }

  .books-list.rail-layout-outside .single-book .book-overview {
    max-width: 85ch;
  }

  /* Fixed positioning for side rails on very wide screens */
  .books-list.rail-layout-outside.has-rail.rail-right .books-rail {
    position: fixed;
    right: var(--wp--preset--spacing--50, 1.5rem);
    top: var(--books-rail-top, 72px);
    float: none;
    margin: 0;
    height: calc(100vh - var(--books-rail-top, 72px) - 16px);
    z-index: 10;
  }

  .books-list.rail-layout-outside.has-rail.rail-left .books-rail {
    position: fixed;
    left: var(--wp--preset--spacing--50, 1.5rem);
    top: var(--books-rail-top, 72px);
    float: none;
    margin: 0;
    height: calc(100vh - var(--books-rail-top, 72px) - 16px);
    z-index: 10;
  }
}
