* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: #0f1117;
  color: #e1e2e6;
  min-height: 100vh;
}

header {
  text-align: center;
  padding: 3rem 1rem 1.5rem;
  position: relative;
}

header h1 {
  font-size: 2.2rem;
  font-weight: 700;
  color: #fff;
}

.subtitle {
  color: #8b8d97;
  margin-top: 0.4rem;
  font-size: 1rem;
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
}

/* ---- Category Tabs ---- */
.category-tabs {
  display: flex;
  gap: 0.4rem;
  margin-top: 1.5rem;
}

.tab {
  padding: 0.55rem 1.3rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid #2a2d35;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  background: #1a1c24;
  color: #8b8d97;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.tab:hover {
  color: #e1e2e6;
}

.tab.library-tab {
  margin-left: auto;
  border-color: #3a5c3a;
  color: #6fcf6f;
}

.tab.library-tab.active {
  background: #2a5c2a;
  border-color: #2a5c2a;
  color: #fff;
}

.tab.active {
  background: #5c6bc0;
  color: #fff;
  border-color: #5c6bc0;
}

/* ---- Search Bar ---- */
.search-bar {
  display: flex;
  gap: 0.5rem;
  margin-top: 0;
}

#search-input {
  flex: 1;
  padding: 0.85rem 1.2rem;
  font-size: 1rem;
  border: 1px solid #2a2d35;
  border-radius: 8px;
  background: #1a1c24;
  color: #e1e2e6;
  outline: none;
  transition: border-color 0.2s;
}

#search-input:focus {
  border-color: #5c6bc0;
}

#search-input::placeholder {
  color: #555;
}

#search-btn {
  padding: 0.85rem 1.8rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  background: #5c6bc0;
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
}

#search-btn:hover {
  background: #7986cb;
}

#search-btn:disabled {
  background: #3a3d4a;
  cursor: not-allowed;
}

/* ---- Loading ---- */
#loading {
  text-align: center;
  padding: 3rem 0;
  color: #8b8d97;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #2a2d35;
  border-top-color: #5c6bc0;
  border-radius: 50%;
  margin: 0 auto 1rem;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---- Error ---- */
#error {
  margin-top: 1.5rem;
  padding: 1rem 1.2rem;
  background: #2d1a1a;
  border: 1px solid #5c2a2a;
  border-radius: 8px;
  color: #f28b8b;
  font-size: 0.95rem;
}

/* ---- Results ---- */
#results {
  margin-top: 2rem;
}

#results-heading {
  font-size: 1.1rem;
  color: #8b8d97;
  margin-bottom: 1.5rem;
  font-weight: 500;
}

/* Genre section */
.genre-section {
  margin-bottom: 2rem;
}

.genre-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #5c6bc0;
  padding-bottom: 0.5rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid #1e2029;
}

/* Book card */
.book-card {
  display: flex;
  gap: 1rem;
  padding: 1rem 1.2rem;
  margin-bottom: 0.5rem;
  background: #1a1c24;
  border: 1px solid #2a2d35;
  border-radius: 8px;
  transition: border-color 0.2s;
  cursor: pointer;
  flex-wrap: wrap;
}

.book-card:hover {
  border-color: #3a3d4a;
}

.book-card.expanded {
  border-color: #5c6bc0;
}

.book-rank {
  font-size: 1.4rem;
  font-weight: 700;
  color: #2a2d35;
  min-width: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.book-info {
  flex: 1;
  min-width: 0;
}

.book-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: #fff;
  margin-bottom: 0.25rem;
}

.book-authors {
  font-size: 0.9rem;
  color: #8b8d97;
  margin-bottom: 0.4rem;
}

.book-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tag {
  font-size: 0.72rem;
  padding: 0.15rem 0.55rem;
  background: #23252f;
  border: 1px solid #2a2d35;
  border-radius: 4px;
  color: #8b8d97;
}

/* Expand arrow */
.book-expand {
  display: flex;
  align-items: center;
  color: #3a3d4a;
  font-size: 0.8rem;
  flex-shrink: 0;
  padding: 0 0.2rem;
}

/* Expanded details */
.book-details {
  width: 100%;
  padding-top: 0.8rem;
  margin-top: 0.6rem;
  border-top: 1px solid #23252f;
}

.book-description {
  font-size: 0.9rem;
  line-height: 1.55;
  color: #b0b1b8;
  margin-bottom: 0.8rem;
}

