:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --text: #262220;
  --text-muted: #7a746c;
  --border: #e4ded3;
  --accent: #8b5e3c;
  --accent-hover: #74492c;
  --accent-contrast: #ffffff;
  --danger: #b3402f;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --overlay: rgba(0, 0, 0, 0.4);

  --status-toread-text: #7a746c;
  --status-reading-text: #a06a00;
  --status-read-text: #2c6b2f;

  --starred-bg: #fbeecb;
  --starred-bg-hover: #f6e4b3;

  --borrowed-bg: #dcefd7;
  --borrowed-bg-hover: #cbe6c3;
  --borrowed-text: #2c6b2f;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1b1a;
    --surface: #242322;
    --text: #ece9e4;
    --text-muted: #9a938a;
    --border: #38362f;
    --accent: #c99562;
    --accent-hover: #dcab7c;
    --accent-contrast: #211a12;
    --danger: #e0685a;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    --overlay: rgba(0, 0, 0, 0.6);

    --status-toread-text: #9a938a;
    --status-reading-text: #e0a746;
    --status-read-text: #6fbf73;

    --starred-bg: #3a2f16;
    --starred-bg-hover: #473a1c;

    --borrowed-bg: #1e3320;
    --borrowed-bg-hover: #274029;
    --borrowed-text: #6fbf73;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar h1 {
  font-size: 1.4rem;
  margin: 0;
}

.topbar-actions {
  display: flex;
  gap: 0.6rem;
}

.topbar-actions form {
  margin: 0;
  display: contents;
}

.btn {
  display: inline-block;
  border: none;
  border-radius: var(--radius);
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 500;
  text-decoration: none;
  line-height: 1.3;
}

.btn[hidden] {
  display: none;
}

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--bg);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}
.btn-danger:hover {
  background: var(--danger);
  color: var(--accent-contrast);
}

.filters {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 2rem;
  flex-wrap: wrap;
}

.filters input,
.filters select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  background: var(--surface);
  color: var(--text);
}

#searchInput {
  flex: 1;
  min-width: 180px;
}

.year-input {
  width: 80px;
}

.year-input-wide {
  width: 118px;
}

.view-toggle {
  display: flex;
  gap: 0.2rem;
}

.view-toggle .btn {
  padding: 0.4rem 0.6rem;
  line-height: 1;
}

.view-toggle .btn.active {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.result-count {
  padding: 0 2rem;
  margin: 0 0 0.4rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* pages with no .filters bar between the topbar and the count need that
   bar's top spacing restored some other way, or the count sits jammed
   right under the topbar's border */
.result-count.no-filters {
  padding-top: 0.75rem;
}

/* nested inside a detail-page info column, not directly under the
   full-width topbar/filters — that 2rem side padding was meant for the
   latter and just misaligns it here */
.detail-info .result-count {
  padding: 0;
}

.author-matches {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  padding: 0 2rem;
  margin: 0 0 0.8rem;
}

.author-matches[hidden] {
  display: none;
}

.author-matches-label {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-right: 0.2rem;
}

.author-match-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.78rem;
  text-decoration: none;
}

.author-match-chip:hover {
  background: var(--accent);
  color: var(--accent-contrast);
}

.author-match-chip span {
  opacity: 0.75;
}

/* ---------- authors index ---------- */

.authors-index-title {
  margin: 0;
  font-size: 1.1rem;
}

.author-index-list {
  columns: 260px 3;
  column-gap: 2.5rem;
  padding: 0.5rem 2rem 2rem;
}

.author-section-header {
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 0.7rem 0.5rem 0.15rem;
  break-after: avoid-column;
  break-inside: avoid-column;
}

.author-section-header:first-of-type {
  padding-top: 0.2rem;
}

.author-index-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.4rem 0.5rem;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  break-inside: avoid-column;
}

.author-index-row[hidden],
.author-section-header[hidden],
.author-index-list[hidden] {
  display: none;
}

