/*
 *  Estilos Modernos y Responsivos para La Biblioteca
 */

@property --border-angle {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}

:root {
  --primary-color: #2c3e50;
  --secondary-color: #34495e;
  --accent-color: #e67e22;
  /* Un naranja elegante para destacar */
  --accent-hover: #d35400;
  --text-main: #2c3e50;
  --text-light: #7f8c8d;
  --bg-body: #f4f6f8;
  --bg-card: #ffffff;
  --border-color: #e1e4e8;
  --shadow-sm: 0 4px 6px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 10px 20px rgba(0, 0, 0, 0.08);
  --font-heading: 'Playfair Display', serif;
  --font-body: 'Inter', sans-serif;

  /* VARIABLES IMPORTADAS DEL LIBRO ANIMADO */
  --book-bg-color: #0f172a;
  --book-text-color: #cbd5e1;
  --book-accent-color: #044494;
  /* Color botón DESCAGAR */
  --book-accent-hover: #033675;
  /* Más oscuro para hover */
  --book-accent-light: #b3c5df;
  /* Color botón INFORMACIÓN */
  --book-glass-bg: rgba(255, 255, 255, 0.05);
  --book-glass-border: rgba(255, 255, 255, 0.1);
  --book-gold: #fbbf24;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.6;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-heading);
  margin-top: 0;
  color: var(--primary-color);
}

a {
  text-decoration: none;
  color: inherit;
  transition: all 0.3s ease;
}

ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

/* Layout */
.main-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.row {
  width: 100%;
  max-width: 1400px;
  /* Ancho máximo generoso */
  margin: 0 auto;
  padding: 0 30px;
}

/* Header */
.page-header {
  background: white;
  padding: 20px 0;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

.page-header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 15px;
}

.logo {
  font-family: var(--font-heading);
  font-size: 26px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo span {
  color: var(--accent-color);
}

/* Search */
.catalog-search {
  position: relative;
  width: 100%;
  max-width: 350px;
}

.search-input {
  width: 100%;
  padding: 12px 20px 12px 45px;
  border: 1px solid var(--border-color);
  border-radius: 50px;
  font-family: var(--font-body);
  font-size: 15px;
  transition: all 0.3s ease;
  background: #f9f9f9;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent-color);
  background: white;
  box-shadow: 0 0 0 3px rgba(230, 126, 34, 0.1);
}

.search-icon {
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  color: #95a5a6;
}

/* Toolbar & Filters (Ocultado para maximizar espacio vertical) */
.toolbar {
  display: none !important;
}

.filter-options {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-item {
  background: white;
  border: 1px solid var(--border-color);
  padding: 8px 18px;
  border-radius: 20px;
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 500;
  color: var(--text-light);
  transition: all 0.2s ease;
}

.filter-item:hover {
  background: #f1f1f1;
  color: var(--text-main);
}

.filter-item.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.sort-options {
  padding: 10px 15px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: white;
  cursor: pointer;
  font-family: var(--font-body);
}

/* Estilos para portadas dinámicas */
/* Estilos para portadas (Estáticas) */
.book-cover-img {
  opacity: 1;
  transition: transform 0.3s ease;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* .loaded class ya no es necesaria con imágenes estáticas, pero se mantiene por compatibilidad si algún script antiguo la usa */
.book-cover-img.loaded {
  opacity: 1;
}

/* Responsive Grid System */
.books-grid-container {
  min-height: 400px;
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  gap: 40px;
  padding-bottom: 40px;
}

/* ... existing code ... */

.book-visual {
  flex: 0 0 150px;
  /* Aumentar espacio reservado para que el libro no toque el texto */
  display: flex;
  justify-content: center;
  align-items: center;
  perspective: 1000px;
  position: relative;
  z-index: 20;
}

/* Book Card - Premium Clean Lift & Comet Border (Cometa Azul) */
.book-card {
  background-color: #ffffff;
  border: 1px solid #e1e4e8;
  border-radius: 12px;
  overflow: visible;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.04);
  position: relative;

  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 0.4s ease,
    border-color 0.3s ease;

  display: flex;
  flex-direction: column;
  min-height: 20px;
  height: auto;
}

/* Pseudo-elemento para el borde "Cometa" */
.book-card::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 13px;
  padding: 2px;

  background: conic-gradient(from var(--border-angle),
      transparent 20%,
      rgba(37, 99, 235, 0.3) 80%,
      #2563eb 100%);

  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);

  -webkit-mask-composite: xor;
  mask-composite: exclude;

  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: 10;
}

.book-card:hover {
  transform: translateY(-8px);
  border-color: transparent;
  box-shadow: 0 20px 40px -12px rgba(0, 0, 0, 0.12);
  z-index: 10;
  /* La ola azul ya no existe, solo el cometa */
}

.book-card:hover::after {
  opacity: 1;
  animation: border-spin 2s linear infinite;
}

@keyframes border-spin {
  from {
    --border-angle: 0deg;
  }

  to {
    --border-angle: 360deg;
  }
}

.book-card-body {
  padding: 15px;
  /* Optimizar espacio interno */
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  gap: 15px;
  /* Espacio equilibrado */
  flex: 1;
  align-items: center;
  width: 100%;
  /* Asegurar ancho total */
}



/* INFO DEL LIBRO (LADO DERECHO) */
.book-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  z-index: 10;
  text-align: right;
  padding-left: 10px;

  /* CRITICAL: Text Containment */
  min-width: 0;
  max-width: 100%;
  overflow: hidden;

  overflow-wrap: break-word;
  /* Estándar moderno */
  word-wrap: break-word;
  /* Retrocompatibilidad */
  word-break: break-word;
  /* Asegura ruptura de palabras muy largas */
}

