:root {
  --bg: #050505;
  --panel: #111111;
  --panel-2: #1a1a1a;
  --line: rgba(255,255,255,.08);
  --text: #f5f5f5;
  --muted: #9aa0a6;
  --accent: #3b82f6;
  --topbar-h: 52px;
  --toolbar-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow: hidden;
}

button, input { font-family: inherit; }

#loading {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--bg); transition: opacity .4s;
}
#loading.hidden { opacity: 0; pointer-events: none; }
.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.12);
  border-top-color: var(--accent);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading p { margin-top: 14px; color: var(--muted); font-size: 14px; }

.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px; z-index: 30;
  background: linear-gradient(to bottom, rgba(0,0,0,.85), rgba(0,0,0,0));
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.topbar-title { font-size: 14px; font-weight: 600; letter-spacing: .02em; max-width: 42%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-jump { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.page-jump input {
  width: 56px; height: 30px; text-align: center; color: #fff;
  background: rgba(255,255,255,.08); border: 1px solid var(--line); border-radius: 8px; outline: none;
  touch-action: manipulation;
  -webkit-user-select: auto;
  user-select: auto;
}
.page-jump input:focus { border-color: var(--accent); }
.icon-btn {
  width: 36px; height: 36px; border: 0; border-radius: 10px;
  background: rgba(255,255,255,.08); color: #fff; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:active, .icon-btn.active { background: var(--accent); }

#flipbook-container {
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0;
  bottom: calc(var(--toolbar-h) + var(--safe-bottom));
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
#flipbook { box-shadow: 0 18px 60px rgba(0,0,0,.55); }
#flipbook .page { background: #111; overflow: hidden; }
#flipbook .page img { width: 100%; height: 100%; object-fit: contain; display: block; background: #111; }

.hotspot {
  position: absolute; top: 8%; bottom: 8%; width: 18%; z-index: 8; cursor: pointer;
}
.hotspot.left { left: 0; }
.hotspot.right { right: 0; }

.toolbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--toolbar-h) + var(--safe-bottom));
  padding: 8px 8px calc(8px + var(--safe-bottom));
  background: rgba(8,8,8,.94);
  border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  overflow-x: auto; gap: 6px;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.tool {
  min-width: 42px; height: 48px; border: 0; background: transparent; color: #ddd;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 10px; cursor: pointer; flex: 0 0 auto;
}
.tool-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
}
.tool-ico svg,
.tool svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tool.active, .tool:active { color: #fff; }
.tool span { line-height: 1; }

.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50;
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.overlay.show { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed; z-index: 60; background: var(--panel);
  color: var(--text); display: flex; flex-direction: column;
  transform: translateY(110%); transition: transform .28s ease;
}
.sheet.open { transform: translateY(0); }
.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.sheet-header h3 { font-size: 16px; }
.sheet-body { overflow: auto; padding: 10px 12px 20px; }

#catalog-sheet {
  left: 0; right: 0; bottom: 0; height: min(78vh, 640px);
  border-radius: 16px 16px 0 0;
}
#thumbs-sheet {
  left: 0; right: 0; bottom: 0; height: min(42vh, 320px);
  border-radius: 16px 16px 0 0;
}
#contact-sheet {
  left: 0; right: 0; bottom: 0; height: auto; max-height: 86vh;
  border-radius: 16px 16px 0 0;
}

.toc-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 10px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.toc-item.active { background: rgba(59,130,246,.16); }
.toc-page { color: var(--accent); font-size: 12px; font-weight: 700; min-width: 52px; }
.toc-title { font-size: 14px; }

.thumbs-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px;
}
.thumb {
  position: relative; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; cursor: pointer; background: #000;
}
.thumb img { width: 100%; height: 110px; object-fit: cover; display: block; }
.thumb span {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.65); color: #fff; font-size: 11px; text-align: center; padding: 2px 0;
}
.thumb.active { outline: 2px solid var(--accent); }

.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.form-row input, .form-row textarea {
  width: 100%; background: var(--panel-2); color: #fff; border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; outline: none;
}
.form-row textarea { min-height: 88px; resize: vertical; }
.contact-actions { display: flex; gap: 8px; margin-bottom: 14px; }
.pill {
  flex: 1; text-align: center; text-decoration: none; color: #fff;
  background: #222; border-radius: 10px; padding: 10px 8px; font-size: 13px;
}
.primary-btn {
  width: 100%; height: 44px; border: 0; border-radius: 12px;
  background: var(--accent); color: #fff; font-size: 15px; cursor: pointer;
}

