:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #ece7dc;
  --surface-3: #e3dccd;
  --border: #ddd5c6;
  --text: #1f1b15;
  --muted: #6e665a;
  --faint: #a59d8f;
  --accent: #2f5d50;
  --accent-hover: #264d42;
  --accent-ink: #ffffff;
  --accent-soft: #dce8e2;
  --mark: #ffe39a;
  --danger: #a8402e;
  --want: #b7791f;
  --reading: #2c6aa8;
  --done: #2f855a;
  --shadow-sm: 0 1px 2px rgba(48, 36, 12, .07);
  --shadow: 0 1px 2px rgba(48, 36, 12, .06), 0 8px 24px rgba(48, 36, 12, .08);
  --shadow-lg: 0 12px 48px rgba(30, 22, 8, .22);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, Cambria, serif;
  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --radius: 10px;
  --top: 60px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151412; --surface: #1d1c19; --surface-2: #26241f; --surface-3: #302d27; --border: #36322b;
    --text: #ece6da; --muted: #a59d8f; --faint: #6f685d; --accent: #82c2ac; --accent-hover: #9bd3bf;
    --accent-ink: #0f1f1a; --accent-soft: #233630; --mark: #6b5513; --danger: #e07a64;
    --want: #e0a84a; --reading: #6aa8e6; --done: #6cc196;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
    --shadow-lg: 0 12px 48px rgba(0,0,0,.6); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151412; --surface: #1d1c19; --surface-2: #26241f; --surface-3: #302d27; --border: #36322b;
  --text: #ece6da; --muted: #a59d8f; --faint: #6f685d; --accent: #82c2ac; --accent-hover: #9bd3bf;
  --accent-ink: #0f1f1a; --accent-soft: #233630; --mark: #6b5513; --danger: #e07a64;
  --want: #e0a84a; --reading: #6aa8e6; --done: #6cc196;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  --shadow-lg: 0 12px 48px rgba(0,0,0,.6); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
.ic { width: 18px; height: 18px; flex: none; }
[hidden] { display: none !important; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--text) 18%, transparent); border-radius: 10px;
  border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background-color: color-mix(in srgb, var(--text) 32%, transparent); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--top); display: flex; align-items: center; gap: 16px;
  padding: 0 20px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font: 600 19px/1 var(--serif); white-space: nowrap; width: 270px; }
