/* 藏书阁 BookCase — 移动端优先，粉色主色 + 圆角卡片 + 深色模式 */

:root {
  --pink: #ef5f8a;
  --pink-2: #ff8fb4;
  --pink-soft: #ffe4ee;
  --pink-soft-2: #fff1f6;
  --accent: #7c5cff;
  --ok: #2fb37a;
  --warn: #e8912d;
  --danger: #e5484d;

  --bg: #fff7fa;
  --bg-2: #ffeef4;
  --card: #ffffff;
  --card-2: #fffafc;
  --text: #2b2028;
  --text-2: #7a6a74;
  --text-3: #a8969f;
  --line: #f0dfe6;
  --line-2: #f7e9ef;
  --shadow: 0 2px 10px rgba(190, 120, 150, .10);
  --shadow-lg: 0 10px 34px rgba(180, 100, 140, .18);

  --r-lg: 20px;
  --r: 16px;
  --r-sm: 12px;

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

html[data-theme="dark"] {
  --pink: #ff8fb4;
  --pink-2: #ff6f9d;
  --pink-soft: #40202f;
  --pink-soft-2: #2e1a25;
  --accent: #a78bfa;
  --ok: #46c98d;
  --warn: #f0a94a;
  --danger: #ff6369;

  --bg: #16121a;
  --bg-2: #1d1723;
  --card: #221b28;
  --card-2: #291f30;
  --text: #f4ecf1;
  --text-2: #b6a5b1;
  --text-3: #88798a;
  --line: #342a3c;
  --line-2: #2c2234;
  --shadow: 0 2px 10px rgba(0, 0, 0, .35);
  --shadow-lg: 0 12px 36px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}

body { display: flex; flex-direction: column; }

button, input, textarea, select { font: inherit; color: inherit; }
button { border: none; background: none; cursor: pointer; }
input, textarea, select { background: none; border: none; outline: none; }
a { color: var(--pink); }

/* ---------- 顶栏 ---------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 40;
  padding: calc(var(--safe-t) + 12px) 16px 10px;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
  backdrop-filter: blur(8px);
}
.appbar-row { display: flex; align-items: center; gap: 10px; }
.appbar h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: .5px;
}
.appbar .sub { color: var(--text-2); font-size: 12.5px; margin-top: 2px; }
.appbar .spacer { flex: 1; }

.search {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 9px 12px;
  box-shadow: var(--shadow);
}
.search svg { flex: none; opacity: .55; }
.search input { flex: 1; min-width: 0; }

/* ---------- 主体 ---------- */
main.view {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 16px 120px;
  display: none;
}
main.view.active { display: block; }

/* 筛选 chips */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 0 6px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  padding: 6px 13px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text-2);
  font-size: 13px;
  white-space: nowrap;
  transition: .15s;
}
.chip.on {
  background: var(--pink);
  border-color: var(--pink);
  color: #fff;
  font-weight: 600;
}

.meta-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 2px 8px;
  color: var(--text-3);
  font-size: 12.5px;
}
.meta-line .spacer { flex: 1; }
.sortbtn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-2);
  font-size: 12.5px;
}

/* ---------- 图书卡片 ---------- */
.book-list { display: flex; flex-direction: column; gap: 10px; }
.book-card {
  display: flex;
  gap: 12px;
  padding: 10px;
  background: var(--card);
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  align-items: stretch;
  transition: transform .12s;
}
.book-card:active { transform: scale(.985); }

.cover {
  flex: none;
  width: 62px;
  height: 88px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--pink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--pink);
  font-size: 22px;
  position: relative;
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }

.book-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.book-title {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-sub { color: var(--text-2); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-loc {
  margin-top: auto;
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--pink-soft);
  color: var(--pink-2);
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
html[data-theme="dark"] .book-loc { color: var(--pink); }
.book-loc.none { background: var(--line-2); color: var(--text-3); }
.book-flags { display: flex; gap: 5px; margin-top: 4px; flex-wrap: wrap; }
.flag {
  font-size: 11px;
  padding: 1.5px 7px;
  border-radius: 6px;
  background: var(--line-2);
  color: var(--text-2);
}
.flag.reading { background: rgba(124,92,255,.14); color: var(--accent); }
.flag.lent { background: rgba(232,145,45,.16); color: var(--warn); }
.flag.wish { background: rgba(47,179,122,.14); color: var(--ok); }

/* ---------- 空状态 ---------- */
.empty {
  text-align: center;
  padding: 56px 20px;
  color: var(--text-3);
}
.empty .big { font-size: 44px; margin-bottom: 10px; }
.empty p { margin: 4px 0; }
.empty .btn { margin-top: 16px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--r-sm);
  background: var(--pink);
  color: #fff;
  font-weight: 600;
  font-size: 14.5px;
  box-shadow: var(--shadow);
  transition: .15s;
}
.btn:active { transform: scale(.97); }
.btn.ghost {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: none;
}
.btn.soft { background: var(--pink-soft); color: var(--pink-2); box-shadow: none; }
html[data-theme="dark"] .btn.soft { color: var(--pink); }
.btn.danger { background: var(--danger); }
.btn.block { display: flex; width: 100%; }
.btn:disabled { opacity: .5; }

.iconbtn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text-2);
}
.iconbtn:active { transform: scale(.94); }

