/* /shop/ by category (crew-board #816): one shelf per category. Loaded after site.css by
   /shop/ and /shop/<slug>/ only. The page reads the same with every effect off: each
   newer feature sits behind @supports, and motion behind prefers-reduced-motion.

   - Shelves: a heading, a count and a line of text, then the product cards (site.css
     `.tiles`). On a phone a shelf with two or more cards is a sideways rail with scroll
     snap; wider screens keep the grid.
   - The category bar stays under the top bar and jumps to a shelf. The shelf in view is
     marked by assets/js/shop-shelves.js (aria-current); with CSS anchor positioning the
     mark slides between names, otherwise it sits on the current one.
   - Rail extras, phone only: position dots from CSS scroll markers, and cards that
     brighten as they reach the middle (a scroll-driven animation on the inline axis).
   - Opening a product: a cross-document view transition between the two pages; the
     card's picture grows into the product page's picture. */

.shop-shelves { display: grid; gap: 2.8rem; }

/* ---- A house book on the Books shelf (crew-board #861) ----
   The whole portrait cover shows, standing on the card's dark panel, with the pen name
   and series under the title. */
.tiles .card.is-book .card-media.is-cover {
  height: 15rem;
  background: radial-gradient(120% 90% at 50% 0%, rgba(124, 92, 255, 0.22), rgba(10, 8, 22, 0.75) 70%);
}
#shop .tiles .card.is-book .card-media.is-cover img {
  inset: 0.9rem 0;
  height: calc(100% - 1.8rem);
  object-fit: contain;
  object-position: center;
  opacity: 1;
  /* The whole cover, so no parallax zoom on it (fx-parallax.css). */
  scale: 1;
  animation: none;
  filter: drop-shadow(0 14px 22px rgba(0, 0, 0, 0.55));
}
.tiles .card.is-book .card-media.is-cover::after { display: none; }
#shop .tiles .card .shop-byline {
  margin: 0.15rem 0 0.35rem;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  color: var(--muted);
}

/* ---- The category bar ---- */
.shelf-nav {
  position: sticky;
  top: calc(var(--header) + 0.55rem);
  z-index: 20;
  justify-self: start;
  max-width: 100%;
  padding: 0.3rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(6, 6, 12, 0.9);
  box-shadow: var(--shadow), inset 0 1px 0 var(--highlight);
  -webkit-backdrop-filter: blur(18px) saturate(1.35);
  backdrop-filter: blur(18px) saturate(1.35);
}
.shelf-nav ul {
  position: relative;
  display: flex;
  gap: 0.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  border-radius: 999px;
}
.shelf-nav ul::-webkit-scrollbar { display: none; }
.shelf-nav li { flex: none; }
.shelf-nav a {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  min-height: 2.5rem;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.93rem;
  font-weight: 600;
  line-height: 1.5;
  text-decoration: none;
  white-space: nowrap;
}
.shelf-nav a:hover { color: var(--white); background: var(--wash); }
.shelf-nav a:focus-visible { outline: 2px solid var(--accent2); outline-offset: -2px; }
.shelf-nav a[aria-current="true"] {
  color: var(--white);
  background: color-mix(in srgb, var(--section-accent) 22%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--section-accent) 70%, transparent);
}
.shelf-nav-count { color: var(--section-accent); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; }

/* With anchor positioning the mark is one pill that slides to the current name. */
@supports (anchor-name: --shelf-here) and (left: anchor(left)) {
  .shelf-nav a[aria-current="true"] { anchor-name: --shelf-here; background: none; box-shadow: none; }
  .shelf-nav ul:has(a[aria-current="true"])::before {
    content: "";
    position: absolute;
    position-anchor: --shelf-here;
    top: anchor(top);
    left: anchor(left);
    width: anchor-size(width);
    height: anchor-size(height);
    border-radius: 999px;
    background: color-mix(in srgb, var(--section-accent) 22%, transparent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--section-accent) 70%, transparent);
    pointer-events: none;
  }
  @media (prefers-reduced-motion: no-preference) {
    .shelf-nav ul::before { transition: left 0.35s cubic-bezier(.2, .7, .2, 1), width 0.35s cubic-bezier(.2, .7, .2, 1); }
  }
}