.book-links {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.book-link {
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.35rem 0.8rem;
  background: #23252f;
  border: 1px solid #2a2d35;
  border-radius: 6px;
  color: #5c6bc0;
  text-decoration: none;
  transition: background 0.2s;
}

.book-link:hover {
  background: #2a2d35;
  color: #7986cb;
}

/* Find Similar button */
.similar-btn {
  margin-top: 0.7rem;
  padding: 0.5rem 1.2rem;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid #5c6bc0;
  border-radius: 6px;
  background: transparent;
  color: #5c6bc0;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.similar-btn:hover {
  background: #5c6bc0;
  color: #fff;
}

/* Back to search button */
.back-btn {
  display: inline-block;
  margin-bottom: 1.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid #2a2d35;
  border-radius: 6px;
  background: #1a1c24;
  color: #8b8d97;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.back-btn:hover {
  background: #23252f;
  color: #e1e2e6;
}

/* Book action buttons row */
.book-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.7rem;
  flex-wrap: wrap;
}

/* Save to Library */
.save-btn {
  padding: 0.45rem 1rem;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid #2a5c2a;
  border-radius: 6px;
  background: transparent;
  color: #6fcf6f;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.save-btn:hover {
  background: #2a5c2a;
  color: #fff;
}

.save-btn.saved {
  background: #1a2e1a;
  border-color: #2a5c2a;
  color: #4a9a4a;
  cursor: default;
}

/* Remove from Library */
.remove-btn {
  padding: 0.45rem 1rem;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid #5c2a2a;
  border-radius: 6px;
  background: transparent;
  color: #cf6f6f;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.remove-btn:hover {
  background: #5c2a2a;
  color: #fff;
}

/* Recommend button in library */
.recommend-btn {
  display: block;
  width: 100%;
  padding: 0.8rem;
  margin-bottom: 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  border: 1px solid #5c6bc0;
  border-radius: 8px;
  background: #5c6bc0;
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
}

.recommend-btn:hover {
  background: #7986cb;
}

/* Library hint */
.library-hint {
  color: #555;
  font-size: 0.95rem;
  text-align: center;
  padding: 2rem 0;
}

/* Saved / Liked / Disliked view switcher — a single segmented control
   that uses the same green accent as the top-level "My Library" tab, so
   the library section reads as one cohesive unit. */
.library-views {
  display: flex;
  margin: 0 0 1.5rem;
  border: 1px solid #3a5c3a;
  border-radius: 8px;
  overflow: hidden;
  background: #1a2e1a;
}

.library-view {
  flex: 1;
  padding: 0.7rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  border-right: 1px solid #2a4a2a;
  background: transparent;
  color: #6fcf6f;
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
}

.library-view:last-child {
  border-right: none;
}

.library-view:hover {
  background: #223d22;
  color: #a1e0a1;
}

.library-view.active {
  background: #2a5c2a;
  color: #fff;
  cursor: default;
}

.library-view.active:hover {
  background: #2a5c2a;
  color: #fff;
}

/* Thumbs up / thumbs down */
.feedback-btn {
  padding: 0.4rem 0.7rem;
  font-size: 0.95rem;
  line-height: 1;
  border: 1px solid #333;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
}

.feedback-btn:hover {
  background: #1a1a1a;
}

.feedback-btn:active {
  transform: scale(0.95);
}

.like-btn.active {
  background: #1a2e1a;
  border-color: #2a5c2a;
}

.dislike-btn.active {
  background: #2e1a1a;
  border-color: #5c2a2a;
}

/* Relevance badge */
.relevance-badge {
  font-size: 0.82rem;
  font-weight: 700;
  min-width: 3.2rem;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  flex-shrink: 0;
}

.relevance-badge.high {
  background: #1a2e1a;
  color: #6fcf6f;
  border: 1px solid #2a5c2a;
}

.relevance-badge.mid {
  background: #2e2a1a;
  color: #cfb86f;
  border: 1px solid #5c4f2a;
}

.relevance-badge.low {
  background: #2d1a1a;
  color: #cf6f6f;
  border: 1px solid #5c2a2a;
}

/* ---- Pagination ---- */
#pagination {
  display: flex;
  justify-content: center;
  gap: 0.4rem;
  margin-top: 2rem;
  padding-bottom: 3rem;
}

.page-btn {
  padding: 0.5rem 0.9rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: 1px solid #2a2d35;
  border-radius: 6px;
  background: #1a1c24;
  color: #8b8d97;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.page-btn:hover:not(:disabled) {
  background: #23252f;
  color: #e1e2e6;
}

.page-btn.active {
  background: #5c6bc0;
  color: #fff;
  border-color: #5c6bc0;
}

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