.author-index-row:hover {
  background: var(--bg);
}

.author-index-photo {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--bg);
  overflow: hidden;
}

.author-index-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.author-index-name {
  flex: 1;
  font-size: 0.9rem;
}

.author-index-count {
  color: var(--text-muted);
  font-size: 0.78rem;
  flex-shrink: 0;
}

.author-index-meta {
  color: var(--text-muted);
  font-size: 0.78rem;
  flex-shrink: 0;
  margin-right: 0.8rem;
}

/* ---------- authors index: card view ---------- */

.author-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  align-items: start;
  gap: 1.2rem;
  padding: 0.5rem 2rem 2rem;
}

.author-grid[hidden] {
  display: none;
}

.author-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 0.9rem;
  text-decoration: none;
  color: var(--text);
}

.author-card[hidden] {
  display: none;
}

.author-card:hover {
  border-color: var(--accent);
}

.author-card-left {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.3rem;
  flex: 0 0 108px;
}

.author-card-photo {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.65rem;
  flex-shrink: 0;
}

.author-card-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.author-card-name {
  font-weight: 600;
  font-size: 0.85rem;
  line-height: 1.3;
}

.author-card-count {
  color: var(--text-muted);
  font-size: 0.74rem;
}

.author-card-meta {
  color: var(--text-muted);
  font-size: 0.7rem;
}

.author-card-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem;
  margin-top: 0.1rem;
}

.author-card-titles {
  list-style: none;
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 0 0 0 0.9rem;
  border-left: 1px solid var(--border);
  text-align: left;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 0.35rem;
}

.author-card-titles li a {
  display: block;
  font-size: 0.76rem;
  line-height: 1.35;
  color: var(--text-muted);
  text-decoration: none;
  white-space: normal;
  overflow-wrap: break-word;
}

.author-card-titles li a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* ---------- grid view (covers) ---------- */

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1.2rem;
  padding: 0.5rem 2rem 2rem;
}

.book-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.book-card:hover {
  border-color: var(--accent);
}

.star-toggle {
  background: none;
  border: none;
  padding: 0;
  color: var(--border);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.book-card .star-toggle {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  z-index: 1;
  font-size: 1.3rem;
}

.star-toggle:hover {
  color: #d4a017;
}

.star-toggle.starred {
  color: #d4a017;
}

.col-star {
  width: 2rem;
  text-align: center;
  padding-left: 0.8rem !important;
}

.col-star .star-toggle {
  font-size: 1rem;
}

.star-filter-btn.active {
  background: #d4a017;
  border-color: #d4a017;
  color: #ffffff;
}

.borrowed-filter-btn.active {
  background: #3f8a44;
  border-color: #3f8a44;
  color: #ffffff;
}

/* the starred background is the primary signal — a discrete but distinct
   hue, not just a shade of the neutral theme */
.book-table tbody tr.starred td {
  background: var(--starred-bg);
}

.book-table tbody tr.starred:hover td {
  background: var(--starred-bg-hover);
}

.book-card.starred {
  background: var(--starred-bg);
}

.book-card.starred:hover {
  background: var(--starred-bg-hover);
}

/* borrowed wins over starred when a book is both — placed after the
   starred rules so it takes precedence at equal specificity */
.book-table tbody tr.borrowed td {
  background: var(--borrowed-bg);
}

.book-table tbody tr.borrowed:hover td {
  background: var(--borrowed-bg-hover);
}

.book-card.borrowed {
  background: var(--borrowed-bg);
}

.book-card.borrowed:hover {
  background: var(--borrowed-bg-hover);
}

.borrowed-badge {
  color: var(--borrowed-text);
  margin-left: 0.5rem;
}

.book-cover {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg);
}

.book-cover-placeholder {
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 6px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-align: center;
  padding: 0.5rem;
}

.book-title {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.3;
  color: var(--text);
  text-decoration: none;
}

.book-title:hover {
  color: var(--accent);
  text-decoration: underline;
}

