:root {
  --bg: #fbf7f0;
  --card: #ffffff;
  --soft: #f3ede2;
  --ink: #23312d;
  --muted: #66716d;
  --line: #e6ddcf;
  --brand: #1f6f5c;
  --brand-ink: #ffffff;
  --brand-soft: #e2f0eb;
  --ok: #1f7a4d;
  --ok-soft: #dff3e7;
  --wait: #9a5b00;
  --wait-soft: #fcefd8;
  --no: #7b7f86;
  --no-soft: #eeeff1;
  --heart: #c2415b;
  --c1: #e07a5f; --c2: #3d8b73; --c3: #f2b84b;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(35,49,45,.06), 0 4px 16px rgba(35,49,45,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151a19; --card: #1d2422; --soft: #232b29; --ink: #eef2ef; --muted: #a2aca8; --line: #313b38;
    --brand: #5cc3a6; --brand-ink: #0d1b17; --brand-soft: #1f3a33;
    --ok: #6fd39c; --ok-soft: #1b3326; --wait: #f2b765; --wait-soft: #3a2d17; --no: #9aa1a8; --no-soft: #2a2f33;
    --heart: #f07b93; --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 "Nunito Sans", system-ui, -apple-system, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
h1, h2, h3 { font-family: Fraunces, Georgia, serif; line-height: 1.15; margin: 0 0 .35em; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
a { color: var(--brand); }
code { font-size: .8rem; background: var(--soft); padding: 2px 5px; border-radius: 6px; word-break: break-all; }

.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font: 700 1.2rem Fraunces, serif; }
.logo { width: 28px; height: 28px; }
.scope {
  display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 6px 12px; font: inherit; font-size: .85rem; max-width: 58vw; cursor: pointer;
}
.scope-label { color: var(--muted); }
.scope-value { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

main { max-width: 640px; margin: 0 auto; padding: 16px; }
.tab { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
.page-h { margin: 6px 0 14px; }
.intro { padding: 8px 2px 14px; }
.intro p { color: var(--muted); margin: 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card.soft { background: var(--soft); box-shadow: none; }
.row { display: flex; align-items: center; }
.between { justify-content: space-between; }
.gap { gap: 8px; } .wrap { flex-wrap: wrap; } .grow { flex: 1; }
.hint { color: var(--muted); font-size: .9rem; margin: 4px 0 10px; }
.center { text-align: center; }
.note { background: var(--wait-soft); color: var(--wait); border-radius: 10px; padding: 8px 10px; font-size: .88rem; margin: 10px 0 0; }

textarea, input:not([type=checkbox]):not([type=radio]) {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; outline: none; resize: vertical;
}
textarea:focus, input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.input-card textarea { margin-bottom: 10px; min-height: 96px; }
.field { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 10px; }
.field input, .field textarea { margin-top: 4px; font-weight: 400; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px;
  border-radius: 12px; border: 1px solid transparent; font: 700 .95rem "Nunito Sans", sans-serif; cursor: pointer;
  background: var(--soft); color: var(--ink); -webkit-tap-highlight-color: transparent; text-decoration: none;
}
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .85rem; }
.btn.block { width: 100%; margin-top: 6px; }
.btn.danger { color: var(--heart); }
.btn:disabled { opacity: .55; cursor: default; }
.btn:active:not(:disabled) { transform: scale(.98); }
.link { background: none; border: 0; color: var(--brand); font: 700 .9rem inherit; font-family: inherit; cursor: pointer; padding: 6px; }

.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumbs:not(:empty) { margin-bottom: 10px; }
.thumb { position: relative; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 14px; line-height: 1; cursor: pointer; }

.title-list { list-style: none; margin: 0 0 8px; padding: 0; }
.title-list li { display: grid; grid-template-columns: 24px 1fr 32px; gap: 8px; align-items: start; padding: 8px 0; border-top: 1px solid var(--line); }
.title-list li:first-child { border-top: 0; }
.title-list input[type=checkbox] { width: 20px; height: 20px; margin-top: 10px; accent-color: var(--brand); }
.title-list .t-in { display: grid; gap: 4px; }
.title-list .t-in input { padding: 7px 10px; }
.title-list .t-in input.author { font-size: .88rem; color: var(--muted); }
.title-list .rm { border: 0; background: none; color: var(--muted); font-size: 20px; cursor: pointer; margin-top: 4px; }

.results { display: grid; gap: 12px; }
.book { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.book-main { display: grid; grid-template-columns: 64px 1fr; gap: 12px; padding: 14px; }
.cover {
  width: 64px; height: 90px; border-radius: 6px; overflow: hidden; display: grid; place-items: center; text-align: center;
  font: 700 .62rem/1.15 Fraunces, serif; color: #fff; padding: 6px; background: var(--c2); box-shadow: inset -4px 0 0 rgba(0,0,0,.12);
}
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover.has-img { padding: 0; }
.book h3 { margin: 0 0 2px; font-size: 1.05rem; }
.book .by { color: var(--muted); font-size: .88rem; margin: 0 0 8px; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: .84rem; font-weight: 700; }
.status.ok { background: var(--ok-soft); color: var(--ok); }
.status.wait { background: var(--wait-soft); color: var(--wait); }
.status.no { background: var(--no-soft); color: var(--no); }
.status.loading { background: var(--soft); color: var(--muted); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.where { font-size: .88rem; margin: 6px 0 0; }
.reason { font-size: .88rem; color: var(--muted); font-style: italic; margin: 6px 0 0; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.tag { font-size: .72rem; padding: 2px 8px; border-radius: 999px; background: var(--soft); color: var(--muted); }
.book-actions { display: flex; border-top: 1px solid var(--line); }
.book-actions button, .book-actions a {
  flex: 1; min-height: 44px; border: 0; background: none; color: var(--ink); font: 700 .82rem "Nunito Sans", sans-serif;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px; cursor: pointer; text-decoration: none;
  border-left: 1px solid var(--line);
}
.book-actions > :first-child { border-left: 0; }
.book-actions svg { width: 16px; height: 16px; }
.book-actions .on { color: var(--heart); }
.book-actions .on-loved { color: var(--ok); }
.copies { padding: 0 14px 12px; }
.copies summary { cursor: pointer; font-size: .85rem; color: var(--brand); font-weight: 700; padding: 4px 0; }
.copies table { width: 100%; border-collapse: collapse; font-size: .84rem; margin-top: 6px; }
.copies td { padding: 5px 4px; border-top: 1px solid var(--line); vertical-align: top; }
.copies td:last-child { text-align: right; white-space: nowrap; }
.copies .ed { font-size: .8rem; color: var(--muted); margin: 10px 0 0; }
.muted { color: var(--muted); }

.trip { display: grid; gap: 8px; margin-bottom: 14px; }
.trip-row { display: flex; justify-content: space-between; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.trip-row b { font-size: 1.3rem; font-family: Fraunces, serif; color: var(--ok); }
.trip-row.best { border-color: var(--ok); background: var(--ok-soft); }
.plain { list-style: none; padding: 0; margin: 8px 0 0; }
.plain li { padding: 6px 0; border-top: 1px solid var(--line); font-size: .92rem; }
details > summary { cursor: pointer; font-weight: 700; }

.taste { display: flex; flex-wrap: wrap; gap: 6px; }
.taste .tag { font-size: .82rem; background: var(--brand-soft); color: var(--brand); }
.taste p { margin: 0; color: var(--muted); font-size: .9rem; }

.lib { border-top: 1px solid var(--line); padding: 10px 0; }
.lib:first-of-type { border-top: 0; }
.lib-head { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.lib-head input, .branch input { width: 20px; height: 20px; accent-color: var(--brand); }
.branches { display: grid; gap: 2px; margin: 6px 0 0 30px; }
.branch { display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 6px; font-size: .92rem; min-height: 36px; }
.home-pick { font-size: .78rem; border: 1px solid var(--line); background: none; color: var(--muted); border-radius: 999px; padding: 3px 10px; cursor: pointer; font-family: inherit; }
.home-pick.is-home { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 700; }
.add-lib { margin-top: 10px; }
.add-lib summary { color: var(--brand); font-size: .92rem; }
.steps { padding-left: 20px; margin: 6px 0; font-size: .92rem; }
.steps li { margin-bottom: 6px; }

.scope-sheet { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.35); display: flex; align-items: flex-start; justify-content: center; padding: 70px 16px 16px; }
.sheet-card { background: var(--card); border-radius: var(--radius); padding: 16px; width: 100%; max-width: 440px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.scope-options { display: grid; gap: 8px; margin: 10px 0 4px; }
.scope-opt { text-align: left; border: 1.5px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 12px; padding: 10px 12px; font: inherit; cursor: pointer; }
.scope-opt b { display: block; }
.scope-opt span { font-size: .85rem; color: var(--muted); }
.scope-opt.sel { border-color: var(--brand); background: var(--brand-soft); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; border: 0; background: none;
  color: var(--muted); font: 700 .72rem "Nunito Sans", sans-serif; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.tabs svg { width: 24px; height: 24px; }
.tabs button.active { color: var(--brand); }
.badge { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 18px; height: 18px; border-radius: 9px; background: var(--heart); color: #fff; font-size: .68rem; display: grid; place-items: center; padding: 0 5px; }

.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .9rem; font-weight: 600; max-width: calc(100vw - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.empty h3 { color: var(--ink); }

/* Library trip / shelf list */
button.trip-row { width: 100%; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.trip-head { margin-bottom: 12px; }
.trip-head h2 { font-size: 1.45rem; margin-top: 4px; }
.shelf-group h3 { margin-bottom: 0; }
.shelf { list-style: none; margin: 6px 0 0; padding: 0; }
.shelf li { border-top: 1px solid var(--line); }
.shelf label { display: grid; grid-template-columns: 26px minmax(92px, auto) 1fr; gap: 10px; align-items: center; padding: 12px 0; cursor: pointer; }
.shelf input { width: 22px; height: 22px; accent-color: var(--ok); }
.call { font: 700 1.05rem/1.2 ui-monospace, "SF Mono", Menlo, monospace; background: var(--wait-soft); color: var(--ink); padding: 6px 8px; border-radius: 8px; text-align: center; letter-spacing: .02em; }
.shelf-title { font-weight: 700; line-height: 1.25; }
.shelf-title small { display: block; font-weight: 400; color: var(--muted); font-size: .84rem; }
.shelf li.got .shelf-title, .shelf li.got .call { opacity: .45; text-decoration: line-through; }

.thumb.vid { display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: .75rem; width: 76px; }
