:root {
  --bg: #f2f2f7;
  --bg-elev: #ffffff;
  --text: #111114;
  --sub: #6b6f76;
  --line: rgba(0, 0, 0, .08);
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, .12);
  --glass: rgba(255, 255, 255, .74);
  --glass-line: rgba(255, 255, 255, .65);
  --danger: #ff3b30;
  --reader-bg: #faf9f6;
  --reader-pdf: #e8e8ed;
  --shadow: 0 12px 34px rgba(0, 0, 0, .09);
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #000000;
  --bg-elev: #141416;
  --text: #f2f2f7;
  --sub: #9a9aa2;
  --line: rgba(255, 255, 255, .1);
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, .2);
  --glass: rgba(30, 30, 32, .72);
  --glass-line: rgba(255, 255, 255, .08);
  --danger: #ff453a;
  --reader-bg: #000000;
  --reader-pdf: #0b0b0c;
  --shadow: 0 12px 34px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC", "Noto Sans CJK SC", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hidden { display: none !important; }

/* ---------- 书架 ---------- */

.shelf {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.shelf-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 16px) 20.5px 12px;
  background: var(--bg);
  z-index: 2;
}

.shelf-heading h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -.02em;
}

.shelf-heading p {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--sub);
}

.shelf-main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px 20.5px calc(118px + env(safe-area-inset-bottom));
}

.book-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 760px;
  margin: 0 auto;
}

.book-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 12px 12px 12px;
  border-radius: 18px;
  background: var(--bg-elev);
  box-shadow: 0 1px 0 var(--line), 0 8px 24px rgba(0, 0, 0, .04);
  cursor: pointer;
  text-align: left;
  border: 0;
  width: 100%;
  transition: transform .16s ease, background .16s ease;
}

html[data-theme="dark"] .book-card {
  box-shadow: 0 1px 0 var(--line);
}

.book-card:active { transform: scale(.988); }

.book-cover {
  flex: 0 0 auto;
  width: 54px;
  height: 72px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  color: #fff;
  background: linear-gradient(150deg, #5aa9ff, #0a63d6);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22), 0 6px 14px rgba(10, 99, 214, .22);
  overflow: hidden;
}

.book-cover.pdf {
  background: linear-gradient(150deg, #ff8a7a, #c93125);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22), 0 6px 14px rgba(201, 49, 37, .22);
}

.book-meta {
  flex: 1;
  min-width: 0;
  padding-right: 34px;
}

.book-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-author {
  margin-top: 3px;
  font-size: 12px;
  color: var(--sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-progress {
  margin-top: 9px;
  height: 3px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}

.book-progress span {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: var(--accent);
  transition: width .25s ease;
}

.book-sub {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--sub);
}

.book-sub .continue {
  color: var(--accent);
  font-weight: 600;
}

.book-menu {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--sub);
  display: grid;
  place-items: center;
}

.book-menu:active { background: var(--line); }

.book-menu svg { width: 18px; height: 18px; }

/* 空状态 */

.empty {
  max-width: 340px;
  margin: 12vh auto 0;
  text-align: center;
  padding: 0 12px;
}

.empty-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: var(--bg-elev);
  color: var(--accent);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .06);
}

.empty-icon svg { width: 30px; height: 30px; stroke-width: 1.7; }

.empty h2 {
  margin: 0 0 8px;
  font-size: 18px;
  font-weight: 650;
}

.empty p {
  margin: 0 0 20px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--sub);
}

.empty .empty-hint {
  margin: 14px 0 0;
  font-size: 11px;
  opacity: .7;
}

.primary-btn {
  border: 0;
  border-radius: 999px;
  padding: 12px 26px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 10px 22px rgba(10, 132, 255, .3);
}

.primary-btn:active { transform: scale(.97); }

/* 通用玻璃圆 */

.glass-btn {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--text);
  background: var(--glass);
  box-shadow: inset 0 0 0 1px var(--glass-line), 0 4px 14px rgba(0, 0, 0, .06);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
}

.glass-btn:active { transform: scale(.94); }

.glass-btn.text-btn {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.01em;
}

.fab {
  position: fixed;
  right: 20.5px;
  bottom: calc(22px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 12px 26px rgba(10, 132, 255, .38);
  z-index: 3;
}

.fab:active { transform: scale(.94); }

.fab svg { width: 26px; height: 26px; }

/* ---------- 阅读器 ---------- */

.reader {
  position: fixed;
  inset: 0;
  background: var(--reader-bg);
  z-index: 40;
  overflow: hidden;
}

.stage {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: center;
}

.stage.epub {
  background: var(--reader-bg);
}

.stage.epub iframe {
  width: min(100%, 860px);
  height: 100%;
  border: 0;
  display: block;
  background: var(--reader-bg);
}

.stage.pdf {
  display: block;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--reader-pdf);
  padding: calc(env(safe-area-inset-top) + 62px) 10px calc(env(safe-area-inset-bottom) + 82px);
}

