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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: #f5f7fa;
  color: #333;
  min-height: 100vh;
}

header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 16px 0;
  box-shadow: 0 2px 12px rgba(102, 126, 234, 0.3);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.logo {
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 1px;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 30px 20px;
}

/* Search Page */
.search-section {
  text-align: center;
  margin-bottom: 40px;
}

.search-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  color: #2d3748;
}

.search-subtitle {
  color: #718096;
  margin-bottom: 24px;
  font-size: 14px;
}

.search-box {
  display: flex;
  max-width: 600px;
  margin: 0 auto;
  gap: 10px;
}

.search-box input {
  flex: 1;
  padding: 14px 20px;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.search-box input:focus {
  border-color: #667eea;
}

.search-box button {
  padding: 14px 32px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.2s;
}

.search-box button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.search-box button:active {
  transform: translateY(0);
}

/* Results Grid */
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
}

.book-card {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  display: flex;
  gap: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.book-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.book-cover {
  width: 90px;
  height: 120px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: #e2e8f0;
}

.book-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: hidden;
}

.book-name {
  font-size: 17px;
  font-weight: 700;
  color: #1a202c;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-author {
  font-size: 13px;
  color: #718096;
}

.book-meta {
  font-size: 12px;
  color: #a0aec0;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.book-desc {
  font-size: 13px;
  color: #4a5568;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: auto;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.badge-free {
  background: #c6f6d5;
  color: #22543d;
}

.badge-paid {
  background: #fed7d7;
  color: #9b2c2c;
}

.badge-category {
  background: #e9d8fd;
  color: #553c9a;
}

/* Detail Page */
.detail-page {
  max-width: 800px;
  margin: 0 auto;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #667eea;
  text-decoration: none;
  font-size: 14px;
  margin-bottom: 20px;
  cursor: pointer;
}

.back-btn:hover {
  text-decoration: underline;
}

.detail-header {
  background: #fff;
  border-radius: 16px;
  padding: 30px;
  display: flex;
  gap: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  margin-bottom: 20px;
}

.detail-cover {
  width: 160px;
  height: 213px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
  background: #e2e8f0;
}

.detail-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-title {
  font-size: 24px;
  font-weight: 800;
  color: #1a202c;
}

.detail-author {
  font-size: 15px;
  color: #4a5568;
}

.detail-stats {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.stat-item {
  text-align: center;
}

.stat-value {
  font-size: 18px;
  font-weight: 700;
  color: #2d3748;
}

.stat-label {
  font-size: 12px;
  color: #a0aec0;
  margin-top: 2px;
}

.detail-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.detail-latest {
  font-size: 13px;
  color: #718096;
  margin-top: auto;
}

.detail-actions {
  background: #fff;
  border-radius: 16px;
  padding: 24px 30px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 36px;
  background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.2s;
}

.download-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(72, 187, 120, 0.4);
}

.download-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.progress-wrap {
  margin-top: 16px;
}

.progress-bar-bg {
  width: 100%;
  height: 20px;
  background: #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #48bb78 0%, #38a169 100%);
  border-radius: 10px;
  transition: width 0.3s ease;
}

.progress-text {
  margin-top: 8px;
  font-size: 13px;
  color: #4a5568;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.download-status {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  display: none;
}

.download-status.show {
  display: block;
}

.download-status.success {
  background: #f0fff4;
  color: #22543d;
  border: 1px solid #c6f6d5;
}

.download-status.error {
  background: #fff5f5;
  color: #9b2c2c;
  border: 1px solid #fed7d7;
}

.download-status.info {
  background: #ebf8ff;
  color: #2a4365;
  border: 1px solid #bee3f8;
}

/* Loading */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: #a0aec0;
  font-size: 16px;
}

.spinner {
  display: inline-block;
  width: 32px;
  height: 32px;
  border: 3px solid #e2e8f0;
  border-top-color: #667eea;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

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

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #a0aec0;
}

.empty-state p {
  font-size: 16px;
  margin-top: 8px;
}

/* Responsive */
@media (max-width: 768px) {
  .results-grid {
    grid-template-columns: 1fr;
  }

  .detail-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .detail-stats {
    justify-content: center;
  }

  .search-box {
    flex-direction: column;
  }

  .search-box button {
    width: 100%;
  }
}
