:root {
  --bg: #faf6ef; --card: #fff; --ink: #2b2118; --muted: #7a6b5d; --accent: #8a4b2a; --accent-ink: #fff;
  --line: #e8dfd2; --ok: #2e7d4f; --err: #b3261e; --radius: 14px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.wrap { max-width: 720px; margin: 0 auto; padding: 16px 16px 48px; }
header.top { display: flex; align-items: baseline; gap: 10px; padding: 8px 0 12px; }
header.top a { color: inherit; text-decoration: none; }
header.top h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.02em; }
header.top .tag { color: var(--muted); font-size: .9rem; }
h2 { font-size: 1.15rem; margin: 24px 0 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.btn {
  display: block; width: 100%; text-align: center; border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-ink); font: inherit; font-weight: 600; font-size: 1.1rem;
  padding: 18px 16px; cursor: pointer; text-decoration: none; -webkit-appearance: none;
}
.btn:active { opacity: .85; }
.btn.secondary { background: transparent; color: var(--accent); border: 2px solid var(--accent); padding: 14px 16px; font-size: 1rem; }
.btn[disabled], .btn.disabled { opacity: .5; pointer-events: none; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; font: inherit; padding: 8px 0; cursor: pointer; }
input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.tips { color: var(--muted); font-size: .92rem; margin: 0; padding-left: 1.2em; }
.tips li { margin: 4px 0; }
.hidden { display: none !important; }
.status { display: flex; align-items: center; gap: 12px; }
.spinner { flex: none; width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.error { border-color: var(--err); color: var(--err); }
.notice { color: var(--muted); font-size: .92rem; }
.preview { width: 100%; max-height: 220px; object-fit: cover; border-radius: 10px; margin-bottom: 12px; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 0; padding: 0; list-style: none; }
@media (min-width: 480px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 680px) { .grid { grid-template-columns: repeat(4, 1fr); } }
.book { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.cover { aspect-ratio: 2 / 3; background: #efe6d8; display: flex; align-items: center; justify-content: center; position: relative; }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .25s; }
.cover img.loaded { opacity: 1; }
.cover .ph { padding: 10px; text-align: center; font-weight: 600; color: #6b4f3a; font-size: .95rem; word-break: break-word; }
.book .meta { padding: 8px 10px 10px; }
.book .t { font-weight: 600; font-size: .95rem; line-height: 1.25; }
.book .a { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.unresolved { list-style: none; margin: 0; padding: 0; }
.unresolved li { padding: 8px 0; border-top: 1px solid var(--line); font-size: .92rem; word-break: break-word; }
.unresolved li:first-child { border-top: 0; }
.unresolved small { color: var(--muted); display: block; }
.sharebox { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sharebox a { word-break: break-all; color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
footer { color: var(--muted); font-size: .8rem; text-align: center; margin-top: 32px; }
.parts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { min-width: 28px; height: 28px; padding: 0 6px; border-radius: 99px; border: 1px solid var(--line); background: #f3ece1; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; font-size: .85rem; font-weight: 600; }
.chip.done { background: var(--ok); border-color: var(--ok); color: #fff; }
.chip.reading, .chip.uploading { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.retry { background: #f0c36d; border-color: #f0c36d; color: #5b3d00; }
.chip.error { background: var(--err); border-color: var(--err); color: #fff; }
.parterrs { margin-top: 12px; }
.parterr { color: var(--err); font-size: .92rem; padding: 8px 0; border-top: 1px solid var(--line); }
.parterr:first-child { border-top: 0; }
.parterr .retry { width: auto; display: inline-block; margin-top: 8px; padding: 8px 16px; }
.btn small { display: block; font-weight: 400; font-size: .85rem; margin-top: 4px; opacity: .9; }
.btn.danger { background: transparent; color: var(--err); border: 2px solid var(--err); font-size: 1rem; padding: 14px 16px; margin-top: 12px; }
.clear-link { font-size: .9rem; }
.cleared { background: #e9f4ec; border: 1px solid var(--ok); color: #1f5a37; border-radius: var(--radius); padding: 12px 16px; margin: 12px 0; }
.cleared span { display: block; font-size: .92rem; margin-top: 2px; }
.modal { position: fixed; inset: 0; background: rgba(43, 33, 24, .55); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.modal .sheet { background: var(--card); width: 100%; max-width: 480px; border-radius: 18px 18px 0 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto; }
.modal .sheet h2 { margin-top: 0; }
@media (min-width: 560px) { .modal { align-items: center; } .modal .sheet { border-radius: 18px; } }

/* Search bar above the cover grid: sticks to the top while the shelf scrolls. 16px text so iOS Safari doesn't zoom in on focus. */
.searchbar {
  position: -webkit-sticky; position: sticky; top: 0; z-index: 5;
  margin: 8px -16px 12px; padding: 8px 16px 6px; padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.sb-row { position: relative; }
.sb-input {
  display: block; width: 100%; height: 48px; padding: 0 46px 0 14px; font: inherit; font-size: 16px; color: var(--ink);
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); -webkit-appearance: none; appearance: none;
}
.sb-input:focus { outline: none; border-color: var(--accent); }
.sb-input::-webkit-search-cancel-button, .sb-input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }
.sb-clear {
  position: absolute; right: 2px; top: 2px; width: 44px; height: 44px; border: 0; background: none; color: var(--muted);
  font-size: 28px; line-height: 1; cursor: pointer; border-radius: 50%;
}
.sb-meta { display: flex; align-items: center; gap: 10px; min-height: 36px; font-size: .9rem; color: var(--muted); }
.sb-count { font-weight: 600; }
.sb-jump { border: 0; background: none; color: var(--accent); font: inherit; font-size: .9rem; font-weight: 600; padding: 6px 0; cursor: pointer; }
.sb-sort { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.sb-sort select { font: inherit; font-size: 16px; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; height: 36px; }
.sb-empty { text-align: center; padding: 28px 8px; color: var(--muted); }
.sb-empty strong { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: 6px; word-break: break-word; }
mark { background: #ffe08a; color: inherit; border-radius: 3px; padding: 0 1px; }
.unmatched-wrap { scroll-margin-top: 130px; }
@media (max-width: 440px) { .sb-sortword { display: none; } }
.sb-count, .sb-jump { white-space: nowrap; }
.sb-sort select { max-width: 140px; }
.unresolved li.first { border-top: 0; }

/* Tap to fix: tappable unmatched spines, the bottom sheet with suggestions, and the toast. */
.unresolved li.tap { cursor: pointer; padding: 12px 28px 12px 0; position: relative; -webkit-tap-highlight-color: rgba(138, 75, 42, .15); min-height: 44px; }
.unresolved li.tap::after { content: "›"; position: absolute; right: 4px; top: 50%; transform: translateY(-50%); color: var(--accent); font-size: 1.5rem; line-height: 1; }
.unresolved li.tap:active { background: #f3ece1; }
.unresolved li.tap:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.unresolved li.lowq { color: var(--muted); font-style: italic; }
.hidden-reads { margin: 8px 2px 0; }
.hidden-reads .link { padding: 4px 0 4px 4px; }
.fix .rawtext { margin: 0 0 12px; padding: 10px 12px; background: #f3ece1; border-radius: 10px; word-break: break-word; font-size: .95rem; }
.fix-status { padding: 10px 0; }
.sugglist { list-style: none; margin: 0 0 12px; padding: 0; }
.sugglist li { margin: 0 0 8px; }
.sg { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px 8px 8px; font: inherit; color: var(--ink); cursor: pointer; -webkit-appearance: none; }
.sg:active { background: #f3ece1; }
.sg-cover { flex: none; position: relative; width: 40px; height: 60px; border-radius: 4px; background: #efe6d8; display: flex; align-items: center; justify-content: center; color: #6b4f3a; font-weight: 700; overflow: hidden; }
.sg-cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .25s; }
.sg-cover img.loaded { opacity: 1; }
.sg-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sg-title { font-weight: 600; line-height: 1.25; }
.sg-author { color: var(--muted); font-size: .88rem; }
.sg-add { flex: none; color: var(--accent); font-weight: 700; }
.fix-search { display: flex; gap: 8px; margin: 4px 0 12px; }
.fix-search input { flex: 1; min-width: 0; height: 48px; padding: 0 14px; font: inherit; font-size: 16px; color: var(--ink); background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); -webkit-appearance: none; appearance: none; }
.fix-search input:focus { outline: none; border-color: var(--accent); }
.fix-search .btn { width: auto; padding: 0 18px; height: 48px; }
.fix .btn.danger { margin-top: 4px; }
.fix .btn.danger.armed { background: var(--err); color: #fff; }
.modal.busy .sheet { opacity: .7; }
body.sheet-open { overflow: hidden; }
.toast { position: fixed; left: 12px; right: 12px; bottom: calc(16px + env(safe-area-inset-bottom)); max-width: 480px; margin: 0 auto; background: #2b2118; color: #fff; padding: 12px 16px; border-radius: 12px; z-index: 20; box-shadow: 0 4px 16px rgba(0, 0, 0, .3); }
/* Accounts and lending (ADR-012). */
.wrap.narrow { max-width: 560px; }
header.top .acct { margin-left: auto; display: flex; gap: 12px; align-items: baseline; font-size: .92rem; }
header.top .acct a { color: var(--accent); text-decoration: underline; }
header.top .acct .link { padding: 0; font-size: .92rem; }
header.top .acct a.forge { background: var(--accent); color: var(--accent-ink); text-decoration: none; font-weight: 600; padding: 6px 12px; border-radius: 99px; white-space: nowrap; }
.lede { margin: -4px 0 8px; font-size: 1.02rem; }
.libcard { margin: 12px 0; }
.libcard img { display: block; width: 100%; height: auto; aspect-ratio: 856 / 540; border-radius: 16px; box-shadow: 0 6px 20px rgba(43, 33, 24, .18); background: var(--line); }
.libcard .cardlinks { display: flex; gap: 16px; margin-top: 8px; font-size: .92rem; }
.libcard .cardlinks a, .libcard .cardlinks .link { color: var(--accent); padding: 0; }
.forged h2 { margin-top: 8px; }
.tabs { display: flex; gap: 8px; margin: 8px 0; }
.tab { flex: 1; border: 2px solid var(--accent); background: transparent; color: var(--accent); border-radius: var(--radius); padding: 10px; font: inherit; font-weight: 600; cursor: pointer; }
.tab.on { background: var(--accent); color: var(--accent-ink); }
.form label { display: block; margin: 0 0 12px; font-weight: 600; font-size: .95rem; }
.form label small { font-weight: 400; color: var(--muted); }
.form input, .form textarea, select { display: block; width: 100%; margin-top: 4px; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.formerr { color: var(--err); font-size: .92rem; }
.pill { display: inline-block; font-size: .8rem; font-weight: 600; padding: 2px 10px; border-radius: 99px; background: #f3ece1; color: var(--accent); margin-top: 4px; }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700; letter-spacing: .08em; margin-top: 4px; }
.copyhead { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 8px; }
.cover.small { width: 84px; flex: none; border-radius: 8px; overflow: hidden; }
.cover.small img { opacity: 1; }
#actions .btn, .lend .btn { margin-top: 10px; }
.history { margin: 0; padding-left: 1.2em; }
.history li { margin: 6px 0; }
.history small { display: block; color: var(--muted); }
.loans { list-style: none; margin: 0; padding: 0; }
.loan .loanhead { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.loan .lt { font-weight: 700; color: var(--ink); }
.loan blockquote { margin: 8px 0; padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); }
.loan .address { background: #faf6ef; border: 1px dashed var(--line); border-radius: 10px; padding: 8px 12px; margin-top: 8px; }
.loan .address small { color: var(--muted); }
.pre { white-space: pre-line; }
.loan .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.loan .actions .btn { width: auto; flex: 1 1 auto; padding: 10px 14px; font-size: .95rem; }
.empty.small { padding: 8px 0; text-align: left; }
.book.tap { cursor: pointer; }
.book .lendtag { font-size: .75rem; font-weight: 600; color: var(--accent); padding: 0 10px 8px; }
.lend .copyrow { border-top: 1px solid var(--line); padding: 10px 0; }
.lend .copyrow:first-of-type { border-top: 0; }
header.top h1 { white-space: nowrap; }
@media (max-width: 520px) { header.top:has(.acct) .tag { display: none; } }
.lend a.code { color: var(--accent); }

/* Floating library card. Phones and mid-size screens: a small tilted card at the end of the page, in the normal flow (it can't
   cover anything). Wide screens: fixed in the right margin, outside the content column. Only the card itself takes clicks. */
.floatcard { display: block; width: 128px; margin: 0 auto 36px; transform: rotate(-5deg); border-radius: 9px; line-height: 0; }
.floatcard img { display: block; width: 100%; height: auto; aspect-ratio: 856 / 540; border-radius: 9px; box-shadow: 0 6px 16px rgba(43, 33, 24, .2); }
.floatcard:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
@media (min-width: 1160px) {
  .floatcard { position: fixed; right: 32px; bottom: 44px; width: 172px; margin: 0; z-index: 5; }
}
@media (min-width: 1000px) {
  body:has(.wrap.narrow) .floatcard { position: fixed; right: 32px; bottom: 44px; width: 164px; margin: 0; z-index: 5; }
}
@media (prefers-reduced-motion: no-preference) {
  .floatcard { animation: floatcard-drift 17s ease-in-out infinite; }
  .floatcard img { animation: floatcard-shadow 17s ease-in-out infinite; }
  .floatcard:hover { animation-play-state: paused; }
  .floatcard:hover img { animation-play-state: paused; }
}
@keyframes floatcard-drift {
  0%, 100% { transform: translate(0, 0) rotate(-6deg); }
  30% { transform: translate(-5px, -9px) rotate(-2.5deg); }
  65% { transform: translate(4px, -4px) rotate(-8deg); }
}
@keyframes floatcard-shadow {
  0%, 100% { box-shadow: 0 6px 16px rgba(43, 33, 24, .2); }
  30% { box-shadow: 0 14px 26px rgba(43, 33, 24, .16); }
  65% { box-shadow: 0 9px 20px rgba(43, 33, 24, .19); }
}

/* Cross-shelf search (home form and /search.html). 16px text so iOS Safari does not zoom on focus. */
.sitesearch { display: flex; gap: 8px; margin: 8px 0 16px; align-items: stretch; }
.sitesearch input {
  flex: 1; min-width: 0; height: 48px; padding: 0 14px; font: inherit; font-size: 16px; color: var(--ink);
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); -webkit-appearance: none; appearance: none;
}
.sitesearch input:focus { outline: none; border-color: var(--accent); }
.sitesearch .btn { width: auto; padding: 0 18px; height: 48px; flex: none; }
.hits { list-style: none; margin: 0; padding: 0; }
.hit { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 0 0 12px; }
.hithead { display: flex; gap: 12px; align-items: flex-start; }
.hit .cover { flex: none; width: 56px; height: 84px; border-radius: 4px; background: #efe6d8; display: flex; align-items: center; justify-content: center; color: #6b4f3a; font-weight: 700; overflow: hidden; position: relative; }
.hit .cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.hitmeta { flex: 1; min-width: 0; }
.hit-title { font-weight: 700; line-height: 1.25; margin: 0; font-size: 1.05rem; }
.hit-author, .hit-isbn { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.hit-avail { margin-top: 6px; }
.holds { list-style: none; margin: 10px 0 0; padding: 0; border-top: 1px solid var(--line); }
.hold { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: baseline; padding: 8px 0 0; font-size: .95rem; }
.hold a { color: var(--accent); }
.hold .copies { display: flex; flex-wrap: wrap; gap: 8px; }
.hold .copies a { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .88rem; letter-spacing: .04em; }
.search-empty { text-align: center; padding: 28px 8px; color: var(--muted); }
.search-empty strong { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: 6px; word-break: break-word; }
.search-more { margin: 8px 0 16px; }
.search-err { margin-top: 12px; }

/* Owner-only switch on /s/{id}: include this shelf in cross-shelf search. */
.share-public { margin: 0 0 16px; }
.share-public-label { display: flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }
.share-public-label input { width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--accent); }
.share-public .notice { margin: 6px 0 0; }
.share-public .formerr { margin: 6px 0 0; }
