:root {
  --bg: #14161a; --panel: #1c1f26; --panel2: #232733; --line: #2e3341;
  --text: #e6e8ee; --muted: #9aa2b1; --accent: #6ea8fe; --accent2: #3d7cf0;
  --ok: #57c98a; --warn: #f0a35e; --err: #ef6f6f; --radius: 10px;
}
:root[data-theme="light"] {
  --bg: #f6f5f1; --panel: #fffdf9; --panel2: #efece4; --line: #ddd8cc;
  --text: #23201a; --muted: #6b675d; --accent: #2f6fd0; --accent2: #2f6fd0;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button {
  background: var(--accent2); color: #fff; border: 0; border-radius: 8px;
  padding: .5rem .9rem; font-size: 15px; cursor: pointer;
}
button:hover { background: var(--accent); }
button:disabled { opacity: .55; cursor: default; }
input, select {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: .45rem .6rem; font-size: 15px;
}
code { background: var(--panel2); padding: .1rem .35rem; border-radius: 5px; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 1.2rem; padding: .7rem 1.2rem;
  background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 1.05rem; }
.topbar nav { display: flex; gap: 1rem; }
.topbar .search { margin-left: auto; }
.topbar .search input { width: min(360px, 60vw); }
.topbar .logout { display: flex; align-items: center; gap: .6rem; }
.topbar .who { color: var(--muted); font-size: .9rem; }
.topbar .logout button { background: transparent; border: 1px solid var(--line); }

.container { max-width: 1180px; margin: 0 auto; padding: 1.3rem 1.2rem 4rem; }

/* ---- toolbar / stats ---- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.stats { color: var(--muted); }
.stats b { color: var(--text); }
.warn { color: var(--warn); }
.ok { color: var(--ok); }

/* ---- book grid ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1.1rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.card .cover { display: block; aspect-ratio: 2/3; background: var(--panel2); }
.card .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.nocover { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; font-size: 3rem; color: var(--muted); }
.nocover.big { font-size: 5rem; }
.card .meta { padding: .55rem .6rem .7rem; }
.card .title { font-weight: 600; display: block; }
.card .authors, .card .series { font-size: .82rem; color: var(--muted); margin-top: .2rem; }
/* clamp very long author lists (omnibuses) to keep cards uniform */
.card .authors { display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
/* collapsible author list on the detail page */
.authors-collapse summary { cursor: pointer; color: var(--accent); list-style: none; }
.authors-collapse summary::-webkit-details-marker { display: none; }
.authors-collapse[open] summary { margin-bottom: .3rem; }
.panel form label { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .7rem; font-size: .9rem; color: var(--muted); }
.panel form input { font-size: 1rem; }

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

/* ---- pager ---- */
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; margin: 1.6rem 0; color: var(--muted); }

/* ---- detail ---- */
.detail { display: grid; grid-template-columns: 260px 1fr; gap: 1.8rem; }
.detail-cover img, .detail-cover .nocover { width: 100%; border-radius: var(--radius); background: var(--panel2); }
.detail-body h1 { margin: 0 0 .8rem; }
.detail .line { margin: .35rem 0; }
.detail .k { color: var(--muted); margin-right: .4rem; }
.meta-small { color: var(--muted); font-size: .9rem; }
.tag { display: inline-block; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: .1rem .5rem; margin: 0 .3rem .3rem 0; font-size: .85rem; }
.actions { margin: 1.1rem 0; }
.btn { display: inline-block; background: var(--accent2); color: #fff; padding: .55rem 1rem; border-radius: 8px; }
.btn:hover { background: var(--accent); text-decoration: none; }
.annotation { color: #d3d7e0; }
.annotation p { margin: .5rem 0; }

/* ---- browse lists ---- */
.browse-list { list-style: none; padding: 0; columns: 2; }
.browse-list li { break-inside: avoid; padding: .25rem 0; }
.browse-list .count { color: var(--muted); font-size: .82rem; margin-left: .3rem; }

/* ---- scan ---- */
.muted { color: var(--muted); }
.scan-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-top: 1rem; max-width: 640px; }
.scan-head { display: flex; gap: .6rem; align-items: center; margin-bottom: .6rem; }
.badge { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: .1rem .5rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.status-done .badge { color: var(--ok); }
.status-error .badge { color: var(--err); }
.status-running .badge { color: var(--accent); }
.progress { height: 10px; background: var(--panel2); border-radius: 6px; overflow: hidden; }
.progress .bar { height: 100%; background: var(--accent2); transition: width .3s; }
.scan-counts { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: .6rem; color: var(--muted); font-size: .9rem; }

/* ---- login ---- */
.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 2rem; width: min(360px, 92vw); display: flex; flex-direction: column; gap: .9rem; }
.login-card h1 { margin: 0 0 .5rem; text-align: center; }
.login-card label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; color: var(--muted); }
.login-card input { font-size: 1rem; }
.error { color: var(--err); margin: 0; }