/* ---- A shelf ---- */
.shelf { min-width: 0; scroll-margin-top: calc(var(--header) + 4.4rem); }
.shelf-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 0.3rem 1rem;
  margin: 0 0 1.2rem;
}
.shelf-title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.9rem, 4.6vw, 2.7rem);
  line-height: 1.08;
  text-wrap: balance;
  color: var(--white);
}
.shelf-count {
  margin: 0;
  color: var(--section-accent);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  white-space: nowrap;
}
.shelf-blurb { grid-column: 1 / -1; margin: 0; max-width: 38rem; color: var(--muted); }
.shelf-head::after {
  content: "";
  grid-column: 1 / -1;
  height: 1px;
  margin-top: 0.55rem;
  background: linear-gradient(90deg, var(--section-accent), color-mix(in srgb, var(--section-accent) 20%, transparent) 55%, transparent);
  transform-origin: left center;
}
@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    .shelf-head::after {
      animation: shelf-rule linear both;
      animation-timeline: view();
      animation-range: entry 20% cover 38%;
    }
  }
}
@keyframes shelf-rule {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

/* ---- Phone: a shelf with two or more cards is a sideways rail ---- */
@media (max-width: 600px) {
  .shop-shelves { gap: 2.2rem; }
  .shelf-rail.is-rail {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: min(84%, 21rem);
    gap: 14px;
    /* Out to the screen's edges, so the next card peeks in from the side. */
    margin-inline: -1rem;
    padding: 0.5rem 1rem 1.1rem;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: 1rem;
    scrollbar-width: none;
  }
  .shelf-rail.is-rail::-webkit-scrollbar { display: none; }
  .shelf-rail.is-rail > .card { scroll-snap-align: center; }
  /* A rail is as tall as its longest card, so the description is cut to five lines here;
     the title opens the product's page, which has all of it. */
  .shelf-rail.is-rail > .card > p:not([class]) {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 5;
    line-clamp: 5;
    overflow: hidden;
  }

  /* Position dots from the browser's own scroll markers; without them the rail just swipes. */
  @supports (scroll-marker-group: after) {
    .shelf-rail.is-rail { scroll-marker-group: after; }
    .shelf-rail.is-rail::scroll-marker-group {
      display: flex;
      justify-content: center;
      align-items: center;
      gap: 0.4rem;
      min-height: 1.1rem;
    }
    .shelf-rail.is-rail > .card::scroll-marker {
      content: "";
      inline-size: 0.45rem;
      block-size: 0.45rem;
      border-radius: 999px;
      background: var(--border-strong);
    }
    .shelf-rail.is-rail > .card::scroll-marker:target-current {
      inline-size: 1.25rem;
      background: var(--section-accent);
    }
    .shelf-rail.is-rail > .card::scroll-marker:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }
  }
}
@media (max-width: 600px) and (prefers-reduced-motion: no-preference) {
  @supports (scroll-marker-group: after) {
    .shelf-rail.is-rail > .card::scroll-marker { transition: inline-size 0.25s ease, background-color 0.25s ease; }
  }
  /* A card is at full strength in the middle of the rail and eases back at the sides. */
  @supports (animation-timeline: view(inline)) {
    .shelf-rail.is-rail > .card {
      animation: shelf-focus linear both;
      animation-timeline: view(inline);
    }
  }
}
@keyframes shelf-focus {
  0%, 100% { opacity: 0.6; scale: 0.95; }
  30%, 70% { opacity: 1; scale: 1; }
}

/* ---- Opening a product: the two shop pages cross-fade and the picture travels ---- */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  .shop-product .writing-figure img { view-transition-name: shop-cover; }
  ::view-transition-group(shop-cover) { animation-duration: 0.42s; animation-timing-function: cubic-bezier(.2, .7, .2, 1); }
  ::view-transition-old(shop-cover),
  ::view-transition-new(shop-cover) { height: 100%; object-fit: cover; }
}

@media (prefers-contrast: more) {
  .shelf-nav { background: var(--bg); border-color: var(--white); }
  .shelf-nav a { color: var(--white); }
}
