:root {
  --bg: #faf6f1;
  --card: #fffdf9;
  --primary: #8b6fa9;
  --primary-ink: #5f4876;
  --primary-soft: #efe8f4;
  --text: #2a2521;
  --muted: #6e655b;
  --line: #eae2d8;
  --ok: #5e9a6b;
  --warn: #c99a3c;
  --danger: #c0503f;
  --radius: 18px;
  --tab-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --serif: "Songti SC","STSong","Noto Serif CJK SC","Source Han Serif SC",Georgia,serif;
  --shadow-soft: 0 1px 2px rgba(60,50,40,.05), 0 10px 30px rgba(60,50,40,.06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: calc(var(--tab-h) + var(--safe-b));
}

.app-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--primary);
  color: #fff;
  padding: 14px 16px calc(14px + env(safe-area-inset-top, 0px));
  padding-top: max(14px, env(safe-area-inset-top));
  box-shadow: 0 1px 2px rgba(60,50,40,.06), 0 8px 24px rgba(95,72,118,.18);
}
.app-header h1 { margin: 0; font-size: 19px; font-weight: 600; font-family: var(--serif); letter-spacing: .5px; }

.view { padding: 14px 14px 24px; }

/* 卡片 */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
  box-shadow: var(--shadow-soft);
}
.card-title { font-weight: 600; margin: 0 0 10px; font-size: 15px; }

/* 统计 */
.stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 14px 8px; text-align: center; }
.stat-num { font-size: 22px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* 分类统计 */
.cat-list { display: flex; flex-wrap: wrap; gap: 8px; }
.cat-chip { background: var(--primary-soft); color: var(--primary); padding: 6px 12px; border-radius: 999px; font-size: 13px; }
.cat-chip b { margin-left: 4px; color: var(--text); }

/* 书籍列表 */
.book { display: flex; gap: 12px; align-items: center; }
.book-cover { width: 52px; height: 72px; object-fit: cover; border-radius: 6px; background: var(--line); flex: 0 0 auto; }
.book-cover.ph { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 11px; text-align: center; }
.book-meta { min-width: 0; flex: 1; }
.book-title { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-loc { color: var(--primary); font-size: 12px; margin-top: 2px; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; margin-left: 6px; }
.badge.reading { background: #fff4e0; color: var(--warn); }
.badge.done { background: #e7f8ee; color: var(--ok); }
.badge.borrowed { background: #fdeaea; color: var(--danger); }

/* 位置树 */
.loc-node { padding: 4px 0; }
.loc-row { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--card); border-radius: 10px; margin-bottom: 8px; }
.loc-ico { width: 26px; text-align: center; }
.loc-name { flex: 1; font-weight: 500; }
.loc-count { color: var(--muted); font-size: 12px; }

/* 搜索 */
.search-bar { display: flex; gap: 8px; margin-bottom: 12px; }
.search-bar input { flex: 1; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 15px; background: #fff; }
.search-bar select { padding: 11px 8px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

/* 按钮 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 16px; border: none; border-radius: 10px; font-size: 15px; font-weight: 600; cursor: pointer; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-ghost { background: var(--primary-soft); color: var(--primary); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.link { color: var(--primary); background: none; border: none; font-size: 14px; cursor: pointer; }

/* 底部导航 */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--tab-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: #fff; border-top: 1px solid var(--line);
  display: flex; align-items: stretch;
}
.tab { flex: 1; border: none; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 11px; cursor: pointer; }
.tab.active { color: var(--primary); }
.tab-ico { font-size: 20px; line-height: 1; }
.tab-scan .tab-scan-ico { background: var(--primary); color: #fff; width: 42px; height: 42px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 20px; margin-top: -18px; box-shadow: 0 4px 12px rgba(95,72,118,.35); }

/* 弹窗 */
.modal-root { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.modal-root.hidden, .hidden { display: none !important; }
.sheet { background: #fff; width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); max-height: 92vh; overflow-y: auto; }
.sheet h3 { margin: 4px 0 14px; font-size: 17px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 15px; background: #fff; font-family: inherit;
}
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.sheet-actions { display: flex; gap: 10px; margin-top: 8px; }

/* 扫码层 */
.scanner-layer { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; align-items: center; justify-content: center; }
#scanVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: relative; width: 70%; max-width: 320px; height: 160px; border: 2px solid #fff; border-radius: 12px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); }
.scan-bar { position: absolute; left: 15%; right: 15%; top: 50%; height: 2px; background: var(--primary); animation: scan 1.6s infinite ease-in-out; }
@keyframes scan { 0%,100% { transform: translateY(-70px); } 50% { transform: translateY(70px); } }
.scan-tip { position: absolute; bottom: 90px; width: 100%; text-align: center; color: #fff; font-size: 14px; }
.scan-close { position: absolute; bottom: 36px; left: 50%; transform: translateX(-50%); background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.4); padding: 9px 18px; border-radius: 999px; font-size: 14px; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: rgba(31,35,48,.92); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 60; max-width: 80%; text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; font-size: 14px; }
.section-gap { height: 6px; }
.cover-row { display: flex; gap: 14px; align-items: flex-start; }
.cover-row img { width: 92px; height: 128px; object-fit: cover; border-radius: 8px; background: var(--line); flex: 0 0 auto; }
.kv { display: flex; gap: 8px; font-size: 14px; margin: 3px 0; }
.kv .k { color: var(--muted); flex: 0 0 64px; }
.kv .v { flex: 1; }

/* ===== Family OS 温暖家庭风：衬线标题 + 更松的呼吸感 ===== */
.card-title, .stat-num, .book-title, .sheet h3, .loc-name {
  font-family: var(--serif);
  letter-spacing: .2px;
}
.stat-num { font-weight: 700; }
.book-title { font-weight: 600; }
.tabbar { box-shadow: 0 -1px 2px rgba(60,50,40,.04), 0 -8px 24px rgba(60,50,40,.05); }
