/* =============================================
   3D Flipbook - 电子宣传册
   样式表
   ============================================= */

:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --bg-dark: #1a1a2e;
  --bg-surface: #2a2a3e;
  --bg-page: #f5f0e8;
  --text-primary: #333;
  --text-secondary: #666;
  --text-light: #aaa;
  --border: #ddd;
  --shadow: rgba(0,0,0,0.2);
  --radius: 8px;
  --book-width: 800px;
  --book-height: 560px;
  --page-gap: 0px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* ===== 顶部导航 ===== */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 1000;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-title {
  color: #eee;
  font-size: 16px;
  font-weight: 600;
  margin-left: 6px;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: #bbb;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.btn-icon:active {
  transform: scale(0.92);
}

.btn-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: #999;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s;
}

.btn-close:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

/* ===== 侧边栏 ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: -340px;
  width: 320px;
  height: 100%;
  background: var(--bg-surface);
  z-index: 2000;
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 20px rgba(0,0,0,0.4);
}

.sidebar.open {
  left: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-header h3 {
  color: #eee;
  font-size: 18px;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.book-list-placeholder {
  color: #666;
  text-align: center;
  padding: 40px 20px;
  font-size: 14px;
}

.sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1999;
  display: none;
}

.sidebar-overlay.show {
  display: block;
}

/* 书库卡片 */
.book-card {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.book-card:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.15);
}

.book-card.active {
  border-color: var(--primary);
  background: rgba(26,115,232,0.15);
}

.book-card-cover {
  width: 64px;
  height: 88px;
  border-radius: 4px;
  overflow: hidden;
  flex-shrink: 0;
  background: #333;
}

.book-card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-card-info {
  flex: 1;
  min-width: 0;
}

.book-card-title {
  color: #eee;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-card-meta {
  color: #888;
  font-size: 12px;
}

.book-card-delete {
  color: #ff4444;
  font-size: 12px;
  padding: 2px 8px;
  border: 1px solid #ff4444;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  margin-top: 4px;
  transition: all 0.2s;
}

.book-card-delete:hover {
  background: rgba(255,68,68,0.2);
}

/* ===== 上传面板 ===== */
.upload-panel {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.6);
}

.upload-panel.show {
  display: flex;
}

.upload-panel-inner {
  background: var(--bg-surface);
  border-radius: 12px;
  width: 90%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.upload-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.upload-header h3 {
  color: #eee;
  font-size: 18px;
}

.upload-body {
  padding: 20px;
}

.upload-dropzone {
  border: 2px dashed rgba(255,255,255,0.2);
  border-radius: 12px;
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
}

.upload-dropzone:hover,
.upload-dropzone.dragover {
  border-color: var(--primary);
  background: rgba(26,115,232,0.1);
}

.upload-dropzone p {
  color: #aaa;
  margin-top: 12px;
  font-size: 14px;
}

.upload-dropzone .upload-hint {
  color: #666;
  font-size: 12px;
  margin-top: 4px;
}

.upload-progress {
  text-align: center;
  padding: 20px;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 12px;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  border-radius: 3px;
  transition: width 0.3s;
}

#progressText {
  color: #aaa;
  font-size: 13px;
}

.upload-form {
  padding: 10px 0;
}

.input-field {
  width: 100%;
  padding: 10px 14px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  color: #eee;
  font-size: 14px;
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.2s;
}

.input-field:focus {
  border-color: var(--primary);
}

/* 文件列表 */
.file-list {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 12px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.05);
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 13px;
}

.file-item .file-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.file-item .file-name {
  color: #ddd;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-item .file-size {
  color: #888;
  font-size: 12px;
  flex-shrink: 0;
}

.btn-block {
  width: 100%;
  display: block;
}

/* 空状态操作按钮 */
.empty-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ===== 通用按钮 ===== */
.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 24px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: rgba(255,255,255,0.08);
  color: #ccc;
  border: 1px solid rgba(255,255,255,0.2);
  padding: 10px 24px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
}

.btn-secondary:hover {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.3);
  transform: translateY(-1px);
}

.btn-lg {
  padding: 14px 32px;
  font-size: 16px;
}

/* ===== 分享弹窗 ===== */
.share-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.6);
}

.share-modal.show {
  display: flex;
}

.share-modal-inner {
  background: var(--bg-surface);
  border-radius: 12px;
  width: 90%;
  max-width: 380px;
}

.share-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.share-header h3 {
  color: #eee;
  font-size: 18px;
}

.share-body {
  padding: 24px;
  text-align: center;
}

.share-qr {
  width: 200px;
  height: 200px;
  margin: 0 auto 16px;
  background: #fff;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.share-qr img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.qr-placeholder {
  color: #999;
  font-size: 13px;
}

.share-url {
  color: #aaa;
  font-size: 12px;
  word-break: break-all;
  margin-bottom: 16px;
  padding: 8px;
  background: rgba(0,0,0,0.2);
  border-radius: 4px;
}

