/* ===== Books Grid (list page) ===== */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.book-card a {
  display: block;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.2s, transform 0.2s;
}

.book-card a:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
}

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

.book-card-body {
  padding: 1rem;
}

.book-card-body h2 {
  font-size: 1.1rem;
  margin: 0 0 0.5rem;
  line-height: 1.4;
}

.book-card-summary {
  font-size: 0.9rem;
  color: var(--secondary);
  margin: 0 0 0.5rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-card-meta {
  font-size: 0.8rem;
  color: var(--secondary);
}

.book-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.5rem;
}

.book-tag {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  background: var(--code-bg);
  color: var(--secondary);
}

/* ===== Book Section (top page) ===== */
.book-header {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 2rem;
  align-items: flex-start;
}

.book-cover img {
  width: 200px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.book-header-info h1 {
  margin-top: 0;
}

.book-description {
  color: var(--secondary);
  font-size: 1rem;
  line-height: 1.6;
}

.book-source-link {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: var(--primary);
}

.book-chapter-list {
  padding-left: 1.5rem;
  line-height: 2;
}

.book-chapter-list a {
  text-decoration: none;
  color: var(--primary);
}

.book-chapter-list a:hover {
  text-decoration: underline;
}

/* ===== Book Chapter Layout (sidebar + post-single) ===== */
.book-with-sidebar {
  display: flex;
  gap: 0;
  min-height: calc(100vh - 200px);
  /* Break out of PaperMod's .main container */
  width: 100vw;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  max-width: 1200px;
}

.book-with-sidebar .post-single {
  flex: 1;
  min-width: 0;
  padding: 0 2rem;
}

/* Sidebar */
.book-sidebar {
  width: 260px;
  min-width: 260px;
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  font-size: 0.85rem;
  background: var(--code-bg);
}

.book-sidebar-header {
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.book-sidebar-header a {
  font-weight: 700;
  font-size: 0.9rem;
  text-decoration: none;
  color: var(--primary);
  line-height: 1.4;
}

.book-sidebar-chapters {
  list-style: decimal;
  padding-left: 1.5rem;
  margin: 0;
}

.book-sidebar-chapters li {
  margin-bottom: 0.4rem;
  line-height: 1.5;
}

.book-sidebar-chapters a {
  text-decoration: none;
  color: var(--secondary);
  transition: color 0.15s;
}

.book-sidebar-chapters a:hover {
  color: var(--primary);
}

.book-sidebar-chapters li.active a {
  color: var(--accent, #4f46e5);
  font-weight: 600;
}

.book-sidebar-chapters li.active::marker {
  font-weight: 600;
  color: var(--accent, #4f46e5);
}

/* Mobile toggle */
.book-sidebar-toggle {
  display: none;
  position: sticky;
  top: var(--header-height);
  z-index: 10;
  background: var(--theme);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--primary);
  width: 100%;
  text-align: left;
  margin-bottom: 0.5rem;
}

/* ===== Mobile ===== */
@media (max-width: 768px) {
  .book-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .book-cover img {
    width: 160px;
  }

  .book-with-sidebar {
    flex-direction: column;
    width: auto;
    left: auto;
    transform: none;
  }

  .book-sidebar-toggle {
    display: block;
  }

  .book-sidebar {
    display: none;
    width: 100%;
    min-width: 100%;
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 1rem 1rem;
  }

  .book-sidebar.open {
    display: block;
  }

  .book-with-sidebar .post-single {
    padding: 0;
  }
}
