:root {
  --bg: #fafaf8; --fg: #1f2328; --muted: #6b7280; --line: #e5e7eb; --accent: #2563eb; --accent-bg: #eff6ff;
  --card: #fff; --ok: #16a34a; --warn: #d97706; --err: #dc2626;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111418; --fg: #e5e7eb; --muted: #9ca3af; --line: #2a2f36; --accent: #60a5fa; --accent-bg: #1e293b; --card: #181c22; }
}
* { box-sizing: border-box; }
html { font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
body { margin: 0; background: var(--bg); color: var(--fg); }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
header.top { border-bottom: 1px solid var(--line); background: var(--card); }
header.top .wrap { display: flex; align-items: center; justify-content: space-between; height: 52px; }
header.top .brand { font-weight: 600; font-size: 17px; color: var(--fg); }
header.top nav a { margin-left: 16px; }
main.wrap { padding-top: 24px; padding-bottom: 40px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
h1 { font-size: 24px; margin: 0 0 12px; } h2 { font-size: 18px; margin: 20px 0 8px; } h3 { font-size: 15px; margin: 14px 0 6px; }
pre { white-space: pre-wrap; word-break: break-word; background: var(--card); border: 1px solid var(--line); padding: 10px; border-radius: 6px; }
input, select, button, textarea { font: inherit; color: inherit; }
input[type=text], input[type=search], input[type=number], input[type=password], select {
  background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; min-width: 0;
}
button, .btn { background: var(--accent); color: #fff; border: 0; border-radius: 6px; padding: 7px 14px; cursor: pointer; display: inline-block; }
button.secondary, .btn.secondary { background: var(--accent-bg); color: var(--accent); }
button.danger { background: var(--err); }
button:disabled { opacity: .5; cursor: default; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; }
table { border-collapse: collapse; width: 100%; } th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
td.num, th.num { text-align: right; white-space: nowrap; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--accent-bg); color: var(--accent); }
.badge.ok { background: #dcfce7; color: #166534; } .badge.warn { background: #fef3c7; color: #92400e; } .badge.err { background: #fee2e2; color: #991b1b; }
.progress { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .4s; }
.search-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.search-form input[type=search] { flex: 1 1 320px; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; margin-bottom: 14px; }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
.books { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.book { display: flex; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px 10px 40px; position: relative; }
.book .dl-btns { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 12px; }
.btn.outline { background: transparent; color: var(--accent); border: 1px solid var(--accent); padding: 3px 12px; font-size: 12px; border-radius: 5px; }
.btn.outline:hover { background: var(--accent-bg); text-decoration: none; }
.book img, .book .nocover { width: 70px; height: 100px; object-fit: cover; border-radius: 4px; background: var(--line); flex: 0 0 70px; }
.book .nocover { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 24px; }
.book .t { font-weight: 600; } .book .a { color: var(--muted); font-size: 13px; }
.book .s { font-size: 13px; }
.book .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.pager { display: flex; gap: 6px; align-items: center; margin: 14px 0; flex-wrap: wrap; }
.pager a, .pager .cur { display: inline-block; min-width: 30px; text-align: center; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; }
.pager .cur { background: var(--accent); color: #fff; border-color: var(--accent); }
.more { text-align: center; margin: 16px 0; }
.books + .books { margin-top: 12px; }
.bookpage { display: grid; grid-template-columns: 240px 1fr; gap: 24px; }
@media (max-width: 700px) { .bookpage { grid-template-columns: 1fr; } }
.bookpage img { width: 100%; border-radius: 6px; border: 1px solid var(--line); }
.bookpage .nocover { width: 100%; aspect-ratio: 2/3; display: flex; align-items: center; justify-content: center; background: var(--line); border-radius: 6px; color: var(--muted); font-size: 48px; }
.dl { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
.dl .btn.outline { padding: 6px 18px; font-size: 14px; }
.annotation { white-space: pre-wrap; }
.tags a { margin-right: 8px; }
dl.meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 10px 0; }
dl.meta dt { color: var(--muted); } dl.meta dd { margin: 0; }
.admin-nav { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; } @media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }
.htmx-indicator { opacity: 0; transition: opacity .2s; } .htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
.list-cols { columns: 3 240px; column-gap: 24px; } .list-cols a { display: block; padding: 2px 0; }
.letters a { display: inline-block; padding: 2px 6px; margin: 2px; border: 1px solid var(--line); border-radius: 4px; }
.letters a.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.filters[hidden], [hidden] { display: none !important; }

form.inline { display: inline; margin-left: 16px; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; }
button.link:hover { text-decoration: underline; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.stack input { font-size: 15px; }

details.menu { display: inline-block; position: relative; margin-left: 16px; }
details.menu summary { list-style: none; cursor: pointer; color: var(--accent); }
details.menu summary::-webkit-details-marker { display: none; }
details.menu .menu-items { position: absolute; right: 0; top: 28px; min-width: 180px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 6px 0; z-index: 20; display: flex; flex-direction: column; }
details.menu .menu-items a, details.menu .menu-items button.link { display: block; width: 100%; text-align: left; padding: 7px 14px; margin: 0; color: var(--fg); }
details.menu .menu-items a:hover, details.menu .menu-items button.link:hover { background: var(--accent-bg); text-decoration: none; }
details.menu .menu-items form { margin: 0; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }
