:root {
  --bg: #f3efe6;
  --bg-2: #ece5d8;
  --panel: #fffdf8;
  --ink: #241f19;
  --ink-2: #5b5145;
  --ink-3: #948877;
  --line: rgba(61, 46, 30, 0.12);
  --accent: #a8452a;
  --accent-soft: rgba(168, 69, 42, 0.1);
  --jade: #2f6b5f;
  --radius: 14px;
  --sans: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", SimSun, serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(120% 60% at 0% 0%, rgba(181, 138, 82, 0.14), transparent 60%),
    linear-gradient(180deg, #f7f2e8, #efe9dc);
}

button {
  border: none;
  background: none;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  padding: 0;
}

input {
  font-family: inherit;
}

[hidden] {
  display: none !important;
}

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
}

.topbar {
  flex: none;
  height: calc(54px + var(--safe-top));
  padding: var(--safe-top) 16px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(250, 246, 238, 0.86);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(150deg, #2a231c, #4a2f1f);
  color: #f3e8d5;
  font-family: var(--serif);
  font-size: 16px;
}
.brand-name {
  font-family: var(--serif);
  font-size: 17px;
  letter-spacing: 0.16em;
}

.conn {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--ink-3);
  max-width: 48%;
}
.conn i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #bfa06a;
  flex: none;
}
.conn.online i {
  background: #3f8c6b;
  box-shadow: 0 0 0 3px rgba(63, 140, 107, 0.15);
}
.conn.offline i {
  background: #b04a38;
}
.conn span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.view {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 14px calc(78px + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
}

.tabbar {
  flex: none;
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 760px;
  height: calc(58px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: rgba(255, 253, 248, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(14px);
  z-index: 20;
}
.tabbar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10.5px;
  color: var(--ink-3);
}
.tabbar button.active {
  color: var(--accent);
  font-weight: 600;
}
.tab-ico {
  font-size: 15px;
  line-height: 1;
}

/* ---------- shelf ---------- */
.hero {
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  padding: 16px 18px;
  margin-bottom: 14px;
  color: #f5eddd;
  background: linear-gradient(125deg, var(--c1, #2f4f4a), var(--c2, #152a27));
  box-shadow: 0 12px 26px rgba(40, 28, 15, 0.16);
}
.offline-bar {
  display: block;
  width: 100%;
  margin-bottom: 12px;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(176, 74, 56, 0.1);
  border: 1px solid rgba(176, 74, 56, 0.18);
  color: #9b4334;
  font-size: 11px;
  text-align: center;
}
.hero .eyebrow {
  font-size: 10px;
  letter-spacing: 0.2em;
  opacity: 0.65;
}
.hero h2 {
  margin: 6px 0 4px;
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.45;
  font-weight: 600;
}
.hero p {
  margin: 0 0 12px;
  font-size: 11px;
  opacity: 0.75;
}
.hero .btn {
  background: rgba(255, 255, 255, 0.14);
  color: #fff8ec;
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border-radius: 9px;
  font-size: 12.5px;
  background: rgba(61, 46, 30, 0.06);
  color: var(--ink-2);
}
.btn.primary {
  background: linear-gradient(160deg, #b04c2e, #92381f);
  color: #fff6ea;
}
.btn.block {
  width: 100%;
}
.btn:active {
  opacity: 0.82;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 16px 2px 10px;
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: 0.08em;
}
.section-title strong {
  font-family: var(--serif);
  font-size: 17px;
  color: var(--ink);
  letter-spacing: 0;
}
.section-title .count {
  font-size: 10.5px;
  color: var(--ink-3);
  margin-left: auto;
}
.sort-toggle {
  margin-left: 8px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 10px;
  color: var(--ink-3);
  background: rgba(61, 46, 30, 0.06);
  white-space: nowrap;
}
.sort-toggle.active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.chips {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 2px 2px 10px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar {
  display: none;
}
.chip {
  flex: none;
  height: 28px;
  padding: 0 11px;
  border-radius: 999px;
  font-size: 11.5px;
  color: var(--ink-2);
  background: rgba(61, 46, 30, 0.055);
}
.chip.active {
  background: #262019;
  color: #f5ecdc;
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px 12px;
}
.card {
  min-width: 0;
  content-visibility: auto;
  contain-intrinsic-size: 210px;
}
.cover {
  position: relative;
  aspect-ratio: 0.7;
  border-radius: 4px 9px 9px 4px;
  background: linear-gradient(152deg, var(--c1), var(--c2));
  color: #f3e9d6;
  overflow: hidden;
  box-shadow: 0 8px 16px rgba(30, 20, 10, 0.18), inset 0 0 0 1px rgba(255, 255, 255, 0.07);
}
.cover::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 6px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.32), rgba(255, 255, 255, 0.06));
}
.cover-title {
  position: absolute;
  top: 30px;
  right: 10px;
  height: calc(100% - 66px);
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.1em;
  line-height: 1.2;
  overflow: hidden;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.28);
}
.cover-cat {
  position: absolute;
  left: 10px;
  top: 8px;
  max-width: calc(100% - 20px);
  font-size: 8px;
  padding: 2px 5px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  color: rgba(255, 248, 235, 0.86);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cover-author {
  position: absolute;
  left: 10px;
  bottom: 8px;
  max-width: calc(100% - 18px);
  font-size: 8.5px;
  opacity: 0.72;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.cover-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.16);
}
.cover-progress i {
  display: block;
  height: 100%;
  background: #e0a86f;
}
.card h3 {
  margin: 7px 2px 2px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card p {
  margin: 0 2px;
  font-size: 9.5px;
  color: var(--ink-3);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.card:active .cover {
  transform: scale(0.98);
}
.cover {
  transition: transform 0.15s ease;
}

.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--ink-3);
  font-size: 12.5px;
  line-height: 1.9;
}
.empty .empty-mark {
  width: 54px;
  height: 54px;
  margin: 0 auto 14px;
  border-radius: 50%;
  border: 1px dashed var(--line);
  display: grid;
  place-items: center;
  font-size: 20px;
}

/* ---------- search ---------- */
.search-box {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.search-box input {
  flex: 1;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 0 12px;
  font-size: 13px;
  color: var(--ink);
  outline: none;
}
.search-box input:focus {
  border-color: rgba(168, 69, 42, 0.45);
}
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--ink-3);
  margin-bottom: 10px;
}
.hits {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.hit {
  padding: 11px 12px;
  border-radius: 11px;
  background: var(--panel);
  border: 1px solid var(--line);
  text-align: left;
}
.hit .hit-book {
  font-size: 11.5px;
  color: var(--accent);
  font-weight: 600;
}
.hit .hit-chapter {
  font-size: 10.5px;
  color: var(--ink-3);
  margin-left: 6px;
}
.hit .hit-snippet {
  margin-top: 5px;
  font-family: var(--serif);
  font-size: 12px;
  line-height: 1.8;
  color: var(--ink-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.hit mark {
  background: rgba(214, 160, 60, 0.3);
  color: inherit;
  border-radius: 2px;
}

/* ---------- me ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.panel h3 {
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--ink-3);
  font-weight: 500;
}
.kv {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-size: 12px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--line);
}
.kv:last-of-type {
  border-bottom: none;
}
.kv span {
  color: var(--ink-3);
  flex: none;
}
.kv em {
  font-style: normal;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}
.theme-row {
  display: flex;
  gap: 8px;
}
.theme-dot {
  flex: 1;
  height: 38px;
  border-radius: 9px;
  border: 2px solid transparent;
  display: grid;
  place-items: center;
  font-size: 11px;
  color: var(--ink-2);
}
.theme-dot.active {
  border-color: var(--accent);
}
.row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.row .btn {
  flex: 1;
}
.hint {
  font-size: 11px;
  line-height: 1.8;
  color: var(--ink-3);
}

/* ---------- connect ---------- */
.connect {
  padding: 8vh 22px 0;
  text-align: center;
}
.connect h2 {
  font-family: var(--serif);
  font-size: 24px;
  margin: 0 0 8px;
}
.connect p {
  font-size: 12px;
  color: var(--ink-3);
  line-height: 1.9;
  margin: 0 0 22px;
}
.connect input {
  width: 100%;
  height: 44px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 0 12px;
  font-size: 13px;
  margin-bottom: 10px;
  outline: none;
}
.connect .btn {
  height: 44px;
  width: 100%;
  border-radius: 11px;
}

/* ---------- reader ---------- */
.reader {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  background: var(--r-bg);
  color: var(--r-ink);
  --r-font: var(--serif);
}
.reader[data-theme="paper"] {
  --r-bg: #f3ead8;
  --r-ink: #3a3129;
  --r-muted: #8c7c64;
  --r-line: rgba(90, 70, 40, 0.16);
  --r-accent: #a8452a;
  --r-panel: #f8f0e0;
}
.reader[data-theme="light"] {
  --r-bg: #fbfaf6;
  --r-ink: #262320;
  --r-muted: #8c857a;
  --r-line: rgba(40, 35, 28, 0.12);
  --r-accent: #a8452a;
  --r-panel: #ffffff;
}
.reader[data-theme="green"] {
  --r-bg: #dfe9d8;
  --r-ink: #2c3a2b;
  --r-muted: #6c7d68;
  --r-line: rgba(44, 58, 43, 0.16);
  --r-accent: #4a6b48;
  --r-panel: #eaf1e4;
}
.reader[data-theme="dark"] {
  --r-bg: #14120f;
  --r-ink: #cdc4b4;
  --r-muted: #7d7466;
  --r-line: rgba(255, 255, 255, 0.08);
  --r-accent: #d99a6c;
  --r-panel: #1c1916;
}
.reader-bar {
  flex: none;
  height: calc(50px + var(--safe-top));
  padding: var(--safe-top) 10px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--r-line);
  background: color-mix(in srgb, var(--r-bg) 88%, transparent);
  backdrop-filter: blur(10px);
  z-index: 3;
}
.reader-bar .icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 16px;
  color: var(--r-ink);
  opacity: 0.8;
  flex: none;
}
.reader-bar .icon-btn:active {
  background: color-mix(in srgb, var(--r-ink) 9%, transparent);
}
.reader-title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.reader-title strong {
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.reader-title span {
  font-size: 10px;
  color: var(--r-muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.reader-tools {
  display: flex;
  gap: 2px;
  flex: none;
}
.reader-tools button {
  height: 30px;
  padding: 0 8px;
  border-radius: 7px;
  font-size: 11px;
  color: var(--r-muted);
}
.reader-tools button:active {
  background: color-mix(in srgb, var(--r-ink) 8%, transparent);
}
.reader-scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 22px 20px 100px;
  scroll-behavior: smooth;
}
.reader-page {
  max-width: 720px;
  margin: 0 auto;
  font-family: var(--r-font);
  font-size: var(--r-fs, 19px);
  line-height: 1.9;
}
.page-eyebrow {
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--r-muted);
  margin-bottom: 12px;
}
.page-title {
  margin: 0 0 26px;
  font-size: 1.5em;
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.03em;
  line-height: 1.5;
}
.page-body p {
  margin: 0 0 0.62em;
  text-indent: 2em;
  text-align: justify;
  word-break: break-word;
}
.page-end {
  margin: 40px 0 8px;
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--r-muted);
}
.reader-foot {
  flex: none;
  height: calc(52px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--r-line);
  background: color-mix(in srgb, var(--r-bg) 90%, transparent);
  backdrop-filter: blur(10px);
  padding-left: 12px;
  padding-right: 12px;
}
.reader-foot button {
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--r-line);
  font-size: 11.5px;
  color: var(--r-muted);
  flex: none;
}
.foot-mid {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  justify-content: center;
}
.foot-bar {
  width: 100%;
  height: 3px;
  border-radius: 99px;
  background: color-mix(in srgb, var(--r-ink) 12%, transparent);
  overflow: hidden;
}
.foot-bar i {
  display: block;
  height: 100%;
  background: var(--r-accent);
}
.foot-label {
  font-size: 9.5px;
  color: var(--r-muted);
  font-variant-numeric: tabular-nums;
}

.toc-panel {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(84vw, 360px);
  z-index: 70;
  background: var(--r-panel);
  border-right: 1px solid var(--r-line);
  box-shadow: 20px 0 50px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
}
.toc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
}
.toc-head strong {
  font-family: var(--serif);
  font-size: 15px;
}
.toc-head button {
  width: 30px;
  height: 30px;
  color: var(--r-muted);
}
.toc-filter {
  margin: 0 14px 8px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--r-line);
  background: transparent;
  color: var(--r-ink);
  padding: 0 10px;
  font-size: 12px;
  outline: none;
}
.toc-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 20px;
}
.toc-item {
  width: 100%;
  text-align: left;
  padding: 10px 10px;
  border-radius: 7px;
  font-size: 12px;
  color: var(--r-ink);
  opacity: 0.8;
  display: flex;
  gap: 8px;
  align-items: center;
}
.toc-item.active {
  color: var(--r-accent);
  opacity: 1;
  font-weight: 600;
  background: color-mix(in srgb, var(--r-accent) 10%, transparent);
}
.toc-num {
  width: 26px;
  flex: none;
  text-align: right;
  font-size: 9.5px;
  color: var(--r-muted);
}