/* ---- admin panels (authors/genres) ---- */
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 1rem 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1.2rem; }
.panel h2 { margin: 0 0 .7rem; font-size: 1.05rem; }
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 160px; }
button.small { padding: .3rem .6rem; font-size: .85rem; }
button.ok-btn { background: var(--ok); }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); }
.data-table th { color: var(--muted); font-weight: 600; font-size: .85rem; }
.data-table.wide td { vertical-align: middle; }
.decision { display: flex; gap: .5rem; }
.decision form { display: inline; }
.sep { border: 0; border-top: 1px solid var(--line); margin: 2rem 0; }

/* ---- genre category cards ---- */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .8rem; }
.cat-card { display: flex; justify-content: space-between; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; }
.cat-card:hover { border-color: var(--accent2); text-decoration: none; }
.cat-name { font-weight: 600; color: var(--text); }
.cat-count { color: var(--muted); font-size: .85rem; }

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

/* ---- random books block ---- */
.random-block { margin-bottom: 1.6rem; padding-bottom: 1.2rem; border-bottom: 1px solid var(--line); }
.random-head { display: flex; align-items: baseline; justify-content: space-between; }
.random-head h2 { margin: .2rem 0 .8rem; }
.refresh-link { font-size: .9rem; }

/* ---- collect chips (add to collection) ---- */
.collect { margin: 1rem 0; display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.chip { display: inline-block; background: var(--panel2); color: var(--text); border: 1px solid var(--line);
        border-radius: 999px; padding: .25rem .7rem; font-size: .85rem; cursor: pointer; }
.chip:hover { border-color: var(--accent2); text-decoration: none; }
.chip-on { background: var(--accent2); color: #fff; border-color: var(--accent2); }
.chip-new { color: var(--muted); }
.share-list { list-style: none; padding: 0; margin: .7rem 0 0; }
.share-list li { padding: .2rem 0; }

/* ---- reader ---- */
.reader-body { background: var(--bg); }
.reader-bar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem;
  padding: .5rem 1rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.rb-back { font-size: 1.3rem; text-decoration: none; }
.rb-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.rb-controls { display: flex; align-items: center; gap: .4rem; }
.rb-controls button { background: var(--panel2); color: var(--text); border: 1px solid var(--line); padding: .3rem .6rem; border-radius: 6px; }
.rb-progress { color: var(--muted); font-size: .85rem; min-width: 3ch; text-align: right; }

.reader-content {
  max-width: 40rem; margin: 0 auto; padding: 2rem 1.3rem 6rem;
  font-size: 20px; line-height: 1.65; color: var(--text);
  font-family: system-ui, "Segoe UI", sans-serif;
}
.reader-content.serif { font-family: Georgia, "Times New Roman", serif; }
.reader-content p { margin: 0 0 .9em; text-align: justify; text-indent: 1.4em; }
.reader-content .fb2-title { margin: 2em 0 1em; text-align: center; }
.reader-content .fb2-title h3 { margin: .2em 0; text-indent: 0; }
.reader-content h4.subtitle { text-align: center; text-indent: 0; margin: 1.4em 0 .8em; color: var(--muted); }
.reader-content .empty-line { height: 1em; }
.reader-content .epigraph, .reader-content .cite { margin: 1.2em 2em; font-style: italic; color: var(--muted); border-left: 2px solid var(--line); padding-left: 1em; }
.reader-content .epigraph p, .reader-content .cite p { text-indent: 0; text-align: left; }
.reader-content .text-author { text-indent: 0; text-align: right; font-style: italic; color: var(--muted); }
.reader-content .poem { margin: 1.2em 1.5em; }
.reader-content .stanza { margin: 0 0 1em; }
.reader-content .v { text-indent: 0; text-align: left; margin: 0; }
.reader-content .fb2-image { display: block; max-width: 100%; margin: 1.2em auto; }
.reader-content .note-ref { font-size: .75em; vertical-align: super; text-decoration: none; padding: 0 .15em; }
.reader-content .notes .note { font-size: .9em; color: var(--muted); margin: .8em 0; }
.reader-content .notes-title { text-align: center; }

@media (max-width: 700px) {
  .detail { grid-template-columns: 1fr; }
  .detail-cover { max-width: 220px; }
  .browse-list { columns: 1; }
  .admin-grid { grid-template-columns: 1fr; }
  .rb-title { display: none; }
}
