/* ============================================
   Kids English Flashcards — Design System & Styles
   ============================================ */

/* --- CSS Variables / Design Tokens --- */
:root {
  --color-primary: #FF6B6B;
  --color-primary-light: #FF8E8E;
  --color-primary-dark: #E55555;
  --color-secondary: #4ECDC4;
  --color-secondary-light: #7EDDD6;
  --color-accent: #FFE66D;
  --color-accent-dark: #F0D85E;
  --color-purple: #A29BFE;
  --color-pink: #FD79A8;
  --color-orange: #FDCB6E;
  --color-blue: #74B9FF;
  --color-green: #55EFC4;
  --color-bg: #F0F2F5;
  --color-bg-warm: #FFF9F0;
  --color-card: #FFFFFF;
  --color-text: #2D3436;
  --color-text-light: #636E72;
  --color-text-muted: #B2BEC3;
  --color-border: #E0E0E0;
  --color-danger: #FF6B6B;
  --color-success: #00B894;

  --font-family: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 999px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.16);
  --shadow-glow: 0 4px 20px rgba(255, 107, 107, 0.3);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --header-height: 60px;
}

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

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* --- Header --- */
#app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  z-index: 100;
}

.header-content {
  max-width: 600px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.header-title {
  font-size: 1.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--color-primary), var(--color-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-sm);
  color: var(--color-text);
  transition: var(--transition);
}

.header-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}

.header-spacer {
  width: 40px;
}

/* --- Main App --- */
#app {
  max-width: 600px;
  margin: 0 auto;
  padding: calc(var(--header-height) + 16px) 16px 32px;
  min-height: 100vh;
  min-height: 100dvh;
}

/* --- Page Animations --- */
.page-enter {
  animation: pageIn 0.35s ease-out;
}

@keyframes pageIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* =========================
   HOME PAGE
   ========================= */
.home-page {
  padding-bottom: 100px;
}

.home-hero {
  text-align: center;
  padding: 24px 0 32px;
}

.home-hero h2 {
  font-size: 1.8rem;
  font-weight: 900;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.home-hero p {
  color: var(--color-text-light);
  font-size: 0.95rem;
}

/* Theme Grid */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.theme-card {
  background: var(--color-card);
  border-radius: var(--radius-md);
  padding: 20px 16px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: var(--color-text);
  position: relative;
  overflow: hidden;
}

.theme-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--color-primary), var(--color-secondary));
  opacity: 0;
  transition: var(--transition);
}

.theme-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}

.theme-card:hover::before {
  opacity: 1;
}

.theme-card:active {
  transform: translateY(-2px) scale(0.98);
}

.theme-card-emoji {
  font-size: 2.5rem;
  margin-bottom: 8px;
  display: block;
}

.theme-card-name {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.theme-card-meta {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.theme-card-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 700;
  background: var(--color-accent);
  color: var(--color-text);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 48px 24px;
}

.empty-state-icon {
  font-size: 4rem;
  margin-bottom: 16px;
  animation: bounce 2s infinite;
}

@keyframes bounce {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-12px);
  }
}

.empty-state h3 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--color-text);
}

.empty-state p {
  color: var(--color-text-light);
  margin-bottom: 24px;
  line-height: 1.6;
}

/* Generate FAB Button */
.fab-generate {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 568px;
  width: calc(100% - 32px);
  padding: 16px 32px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
  color: white;
  border: none;
  border-radius: var(--radius-lg);
  font-family: var(--font-family);
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow-glow);
  transition: var(--transition);
  z-index: 50;
}

.fab-generate:hover {
  transform: translateX(-50%) translateY(-2px);
  box-shadow: 0 6px 24px rgba(255, 107, 107, 0.4);
}

.fab-generate:active {
  transform: translateX(-50%) scale(0.98);
}

/* =========================
   GENERATE PAGE
   ========================= */
.generate-page {
  padding-bottom: 100px;
}

.generate-section {
  margin-bottom: 28px;
}

.generate-section-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Age Selector */
.age-selector {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.age-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 3px solid var(--color-border);
  background: var(--color-card);
  font-family: var(--font-family);
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--color-text-light);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.age-btn:hover {
  border-color: var(--color-primary-light);
  color: var(--color-primary);
}

.age-btn.selected {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: white;
  box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
  transform: scale(1.08);
}

/* Theme Category */
.theme-category {
  margin-bottom: 16px;
}

.theme-category-header {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--color-text-light);
  margin-bottom: 8px;
  padding-left: 4px;
}

.theme-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.theme-chip {
  padding: 8px 16px;
  border-radius: var(--radius-full);
  border: 2px solid var(--color-border);
  background: var(--color-card);
  font-family: var(--font-family);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}

.theme-chip:hover {
  border-color: var(--color-secondary);
  background: rgba(78, 205, 196, 0.08);
}

