/* netlib — no framework, CSS variables, light/dark */

:root {
  --bg: #faf8f5;
  --bg-elev: #ffffff;
  --bg-sunk: #f1ede6;
  --fg: #1f1d1a;
  --fg-muted: #6b665e;
  --fg-faint: #9a948a;
  --line: #e4ded4;
  --accent: #9c4a1a;
  --accent-fg: #ffffff;
  --accent-soft: #f6e7dc;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 14px rgb(0 0 0 / .06);
  --radius: 10px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --font-serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --wrap: 1180px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161514;
    --bg-elev: #1f1e1c;
    --bg-sunk: #121110;
    --fg: #ebe7e0;
    --fg-muted: #a8a196;
    --fg-faint: #757068;
    --line: #2f2d2a;
    --accent: #e39a62;
    --accent-fg: #1a120c;
    --accent-soft: #3a2a1f;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 4px 16px rgb(0 0 0 / .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161514;
  --bg-elev: #1f1e1c;
  --bg-sunk: #121110;
  --fg: #ebe7e0;
  --fg-muted: #a8a196;
  --fg-faint: #757068;
  --line: #2f2d2a;
  --accent: #e39a62;
  --accent-fg: #1a120c;
  --accent-soft: #3a2a1f;
  --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 4px 16px rgb(0 0 0 / .3);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration-color: color-mix(in srgb, currentColor 35%, transparent); text-underline-offset: 2px; }
a:hover { color: var(--accent); }
img { max-width: 100%; }
small { color: var(--fg-faint); font-size: .8em; }
.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 16px; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner { display: flex; align-items: center; gap: 16px; height: 60px; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; letter-spacing: -.01em; color: var(--accent); }
.logo span { color: var(--fg); }
.search { flex: 1; max-width: 560px; }
.search input {
  width: 100%; height: 40px; padding: 0 14px 0 38px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--bg-elev) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%239a948a'%3E%3Cpath d='M10 2a8 8 0 0 1 6.3 12.9l5.4 5.4-1.4 1.4-5.4-5.4A8 8 0 1 1 10 2zm0 2a6 6 0 1 0 0 12 6 6 0 0 0 0-12z'/%3E%3C/svg%3E") 12px 50% / 18px no-repeat;
  color: var(--fg); font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.nav { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.nav a, .icon-link {
  padding: 8px 10px; border-radius: var(--radius-sm); text-decoration: none; color: var(--fg-muted);
  background: none; border: 0; cursor: pointer; display: inline-flex; align-items: center; font: inherit;
}
.nav a:hover, .icon-link:hover { background: var(--bg-sunk); color: var(--fg); }
.nav a[aria-current] { color: var(--fg); font-weight: 600; }
.theme-toggle svg { display: none; }
[data-theme="auto"] .theme-toggle .i-auto,
[data-theme="dark"] .theme-toggle .i-dark,
[data-theme="light"] .theme-toggle .i-light { display: block; }

@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 8px 0; gap: 8px; }
  .logo span { display: none; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .nav a:not(.icon-link) { padding: 6px 8px; }
}

/* ---------------------------------------------------------------- headings */
.results { padding: 24px 0 40px; min-height: 60vh; }
.narrow { max-width: 680px; }
.h1 { font: 700 clamp(1.5rem, 1.2rem + 1.4vw, 2.1rem)/1.15 var(--font-serif); margin: 0 0 16px; letter-spacing: -.01em; }
.h2 { font: 700 1.25rem/1.25 var(--font-serif); margin: 0 0 12px; }
.h2 a { text-decoration: none; }
.h-sub { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--fg-muted); margin: 0 0 10px; font-weight: 600; }
.h-sub small { margin-left: 6px; letter-spacing: 0; text-transform: none; }
.h-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.link-more { color: var(--fg-muted); text-decoration: none; font-size: .95rem; white-space: nowrap; }
.eyebrow { display: inline-block; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); margin-bottom: 4px; text-decoration: none; font-weight: 600; }
.meta { color: var(--fg-muted); font-size: .92rem; }
.block { margin: 0 0 32px; }
.empty { color: var(--fg-muted); padding: 24px 0; }
.muted { color: var(--fg-faint); }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .h1 { margin-bottom: 6px; }

/* ---------------------------------------------------------------- covers */
.cover {
  display: block; width: 100%; height: auto; aspect-ratio: 2 / 3; object-fit: cover;
  border-radius: 4px; background: var(--bg-sunk);
  box-shadow: 0 1px 2px rgb(0 0 0 / .12), 0 2px 8px rgb(0 0 0 / .08);
}