.book-title {
  font-size: 1.1rem;
  line-height: 1.2;
  margin-bottom: 5px;
  max-width: 100%;
}

.book-author {
  font-size: 12px;
  color: var(--accent-color);
  font-weight: 600;
  margin-bottom: 8px;
  text-transform: uppercase;
  max-width: 100%;
}

.book-desc {
  font-size: 14px;
  color: var(--text-light);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: auto;
  /* Empuja el botón hacia abajo */
}

/* DETAILS BUTTON (CUSTOMIZED) */
.details-btn {
  margin-top: 15px;
  padding: 8px 12px;
  background: var(--primary-color);
  border: none;
  text-align: center;
  color: white;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  border-radius: 4px;
  align-self: flex-end;
  /* A la derecha */
  transition: background 0.2s ease;
}

.details-btn:hover {
  background: var(--accent-color);
}


/* Pagination */
.pagination-container {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
  padding: 20px 0;
  flex-wrap: wrap;
}

.page-btn {
  width: 40px;
  height: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  background: white;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.page-btn:hover {
  background-color: #f1f1f1;
}

.page-btn.active {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Modal */
.main-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  z-index: 2000;
  display: none;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.main-overlay.visible {
  opacity: 1;
}

.overlay-details {
  background: white;
  width: 90%;
  max-width: 900px;
  max-height: 90vh;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes slideUp {
  from {
    transform: translateY(50px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.overlay-content-wrapper {
  display: flex;
  flex-direction: row;
}

.overlay-image {
  width: 40%;
  background-color: #f8f9fa;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
}

.book-3d-modal img {
  border-radius: 5px;
  box-shadow: 0 20px 40px -5px rgba(0, 0, 0, 0.4);
  max-width: 100%;
  height: auto;
}

.overlay-desc {
  width: 60%;
  padding: 50px;
  overflow-y: auto;
  max-height: 90vh;
}

.overlay_title {
  font-size: 32px;
  line-height: 1.2;
  margin-bottom: 5px;
}

.meta-info {
  margin-bottom: 25px;
  font-size: 14px;
  color: #888;
}

.published-badge {
  background: #edf2f7;
  padding: 4px 10px;
  border-radius: 4px;
}

.divider {
  height: 1px;
  background: #eee;
  width: 100%;
  margin: 20px 0;
}

.modal-actions {
  margin-top: 30px;
  display: flex;
  gap: 15px;
}

.button {
  padding: 12px 24px;
  border-radius: 30px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: transform 0.2s;
}

.button:hover {
  transform: translateY(-2px);
}

.primary-btn {
  background: var(--accent-color);
  color: white;
}

.secondary-btn {
  background: transparent;
  border: 2px solid var(--border-color);
  color: var(--text-main);
}

.close-overlay-btn {
  position: absolute;
  top: 15px;
  right: 15px;
  background: white;
  border: none;
  border-radius: 50%;
  width: 35px;
  height: 35px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  z-index: 10;
  font-size: 16px;
  color: #555;
  transition: all 0.2s;
}

.close-overlay-btn:hover {
  background: var(--accent-color);
  color: white;
  transform: rotate(90deg);
}

/* Scrollbar */
.overlay-desc::-webkit-scrollbar {
  width: 8px;
}

.overlay-desc::-webkit-scrollbar-thumb {
  background-color: #ccc;
  border-radius: 4px;
}

/* Media Queries */
@media (max-width: 900px) {
  .overlay-content-wrapper {
    flex-direction: column;
  }

  .overlay-image,
  .overlay-desc {
    width: 100%;
  }

  .overlay-image {
    padding: 20px;
    height: 250px;
  }

  .book-3d-modal img {
    max-height: 200px;
  }

  .overlay-desc {
    padding: 30px;
  }
}

@media (max-width: 768px) {
  .page-header-container {
    flex-direction: column;
    align-items: stretch;
  }

  .catalog-search {
    max-width: 100%;
  }

  .book-card-body {
    flex-direction: column;
    /* En móvil, imagen arriba, texto abajo */
    gap: 15px;
  }

  .book-info {
    text-align: center;
    padding-left: 0;
  }

  .details-btn {
    align-self: center;
  }

  .book-visual {
    flex: 0 0 auto;
    display: flex;
    justify-content: center;
    /* Reducir escala en móvil si es necesario */
    transform: scale(0.8);
  }

  .books-grid {
    grid-template-columns: 1fr;
  }
}

/* 
===================================================================
   ESTILOS 3D IMPORTADOS (Animated Book)
=================================================================== 
*/

.book {
  position: relative;
  width: 200px;
  height: 300px;
  perspective: 1000px;
  transform-style: preserve-3d;
  transition: transform 1.5s ease;
  cursor: pointer;
  /* Reducir aún más para garantizar que quepa */
  transform: scale(0.65);
  margin: -50px -35px;
  /* Ajustar margen negativo */
}

.hardcover_front,
.hardcover_back,
.book_spine,
.hardcover_front li,
.hardcover_back li,
.book_spine li {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  pointer-events: none;
}

.hardcover_front,
.hardcover_back {
  transform-origin: 0% 100%;
}

.hardcover_front {
  transition: all 1.6s cubic-bezier(0.25, 1, 0.5, 1), z-index 0.6s;
  transform: rotateY(-34deg) translateZ(8px);
  z-index: 100;
}

.hardcover_back {
  transform: rotateY(-15deg) translateZ(-8px);
}

/* Grosor de las tapas */
.hardcover_front li:first-child,
.hardcover_front li:last-child,
.hardcover_back li:first-child,
.hardcover_back li:last-child,
.book_spine li:first-child,
.book_spine li:last-child {
  background-color: #1e293b;
}

/* Imagen de portada */
.hardcover_front li:first-child {
  cursor: default;
  user-select: none;
  transform: translateZ(2px);
  overflow: hidden;
  border-radius: 4px 2px 2px 4px;
  box-shadow: inset 4px 0 10px rgba(0, 0, 0, 0.5);
}

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

.hardcover_front li:last-child {
  transform: rotateY(180deg) translateZ(2px);
  background: #fdf8e8;
}

.hardcover_back li:first-child {
  transform: translateZ(2px);
  background: #fdf8e8;
}

.hardcover_back li:last-child {
  transform: translateZ(-2px);
  background: #1e293b;
}

/* Grosor (bordes) */
.hardcover_front li:first-child:after,
.hardcover_front li:first-child:before,
.hardcover_front li:last-child:after,
.hardcover_front li:last-child:before,
.hardcover_back li:first-child:after,
.hardcover_back li:first-child:before,
.hardcover_back li:last-child:after,
.hardcover_back li:last-child:before,
.book_spine li:first-child:after,
.book_spine li:first-child:before,
.book_spine li:last-child:after,
.book_spine li:last-child:before {
  position: absolute;
  top: 0;
  left: 0;
  background: #334155;
  content: "";
}

/* LOMO DEL LIBRO */
.book_spine {
  transform: rotateY(60deg) translateX(-5px) translateZ(-12px);
  width: 16px;
  z-index: 0;
  background: #334155;
}

.book_spine li:first-child {
  transform: translateZ(2px);
}

.book_spine li:last-child {
  transform: translateZ(-2px);
}

/* Ajustes finos del grosor */
.hardcover_front li:first-child:after,
.hardcover_front li:first-child:before {
  width: 4px;
  height: 100%;
}

.hardcover_front li:first-child:after {
  transform: rotateY(90deg) translateZ(-2px) translateX(2px);
}

.hardcover_front li:first-child:before {
  transform: rotateY(90deg) translateZ(198px) translateX(2px);
}

.hardcover_back li:first-child:after,
.hardcover_back li:first-child:before {
  width: 4px;
  height: 100%;
}

.hardcover_back li:first-child:after {
  transform: rotateY(90deg) translateZ(-2px) translateX(2px);
}

.hardcover_back li:first-child:before {
  transform: rotateY(90deg) translateZ(198px) translateX(2px);
}

.book_spine li:first-child:after,
.book_spine li:first-child:before {
  width: 4px;
  height: 100%;
}

.book_spine li:first-child:after {
  transform: rotateY(90deg) translateZ(-2px) translateX(2px);
}

.book_spine li:first-child:before {
  transform: rotateY(-90deg) translateZ(-12px);
}

/* PÁGINAS */
.page,
.page>li {
  position: absolute;
  top: 0;
  left: 0;
  transform-style: preserve-3d;
  pointer-events: none;
}

.page {
  width: 100%;
  height: 98%;
  top: 1%;
  left: 3%;
  z-index: 10;
}

.page>li {
  width: 100%;
  height: 100%;
  transform-origin: left center;
  transition-property: transform;
  transition-timing-function: ease;
  background: linear-gradient(to right, #e0d8c0 0%, #fdf8e8 100%);
  box-shadow: inset 0px -1px 2px rgba(50, 50, 50, 0.1), inset -1px 0px 1px rgba(150, 150, 150, 0.2);
  border-radius: 0 5px 5px 0;
}

/* Posiciones iniciales de las páginas */
.page li:nth-child(1) {
  transform: rotateY(-28deg);
  transition-duration: 0.6s;
}

.page li:nth-child(2) {
  transform: rotateY(-30deg);
  transition-duration: 0.6s;
}

/* Las páginas 3+ ahora son generadas dinámicamente desde JS (ver BOOK_ANIMATION_CONFIG) */

/* Contenido de la página (Botones) */
.page-content {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100%;
  gap: 15px;
  padding: 20px;
  text-align: center;
  pointer-events: none;
}

/* Botones Premium */
/* Botones Premium (Importados de Animated CSS Book) */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 10px 15px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--book-accent-color);
  font-weight: 700;
  font-size: 0.8rem;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  transition: background-color 0.2s, color 0.2s, box-shadow 0.2s;
  border: 1px solid rgba(0, 64, 149, 0.2);
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  pointer-events: auto;
  position: relative;
  z-index: 1000;
  backface-visibility: hidden;
  transform: translateZ(1px);
}

.btn i {
  margin-right: 8px;
  transition: transform 0.3s ease;
}

.btn:hover {
  box-shadow: 0 8px 15px rgba(0, 0, 0, 0.15);
  background: var(--book-accent-color);
  color: white;
}

.btn:hover i {
  transform: scale(1.1);
}

/* Variantes */


.btn-info {
  background: var(--book-accent-light);
  color: #0f172a;
  border: none;
}

.btn-info:hover {
  background: #a0b8d9;
  color: #0f172a;
}

/* Btn Descargar (Principal) */
.btn-primary {
  background: var(--book-accent-color);
  color: white;
  box-shadow: 0 4px 15px rgba(4, 68, 148, 0.3);
  border: none;
}

.btn-primary:hover {
  background: var(--book-accent-hover);
  color: white;
  box-shadow: 0 6px 18px rgba(4, 68, 148, 0.5);
}

/* Clases para animación JS */
.anim-read,
.anim-info,
.anim-download {
  transition: none !important;
  will-change: transform, opacity;
}

/* Asegurar que la página de los botones esté accesible */
.book:hover>.page li:nth-child(2) {
  z-index: 50;
}

/* ANIMACIONES DE APERTURA (HOVER) */
.book:hover>.hardcover_front {
  transform: rotateY(-145deg) translateZ(0);
  z-index: 0;
}

/* Animación para LEER */
@keyframes click-read {
  0% {
    transform: translateZ(1px) scale(1);
  }

  50% {
    transform: translateZ(1px) scale(0.9);
    opacity: 0.8;
  }

  100% {
    transform: translateZ(1px) scale(1);
    opacity: 1;
  }
}

.anim-read {
  animation: click-read 0.4s cubic-bezier(0.25, 1, 0.5, 1) forwards !important;
}

/* Animación para INFORMACIÓN: Shake */
@keyframes click-info {
  0% {
    transform: translateZ(1px) translateX(0);
  }

  25% {
    transform: translateZ(1px) translateX(-4px) rotate(-3deg);
  }

  50% {
    transform: translateZ(1px) translateX(4px) rotate(3deg);
  }

  75% {
    transform: translateZ(1px) translateX(-2px) rotate(-1deg);
  }

  100% {
    transform: translateZ(1px) translateX(0) rotate(0);
  }
}

.anim-info {
  animation: click-info 0.5s ease-in-out forwards !important;
}

/* Animación para DESCARGAR */
@keyframes click-download {
  0% {
    transform: translateZ(1px) translateY(0);
  }

  40% {
    transform: translateZ(1px) translateY(-4px);
  }

  100% {
    transform: translateZ(1px) translateY(20px);
    opacity: 0;
  }
}

.anim-download {
  animation: click-download 0.6s ease-in forwards !important;
}

.book:hover>.page li:nth-child(1) {
  transform: rotateY(-30deg);
  transition-duration: 1.8s;
}

.book:hover>.page li:nth-child(2) {
  transform: rotateY(-35deg);
  transition-duration: 2.0s;
}

/* Las animaciones hover para páginas 3+ también son dinámicas */