/* Library Page Styles */

.library-hero-text {
  max-width: min(21rem, 100% - 2.5rem);
  text-align: center;
  gap: 1rem;
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  margin-top: 3rem;
}

.library-hero-text h1 {
  font: var(--title-lg);
  color: var(--text-title);
  font-size: 1.75rem;
  animation: fadeIn 4s;
}

.library-hero-text p {
  font: var(--body-lg);
  color: var(--text-body);
  font-size: 0.875rem;
  animation: fadeIn 10s;
  margin-top: 1rem;
}

@media (width >=64em) {
  .library-hero-text {
    max-width: 39.06rem;
    gap: 2rem;
    margin-top: 4rem;
  }

  .library-hero-text h1 {
    font: var(--title-lg);
    color: var(--text-title);
  }

  .library-hero-text p {
    font: var(--body-lg);
    color: var(--text-body);
    margin-top: 2rem;
  }
}

/* Search Container (busca ao vivo: filtra enquanto digita, sem botão de enviar) */
.search-container {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 640px;
  margin: 2rem auto 0;
  background: var(--shape-base);
  border-radius: 999px;
  border: 1px solid var(--shape-stroke);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-container:focus-within {
  border-color: var(--pink-base);
  box-shadow: 0 0 0 4px rgb(149 71 165 / 0.2);
}

.search-icon {
  position: absolute;
  left: 1.5rem;
  width: 1.25rem;
  height: 1.25rem;
  color: var(--text-label);
  pointer-events: none;
  transition: color 0.2s ease;
}

.search-container:focus-within .search-icon {
  color: var(--pink-light);
}

#search-input {
  flex: 1;
  min-width: 0;
  width: 100%;
  background: transparent;
  border: none;
  padding: 1.125rem 3.5rem 1.125rem 3.5rem;
  color: var(--text-title);
  font: var(--body-md);
  outline: none;
}

#search-input::placeholder {
  color: var(--text-label);
}

/* Esconde o "x" nativo do navegador; usamos o nosso */
#search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

#search-clear {
  position: absolute;
  right: 0.75rem;
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-label);
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

#search-clear svg {
  width: 1.125rem;
  height: 1.125rem;
}

#search-clear:hover {
  background: var(--shape-hover);
  color: var(--text-title);
}

#search-input:placeholder-shown~#search-clear {
  display: none;
}

/* Filters Section */
.filters-section {
  background: var(--shape-background);
  padding: 2rem 0;
  border-bottom: 1px solid var(--shape-stroke);
}

.filters {
  display: flex;
  align-items: center;
  gap: 2rem;
  flex-wrap: wrap;
  justify-content: center;
}

.filters .filters-title {
  font: var(--title-xs);
  color: var(--text-title);
  margin: 0;
}

.filter-buttons {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

.filter-btn {
  background: var(--shape-base);
  border: 1px solid var(--shape-stroke);
  color: var(--text-body);
  padding: 0.75rem 1.5rem;
  border-radius: 25px;
  cursor: pointer;
  font: var(--body-sm);
  transition: all 0.3s ease;
}

.filter-btn:hover,
.filter-btn.active {
  background-color: var(--pink-dark);
  color: var(--text-title);
  border-color: transparent;
  transform: translateY(-2px);
}

.filter-btn:hover::before {
  background-color: var(--pink-base);
}

/* Books Grid */
.books-grid {
  background: var(--shape-background);
  padding: 4rem 0;
}

.grid-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3rem;
}

.grid-header h2 {
  font: var(--title-md);
  color: var(--text-title);
}

.view-toggle {
  display: flex;
  gap: 0.5rem;
}

.view-btn {
  background: var(--shape-base);
  border: 1px solid var(--shape-stroke);
  color: var(--text-body);
  padding: 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.2rem;
  transition: all 0.3s ease;
}

.view-btn:hover,
.view-btn.active {
  background-color: var(--blue-dark);
  color: var(--text-title);
  border-color: var(--blue-dark);
}

.view-btn:hover::before {
  background-color: var(--blue-mid);
}

/* Books Container */
.books-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 2rem;
  margin-bottom: 3rem;
}

.books-container.list-view {
  grid-template-columns: 1fr;
  gap: 1rem;
}

.book-card {
  background: var(--shape-base);
  border-radius: 1rem;
  overflow: hidden;
  transition: all 0.3s ease;
  border: 2px solid var(--shape-stroke);
  cursor: pointer;
}

.book-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
  border-color: var(--pink-base);
}

.book-cover {
  width: 100%;
  height: 300px;
  background: linear-gradient(135deg, var(--blue-mid), var(--pink-base));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
  position: relative;
  overflow: hidden;
}

.book-cover::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.1) 50%, transparent 70%);
  transform: translateX(-100%);
  transition: transform 0.6s ease;
}

.book-card:hover .book-cover::before {
  transform: translateX(100%);
}

