* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: #f5f5f5;
  padding: 20px;
}

.home {
  max-width: 1200px;
  margin: 0 auto;
}

.home h1 {
  text-align: center;
  color: #333;
  margin-bottom: 30px;
  font-size: 2.5rem;
}

.stories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 20px;
  padding: 20px 0;
}

.story-card {
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  text-decoration: none;
  display: block;
  color: inherit;
}

.story-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.cover-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  display: block;
}

.story-card h2 {
  padding: 15px;
  font-size: 1.2rem;
  color: #333;
  text-align: center;
}

/* Story page styles */
.story-page {
  max-width: 800px;
  margin: 0 auto;
}

.story-container {
  background: white;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  min-height: 500px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.back-link {
  display: inline-block;
  margin-bottom: 20px;
  color: #42b983;
  text-decoration: none;
  font-weight: 500;
}

.back-link:hover {
  text-decoration: underline;
}

/* Cover pages */
.cover-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 400px;
  gap: 30px;
}

.cover-image-large {
  max-width: 400px;
  width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.cover-title {
  font-size: 3rem;
  color: #333;
  margin: 0;
}

.the-end {
  font-size: 3rem;
  color: #42b983;
  margin: 0;
  font-weight: bold;
}

/* Content pages */
.content-page {
  display: flex;
  flex-direction: column;
  gap: 30px;
  min-height: 400px;
}

.page-images {
  display: flex;
  gap: 15px;
  justify-content: center;
  flex-wrap: wrap;
}

.page-image {
  max-width: 250px;
  width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.cover-back-image {
  max-width: 400px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.page-sentences {
  display: flex;
  flex-direction: column;
  gap: 20px;
  text-align: center;
}

.sentence {
  font-size: 1.4rem;
  line-height: 1.8;
  color: #333;
}

.cover-back-text .sentence {
  font-size: 2.5rem;
  font-weight: bold;
}

.word {
  display: inline;
  margin-right: 0.25em;
  transition: color 0.3s ease, transform 1s ease;
}

.word-completed {
  color: #42b983;
  font-weight: bold;
  animation: wordComplete 1s ease;
  position: relative;
}

/* Spark particles for fireworks effect */
.spark-particle {
  position: fixed;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%, -50%);
}

.word-current {
  color: #2196f3;
  font-weight: bold;
}

@keyframes wordComplete {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}

.page-complete {
  margin-top: 20px;
  padding: 15px;
  background: #42b983;
  color: white;
  border-radius: 8px;
  font-size: 1.2rem;
  font-weight: bold;
  text-align: center;
}

/* Story content container */
.story-content-container {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Progress indicator */
.progress-indicator {
  font-size: 1.1rem;
  color: #666;
  font-weight: 500;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  margin-bottom: 15px;
}

/* Progress bar */
.progress-bar {
  display: flex;
  gap: 0; /* Squares touch */
  justify-content: center;
  flex-wrap: nowrap; /* Keep on one line */
  margin: 15px 0;
  width: 100%; /* Auto-adjust width */
  padding: 5px 0;
  box-sizing: border-box;
  overflow-x: auto;
}

.progress-dot {
  flex: 1 1 auto; /* Auto-adjust size */
  min-width: 4px; /* Minimum size for dots */
  height: 10px;
  border-radius: 0; /* Squares */
  background: #ccc;
  transition: all 0.2s;
}

.progress-dot.current {
  transform: scale(1.3);
  box-shadow: 0 0 0 3px rgba(66, 185, 131, 0.3);
  background: #42b983;
}

/* Navigation */
.navigation {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 15px;
  margin-bottom: 20px;
  padding: 10px 15px;
  background: #f9f9f9;
  border-radius: 8px;
  gap: 12px;
  flex-wrap: wrap;
}

.nav-button {
  padding: 10px 20px;
  font-size: 0.95rem;
  background: #42b983; /* Default green, overridden by specific classes */
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s;
  flex: 0 1 auto;
  min-width: 80px;
}

.nav-button:hover:not(:disabled) {
  background: #35a372; /* Darker green */
}

.prev-button {
  background: #9e9e9e; /* Grey */
}

.prev-button:hover:not(:disabled) {
  background: #757575; /* Darker grey */
}

.next-button {
  background: #42b983; /* Green */
}

.next-button:hover:not(:disabled) {
  background: #35a372; /* Darker green */
}

.nav-button:disabled {
  background: #ccc;
  cursor: not-allowed;
  opacity: 0.6;
}

.page-indicator {
  font-size: 1.1rem;
  color: #666;
  font-weight: 500;
  flex: 0 0 auto;
  text-align: center;
}

/* Mobile responsive styles */
@media (max-width: 768px) {
  body {
    padding: 10px;
  }

  .story-container {
    padding: 15px;
  }

  .navigation {
    flex-direction: row;
    gap: 12px;
    padding: 15px;
  }

  .nav-button {
    flex: 1 1 auto;
    padding: 14px 20px;
    font-size: 1rem;
  }

  .progress-indicator {
    font-size: 1rem;
  }

  .progress-bar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .progress-dot {
    min-width: 3px;
    height: 8px;
  }

  .sentence {
    font-size: 1.2rem;
    line-height: 1.5;
  }

  .cover-back-text .sentence {
    font-size: 2rem;
  }

  .page-image {
    max-width: 100%;
  }

  .cover-back-image {
    max-width: 100%;
  }

  .recognize-button {
    width: 100%;
    min-width: auto;
  }

  .recognize-container {
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .sentence {
    font-size: 1.1rem;
    line-height: 1.4;
  }

  .cover-back-text .sentence {
    font-size: 1.6rem;
  }

  .nav-button {
    font-size: 0.95rem;
    padding: 12px 16px;
  }

  .page-indicator {
    font-size: 0.95rem;
  }

  .cover-title {
    font-size: 2rem;
  }

  .the-end {
    font-size: 2rem;
  }
}

.loading, .error {
  text-align: center;
  padding: 40px;
  font-size: 1.2rem;
  color: #666;
}

.error {
  color: #d32f2f;
}

/* Recognize component styles */
.recognize-container {
  margin-bottom: 20px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.recognize-button {
  padding: 14px 28px;
  font-size: 1rem;
  background: #51cf66;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  min-width: 180px;
}

.recognize-button:hover:not(:disabled) {
  background: #40c057;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
}

.recognize-button.active {
  background: #ff6b6b;
}

.recognize-button.active:hover:not(:disabled) {
  background: #fa5252;
  box-shadow: 0 4px 8px rgba(255, 107, 107, 0.3);
}

.recognize-button:disabled {
  background: #ccc;
  cursor: not-allowed;
  opacity: 0.6;
  box-shadow: none;
}

.recognize-button:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.error-message {
  margin-top: 10px;
  color: #d32f2f;
  font-size: 0.9rem;
  text-align: right;
}
