/* ═══════════════════════════════════════════════════════════════════════
   DEVMARK LIBRARY — book cards, covers, grid
   ═══════════════════════════════════════════════════════════════════════

   The shelf is the signature; the grid is the workhorse. Research on
   catalogue interfaces is consistent that a cover-led grid beats a list when
   the thumbnail is doing real decision-making work, which for books it is.
   So: shelf to browse a shelf, grid to browse the library.

   COVER STRATEGY — three tiers, one shape
   The card never changes size or layout depending on which tier fires, so a
   missing cover produces a different-looking book, not a broken row.

     1  Open Library cover, referenced by src. Not downloaded, not
        re-hosted — that is the use the Covers API documents as permitted,
        and CoverID lookups are its un-throttled path. `?default=false`
        makes a missing cover 404 rather than return a blank placeholder
        image, which is what lets tier 3 take over.
     2  A locally hosted asset, if one is ever cleared for use. Same slot.
     3  A Devmark cover: drawn in CSS from the book's own metadata. No
        request, no licence question, and it looks deliberate rather than
        apologetic.
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Grid ────────────────────────────────────────────────────────────────
   auto-fill rather than auto-fit: with auto-fit a final row holding two
   books stretches them to full width, which looks like a bug. */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: clamp(20px, 2.4vw, 38px) clamp(14px, 1.6vw, 26px);
}
.grid--tight { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 24px 14px; }
}

/* ── Card ────────────────────────────────────────────────────────────── */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  min-width: 0;
}

.card__a {
  display: flex; flex-direction: column; gap: var(--s-3);
  min-width: 0;
  border-radius: var(--r-2);
}
/* The whole card is one link, so the hit target is the card, not the title. */
.card__a::after { content: ""; position: absolute; inset: 0; border-radius: var(--r-3); }

.card__cover {
  display: block;
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: var(--r-2);
  background: var(--ink-800);
  /* A book is lit from above-left and sits on the page. */
  box-shadow: var(--lift-2);
  transform-origin: 50% 88%;
  transition:
    transform var(--d-content) var(--e-spring-soft),
    box-shadow var(--d-content) var(--e-out);
  will-change: transform;
  overflow: hidden;
  isolation: isolate;
}

/* The board edge — a hairline of spine down the left, so a flat rectangle
   reads as an object with thickness. */
.card__cover::before {
  content: "";
  position: absolute; inset: 0 auto 0 0;
  width: 6px; z-index: 3;
  background: linear-gradient(90deg,
    rgba(0,0,0,.44) 0%, rgba(0,0,0,.20) 45%, rgba(255,255,255,.07) 100%);
  pointer-events: none;
}
/* Sheen. Sits still at rest and sweeps once on hover. */
.card__cover::after {
  content: "";
  position: absolute; inset: 0; z-index: 4;
  background: linear-gradient(104deg,
    transparent 38%, rgba(255,255,255,.11) 49%, transparent 60%);
  transform: translateX(-120%);
  transition: transform var(--d-signature) var(--e-out);
  pointer-events: none;
}

.card__img {
  /* Must be positioned: the generated fallback sits at z-index 1, and a
     static image cannot paint above it however high its z-index is set. */
  position: absolute; inset: 0; z-index: 2;
  width: 100%; height: 100%;
  object-fit: cover;
  /* Covers arrive at wildly different aspect ratios; cropping to the card's
     ratio keeps the grid even. The image is decorative here — the title is
     adjacent in text — so alt is empty by design (see build.py). */
  transition: opacity var(--d-content) var(--e-out), transform var(--d-content) var(--e-out);
}
/* Visible by default. Nothing has to run for a cover to be seen: the image
   paints over the generated cover beneath it as soon as it decodes, so there
   is no flash and no dependency on a script having initialised this subtree.
   The only thing that hides a cover is a real load error. */
.card__img { opacity: 1; }
.card__img[data-cover-failed] { display: none; }

/* ── Tier 3: the Devmark cover ───────────────────────────────────────────
   Drawn from the record itself. Present in the DOM underneath the image,
   so if the image 404s or is still loading there is never an empty box. */
