/* ===== 设计系统 ===== */
:root {
  --color-primary: #FF6B6B;
  --color-primary-dark: #ee5a5a;
  --color-secondary: #4ECDC4;
  --color-accent: #FFE66D;
  --color-bg: #FFF8F0;
  --color-card: #FFFFFF;
  --color-text: #2D3436;
  --color-text-secondary: #636E72;
  --color-text-light: #B2BEC3;
  --color-border: #F0E6D8;
  --color-success: #00B894;
  --color-cn-badge: #FF6B6B;
  --color-en-badge: #4ECDC4;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 999px;
  --font-cn: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-en: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== 基础重置 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--font-cn);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
input, button { font-family: inherit; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; height: auto; }

/* ===== 视图切换 ===== */
.view { display: none; }
.view.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Hero 搜索区 ===== */
.hero {
  background: linear-gradient(135deg, var(--color-primary) 0%, #FF8E8E 50%, var(--color-accent) 100%);
  padding: 48px 20px 32px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 60%);
  animation: float 8s ease-in-out infinite;
}
@keyframes float { 0%, 100% { transform: translateY(0) rotate(0deg); } 50% { transform: translateY(-20px) rotate(5deg); } }
.hero-content { position: relative; z-index: 1; }
.hero-emoji { font-size: 48px; margin-bottom: 4px; }
.hero-title {
  font-size: 28px;
  font-weight: 700;
  color: #FFF;
  letter-spacing: 2px;
  text-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.hero-subtitle {
  font-size: 14px;
  color: rgba(255,255,255,0.9);
  margin-top: 4px;
  font-weight: 400;
}
.search-container {
  position: relative;
  z-index: 1;
  margin-top: 20px;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}
.search-box {
  display: flex;
  align-items: center;
  background: var(--color-card);
  border-radius: var(--radius-full);
  padding: 0 16px;
  box-shadow: var(--shadow-lg);
  transition: var(--transition);
}
.search-box:focus-within { box-shadow: 0 8px 32px rgba(0,0,0,0.18); transform: scale(1.02); }
.search-icon { width: 20px; height: 20px; color: var(--color-text-light); flex-shrink: 0; }
#search-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 14px 12px;
  font-size: 15px;
  background: transparent;
  color: var(--color-text);
}
#search-input::placeholder { color: var(--color-text-light); }
.search-clear {
  background: none;
  border: none;
  color: var(--color-text-light);
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 8px;
  background: var(--color-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 300px;
  overflow-y: auto;
  z-index: 100;
  text-align: left;
}
.search-item {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border);
  transition: var(--transition);
}
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: #fafafa; }
.search-item-cover {
  width: 36px;
  height: 48px;
  border-radius: 4px;
  object-fit: cover;
  margin-right: 12px;
  background: #eee;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.search-item-info {
  flex: 1;
  overflow: hidden;
}
.search-item-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-item-author {
  font-size: 12px;
  color: var(--color-text-light);
  margin-top: 2px;
}

/* ===== 分类标签 ===== */
.category-tabs {
  display: flex;
  gap: 8px;
  padding: 16px 20px 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.category-tabs::-webkit-scrollbar { display: none; }
.tab {
  flex-shrink: 0;
  padding: 8px 18px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-full);
  background: var(--color-card);
  color: var(--color-text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.tab:active { transform: scale(0.96); }
.tab.active {
  background: var(--color-primary);
  color: #FFF;
  border-color: var(--color-primary);
  box-shadow: 0 2px 8px rgba(255,107,107,0.3);
}

/* ===== 书籍网格 ===== */
.content { padding: 0 0 32px; }
.book-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px 16px;
}
.book-card {
  background: var(--color-card);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}
.book-card:active { transform: scale(0.97); box-shadow: var(--shadow-md); }
.book-cover {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
  background: linear-gradient(135deg, #f5f0e8 0%, #ede4d8 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  position: relative;
}
.card-fav-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 14px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  z-index: 2;
}
.book-info { padding: 10px 12px 14px; }
.book-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
mark.highlight {
  background-color: rgba(255, 107, 107, 0.15);
  color: var(--color-primary);
  border-radius: 2px;
  padding: 0 2px;
}
.book-author {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 4px;
}
.book-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  color: #FFF;
}
.book-badge.cn { background: var(--color-cn-badge); }
.book-badge.en { background: var(--color-en-badge); }
.book-age {
  display: inline-block;
  font-size: 11px;
  color: var(--color-text-light);
  margin-top: 4px;
}

/* ===== 空状态 ===== */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--color-text-secondary);
}
.empty-emoji { font-size: 48px; display: block; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }
.empty-hint { font-size: 13px; color: var(--color-text-light); margin-top: 4px; }

/* ===== 绘本详情页 ===== */
.book-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(255,248,240,0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-border);
}
.back-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--color-primary);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  padding: 8px 4px;
}
.back-btn svg { width: 20px; height: 20px; }
.icon-btn {
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  color: var(--color-text-secondary);
}
.icon-btn svg { width: 22px; height: 22px; }
.book-header-actions { display: flex; gap: 4px; }