.hint {
  position: fixed; inset: 0; z-index: 80;
  display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,.55);
}
.hint.show { display: flex; }
.hint-card {
  width: min(320px, 86vw); text-align: center; color: #fff;
}
.swipe-demo {
  width: 120px; height: 80px; margin: 0 auto 16px; position: relative;
  border: 2px solid rgba(255,255,255,.4); border-radius: 12px;
}
.finger {
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  position: absolute; top: 50%; left: 20%; transform: translateY(-50%);
  animation: swipe 1.4s ease-in-out infinite;
}
@keyframes swipe {
  0% { left: 18%; opacity: .3; }
  40% { opacity: 1; }
  100% { left: 70%; opacity: .2; }
}

@media (min-width: 901px) {
  #catalog-sheet {
    top: 0; bottom: 0; left: 0; right: auto;
    width: 340px; height: 100%;
    border-radius: 0; transform: translateX(-105%);
  }
  #catalog-sheet.open { transform: translateX(0); }
}


html, body {
  height: 100dvh;
}

#flipbook-container {
  z-index: 1;
}

.toolbar {
  z-index: 1000;
  background: #000;
}

@media (max-width: 900px) {
  :root {
    --topbar-h: 48px;
    --toolbar-h: 76px;
  }
  .topbar {
    background: #000;
  }
  .toolbar {
    justify-content: flex-start;
    gap: 0;
    padding: 6px 4px calc(10px + var(--safe-bottom));
    border-top: 1px solid #2a2a2a;
    -webkit-overflow-scrolling: touch;
  }
  .tool {
    min-width: 58px;
    height: 60px;
    color: #fff;
    font-size: 11px;
  }
  .tool-ico {
    font-size: 18px;
    margin-bottom: 4px;
  }
  #flipbook-container {
    top: var(--topbar-h);
    bottom: calc(var(--toolbar-h) + var(--safe-bottom));
  }
}