/* ---- Auth ---- */
#auth-bar {
  position: absolute;
  top: 1.2rem;
  right: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-size: 0.88rem;
  color: #8b8d97;
}

.auth-btn {
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid #2a2d35;
  border-radius: 6px;
  background: #1a1c24;
  color: #e1e2e6;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.auth-btn:hover {
  background: #23252f;
}

#auth-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.auth-card {
  position: relative;
  width: 100%;
  max-width: 360px;
  background: #1a1c24;
  border: 1px solid #2a2d35;
  border-radius: 12px;
  padding: 2rem 1.8rem;
}

.auth-card h2 {
  color: #fff;
  font-size: 1.3rem;
  margin-bottom: 1.2rem;
}

.auth-card input {
  width: 100%;
  padding: 0.75rem 1rem;
  margin-bottom: 0.8rem;
  font-size: 0.95rem;
  border: 1px solid #2a2d35;
  border-radius: 8px;
  background: #0f1117;
  color: #e1e2e6;
  outline: none;
  transition: border-color 0.2s;
}

.auth-card input:focus {
  border-color: #5c6bc0;
}

#auth-submit {
  width: 100%;
  padding: 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  background: #5c6bc0;
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
}

#auth-submit:hover {
  background: #7986cb;
}

#auth-submit:disabled {
  background: #3a3d4a;
  cursor: not-allowed;
}

.auth-error {
  margin-bottom: 0.8rem;
  padding: 0.6rem 0.8rem;
  background: #2d1a1a;
  border: 1px solid #5c2a2a;
  border-radius: 6px;
  color: #f28b8b;
  font-size: 0.85rem;
}

.auth-toggle {
  margin-top: 1rem;
  font-size: 0.85rem;
  color: #8b8d97;
  text-align: center;
}

.auth-toggle button {
  background: none;
  border: none;
  color: #5c6bc0;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}

.auth-toggle button:hover {
  color: #7986cb;
}

.auth-close {
  position: absolute;
  top: 0.7rem;
  right: 1rem;
  background: none;
  border: none;
  color: #8b8d97;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.auth-close:hover {
  color: #e1e2e6;
}

.library-login-btn {
  display: block;
  max-width: 260px;
  margin: 0 auto;
}

/* ---- Utility ---- */
.hidden {
  display: none !important;
}

/* ---- Library sections ---- */
.section-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0 0 1.2rem;
}

.section-chip {
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid #3a3d4a;
  border-radius: 999px;
  background: #1a1c24;
  color: #8b8d97;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, border-color 0.18s;
}

.section-chip:hover {
  background: #23252f;
  color: #e1e2e6;
}

.section-chip.active {
  background: #5c6bc0;
  border-color: #5c6bc0;
  color: #fff;
  cursor: default;
}

.section-chip.section-new {
  border-style: dashed;
  color: #7986cb;
}

.section-chip.section-manage {
  font-size: 0.78rem;
  padding: 0.45rem 0.7rem;
}

.section-chip.section-delete {
  border-color: #5c2a2a;
  color: #cf6f6f;
}

.section-chip.section-delete:hover {
  background: #5c2a2a;
  color: #fff;
}

/* "Add to section…" dropdown on saved-book cards */
.section-select {
  padding: 0.45rem 0.7rem;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid #3a3d4a;
  border-radius: 6px;
  background: #1a1c24;
  color: #8b8d97;
  cursor: pointer;
}

.section-select:hover {
  background: #23252f;
  color: #e1e2e6;
}

/* Selection checkbox for ad-hoc "recommend from selected" */
.select-box {
  width: 1.1rem;
  height: 1.1rem;
  align-self: center;
  accent-color: #5c6bc0;
  cursor: pointer;
}

/* The "Recommend from N selected" bar reuses .recommend-btn; tint it so the
   two recommend actions read as related but distinct. */
.selected-bar {
  background: #2a5c2a;
  border-color: #2a5c2a;
}

.selected-bar:hover {
  background: #3a7c3a;
}

/* Built-in reading-status chips — same shape as sections, warmer tint so
   they read as system shelves rather than user-created ones. */
.section-chip.section-builtin {
  border-color: #4a3d2a;
  color: #cfa86f;
}

.section-chip.section-builtin:hover {
  background: #2f2820;
  color: #e8c890;
}

.section-chip.section-builtin.active {
  background: #8a6d3b;
  border-color: #8a6d3b;
  color: #fff;
}

/* ---- Admin stats ---- */
.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.7rem;
  margin-bottom: 1.5rem;
}

.stats-card {
  padding: 0.9rem 1rem;
  background: #1a1c24;
  border: 1px solid #2a2d35;
  border-radius: 8px;
  text-align: center;
}

