.books-hero {
  padding: 4.5rem 1.5rem 2.5rem;
}

.books-hero__content {
  max-width: 960px;
  margin: 0 auto;
  text-align: left;
}

.books-section {
  padding: 0 1.5rem 5rem;
}

.books-section__header {
  max-width: 1100px;
  margin: 0 auto 2rem;
}

.books-grid {
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.75rem;
}

.book-card {
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.book-thumb {
  position: relative;
  padding-top: 150%;
  background: rgba(255, 255, 255, 0.08);
}

.book-thumb img,
.book-thumb__placeholder {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.book-thumb img {
  object-fit: contain;
  background: rgba(10, 6, 20, 0.6);
}

.book-thumb__placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.7);
  background: linear-gradient(135deg, rgba(106, 13, 173, 0.55), rgba(179, 78, 233, 0.35));
}

.book-card__body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.book-card__body h3 {
  margin: 0;
  font-size: 1.25rem;
}

.book-card__topic {
  margin: 0;
  font-weight: 600;
  color: rgba(245, 242, 255, 0.8);
}

.book-card__excerpt {
  margin: 0;
  color: rgba(245, 242, 255, 0.75);
  line-height: 1.5;
  min-height: 4.5em;
}

.book-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.btn-danger {
  background: linear-gradient(135deg, #ff4d4d, #b31237);
  box-shadow: 0 12px 24px rgba(179, 18, 55, 0.35);
}

.btn-danger:hover {
  box-shadow: 0 16px 30px rgba(179, 18, 55, 0.45);
}

.books-empty {
  max-width: 900px;
  margin: 3rem auto 0;
  padding: 2rem;
  text-align: center;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.books-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 2000;
}

.books-modal.is-visible {
  display: flex;
}

.books-modal__overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 6, 20, 0.7);
  backdrop-filter: blur(10px);
}

.books-modal__panel {
  position: relative;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  max-width: 900px;
  width: 100%;
  max-height: 92vh;
  overflow: hidden;
  background: #13071c;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
}

.books-modal__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.5rem 1.5rem 0.5rem;
}

.books-modal__actions {
  display: flex;
  gap: 0.5rem;
}

.books-modal__expand,
.books-modal__close {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 1.25rem;
  line-height: 1;
  border-radius: 999px;
  width: 40px;
  height: 40px;
  cursor: pointer;
}

.books-modal__close {
  font-size: 1.5rem;
}

.books-modal__meta {
  padding: 0 1.5rem 0.5rem;
  color: rgba(245, 242, 255, 0.7);
}

.books-modal__content {
  --books-page-width: 560px;
  padding: 1.5rem;
  overflow: hidden;
  color: rgba(245, 242, 255, 0.9);
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 0;
}

.book-page {
  flex: 1 1 auto;
  height: 100%;
  width: min(100%, var(--books-page-width));
  max-width: 100%;
  min-height: 0;
  max-height: 100%;
  margin: 0 auto;
  overflow-y: auto;
  padding: 1.5rem;
  background: rgba(21, 10, 34, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  display: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.book-page.is-active {
  display: block;
}

.books-modal__footer {
  padding: 1rem 1.5rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.books-modal__nav {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.books-modal__nav:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.books-modal__page {
  font-weight: 600;
  color: rgba(245, 242, 255, 0.8);
}

.books-modal__content h1,
.books-modal__content h2,
.books-modal__content h3 {
  color: #fff;
}

.books-modal__content .chapter-card,
.books-modal__content .book-title-page,
.books-modal__content .toc-page {
  background: transparent;
  border-radius: 16px;
  padding: 1.5rem;
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: inherit;
  margin-bottom: 1.5rem;
}

.books-modal__content .book-cover-page {
  margin-bottom: 1.5rem;
  width: min(100%, 832px);
  aspect-ratio: 832 / 1258;
  padding: 12px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: linear-gradient(180deg, rgba(20, 18, 54, 0.92), rgba(9, 8, 31, 0.95));
  box-shadow: 0 18px 36px rgba(4, 3, 21, 0.45);
  box-sizing: border-box;
  margin-left: auto;
  margin-right: auto;
}

.books-modal__content .book-cover-page img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.books-modal__content .chapter-card h2 {
  margin-top: 0;
  color: inherit;
  line-height: 1.3;
  font-weight: 800;
  word-break: break-word;
  hyphens: auto;
}

.books-modal__content .chapter-card .chapter-body {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.8;
  font-family: inherit;
  font-size: inherit;
  text-align: left;
  max-width: 100%;
  hyphens: auto;
}

.books-modal__content .chapter-card .chapter-body p {
  margin: 0.75em 0;
}

.books-modal__content .chapter-card .chapter-body ul,
.books-modal__content .chapter-card .chapter-body ol {
  margin: 0.75em 0 0.85em 1.4em;
}

.books-modal__content .chapter-card .chapter-body li {
  margin: 0.25em 0;
}

.books-modal__content .chapter-card .chapter-body pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 0.85em 0;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  font-size: 0.95em;
  max-width: 100%;
  box-sizing: border-box;
}

.books-modal__content .chapter-card .chapter-body code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  padding: 2px 6px;
  word-break: break-word;
}


.books-modal__content .chapter-card img,
.books-modal__content .chapter-body img,
.books-modal__content .qb-chapter-image-box img {
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0.75rem auto;
  border-radius: 12px;
}

.books-modal__content .qb-chapter-image-box {
  margin: 1rem 0 1.25rem;
}

.books-modal__panel.is-maximized {
  width: min(98vw, 1400px);
  max-width: min(98vw, 1400px);
  max-height: 98vh;
}

.books-modal__panel.is-maximized .books-modal__content {
  --books-page-width: 1024px;
}

.books-loading,
.books-error {
  padding: 1rem;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
}

.books-modal-open {
  overflow: hidden;
}

@media (max-width: 720px) {
  .books-modal__panel {
    max-height: 90vh;
  }

  .books-modal__header {
    flex-direction: column;
    align-items: flex-start;
  }

  .books-modal__content {
    padding: 0.85rem;
  }

  .book-page {
    padding: 0.9rem;
    font-size: 11px;
    line-height: 1.65;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  .books-modal__content .chapter-card,
  .books-modal__content .book-title-page,
  .books-modal__content .toc-page {
    padding: 0.9rem;
  }

  .books-modal__content .chapter-card .chapter-body,
  .books-modal__content .chapter-card .chapter-body p,
  .books-modal__content .chapter-card .chapter-body li {
    font-size: 1em;
    line-height: 1.65;
  }

  .books-modal__content .chapter-card h2 {
    font-size: 1.08em;
    line-height: 1.3;
  }
}

@media (max-width: 420px) {
  .book-page {
    font-size: 9.5px;
    line-height: 1.58;
  }

  .books-modal__content .chapter-card .chapter-body,
  .books-modal__content .chapter-card .chapter-body p,
  .books-modal__content .chapter-card .chapter-body li {
    font-size: 1em;
    line-height: 1.58;
  }

  .books-modal__content .chapter-card h2 {
    font-size: 1.02em;
  }
}
