/* ===== RESET & BASE ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Lora', serif;
  min-height: 100vh;
  margin: 0;
  overflow: hidden;
  transition: background-color 0.3s, color 0.3s;
}

h1, h2, h3 {
  font-family: 'Fredoka One', cursive;
}

/* ===== LIGHT MODE (default) ===== */
body {
  background-color: #f0f0f0;
  color: #111;
}

/* ===== DARK MODE ===== */
body.dark {
  background-color: #111;
  color: #fff;
}

/* ===== SCREENS ===== */
.screen {
  display: none;
  width: 100vw;
  height: 100vh;
  padding: 40px 20px;
  overflow-y: auto;
}

.screen.active {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 40px;
}

/* ===== WELCOME SCREEN ===== */
.welcome-container {
  text-align: center;
  max-width: 500px;
}

.logo {
  font-size: 3.5rem;
  margin-bottom: 8px;
  letter-spacing: -1px;
}

.tagline {
  font-size: 1.1rem;
  opacity: 0.7;
  margin-bottom: 48px;
}

.theme-buttons {
  display: flex;
  gap: 20px;
  justify-content: center;
}

.theme-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 28px 36px;
  border: 2px solid #ccc;
  border-radius: 16px;
  background: transparent;
  color: inherit;
  font-family: 'Lora', serif;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.theme-btn:hover {
  transform: translateY(-2px);
}

/* Light mode button styles */
body:not(.dark) .theme-btn:hover {
  border-color: #111;
  background: #111;
  color: #fff;
}

/* Dark mode button styles */
body.dark .theme-btn {
  border-color: #444;
}

body.dark .theme-btn:hover {
  border-color: #fff;
  background: #fff;
  color: #111;
}

.theme-icon {
  font-size: 2rem;
}

/* ===== LANGUAGE SCREEN ===== */
.lang-container {
  text-align: center;
  max-width: 700px;
  width: 100%;
}

.lang-container h2 {
  font-size: 2rem;
  margin-bottom: 24px;
}

.lang-search {
  width: 100%;
  max-width: 400px;
  padding: 14px 20px;
  border-radius: 12px;
  border: 2px solid #ccc;
  font-family: 'Lora', serif;
  font-size: 1rem;
  margin-bottom: 28px;
  outline: none;
  transition: border-color 0.2s;
}

/* Light mode input */
body:not(.dark) .lang-search {
  background: #111;
  color: #fff;
  border-color: #111;
}

body:not(.dark) .lang-search::placeholder {
  color: #888;
}

/* Dark mode input */
body.dark .lang-search {
  background: #fff;
  color: #111;
  border-color: #fff;
}

body.dark .lang-search::placeholder {
  color: #888;
}

.lang-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  max-height: 50vh;
  overflow-y: auto;
  padding: 4px;
}

.lang-btn {
  padding: 12px 8px;
  border-radius: 10px;
  border: 2px solid #ddd;
  background: transparent;
  color: inherit;
  font-family: 'Lora', serif;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

.lang-btn:hover {
  transform: translateY(-1px);
}

/* Light mode lang buttons */
body:not(.dark) .lang-btn:hover,
body:not(.dark) .lang-btn.selected {
  background: #111;
  color: #fff;
  border-color: #111;
}

/* Dark mode lang buttons */
body.dark .lang-btn {
  border-color: #333;
}

body.dark .lang-btn:hover,
body.dark .lang-btn.selected {
  background: #fff;
  color: #111;
  border-color: #fff;
}

/* ===== MODE SELECTION SCREEN ===== */
.mode-container {
  text-align: center;
  max-width: 600px;
  width: 100%;
}

.mode-container h2 {
  font-size: 2rem;
  margin-bottom: 40px;
}

.mode-buttons {
  display: flex;
  gap: 24px;
  justify-content: center;
  flex-wrap: wrap;
}

.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 36px 32px;
  border-radius: 16px;
  border: 2px solid #ddd;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: all 0.2s;
  width: 240px;
}

