/* ===== English Learning App ===== */
:root {
  --bg: #FAF7F2;
  --surface: #FFFFFF;
  --ink: #1F2937;
  --ink-soft: #6B7280;
  --ink-faint: #9CA3AF;
  --primary: #2D5F4E;
  --primary-light: #E8F0ED;
  --accent: #E8833A;
  --accent-light: #FDF0E4;
  --border: #E8E4DD;
  --shadow: 0 2px 12px rgba(45, 60, 50, 0.08);
  --radius: 16px;
  --radius-sm: 10px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: 80px;
}

/* ===== Top Bar ===== */
.topbar {
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 16px 20px 12px;
  z-index: 100;
  border-bottom: 1px solid var(--border);
}
.topbar h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
}
.topbar .sub {
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin-top: 2px;
}

/* ===== Home: Book Grid ===== */
.book-grid {
  padding: 20px 16px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
.book-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s ease;
  border-left: 5px solid var(--primary);
}
.book-card:active { transform: scale(0.98); }
.book-card .book-type {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.book-card .book-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 4px;
}
.book-card .book-desc {
  font-size: 0.82rem;
  color: var(--ink-soft);
}
.book-card .book-meta {
  margin-top: 10px;
  font-size: 0.75rem;
  color: var(--ink-faint);
  display: flex;
  gap: 12px;
}