.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: #333;
  color: white;
  padding: 16px 24px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 99999;
  opacity: 0;
  transition: all 0.3s;
  min-width: 280px;
  max-width: calc(100vw - 32px);
  text-align: center;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { background: #10b981; }
.toast.error { background: #ef4444; }
.toast.info { background: #3b82f6; }
.primary-btn:disabled { opacity: .65; cursor: not-allowed; }

@media (max-width: 900px) {
  .toast {
    top: calc(12px + env(safe-area-inset-top, 0px));
    padding: 14px 18px;
    font-size: 14px;
    min-width: 0;
    width: calc(100vw - 32px);
  }
}

#search-sheet {
  left: 0; right: 0; bottom: 0; height: min(78vh, 640px);
  border-radius: 16px 16px 0 0;
}
#search-input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 16px;
  color: #fff;
  background: var(--panel-2);
  outline: none;
}
#search-input:focus { border-color: var(--accent); }
.search-result-item {
  display: flex;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.2s;
}
.search-result-item:hover,
.search-result-item:active {
  background: rgba(59,130,246,.16);
}
.search-result-thumb {
  width: 60px;
  height: 80px;
  object-fit: cover;
  border-radius: 4px;
  margin-right: 12px;
  flex-shrink: 0;
  background: #1a1a1a;
}
.search-result-info { flex: 1; min-width: 0; }
.search-result-title {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.search-result-page {
  font-size: 12px;
  color: var(--muted);
}
.search-highlight {
  background: #fef3c7;
  color: #92400e;
  padding: 2px 4px;
  border-radius: 2px;
}
@media (min-width: 901px) {
  #search-sheet {
    top: 0; bottom: 0; left: 0; right: auto;
    width: 340px; height: 100%;
    border-radius: 0; transform: translateX(-105%);
  }
  #search-sheet.open { transform: translateX(0); }
}


.sheet {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes swipeFeedback {
  0% { opacity: 0; transform: translateY(-50%) scale(.85); }
  40% { opacity: 1; transform: translateY(-50%) scale(1); }
  100% { opacity: 0; transform: translateY(-50%) scale(1); }
}
#flipbook-container.swipe-left::after,
#flipbook-container.swipe-right::after {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 60px;
  height: 60px;
  background: rgba(0,0,0,.35);
  border-radius: 50%;
  color: #fff;
  font-size: 30px;
  line-height: 60px;
  text-align: center;
  animation: swipeFeedback .3s;
  pointer-events: none;
  z-index: 100;
}
#flipbook-container.swipe-left::after { content: '‹'; left: 20px; }
#flipbook-container.swipe-right::after { content: '›'; right: 20px; }

@media (max-width: 768px) {
  .topbar {
    height: calc(50px + env(safe-area-inset-top, 0px));
    padding: 0 10px;
    padding-top: env(safe-area-inset-top, 0px);
  }
  .topbar-title { font-size: 14px; max-width: 36%; }
  .page-jump input {
    width: 45px;
    height: 32px;
    padding: 4px 6px;
    font-size: 16px;
  }
  .icon-btn {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }
  .toolbar {
    padding: 8px 5px calc(10px + env(safe-area-inset-bottom, 0px));
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  .toolbar::-webkit-scrollbar { display: none; }
  .tool {
    min-width: 60px;
    min-height: 44px;
    height: 60px;
    padding: 8px 10px;
    font-size: 12px;
  }
  .tool-ico { font-size: 16px; margin-bottom: 2px; }
  .tool span:last-child { font-size: 11px; }
  #first-page,
  #last-page,
  #zoom-in,
  #zoom-out { display: none !important; }
  .hotspot { width: 25%; }
  .sheet {
    width: 100%;
    max-width: 100%;
  }
  #search-sheet,
  #catalog-sheet {
    height: min(88vh, 720px);
  }
  .form-row input,
  .form-row textarea {
    font-size: 16px;
    padding: 14px 12px;
    min-height: 44px;
  }
  .form-row textarea { min-height: 120px; }
  .primary-btn {
    height: 48px;
    font-size: 16px;
    border-radius: 10px;
  }
  .contact-actions {
    flex-direction: column;
    gap: 10px;
  }
  .pill {
    width: 100%;
    padding: 14px;
    font-size: 15px;
  }
  .toast {
    top: auto;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%) translateY(20px);
    min-width: 0;
    width: calc(100vw - 32px);
    padding: 14px 16px;
    font-size: 14px;
    border-radius: 12px;
  }
  .toast.show {
    transform: translateX(-50%) translateY(0);
  }
  #loading p { font-size: 14px; }
  #loading .spinner { width: 40px; height: 40px; }
}


#share-sheet {
  left: 0; right: 0; bottom: 0; height: auto; max-height: 86vh;
  border-radius: 16px 16px 0 0;
}
@media (min-width: 901px) {
  #share-sheet {
    top: 0; bottom: 0; left: 0; right: auto;
    width: 380px; height: 100%;
    border-radius: 0; transform: translateX(-105%);
  }
  #share-sheet.open { transform: translateX(0); }
}

/* 分享面板样式 */
.share-section {
    padding: 20px 15px;
    border-bottom: 1px solid var(--line);
}
.share-section:last-child {
    border-bottom: none;
}
.share-section h4 {
    margin: 0 0 10px 0;
    font-size: 16px;
    color: var(--text);
}
.share-tip {
    font-size: 13px;
    color: var(--muted);
    margin: 0 0 15px 0;
}
.share-input-group {
    display: flex;
    gap: 10px;
}
.share-input-group input {
    flex: 1;
    padding: 12px;
    border: 2px solid var(--line);
    border-radius: 8px;
    font-size: 14px;
    background: var(--panel-2);
    color: #fff;
}
.share-input-group input:focus {
    outline: none;
    border-color: #667eea;
}
.btn-copy,
.btn-download {
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: transform 0.2s;
}
.btn-copy:hover,
.btn-download:hover {
    transform: translateY(-2px);
}
.btn-copy:active,
.btn-download:active {
    transform: translateY(0);
}
.btn-download {
    width: 100%;
    margin-top: 15px;
}
.share-tips {
    margin: 0;
    padding-left: 20px;
}
.share-tips li {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 8px;
    line-height: 1.6;
}
#qrcode {
    background: white;
    display: inline-block;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
#qrcode img {
    display: block !important;
    margin: 0 auto !important;
}
@media (max-width: 768px) {
    .share-input-group {
        flex-direction: column;
    }
    .btn-copy {
        width: 100%;
    }
    #share-sheet {
        height: min(88vh, 720px);
    }
}