.mode-btn:hover {
  transform: translateY(-3px);
}

body:not(.dark) .mode-btn:hover {
  background: #111;
  color: #fff;
  border-color: #111;
}

body.dark .mode-btn {
  border-color: #333;
}

body.dark .mode-btn:hover {
  background: #fff;
  color: #111;
  border-color: #fff;
}

.mode-icon {
  font-size: 2.5rem;
}

.mode-label {
  font-family: 'Fredoka One', cursive;
  font-size: 1.3rem;
}

.mode-desc {
  font-size: 0.85rem;
  opacity: 0.7;
}

/* ===== PREMIUM BADGE ===== */
.mode-btn-premium {
  position: relative;
  border-style: dashed;
}

.premium-badge {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 10px;
  border-radius: 8px;
  font-size: 0.7rem;
  font-family: 'Fredoka One', cursive;
  background: linear-gradient(135deg, #f1c40f, #e67e22);
  color: #fff;
}

/* ===== PASTE SCREEN ===== */
.paste-container {
  text-align: center;
  max-width: 550px;
  width: 100%;
}

.paste-container h2 {
  font-size: 1.8rem;
  margin-bottom: 24px;
}

.paste-textarea {
  height: 300px;
  resize: vertical;
  text-align: left;
}

.paste-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 20px;
}

/* ===== PLACEHOLDER & BACK BUTTON ===== */
.placeholder-container {
  text-align: center;
}

.placeholder-container h2 {
  font-size: 2rem;
  margin-bottom: 12px;
}

.placeholder-container p {
  opacity: 0.6;
  margin-bottom: 24px;
}

.back-btn {
  padding: 12px 28px;
  border-radius: 10px;
  border: 2px solid currentColor;
  background: transparent;
  color: inherit;
  font-family: 'Lora', serif;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

body:not(.dark) .back-btn:hover {
  background: #111;
  color: #fff;
}

body.dark .back-btn:hover {
  background: #fff;
  color: #111;
}

/* ===== FORM CONTAINER ===== */
.form-container {
  max-width: 550px;
  width: 100%;
}

.form-step {
  display: none;
}

.form-step.active {
  display: block;
}

.form-step h2 {
  font-size: 1.8rem;
  margin-bottom: 28px;
  text-align: center;
}

/* ===== PROGRESS BAR ===== */
.progress-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 36px;
}

.progress-step {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Fredoka One', cursive;
  font-size: 0.9rem;
  border: 2px solid #ccc;
  transition: all 0.3s;
}

body:not(.dark) .progress-step.active {
  background: #111;
  color: #fff;
  border-color: #111;
}

body.dark .progress-step {
  border-color: #444;
}

body.dark .progress-step.active {
  background: #fff;
  color: #111;
  border-color: #fff;
}

.progress-line {
  width: 40px;
  height: 2px;
  background: #ccc;
}

body.dark .progress-line {
  background: #444;
}

/* ===== FORM LABELS ===== */
.form-label {
  display: block;
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  margin-bottom: 10px;
  margin-top: 24px;
}

/* ===== FORM INPUTS ===== */
.form-input {
  width: 100%;
  padding: 14px 18px;
  border-radius: 12px;
  border: 2px solid #ccc;
  font-family: 'Lora', serif;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

body:not(.dark) .form-input {
  background: #111;
  color: #fff;
  border-color: #111;
}

body:not(.dark) .form-input::placeholder {
  color: #888;
}

body.dark .form-input {
  background: #fff;
  color: #111;
  border-color: #fff;
}

body.dark .form-input::placeholder {
  color: #888;
}

/* ===== AGE / PAGES SLIDER ===== */
.age-slider-container {
  display: flex;
  align-items: center;
  gap: 16px;
}

.age-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  border-radius: 4px;
  outline: none;
}

body:not(.dark) .age-slider {
  background: #ddd;
}

body:not(.dark) .age-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #111;
  cursor: pointer;
}

body.dark .age-slider {
  background: #333;
}