/* Book colors */
.bc-dialog1 { border-left-color: #4A6FA5; }
.bc-dialog1 .book-type { color: #4A6FA5; }
.bc-dialog2 { border-left-color: #8B3A4E; }
.bc-dialog2 .book-type { color: #8B3A4E; }
.bc-dialog3 { border-left-color: #2D5F4E; }
.bc-dialog3 .book-type { color: #2D5F4E; }
.bc-vocab1 { border-left-color: #E8833A; }
.bc-vocab1 .book-type { color: #E8833A; }
.bc-vocab2 { border-left-color: #2A9D8F; }
.bc-vocab2 .book-type { color: #2A9D8F; }
.bc-vocab3 { border-left-color: #6B4C9A; }
.bc-vocab3 .book-type { color: #6B4C9A; }
.bc-vlog1 { border-left-color: #B4593B; }
.bc-vlog1 .book-type { color: #B4593B; }
.bc-vlog2 { border-left-color: #4A7C59; }
.bc-vlog2 .book-type { color: #4A7C59; }

/* ===== Section List (Parts/Levels) ===== */
.section-list { padding: 16px; }
.section-item {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.section-item:active { transform: scale(0.98); }
.section-item .sec-title {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 4px;
}
.section-item .sec-count {
  font-size: 0.78rem;
  color: var(--ink-faint);
}

/* ===== Back button ===== */
.back-bar {
  padding: 12px 16px 0;
}
.back-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 0;
}
.back-btn:active { opacity: 0.6; }

/* ===== Flashcard (Vocab) ===== */
.card-container {
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.flashcard {
  width: 100%;
  max-width: 380px;
  height: 340px;
  perspective: 1000px;
  cursor: pointer;
  margin-bottom: 20px;
}
.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s;
  transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}
.card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}
.card-front {
  background: var(--surface);
  box-shadow: var(--shadow);
}
.card-back {
  background: var(--primary-light);
  transform: rotateY(180deg);
}
.card-word {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
}
.card-pos {
  font-size: 0.85rem;
  color: var(--ink-faint);
  font-style: italic;
}
.card-zh {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 10px;
}
.card-mne {
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin-bottom: 10px;
  line-height: 1.5;
}
.card-ex {
  font-size: 0.85rem;
  color: var(--ink);
  line-height: 1.5;
  font-style: italic;
}
.card-hint {
  font-size: 0.72rem;
  color: var(--ink-faint);
  margin-top: 12px;
}

/* Big play button on card */
.card-play {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(232, 131, 58, 0.4);
}
.card-play:active { transform: scale(0.92); }

/* Card navigation */
.card-nav {
  display: flex;
  gap: 12px;
  align-items: center;
}
.nav-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--ink);
}
.nav-btn:active { background: var(--primary-light); }
.card-counter {
  font-size: 0.85rem;
  color: var(--ink-soft);
  min-width: 60px;
  text-align: center;
}
.known-btn {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 0.9rem;
  cursor: pointer;
}
.known-btn:active { opacity: 0.85; }
.known-btn.known {
  background: var(--ink-faint);
}

/* ===== Dialogue View ===== */
.dialogue-container {
  padding: 16px;
}
.dialogue-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--primary);
}
.bubble {
  margin-bottom: 12px;
  max-width: 90%;
  cursor: pointer;
}
.bubble .speaker {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-faint);
  margin-bottom: 3px;
  padding-left: 4px;
}
.bubble .en {
  background: var(--surface);
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 0.95rem;
  line-height: 1.5;
  box-shadow: var(--shadow);
}
.bubble .zh {
  font-size: 0.8rem;
  color: var(--ink-soft);
  padding: 4px 4px 0;
  line-height: 1.4;
}
.bubble.right { margin-left: auto; }
.bubble.right .en {
  background: var(--primary);
  color: white;
}
.bubble:active .en { opacity: 0.85; }

/* Phrase list (callouts) */
.phrase-section {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.phrase-section h4 {
  font-size: 0.88rem;
  color: var(--primary);
  margin-bottom: 10px;
}
.phrase-item {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.phrase-item:last-child { border-bottom: none; }
.phrase-item .en {
  font-size: 0.92rem;
  font-weight: 500;
}
.phrase-item .zh {
  font-size: 0.8rem;
  color: var(--ink-soft);
}

/* Play indicator */
.playing .en::after {
  content: " 🔊";
  font-size: 0.8rem;
}

/* ===== Progress bar ===== */
.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 12px 16px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s;
}

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-faint);
}
.empty-state .icon { font-size: 2.5rem; margin-bottom: 12px; }

/* ===== TTS controls ===== */
.tts-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 200;
}
.speed-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--ink-soft);
}
.speed-control select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.8rem;
  background: var(--bg);
}
.stop-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 0.78rem;
  cursor: pointer;
  color: var(--ink-soft);
}
.play-all-btn {
  display: block;
  width: 100%;
  background: var(--primary-light);
  border: 1px solid var(--primary);
  color: var(--primary);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  margin: 4px 0 12px;
}
.play-all-btn:active { opacity: 0.7; }
.scene-video {
  width: 100%;
  border-radius: var(--radius-sm);
  margin: 4px 0 12px;
  background: #000;
}

/* Hide scrollbar but allow scroll */
::-webkit-scrollbar { width: 0; }

/* ===== Vlog reader ===== */
.vlog-container { padding: 16px; }
.vlog-meta {
  font-size: 0.72rem;
  color: var(--ink-faint);
  padding: 0 4px 12px;
}
.vlog-para {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 14px 16px 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.vlog-para:active { background: var(--primary-light); }
.vlog-para .para-no {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 0.68rem;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}
.vlog-para .en {
  font-size: 0.95rem;
  line-height: 1.75;
  padding-right: 18px;
}
.vlog-para .zh {
  font-size: 0.82rem;
  color: var(--ink-soft);
  line-height: 1.7;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.vlog-para .w-active { background: var(--accent-light); }

/* ===== Long-press word ===== */
.w {
  display: inline;
  border-radius: 4px;
  padding: 0 1px;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.w-active {
  background: var(--accent-light);
  box-shadow: 0 0 0 2px var(--accent-light);
  color: var(--accent);
}
.bubble.right .w-active {
  background: rgba(255, 255, 255, 0.28);
  color: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.28);
}

/* Word popup card */
.wordcard {
  position: fixed;
  z-index: 500;
  min-width: 190px;
  max-width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(31, 41, 55, 0.18);
  padding: 14px 16px 12px;
  animation: wcIn 0.16s ease-out;
}
.wordcard.below { animation-name: wcInBelow; }

@keyframes wcIn {
  from { opacity: 0; transform: translateY(6px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes wcInBelow {
  from { opacity: 0; transform: translateY(-6px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.wordcard .wc-word {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.3;
}
.wordcard .wc-ipa {
  font-size: 0.8rem;
  color: var(--ink-soft);
  font-family: "Segoe UI", "Noto Sans", system-ui, sans-serif;
  letter-spacing: 0.02em;
  margin-top: 3px;
}
.wordcard .wc-read {
  font-size: 0.72rem;
  color: var(--ink-faint);
  margin-top: 2px;
}
.wordcard .wc-read b { color: var(--ink-soft); font-weight: 600; }

.wordcard .wc-pos {
  font-size: 0.72rem;
  color: var(--ink-faint);
  font-style: italic;
  margin-top: 2px;
}
.wordcard .wc-zh {
  font-size: 0.86rem;
  color: var(--ink);
  margin-top: 6px;
  line-height: 1.45;
}
.wordcard .wc-zh.wc-miss {
  color: var(--ink-soft);
  font-size: 0.78rem;
}
.wordcard .wc-form {
  font-size: 0.72rem;
  color: var(--ink-faint);
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}
.wordcard .wc-form b { color: var(--ink-soft); }

.wc-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  align-items: center;
}
.wc-btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.76rem;
  cursor: pointer;
  white-space: nowrap;
}
.wc-btn:active { background: var(--primary-light); }
.wc-play {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.wc-play:active { opacity: 0.85; }
.wc-close {
  margin-left: auto;
  color: var(--ink-faint);
  background: none;
  border-color: transparent;
}

.wc-arrow {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
  transform: translateX(-50%) rotate(45deg);
  bottom: -6px;
}
.wordcard.below .wc-arrow {
  bottom: auto;
  top: -6px;
  transform: translateX(-50%) rotate(225deg);
}