.share-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn-share {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: 1px solid rgba(255,255,255,0.2);
  background: transparent;
  color: #ddd;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.btn-share:hover {
  background: rgba(255,255,255,0.1);
  border-color: var(--primary);
}

/* ===== 遮罩 ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
  display: none;
}

.modal-overlay.show {
  display: block;
}

/* ===== 主舞台 ===== */
.flipbook-stage {
  position: fixed;
  top: 52px;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* 空状态 */
.empty-state {
  text-align: center;
  color: #666;
  padding: 40px;
}

.empty-state svg {
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-state h2 {
  color: #888;
  font-size: 24px;
  margin-bottom: 8px;
}

.empty-state p {
  color: #666;
  font-size: 14px;
  margin-bottom: 24px;
}

/* 加载状态 */
.loading-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  z-index: 100;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

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

#loadingText {
  color: #aaa;
  font-size: 14px;
}

/* ===== 书籍容器 ===== */
.book-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  position: relative;
}

/* 工具栏 */
.book-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 700px;
  padding: 8px 12px;
  gap: 8px;
  z-index: 50;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tool-btn {
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  color: #aaa;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  font-size: 12px;
}

.tool-btn:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.tool-btn:active {
  transform: scale(0.9);
}

.page-indicator {
  color: #ccc;
  font-size: 13px;
  min-width: 70px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.book-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  overflow: hidden;
  touch-action: pinch-zoom;
}

/* ===== 3D书核心 ===== */
.book-3d {
  position: relative;
  display: flex;
  flex-direction: row;
  width: min(880px, 92vw);
  height: min(620px, 78vh);
  max-width: 95vw;
  max-height: 85vh;
  perspective: 1400px;
  transform-style: preserve-3d;
  transform: translateZ(0);
  transition: transform 0.3s ease;
  will-change: transform;
}

/* ===== 移动端单页模式 ===== */
.mobile-mode {
  width: 100% !important;
  height: auto !important;
  max-width: 100% !important;
  max-height: 100% !important;
  flex-direction: column !important;
  align-items: center;
  justify-content: center;
  perspective: none !important;
}

.mobile-mode .book-page {
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
  aspect-ratio: 3/4;
  max-height: 80vh;
  border-radius: 4px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.mobile-mode .book-page-left,
.mobile-mode .book-page-right {
  border: none;
  border-radius: 4px;
}

.mobile-mode .book-page-content {
  position: relative;
  height: 100%;
}

.mobile-mode .book-page-content img {
  object-fit: contain;
  width: 100%;
  height: 100%;
  border-radius: 4px;
}

.mobile-mode .book-page-number {
  bottom: 12px;
  font-size: 13px;
  color: rgba(0,0,0,0.4);
  background: rgba(255,255,255,0.7);
  padding: 2px 10px;
  border-radius: 10px;
}

/* 书脊阴影 */
.book-3d::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 40px;
  transform: translateX(-50%);
  background: linear-gradient(
    to right,
    rgba(0,0,0,0) 0%,
    rgba(0,0,0,0.15) 30%,
    rgba(0,0,0,0.2) 50%,
    rgba(0,0,0,0.15) 70%,
    rgba(0,0,0,0) 100%
  );
  z-index: 5;
  pointer-events: none;
}

/* 移动端书脊阴影隐藏 */
.mobile-mode.book-3d::before {
  display: none;
}

/* 展开的书 */
.book-spread {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  transform-style: preserve-3d;
}

/* 单页 */
.book-page {
  position: relative;
  width: 50%;
  height: 100%;
  flex-shrink: 0;
  background: var(--bg-page);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transform-style: preserve-3d;
  overflow: hidden;
}

.book-page-left {
  border-right: 1px solid rgba(0,0,0,0.08);
  border-radius: 4px 0 0 4px;
}

.book-page-right {
  border-left: 1px solid rgba(0,0,0,0.08);
  border-radius: 0 4px 4px 0;
}

/* 页面内容容器 */
.book-page-content {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.book-page-content img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* 页码水印 */
.book-page-number {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(0,0,0,0.25);
  font-size: 11px;
  font-family: serif;
  pointer-events: none;
}

/* ===== 翻页 - 实时3D翻转 ===== */

/* 当前展开的页面 */
.page-static {
  z-index: 1;
}

/* 翻转动画容器 */
.flip-animation-wrap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 99;
  transform-style: preserve-3d;
}

/* 正在翻的页面容器 */
.page-flipping {
  position: absolute;
  width: 50%;
  height: 100%;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  z-index: 100;
  will-change: transform;
  contain: layout style;
}

.page-flipping.right-edge {
  left: 50%;
  transform-origin: left center;
}

.page-flipping.left-edge {
  left: 0;
  transform-origin: right center;
}

