body.books-theme-page {
  --books-bg: #fff;
  --books-text: #000;
  --books-border: #000;
  --books-surface: #fff;
  --books-surface-inverse: #000;
  --books-surface-inverse-text: #fff;
  --books-muted: #777;
  --books-row-border: #ddd;
  --books-disabled-border: #bcbcbc;
  --books-disabled-surface: #f5f5f5;
  --books-disabled-text: #9a9a9a;
  --books-overlay: rgba(255, 255, 255, 0.1);
  --books-modal-bg: rgba(255, 255, 255, 0.85);
  background-color: var(--books-bg);
  color: var(--books-text);
}

body.books-theme-page a {
  color: var(--books-text);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme]) body.books-theme-page {
    --books-bg: #000;
    --books-text: #fff;
    --books-border: #fff;
    --books-surface: #000;
    --books-surface-inverse: #fff;
    --books-surface-inverse-text: #000;
    --books-muted: #b3b3b3;
    --books-row-border: #444;
    --books-disabled-border: #666;
    --books-disabled-surface: #202020;
    --books-disabled-text: #777;
    --books-overlay: rgba(0, 0, 0, 0.35);
    --books-modal-bg: rgba(0, 0, 0, 0.8);
  }
}

html[data-theme='dark'] body.books-theme-page {
  --books-bg: #000;
  --books-text: #fff;
  --books-border: #fff;
  --books-surface: #000;
  --books-surface-inverse: #fff;
  --books-surface-inverse-text: #000;
  --books-muted: #b3b3b3;
  --books-row-border: #444;
  --books-disabled-border: #666;
  --books-disabled-surface: #202020;
  --books-disabled-text: #777;
  --books-overlay: rgba(0, 0, 0, 0.35);
  --books-modal-bg: rgba(0, 0, 0, 0.8);
}

html[data-theme='light'] body.books-theme-page {
  --books-bg: #fff;
  --books-text: #000;
  --books-border: #000;
  --books-surface: #fff;
  --books-surface-inverse: #000;
  --books-surface-inverse-text: #fff;
  --books-muted: #777;
  --books-row-border: #ddd;
  --books-disabled-border: #bcbcbc;
  --books-disabled-surface: #f5f5f5;
  --books-disabled-text: #9a9a9a;
  --books-overlay: rgba(255, 255, 255, 0.1);
  --books-modal-bg: rgba(255, 255, 255, 0.85);
}

.books-page {
  padding: 20px;
}

.books-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.books-view-switch {
  display: flex;
  gap: 8px;
}

.view-toggle {
  border: 1px solid var(--books-border);
  border-radius: 0;
  padding: 4px 10px;
  background: var(--books-surface);
  color: var(--books-text);
  font: inherit;
  cursor: pointer;
}

.view-toggle.is-active {
  background: var(--books-surface-inverse);
  color: var(--books-surface-inverse-text);
}

.books-sort-switch {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.books-count-label {
  color: var(--books-muted);
  white-space: nowrap;
}

.sort-toggle {
  border: 1px solid var(--books-border);
  border-radius: 0;
  padding: 4px 10px;
  background: var(--books-surface);
  color: var(--books-text);
  font: inherit;
  cursor: pointer;
}

.sort-toggle.is-active {
  background: var(--books-surface-inverse);
  color: var(--books-surface-inverse-text);
}

@media (max-width: 699px) {
  .books-toolbar {
    display: none;
  }

  .books-grid.view-panel {
    display: grid !important;
  }

  .books-list.view-panel {
    display: none !important;
  }
}

.books-page-title {
  font-size: 1em;
  margin-bottom: 20px;
  font-weight: 700;
}

.books-search-row {
  margin-bottom: 12px;
}

.books-search {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--books-border);
  border-radius: 999px;
  padding: 4px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--books-surface);
}

.books-search-input {
  width: 100%;
  min-width: 0;
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  color: var(--books-text);
  font: inherit;
  line-height: 1.2;
  outline: none;
}

.books-search-input::placeholder {
  color: var(--books-muted);
  opacity: 1;
}

.books-search-clear {
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  color: var(--books-text);
  font: inherit;
  font-size: 1em;
  line-height: 1;
  cursor: pointer;
}

.books-search-clear:hover {
  opacity: 0.65;
}

.books-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.category-filter {
  border: 1px solid var(--books-border);
  border-radius: 999px;
  padding: 4px 10px;
  background: var(--books-surface);
  color: var(--books-text);
  font: inherit;
  cursor: pointer;
}

.category-filter.is-active {
  background: var(--books-surface-inverse);
  color: var(--books-surface-inverse-text);
}

.books-filters.is-disabled .category-filter,
.category-filter:disabled {
  border-color: var(--books-disabled-border);
  background: var(--books-disabled-surface);
  color: var(--books-disabled-text);
  cursor: not-allowed;
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px 20px;
}

