/* ================================================================
   style.css — 睡前故事 PWA 手机端样式
   设计语言: 暖色调 / 圆润 / 儿童友好 / 移动优先
   ================================================================ */

/* ── Google Fonts (系统中文字体栈，无需外链) ─────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap');

/* ── CSS 自定义属性 ──────────────────────────────────────────── */
:root {
  /* Colors */
  --c-bg:        #FFF8F0;
  --c-surface:   #FFFFFF;
  --c-primary:   #FF8C69;
  --c-primary-d: #E8704F;
  --c-primary-l: #FFD4C0;
  --c-accent:    #FFD700;
  --c-accent-d:  #F5C400;
  --c-fairy:     #C084FC;
  --c-fairy-bg:  #F3E8FF;
  --c-adventure: #FB923C;
  --c-adv-bg:    #FFF0E0;
  --c-age:       #34D399;
  --c-age-bg:    #ECFDF5;
  --c-dur:       #60A5FA;
  --c-dur-bg:    #EFF6FF;
  --c-text-1:    #3D2B1F;
  --c-text-2:    #7D5E4F;
  --c-text-3:    #B08C7A;
  --c-border:    rgba(61, 43, 31, 0.08);
  --c-shadow:    rgba(61, 43, 31, 0.10);

  /* Spacing */
  --gap:         12px;
  --gap-lg:      20px;
  --radius-sm:   10px;
  --radius-md:   18px;
  --radius-lg:   24px;
  --radius-full: 9999px;

  /* Layout */
  --header-h:    60px;
  --nav-h:       68px;
  --tts-h:       170px;
  --banner-h:    52px;

  /* Transitions */
  --ease:        cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Nunito', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--c-bg);
  color: var(--c-text-1);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; }
img, svg { display: block; }
a { text-decoration: none; color: inherit; }

/* ── App Shell ───────────────────────────────────────────────── */
#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--c-bg);
  overflow: hidden;
}

/* ── Install Banner ──────────────────────────────────────────── */
#install-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: var(--banner-h);
  background: linear-gradient(135deg, #FF8C69, #FFB347);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  z-index: 100;
  animation: slideDown 0.4s var(--ease-smooth);
}
#install-banner .banner-icon { font-size: 20px; flex-shrink: 0; }
#install-banner .banner-text { flex: 1; line-height: 1.35; }
#btn-dismiss-banner {
  font-size: 18px;
  color: rgba(255,255,255,0.8);
  padding: 4px;
  flex-shrink: 0;
}
@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ── App Header ──────────────────────────────────────────────── */
#app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-h);
  padding: 0 16px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
  z-index: 50;
  box-shadow: 0 2px 12px var(--c-shadow);
}
#btn-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--c-bg);
  color: var(--c-primary);
  font-size: 18px;
  font-weight: 800;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
}
#btn-back:active { transform: scale(0.9); background: var(--c-primary-l); }
#header-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--c-text-1);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#header-fav-count {
  font-size: 13px;
  background: var(--c-primary);
  color: #fff;
  border-radius: var(--radius-full);
  padding: 2px 9px;
  font-weight: 700;
}

/* ── Main Content Area ───────────────────────────────────────── */
#main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
/* Padding-bottom adapts to which fixed panel is at bottom */
#main-content.in-home,
#main-content.in-favorites {
  padding-bottom: var(--nav-h);
}
#main-content.in-detail {
  padding-bottom: calc(var(--tts-h) + 16px);
}

/* ── Views ───────────────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; animation: fadeIn 0.25s var(--ease-smooth); }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Filter Bar ──────────────────────────────────────────────── */
#filter-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 248, 240, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--c-border);
}
.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.filter-row::-webkit-scrollbar { display: none; }
.filter-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--c-text-3);
  white-space: nowrap;
  flex-shrink: 0;
}
.chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  border: 1.5px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text-2);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.2s var(--ease);
  min-height: 34px;
}
.chip.active {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(255, 140, 105, 0.4);
  transform: scale(1.04);
}
.chip:active { transform: scale(0.96); }
.filter-divider {
  width: 1px;
  height: 22px;
  background: var(--c-border);
  flex-shrink: 0;
}

/* ── Story Grid ──────────────────────────────────────────────── */
#story-grid,
#favorites-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--gap);
  padding: var(--gap-lg) 16px;
}
@media (min-width: 480px) {
  #story-grid,
  #favorites-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ── Story Card ──────────────────────────────────────────────── */
.story-card {
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  padding: 14px 12px 12px;
  box-shadow: 0 2px 12px var(--c-shadow), 0 0 0 1px var(--c-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease-smooth);
  -webkit-user-select: none;
  user-select: none;
}
.story-card:active {
  transform: scale(0.97);
  box-shadow: 0 1px 6px var(--c-shadow);
}
@media (hover: hover) {
  .story-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 28px rgba(61, 43, 31, 0.14), 0 0 0 1px var(--c-border);
  }
}
.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}
.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--c-text-1);
  line-height: 1.4;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-fav-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  color: var(--c-text-3);
  transition: transform 0.25s var(--ease), color 0.2s;
  flex-shrink: 0;
}
.card-fav-btn.active { color: #FF4D6D; }
.card-fav-btn:active { transform: scale(0.8); }
.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: auto;
}