/* ---------------------------------------------------------------- card grid */
.grid {
  display: grid; gap: 22px 18px;
  grid-template-columns: repeat(auto-fill, minmax(138px, 1fr));
}
@media (max-width: 480px) { .grid { grid-template-columns: repeat(2, 1fr); gap: 18px 14px; } }
.card { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.card-cover { display: block; transition: transform .15s; }
.card-cover:hover { transform: translateY(-2px); }
.card-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.card-title {
  font-weight: 600; line-height: 1.3; text-decoration: none; font-size: .95rem;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-author, .card-series {
  font-size: .85rem; color: var(--fg-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-author a, .card-series { text-decoration: none; }
.card-series { color: var(--fg-faint); }
.num { color: var(--fg-faint); font-variant-numeric: tabular-nums; font-weight: 500; }

.more { grid-column: 1 / -1; display: flex; justify-content: center; padding: 12px 0; }
.more.htmx-request .btn { opacity: .5; pointer-events: none; }

/* ---------------------------------------------------------------- rows */
.rows { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.row { display: grid; grid-template-columns: 44px 1fr auto; gap: 14px; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.row:hover { background: var(--bg-elev); }
.row-cover .cover { width: 44px; border-radius: 3px; }
.row-title { font-weight: 600; text-decoration: none; line-height: 1.3; }
.row-body .meta { font-size: .85rem; margin-top: 2px; }

.toc { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 24px; }
.toc a { padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; font-size: .9rem; background: var(--bg-elev); }
.toc a:hover { border-color: var(--accent); }

/* ---------------------------------------------------------------- chips */
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: baseline; gap: 8px; padding: 7px 14px;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 999px;
  text-decoration: none; transition: border-color .15s;
}
.chip:hover { border-color: var(--accent); color: inherit; }
.chip span { font-weight: 600; }
.chip em { font-style: normal; color: var(--fg-muted); font-size: .85rem; }

/* ---------------------------------------------------------------- book page */
.book { display: grid; grid-template-columns: minmax(180px, 280px) 1fr; gap: 36px; margin-bottom: 40px; }
@media (max-width: 720px) {
  .book { grid-template-columns: 1fr; gap: 20px; }
  .book-cover { max-width: 200px; margin: 0 auto; }
}
.book-cover .cover { border-radius: 6px; box-shadow: var(--shadow), 0 12px 32px rgb(0 0 0 / .14); }
.book-title { margin-bottom: 8px; }
.book-authors { font-size: 1.1rem; margin-bottom: 20px; }
.book-authors a { text-decoration: none; color: var(--fg-muted); }
.book-authors a:hover { color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 24px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; margin: 0 0 24px; font-size: .95rem; }
.facts dt { color: var(--fg-faint); }
.facts dd { margin: 0; }
.annotation { font: 1.05rem/1.65 var(--font-serif); max-width: 68ch; }
.annotation p { margin: 0 0 .8em; }
.notice { padding: 10px 14px; background: var(--bg-sunk); border-radius: var(--radius-sm); color: var(--fg-muted); }

.strip { display: grid; grid-auto-flow: column; grid-auto-columns: 128px; gap: 16px; overflow-x: auto; padding: 4px 2px 12px; scroll-snap-type: x proximity; }
.strip-item { scroll-snap-align: start; }
.strip-item.current .cover { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-elev);
  color: var(--fg); font: inherit; font-weight: 600; font-size: .95rem; text-decoration: none; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--fg-faint); color: var(--fg); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { filter: brightness(1.08); color: var(--accent-fg); border-color: var(--accent); }
.btn-ghost { background: transparent; }
.btn-icon { width: 36px; height: 36px; padding: 0; justify-content: center; color: var(--fg-muted); }
.btn[disabled] { opacity: .5; cursor: progress; }

/* ---------------------------------------------------------------- genres */
.genres { columns: 3 300px; column-gap: 32px; }
.genre-section { break-inside: avoid; margin: 0 0 14px; background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); }
.genre-section summary { cursor: pointer; padding: 12px 16px; font-weight: 600; display: flex; justify-content: space-between; list-style: none; }
.genre-section summary::-webkit-details-marker { display: none; }
.genre-section ul { list-style: none; margin: 0; padding: 0 16px 12px; }
.genre-section li { padding: 3px 0; display: flex; justify-content: space-between; gap: 8px; }
.genre-section li a { text-decoration: none; }

/* ---------------------------------------------------------------- settings */
.settings fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; margin: 0 0 18px; background: var(--bg-elev); }
.settings legend { font-weight: 700; padding: 0 6px; }
.check { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; }
.check input { accent-color: var(--accent); width: 18px; height: 18px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 16px; margin-top: 6px; }
.hint { color: var(--fg-muted); font-size: .9rem; }

/* ---------------------------------------------------------------- misc */
.footer { padding: 24px 16px 40px; color: var(--fg-faint); font-size: .85rem; border-top: 1px solid var(--line); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20;
  background: var(--fg); color: var(--bg); padding: 10px 18px; border-radius: 999px; box-shadow: var(--shadow);
  font-size: .95rem; max-width: calc(100vw - 32px);
}
.htmx-request.search input { background-image: none; }

/* ---------------------------------------------------------------- views & selection */
.list-head { margin-bottom: 12px; flex-wrap: wrap; }
.list-head .h1, .list-head .h-sub { margin-bottom: 0; }
.list-tools { display: flex; align-items: center; gap: 10px; }
.page-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.btn-sm { height: 34px; padding: 0 12px; font-size: .9rem; }

.view-switch { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-elev); }
.vs-btn { border: 0; background: none; color: var(--fg-faint); width: 36px; height: 34px; display: grid; place-items: center; cursor: pointer; }
.vs-btn + .vs-btn { border-left: 1px solid var(--line); }
.vs-btn:hover { color: var(--fg); }
.vs-btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }

/* checkbox: hidden on cards until hover / selection mode, always on rows */
.pick { display: grid; place-items: center; cursor: pointer; }
.pick input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.card { position: relative; }
.card .pick {
  position: absolute; top: 6px; left: 6px; z-index: 1; width: 30px; height: 30px;
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent); border-radius: 6px;
  box-shadow: 0 1px 3px rgb(0 0 0 / .2); opacity: 0; transition: opacity .12s;
}
.card:hover .pick, .card .pick:focus-within, body.selecting .card .pick, .card.picked .pick { opacity: 1; }
@media (hover: none) { body.selecting .card .pick { opacity: 1; } }
.card.picked .cover { outline: 3px solid var(--accent); outline-offset: 2px; }

.row { grid-template-columns: 28px 44px 1fr auto; }
.row-compact { grid-template-columns: 28px 1fr auto; padding: 7px 4px; }
.row.picked { background: var(--accent-soft); }
.rows-flat { border-top: 1px solid var(--line); }
.rows-more { border-top: 0; }
.meta-author a { color: var(--fg-muted); text-decoration: none; }
.meta a { text-decoration: none; }
.meta a:hover { color: var(--accent); }
.more[data-list] { padding-top: 16px; }

.selbar {
  position: sticky; bottom: 0; z-index: 15;
  background: color-mix(in srgb, var(--bg-elev) 94%, transparent); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgb(0 0 0 / .08);
}
.selbar-inner { display: flex; align-items: center; gap: 8px; min-height: 58px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.selbar-spacer { flex: 1; }
.selbar-count { margin-right: 6px; }
@media (max-width: 560px) { #sel-show { display: none; } .selbar-count { font-size: .9rem; } }

/* ---------------------------------------------------------------- admin */
.admin .stats-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; }
.stat b { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--fg-muted); font-size: .85rem; }
.panel { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin: 0 0 14px; }
.panel-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 12px; }
.panel-title { margin: 0 0 4px; font-size: 1.15rem; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.panel-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.panel-actions form { margin: 0; }
.facts-inline { grid-template-columns: repeat(auto-fill, minmax(130px, auto) minmax(140px, 1fr)); margin: 0; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .85em; }
.nowrap { white-space: nowrap; }
.warn { color: #b7791f; }
.error-text { color: #c0392b; font-size: .88rem; margin: 6px 0 0; }
:root[data-theme="dark"] .error-text { color: #ff8a7a; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--bg-sunk); color: var(--fg-muted); border: 1px solid var(--line); }
.badge-ok, .badge-done { background: #e3f4e8; color: #23733f; border-color: #c4e6cf; }
.badge-running, .badge-scanning { background: #e4eefc; color: #2457a6; border-color: #c8daf6; }
.badge-paused, .badge-queued { background: #fdf3dc; color: #8a6111; border-color: #f2e0b5; }
.badge-offline, .badge-error, .badge-failed { background: #fbe5e2; color: #a63326; border-color: #f2c9c3; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge { filter: saturate(.8) brightness(.85); } }
:root[data-theme="dark"] .badge { filter: saturate(.8) brightness(.85); }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--fg-muted); background: var(--bg-sunk); }
.table tr:last-child td { border-bottom: 0; }
.job-detail { color: var(--fg-muted); max-width: 520px; }
.history { margin-top: 12px; }
.history summary { cursor: pointer; color: var(--fg-muted); padding: 6px 0; }
.form-grid { display: grid; grid-template-columns: 1fr 2fr auto; gap: 12px; align-items: end; margin-top: 12px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--fg-muted); }
.form-grid input, .form-grid select { height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); color: var(--fg); font: inherit; }
@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr; } .table { font-size: .85rem; } .job-detail { max-width: none; } }
.add-source summary { cursor: pointer; font-weight: 600; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .88em; background: var(--bg-sunk); padding: 1px 5px; border-radius: 4px; }
.covers-form { grid-template-columns: auto auto 1fr auto; align-items: center; }
@media (max-width: 720px) { .covers-form { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 12px; color: var(--fg-muted); font-size: .9rem; }
.field input { height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg); color: var(--fg); font: inherit; }
.user-chip { font-size: .85rem; color: var(--fg-muted); padding: 0 6px; }
.logout-form { margin: 0; }