/* 翻页折叠渐变覆盖层：模拟纸张弯折的明暗变化 */
.page-fold-gradient {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
  mix-blend-mode: multiply;
  will-change: background;
}

/* 翻页空中阴影（投影到书面上） */
.page-air-shadow {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  pointer-events: none;
  z-index: 97;
  background: radial-gradient(ellipse 60% 50% at 50% 50%, rgba(0,0,0,0.35) 0%, transparent 80%);
  will-change: transform, opacity;
}

/* 翻页的前后两面 */
.page-face {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  overflow: hidden;
  background: var(--bg-page);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 翻页时的正面阴影 */
.page-flipping .page-face:first-child {
  box-shadow: 4px 0 20px rgba(0,0,0,0.2);
  border-radius: 4px;
}

.page-face img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
}

.page-face-back {
  transform: rotateY(180deg);
  box-shadow: -2px 0 10px rgba(0,0,0,0.2);
}

/* 翻页阴影 */
.page-flip-shadow {
  position: absolute;
  z-index: 98;
  pointer-events: none;
  will-change: opacity;
}

/* 交互热区 */
.flip-hotzone {
  position: absolute;
  top: 0;
  width: 60px;
  height: 100%;
  z-index: 10;
  cursor: pointer;
  transition: background 0.3s;
}

.flip-hotzone:hover {
  background: rgba(255,255,255,0.05);
}

/* 页面角落翻页指示 */
.flip-corner {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 40px;
  height: 40px;
  z-index: 11;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.flip-corner::after {
  content: '';
  position: absolute;
  right: 0;
  bottom: 0;
  width: 30px;
  height: 30px;
  border-right: 3px solid rgba(255,255,255,0.3);
  border-bottom: 3px solid rgba(255,255,255,0.3);
  border-radius: 0 0 4px 0;
}

.book-page:hover .flip-corner {
  opacity: 1;
}

/* ===== 缩略图面板 ===== */
.thumbnails-panel {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 280px;
  background: var(--bg-surface);
  z-index: 100;
  display: flex;
  flex-direction: column;
  border-left: 1px solid rgba(255,255,255,0.1);
  box-shadow: -4px 0 20px rgba(0,0,0,0.3);
}

.thumbnails-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.thumbnails-header h4 {
  color: #eee;
  font-size: 14px;
}

.thumbnails-grid {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.thumbnail-item {
  cursor: pointer;
  border-radius: 4px;
  overflow: hidden;
  aspect-ratio: 3/4;
  background: rgba(255,255,255,0.05);
  border: 2px solid transparent;
  transition: all 0.2s;
  position: relative;
}

.thumbnail-item:hover {
  border-color: rgba(255,255,255,0.2);
}

.thumbnail-item.active {
  border-color: var(--primary);
}

.thumbnail-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumbnail-page-num {
  position: absolute;
  bottom: 2px;
  right: 4px;
  color: #fff;
  font-size: 10px;
  background: rgba(0,0,0,0.6);
  padding: 1px 4px;
  border-radius: 2px;
}

/* ===== 底部信息 ===== */
.book-footer {
  padding: 8px 0;
  text-align: center;
  z-index: 10;
}

.book-footer span {
  color: #555;
  font-size: 12px;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .topbar-title {
    font-size: 14px;
    max-width: 120px;
  }

  .book-3d {
    max-height: 60vh;
  }

  .mobile-mode .book-page {
    max-height: 70vh;
    aspect-ratio: 3/4;
  }

  .book-toolbar {
    padding: 4px 8px;
    max-width: 100%;
  }

  .tool-btn {
    width: 30px;
    height: 30px;
  }

  .page-indicator {
    font-size: 12px;
    min-width: 60px;
  }

  .thumbnails-panel {
    width: 200px;
  }

  .thumbnails-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .sidebar {
    width: 280px;
  }

  .upload-panel-inner {
    width: 95%;
  }
}

@media (max-width: 480px) {
  .topbar {
    height: 44px;
    padding: 0 8px;
  }

  .flipbook-stage {
    top: 44px;
  }

  .book-3d {
    max-height: 50vh;
  }

  .page-indicator {
    min-width: 50px;
  }

  .tool-btn {
    display: none;
  }

  .toolbar-group:first-child .tool-btn {
    display: none;
  }

  .page-indicator {
    display: inline-block;
    min-width: 60px;
    font-size: 14px;
  }

  .toolbar-group:last-child {
    display: none;
  }

  .toolbar-group:first-child {
    justify-content: center;
    width: 100%;
  }

  .toolbar-group:first-child .page-indicator {
    font-size: 15px;
    font-weight: 500;
    color: #ccc;
  }

  .empty-state h2 {
    font-size: 20px;
  }

  .book-card-cover {
    width: 48px;
    height: 66px;
  }
}

/* ===== 滚动条美化 ===== */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.25);
}