body.dark .age-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
}

.age-display {
  font-family: 'Fredoka One', cursive;
  font-size: 1.5rem;
  min-width: 40px;
  text-align: center;
}

/* ===== CHIPS ===== */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  padding: 10px 20px;
  border-radius: 20px;
  border: 2px solid #ddd;
  background: transparent;
  color: inherit;
  font-family: 'Lora', serif;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

/* Light mode chips */
body:not(.dark) .chip:hover,
body:not(.dark) .chip.selected {
  background: #111;
  color: #fff;
  border-color: #111;
}

/* Dark mode chips */
body.dark .chip {
  border-color: #333;
}

body.dark .chip:hover,
body.dark .chip.selected {
  background: #fff;
  color: #111;
  border-color: #fff;
}

/* Genre color chips */
.chip-adventure.selected { background: #2ecc71 !important; border-color: #2ecc71 !important; color: #fff !important; }
.chip-historical.selected { background: #e67e22 !important; border-color: #e67e22 !important; color: #fff !important; }
.chip-scifi.selected { background: #3498db !important; border-color: #3498db !important; color: #fff !important; }
.chip-magic.selected { background: #9b59b6 !important; border-color: #9b59b6 !important; color: #fff !important; }

/* ===== FORM BUTTONS ===== */
.form-buttons {
  display: flex;
  justify-content: space-between;
  margin-top: 36px;
}

.next-btn {
  padding: 14px 36px;
  border-radius: 12px;
  border: none;
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s;
}

body:not(.dark) .next-btn {
  background: #111;
  color: #fff;
}

body:not(.dark) .next-btn:hover {
  transform: translateY(-2px);
}

body.dark .next-btn {
  background: #fff;
  color: #111;
}

body.dark .next-btn:hover {
  transform: translateY(-2px);
}

.generate-btn {
  padding: 14px 36px;
  border-radius: 12px;
  border: none;
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s;
  background: linear-gradient(135deg, #9b59b6, #3498db);
  color: #fff;
}

.generate-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(155, 89, 182, 0.4);
}

/* ===== LOADING SCREEN ===== */
.loading-container {
  text-align: center;
  max-width: 500px;
}

.loading-spinner {
  width: 60px;
  height: 60px;
  border: 4px solid #ddd;
  border-top: 4px solid #9b59b6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 24px;
}

body.dark .loading-spinner {
  border-color: #333;
  border-top-color: #9b59b6;
}

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

.loading-container h2 {
  font-size: 1.8rem;
  margin-bottom: 12px;
}

.loading-text {
  opacity: 0.7;
  margin-bottom: 24px;
}

.loading-tips {
  padding: 16px 24px;
  border-radius: 12px;
  font-style: italic;
  opacity: 0.8;
}

body:not(.dark) .loading-tips {
  background: #e8e8e8;
}

body.dark .loading-tips {
  background: #1e1e1e;
}

/* ===== BOOK READER ===== */
.reader-container {
  max-width: 650px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  padding: 20px 0;
}

.reader-cover {
  text-align: center;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 40px 20px;
}

.reader-title {
  font-size: 2.5rem;
  margin-bottom: 12px;
  line-height: 1.2;
}

.reader-subtitle {
  font-size: 1.2rem;
  opacity: 0.7;
  margin-bottom: 24px;
}

.reader-dedication {
  font-style: italic;
  opacity: 0.6;
  font-size: 1rem;
}

.reader-page {
  flex: 1;
  width: 100%;
  overflow-y: auto;
  padding: 20px;
}

.reader-page-number {
  text-align: center;
  font-family: 'Fredoka One', cursive;
  font-size: 0.9rem;
  opacity: 0.5;
  margin-bottom: 20px;
}

.reader-page-text {
  font-size: 1.1rem;
  line-height: 1.8;
  margin-bottom: 24px;
}

.reader-page-img {
  padding: 12px;
  border-radius: 12px;
  text-align: center;
  font-size: 0.9rem;
  overflow: hidden;
}

body:not(.dark) .reader-page-img {
  background: #f0f0f0;
}

body.dark .reader-page-img {
  background: #1e1e1e;
}

/* Actual illustration image */
.reader-illustration {
  width: 100%;
  max-width: 500px;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

/* Image loading spinner */
.img-loading {
  padding: 32px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  opacity: 0.7;
}

.img-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #ddd;
  border-top: 3px solid #9b59b6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

body.dark .img-spinner {
  border-color: #333;
  border-top-color: #9b59b6;
}

.img-loading p {
  font-family: 'Fredoka One', cursive;
  font-size: 0.9rem;
}

.img-desc {
  opacity: 0.6;
  font-style: italic;
}

/* Reader navigation */
.reader-nav {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 16px 0;
  width: 100%;
  justify-content: center;
}

.reader-nav-btn {
  padding: 12px 24px;
  border-radius: 10px;
  border: none;
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

body:not(.dark) .reader-nav-btn {
  background: #111;
  color: #fff;
}

body.dark .reader-nav-btn {
  background: #fff;
  color: #111;
}

.reader-nav-btn:hover {
  transform: translateY(-2px);
}

.reader-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

/* ===== TEXT-TO-SPEECH CONTROLS ===== */
.tts-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  justify-content: center;
  padding: 8px 0;
}

.tts-btn {
  padding: 10px 24px;
  border-radius: 20px;
  border: none;
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  background: linear-gradient(135deg, #e67e22, #f39c12);
  color: #fff;
}

.tts-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(230, 126, 34, 0.4);
}

.tts-btn.speaking {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4); }
  50% { box-shadow: 0 0 0 10px rgba(231, 76, 60, 0); }
}

.tts-speed {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'Fredoka One', cursive;
  font-size: 0.85rem;
  opacity: 0.8;
}

.tts-speed label {
  margin-right: 2px;
}

.tts-speed-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #ddd;
  background: transparent;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

body:not(.dark) .tts-speed-btn.active {
  background: #111;
  border-color: #111;
}

body.dark .tts-speed-btn {
  border-color: #444;
}

body.dark .tts-speed-btn.active {
  background: #fff;
  border-color: #fff;
}

/* Voice gender buttons */
.tts-voice {
  display: flex;
  gap: 6px;
}

.tts-voice-btn {
  padding: 6px 14px;
  border-radius: 16px;
  border: 2px solid #ddd;
  background: transparent;
  color: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'Lora', serif;
}

body:not(.dark) .tts-voice-btn.active {
  background: #111;
  color: #fff;
  border-color: #111;
}

body.dark .tts-voice-btn {
  border-color: #444;
}

body.dark .tts-voice-btn.active {
  background: #fff;
  color: #111;
  border-color: #fff;
}

/* Parent reading mode button */
.tts-parent-btn {
  padding: 8px 20px;
  border-radius: 16px;
  border: 2px dashed #e67e22;
  background: transparent;
  color: inherit;
  font-family: 'Fredoka One', cursive;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

.tts-parent-btn:hover {
  background: #e67e22;
  color: #fff;
  border-style: solid;
}

.tts-parent-btn.active {
  background: #e67e22;
  color: #fff;
  border-style: solid;
}

/* Parent mode — large text */
.reader-page-text.parent-mode {
  font-size: 1.8rem;
  line-height: 2;
  text-align: center;
}

.reader-nav-info {
  font-family: 'Fredoka One', cursive;
  font-size: 0.9rem;
  opacity: 0.6;
  min-width: 80px;
  text-align: center;
}

.reader-bottom-buttons {
  display: flex;
  gap: 16px;
  padding-top: 8px;
}

/* ===== SCROLLBAR ===== */
.lang-grid::-webkit-scrollbar {
  width: 6px;
}

.lang-grid::-webkit-scrollbar-track {
  background: transparent;
}

.lang-grid::-webkit-scrollbar-thumb {
  background: #aaa;
  border-radius: 3px;
}

body.dark .lang-grid::-webkit-scrollbar-thumb {
  background: #555;
}

/* ===== SEARCH SCREEN ===== */
.search-container {
  max-width: 600px;
  width: 100%;
}

.search-container h2 {
  font-size: 2rem;
  margin-bottom: 20px;
  text-align: center;
}

.search-results {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 45vh;
  overflow-y: auto;
}

.search-loading {
  text-align: center;
  opacity: 0.6;
  font-style: italic;
}

.search-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border-radius: 12px;
  transition: transform 0.2s;
}

body:not(.dark) .search-card {
  background: #fff;
  border: 2px solid #ddd;
}

body.dark .search-card {
  background: #1e1e1e;
  border: 2px solid #333;
}

.search-card:hover {
  transform: translateY(-2px);
}

.search-cover {
  width: 60px;
  height: 80px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}

.search-cover-placeholder {
  width: 60px;
  height: 80px;
  border-radius: 6px;
  flex-shrink: 0;
}

body:not(.dark) .search-cover-placeholder {
  background: #e8e8e8;
}

body.dark .search-cover-placeholder {
  background: #333;
}

.search-card-info {
  flex: 1;
  min-width: 0;
}

.search-card-title {
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  margin-bottom: 4px;
}

.search-card-author {
  font-size: 0.85rem;
  opacity: 0.7;
  margin-bottom: 4px;
}

.search-card-source {
  font-size: 0.75rem;
  opacity: 0.5;
}

.search-read-btn {
  flex-shrink: 0;
  text-decoration: none;
  font-size: 0.85rem;
  padding: 10px 20px;
}

/* Not found message */
.search-not-found {
  text-align: center;
  margin-top: 32px;
}

.search-not-found h3 {
  font-size: 1.5rem;
  margin-bottom: 12px;
}

.search-not-found p {
  opacity: 0.7;
  margin-bottom: 8px;
}

.search-not-found .generate-btn {
  margin-top: 16px;
}

/* ===== PRICE BOX ===== */
.price-box {
  margin-top: 24px;
  padding: 20px;
  border-radius: 12px;
  text-align: center;
}

body:not(.dark) .price-box {
  background: #fff;
  border: 2px solid #ddd;
}

body.dark .price-box {
  background: #1e1e1e;
  border: 2px solid #333;
}

.price-label {
  font-family: 'Fredoka One', cursive;
  font-size: 0.9rem;
  opacity: 0.6;
  margin-bottom: 4px;
}

.price-amount {
  font-family: 'Fredoka One', cursive;
  font-size: 2rem;
  background: linear-gradient(135deg, #9b59b6, #3498db);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.price-detail {
  font-size: 0.85rem;
  opacity: 0.6;
  margin-bottom: 12px;
}

.price-table {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 12px 0;
}

.price-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  opacity: 0.5;
  transition: all 0.2s;
}

.price-row.active {
  opacity: 1;
  font-weight: 600;
}

body:not(.dark) .price-row.active {
  background: #f0f0f0;
}

body.dark .price-row.active {
  background: #2a2a2a;
}

.price-note {
  font-size: 0.8rem;
  opacity: 0.7;
  margin-top: 8px;
  font-style: italic;
}

/* ===== CHILDREN FIELDS ===== */
.child-block {
  margin-top: 16px;
  padding: 16px;
  border-radius: 12px;
}

.child-block + .child-block {
  margin-top: 20px;
}

body:not(.dark) .child-block + .child-block {
  border-top: 2px solid #ddd;
  padding-top: 20px;
}

body.dark .child-block + .child-block {
  border-top: 2px solid #333;
  padding-top: 20px;
}

.child-header {
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  margin-bottom: 12px;
  opacity: 0.7;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 500px) {
  .logo {
    font-size: 2.5rem;
  }

  .theme-buttons {
    flex-direction: column;
    align-items: center;
  }

  .mode-buttons {
    flex-direction: column;
    align-items: center;
  }
}