.book-author {
  display: inline-block;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-decoration: none;
  cursor: pointer;
}

.book-author:hover {
  color: var(--accent);
  text-decoration: underline;
}

.book-year {
  color: var(--text-muted);
  font-size: 0.75rem;
}

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

.tag {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-decoration: none;
  cursor: pointer;
}

.tag:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.status-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  width: fit-content;
}

.detail-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.detail-status-badges {
  display: flex;
  align-items: center;
}

.status-to-read {
  color: var(--status-toread-text);
}
.status-reading {
  color: var(--status-reading-text);
}
.status-read {
  color: var(--status-read-text);
}

/* ---------- list view (dense table) ---------- */

.book-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  padding: 0 2rem 2rem;
}

.book-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg);
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.3rem 0.6rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.book-table thead th:hover {
  color: var(--accent);
}

.book-table thead th.col-star {
  cursor: default;
}

.book-table thead th.col-star:hover {
  color: var(--text-muted);
}

.book-table thead th.sorted {
  color: var(--accent);
}

.book-table td {
  padding: 0.28rem 0.6rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 0;
}

.book-table tbody tr {
  cursor: pointer;
}

.book-table tbody tr:hover td {
  background: var(--bg);
}

.book-table .col-title {
  font-weight: 600;
  width: 32%;
}

.book-table .col-author {
  width: 20%;
  color: var(--text-muted);
}

.book-table .col-year {
  width: 4rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.book-table .col-status {
  width: 8rem;
  white-space: nowrap;
}

.book-table .col-subjects {
  color: var(--text-muted);
  white-space: normal;
}

.subject-link {
  cursor: pointer;
}

.subject-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.author-link,
.title-link {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.author-link:hover,
.title-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
}

/* ---------- detail pages (book / author) ---------- */

.topbar-nav {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.detail-page {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem;
}

.detail-page-author h1 {
  margin-bottom: 0.2rem;
}

.detail-page:has(> .detail-cover) {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}

.author-header {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  margin-bottom: 1.5rem;
}

.author-photo-column {
  width: 160px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.author-photo-column .author-photo {
  width: 100%;
}

.author-photo-edit-btn {
  width: 100%;
  font-size: 0.78rem;
  padding: 0.4rem 0.6rem;
}

.author-photo-edit-box[hidden] {
  display: none;
}

.author-photo-edit-box input {
  width: 100%;
  margin-bottom: 0.5rem;
  font-size: 0.8rem;
}

.author-photo-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.author-photo-edit-actions .btn {
  font-size: 0.78rem;
  padding: 0.35rem 0.6rem;
}

.author-name-row {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
}

.author-name-edit-btn {
  font-size: 0.78rem;
  padding: 0.3rem 0.6rem;
  flex-shrink: 0;
}

.author-name-edit {
  display: flex;
  gap: 0.5rem;
  margin: 0.3rem 0;
}

.author-name-edit[hidden] {
  display: none;
}

.author-name-edit input {
  flex: 1;
  max-width: 360px;
  font-size: 1rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.detail-cover {
  width: 220px;
  flex-shrink: 0;
}

.detail-cover img,
.detail-cover-placeholder {
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: var(--radius);
  object-fit: cover;
}

.detail-cover-placeholder {
  font-size: 0.85rem;
}

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

.detail-info h1 {
  margin: 0.4rem 0 0.1rem;
  font-size: 1.6rem;
}

.detail-author-row {
  margin: 0;
  font-size: 1rem;
}

.detail-author-sep {
  color: var(--text-muted);
}

.detail-author {
  color: var(--text-muted);
  font-size: 1rem;
  text-decoration: none;
}

.detail-author:hover {
  color: var(--accent);
  text-decoration: underline;
}

.detail-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.3rem 1rem;
  margin: 1.2rem 0;
  font-size: 0.9rem;
}

.detail-meta dt {
  color: var(--text-muted);
}

.detail-meta dd {
  margin: 0;
}

.detail-subjects {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 1rem 0;
}

.detail-subjects .tag {
  /* .tag's default background matches the page body here (unlike the
     catalog, where tags sit inside a --surface card) — override so they
     don't blend into the page. */
  background: var(--surface);
  border-color: var(--border);
}

.detail-notes {
  margin-top: 1.5rem;
}

.detail-notes h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.detail-notes p {
  white-space: pre-wrap;
  line-height: 1.5;
}

.detail-notes-empty {
  color: var(--text-muted);
  font-style: italic;
}

.related-books-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.related-books-list[hidden] {
  display: none;
}

.related-book-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.6rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}

.related-book-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.related-book-item a {
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}

.related-book-item a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.related-book-author {
  color: var(--text-muted);
  font-size: 0.85rem;
}

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

.project-book-thumb {
  width: 34px;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.related-note-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.related-note-row[hidden] {
  display: none;
}

.related-note {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  white-space: pre-wrap;
  flex: 1;
  min-width: 0;
}

.related-note-empty {
  font-style: italic;
}

.related-note-edit-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.76rem;
  text-decoration: underline;
  padding: 0;
  flex-shrink: 0;
}

.related-note-edit-btn:hover {
  color: var(--accent);
}

.related-note-edit {
  margin-top: 0.35rem;
}

.related-note-edit[hidden] {
  display: none;
}

.related-note-edit textarea {
  width: 100%;
  resize: vertical;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
}

.related-note-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.related-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 0.2rem;
  flex-shrink: 0;
}

.related-remove:hover {
  color: var(--danger);
}

.related-add-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.9rem;
}