.pdf-page-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100%;
}

.pdf-page-wrap canvas {
  display: block;
  max-width: 100%;
  height: auto !important;
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 6px 26px rgba(0, 0, 0, .16);
}

html[data-theme="dark"] .pdf-page-wrap canvas {
  filter: invert(1) hue-rotate(180deg);
}

.reader-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 10px;
  background: var(--reader-bg);
  background: color-mix(in srgb, var(--reader-bg) 76%, transparent);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
  transition: opacity .22s ease, transform .22s ease;
}

.reader-heading {
  flex: 1;
  min-width: 0;
  text-align: center;
  padding: 0 4px;
}

.reader-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-sub {
  margin-top: 2px;
  font-size: 11px;
  color: var(--sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  padding: 12px 20.5px calc(env(safe-area-inset-bottom) + 10px);
  background: var(--reader-bg);
  background: color-mix(in srgb, var(--reader-bg) 76%, transparent);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
  transition: opacity .22s ease, transform .22s ease;
}

.progress-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  margin: 0;
  background: transparent;
}

.progress-slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 3px;
  background: var(--line);
}

.progress-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 8px rgba(10, 132, 255, .45);
}

.progress-slider::-moz-range-track {
  height: 4px;
  border-radius: 3px;
  background: var(--line);
}

.progress-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
}

.progress-labels {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 11px;
  color: var(--sub);
  font-variant-numeric: tabular-nums;
}

.progress-labels span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader.chrome-hidden .chrome {
  opacity: 0;
  pointer-events: none;
}

.reader.chrome-hidden .reader-top { transform: translateY(-8px); }
.reader.chrome-hidden .reader-bottom { transform: translateY(8px); }

/* 加载 / 提示 */

.loading {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: color-mix(in srgb, var(--reader-bg) 82%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-size: 13px;
  color: var(--sub);
}

.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2.5px solid var(--line);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translate(-50%, 8px);
  z-index: 120;
  max-width: calc(100vw - 48px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
  box-shadow: inset 0 0 0 1px var(--glass-line), var(--shadow);
  font-size: 13px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- 底部面板 ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .38);
  opacity: 0;
  transition: opacity .22s ease;
}

.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border-radius: 22px 22px 0 0;
  padding: 6px 0 calc(env(safe-area-inset-bottom) + 6px);
  transform: translateY(100%);
  transition: transform .26s cubic-bezier(.22, .8, .24, 1);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, .16);
}

.sheet.open .sheet-backdrop { opacity: 1; }
.sheet.open .sheet-panel { transform: translateY(0); }

.sheet-grip {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 4px auto 2px;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px 8px 20.5px;
}

.sheet-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
}

.sheet-head .glass-btn {
  width: 34px;
  height: 34px;
}

.sheet-head .glass-btn svg { width: 18px; height: 18px; }

.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2px 12px 10px;
}

.toc-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 11px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
}

.toc-item:active { background: var(--line); }

.toc-item.current {
  color: var(--accent);
  font-weight: 600;
  background: var(--accent-soft);
}

.toc-item .toc-label {
  flex: 1;
  min-width: 0;
}

.toc-item .toc-page {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--sub);
  font-variant-numeric: tabular-nums;
}

.toc-item .toc-label.clamp {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.settings-group {
  padding: 8px 8px 14px;
}

.settings-label {
  font-size: 12px;
  color: var(--sub);
  margin: 4px 2px 10px;
}

.segmented {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 11px;
  background: var(--line);
}

.segmented button {
  flex: 1;
  border: 0;
  border-radius: 9px;
  padding: 9px 0;
  background: transparent;
  font-size: 13px;
  color: var(--text);
}

.segmented button.active {
  background: var(--bg-elev);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .12);
}

.font-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}

.font-row .font-btn {
  width: 46px;
  height: 40px;
  border: 0;
  border-radius: 11px;
  background: var(--line);
  font-size: 17px;
  font-weight: 600;
}

.font-row .font-value {
  flex: 1;
  text-align: center;
  font-size: 13px;
  color: var(--sub);
  font-variant-numeric: tabular-nums;
}

.action-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  font-size: 15px;
}

.action-item:active { background: var(--line); }
.action-item.danger { color: var(--danger); }
.action-item svg { width: 20px; height: 20px; }

.sheet-hint {
  padding: 4px 12px 14px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--sub);
}

@media (min-width: 700px) {
  .sheet { align-items: center; }
  .sheet-panel {
    border-radius: 20px;
    max-height: 74vh;
    margin-bottom: 4vh;
    padding-bottom: 10px;
  }
  .shelf-main { padding-top: 10px; }
  .book-list { gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
