/* Space between page hero header and book grid */
.library-page {
  margin-block-start: clamp(1.75rem, 4vw, 3rem);
}

.library {
  --library-gap: clamp(1.5rem, 3vw, 2.5rem);

  display: grid;
  gap: var(--library-gap);
  grid-template-columns: repeat(auto-fill, minmax(180px, 240px));
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-width: 0;
  justify-content: start;
}

/* Reading modal container - positioned outside normal flow */
turbo-frame#reading-modal-container {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
}

turbo-frame#reading-modal-container:not(:empty) {
  pointer-events: auto;
}

/* Card link: no stray hairline/outline from the anchor */
.library-card__link {
  display: block;
  text-decoration: none;
  color: inherit;
  border: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.library-card__link:focus-visible {
  outline: 2px solid var(--color-link, #2563eb);
  outline-offset: 4px;
  border-radius: 0.25rem;
}

/* Library Card - Just the Cover */
.library-card {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  display: block;
  max-width: 240px;
  width: 100%;
  /* Lifted cards must stack above the page hero / siblings so hover translate isn't clipped or covered */
  position: relative;
  z-index: 0;
}

.library-card:hover {
  z-index: 2;
}

.library-card__cover-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

.library-card:hover .library-card__cover-wrapper {
  transform: translateY(-8px);
}

/* "New book" tile: intentional frame (moves with the cover on hover) */
.library-card--new .library-card__cover-wrapper {
  border: 2px solid color-mix(in srgb, var(--color-border, rgba(15, 23, 42, 0.2)) 50%, transparent);
  border-radius: 0.375rem;
  box-sizing: border-box;
}

.library-card__cover {
  display: block;
  width: 100%;
  height: 100%;
  text-decoration: none;
  background: linear-gradient(135deg, 
    color-mix(in srgb, var(--color-selected) 30%, transparent) 0%, 
    color-mix(in srgb, var(--color-selected-dark) 30%, transparent) 100%);
}

.library-card__cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  /* Avoid subpixel “hairline” borders at overflow edges (cover hover uses wrapper lift only, not image scale) */
  backface-visibility: hidden;
  transform: translateZ(0);
}

.library-card__placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  text-align: center;
  color: var(--color-ink);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
}

.library-card__placeholder span {
  display: block;
}

.library-card__placeholder.theme--black,
.library-card__placeholder.theme--blue,
.library-card__placeholder.theme--green,
.library-card__placeholder.theme--magenta,
.library-card__placeholder.theme--orange,
.library-card__placeholder.theme--violet {
  background: url("/assets/covers/cover-blue-f33c5778.png") no-repeat center;
  background-size: cover;
  color: var(--color-always-white);
}

.library-card__placeholder.theme--black {
  background-image: url("/assets/covers/cover-black-443e3258.png");
}

.library-card__placeholder.theme--green {
  background-image: url("/assets/covers/cover-green-e645ae7b.png");
}

.library-card__placeholder.theme--magenta {
  background-image: url("/assets/covers/cover-magenta-dcc72425.png");
}

.library-card__placeholder.theme--orange {
  background-image: url("/assets/covers/cover-orange-e6f7b90d.png");
}

.library-card__placeholder.theme--violet {
  background-image: url("/assets/covers/cover-violet-7a1433e8.png");
}

.library-card__placeholder.theme--white {
  background: url("/assets/covers/cover-white-a033e48d.png") no-repeat center;
  background-size: cover;
  color: var(--color-ink);
}

/* Overlay with Actions */
.library-card__overlay {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--color-ink) 85%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 300ms cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.library-card:hover .library-card__overlay {
  opacity: 1;
  pointer-events: auto;
}

.library-card__actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 80%;
  max-width: 180px;
  align-items: center;
}

.library-card__action-btn {
  width: 100%;
  justify-content: center;
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
}

.library-card__cover--empty {
  position: relative;
  overflow: hidden;
  background: color-mix(in srgb, var(--color-panel, #fff) 80%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.library-card__cover-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.35;
  pointer-events: none;
  backface-visibility: hidden;
  transform: translateZ(0);
}

.library-card__new-cta {
  position: relative;
  z-index: 1;
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  padding: 0.5rem 0.75rem;
  text-align: center;
}

.library-card__new-label {
  font-size: clamp(0.85rem, 0.75rem + 0.4vw, 0.95rem);
  font-weight: 600;
  line-height: 1.25;
  color: var(--color-ink);
  max-width: 11ch;
}

.library-card__new-button {
  align-items: center;
  background: var(--color-positive, #2563eb);
  border-radius: 999px;
  display: inline-flex;
  flex-shrink: 0;
  inline-size: 3rem;
  block-size: 3rem;
  justify-content: center;
  box-shadow: 0 10px 25px rgb(37 99 235 / 0.35);
}

/* Responsive */
@media (max-width: 600px) {
  .library {
    grid-template-columns: repeat(auto-fill, minmax(140px, 180px));
    gap: 1.25rem;
  }

  .library-card {
    max-width: 180px;
  }
}

/* Reading completion (plan #6) — library, landing tiles, store inline */
.reading-progress-meter {
  box-sizing: border-box;
}

.reading-progress-meter__track {
  display: block;
  height: 3px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--color-ink, #0f172a) 22%, transparent);
  overflow: hidden;
}

.reading-progress-meter__fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--color-link, #2563eb);
  min-width: 2px;
  transition: width 0.35s ease;
}

.reading-progress-meter--strip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  padding: 0.45rem 0.45rem 0.35rem;
  background: linear-gradient(to top, rgba(15, 23, 42, 0.82) 0%, rgba(15, 23, 42, 0.35) 55%, transparent 100%);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  pointer-events: none;
}

.reading-progress-meter--strip .reading-progress-meter__label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  text-align: right;
  line-height: 1.2;
}

.reading-progress-meter--inline {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.reading-progress-meter--inline .reading-progress-meter__track {
  flex: 1;
  min-width: 0;
}

.reading-progress-meter--inline .reading-progress-meter__label {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 700;
  color: color-mix(in srgb, var(--color-ink, #0f172a) 65%, transparent);
  min-width: 2.25rem;
  text-align: right;
}