.related-add-row input {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
}

#relatedBookInput {
  flex: 1;
  min-width: 200px;
}

#relatedNoteInput {
  flex: 2;
  min-width: 220px;
}

.author-bio {
  max-width: 640px;
  margin: 1.2rem 0 1.8rem;
}

.author-bio-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 0.4rem;
}

.author-bio-header h2 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin: 0;
}

.author-bio-actions {
  display: flex;
  gap: 0.4rem;
}

.author-bio-actions .btn {
  padding: 0.3rem 0.6rem;
  font-size: 0.78rem;
}

.author-bio-text {
  line-height: 1.55;
  white-space: pre-wrap;
}

.author-bio-text.empty {
  color: var(--text-muted);
  font-style: italic;
}

.author-bio-source {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: 0.3rem;
}

.author-bio-edit textarea {
  width: 100%;
  resize: vertical;
}

.detail-page-author .book-table {
  padding: 0;
  margin-top: 1rem;
}

.book-table-heading {
  margin: 1.6rem 0 0;
  font-size: 1rem;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--overlay);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 3rem 1rem;
  overflow-y: auto;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem 1.75rem;
  width: 100%;
  max-width: 560px;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.9rem;
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-muted);
}

.modal h2 {
  margin-top: 0;
}

.author-add-modal {
  max-width: 420px;
}

.author-add-hint {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin: -0.4rem 0 0.9rem;
}

.empty-state .btn {
  margin-top: 0.8rem;
}

.lookup-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.lookup-row input {
  flex: 1;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.lookup-results {
  display: flex;
  gap: 0.6rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}

.lookup-results:empty {
  margin: 0;
}

.lookup-card {
  flex: 0 0 110px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  cursor: pointer;
  font-size: 0.75rem;
  text-align: center;
}

.lookup-card:hover {
  border-color: var(--accent);
}

.lookup-card img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 4px;
  margin-bottom: 0.3rem;
  background: var(--bg);
}

.lookup-card-meta {
  color: var(--text-muted);
  font-size: 0.68rem;
  margin-top: 0.2rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
  margin-bottom: 0.7rem;
}

.form-grid label,
.full-width {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
  color: var(--text-muted);
  gap: 0.25rem;
  margin-bottom: 0.7rem;
}

.form-grid label[hidden] {
  display: none;
}

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 0.45rem !important;
  align-self: end;
}