/* ---------- 底部 Tab ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  padding: 8px 6px calc(var(--safe-b) + 8px);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line-2);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--text-3);
  font-size: 11px;
  padding: 4px 0;
}
.tab.on { color: var(--pink); font-weight: 600; }
.tab svg { width: 22px; height: 22px; }

.fab-wrap { flex: none; width: 76px; display: flex; justify-content: center; }
.fab {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--pink-2), var(--pink));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(232, 90, 140, .4);
  margin-top: -22px;
}
.fab:active { transform: scale(.94); }

/* ---------- 弹层 / Sheet ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(20, 12, 18, .55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.overlay.hidden { display: none; }
.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  background: var(--bg);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: up .22s ease;
}
@keyframes up { from { transform: translateY(24px); opacity: .4; } to { transform: none; opacity: 1; } }

.sheet-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line-2);
  flex: none;
}
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-head .spacer { flex: 1; }
.sheet-body { overflow-y: auto; padding: 14px 16px; flex: 1; }
.sheet-foot {
  flex: none;
  display: flex; gap: 10px;
  padding: 12px 16px calc(var(--safe-b) + 12px);
  border-top: 1px solid var(--line-2);
  background: var(--card-2);
}
.sheet-foot .btn { flex: 1; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 14px; }
.field > label {
  display: block;
  font-size: 12.5px;
  color: var(--text-2);
  margin-bottom: 6px;
  font-weight: 600;
}
.input {
  width: 100%;
  padding: 11px 13px;
  border-radius: var(--r-sm);
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 15px;
}
.input:focus { border-color: var(--pink); }
textarea.input { resize: vertical; min-height: 76px; line-height: 1.6; }
.row2 { display: flex; gap: 10px; }
.row2 > * { flex: 1; min-width: 0; }

.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text-2);
  font-size: 13px;
}
.seg button.on { background: var(--pink); border-color: var(--pink); color: #fff; font-weight: 600; }

/* ---------- 位置树 ---------- */
.place-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.place-item .pi-main { flex: 1; min-width: 0; }
.place-item .pi-name { font-weight: 600; }
.place-item .pi-path { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.place-item .pi-count {
  font-size: 12px; color: var(--pink); font-weight: 700;
  background: var(--pink-soft);
  padding: 3px 9px; border-radius: 999px;
}
html[data-theme="dark"] .place-item .pi-count { color: var(--pink); }
.place-row { display: flex; gap: 8px; margin-top: 8px; }

/* ---------- 扫码 ---------- */
.scan-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  background: #000;
  overflow: hidden;
}
.scan-wrap video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-wrap canvas { display: none; }
.scan-mask {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.scan-box {
  width: 74%;
  height: 30%;
  border: 2px solid var(--pink-2);
  border-radius: 14px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.42);
  position: relative;
}
.scan-box::after {
  content: "";
  position: absolute; left: 8%; right: 8%; top: 50%;
  height: 2px; background: var(--pink-2);
  animation: sweep 1.8s ease-in-out infinite;
  box-shadow: 0 0 12px var(--pink-2);
}
@keyframes sweep { 0%,100% { transform: translateY(-40px); } 50% { transform: translateY(40px); } }
.scan-tip {
  position: absolute; bottom: 14px; left: 0; right: 0;
  text-align: center; color: #fff; font-size: 13px; text-shadow: 0 1px 4px rgba(0,0,0,.6);
  padding: 0 20px;
}
.scan-actions {
  position: absolute; bottom: 46px; left: 0; right: 0;
  display: flex; justify-content: center; gap: 12px;
}
.scan-actions .mini {
  background: rgba(0,0,0,.5);
  color: #fff; border-radius: 999px; padding: 8px 16px; font-size: 13px;
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,.25);
}

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%; bottom: calc(var(--safe-b) + 92px);
  transform: translateX(-50%) translateY(12px);
  z-index: 200;
  background: rgba(35, 22, 30, .94);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: .22s;
  max-width: 86vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 设置项 ---------- */
.group {
  background: var(--card);
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  margin-bottom: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.group-title {
  padding: 11px 14px 6px;
  font-size: 12px;
  color: var(--text-3);
  font-weight: 700;
  letter-spacing: .3px;
}
.cell {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px;
  border-top: 1px solid var(--line-2);
  width: 100%;
  text-align: left;
}
.cell:first-of-type { border-top: none; }
.cell .c-main { flex: 1; min-width: 0; }
.cell .c-title { font-weight: 500; }
.cell .c-desc { font-size: 12px; color: var(--text-3); margin-top: 2px; line-height: 1.45; }
.cell .c-right { color: var(--text-3); font-size: 13px; flex: none; }
.cell .chev { opacity: .35; }

.stat-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin-bottom: 14px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line-2);
  border-radius: var(--r);
  padding: 12px 10px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 21px; color: var(--pink); }
.stat span { font-size: 11.5px; color: var(--text-3); }

/* 详情大图 */
.detail-cover {
  width: 120px; height: 170px;
  border-radius: 12px; overflow: hidden;
  background: var(--pink-soft);
  display: flex; align-items: center; justify-content: center;
  color: var(--pink); font-size: 34px;
  box-shadow: var(--shadow-lg);
  flex: none;
}
.detail-cover img { width: 100%; height: 100%; object-fit: cover; }
.detail-head { display: flex; gap: 14px; margin-bottom: 16px; }
.detail-head .dh-main { flex: 1; min-width: 0; }
.detail-head h3 { margin: 0 0 4px; font-size: 17px; line-height: 1.35; }

.thumb-row { display: flex; gap: 8px; flex-wrap: wrap; }
.thumb {
  position: relative;
  width: 68px; height: 68px; border-radius: 10px; overflow: hidden;
  background: var(--line-2);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .del {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0,0,0,.55); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; line-height: 1;
}

.stars { display: flex; gap: 3px; }
.stars button { font-size: 22px; color: var(--line); line-height: 1; }
.stars button.on { color: #ffb400; }

.hidden { display: none !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--text-3); }
.small { font-size: 12.5px; }

/* 加载中 */
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--line);
  border-top-color: var(--pink);
  animation: spin .8s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
