/* Library, PDF and EPUB reader. Extends the base styles in app.css. */
#collection { grid-template-columns: minmax(0, 1fr); overflow-x: hidden; scrollbar-width: thin; }
.folder, .volume { min-width: 0; }
.ico { background: transparent; border: 0; color: var(--dim); padding: 4px 6px; border-radius: 6px; line-height: 1; min-width: 28px; min-height: 28px; }
.ico:hover, .ico.on { color: var(--gold); }
.ico.danger:hover { color: var(--rose); }
.grip { cursor: grab; color: var(--dim); padding: 4px; user-select: none; touch-action: none; }
.tri, .tog { display: inline-block; transition: transform .15s; }
.folder.open > .folder-head .tri, .volume:not(.collapsed) .tog { transform: rotate(90deg); }
.folder-head { cursor: pointer; }
.folder:not(.open) > .folder-body { display: none; }
.folder-body { display: grid; gap: 8px; margin-top: 8px; padding-left: 8px; }
.fname, .volume-name { flex: 1; min-width: 0; width: auto !important; }
.volume.dragging, .folder.dragging { opacity: .4; }
.drop-before { box-shadow: 0 -2px 0 var(--gold); }
.drop-after { box-shadow: 0 2px 0 var(--gold); }
.drop-into { outline: 1px dashed var(--gold); }
.drop-root { display: none; padding: 8px; border: 1px dashed var(--line2); border-radius: var(--radius); color: var(--dim); font-size: 12px; text-align: center; }
.dragging-vol .drop-root { display: block; }
.drop-root.over { border-color: var(--gold); color: var(--gold); }
.volume-cover { cursor: pointer; margin: 6px 0; }
.cover-placeholder { border: 1px dashed var(--line2); border-radius: 6px; padding: 6px; text-align: center; color: var(--dim); font-size: 12px; }
.chip { font: 11px var(--mono); color: var(--dim); align-self: center; overflow-wrap: anywhere; }
.volume-cut { margin-top: 6px; padding: 3px 10px; font-size: 12px; }
.btn.wide { width: 100%; justify-content: center; margin-top: 8px; padding: 4px 10px; font-size: 12px; }
.lang-head { text-transform: uppercase; letter-spacing: .1em; margin-top: 6px; }
.hit { display: grid; gap: 2px; text-align: left; background: var(--ink2); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
.hit:hover { border-color: var(--gold); }
.hit .snip { color: var(--dim); font-size: 13px; }
.hit mark, .pdf-tl mark.hl { background: color-mix(in srgb, var(--gold) 55%, transparent); color: inherit; border-radius: 2px; }

/* reader bar */
#reader .rd-bar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.rd-title { flex: 1; min-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rd-btn[hidden] { display: none; }
.rd-btn { padding: 6px 12px; min-height: 36px; white-space: nowrap; flex: none; }
.rd-go { width: 64px !important; padding: 6px !important; flex: none; }
.rd-zl { flex: none; text-transform: none; }

/* PDF */
.pdf-scroll { position: relative; background: var(--ink2); -webkit-overflow-scrolling: touch; }
.pdf-pages { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 12px; }
.pdf-pg { position: relative; background: #fff; box-shadow: 0 2px 14px rgba(0, 0, 0, .45); flex: none; }
.pdf-pg canvas { display: block; }
.pdf-tl { position: absolute; inset: 0; overflow: hidden; line-height: 1; text-align: initial; }
.pdf-tl span { position: absolute; white-space: pre; color: transparent; transform-origin: 0 0; cursor: text; }
.pdf-tl ::selection { background: rgba(60, 130, 255, .35); }
.pdf-tl mark.hl { color: transparent; }
.crop { position: absolute; z-index: 3; border: 2px dashed var(--cyan); background: rgba(127, 214, 255, .14); cursor: move; touch-action: none; }
.crop .ch { position: absolute; width: 26px; height: 26px; background: var(--cyan); border-radius: 50%; opacity: .85; }
.crop .tl { left: -13px; top: -13px; }
.crop .br { right: -13px; bottom: -13px; }

/* highlights */
.pdf-tl mark.uh { background: color-mix(in srgb, var(--c) 50%, transparent); color: transparent; border-radius: 2px; }
.hl-sw { flex: none; width: 24px; height: 24px; min-height: 0; padding: 0; border-radius: 50%; border: 2px solid transparent; opacity: .7; }
.hl-sw.on { border-color: var(--star); opacity: 1; }
.hl-panel { position: absolute; z-index: 6; top: 56px; right: 8px; bottom: 8px; width: min(380px, calc(100% - 16px)); overflow: auto; background: var(--ink2); border: 1px solid var(--line2); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 6px; align-content: start; }
.hl-panel[hidden] { display: none; }
.hl-row { display: flex; gap: 6px; align-items: stretch; flex: none; }
.hl-t { flex: 1; min-width: 0; text-align: left; background: var(--ink3); border: 0; border-left: 4px solid var(--gold); border-radius: 6px; padding: 8px 10px; color: var(--star); font-size: 13px; overflow-wrap: anywhere; }
.hl-b { flex: none; min-width: 36px; padding: 4px 8px; }

/* EPUB */
.rd-body.ep { position: relative; display: flex; overflow: hidden; }
.ep-view { flex: 1; min-width: 0; }
.ep-toc { position: absolute; inset: 0 auto 0 0; z-index: 4; width: min(340px, 100%); background: var(--ink2); border-right: 1px solid var(--line2); display: flex; flex-direction: column; gap: 8px; padding: 10px; }
.ep-toc[hidden] { display: none; }
.ep-list { overflow: auto; flex: 1; display: grid; align-content: start; gap: 2px; }
.ep-item { background: transparent; border: 0; text-align: left; padding: 9px 10px; border-radius: 6px; color: var(--star); }
.ep-item:hover { background: var(--ink3); }

@media (max-width: 760px) {
  .rd-btn .lbl { display: none; }
  .rd-btn { padding: 6px 12px; font-size: 16px; }
  .rd-title { min-width: 40px; font-size: 14px; }
  .pdf-pages { padding: 8px 4px; }
  .ico { min-width: 36px; min-height: 36px; }
}
@media (pointer: coarse) { .hl-sw { width: 34px; height: 34px; } .hl-b { min-width: 44px; min-height: 44px; } .rd-btn { min-height: 44px; } .grip { padding: 8px; } }

/* progress, bookmarks, peers in the library */
.vprog { position: relative; height: 4px; margin-top: 8px; background: var(--ink3); border-radius: 2px; }
.vprog i { position: absolute; inset: 0 auto 0 0; background: var(--gold); border-radius: 2px; }
.vprog b { position: absolute; top: -3px; width: 2px; height: 10px; background: var(--cyan); transform: translateX(-1px); }
.peer-dot { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; color: var(--dim); }
.peer-dot i { width: 8px; height: 8px; border-radius: 50%; background: hsl(var(--h) 70% 60%); flex: none; }
@media (prefers-reduced-motion: no-preference) { .peer-dot i { animation: peerp 2s ease-in-out infinite; } }
@keyframes peerp { 50% { opacity: .35; } }
.hit-grp { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 13px; }
.hit-grp b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hit-grp .mono { color: var(--dim); flex: none; }
.hit-bar { flex: 0 0 60px; height: 4px; background: var(--ink3); border-radius: 2px; position: relative; }
.hit-bar i { position: absolute; inset: 0 auto 0 0; background: var(--gold); border-radius: 2px; }

/* reading together */
.rd-peers { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 12px; border-bottom: 1px solid var(--line); }
.rd-peers[hidden] { display: none; }
.rd-peerg { display: inline-flex; border: 1px solid hsl(var(--h) 60% 55%); border-radius: 999px; overflow: hidden; font-size: 12px; }
.rd-peer, .rd-peer-f { background: hsl(var(--h) 55% 30% / .55); color: var(--star); border: 0; padding: 4px 10px; min-height: 28px; }
.rd-peer-f { background: transparent; color: var(--dim); border-left: 1px solid var(--line2); }
.rd-peer-f.on { color: var(--ink); background: hsl(var(--h) 70% 65%); }

/* dictionary popover */
.dict-pop { position: fixed; z-index: 70; max-height: 260px; overflow: auto; background: var(--ink2); color: var(--star); border: 1px solid var(--line2); border-radius: 10px; padding: 10px 12px; box-shadow: 0 8px 28px rgba(0, 0, 0, .5); font-size: 13px; display: grid; gap: 6px; }
.dict-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dict-body p { margin: 4px 0; }
.dict-acts { display: flex; flex-wrap: wrap; gap: 6px; }
.dict-acts .btn { padding: 3px 10px; font-size: 12px; text-decoration: none; }

/* evidence mode */
.pdf-tl mark.uh.ev { background: color-mix(in srgb, var(--c) 65%, transparent); outline: 2px solid var(--c); }
.ev-panel { position: absolute; z-index: 5; right: 0; bottom: 0; width: min(320px, 40%); background: var(--ink2); border-left: 1px solid var(--line2); padding: 8px; display: flex; flex-direction: column; gap: 6px; overflow: hidden; }
.ev-panel[hidden] { display: none; }
#reader.ev-open .rd-body { margin-right: min(320px, 40%); }
.ev-head { display: flex; align-items: center; gap: 6px; }
.ev-head strong { flex: 1; }
.ev-for { margin: 0; font-size: 12px; overflow-wrap: anywhere; }
.ev-opt { font-size: 12px; color: var(--dim); display: flex; gap: 6px; align-items: center; }
.ev-list { overflow: auto; display: grid; gap: 6px; align-content: start; flex: 1; }
.ev-item { display: grid; gap: 2px; text-align: left; background: var(--ink3); border: 1px solid var(--line); border-left: 4px solid #ff9a3d; border-radius: 6px; padding: 8px; color: var(--star); }
.ev-item.on { border-color: #ff9a3d; background: color-mix(in srgb, #ff9a3d 18%, var(--ink3)); }
.ev-item .snip { color: var(--dim); font-size: 13px; overflow-wrap: anywhere; }
@media (max-width: 760px) {
  .ev-panel { top: auto !important; width: 100%; max-height: 42%; border-left: 0; border-top: 1px solid var(--line2); }
  #reader.ev-open .rd-body { margin-right: 0; margin-bottom: min(42%, 300px); }
}

/* focus mode */
body.focus-mode #top, body.focus-mode #library, body.focus-mode #libTab, body.focus-mode #statusbar { display: none !important; }
body.focus-mode #reader { inset: 0; }
body.focus-mode #reader .rd-bar, body.focus-mode #reader .rd-peers { opacity: .6; transition: opacity .2s; }
body.focus-mode #reader .rd-bar:hover, body.focus-mode #reader .rd-bar:focus-within, body.focus-mode #reader .rd-peers:hover { opacity: 1; }
body.focus-mode .pdf-scroll { background: color-mix(in srgb, var(--ink) 55%, #000); }
body.focus-mode .pdf-pg { box-shadow: 0 0 80px rgba(0, 0, 0, .6); }
body.focus-mode .ep-view { max-width: 760px; margin: 0 auto; }
.fx { position: fixed; z-index: 30; right: 12px; bottom: 12px; display: flex; gap: 8px; align-items: center; opacity: .75; }
.fx:hover { opacity: 1; }
.fx .btn { padding: 4px 12px; min-height: 34px; }
.fx-t { display: inline-flex; align-items: center; gap: 4px; background: var(--ink2); border: 1px solid var(--line2); border-radius: 999px; padding: 2px 4px 2px 12px; font-size: 12px; }
.fx-p { background: transparent; border: 0; color: var(--dim); padding: 4px 8px; border-radius: 999px; min-height: 28px; }
.fx-p:hover { color: var(--gold); }

/* compact reader bar: ✕  title … Cut  ⛶  ⋯ ; everything else lives in the ⋯ popover */
.rd-ico { min-width: 36px; padding: 6px 10px; font-size: 16px; flex: none; }
#reader .rd-bar .rd-btn .lbl { display: inline; }
.rd-more { position: absolute; top: 50px; right: 8px; z-index: 6; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; width: min(430px, calc(100% - 16px)); padding: 10px; background: var(--ink2); border: 1px solid var(--line2); border-radius: 14px; box-shadow: 0 16px 50px rgba(0, 0, 0, .55); }
.rd-more[hidden] { display: none; }
.rd-more .rd-btn .lbl { display: inline; }
.rd-more .rd-go { width: 64px !important; }
.rd-ico[hidden] { display: none; }
body.focus-mode #reader .rd-bar { overflow-x: auto; }

.web-src { display: inline-block; margin: 4px 0; font: 11px var(--mono); color: var(--dim); text-decoration: none; overflow-wrap: anywhere; }
.web-src:hover { color: var(--gold); }

/* ===== tidy library: calm cards, icons instead of emoji, one place for destructive actions ===== */
#library { gap: 10px; }
.lib-tabs { background: var(--ink2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 2px; }
.lib-tabs .btn { flex: 1; justify-content: center; border: 0; padding: 5px 10px; font-size: 13px; }
.lib-tabs .btn.on { background: var(--ink3); color: var(--gold); }
.lib-actions { gap: 6px; }
.lib-actions .btn { flex: 1; justify-content: center; padding: 5px 10px; font-size: 13px; gap: 6px; }
#libSearch { padding: 7px 12px; font-size: 13px; }
#collection { gap: 8px; padding-right: 4px; }
.volume, .folder { border: 1px solid var(--line); border-radius: 12px; padding: 8px 8px 10px; background: color-mix(in srgb, var(--ink2) 55%, transparent); }
.volume.is-locked, .folder.is-locked { border-color: color-mix(in srgb, var(--gold) 40%, var(--line)); }
.v-head, .folder-head { display: flex; align-items: center; gap: 2px; min-width: 0; }
.grip { opacity: .3; padding: 4px 2px; display: grid; place-items: center; }
.volume:hover > .v-head .grip, .folder-head:hover .grip { opacity: .9; }
.volume-name, .fname { flex: 1; min-width: 0; font: 600 15px var(--serif); padding: 4px 6px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--star); text-overflow: ellipsis; }
.volume-name:focus, .fname:focus { border-color: var(--line2); background: var(--ink); outline: none; }
.ico { display: grid; place-items: center; background: transparent; border: 0; color: var(--dim); width: 28px; height: 28px; padding: 0; border-radius: 7px; flex: none; }
.ico:hover { color: var(--star); background: var(--ink3); }
.ico.on { color: var(--gold); }
.ico svg { display: block; }
.tog svg, .tri svg { transition: transform .15s; }
.volume:not(.collapsed) .tog svg, .folder.open > .folder-head .tri svg { transform: rotate(90deg); }
.tri { display: grid; place-items: center; width: 22px; color: var(--dim); }
.folder-head { cursor: pointer; }
.folder-head > svg { color: var(--dim); flex: none; margin: 0 4px 0 2px; }
.folder-head .count { font-size: 11px; color: var(--dim); background: var(--ink); border-radius: 999px; padding: 0 7px; margin-right: 2px; text-transform: none; letter-spacing: 0; }
.folder-body { gap: 8px; margin-top: 8px; padding-left: 8px; border-left: 1px solid var(--line); }
.v-row { display: flex; gap: 10px; margin-top: 8px; }
.v-thumb { flex: none; width: 48px; height: 68px; border-radius: 6px; background: var(--ink); border: 1px dashed var(--line2); display: grid; place-items: center; color: var(--dim); padding: 0; overflow: hidden; }
.v-thumb:hover { border-color: var(--gold); color: var(--gold); }
.v-thumb:has(img) { border-style: solid; border-color: var(--line); }
.v-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; } /* the whole cover, never cropped */
.v-info { flex: 1; min-width: 0; display: grid; gap: 5px; align-content: start; }
.v-meta { font-size: 11px; color: var(--dim); text-transform: none; letter-spacing: .02em; overflow-wrap: anywhere; }
.v-sub { font-size: 12px; color: var(--dim); }
.v-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.btn.sm { padding: 3px 12px; font-size: 12px; min-height: 28px; gap: 6px; }
.btn.sm.icon { padding: 3px 8px; }
.btn.sm.on { border-color: var(--gold); color: var(--gold); }
.web-src { display: inline-flex; align-items: center; gap: 5px; margin: 0; }
.volume-text { margin-top: 8px; }
.volume-cut { margin-top: 6px; display: inline-flex; align-items: center; }
.node-lock svg { display: block; }
.node-lock { display: grid; place-items: center; }
#library .volume-name, #library .fname { border: 1px solid transparent; background: transparent; width: auto; padding: 4px 6px; }
#library .volume-name:focus, #library .fname:focus { border-color: var(--line2); background: var(--ink); }
#library .volume-name:hover, #library .fname:hover { border-color: var(--line); }

/* bigger covers (whole image, never cropped) + full-size viewer */
.v-thumb { width: 92px; height: 130px; border-radius: 8px; }
.v-thumb img { background: color-mix(in srgb, var(--ink3) 50%, transparent); }
.v-thumb:not(:has(img)) { height: 92px; }
.v-info { gap: 6px; }
.cover-card { place-items: center; }
.cover-big { max-width: 100%; max-height: 68vh; object-fit: contain; border-radius: 10px; box-shadow: 0 10px 40px rgba(0, 0, 0, .5); }
.cover-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
