:root {
  --max-width: 1200px;
  --color-text: #222;
  --color-bg: #fff;
  --color-accent: #e84a43;
  --color-border: #e2e2e2;
  --font-heading: "Bodoni Moda", Georgia, serif;
  --font-body: "Newsreader", Georgia, serif;
  --cover-ratio: 140 / 210;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-bg) url("../images/background_marbled_DoF.png") center center / cover no-repeat fixed;
  line-height: 1.5;
}

h1, h2, h3 {
  font-family: var(--font-heading);
  /* Bodoni Moda só carrega o peso 600 — sem isso, o navegador aplicaria
     um negrito sintético (h1-h3 são "bold" por padrão), o que distorce
     a fonte em vez de usar o alto contraste natural dela. */
  font-weight: 600;
  font-synthesis-weight: none;
}

.wrap {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem;
}

.site-header {
  background: transparent;
}

.site-header__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  padding-top: 1rem;
  padding-bottom: 1rem;
}

.site-header__nav a {
  color: #222;
  text-decoration: none;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.6);
}

.site-header__nav a:hover {
  color: var(--color-accent);
}

/* flex: 1 0 100% força o próximo item a ocupar sozinho a linha de baixo,
   com a largura exata da caixa de conteúdo (sem o padding lateral do
   header) — a mesma largura ocupada pelo grid de capas em main.wrap. */
.site-header__underline {
  flex: 1 0 100%;
  height: 0;
  margin-top: 1rem;
  border-bottom: 1px solid #3a3a3a;
}

.logo {
  height: 60px;
  width: auto;
  display: block;
}

main.wrap {
  padding-top: 1em;
  padding-bottom: 2em;
}

/* Grid de capas: 140x210mm (2:3), gap de 1em, responsivo */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  grid-auto-flow: dense;
  gap: 1em;
}

.book-cover {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: var(--cover-ratio);
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transition: box-shadow 0.15s ease;
  animation: cover-grow-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) backwards;
  animation-delay: calc(var(--stagger, 0) * 70ms);
}

/* Quando há transição "marbled" (canvas), a <img> original fica só como
   fallback enquanto o canvas carrega, e some assim que ele existe. */
.book-cover:has(.cover-marble-canvas) img {
  visibility: hidden;
}

.cover-marble-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.book-cover:hover,
.book-cover:focus-visible {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

/* Livro mais recente: destaque ocupando 2 colunas (e 2 linhas, pra manter a proporção 140:210) */
.book-cover--featured {
  grid-column: span 2;
  grid-row: span 2;
}

@media (max-width: 480px) {
  .book-cover--featured {
    grid-column: span 1;
    grid-row: span 1;
  }
}

@keyframes cover-grow-in {
  from {
    opacity: 0;
    transform: scale(0.05);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

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

/* Modal (quadro) */
.book-modal {
  border: none;
  border-radius: 8px;
  padding: 0;
  width: min(900px, 92vw);
  max-height: 88vh;
  background: hsl(0, 0%, 80%); /* fallback até o JS calcular a cor média da capa */
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.book-modal::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.modal-content {
  display: grid;
  grid-template-columns: minmax(0, 320px) 1fr;
  gap: 2em;
  padding: 2em;
  max-height: 88vh;
  overflow-y: auto;
}

.modal-image {
  width: 100%;
  aspect-ratio: var(--cover-ratio);
  object-fit: cover;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.modal-text h2 {
  margin-top: 0;
  margin-bottom: 0.25rem;
}

.modal-text h3 {
  font-size: 1.05rem;
  margin: 1.5rem 0 0.5rem;
}

.modal-text .book-subtitle {
  font-style: italic;
  color: #555;
}

#modal-body img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1rem auto;
  border-radius: 4px;
}

.modal-text .book-author {
  font-style: italic;
  color: #666;
  margin-top: 0;
}

.modal-text blockquote {
  margin: 1.5rem 0;
  padding-left: 1rem;
  border-left: 3px solid var(--color-accent);
  font-style: italic;
  color: #555;
}

.buy-button {
  display: inline-block;
  margin-top: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--buy-button-color, hsl(0, 0%, 28%));
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  border-radius: 4px;
  transition: filter 0.15s ease;
}

.buy-button:hover {
  filter: brightness(1.1);
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.08);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  background: rgba(0, 0, 0, 0.15);
}

.site-footer {
  border-top: 1px solid var(--color-border);
  margin-top: 3rem;
  padding: 1.5rem 0;
  text-align: center;
}

.copyright {
  color: #777;
  font-size: 0.9rem;
  margin: 0;
}

/* Responsivo: empilha a imagem sobre o texto no modal em telas menores */
@media (max-width: 640px) {
  .modal-content {
    grid-template-columns: 1fr;
    padding: 1.5em;
  }

  .modal-image {
    max-width: 200px;
    margin: 0 auto;
  }
}