.card__fallback {
  position: absolute; inset: 0; z-index: 1;
  display: flex; flex-direction: column;
  padding: 14px 13px 12px;
  background:
    linear-gradient(160deg, rgba(255,255,255,.09), transparent 52%),
    oklch(var(--lt, 28%) var(--spine-c) var(--hue, 30));
  color: rgba(255,255,255,.95);
}
.card__fallback-title {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(0.82rem, 1.5vw, 1rem); line-height: 1.16;
  letter-spacing: -0.012em;
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card__fallback-author {
  margin-top: auto;
  font-size: var(--t-micro); letter-spacing: 0.08em; text-transform: uppercase;
  color: rgba(255,255,255,.62);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card__fallback-rule {
  width: 22px; height: 2px; background: var(--signal);
  margin-bottom: 9px; margin-top: 10px;
}

/* ── Card text ───────────────────────────────────────────────────────── */
.card__title {
  font-family: var(--font-display);
  font-weight: 700; font-size: 0.97rem; line-height: 1.24;
  letter-spacing: -0.01em;
  color: var(--paper);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
  /* The underline grows from the left on hover, drawn as a background so it
     cannot shift the text baseline. */
  background-image: linear-gradient(var(--paper), var(--paper));
  background-size: 0% 1px; background-repeat: no-repeat; background-position: 0 100%;
  transition: background-size var(--d-ui) var(--e-out);
}
.card__author {
  font-size: var(--t-small); color: var(--paper-3);
  display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden;
}
.card__meta {
  display: flex; align-items: center; gap: 8px;
  font-size: var(--t-micro); letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--paper-4);
}
.card__meta span { white-space: nowrap; }
.card__meta i { font-style: normal; opacity: .5; }

/* ── Card states ─────────────────────────────────────────────────────────
   Hover and focus-within are identical, so keyboard users get the same
   affordance. Only transform and shadow animate — no layout property does,
   so a 300-card grid never reflows on hover. */
@media (hover: hover) and (pointer: fine) {
  .card:hover .card__cover,
  .card:focus-within .card__cover {
    transform: translateY(-8px) scale(1.022) rotate(-0.4deg);
    box-shadow: var(--lift-3);
  }
  .card:hover .card__cover::after { transform: translateX(120%); }
  .card:hover .card__title { background-size: 100% 1px; }
}
.card:focus-within .card__cover { transform: translateY(-8px) scale(1.022); box-shadow: var(--lift-3); }
.card__a:focus-visible { outline: none; }
.card__a:focus-visible ~ .card__cover,
.card:focus-within .card__cover { outline: 2px solid var(--accent); outline-offset: 3px; }

@media (hover: none) {
  .card__a:active + .card__cover, .card:active .card__cover { transform: scale(0.978); }
}

/* ── Wide card: used in collections and related books ──────────────────── */
.wcard {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: var(--s-4);
  align-items: start;
  padding: var(--s-4);
  border: 1px solid var(--hair);
  border-radius: var(--r-3);
  /* The LIGHTEST surface, on a page that is a step darker. A card that is
     darker than its page reads as a hole cut in the page; a card that is
     lighter reads as a card resting on it. */
  background: var(--surface);
  box-shadow: var(--lift-1);
  position: relative;
  transition: background var(--d-fast) var(--e-out),
              border-color var(--d-fast) var(--e-out),
              box-shadow var(--d-ui) var(--e-out),
              transform var(--d-ui) var(--e-spring-snap);
}
.wcard:hover {
  background: var(--surface);
  border-color: var(--accent-line);
  box-shadow: var(--lift-2);
  transform: translateY(-3px);
}
.wcard__cover {
  display: block;
  aspect-ratio: 2/3; border-radius: var(--r-1); overflow: hidden;
  position: relative; box-shadow: var(--lift-2); background: var(--raised);
}
.wcard__title {
  font-family: var(--font-display); font-weight: 700;
  font-size: 0.98rem; line-height: 1.24; color: var(--paper);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.wcard__title::after { content: ""; position: absolute; inset: 0; }
.wcard__author { font-size: var(--t-small); color: var(--paper-3); margin-top: 3px; }
.wcard__why {
  margin-top: var(--s-2); font-size: var(--t-small);
  color: var(--paper-3); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* ── Rail card sizing ────────────────────────────────────────────────── */
.rail .card { width: 168px; }
.rail .wcard { width: 330px; }
@media (max-width: 560px) {
  .rail .card { width: 138px; }
  .rail .wcard { width: 280px; }
}

/* ── Verified marker ─────────────────────────────────────────────────────
   Devmark's mark, reused as a data-quality signal: it appears only where
   two independent sources agreed. It is not decoration and it is not shown
   where the record carries unresolved flags. */
.verified {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--t-micro); letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--paper-3);
}
.verified svg { width: 11px; height: 11px; color: var(--accent); flex: none; }

/* ── Empty & loading states ──────────────────────────────────────────── */
.empty {
  padding: clamp(40px, 7vw, 88px) var(--s-5);
  text-align: center;
  border: 1px dashed var(--hair-2);
  border-radius: var(--r-4);
}
.empty__title {
  font-family: var(--font-display); font-size: var(--t-h2); color: var(--paper);
  margin-bottom: var(--s-3);
}
.empty__body { color: var(--paper-3); max-width: 46ch; margin: 0 auto var(--s-5); }

/* Skeletons match the real card's box exactly, so nothing shifts when the
   content arrives. */
.skel {
  background: linear-gradient(100deg, var(--ink-800) 28%, var(--ink-700) 48%, var(--ink-800) 68%);
  background-size: 220% 100%;
  animation: skel 1.4s var(--e-in-out) infinite;
  border-radius: var(--r-2);
}
@keyframes skel { to { background-position: -120% 0; } }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } }

/* The reason a related book is related. Sits above the title, in the label
   treatment used for kickers elsewhere, so it reads as an annotation rather
   than as a badge. */
.card__why {
  display: block;
  margin-top: var(--s-3);
  font-size: var(--t-micro); letter-spacing: var(--ls-label);
  text-transform: uppercase; color: var(--accent);
  font-weight: 700;
}
.card__why + .card__title { margin-top: 4px; }
