/* ==========================================================================
   Book grid, cards and skeletons — Grimmory parity
   ========================================================================== */

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-width, 150px), 1fr));
  gap: var(--grid-gap, 16px);
  align-items: start;
}

.book-grid--compact {
  --card-width: 128px;
  --grid-gap: 12px;
}

/* ---- Card --------------------------------------------------------------- */
.book-card {
  --card-radius: var(--cover-radius);
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  outline: none;
}

.book-card-cover-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 7;
  border-radius: var(--card-radius);
  overflow: hidden;
  background: var(--color-surface-200);
  box-shadow: var(--shadow-card);
  transition: transform var(--duration-micro) var(--ease-glide),
    box-shadow var(--duration-micro) var(--ease-glide);
}

.book-card--square .book-card-cover-wrap {
  aspect-ratio: 1 / 1;
}

.book-card:hover .book-card-cover-wrap,
.book-card:focus-within .book-card-cover-wrap {
  box-shadow: var(--shadow-card-hover);
}

.book-card.is-selected .book-card-cover-wrap {
  transform: scale(0.93);
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.book-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Deterministic gradient fallback when no cover exists / fails to load. */
.book-cover--fallback {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-3);
  width: 100%;
  height: 100%;
  color: rgb(255 255 255 / 92%);
  background-image: linear-gradient(150deg, var(--grad-start, #78716c), var(--grad-end, #292524));
}

.book-cover--fallback .fallback-title {
  font-family: var(--font-cover-serif);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-shadow: 0 1px 3px rgb(0 0 0 / 35%);
}

.book-cover--fallback .fallback-author {
  font-size: var(--app-text-xs);
  font-weight: 500;
  color: rgb(255 255 255 / 72%);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Cover overlays sit above the image */
.book-cover-badges {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.book-format-pill {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 3;
  padding: 1px 5px;
  border-radius: var(--radius-sm);
  background: rgb(0 0 0 / 55%);
  color: rgb(255 255 255 / 95%);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  backdrop-filter: blur(2px);
}

.book-series-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
  max-width: 60%;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  background: rgb(0 0 0 / 55%);
  color: rgb(255 255 255 / 95%);
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  backdrop-filter: blur(2px);
}

/* Reading progress bar pinned to the cover bottom */
.book-progress {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  z-index: 4;
  height: 4px;
  background: rgb(0 0 0 / 45%);
}

.book-progress > i {
  display: block;
  height: 100%;
  background: var(--color-primary);
  border-radius: 0 2px 2px 0;
}

/* Hover overlay with Read + ellipsis */
.book-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  background: linear-gradient(to top, rgb(0 0 0 / 55%) 0%, rgb(0 0 0 / 0%) 55%);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--duration-micro) var(--ease-glide),
    transform var(--duration-micro) var(--ease-glide);
  pointer-events: none;
}

.book-card:hover .book-overlay,
.book-card:focus-within .book-overlay {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.book-overlay-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 28px;
  padding: 0 10px;
  border-radius: var(--radius-md);
  background: rgb(0 0 0 / 72%);
  color: rgb(255 255 255 / 92%);
  font-size: var(--app-text-xs);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 18%);
  backdrop-filter: blur(3px);
  transition: background var(--duration-micro);
}

.book-overlay-action svg {
  width: 14px;
  height: 14px;
}

.book-overlay-action:hover {
  background: rgb(0 0 0 / 88%);
  color: #fff;
}

.book-overlay-action--read {
  flex: 1 1 auto;
}

.book-overlay-menu {
  width: 28px;
  padding: 0;
  flex-shrink: 0;
}

/* Selection checkbox */
.book-select-check {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 6;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgb(0 0 0 / 45%);
  border: 2px solid rgb(255 255 255 / 85%);
  color: transparent;
  transition: background var(--duration-micro), color var(--duration-micro);
}

.book-select-check.is-checked {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

.book-select-check svg {
  width: 12px;
  height: 12px;
}

/* Meta */
.book-meta {
  padding-top: 8px;
  min-width: 0;
}

.book-title {
  font-size: 13px;
  line-height: 17px;
  font-weight: 550;
  color: var(--color-text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-author {
  margin-top: 1px;
  font-size: 12px;
  line-height: 15px;
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-detail-line {
  font-size: 12px;
  line-height: 15px;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Stretched link covers the card so click opens detail */
.book-card-link {
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: var(--card-radius);
  cursor: pointer;
}

.book-card.is-selecting .book-card-link {
  cursor: pointer;
}

/* ---- Context menu ------------------------------------------------------- */
.card-menu {
  position: fixed;
  z-index: 200;
  min-width: 190px;
  padding: 5px;
  border-radius: var(--radius-md);
  background: var(--color-card);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-pop);
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: 7px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--app-text-sm);
  color: var(--color-text);
  text-align: left;
}

.menu-item svg {
  width: 15px;
  height: 15px;
  color: var(--color-text-muted);
}

.menu-item:hover {
  background: var(--color-surface-hover);
}

.menu-item:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.menu-item:disabled:hover {
  background: transparent;
}

.menu-item--danger {
  color: var(--color-danger);
}

.menu-item--danger svg {
  color: var(--color-danger);
}

.menu-item--danger:hover {
  background: color-mix(in srgb, var(--color-danger) 10%, transparent);
}

.menu-divider {
  height: 1px;
  margin: 4px 0;
  background: var(--color-border);
}

/* ---- Skeleton ----------------------------------------------------------- */
.skeleton-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.skeleton-cover {
  width: 100%;
  aspect-ratio: 5 / 7;
  border-radius: var(--cover-radius);
  background-image: linear-gradient(
    90deg,
    var(--color-skeleton-base) 0%,
    var(--color-skeleton-highlight) 50%,
    var(--color-skeleton-base) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 2s linear infinite;
}

.skeleton-line {
  height: 10px;
  margin-top: 8px;
  border-radius: 4px;
  background-image: linear-gradient(
    90deg,
    var(--color-skeleton-base) 0%,
    var(--color-skeleton-highlight) 50%,
    var(--color-skeleton-base) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 2s linear infinite;
}

.skeleton-line--short {
  width: 60%;
  margin-top: 6px;
  height: 9px;
}

@keyframes skeleton-shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

/* Row skeletons for table mode */
.skeleton-row {
  height: 56px;
  border-radius: var(--radius-sm);
  background-image: linear-gradient(
    90deg,
    var(--color-skeleton-base) 0%,
    var(--color-skeleton-highlight) 50%,
    var(--color-skeleton-base) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 2s linear infinite;
}