.checkbox-label input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
}

.subject-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.btn-small {
  font-size: 0.72rem;
  padding: 0.25rem 0.55rem;
}

.tag-input {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem;
  background: var(--surface);
}

.tag-input:focus-within {
  border-color: var(--accent);
}

.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.tag-chips:not(:empty) {
  margin-bottom: 0.3rem;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.3rem 0.15rem 0.6rem;
  font-size: 0.8rem;
  color: var(--text);
}

.tag-chip-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1;
  padding: 0 0.15rem;
}

.tag-chip-remove:hover {
  color: var(--danger);
}

#subjectInput,
#authorInput {
  border: none;
  padding: 0.3rem 0.1rem;
  width: 100%;
  background: transparent;
}

#subjectInput:focus,
#authorInput:focus {
  outline: none;
}

.tag-suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  margin-top: 0.3rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 260px;
  overflow-y: auto;
  z-index: 10;
}

.tag-suggestion {
  padding: 0.45rem 0.7rem;
  font-size: 0.85rem;
  cursor: pointer;
}

.tag-suggestion:hover {
  background: var(--bg);
  color: var(--accent);
}

input,
select,
textarea {
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
}

.modal-actions-right {
  display: flex;
  gap: 0.5rem;
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
}


/* ---------- timeline ---------- */

.timeline-filters {
  flex-wrap: wrap;
  gap: 0.6rem;
}

.theme-dropdown {
  position: relative;
}

.theme-dropdown-panel {
  position: absolute;
  top: calc(100% + 0.3rem);
  left: 0;
  z-index: 20;
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.6rem;
}

.theme-dropdown-panel[hidden] {
  display: none;
}

.theme-dropdown-panel input[type="text"] {
  width: 100%;
  margin-bottom: 0.5rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
}

.theme-dropdown-list {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.theme-dropdown-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.3rem;
  font-size: 0.83rem;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
}

.theme-dropdown-row:hover {
  background: var(--bg);
}

.theme-dropdown-row span {
  color: var(--text-muted);
  font-size: 0.76rem;
}

.selected-theme-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  flex: 1;
}

.selected-theme-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: 999px;
  padding: 0.25rem 0.4rem 0.25rem 0.7rem;
  font-size: 0.76rem;
}

.selected-theme-chip-swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.selected-theme-chip-remove {
  background: none;
  border: none;
  color: inherit;
  opacity: 0.8;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0 0.15rem;
}

.selected-theme-chip-remove:hover {
  opacity: 1;
}

.timeline-scroll {
  overflow-x: auto;
  padding: 0.5rem 2rem 3rem;
}

.timeline-track {
  position: relative;
}

.timeline-axis-line {
  position: absolute;
  left: 0;
  height: 1px;
  background: var(--border);
}

.timeline-tick {
  position: absolute;
  width: 1px;
  height: 8px;
  background: var(--border);
  transform: translateX(-0.5px);
}