.stats-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: #7986cb;
}

.stats-label {
  margin-top: 0.3rem;
  font-size: 0.78rem;
  color: #8b8d97;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.stats-table th,
.stats-table td {
  padding: 0.55rem 0.8rem;
  text-align: left;
  border-bottom: 1px solid #2a2d35;
}

.stats-table th {
  color: #8b8d97;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats-table td {
  color: #e1e2e6;
}

/* ---- Site footer ---- */
.site-footer {
  margin: 3rem auto 1.5rem;
  padding: 1.2rem 1rem 0;
  max-width: 900px;
  border-top: 1px solid #2a2d35;
  text-align: center;
  color: #8b8d97;
  font-size: 0.88rem;
}

.site-footer a {
  color: #7986cb;
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

/* ---- Year filter row ---- */
.year-filter {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: #8b8d97;
  flex-wrap: wrap;
}

.year-filter input {
  width: 6.5rem;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  border: 1px solid #2a2d35;
  border-radius: 6px;
  background: #1a1c24;
  color: #e1e2e6;
}

.year-filter input:focus {
  outline: none;
  border-color: #5c6bc0;
}

.year-filter-hint {
  font-size: 0.75rem;
  color: #555;
}

/* ---- Book cover in expanded details ---- */
.book-cover {
  float: left;
  width: 92px;
  margin: 0.2rem 1rem 0.5rem 0;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.book-details::after {  /* contain the float */
  content: "";
  display: block;
  clear: both;
}

/* ---- Light mode ----
   Dark is the default; body.light opts in (persisted in localStorage).
   Curated overrides for the major surfaces rather than a full variable
   refactor — extend here if a new component reads as too dark. */
body.light {
  background: #f4f4f7;
  color: #24262e;
}

body.light header h1 { color: #3f51b5; }
body.light .subtitle,
body.light .year-filter,
body.light #results-heading { color: #5a5d6b; }

body.light #search-input,
body.light .year-filter input,
body.light .auth-card input {
  background: #ffffff;
  color: #24262e;
  border-color: #c9ccd6;
}

body.light .tab {
  background: #e8e9ef;
  color: #5a5d6b;
  border-color: #c9ccd6;
}

body.light .tab.active {
  background: #5c6bc0;
  color: #fff;
  border-color: #5c6bc0;
}

body.light .book-card,
body.light .stats-card,
body.light .auth-card,
body.light .back-btn {
  background: #ffffff;
  border-color: #d8dae2;
}

body.light .book-card:hover { border-color: #b9bdcc; }
body.light .book-title { color: #24262e; }
body.light .book-authors,
body.light .book-description,
body.light .stats-label,
body.light .library-hint,
body.light .site-footer { color: #5a5d6b; }

body.light .tag {
  background: #e8e9ef;
  color: #5a5d6b;
  border-color: #c9ccd6;
}

body.light .save-btn,
body.light .similar-btn,
body.light .remove-btn,
body.light .feedback-btn,
body.light .section-select,
body.light .auth-btn,
body.light .page-btn {
  background: #ffffff;
  border-color: #c9ccd6;
}

body.light .section-chip {
  background: #ffffff;
  border-color: #c9ccd6;
  color: #5a5d6b;
}

body.light .section-chip.active {
  background: #5c6bc0;
  border-color: #5c6bc0;
  color: #fff;
}

body.light .section-chip.section-builtin {
  border-color: #d9b370;
  color: #9a7224;
}

body.light .section-chip.section-builtin.active {
  background: #8a6d3b;
  border-color: #8a6d3b;
  color: #fff;
}

body.light .library-views { background: #e9f3e9; border-color: #bcd6bc; }
body.light .library-view { color: #3a7c3a; border-color: #cfe2cf; }
body.light .library-view.active,
body.light .library-view.active:hover { background: #3a7c3a; color: #fff; }
body.light .library-view:hover { background: #d9ead9; color: #2a5c2a; }

body.light .stats-table th { color: #8b8d97; }
body.light .stats-table td { color: #24262e; border-color: #d8dae2; }
body.light .book-rank { color: #d0d2da; }
body.light .book-expand { color: #9aa; }
body.light .site-footer { border-color: #d8dae2; }

/* Forgot account help link in the auth modal */
.auth-forgot {
  margin-top: 0.8rem;
  font-size: 0.8rem;
  color: #8b8d97;
  text-align: center;
}

.auth-forgot a {
  color: #7986cb;
  text-decoration: none;
}

.auth-forgot a:hover {
  text-decoration: underline;
}