.theme-chip.selected {
  border-color: var(--color-secondary);
  background: var(--color-secondary);
  color: white;
  box-shadow: 0 3px 10px rgba(78, 205, 196, 0.3);
}

.theme-chip-emoji {
  font-size: 1.1rem;
}

/* Existing indicator */
.theme-existing-info {
  margin-top: 12px;
  padding: 12px 16px;
  background: rgba(78, 205, 196, 0.1);
  border-radius: var(--radius-md);
  border-left: 4px solid var(--color-secondary);
  font-size: 0.85rem;
  color: var(--color-text-light);
}

.theme-existing-info strong {
  color: var(--color-secondary);
}

.theme-limit-warning {
  background: rgba(255, 107, 107, 0.1);
  border-left-color: var(--color-primary);
}

.theme-limit-warning strong {
  color: var(--color-primary);
}

/* Generate Button */
.btn-generate {
  width: 100%;
  padding: 16px 32px;
  border: none;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--color-secondary), #45B7AA);
  color: white;
  font-family: var(--font-family);
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 16px rgba(78, 205, 196, 0.3);
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 568px;
  width: calc(100% - 32px);
  z-index: 50;
}

.btn-generate:hover:not(:disabled) {
  transform: translateX(-50%) translateY(-2px);
  box-shadow: 0 6px 24px rgba(78, 205, 196, 0.4);
}

.btn-generate:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* =========================
   PROGRESS OVERLAY
   ========================= */
.progress-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.progress-card {
  background: var(--color-card);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  text-align: center;
  width: 90%;
  max-width: 360px;
  box-shadow: var(--shadow-lg);
}

.progress-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  animation: spin 2s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.progress-title {
  font-size: 1.2rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.progress-subtitle {
  font-size: 0.85rem;
  color: var(--color-text-light);
  margin-bottom: 20px;
}

.progress-bar-container {
  width: 100%;
  height: 12px;
  background: var(--color-bg);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-purple), var(--color-secondary));
  background-size: 200% 100%;
  border-radius: var(--radius-full);
  transition: width 0.5s ease;
  animation: shimmer 2s linear infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

.progress-count {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  font-weight: 600;
}

/* =========================
   PREVIEW PAGE
   ========================= */
.preview-page {
  padding-bottom: 100px;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.preview-title {
  font-size: 1.2rem;
  font-weight: 800;
}

.preview-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.preview-card {
  background: var(--color-card);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.preview-card:hover {
  box-shadow: var(--shadow-md);
}

.preview-card-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  background: var(--color-bg);
}

.preview-card-body {
  padding: 16px;
}

.preview-card-word {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--color-primary);
  margin-bottom: 2px;
}

.preview-card-cn {
  font-size: 1rem;
  color: var(--color-text-light);
  margin-bottom: 8px;
}

.preview-card-sentence {
  font-size: 0.9rem;
  color: var(--color-text);
  margin-bottom: 4px;
  font-style: italic;
}

.preview-card-tip {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  padding: 8px 12px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  margin-top: 8px;
}

.preview-card-actions {
  display: flex;
  justify-content: flex-end;
  padding: 8px 16px 16px;
  gap: 8px;
}

.btn-regenerate {
  padding: 8px 16px;
  border-radius: var(--radius-full);
  border: 2px solid var(--color-border);
  background: var(--color-card);
  font-family: var(--font-family);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-text-light);
  cursor: pointer;
  transition: var(--transition);
}

.btn-regenerate:hover {
  border-color: var(--color-orange);
  color: var(--color-orange);
  background: rgba(253, 203, 110, 0.1);
}

.btn-regenerate:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Save All Button */
.btn-save-all {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 568px;
  width: calc(100% - 32px);
  padding: 16px 32px;
  background: linear-gradient(135deg, var(--color-success), #00A884);
  color: white;
  border: none;
  border-radius: var(--radius-lg);
  font-family: var(--font-family);
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 184, 148, 0.3);
  transition: var(--transition);
  z-index: 50;
}

.btn-save-all:hover {
  transform: translateX(-50%) translateY(-2px);
  box-shadow: 0 6px 24px rgba(0, 184, 148, 0.4);
}

.btn-save-all:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* =========================
   VIEWER PAGE
   ========================= */
.viewer-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  min-height: calc(100vh - var(--header-height) - 32px);
  min-height: calc(100dvh - var(--header-height) - 32px);
  padding-bottom: 80px;
}

#viewer-card-area {
  width: 100%;
  display: flex;
  justify-content: center;
}

/* Flashcard 3D Flip */
.flashcard-container {
  perspective: 1200px;
  width: 100%;
  max-width: 360px;
  height: 480px;
  margin: 16px 0;
  cursor: pointer;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
}

.flashcard-inner.flipped {
  transform: rotateY(180deg);
}