.timeline-tick-label {
  position: absolute;
  transform: translateX(-50%);
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.timeline-item {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
  max-width: 480px;
  overflow: hidden;
}

.timeline-dot {
  flex-shrink: 0;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
}

.timeline-label {
  font-size: 0.72rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-label-author {
  color: var(--text-muted);
}

.timeline-item:hover .timeline-label {
  color: var(--accent);
  text-decoration: underline;
}

.timeline-item:hover .timeline-dot {
  background: var(--accent-hover);
}

.timeline-item-dot-only {
  padding: 3px;
  margin: -3px;
}

.timeline-item-dot-only:hover .timeline-dot {
  transform: scale(1.7);
}

/* ---------- book projects ---------- */

.project-index-list {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 2rem 2rem;
  max-width: 700px;
}

.project-index-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0.5rem;
  text-decoration: none;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.project-index-row:hover {
  background: var(--surface);
}

.project-index-main {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.project-index-name {
  font-weight: 600;
}

.project-index-note {
  color: var(--text-muted);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-index-count {
  color: var(--text-muted);
  font-size: 0.78rem;
  flex-shrink: 0;
}

.detail-projects {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.5rem 0;
}

.add-to-project-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0.5rem 0 1rem;
}

.add-to-project-row select,
.add-to-project-row input {
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.8rem;
}

.add-to-project-row input {
  width: 180px;
}

.project-badge {
  display: inline-block;
  background: var(--surface);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.76rem;
  text-decoration: none;
}

.project-badge:hover {
  background: var(--accent);
  color: var(--accent-contrast);
}

/* ---------- dashboard ---------- */
.dashboard {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem 2rem 3rem;
}

.dashboard-columns {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 2.5rem;
  align-items: start;
}

.dashboard-col-main,
.dashboard-col-side {
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
  min-width: 0;
}

@media (max-width: 900px) {
  .dashboard-columns {
    grid-template-columns: 1fr;
  }
}

.dashboard-section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.dashboard-section-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.dashboard-see-all {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
}

.dashboard-see-all:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* reuse the catalog's own .book-grid/.book-card look; just drop the
   full-page padding since it's nested inside .dashboard's padding already */
.dashboard-books-grid {
  padding: 0;
}

.dashboard-projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.dashboard-project-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  text-decoration: none;
  color: inherit;
}

.dashboard-project-card:hover {
  border-color: var(--accent);
}

.dashboard-project-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

.dashboard-project-count {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.dashboard-project-preview {
  list-style: none;
  margin: 0.3rem 0 0;
  padding-left: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.dashboard-project-preview li {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.dashboard-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 1rem;
}

.dashboard-list li.starred {
  background: var(--starred-bg);
}

.dashboard-list a {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text);
  text-decoration: none;
}

.dashboard-list a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.dashboard-list-meta {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.dashboard-list p {
  margin: 0.3rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

/* ---------- auto-linked URLs inside notes/bios/descriptions ---------- */
.note-link {
  color: var(--accent);
  word-break: break-word;
}

.note-link:hover {
  color: var(--accent-hover);
}

/* ---------- author meta (life years / nationality / genres) ---------- */
.author-meta-block {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin: 0 0 1.2rem;
}

.author-meta-row {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0;
}

.author-meta-edit-btn {
  flex-shrink: 0;
}

.author-meta-row span[hidden] {
  display: none;
}

.author-meta-row span:not([hidden]) ~ span:not([hidden])::before {
  content: " · ";
}

/* ---------- mobile ---------- */
@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.7rem;
    padding: 1rem 1.1rem;
  }

  .topbar-actions {
    flex-wrap: wrap;
    width: 100%;
  }

  .btn {
    white-space: nowrap;
  }

  /* book/author detail: fixed-width cover-beside-info layout doesn't fit
     a phone screen, so stack the cover/photo above the text instead */
  .detail-page {
    padding: 1.25rem 1.1rem;
  }

  .detail-page:has(> .detail-cover),
  .author-header {
    flex-direction: column;
  }

  .detail-cover {
    width: min(220px, 60vw);
    margin: 0 auto;
  }

  .author-photo-column {
    width: min(160px, 50vw);
    margin: 0 auto;
  }

  /* add/edit book modal: a fixed 2-column grid doesn't have room to
     shrink (inputs have their own intrinsic minimum width), which pushed
     the whole modal wider than the screen — collapse to one column */
  .modal-overlay {
    padding: 1.25rem 0.6rem;
  }

  .modal {
    padding: 1.25rem 1.1rem;
  }

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

  .lookup-row {
    flex-wrap: wrap;
  }

  .lookup-row input {
    flex: 1 1 100%;
  }
}

/* ---------- login page ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-card h1 {
  margin: 0 0 0.5rem;
  font-size: 1.4rem;
  text-align: center;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.login-card input[type="password"] {
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.login-card .btn {
  width: 100%;
  text-align: center;
}

.login-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0;
}
