/* Library — quiet library aesthetic */
:root {
  --ink: #1f2933;
  --muted: #6b7280;
  --paper: #faf7f2;
  --card: #ffffff;
  --accent: #7c4d21;
  --accent-dark: #5d3a18;
  --line: #e5e0d8;
  --danger: #a33;
  /* post-it / plastic tints (light) */
  --pre-code-bg: #f4efe6;
  --code-bg: rgba(124, 77, 33, 0.07);
  --hover-row: #f3ede2;
  --job-pre-bg: #f4efe6;
  --thumb-bg: #efe9df;
  --cover-bg: #efe9df;
  --topbar-bg: #2c2318;
  --topbar-fg: #f5efe4;
  --topbar-muted: #b8a88f;
  --tab-ink: #4a3a26;
  --tab-1: #e8c9a8;
  --tab-2: #d9b8a5;
  --spine-bg: #e9e2d5;
  --note-bg: rgba(255, 253, 248, 0.72);
}
body.theme-dark {
  --ink: #e8e4dc;
  --muted: #a8a294;
  --paper: #191714;
  --card: #241f1a;
  --accent: #c98b4b;
  --accent-dark: #e0a76a;
  --line: #3d362e;
  --danger: #e07b6f;
  --pre-code-bg: #2b261f;
  --code-bg: rgba(201, 139, 75, 0.14);
  --hover-row: #2e2822;
  --job-pre-bg: #2b261f;
  --thumb-bg: #332c24;
  --cover-bg: #332c24;
  --topbar-bg: #12100d;
  --topbar-fg: #e8e4dc;
  --topbar-muted: #9c8e77;
  --tab-ink: #2a2118;
  --tab-1: #d8b18c;
  --tab-2: #c9a08b;
  --spine-bg: #211d18;
  --note-bg: rgba(48, 42, 35, 0.72);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Georgia, 'Times New Roman', serif;
  color: var(--ink);
  background: var(--paper);
}
.topbar {
  display: flex;
  align-items: flex-end;
  gap: 1.25rem;
  padding: 0.7rem 1.75rem 0;
  background: var(--topbar-bg);
  color: var(--topbar-fg);
}
.brand-block { display: flex; align-items: baseline; gap: 0.75rem; padding-bottom: 0.55rem; }
.brand {
  font-size: 1.6rem;
  font-weight: bold;
  color: var(--topbar-fg);
  text-decoration: none;
  letter-spacing: 0.02em;
}
.subtitle { color: var(--topbar-muted); font-size: 0.95rem; font-style: italic; }
.tabs {
  margin-left: auto;
  display: flex;
  align-items: flex-end;
  gap: 0.6rem;
}
.tab {
  position: relative;
  display: inline-block;
  padding: 0.6rem 1.15rem 0.8rem;
  font-size: 1.15rem;
  text-decoration: none;
  color: var(--tab-ink);
  border: none;
  border-radius: 2px 2px 7px 2px;
  box-shadow: 0 2px 3px rgba(0,0,0,0.25), 0 1px 0 rgba(0,0,0,0.15);
  transform: rotate(-11.6deg);
  transform-origin: top center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  clip-path: polygon(0 4%, 100% 0, 98% 100%, 2% 96%);
}
.tab:nth-child(2) { transform: rotate(8.8deg) translateY(1px); }
.tab:nth-child(1) { background: var(--tab-1); }          /* warm tan post-it  */
.tab:nth-child(2) { background: var(--tab-2); }          /* dusty rose post-it */
.tab:hover {
  transform: rotate(0deg) translateY(-3px);
  box-shadow: 0 5px 8px rgba(0,0,0,0.3);
  z-index: 2;
}
.tab.active {
  background: var(--paper);
  color: var(--ink);
  font-weight: bold;
  transform: rotate(0deg) translateY(2px);
  z-index: 1;
  box-shadow: 0 2px 2px rgba(0,0,0,0.35);
}
.logout-btn {
  color: var(--topbar-muted);
  text-decoration: none;
  padding: 0.45rem 0.8rem 0.55rem;
  font-size: 1.05rem;
  margin-left: 0.5rem;
}
.logout-btn:hover { color: var(--topbar-fg); }
.theme-btn {
  background: none; border: none; cursor: pointer;
  color: var(--topbar-muted); font-size: 1.05rem; padding: 0.3rem 0.5rem;
  margin-left: 0.25rem; line-height: 1;
}
.theme-btn:hover { color: var(--topbar-fg); }