/* ===== 详情内容 ===== */
.book-detail { padding: 20px 16px; max-width: 480px; margin: 0 auto; }
.detail-hero {
  text-align: center;
  margin-bottom: 24px;
}
.detail-cover {
  width: 120px;
  height: 160px;
  border-radius: var(--radius-md);
  object-fit: cover;
  box-shadow: var(--shadow-md);
  margin-bottom: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 64px;
  background: linear-gradient(135deg, #f5f0e8 0%, #ede4d8 100%);
}
.detail-title {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.3;
}
.detail-subtitle {
  font-size: 14px;
  color: var(--color-text-secondary);
  margin-top: 2px;
}
.detail-meta {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
  flex-wrap: wrap;
}
.meta-tag {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  background: var(--color-bg);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

/* ===== 阅读准备 ===== */
.prep-section {
  background: var(--color-card);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.prep-section h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.prep-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.prep-list li {
  font-size: 14px;
  color: var(--color-text-secondary);
  padding-left: 20px;
  position: relative;
  line-height: 1.5;
}
.prep-list li::before {
  content: '•';
  position: absolute;
  left: 6px;
  color: var(--color-primary);
  font-weight: 700;
}

/* ===== 语言切换 ===== */
.lang-switcher {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  background: var(--color-card);
  border-radius: var(--radius-full);
  padding: 4px;
  box-shadow: var(--shadow-sm);
}
.lang-btn {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  background: transparent;
  color: var(--color-text-secondary);
}
.lang-btn.active {
  background: var(--color-primary);
  color: #FFF;
  box-shadow: 0 2px 8px rgba(255,107,107,0.3);
}

/* ===== TTS 控制条 ===== */
.tts-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  background: var(--color-card);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  box-shadow: var(--shadow-sm);
}
.tts-bar label {
  font-size: 13px;
  color: var(--color-text-secondary);
  white-space: nowrap;
}
.voice-select {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--color-bg);
  color: var(--color-text);
  outline: none;
}

/* ===== 逐页脚本卡片流 ===== */
.page-card {
  background: var(--color-card);
  border-radius: var(--radius-md);
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  border: 1px solid var(--color-border);
}
.page-card-header {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  background: #fdfaf5;
  border-bottom: 1px solid var(--color-border);
}
.page-number {
  font-size: 13px;
  font-weight: 600;
  color: #FFF;
  background: var(--color-primary);
  padding: 3px 12px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}
.page-title {
  font-size: 16px;
  font-weight: 600;
  margin-left: 12px;
  color: var(--color-text);
  line-height: 1.4;
}
.page-body-inner {
  padding: 20px 16px;
}
.script-block {
  margin-bottom: 24px;
}
.script-text {
  font-size: 18px;
  line-height: 1.6;
  color: var(--color-text);
  margin-bottom: 12px;
  padding: 0 4px;
}
.script-text.en-text {
  font-family: var(--font-en);
  font-size: 17px;
}
/* ===== 迷你播放器 ===== */
.audio-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: #fafafa;
  margin-bottom: 10px;
}
.ap-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.ap-btn.cn-btn { background: rgba(255, 107, 107, 0.15); color: var(--color-primary-dark); }
.ap-btn.en-btn { background: rgba(78, 205, 196, 0.15); color: #2b9991; }
.ap-btn:hover { transform: scale(1.1); }
.ap-bar {
  flex: 1;
  height: 6px;
  background: #e8e2da;
  border-radius: 3px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.ap-fill {
  height: 100%;
  width: 0;
  border-radius: 3px;
  transition: width 0.1s linear;
}
.cn-btn ~ .ap-bar .ap-fill, .audio-player:has(.cn-btn) .ap-fill { background: var(--color-primary); }
.en-btn ~ .ap-bar .ap-fill, .audio-player:has(.en-btn) .ap-fill { background: var(--color-secondary); }
.ap-time {
  font-size: 11px;
  color: var(--color-text-light);
  font-family: var(--font-en);
  white-space: nowrap;
  min-width: 40px;
}
.ap-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-light);
  white-space: nowrap;
}

/* ===== 连播按钮 ===== */
.autoplay-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.autoplay-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-card);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: var(--transition);
}
.autoplay-btn:hover { background: var(--color-bg); }
.interaction-tip {
  margin-top: 16px;
  padding: 16px;
  background: rgba(255, 230, 109, 0.15);
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--color-accent);
}
.tip-header {
  font-weight: 600;
  color: #bfa300;
  font-size: 14px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tip-content {
  font-size: 15px;
  color: var(--color-text-secondary);
  line-height: 1.5;
}

/* ===== 延伸活动 ===== */
.activities-section {
  background: var(--color-card);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-top: 16px;
  box-shadow: var(--shadow-sm);
}
.activities-section h3 { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.activity-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 14px;
  color: var(--color-text-secondary);
  border-bottom: 1px solid var(--color-border);
}
.activity-item:last-child { border-bottom: none; }
.activity-icon { font-size: 20px; flex-shrink: 0; }

/* ===== 底部 ===== */
.book-footer {
  padding: 24px 20px 40px;
  text-align: center;
  max-width: 480px;
  margin: 0 auto;
}
.footer-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  color: var(--color-text-light);
  font-size: 13px;
}
.footer-divider::before, .footer-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border);
}
.footer-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}
.footer-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--color-card);
  box-shadow: var(--shadow-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text);
  transition: var(--transition);
}
.footer-link:active { transform: scale(0.98); }
.footer-disclaimer {
  font-size: 11px;
  color: var(--color-text-light);
  line-height: 1.5;
  margin-bottom: 8px;
}
.footer-copyright {
  font-size: 11px;
  color: var(--color-text-light);
}