.flashcard-front,
.flashcard-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  background: var(--color-card);
}

.flashcard-back {
  transform: rotateY(180deg);
}

/* Front of flashcard */
.flashcard-front {
  display: flex;
  flex-direction: column;
}

.flashcard-image {
  width: 100%;
  flex: 1;
  object-fit: cover;
  background: linear-gradient(135deg, #f5f7fa, #c3cfe2);
}

.flashcard-word-area {
  padding: 20px;
  text-align: center;
  background: white;
}

.flashcard-word {
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--color-text);
  letter-spacing: 1px;
}

.flashcard-speak-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  border: none;
  background: rgba(255, 107, 107, 0.1);
  color: var(--color-primary);
  font-family: var(--font-family);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
}

.flashcard-speak-btn:hover {
  background: rgba(255, 107, 107, 0.2);
}

/* Back of flashcard */
.flashcard-back {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  background: linear-gradient(135deg, var(--color-bg-warm), var(--color-card));
}

.flashcard-cn {
  font-size: 2.5rem;
  font-weight: 900;
  margin-bottom: 20px;
  color: var(--color-primary);
}

.flashcard-sentence {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 24px;
  text-align: center;
  line-height: 1.5;
  font-style: italic;
  padding: 16px 20px;
  background: rgba(78, 205, 196, 0.1);
  border-radius: var(--radius-md);
  width: 100%;
}

.flashcard-tip {
  font-size: 0.85rem;
  color: var(--color-text-light);
  text-align: center;
  line-height: 1.6;
  padding: 16px;
  background: rgba(162, 155, 254, 0.1);
  border-radius: var(--radius-md);
  width: 100%;
}

.flashcard-tip-label {
  font-weight: 800;
  color: var(--color-purple);
  display: block;
  margin-bottom: 4px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Viewer Navigation */
.viewer-nav {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-top: 8px;
}

.viewer-nav-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--color-border);
  background: var(--color-card);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  color: var(--color-text);
}

.viewer-nav-btn:hover:not(:disabled) {
  border-color: var(--color-primary);
  color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

.viewer-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.viewer-nav-btn svg {
  width: 24px;
  height: 24px;
}

.viewer-counter {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text-light);
  min-width: 60px;
  text-align: center;
}

/* Viewer Toolbar */
.viewer-toolbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  padding: 12px 16px;
  display: flex;
  justify-content: center;
  gap: 16px;
  z-index: 50;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--color-bg);
  font-family: var(--font-family);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--color-text);
  cursor: pointer;
  transition: var(--transition);
}

.toolbar-btn:hover {
  background: var(--color-border);
}

.toolbar-btn.primary {
  background: var(--color-primary);
  color: white;
}

.toolbar-btn.primary:hover {
  background: var(--color-primary-dark);
}

/* =========================
   TOAST NOTIFICATIONS
   ========================= */
#toast-container {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 24px;
  border-radius: var(--radius-full);
  background: var(--color-text);
  color: white;
  font-family: var(--font-family);
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
  white-space: nowrap;
}

.toast.success {
  background: var(--color-success);
}

.toast.error {
  background: var(--color-danger);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }

  to {
    opacity: 0;
    transform: translateY(-8px);
  }
}

/* =========================
   UTILITY CLASSES
   ========================= */
.text-center {
  text-align: center;
}

.text-muted {
  color: var(--color-text-muted);
}

.mt-8 {
  margin-top: 8px;
}

.mt-16 {
  margin-top: 16px;
}

.mb-16 {
  margin-bottom: 16px;
}

.hidden {
  display: none !important;
}

/* Loading placeholder */
.skeleton {
  background: linear-gradient(90deg, var(--color-bg) 25%, #e8e8e8 50%, var(--color-bg) 75%);
  background-size: 200% 100%;
  animation: skeletonShimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeletonShimmer {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

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

  .flashcard-container {
    height: 420px;
  }

  .flashcard-word {
    font-size: 1.8rem;
  }

  .flashcard-cn {
    font-size: 2rem;
  }

  .age-btn {
    width: 52px;
    height: 52px;
    font-size: 1.2rem;
  }
}

/* --- PDF Export Hidden Card (for rendering) --- */
.export-card {
  width: 595px;
  /* A4 width in px at 72 DPI */
  height: 842px;
  /* A4 height */
  background: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  position: fixed;
  left: -9999px;
  top: 0;
}

.export-card-image {
  width: 400px;
  height: 400px;
  object-fit: contain;
  border-radius: 24px;
  margin-bottom: 32px;
}

.export-card-word {
  font-family: 'Nunito', sans-serif;
  font-size: 3.5rem;
  font-weight: 900;
  color: var(--color-text);
}

.export-card-cn {
  font-family: 'Nunito', sans-serif;
  font-size: 1.8rem;
  color: var(--color-text-light);
  margin-top: 12px;
}