:root {
  --bg: #15191e;
  --bg-card: #1e2329;
  --bg-input: #262b33;
  --bg-hover: #2a3040;
  --text: #e4e8ee;
  --text-dim: #8d95a2;
  --accent: #0dbd8b;
  --accent-hover: #0aa87a;
  --border: #2e3440;
  --danger: #ff5b55;
  --tag-bg: #2a3040;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

/* ── Layout ──────────────────────────── */

.app {
  max-width: 600px;
  margin: 0 auto;
  padding: 12px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

header h1 {
  font-size: 16px;
  font-weight: 600;
}

.stats-bar {
  font-size: 12px;
  color: var(--text-dim);
}

/* ── Search ──────────────────────────── */

.search-box {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search-box input {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .2s;
}

.search-box input:focus {
  border-color: var(--accent);
}

.search-box input::placeholder {
  color: var(--text-dim);
}

/* ── Buttons ─────────────────────────── */

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

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

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-download {
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-download:hover:not(:disabled) {
  background: var(--accent-hover);
}

/* ── Tabs ────────────────────────────── */

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}

.tab {
  padding: 6px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  transition: all .15s;
}

.tab:hover { color: var(--text); background: var(--bg-hover); }
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Cards ───────────────────────────── */

.results { flex: 1; }

.book-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}

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

.book-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.book-meta {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.book-meta span { display: inline-flex; align-items: center; gap: 3px; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  background: var(--tag-bg);
  border-radius: 12px;
  font-size: 11px;
  color: var(--text-dim);
}

/* ── Book detail ─────────────────────── */

.book-detail {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.book-detail h2 {
  font-size: 18px;
  margin-bottom: 8px;
}

.book-detail .meta-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.book-detail .annotation {
  background: var(--bg-input);
  border-radius: var(--radius);
  padding: 10px;
  font-size: 13px;
  color: var(--text-dim);
  margin: 10px 0;
  max-height: 200px;
  overflow-y: auto;
}

.book-detail .actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.link-btn {
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  background: none;
  border: none;
  text-decoration: underline;
}

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

/* ── Author/Genre list ───────────────── */

.entity-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: border-color .15s;
}

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

.entity-name { font-weight: 500; }

.entity-count {
  font-size: 12px;
  color: var(--text-dim);
}

/* ── Pagination ──────────────────────── */

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
}

.pagination .page-info {
  font-size: 13px;
  color: var(--text-dim);
}

/* ── Breadcrumbs ─────────────────────── */

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--text-dim);
}

.breadcrumbs .bc-link {
  color: var(--accent);
  cursor: pointer;
}

.breadcrumbs .bc-link:hover { text-decoration: underline; }
.breadcrumbs .bc-sep { color: var(--text-dim); }

/* ── Loading / Empty ─────────────────── */

.loading, .empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 12px;
}

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

.empty-state p { font-size: 14px; }

/* ── Toast notifications ─────────────── */

.toast-container {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: slideIn .3s ease;
}

.toast.success { border-color: var(--accent); }
.toast.error { border-color: var(--danger); color: var(--danger); }

@keyframes slideIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ──────────────────────── */

@media (max-width: 480px) {
  .app { padding: 8px; }
  .book-detail h2 { font-size: 16px; }
  .search-box { flex-direction: column; }
}