.wrap { max-width: 880px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
.wrap.reader { max-width: min(96vw, 130rem); }
h1, h2 { font-weight: normal; }
h2 { border-bottom: 1px solid var(--line); padding-bottom: 0.35rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--danger); }

.login-wrap { display: flex; justify-content: center; padding-top: 10vh; }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 2rem 2.5rem; width: 340px; text-align: center;
}
.login-card input {
  width: 100%; padding: 0.6rem; margin: 0.5rem 0 1rem;
  border: 1px solid var(--line); border-radius: 4px; font-size: 1rem;
}

.searchbar { display: flex; gap: 0.5rem; margin: 1rem 0; }
.searchbar input[type="search"] {
  flex: 1; padding: 0.6rem 0.75rem; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 6px; font-family: inherit;
}
.btn {
  display: inline-block; padding: 0.5rem 0.9rem; font-size: 0.95rem;
  font-family: inherit; border: 1px solid var(--line); border-radius: 5px;
  background: var(--card); color: var(--ink); cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent-dark); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.small { font-size: 0.8rem; padding: 0.3rem 0.6rem; }
.btn.tiny { font-size: 0.72rem; padding: 0.15rem 0.45rem; margin-left: 0.4rem; }
.btn.danger { color: var(--danger); border-color: #e4c4c4; }

.results .hit {
  background: var(--card); border: 1px solid var(--line); border-radius: 6px;
  padding: 0.85rem 1rem; margin: 0.75rem 0;
}
.hit-meta { display: flex; gap: 0.6rem; align-items: baseline; font-size: 0.85rem; }
.score { color: var(--muted); font-family: monospace; }
.hit .src { font-weight: bold; color: var(--accent-dark); text-decoration: none; }
.hit .src:hover { text-decoration: underline; }
.loc { color: var(--muted); }
.text { margin: 0.4rem 0 0; line-height: 1.5; white-space: pre-wrap; }

.booklist { list-style: none; padding: 0; line-height: 1.9; }
.booklist a { color: var(--ink); text-decoration: none; }
.booklist a:hover { color: var(--accent-dark); text-decoration: underline; }

.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 1rem 1.25rem; margin: 1.25rem 0;
}
.panel h2 { margin-top: 0; font-size: 1.1rem; border-bottom: 0; padding-bottom: 0; }