.brand svg { width: 26px; height: 26px; }
.brand .b1 { fill: var(--accent); } .brand .b2 { fill: var(--want); } .brand .b3 { fill: var(--danger); }
.search { flex: 1; display: flex; align-items: center; gap: 8px; max-width: 720px; height: 40px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; box-shadow: var(--shadow-sm); }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-ic { color: var(--faint); display: flex; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 15px; }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.search kbd { font: 12px var(--sans); color: var(--faint); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; }
.toolbar { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.toolbar select { height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.icon-btn { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); color: var(--muted); }
.icon-btn:hover { color: var(--text); background: var(--surface-2); }
.icon-btn.spin .ic { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { width: 36px; height: 34px; border: 0; background: transparent; color: var(--muted); display: flex; align-items: center; justify-content: center; }
.seg button.on { background: var(--accent-soft); color: var(--accent); }
.progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; overflow: hidden; opacity: 0; transition: opacity .3s; }
.progress.on { opacity: 1; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.only-narrow { display: none; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 290px 1fr; min-height: calc(100vh - var(--top)); }
.sidebar { position: sticky; top: var(--top); height: calc(100vh - var(--top)); overflow-y: auto; padding: 18px 16px 18px 20px;
  border-right: 1px solid var(--border); scrollbar-width: thin; }
.main { padding: 18px 28px 60px; min-width: 0; }

/* ---------- filters ---------- */
.facet { padding: 4px 0 18px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.facet:last-of-type { border-bottom: 0; }
.facet-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.facet h4 { margin: 0; font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.link { border: 0; background: none; padding: 0; color: var(--accent); font-size: 12.5px; }
.link:hover { text-decoration: underline; }
.year-caption { font: 600 17px/1.2 var(--serif); margin-bottom: 8px; }
.year-caption small { font: 12px var(--sans); color: var(--muted); font-weight: 400; margin-left: 4px; }
.hist { display: flex; align-items: flex-end; gap: 2px; height: 74px; padding-bottom: 1px; border-bottom: 1px solid var(--border);
  user-select: none; touch-action: none; cursor: crosshair; }
.hist .bar { flex: 1; min-width: 3px; height: 100%; display: flex; align-items: flex-end; position: relative; }
.hist .bar i { display: block; width: 100%; min-height: 2px; border-radius: 2px 2px 0 0; background: var(--surface-3); transition: background .15s, height .25s; }
.hist .bar.has i { background: color-mix(in srgb, var(--accent) 45%, var(--surface-3)); }
.hist .bar.sel i { background: var(--accent); }
.hist .bar:hover i { background: var(--accent-hover); }
.hist .bar.unknown { margin-left: 6px; flex: 0 0 14px; }
.hist .bar.unknown i { background-image: repeating-linear-gradient(45deg, transparent 0 3px, rgba(255,255,255,.35) 3px 5px); }
.hist-tip { position: fixed; z-index: 50; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12px;
  padding: 4px 8px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -130%); }
.year-inputs { display: flex; gap: 10px; margin-top: 10px; color: var(--muted); font-size: 13px; }
.year-inputs label { display: flex; align-items: center; gap: 6px; flex: 1; }
.year-inputs input { width: 100%; min-width: 0; height: 30px; padding: 0 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); }
.year-inputs input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.presets button, .chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 3px 10px; font-size: 12.5px; color: var(--text); }
.presets button:hover, .chip:hover { border-color: var(--accent); }
.presets button.on, .chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip .n { color: var(--faint); margin-left: 3px; font-size: 11.5px; }
.chip.on .n { color: inherit; opacity: .75; }
.chip.zero { opacity: .45; }
.opts { display: flex; flex-direction: column; gap: 1px; }
.opt { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: transparent; text-align: left; padding: 5px 8px;
  border-radius: 7px; color: var(--text); }
.opt:hover { background: var(--surface-2); }
.opt .box { width: 15px; height: 15px; border: 1.5px solid var(--faint); border-radius: 4px; flex: none; display: flex; align-items: center; justify-content: center; }
.opt.on .box { background: var(--accent); border-color: var(--accent); }
.opt.on .box::after { content: ""; width: 7px; height: 4px; border: 2px solid var(--accent-ink); border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.opt .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opt .n, .check .n { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.opt.zero { opacity: .45; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.want { background: var(--want); } .dot.reading { background: var(--reading); } .dot.done { background: var(--done); } .dot.none { border: 1.5px solid var(--faint); }
.check { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; }
.check span:nth-child(2) { flex: 1; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.side-foot { color: var(--muted); font-size: 12.5px; line-height: 1.6; padding-top: 4px; }

/* ---------- results bar ---------- */
.resultbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; margin-bottom: 18px; min-height: 30px; }
.count { font: 600 20px/1.2 var(--serif); }
.count small { font: 13px var(--sans); color: var(--muted); margin-left: 6px; }
.active { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.active .chip { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.active .chip .ic { width: 13px; height: 13px; }
.scanline { display: flex; align-items: center; gap: 10px; margin: -6px 0 16px; padding: 9px 12px; border-radius: 8px; background: var(--surface);
  border: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.scanline b { color: var(--text); font-weight: 600; }
.scanline .file { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }

/* ---------- cover grid ---------- */
.results.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 26px 20px; }
.card { cursor: pointer; outline: 0; min-width: 0; }
.cover { position: relative; aspect-ratio: 2 / 3; border-radius: 6px; overflow: hidden; background: var(--surface-2);
  box-shadow: var(--shadow); transition: transform .18s ease, box-shadow .18s ease; }
.card:hover .cover, .card:focus-visible .cover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.card:focus-visible .cover { outline: 3px solid var(--accent); outline-offset: 2px; }
.cover img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.cover::after { content: ""; position: absolute; inset: 0 auto 0 0; width: 7px; background: linear-gradient(90deg, rgba(0,0,0,.18), transparent); pointer-events: none; }
.ph { width: 100%; height: 100%; padding: 16px 14px; display: flex; flex-direction: column; justify-content: space-between;
  background: linear-gradient(160deg, hsl(var(--h) 38% 42%), hsl(calc(var(--h) + 30) 42% 26%)); color: #fff; }
.ph .t { font: 600 15px/1.25 var(--serif); display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; text-wrap: balance; }
.ph .a { font-size: 11.5px; opacity: .8; }
.ph.small { padding: 4px; } .ph.small .t, .ph.small .a { display: none; }
.badges { position: absolute; left: 6px; bottom: 6px; display: flex; gap: 3px; }
.fmt { font: 700 9.5px/1 var(--sans); letter-spacing: .04em; text-transform: uppercase; padding: 3px 5px; border-radius: 4px;
  background: rgba(20, 18, 14, .78); color: #fff; }
.fmt.pdf { background: #a8402e; } .fmt.epub { background: #2f6b4f; } .fmt.djvu { background: #6b4c9a; }
.fmt.mobi, .fmt.azw3 { background: #b7791f; } .fmt.fb2 { background: #2c6aa8; } .fmt.chm { background: #555; }
.yr { position: absolute; top: 6px; right: 6px; font: 600 11.5px/1 var(--sans); padding: 4px 6px; border-radius: 5px;
  background: rgba(255, 253, 248, .92); color: #1f1b15; box-shadow: var(--shadow-sm); }
.st { position: absolute; top: 7px; left: 7px; width: 11px; height: 11px; border-radius: 50%; border: 2px solid #fff; }
.st.want { background: var(--want); } .st.reading { background: var(--reading); } .st.done { background: var(--done); }
.card .meta { padding: 9px 2px 0; }
.card .title { margin: 0; font: 600 14px/1.3 var(--serif); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .authors { color: var(--muted); font-size: 12.5px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { color: var(--faint); font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hit { margin-top: 5px; font-size: 12px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 7px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.hit b { font-weight: 600; color: var(--accent); }

/* ---------- table ---------- */
.results.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table { width: 100%; border-collapse: collapse; }
.table th { position: sticky; top: var(--top); z-index: 2; background: var(--surface-2); text-align: left; font-size: 11.5px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 9px 12px; cursor: pointer; white-space: nowrap; user-select: none; }
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table th .arrow { color: var(--accent); }
.table td { padding: 8px 12px; border-top: 1px solid var(--border); vertical-align: middle; }
.table tr.row { cursor: pointer; }
.table tr.row:hover td { background: var(--surface-2); }
.table .thumb { width: 34px; height: 48px; border-radius: 3px; overflow: hidden; background: var(--surface-2); box-shadow: var(--shadow-sm); }
.table .thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.table .t1 { font: 600 14px/1.3 var(--serif); }
.table .t2 { color: var(--muted); font-size: 12.5px; }
.table .fmts { display: flex; gap: 3px; flex-wrap: wrap; }
.table .muted { color: var(--muted); }

/* ---------- annotations in the book card ---------- */
.annots { display: flex; flex-direction: column; gap: 4px; }
.annot { position: relative; display: flex; flex-direction: column; gap: 2px; text-align: left; border: 1px solid var(--border); background: var(--surface);
  border-radius: 8px; padding: 7px 10px 7px 14px; cursor: pointer; }
.annot:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.annot::before { content: ""; position: absolute; left: 4px; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--c); }
.annot .aw { font-size: 11.5px; color: var(--muted); }
.annot .aw b { color: var(--accent); font-weight: 600; }
.annot .aq { font: 13px/1.45 var(--serif); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.annot .an { font-size: 12.5px; color: var(--muted); white-space: pre-wrap; }

/* ---------- full-text book search ---------- */
.modes { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.modes button { border: 0; background: transparent; color: var(--muted); padding: 6px 12px; font-size: 13px; display: flex; gap: 6px; align-items: center; }
.modes button + button { border-left: 1px solid var(--border); }
.modes button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.modes .n { font-size: 11.5px; color: var(--faint); font-weight: 400; }
.modes button.on .n { color: inherit; opacity: .75; }
.results.texthits { display: flex; flex-direction: column; gap: 12px; max-width: 980px; }
.text-note { padding: 9px 12px; border-radius: 8px; background: var(--surface); border: 1px dashed var(--border); color: var(--muted); font-size: 13px; }
.text-note.error { color: var(--danger); border-color: var(--danger); }
.thit { display: grid; grid-template-columns: 52px 1fr; gap: 14px; padding: 14px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer; outline: 0; }
.thit:hover, .thit:focus-visible { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.thit .thumb { width: 52px; height: 74px; border-radius: 4px; overflow: hidden; background: var(--surface-2); box-shadow: var(--shadow-sm); }
.thit .thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.thit .tbody { min-width: 0; }
.thead { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-bottom: 6px; }
.thead .title { margin: 0; font: 600 15px/1.3 var(--serif); }
.thead .tmeta { color: var(--muted); font-size: 12.5px; }
.thead .tcount { margin-left: auto; color: var(--faint); font-size: 12px; white-space: nowrap; }
.tfile { display: flex; align-items: center; gap: 6px; margin: 8px 0 2px; color: var(--muted); font-size: 12px; }
.snips { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.snip { padding: 6px 8px; margin: 0 -8px; border-radius: 6px; cursor: pointer; }
.snip:hover { background: var(--surface-2); }
.snip .where { display: flex; gap: 8px; align-items: baseline; font-size: 12px; color: var(--muted); }
.snip .where b { color: var(--accent); font-weight: 600; white-space: nowrap; }
.snip .where span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.snip .frag { font-size: 13px; line-height: 1.5; color: var(--text); overflow-wrap: anywhere; }
.thit .link { margin-top: 4px; }

.empty { text-align: center; padding: 80px 20px; color: var(--muted); }
.empty h3 { font: 600 20px var(--serif); color: var(--text); margin: 0 0 6px; }

/* ---------- book card ---------- */
.backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(15, 12, 8, .35); opacity: 0; pointer-events: none; transition: opacity .2s; }
.backdrop.on { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; z-index: 40; top: 0; right: 0; bottom: 0; width: min(640px, 100vw); background: var(--surface);
  box-shadow: var(--shadow-lg); transform: translateX(105%); transition: transform .25s cubic-bezier(.2, .8, .2, 1);
  display: flex; flex-direction: column; }
.drawer.on { transform: none; }
.drawer-top { display: flex; align-items: center; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.drawer-top .pos { color: var(--muted); font-size: 12.5px; margin-right: auto; padding-left: 4px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 22px 26px 40px; }
.hero { display: grid; grid-template-columns: 150px 1fr; gap: 22px; align-items: start; }
.hero .cover { box-shadow: var(--shadow-lg); }
.hero .cover:hover { transform: none; }
.hero h2 { margin: 0 0 6px; font: 600 23px/1.25 var(--serif); text-wrap: balance; }
.hero .by { color: var(--muted); font-size: 14.5px; }
.by a, .facts a { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--faint); cursor: pointer; }
.by a:hover, .facts a:hover { color: var(--accent); border-color: var(--accent); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 14px 0 0; font-size: 13px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.facts .src { color: var(--faint); font-size: 12px; margin-left: 4px; }
.statusbar { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 16px; }
.statusbar button { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 4px 11px; font-size: 12.5px; }
.statusbar button.on { border-color: currentColor; font-weight: 600; }
.statusbar button.want.on { color: var(--want); } .statusbar button.reading.on { color: var(--reading); } .statusbar button.done.on { color: var(--done); }
.statusbar button.none.on { color: var(--muted); }
.section { margin-top: 24px; }
.section h4 { margin: 0 0 8px; font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.desc { white-space: pre-line; line-height: 1.6; font-size: 14.5px; }
.desc.empty-desc { color: var(--faint); font-style: italic; }
.evidence { margin-top: 10px; font-size: 12.5px; color: var(--muted); background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.notes { white-space: pre-line; background: color-mix(in srgb, var(--want) 10%, var(--surface)); border-left: 3px solid var(--want); padding: 8px 12px; border-radius: 0 8px 8px 0; }
.files { display: flex; flex-direction: column; gap: 10px; }
.file { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.file-head { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.file-head .err { color: var(--danger); }
.path-row { margin-top: 8px; }
.path-row + .path-row { border-top: 1px dashed var(--border); padding-top: 8px; }
.path { font: 12px/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace; color: var(--text); word-break: break-all; }
.path .dir { color: var(--muted); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 7px; }
.btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); font-size: 13px; font-weight: 500; white-space: nowrap; }
.btn .ic { width: 15px; height: 15px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.toc { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }
.toc li { padding: 3px 0; border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent); }
.toc li.l2 { padding-left: 18px; color: var(--muted); font-size: 13px; }
.toc li.hit-row { background: color-mix(in srgb, var(--mark) 45%, transparent); }
details.toc-wrap summary { cursor: pointer; color: var(--accent); font-size: 13px; margin-top: 6px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.drawer-foot { display: flex; gap: 8px; flex-wrap: wrap; }

/* edit form */
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.form input[type=text], .form input[type=number], .form textarea, .form select, .dialog textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); padding: 7px 10px; font-size: 14px; color: var(--text); }
.form textarea { resize: vertical; min-height: 70px; line-height: 1.5; }
.form input:focus, .form textarea:focus, .form select:focus, .dialog textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.form .row2 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.form .check { color: var(--text); font-size: 13.5px; }

/* dialog */
.dialog { border: 0; border-radius: 14px; padding: 0; width: min(640px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
.dialog::backdrop { background: rgba(15, 12, 8, .45); }
.dialog form { padding: 22px 24px; }
.dialog h3 { margin: 0 0 6px; font: 600 20px var(--serif); }
.dialog .hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.dialog textarea { font: 13px/1.6 ui-monospace, "Cascadia Mono", Consolas, monospace; white-space: pre; overflow-x: auto; }
.agents { margin: 4px 0 8px; border-top: 1px solid var(--border); padding-top: 10px; }
.agents summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
.agents .hint.warn { color: var(--danger); }
.agents .cmd { margin-bottom: 10px; }
.agents .cmd-head { display: flex; gap: 8px; align-items: baseline; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.agents .cmd-head b { color: var(--text); }
.agents .cmd-head .link { margin-left: auto; }
.agents pre { margin: 0; padding: 8px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  font: 12px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 180px; overflow: auto; user-select: all; }
.dialog-actions {display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.spacer { flex: 1; }

.toasts { position: fixed; z-index: 60; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 9px; font-size: 13.5px; box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease; max-width: 90vw; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- narrow screens ---------- */
@media (max-width: 1100px) { .brand span { display: none; } .brand { width: auto; } }
@media (max-width: 900px) {
  .only-narrow { display: inline-flex; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 35; top: var(--top); height: calc(100vh - var(--top)); left: 0; width: min(320px, 88vw); background: var(--bg); transform: translateX(-105%);
    transition: transform .25s; box-shadow: var(--shadow-lg); }
  .sidebar.on { transform: none; }
  .main { padding: 16px; }
  .toolbar select { max-width: 130px; }
  .search kbd { display: none; }
}
@media (max-width: 640px) {
  :root { --top: 104px; }
  .topbar { gap: 8px; padding: 8px 12px; flex-wrap: wrap; align-content: center; }
  .search { order: 3; flex: 1 1 100%; max-width: none; }
  .toolbar select { max-width: 160px; }
  .toolbar .seg, #themeBtn { display: none; }
  .results.grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 20px 14px; }
  .hero { grid-template-columns: 100px 1fr; gap: 14px; }
  .hero h2 { font-size: 19px; }
  .drawer-body { padding: 18px 16px 40px; }
  .form .row2 { grid-template-columns: 1fr 1fr; }
  .table .hide-sm { display: none; }
}

/* ================================================================ books on the internet */
body.web-mode .layout, body.web-mode .search, body.web-mode #sort, body.web-mode #viewSeg, body.web-mode #filtersBtn { display: none; }
#webBtn.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.websearch { display: grid; grid-template-columns: 340px 1fr; min-height: calc(100vh - var(--top)); }
.websearch[hidden] { display: none; }
.ws-side { border-right: 1px solid var(--border); padding: 16px 18px 40px; display: flex; flex-direction: column; gap: 18px; background: var(--bg);
  position: sticky; top: var(--top); height: calc(100vh - var(--top)); overflow: auto; }
.ws-head { display: flex; align-items: center; justify-content: space-between; }
.ws-head h3 { margin: 0; font: 600 17px var(--serif); }
.ws-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ws-sources { border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px 8px; margin: 0; }
.ws-sources legend { font-size: 12.5px; color: var(--muted); padding: 0 4px; }
.ws-engines h4 { margin: 0 0 4px; font-size: 13px; }
.ws-engines .hint { margin: 0 0 8px; font-size: 12px; color: var(--muted); }
.ws-site { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.ws-site input, #wsQuery { width: 100%; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); padding: 7px 9px; font-size: 13px; }
#wsQuery { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.ws-engine-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.ws-engine-btns .btn { justify-content: center; }
.ws-dir { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; margin-top: auto; }
.ws-dir b { color: var(--text); font-weight: 500; }

.ws-results { padding: 18px 28px 60px; min-width: 0; }
.ws-intro { max-width: 640px; color: var(--text); line-height: 1.6; }
.ws-group { margin-bottom: 26px; }
.ws-group h4 { margin: 0 0 10px; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.ws-state { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--faint); margin-left: 6px; }
.ws-state .err { color: var(--danger); }
.ws-list { display: grid; gap: 8px; }
.ws-item { display: flex; gap: 14px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.ws-cover { width: 46px; height: 66px; object-fit: cover; border-radius: 4px; flex: none; background: var(--surface-2); box-shadow: var(--shadow-sm); }
.ws-body { min-width: 0; flex: 1; }
.ws-title { font: 600 15px/1.35 var(--serif); }
.ws-have { margin-left: 8px; font: 500 11.5px var(--sans); color: var(--accent); border-color: var(--accent); vertical-align: 2px; }
.ws-meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.ws-note { font-size: 12px; color: var(--faint); margin-top: 2px; }
.ws-files { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.ws-file { gap: 7px; height: 30px; }
.ws-file.done { color: var(--accent); border-color: var(--accent); }
.ws-size { color: var(--muted); font-weight: 400; }
.ws-muted, .ws-empty { font-size: 12.5px; color: var(--muted); }
@media (max-width: 860px) {
  .websearch { grid-template-columns: 1fr; }
  .ws-side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .ws-results { padding: 16px; }
}
.form label.check { display: flex; color: var(--text); font-size: 13px; }
.ws-mysites { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; background: var(--surface); }
.ws-mysites summary { cursor: pointer; font-size: 13px; font-weight: 600; }
.ws-mysites .n { color: var(--faint); font-weight: 400; margin-left: 4px; }
.ws-mysites .chips { margin: 10px 0 8px; }
.ws-site-chip { display: inline-flex; align-items: center; gap: 4px; padding-right: 4px; }
.ws-site-chip a { color: var(--text); text-decoration: none; }
.ws-x { border: 0; background: none; color: var(--faint); padding: 0 3px; font-size: 14px; line-height: 1; cursor: pointer; }
.ws-x:hover { color: var(--danger); }
.ws-suggest { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; width: 100%; }
.ws-add { display: flex; gap: 6px; margin-bottom: 8px; }
.ws-add input { flex: 1; min-width: 0; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); padding: 5px 9px; font-size: 13px; }
#wsFindSites { width: 100%; justify-content: center; }
.ws-known { color: var(--accent); font-size: 12px; }
.ws-count { font: 400 12.5px var(--sans); color: var(--muted); margin-left: 6px; }
.ws-note a { color: var(--accent); text-decoration: none; }
.ws-more { margin-top: 4px; }
.ws-nofiles { margin: 6px 0 10px; }
.ws-nofiles > summary { cursor: pointer; font-size: 13px; color: var(--muted); padding: 6px 0; }
.ws-nofiles[open] > summary { margin-bottom: 8px; }
.ws-disc-head { margin-bottom: 16px; max-width: 760px; }
.ws-disc-head h3 { margin: 0 0 6px; font: 600 17px var(--serif); }
.ws-disc-head .btn { margin-right: 6px; }
.ws-disc-progress { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.ws-pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); animation: ws-pulse 1s ease-in-out infinite alternate; }
@keyframes ws-pulse { from { opacity: .25; } to { opacity: 1; } }
.ws-sub { margin-bottom: 14px; }
.ws-sub h5 { margin: 4px 0 8px; font-size: 12.5px; font-weight: 600; color: var(--text); }
.ws-sub .ws-list { display: grid; gap: 8px; }

/* library settings */
#settingsDlg { width: min(760px, calc(100vw - 32px)); }
.lib-sec { border-top: 1px solid var(--border); padding: 12px 0 6px; }
.lib-sec h4 { margin: 0 0 4px; font-size: 14px; }
.dialog .hint.warn { color: var(--danger); }
.dialog .hint:empty { display: none; }
.lib-row { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); margin-bottom: 6px; }
.lib-row.missing .lib-path { color: var(--faint); text-decoration: line-through; }
.lib-main { margin-bottom: 10px; }
.lib-path { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font: 12.5px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace; }
.lib-n { font-size: 12px; color: var(--muted); white-space: nowrap; }
.lib-row .btn { height: 28px; padding: 0 10px; }
.lib-sub { font-size: 12px; color: var(--muted); margin: 10px 0 6px; }
.lib-add, .lib-layout { display: flex; gap: 8px; align-items: center; margin: 4px 0 10px; flex-wrap: wrap; }
.lib-layout .hint { margin: 0; }
.dialog .check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; margin: 4px 0; }
.dialog .check input { margin-top: 3px; }
.lib-preview { font-size: 12.5px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; }
.lib-preview p { margin: 4px 0; }
.lib-preview ul { margin: 4px 0; padding-left: 18px; max-height: 220px; overflow: auto; }
.lib-preview li { margin: 2px 0; overflow-wrap: anywhere; }
.lib-preview li span { color: var(--muted); }

/* adding dropped books */
#importDlg { width: min(700px, calc(100vw - 32px)); }
.imp-list { max-height: 280px; overflow: auto; margin: 8px 0 10px; border: 1px solid var(--border); border-radius: 8px; padding: 4px 8px; background: var(--bg); }
.imp-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.imp-row:last-child { border-bottom: 0; }
.imp-row.skip { opacity: .55; }
.imp-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.imp-size { color: var(--muted); font-size: 12px; }
.imp-note { width: 100%; padding-left: 38px; color: var(--accent); font-size: 12px; }
.imp-modes { border: 0; padding: 0; margin: 0 0 8px; }
.imp-modes .check { padding: 6px 0; }
.imp-modes .hint { margin: 0; font-size: 12px; }
.drop-zone { position: fixed; inset: 10px; z-index: 80; border: 3px dashed var(--accent); border-radius: 18px; background: color-mix(in srgb, var(--bg) 82%, transparent);
  display: flex; align-items: center; justify-content: center; pointer-events: none; }
.drop-zone[hidden] { display: none; }
.drop-zone div { font: 600 22px var(--serif); color: var(--accent); background: var(--surface); padding: 16px 28px; border-radius: 12px; box-shadow: var(--shadow-lg); }

/* recognizing scans */
.ocr-box { margin: 8px 0 4px; padding: 10px 12px; border: 1px dashed var(--border); border-radius: 8px; font-size: 13px; color: var(--muted);
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.ocr-box > div:first-child { flex: 1; min-width: 220px; }
.ocr-box .err { width: 100%; color: var(--danger); }
.ocr-box.run { display: block; border-style: solid; color: var(--text); }
.ocr-line { display: flex; align-items: center; gap: 10px; justify-content: space-between; margin-bottom: 6px; }
.ocr-bar { height: 5px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.ocr-bar div { height: 100%; background: var(--accent); transition: width .3s; }
.ocr-facts { font-size: 13px; margin: 0 0 12px; }
.ocr-lang { display: flex; flex-direction: column; gap: 4px; font-size: 13px; margin-bottom: 12px; }
.ocr-lang select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }

/* Yandex Disk */
.cloud-mark { background: #2c6aa8; color: #fff; font: 700 9.5px/1 var(--sans); padding: 3px 5px; border-radius: 4px; letter-spacing: .03em; }
.cloud-on { color: #2c6aa8; font-size: 12.5px; }
.file-head .link { margin-left: 6px; font-size: 12.5px; }
.cloud-code { font-size: 14px; margin: 4px 0 10px; line-height: 1.5; }
.cloud-code b { font: 700 18px ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: .08em; padding: 2px 6px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; }
.cloud-run { font-size: 12.5px; color: var(--muted); margin: 4px 0 8px; }

/* sharing with family and friends */
.inbox { display: flex; flex-direction: column; gap: 8px; margin: 0 0 12px; }
.inbox-item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border: 1px solid #2c6aa8; border-radius: 10px; background: color-mix(in srgb, #2c6aa8 7%, transparent); }
.inbox-item > svg { flex: none; width: 22px; height: 22px; color: #2c6aa8; }
.inbox-text { flex: 1; min-width: 0; font-size: 14px; line-height: 1.45; }
.inbox-meta { color: var(--muted); font-size: 12.5px; margin-left: 4px; }
.inbox-note { font-style: italic; color: var(--muted); margin-top: 2px; }
.inbox-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: flex-end; }
.share-book { font-weight: 600; margin: 0 0 10px; }
.share-shelves { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.share-shelf { display: flex; gap: 8px; align-items: baseline; cursor: pointer; }
.share-shelf .link { margin-left: 6px; font-size: 12.5px; }
.share-new { display: flex; gap: 8px; margin-bottom: 10px; }
.share-new input { flex: 1; }
.share-note { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.share-note textarea { resize: vertical; font: inherit; }
html.android .inbox-item { flex-wrap: wrap; }

.cloud-code b.plain { font: inherit; font-weight: 700; letter-spacing: 0; padding: 0; background: none; border: 0; }
.cloud-other { display: flex; gap: 14px; align-items: center; margin: 4px 0 10px; }
.cloud-qr { flex: none; width: 112px; height: 112px; background: #fff; border-radius: 8px; padding: 4px; }
.cloud-qr svg { width: 100%; height: 100%; display: block; }
.cloud-other .cloud-code { margin: 0; }