/* ── Tags ────────────────────────────────────────────────────── */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.tag-fairy     { background: var(--c-fairy-bg);  color: var(--c-fairy); }
.tag-adventure { background: var(--c-adv-bg);    color: var(--c-adventure); }
.tag-age       { background: var(--c-age-bg);    color: var(--c-age); }
.tag-duration  { background: var(--c-dur-bg);    color: var(--c-dur); }

/* ── Empty State ─────────────────────────────────────────────── */
#empty-state,
#favorites-empty {
  padding: 60px 24px;
  text-align: center;
  color: var(--c-text-3);
}
#empty-state .empty-icon,
#favorites-empty .empty-icon { font-size: 56px; margin-bottom: 16px; }
#empty-state p,
#favorites-empty p { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
#empty-state small,
#favorites-empty small { font-size: 13px; color: var(--c-text-3); }

/* ── Favorites View ──────────────────────────────────────────── */
#view-favorites #favorites-grid { padding-top: var(--gap-lg); }

/* ── Detail View ─────────────────────────────────────────────── */
#view-detail { min-height: 100%; }
#story-detail {
  padding: 24px 20px 12px;
}
.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}
#detail-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--c-text-1);
  line-height: 1.35;
  margin-bottom: 20px;
}
#detail-text {
  font-size: 17px;
  line-height: 1.9;
  color: var(--c-text-1);
  letter-spacing: 0.02em;
}
#detail-text p {
  margin-bottom: 18px;
  text-indent: 2em;
}
#detail-text p:last-child { margin-bottom: 0; }

/* ── TTS Panel (fixed at bottom) ────────────────────────────── */
#tts-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tts-h);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--c-border);
  box-shadow: 0 -4px 24px rgba(61, 43, 31, 0.08);
  padding: 14px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 40;
}
#tts-panel.hidden { display: none; }

/* Progress bar */
#progress-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}
#progress-bar {
  flex: 1;
  height: 6px;
  background: var(--c-border);
  border-radius: var(--radius-full);
  position: relative;
  cursor: pointer;
  touch-action: none;
}
#progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--c-primary), var(--c-accent));
  border-radius: var(--radius-full);
  transition: width 0.15s linear;
  pointer-events: none;
}
#progress-thumb {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 16px;
  height: 16px;
  background: var(--c-primary);
  border-radius: var(--radius-full);
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 6px rgba(255, 140, 105, 0.5);
  pointer-events: none;
  transition: left 0.15s linear;
}
.progress-pct {
  font-size: 12px;
  font-weight: 700;
  color: var(--c-text-3);
  min-width: 34px;
  text-align: right;
  flex-shrink: 0;
}

/* Controls row */
#tts-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.speed-group {
  display: flex;
  background: var(--c-bg);
  border-radius: var(--radius-full);
  padding: 3px;
  gap: 2px;
}
.speed-btn {
  padding: 6px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
  color: var(--c-text-2);
  transition: all 0.2s var(--ease);
  min-height: 34px;
}
.speed-btn.active {
  background: var(--c-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(255, 140, 105, 0.4);
}
#btn-play-pause {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--c-primary), var(--c-primary-d));
  color: #fff;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(255, 140, 105, 0.5);
  transition: transform 0.2s var(--ease), box-shadow 0.2s;
  flex-shrink: 0;
}
#btn-play-pause:active {
  transform: scale(0.9);
  box-shadow: 0 2px 8px rgba(255, 140, 105, 0.3);
}
#btn-play-pause.playing {
  background: linear-gradient(135deg, #FF6B6B, #E8704F);
}
#btn-favorite-detail {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--c-bg);
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c-text-3);
  transition: transform 0.25s var(--ease), color 0.2s;
  flex-shrink: 0;
}
#btn-favorite-detail.active { color: #FF4D6D; }
#btn-favorite-detail:active { transform: scale(0.85); }

/* Voice selector */
#voice-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}
#voice-selector label {
  font-size: 12px;
  font-weight: 700;
  color: var(--c-text-3);
  flex-shrink: 0;
}
#voice-select {
  flex: 1;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--c-border);
  background: var(--c-surface);
  font-size: 13px;
  font-family: inherit;
  color: var(--c-text-1);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237D5E4F' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  min-height: 36px;
}

/* ── Bottom Navigation ───────────────────────────────────────── */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-h);
  background: var(--c-surface);
  border-top: 1px solid var(--c-border);
  display: flex;
  z-index: 40;
  box-shadow: 0 -2px 12px var(--c-shadow);
  /* Safe area inset for iPhones with home indicator */
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
#bottom-nav.hidden { display: none; }
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 0 8px;
  color: var(--c-text-3);
  transition: color 0.2s, transform 0.2s var(--ease);
}
.nav-btn.active { color: var(--c-primary); }
.nav-btn:active { transform: scale(0.92); }
.nav-icon { font-size: 22px; line-height: 1; }
.nav-label { font-size: 11px; font-weight: 700; }
.nav-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--c-primary);
  position: absolute;
  top: 8px;
  right: calc(50% - 18px);
  display: none;
}
.nav-btn.has-favorites .nav-dot { display: block; }

/* ── Utility ─────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Loading State ───────────────────────────────────────────── */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--c-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 200;
  transition: opacity 0.4s;
}
#loading-overlay.fade-out { opacity: 0; pointer-events: none; }
.loading-book { font-size: 64px; animation: pulse 1.6s ease-in-out infinite; }
.loading-text {
  font-size: 16px;
  font-weight: 700;
  color: var(--c-text-2);
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.12); }
}

/* ── Scrollbar (desktop preview) ────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--c-primary-l); border-radius: 2px; }