.book-info {
  padding: 1.5rem;
}

.book-title {
  font: var(--title-xs);
  color: var(--text-title);
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

.book-author {
  font: var(--body-sm);
  color: var(--text-label);
  margin-bottom: 1rem;
}

.book-category {
  display: inline-block;
  background-color: var(--pink-dark);
  color: var(--text-title);
  padding: 0.25rem 0.75rem;
  border-radius: 12px;
  font: var(--tag);
  margin-bottom: 1rem;
}

.book-description {
  font: var(--body-sm);
  color: var(--text-body);
  line-height: 1.5;
  margin-bottom: 1rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-rating {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.stars {
  color: #ffd700;
}

.rating-text {
  font: var(--body-xs);
  color: var(--text-label);
}

.book-actions {
  display: flex;
  gap: 1rem;
}

.btn-read {
  flex: 1;
  background-color: var(--blue-dark);
  color: var(--text-title);
  border: none;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font: var(--button);
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
  z-index: 1;
}

.btn-read::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  padding-top: 100%;
  border-radius: 50%;
  background-color: var(--blue-mid);
  transform: translate(-50%, -50%) scale(0);
  transition: transform .7s ease-out;
  z-index: -1;
}

.btn-read:hover::before {
  transform: translate(-50%, -50%) scale(3);
}

.btn-read:not(:hover)::before {
  transform: translate(-50%, -50%) scale(0);
}

.btn-favorite {
  background: var(--shape-hover);
  border: 1px solid var(--shape-stroke);
  color: var(--text-body);
  padding: 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 1.2rem;
}

.btn-favorite:hover,
.btn-favorite.favorited {
  background-color: var(--pink-dark);
  color: var(--text-title);
  border-color: var(--pink-dark);
}

.btn-favorite:hover::before {
  background-color: var(--pink-base);
}

/* List View Styles */
.books-container.list-view .book-card {
  display: flex;
  align-items: center;
  padding: 1rem;
}

.books-container.list-view .book-cover {
  width: 120px;
  height: 160px;
  flex-shrink: 0;
  margin-right: 2rem;
  font-size: 2rem;
}

.books-container.list-view .book-info {
  flex: 1;
  padding: 0;
}

.books-container.list-view .book-actions {
  margin-left: 2rem;
  flex-direction: column;
  min-width: 150px;
}

/* Lista no celular: capa à esquerda, textos à direita e botões ocupando a largura toda embaixo.
   display: contents deixa os filhos de .book-info participarem direto do grid do card. */
@media (width < 48em) {
  .books-container.list-view .book-card {
    display: grid;
    grid-template-columns: 84px 1fr;
    column-gap: 1rem;
    align-items: start;
  }

  .books-container.list-view .book-cover {
    grid-column: 1;
    grid-row: 1 / span 5;
    width: 84px;
    height: 120px;
    margin-right: 0;
  }

  .books-container.list-view .book-info {
    display: contents;
  }

  .books-container.list-view .book-info > * {
    grid-column: 2;
    min-width: 0;
  }

  .books-container.list-view .book-category {
    justify-self: start;
  }

  .books-container.list-view .book-description {
    -webkit-line-clamp: 2;
  }

  .books-container.list-view .book-actions {
    grid-column: 1 / -1;
    flex-direction: row;
    min-width: 0;
    margin: 0.5rem 0 0;
  }
}

/* Load More */
.load-more {
  text-align: center;
}

#load-more-btn {
  background-color: var(--blue-dark);
  color: var(--text-title);
  padding: 1rem 2rem;
  border-radius: 12px;
  font: var(--button);
  cursor: pointer;
  transition: all 0.3s ease;
  border: none;
  position: relative;
  overflow: hidden;
  z-index: 1;
}

#load-more-btn::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  padding-top: 100%;
  border-radius: 50%;
  background-color: var(--blue-mid);
  transform: translate(-50%, -50%) scale(0);
  transition: transform .7s ease-out;
  z-index: -1;
}

#load-more-btn:hover::before {
  transform: translate(-50%, -50%) scale(3);
}

#load-more-btn:not(:hover)::before {
  transform: translate(-50%, -50%) scale(0);
}

/* Reading Stats */
.reading-stats {
  background: var(--shape-background);
  padding: 4rem 0;
  border-top: 1px solid var(--shape-stroke);
}

.reading-stats h2 {
  font: var(--title-md);
  color: var(--text-title);
  text-align: center;
  margin-bottom: 3rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 2rem;
}

.stat-card {
  background: var(--shape-base);
  border: 2px solid var(--shape-stroke);
  border-radius: 1rem;
  padding: 2rem;
  text-align: center;
  transition: all 0.3s ease;
}

.stat-card:hover {
  transform: translateY(-5px);
  border-color: var(--pink-base);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.stat-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.stat-icon img {
  width: 3rem;
  height: 3rem;
  vertical-align: middle;
}

.stat-number {
  font: var(--title-md);
  color: var(--text-title);
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--pink-light), var(--blue-light));
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.stat-label {
  font: var(--body-md);
  color: var(--text-label);
}