.view-panel {
  display: none;
}

.view-panel.is-active {
  display: block;
}

.books-grid.view-panel.is-active {
  display: grid;
}

@media (min-width: 760px) {
  .books-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 980px) {
  .books-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 1200px) {
  .books-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (min-width: 1300px) {
  .books-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

@media (min-width: 1680px) {
  .books-grid {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }
}

.book-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.book-cover-wrap {
  width: 100%;
  aspect-ratio: 7 / 10;
  background: var(--books-disabled-surface);
  overflow: hidden;
}

.book-cover-link {
  display: block;
  width: 100%;
  height: 100%;
}

.book-cover-media {
  position: relative;
  width: 100%;
  height: 100%;
}

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

.book-cover-placeholder {
  position: absolute;
  inset: 0;
  filter: blur(10px);
  transform: scale(1.04);
  transition: opacity 0.24s ease;
}

.book-cover-full {
  position: absolute;
  inset: 0;
}

.js .book-cover-full {
  opacity: 0;
  transition: opacity 0.24s ease;
}

.js .book-cover-full.is-loaded {
  opacity: 1;
}

.js .book-cover-media.is-loaded .book-cover-placeholder {
  opacity: 0;
}

.book-meta p,
.book-title {
  margin: 0;
  font-size: 1em;
  line-height: 1.25;
}

.book-title a {
  color: inherit;
  text-decoration: none;
}

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

.book-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.book-bottom {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: auto;
  padding-top: 1.25em;
  min-width: 0;
}

.book-tags-wrap {
  position: relative;
  min-width: 0;
  overflow: hidden;
}

.book-tags-wrap::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 28px;
  pointer-events: none;
  background: linear-gradient(to right, transparent, var(--books-bg));
}

.book-tags-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  min-width: 0;
  padding-right: 24px;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
}

.book-tags-row::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.book-tag-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--books-border);
  border-radius: 999px;
  padding: 1px 8px;
  background: var(--books-surface);
  color: var(--books-text);
  font-size: 0.85em;
  line-height: 1.25;
  white-space: nowrap;
}

.book-footer {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  padding-top: 0;
}

.book-actions {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  margin-left: auto;
}

.book-card.is-hidden {
  display: none;
}

.books-list {
  overflow-x: auto;
}

.books-list-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.books-list-table th,
.books-list-table td {
  text-align: left;
  vertical-align: top;
  padding: 6px 10px 6px 0;
  font-size: 1em;
  line-height: 1.25;
  font-weight: 400;
}

.books-list-table thead th {
  border-bottom: 1px solid var(--books-border);
}

.books-list-table tbody td {
  border-bottom: 1px solid var(--books-row-border);
}

.books-list-table th:nth-child(1),
.books-list-table td:nth-child(1) {
  width: 20%;
}

.books-list-table th:nth-child(2),
.books-list-table td:nth-child(2) {
  width: 20%;
}

.books-list-table th:nth-child(3),
.books-list-table td:nth-child(3) {
  width: 5%;
}

.books-list-table th:nth-child(4),
.books-list-table td:nth-child(4) {
  width: 20%;
}

.books-list-table th:nth-child(5),
.books-list-table td:nth-child(5) {
  width: 20%;
}

.books-list-table th:nth-child(6),
.books-list-table td:nth-child(6) {
  width: 7.5%;
}

.books-list-table th:nth-child(7),
.books-list-table td:nth-child(7) {
  width: 7.5%;
  text-align: right;
}

.book-row.is-hidden {
  display: none;
}

.copy-biblio-btn {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--books-text);
  font: inherit;
  font-size: 1em;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
}

.copy-biblio-btn:hover {
  text-decoration: none;
  opacity: 0.65;
}

.pdf-link {
  color: var(--books-text);
  text-decoration: none;
}

.pdf-link:hover {
  text-decoration: none;
  opacity: 0.65;
}

.pdf-access-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 4000;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  background: var(--books-overlay);
}

.pdf-access-modal.is-visible {
  opacity: 1;
}

.pdf-access-modal-text {
  margin: 0;
  padding: 8px 14px;
  border: 1px solid var(--books-border);
  background: var(--books-modal-bg);
  color: var(--books-text);
  font: inherit;
  font-size: 1.1em;
  line-height: 1.2;
}

.books-theme-toggle {
  border: 0;
  padding: 0;
  margin: 0 0 0 8px;
  background: transparent;
  color: var(--books-text);
  font: inherit;
  cursor: pointer;
}

.books-theme-toggle-option {
  color: var(--books-muted);
}

.books-theme-toggle[data-active-theme='dark'] .books-theme-toggle-option--dark,
.books-theme-toggle[data-active-theme='light'] .books-theme-toggle-option--light {
  color: var(--books-text);
}