.aa-results table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.aa-results th, .aa-results td { text-align: left; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.aa-results td.t { max-width: 340px; }

.job { border-top: 1px dashed var(--line); padding: 0.5rem 0; font-size: 0.85rem; }
.job pre {
  background: var(--pre-code-bg); padding: 0.5rem; border-radius: 4px;
  white-space: pre-wrap; word-break: break-word; margin: 0.35rem 0 0;
  max-height: 9rem; overflow-y: auto; font-size: 0.78rem;
}
.badge { font-size: 0.72rem; padding: 0.1rem 0.5rem; border-radius: 10px; margin-left: 0.5rem; }
.badge.running { background: #fdf3d7; color: #8a6d1a; }
.badge.done { background: #e2f0e2; color: #2c6e2c; }
.badge.error { background: #f8e2e2; color: var(--danger); }

.crumbs { font-size: 0.9rem; }
.pdf-holder iframe { width: 100%; height: 80vh; border: 1px solid var(--line); border-radius: 6px; }

.rerank-toggle {
  display: flex; align-items: center; gap: 0.3rem;
  font-size: 0.85rem; color: var(--muted); cursor: pointer;
  padding: 0 0.25rem; white-space: nowrap;
}
.rerank-toggle input { accent-color: var(--accent); }
.view-toggle { display: flex; gap: 0.4rem; margin: 0.5rem 0 1rem; }
.view-toggle .btn.active { background: var(--accent); border-color: var(--accent-dark); color: #fff; }
.hidden { display: none !important; }

.booklist.covers {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 1rem; padding: 0;
}
.cover-card a { display: block; text-decoration: none; color: var(--ink); }
.cover-card img {
  width: 100%; aspect-ratio: 2 / 3; object-fit: cover;
  border: 1px solid var(--line); border-radius: 4px;
  background: var(--cover-bg); box-shadow: 2px 2px 5px rgba(0,0,0,0.12);
  display: block;
}
.cover-title {
  display: block; font-size: 0.78rem; line-height: 1.3; margin-top: 0.4rem;
  max-height: 3.1em; overflow: hidden;
}
.cover-card a:hover .cover-title { text-decoration: underline; color: var(--accent-dark); }

/* ---- reader ---- */
.reader h1.book-title { font-size: 1.05rem; color: var(--muted); font-style: italic; }
.reader-toolbar {
  display: flex; align-items: center; gap: 0.5rem; margin: 0.75rem 0;
  flex-wrap: wrap;
}
.reader-toolbar .spacer { flex: 1; }
.page-select { font-family: inherit; padding: 0.3rem 0.5rem; border: 1px solid var(--line); border-radius: 4px; background: var(--card); font-size: 0.85rem; max-width: 14rem; }
.book-search { display: flex; gap: 0.3rem; }
.book-search input { padding: 0.3rem 0.5rem; font-size: 0.85rem; border: 1px solid var(--line); border-radius: 4px; width: 12rem; font-family: inherit; }
.search-panel h3 { margin: 0 0 0.5rem; display: flex; justify-content: space-between; align-items: center; }
.search-panel { max-height: 18rem; overflow-y: auto; }
/* ---- in-book search: full-page overlay ---- */
.search-overlay {
  position: fixed; inset: 0; z-index: 30;
  background: var(--paper);
  display: flex; flex-direction: column;
}
.search-top {
  display: flex; align-items: center; gap: 0.9rem;
  padding: 0.7rem 1.25rem; border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.search-top h3 { margin: 0; font-size: 1.05rem; }
.search-top #search-info { font-style: italic; }
.search-scroll { flex: 1; overflow-y: auto; padding: 1rem 1.5rem 3rem; }
.search-scroll > div { max-width: 46rem; margin: 0 auto; }
body.search-open .reader-body,
body.search-open .reader-toolbar,
body.search-open .page-holder,
body.search-open .center,
body.search-open .dl-strip { display: none; }
.s-hit { border-top: 1px dashed var(--line); padding: 0.65rem 0; cursor: pointer; }
.s-hit .loc { color: var(--accent-dark); font-size: 0.8rem; }
.s-hit .text { margin: 0.3rem 0 0; color: var(--muted); }
.s-hit-head {
  display: flex; align-items: center; gap: 0.6rem;
}
.s-hit-head .matchbar { width: 4rem; }
.s-hit-body { display: flex; gap: 0.7rem; align-items: flex-start; margin-top: 0.35rem; }
.s-prev { flex-shrink: 0; display: block; }
.s-prev img {
  width: 6.5rem; height: auto; border: 1px solid var(--line);
  border-radius: 3px; box-shadow: 1px 2px 4px rgba(0,0,0,0.15);
  background: var(--thumb-bg); display: block;
  transition: transform 0.12s ease;
}
.s-prev img:hover { transform: scale(1.03); }
.s-hit:hover { background: var(--hover-row); }

/* ---- download strip (below page hint) ---- */
.dl-strip {
  display: flex; align-items: center; justify-content: center;
  gap: 1.1rem; margin-top: 0.35rem;
}
.dl-icon {
  display: inline-flex; align-items: center; gap: 0.45rem;
  font-size: 0.92rem; text-decoration: none; color: var(--accent-dark);
  border: 1px solid var(--accent-dark); border-radius: 6px; background: var(--card);
  padding: 0.45rem 0.9rem; font-family: inherit;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
  transition: background 0.15s ease, transform 0.15s ease;
}
.dl-icon:hover { background: var(--hover-row); transform: translateY(-1px); }
.dl-icon svg { flex-shrink: 0; }
.dl-range-inline {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-size: 0.9rem; color: var(--muted);
}
.dl-range-inline input {
  width: 4.2rem; padding: 0.28rem 0.4rem; font-size: 0.88rem;
  font-family: inherit; border: 1px solid var(--line); border-radius: 4px;
  text-align: center; background: var(--card);
}
.dl-range-inline input::-webkit-outer-spin-button,
.dl-range-inline input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.dl-range-inline input[type=number] { -moz-appearance: textfield; appearance: textfield; }
.dl-range-btn {
  display: inline-flex; align-items: center; gap: 0.35rem;
  color: var(--accent-dark);
}
@media print { .dl-strip { display: none; } }

.page-holder {
  position: relative; background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 0.5rem; min-height: 60vh;
  display: flex; justify-content: center;
}
.page-holder img { max-width: 100%; max-height: 82vh; height: auto; border-radius: 4px; }
.page-holder img.page-img-b { margin-left: 2px; }
.page-holder.book-open {
  display: flex; align-items: center; justify-content: center;
  gap: 0; padding: 0.5rem; background: var(--spine-bg);
  min-height: 0; height: fit-content;   /* wrap the pages, no dangling gutter */
}
/* single page in a spread (cover, last odd page) — no spine */
.page-holder.book-open.book-single::before { content: none; }
/* EPUB (HTML) page: scrollable column, no spread visuals */
.page-holder.epub-open { background: var(--card); }
.page-holder.epub-open::before { content: none; }
.page-holder.book-open.book-single img { max-width: calc(100% - 1rem); }
.page-holder.book-open img {
  height: min(86vh, 62rem);          /* fill the screen height */
  width: auto; max-width: calc(50% - 0.4rem);
  object-fit: contain; border-radius: 3px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* ---- book mode: all-screen ---- */
body.book-on .reader-body,
body.book-on .center,
body.book-on .dl-strip { display: none; }
body.book-on .wrap.reader {
  padding: 0.5rem 1rem 1rem;
  max-width: 100vw;                  /* break out of the text column */
  width: 100vw;
}
body.book-on .page-holder.book-open {
  min-height: calc(100vh - 4.6rem);  /* full viewport minus toolbar */
  height: calc(100vh - 4.6rem);
  align-items: center;
  border-radius: 0;
  border: none;
}
body.book-on .page-holder.book-open img {
  height: calc(100vh - 5.6rem);      /* leave a whisker of margin */
  max-width: calc(50% - 0.4rem);
}
body.book-on .reader-toolbar { margin: 0.35rem 0; }
.epub-content {
  width: 100%; max-width: 52rem; max-height: 84vh; overflow-y: auto;
  padding: 2rem 3rem; line-height: 1.65; font-size: 1.08rem;
  text-align: left;
}
.epub-content h2 { border-bottom: 0; margin: 0 0 0.8rem; }
.epub-content p { margin: 0 0 0.85rem; text-align: justify; hyphens: auto; }
.epub-content img {
  max-width: 100%; height: auto; margin: 0.75rem auto; display: block;
  border-radius: 4px;
}
.epub-content pre {
  background: var(--pre-code-bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 0.7rem 0.9rem; overflow-x: auto; font-size: 0.88rem;
  line-height: 1.45; font-family: ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace;
  margin: 0.8rem 0;
}
.epub-content code {
  font-family: ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace;
  font-size: 0.9em; background: rgba(124, 77, 33, 0.07);
  padding: 0.08em 0.3em; border-radius: 3px;
}
.epub-content pre code { background: none; padding: 0; font-size: 1em; }
.epub-content blockquote {
  margin: 0.8rem 1rem; padding-left: 0.8rem;
  border-left: 3px solid var(--accent); color: var(--muted); font-style: italic;
}
.epub-content h1, .epub-content h2, .epub-content h3 { line-height: 1.3; margin: 1.2rem 0 0.6rem; }
.epub-content table { border-collapse: collapse; margin: 0.8rem 0; }
.epub-content td, .epub-content th {
  border: 1px solid var(--line); padding: 0.3rem 0.55rem; font-size: 0.92rem;
}

/* ---- zoom (PDF): --zoom scales the page; body.zoomed allows panning ---- */
.page-holder { --zoom: 1; }
body.zoomed .page-holder,
body.zoomed .page-holder.book-open {
  overflow: auto;                  /* pan around the enlarged page */
  justify-content: flex-start;
  align-items: flex-start;
}
body.zoomed #page-img, body.zoomed #page-img-b { max-width: none; max-height: none; }
body.zoomed:not(.book-on) #page-img,
body.zoomed:not(.book-on) #page-img-b {
  height: calc(82vh * var(--zoom));
  max-height: none;
}
body.zoomed.book-on .page-holder.book-open #page-img,
body.zoomed.book-on .page-holder.book-open #page-img-b {
  height: calc((100vh - 5.6rem) * var(--zoom));
}

/* ---- zoom control (PDF) ---- */
.zoomctl {
  display: inline-flex; align-items: center; gap: 0.15rem;
  color: var(--muted); white-space: nowrap;
}
.zoomctl svg { margin-right: 0.15rem; }
.zoomctl .zoom-btn { padding: 0.15rem 0.5rem; font-weight: bold; }
.zoomctl .zoom-val {
  min-width: 3.2rem; padding: 0.15rem 0.25rem; font-family: inherit;
  font-size: 0.8rem; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 4px; cursor: pointer;
}
.zoomctl .zoom-val:hover { border-color: var(--accent); }
.tapzone {
  position: absolute; top: 0; bottom: 0; width: 7%; cursor: pointer;
}
.tapzone.left { left: 0; }
.tapzone.right { right: 0; }
.tapzone:hover { background: rgba(124, 77, 33, 0.06); }
.page-progress {
  position: absolute; bottom: 0.5rem; right: 0.75rem;
  font-size: 0.75rem; color: var(--muted); background: rgba(250,247,242,0.85);
  padding: 0.1rem 0.45rem; border-radius: 8px; pointer-events: none;
  z-index: 2;
}
.center { text-align: center; }

/* ---- book rows (thumbnail + title + authors + meta) ---- */
.book-rows { list-style: none; padding: 0; margin: 0.5rem 0; }
.book-row {
  display: flex; align-items: center; gap: 0.4rem;
  border-bottom: 1px solid var(--line);
  padding: 0.45rem 0.5rem;
  transition: background 0.12s ease;
}
.book-row:hover { background: var(--hover-row); }
.book-row:hover .row-title { color: var(--accent-dark); text-decoration: underline; }
.row-main {
  display: flex; align-items: center; gap: 0.9rem; flex: 1;
  min-width: 0; text-decoration: none; color: inherit;
}
.row-thumb {
  width: 42px; height: 60px; object-fit: cover;
  border-radius: 3px; box-shadow: 1px 2px 4px rgba(0,0,0,0.2);
  background: var(--thumb-bg); flex-shrink: 0;
}
.row-text { display: flex; flex-direction: column; min-width: 0; }
.row-title { font-size: 1.02rem; color: var(--ink); }
.row-authors {
  font-size: 0.8rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row-meta {
  font-size: 0.8rem; color: var(--muted);
  white-space: nowrap; flex-shrink: 0; margin-left: auto;
}
.row-act { opacity: 0; transition: opacity 0.12s; }
.book-row:hover .row-act { opacity: 1; }

/* ---- ingest portal — translucent sticky-note feel ---- */
.ingest-head { display: flex; align-items: baseline; gap: 1rem; }
.ingest-head h1 { margin: 0; font-size: 1.8rem; }
.quota { margin-left: auto; font-size: 1.05rem; }
.quota strong { font-size: 1.25rem; }
.panel-title { display: flex; align-items: center; gap: 0.5rem; margin-top: 0; font-size: 1.3rem; }
.panel-title::before { content: ''; }
.upload-row { display: flex; align-items: center; gap: 1.2rem; }
.upload-row input[type="file"] { font-size: 1.1rem; }
.aa-rows .aa-pick { width: 1.5rem; height: 1.5rem; accent-color: var(--accent); flex-shrink: 0; }
.aa-actions {
  position: sticky; bottom: 0.4rem; z-index: 4;
  display: flex; align-items: center; justify-content: flex-end; gap: 0.9rem;
  padding: 0.6rem 0.8rem; margin-top: 0.4rem;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.18);
}
.aa-actions #aa-sel-count { font-size: 1.1rem; }
.aa-actions .btn { font-size: 1.25rem; padding: 0.55rem 1.2rem; }
.ipanel {
  /* sticky note: translucent paper, gently rotated, soft rounded corners */
  background: var(--note-bg);
  backdrop-filter: blur(2px);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 2px 4px 12px rgba(0,0,0,0.10);
  padding: 1.4rem 1.7rem;
  margin: 1.4rem 0;
  transform: rotate(-0.35deg);
}
.ipanel:nth-of-type(2n) { transform: rotate(0.4deg); }
.ipanel .searchbar input[type="search"] { font-size: 1.1rem; padding: 0.6rem 0.85rem; }
.ipanel .searchbar select { font-size: 1.05rem; padding: 0.5rem 0.6rem; font-family: inherit; }
.ipanel .searchbar .btn { font-size: 1.05rem; padding: 0.55rem 1.1rem; }
.ipanel .muted { font-size: 1rem; }
.ipanel .row-title { font-size: 1.15rem; }
.ipanel .row-authors, .ipanel .row-meta { font-size: 0.95rem; }
.ipanel .row-thumb { width: 48px; height: 68px; }
.ipanel .btn.tiny { font-size: 0.9rem; padding: 0.2rem 0.55rem; }
.ipanel .job { font-size: 0.95rem; }
.ipanel .badge { font-size: 0.85rem; }
.ipanel .job pre { font-size: 0.88rem; background: var(--pre-code-bg); }
.ipanel .muted.small { font-size: 0.9rem; }

/* right-edge post-it flag tabs — translucent plastic, like 3M sticky flags */
.ingest-wrap { position: relative; padding-right: 7rem; }
.ingest-flags {
  position: fixed;
  top: 10.5rem;
  right: 0.4rem;
  display: flex; flex-direction: column; gap: 0.7rem;
  z-index: 5;
}
.iflag {
  position: relative;
  writing-mode: vertical-rl;
  padding: 1.3rem 0.95rem 1.6rem;
  min-height: 9.5rem;
  font-family: Georgia, serif; font-size: 1.25rem; color: var(--tab-ink);
  border: none; border-radius: 0 8px 8px 0; cursor: pointer;
  transform: translateX(0.35rem) rotate(1.4deg);
  transform-origin: top right;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  box-shadow: 2px 3px 6px rgba(0,0,0,0.22);
  clip-path: polygon(6% 0, 100% 0, 94% 100%, 0 96%);
  backdrop-filter: saturate(1.05);
}
.iflag:nth-child(1) { background: rgba(233, 178, 162, 0.62); transform: rotate(-2.2deg); }  /* rose plastic   */
.iflag:nth-child(2) { background: rgba(240, 206, 160, 0.62); transform: rotate(1.6deg);  }  /* peach plastic  */
.iflag:nth-child(3) { background: rgba(245, 227, 178, 0.60); transform: rotate(-1.8deg); }  /* pale gold      */
.iflag:nth-child(4) { background: rgba(168, 214, 178, 0.60); transform: rotate(2.1deg);  }  /* mint plastic   */
/* diagonal plastic sheen */
.iflag::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(115deg,
    rgba(255,255,255,0.38) 0%, rgba(255,255,255,0.10) 28%,
    rgba(255,255,255,0) 55%, rgba(0,0,0,0.05) 100%);
  mix-blend-mode: screen;
}
.iflag:hover {
  transform: rotate(0deg) translateX(0);
  box-shadow: 3px 5px 10px rgba(0,0,0,0.3);
  z-index: 2;
}
.iflag.active {
  background: rgba(250, 247, 242, 0.92);
  color: var(--ink); font-weight: bold;
  transform: rotate(0deg) translateX(0.55rem);
  box-shadow: 2px 3px 7px rgba(0,0,0,0.3);
  z-index: 3;
}
.iflag.active::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
  background: linear-gradient(180deg, rgba(124,77,33,0.5), rgba(124,77,33,0.2));
  border-radius: 0 3px 3px 0;
}
.iflag.flag-alert { animation: flagPulse 1.6s ease-in-out infinite; }
@keyframes flagPulse {
  0%, 100% { box-shadow: 2px 3px 6px rgba(0,0,0,0.22); }
  50%      { box-shadow: 2px 3px 10px rgba(163,51,51,0.55); }
}
.flag-badge {
  position: absolute; top: 0.35rem; left: 50%; transform: translateX(-50%);
  min-width: 1.1rem; height: 1.1rem; line-height: 1.1rem;
  background: var(--danger); color: #fff; border-radius: 10px;
  font-size: 0.68rem; font-weight: bold; text-align: center; padding: 0 0.25rem;
}
.flag-badge.pulse { animation: badgePulse 1.6s ease-in-out infinite; }
@keyframes badgePulse { 50% { opacity: 0.55; } }
@media (max-width: 900px) {
  .ingest-wrap { padding-right: 1rem; }
  .ingest-flags { position: static; flex-direction: row; flex-wrap: wrap; margin: 0.75rem 0 1.25rem; }
  .iflag {
    writing-mode: horizontal-tb; min-height: 0; padding: 0.5rem 0.9rem;
    transform: none; clip-path: none; border-radius: 4px;
  }
}
.aa-results table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.aa-results th, .aa-results td { text-align: left; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.aa-results td.t { max-width: 340px; }

/* ---- match bar ---- */
.matchbar {
  display: inline-block; width: 5.5rem; height: 0.45rem;
  background: var(--line); border-radius: 4px; overflow: hidden;
  vertical-align: middle; flex-shrink: 0;
}
.matchfill {
  display: block; height: 100%; width: 0;
  border-radius: 4px; transition: width 0.3s ease;
}
.cover-bar { display: block; width: 100%; margin-top: 0.35rem; height: 0.4rem; }
.cover-loc { display: block; margin-top: 0.15rem; }

/* ---- controlled asymmetry: a hand-set paper surface, not a tilted UI ---- */
.topbar {
  padding-top: 0.85rem;
  box-shadow: 0 2px 0 rgba(0,0,0,0.16);
}
.tab {
  transform: rotate(-1.4deg) translateY(1px);
  border-radius: 3px 5px 2px 6px;
  box-shadow: 1px 2px 3px rgba(0,0,0,0.22), 0 1px 0 rgba(0,0,0,0.12);
}
.tab:nth-child(2) { transform: rotate(1.2deg) translateY(2px); }
.tab:hover { transform: rotate(0deg) translateY(-3px); }
.tab.active { transform: rotate(-0.2deg) translateY(2px); }

.library-page {
  max-width: 1040px;
  padding-top: 2rem;
}
.library-page > .searchbar {
  position: relative;
  padding: 0.45rem 0.55rem;
  margin: 0.65rem 0 1.35rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px 8px 5px 7px;
  box-shadow: 3px 4px 0 rgba(124,77,33,0.08);
  transform: rotate(-0.35deg);
}
.library-page > .searchbar input[type="search"] { background: var(--paper); }
.library-page .view-toggle {
  margin: 0.25rem 0 1.3rem 1.1rem;
  transform: rotate(0.65deg);
}
.library-page h2 {
  border-bottom: 0;
  margin: 1.7rem 0 1.1rem 0.35rem;
  transform: rotate(-0.25deg);
}
.library-page h2::after {
  content: '';
  display: block;
  width: min(13rem, 42%);
  margin-top: 0.45rem;
  border-bottom: 2px solid var(--accent);
  opacity: 0.42;
  transform: rotate(0.55deg);
}
.library-page .results .hit {
  border-radius: 4px 8px 5px 7px;
  box-shadow: 2px 3px 0 rgba(124,77,33,0.07);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.library-page .results .hit:nth-of-type(odd) {
  transform: rotate(-0.28deg) translateX(0.12rem);
}
.library-page .results .hit:nth-of-type(even) {
  transform: rotate(0.32deg) translateX(-0.1rem);
}
.library-page .results .hit:hover {
  transform: rotate(0deg) translateY(-2px);
  box-shadow: 3px 5px 0 rgba(124,77,33,0.11);
}
.library-page .book-rows .book-row {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 3px 7px 5px 8px;
  margin: 0.7rem 0;
  padding: 0.5rem 0.65rem;
  box-shadow: 2px 3px 0 rgba(124,77,33,0.07);
  transition: transform 0.15s ease, background 0.12s ease, box-shadow 0.15s ease;
}
.library-page .book-rows .book-row:nth-child(odd) {
  transform: rotate(-0.42deg) translateX(0.12rem);
}
.library-page .book-rows .book-row:nth-child(even) {
  transform: rotate(0.3deg) translateX(-0.1rem);
}
.library-page .book-rows .book-row:hover {
  transform: rotate(0deg) translateY(-2px);
  box-shadow: 3px 5px 0 rgba(124,77,33,0.12);
}
.library-page .booklist.covers { gap: 1.25rem 1.1rem; }
.library-page .cover-card {
  padding: 0.4rem 0.4rem 0.65rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px 8px 5px 7px;
  box-shadow: 2px 4px 0 rgba(124,77,33,0.08);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.library-page .cover-card:nth-child(odd) { transform: rotate(-0.7deg) translateY(0.15rem); }
.library-page .cover-card:nth-child(even) { transform: rotate(0.55deg) translateY(-0.1rem); }
.library-page .cover-card:hover {
  transform: rotate(0deg) translateY(-4px);
  box-shadow: 3px 6px 0 rgba(124,77,33,0.14);
}
.library-page .cover-card img { border-radius: 3px 5px 3px 4px; }

.ingest-page {
  max-width: 1040px;
  padding-right: 1.25rem;
}
.ingest-page .ingest-head h1 { transform: rotate(-0.65deg); }
.ingest-page .ingest-flags {
  position: static;
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin: 1.2rem 0 1.6rem 0.4rem;
}
.ingest-page .iflag {
  writing-mode: horizontal-tb;
  min-height: 0;
  padding: 0.65rem 1rem 0.75rem;
  font-size: 1rem;
  border: 1px solid rgba(124,77,33,0.18);
  border-radius: 3px 7px 4px 6px;
  clip-path: polygon(1% 4%, 98% 0, 100% 94%, 3% 100%);
  box-shadow: 2px 3px 0 rgba(124,77,33,0.13);
  transform: rotate(-1.15deg) translateY(1px);
}
.ingest-page .iflag:nth-child(2) { transform: rotate(0.85deg) translateY(-2px); }
.ingest-page .iflag:nth-child(3) { transform: rotate(-0.55deg) translateY(1px); }
.ingest-page .iflag:nth-child(4) { transform: rotate(1.05deg) translateY(-1px); }
.ingest-page .iflag:hover {
  transform: rotate(0deg) translateY(-3px);
  box-shadow: 3px 5px 0 rgba(124,77,33,0.16);
}
.ingest-page .iflag.active {
  transform: rotate(-0.2deg) translateY(1px);
  box-shadow: 2px 3px 0 rgba(124,77,33,0.16);
}
.ingest-page .iflag.active::before { display: none; }
.ingest-page .ipanel {
  margin: 1.55rem 0.35rem;
  border-radius: 5px 13px 7px 11px;
  box-shadow: 3px 5px 0 rgba(124,77,33,0.09);
}
.ingest-page .ipanel[data-panel="search"] { transform: rotate(-0.3deg); }
.ingest-page .ipanel[data-panel="upload"] { transform: rotate(0.42deg); }
.ingest-page .ipanel[data-panel="collection"] { transform: rotate(-0.48deg); }
.ingest-page .ipanel[data-panel="jobs"] { transform: rotate(0.26deg); }
.ingest-page .aa-results .book-row {
  margin: 0.55rem 0;
  border: 1px solid var(--line);
  border-radius: 3px 7px 4px 6px;
  box-shadow: 1px 2px 0 rgba(124,77,33,0.06);
}
.ingest-page .aa-results .book-row:nth-child(odd) { transform: rotate(-0.22deg); }
.ingest-page .aa-results .book-row:nth-child(even) { transform: rotate(0.25deg); }
.ingest-page .aa-results .book-row:hover { transform: rotate(0deg) translateY(-1px); }
.ingest-page .job {
  margin: 0.65rem 0;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 4px 8px 5px 7px;
  background: var(--card);
  box-shadow: 1px 2px 0 rgba(124,77,33,0.06);
}
.ingest-page .job:nth-child(odd) { transform: rotate(-0.2deg); }
.ingest-page .job:nth-child(even) { transform: rotate(0.24deg); }

@media (max-width: 700px) {
  .topbar { align-items: flex-start; flex-wrap: wrap; padding: 0.75rem 1rem 0; }
  .brand-block { padding-bottom: 0.25rem; }
  .tabs { width: 100%; margin-left: 0; justify-content: flex-start; flex-wrap: wrap; gap: 0.35rem; }
  .tab, .tab:nth-child(2), .tab.active { transform: none; }
  .library-page, .ingest-page { padding-right: 1rem; }
  .library-page > .searchbar { transform: none; flex-wrap: wrap; }
  .library-page .view-toggle { margin-left: 0; transform: none; }
  .library-page .results .hit,
  .library-page .book-rows .book-row,
  .library-page .cover-card,
  .ingest-page .ipanel,
  .ingest-page .aa-results .book-row,
  .ingest-page .job { transform: none; }
  .ingest-page .ingest-flags { margin-left: 0; gap: 0.45rem; }
  .ingest-page .iflag,
  .ingest-page .iflag:nth-child(2),
  .ingest-page .iflag:nth-child(3),
  .ingest-page .iflag:nth-child(4) { transform: none; }
}