/* Em css/library.css */

.book-cover {
  /* Propriedades do background */
  background-size: cover;
  /* Faz a imagem cobrir toda a área, cortando se necessário */
  background-position: center;
  /* Centraliza a imagem */
  background-repeat: no-repeat;
  /* Impede que a imagem se repita */

  /* Estilos que você provavelmente já tem ou pode ajustar */
  width: 100%;
  height: 500px;
  /* Defina uma altura fixa ou use aspect-ratio */
  border-radius: 12px 12px 0 0;
  /* Arredonda os cantos superiores */
  transition: transform 0.3s ease;

  /* Para o caso de alguns livros ainda usarem emojis */
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
  /* Tamanho do emoji, se a imagem não carregar */
  color: var(--text-title);
  background-color: var(--shape-hover);
  /* Cor de fundo caso a imagem falhe */
}

.book-card:hover .book-cover {
  transform: scale(1.05);
  /* Efeito de zoom na capa ao passar o mouse */
}

/* Capas (imagem da Open Library ou capa gerada) */
.book-cover img,
.book-modal-cover img {
  font: var(--body-xs);
  color: transparent;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cover-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1.25rem;
  text-align: left;
}

.cover-fallback-title {
  font: var(--title-xs);
  font-size: 1.125rem;
  line-height: 1.25;
  color: var(--text-title);
}

.cover-fallback-author {
  font: var(--body-xs);
  color: rgb(255 255 255 / 0.75);
}

.books-container.list-view .cover-fallback {
  padding: 0.75rem;
}

.books-container.list-view .cover-fallback-title {
  font-size: 0.8125rem;
}

/* Título do card como botão (abre detalhes) */
.book-title-btn {
  all: unset;
  cursor: pointer;
}

.book-title-btn:focus-visible {
  outline: 2px solid var(--pink-light);
  outline-offset: 3px;
  border-radius: 2px;
}

a.btn-read {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
}

.books-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem;
  color: var(--text-body);

  & h3 {
    font: var(--title-xs);
    color: var(--text-title);
    margin-bottom: 0.5rem;
  }

  & p {
    font: var(--body-sm);
    color: var(--text-label);
  }
}

/* Modal de detalhes do livro */
.book-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: rgb(0 5 10 / 0.8);
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.25s ease;

  &.open {
    opacity: 1;

    & .book-modal-content {
      transform: scale(1);
    }
  }
}

.book-modal-content {
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 2rem 1.5rem;
  text-align: center;
  background: var(--shape-base);
  border: 1px solid var(--shape-stroke);
  border-radius: 1.25rem;
  box-shadow: 0 30px 60px rgb(0 0 0 / 0.5);
  transform: scale(0.94);
  transition: transform 0.25s ease;

  & h2 {
    font: var(--title-sm);
    font-size: 1.5rem;
    color: var(--text-title);
    margin-bottom: 0.25rem;
  }
}

.book-modal-cover {
  width: 140px;
  height: 210px;
  margin: 0 auto 1.5rem;
  border-radius: 0.5rem;
  overflow: hidden;
  box-shadow: 0 16px 32px rgb(0 0 0 / 0.5);
  background: var(--shape-stroke);
}

.book-modal-author {
  font: var(--body-sm);
  color: var(--text-label);
  margin-bottom: 1rem;
}

.book-modal-rating {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  font: var(--body-sm);
  color: var(--text-body);
}

.book-modal-description {
  font: var(--body-md);
  color: var(--text-body);
  line-height: 1.6;
  margin: 1rem 0 1.75rem;
}

.book-modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;

  & > * {
    font: var(--button);
    padding: 0.875rem 1.25rem;
    border-radius: 0.5rem;
    cursor: pointer;
    text-decoration: none;
    transition: filter 0.2s ease, background-color 0.2s ease;
  }

  & .btn-primary {
    color: var(--text-title);
    background: linear-gradient(90deg, var(--pink-base), var(--pink-dark));
    border: none;
  }

  & .btn-secondary {
    color: var(--text-title);
    background: transparent;
    border: 1px solid var(--blue-base);
  }

  & .btn-ghost {
    color: var(--text-label);
    background: transparent;
    border: 1px solid var(--shape-stroke);
  }

  & > *:hover {
    filter: brightness(1.15);
  }
}

/* Aviso rápido (favoritos) */
.library-toast {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 1001;
  padding: 0.875rem 1.25rem;
  border-radius: 0.75rem;
  background: linear-gradient(135deg, var(--pink-base), var(--blue-base));
  font: var(--body-md);
  color: var(--text-title);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.3);
  transform: translateX(calc(100% + 2rem));
  transition: transform 0.3s ease;

  &.show {
    transform: translateX(0);
  }
}