/* ===== 弹窗 ===== */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }
.modal-content {
  position: relative;
  background: var(--color-card);
  border-radius: var(--radius-lg);
  padding: 24px 20px 32px;
  width: 90%;
  max-width: 400px;
  animation: slideUp 0.3s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-content h3 { font-size: 18px; font-weight: 600; margin-bottom: 12px; text-align: center; }
.share-url {
  background: var(--color-bg);
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--color-text-secondary);
  word-break: break-all;
  margin-bottom: 16px;
  font-family: var(--font-en);
}
.btn {
  display: block;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 8px;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--color-primary); color: #FFF; }
.btn-secondary { background: var(--color-bg); color: var(--color-text-secondary); }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--color-text);
  color: #FFF;
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 14px;
  z-index: 2000;
  opacity: 0;
  transition: all 0.3s ease;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== 工具类 ===== */
.hidden { display: none !important; }

/* ===== 加载中状态样式 ===== */
.tts-btn-large.loading {
  background: rgba(255, 199, 0, 0.12);
  color: #b8860b;
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

/* ===== 版本标签 ===== */
.version-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  margin-top: 16px;
}
.version-tab {
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text-light);
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition);
}
.version-tab.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
  font-weight: 500;
}

/* ===== 页脚免责与版权 ===== */
.site-footer {
  padding: 32px 20px;
  text-align: center;
  border-top: 1px solid var(--color-border);
  margin-top: 40px;
}
.footer-disclaimer {
  font-size: 11px;
  color: var(--color-text-light);
  line-height: 1.6;
  max-width: 600px;
  margin: 0 auto 12px;
}
.footer-copyright {
  font-size: 11px;
  color: var(--color-text-light);
}

/* ============================================
   响应式适配 — 手机 / 平板 / 桌面
   ============================================ */

/* --- 平板 (≥768px) --- */
@media (min-width: 768px) {
  .hero { padding: 56px 32px 40px; }
  .hero-title { font-size: 36px; }
  .hero-subtitle { font-size: 16px; }
  .search-container { max-width: 500px; }

  .category-tabs { justify-content: center; padding: 20px 32px 12px; }

  .content { max-width: 900px; margin: 0 auto; padding: 0 24px 40px; }
  .book-grid { grid-template-columns: repeat(4, 1fr); gap: 16px; padding: 16px 0; }

  .book-detail { max-width: 700px; padding: 28px 32px; }
  .detail-cover { width: 160px; height: 213px; }
  .detail-title { font-size: 26px; }

  .script-text { font-size: 17px; }
  .tts-btn-large { padding: 14px; font-size: 15px; }

  .page-card { max-width: 700px; margin-left: auto; margin-right: auto; }

  .modal-content { border-radius: var(--radius-lg); max-width: 440px; margin-bottom: 10vh; }

  .site-footer { max-width: 900px; margin-left: auto; margin-right: auto; }
}

/* --- 桌面 (≥1024px) --- */
@media (min-width: 1024px) {
  .hero { padding: 64px 40px 48px; }
  .hero-emoji { font-size: 56px; }
  .hero-title { font-size: 42px; letter-spacing: 3px; }
  .hero-subtitle { font-size: 17px; margin-top: 8px; }
  .search-container { max-width: 560px; }

  .category-tabs { padding: 24px 0 16px; max-width: 1100px; margin: 0 auto; }

  .content { max-width: 1200px; padding: 0 40px 48px; }
  .book-grid { grid-template-columns: repeat(5, 1fr); gap: 20px; padding: 20px 0; }
  .book-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
  .book-info { padding: 12px 14px 16px; }
  .book-title { font-size: 15px; }

  .book-detail { max-width: 800px; padding: 40px 48px; }
  .detail-cover { width: 180px; height: 240px; }
  .detail-title { font-size: 30px; }

  /* 双栏脚本布局：中文左 + 英文右 */
  .page-body-inner {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    padding: 24px;
  }
  .page-body-inner .interaction-tip {
    grid-column: 1 / -1;
  }

  .page-card { max-width: 900px; }

  .site-footer { max-width: 1200px; }
}

/* --- 超宽屏 (≥1440px) --- */
@media (min-width: 1440px) {
  .content { max-width: 1400px; }
  .book-grid { grid-template-columns: repeat(6, 1fr); }
  .book-detail { max-width: 900px; }
}

/* ===== 安全区域适配 ===== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .site-footer { padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
}