.sheet-wrap {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(20, 14, 8, 0.38);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: 100%;
  max-width: 760px;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  padding: 16px 18px calc(20px + var(--safe-bottom));
  box-shadow: 0 -20px 50px rgba(20, 14, 8, 0.2);
}
.sheet h3 {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-size: 16px;
}
.sheet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--ink-2);
}
.sheet-row:last-of-type {
  border-bottom: none;
}
.stepper {
  display: flex;
  gap: 6px;
}
.stepper button {
  width: 34px;
  height: 32px;
  border-radius: 8px;
  background: rgba(61, 46, 30, 0.07);
  font-size: 15px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(86px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 200;
  background: rgba(38, 31, 24, 0.94);
  color: #f7f0e4;
  font-size: 12px;
  padding: 9px 16px;
  border-radius: 9px;
  max-width: 80vw;
  text-align: center;
  box-shadow: 0 10px 26px rgba(20, 14, 8, 0.25);
}

.loading {
  padding: 50px 0;
  text-align: center;
  color: var(--ink-3);
  font-size: 12px;
}
.spinner {
  width: 22px;
  height: 22px;
  margin: 0 auto 10px;
  border-radius: 50%;
  border: 2px solid rgba(61, 46, 30, 0.14);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (min-width: 620px) {
  .grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
