/* CSS variables — theme */
:root {
  --bg: #f5f5f0;
  --surface: #ffffff;
  --surface2: #f0ede8;
  --border: #ddd9d0;
  --accent: #5b4fcf;
  --accent2: #7c6af7;
  --text: #1a1a2e;
  --muted: #6b6880;
}
html.dark {
  --bg: #0f1117;
  --surface: #141720;
  --surface2: #1a1d27;
  --border: #2e3248;
  --text: #e2e8f0;
  --muted: #8892a4;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
}

/* Header */
.header {
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface2) 100%);
  border-bottom: 1px solid var(--border);
  padding: 20px 32px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .06);
}
.header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Theme toggle button */
.theme-btn {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: .8rem;
  font-family: inherit;
  transition: border-color .15s;
}
.theme-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Stats */
.stats-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 32px;
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}
.stat { display: flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); }
.stat strong { color: var(--text); }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

/* Controls */
.controls {
  padding: 16px 32px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.search-wrap { flex: 1; min-width: 180px; max-width: 380px; position: relative; }
.search-wrap input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 14px 9px 38px;
  border-radius: 8px;
  font-size: .88rem;
  outline: none;
  transition: border-color .2s;
}
.search-wrap input:focus { border-color: var(--accent); }
.search-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }

select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: .88rem;
  outline: none;
  cursor: pointer;
}
select:focus { border-color: var(--accent); }

.view-buttons { margin-left: auto; display: flex; gap: 4px; }
.view-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 7px 11px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  transition: all .15s;
}
.view-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Layout */
.result-info { padding: 8px 32px; font-size: .82rem; color: var(--muted); border-bottom: 1px solid var(--border); }
.content { padding: 20px 32px; }

/* Author group */
.author-group { margin-bottom: 28px; }
.author-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--border);
}
.author-name { font-size: .95rem; font-weight: 600; color: var(--accent); }
.author-count {
  background: var(--surface2);
  color: var(--muted);
  font-size: .72rem;
  padding: 2px 7px;
  border-radius: 10px;
}

/* Book grid (card view) */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.book-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 12px;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
  transition: all .18s;
  position: relative;
}
.book-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 6px 20px rgba(91, 79, 207, .12); }
.book-cover {
  background: var(--surface2);
  border-radius: 5px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
}
.book-title {
  font-size: .80rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-meta { display: flex; justify-content: space-between; align-items: center; margin-top: auto; }
.book-size { font-size: .68rem; color: var(--muted); }

/* Format tags */
.fmt {
  font-size: .68rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.fmt-pdf { background: rgba(220, 38, 38, .12); color: #b91c1c; }
.fmt-epub { background: rgba(21, 128, 61, .12); color: #166534; }
.fmt-mobi, .fmt-azw, .fmt-azw3 { background: rgba(180, 83, 9, .12); color: #92400e; }
.fmt-docx, .fmt-txt { background: rgba(71, 85, 105, .12); color: #475569; }

/* Book list (row view) */
.book-list { display: none; flex-direction: column; gap: 3px; }
.book-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 14px;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all .15s;
}
.book-row:hover { border-color: var(--accent); background: var(--surface2); }
.book-row .fmt { flex-shrink: 0; min-width: 38px; text-align: center; }
.row-title { flex: 1; font-size: .84rem; font-weight: 500; color: var(--text); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.row-author { width: 160px; flex-shrink: 0; font-size: .77rem; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.row-size { width: 55px; flex-shrink: 0; font-size: .75rem; color: var(--muted); text-align: right; }

body.list-view .book-grid { display: none; }
body.list-view .book-list { display: flex; }

.no-results { text-align: center; padding: 60px; color: var(--muted); font-size: 1.1rem; }

/* Scroll-to-top */
.scroll-top {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 42px;
  height: 42px;
  font-size: 1.1rem;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(91, 79, 207, .35);
}
.scroll-top.visible { display: flex; }

/* Reader overlay */
#reader {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 300;
  overflow-y: auto;
  background: var(--bg);
  color: var(--text);
}
#reader.open { display: block; }
#reader-nav {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 32px;
  display: flex;
  gap: 12px;
  align-items: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .06);
}
.reader-back {
  background: none;
  border: 1px solid var(--border);
  color: var(--accent);
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: .83rem;
  font-family: inherit;
  flex-shrink: 0;
}
.reader-back:hover { border-color: var(--accent2); }
#reader-title { flex: 1; font-size: .9rem; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#reader-content {
  max-width: 820px;
  margin: 0 auto;
  padding: 32px 24px;
  font-family: 'Georgia', serif;
  line-height: 1.85;
}
#reader-content h1 { color: var(--accent); font-size: 1.3rem; border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 6px; }
#reader-content h2, #reader-content h3, #reader-content h4 { color: var(--text); }
#reader-content a { color: var(--accent); }
#reader-content pre {
  white-space: pre-wrap;
  font-family: 'Georgia', serif;
  font-size: .93rem;
  background: var(--surface2);
  color: var(--text);
  padding: 12px;
  border-radius: 6px;
}
#reader-content code { background: var(--surface2); color: var(--text); }
#reader-content blockquote { border-left: 3px solid var(--accent); padding-left: 16px; color: var(--muted); }
#reader-content table { border-collapse: collapse; width: 100%; }
#reader-content td, #reader-content th { border: 1px solid var(--border); padding: 6px 10px; }
#reader-content th { background: var(--surface2); }
#reader-content img { max-width: 100%; border-radius: 6px; }

/* Responsive */
@media (max-width: 600px) {
  .header, .controls, .stats-bar, .content { padding-left: 14px; padding-right: 14px; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .row-author, .row-size { display: none; }
  #reader-nav { padding: 10px 14px; }
  #reader-content { padding: 20px 14px; }
}
