body {
  font-family: sans-serif;
  margin: 0;
  background-color: #f4f4f9;
  color: #333;
}

header {
  background-color: #4a4e9d;
  color: white;
  padding: 1rem;
  text-align: center;
  position: relative;
  overflow: hidden;
  z-index: 1;
}

main {
  padding: 1rem;
  max-width: 1200px;
  margin: 0 auto;
}

.controls {
  background-color: white;
  padding: 1rem;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  margin-bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: center;
}

select, input, button {
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
  background-color: white;
}

button {
  cursor: pointer;
  background-color: #e9e9ed;
}

button:hover {
  background-color: #dcdce1;
}

#welcome {
  text-align: center;
  padding: 2rem;
  background-color: white;
  border-radius: 8px;
}

.sentence {
  background-color: white;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.jp {
  font-size: 1.5rem;
  font-weight: bold;
  margin: 0 0 0.5rem 0;
}

.romaji {
  font-style: italic;
  color: #555;
  margin: 0 0 0.5rem 0;
}

.en {
  color: #333;
  margin: 0;
}

.error {
  color: red;
  font-weight: bold;
  text-align: center;
  padding: 2rem;
  background-color: white;
  border-radius: 8px;
}

@media (min-width: 768px) {
  #sentenceList {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
  }
  #sentenceList .sentence {
    margin-bottom: 0;
  }
}

/* --- Main Navigation Bar in Header --- */
.main-nav {
  display: flex;
  justify-content: center;
  gap: 1rem;
  padding-top: 1rem;
}

.main-nav button {
  background-color: rgba(255, 255, 255, 0.2);
  color: white;
  border: 1px solid white;
  padding: 0.5rem 1.5rem;
  font-size: 1rem;
  border-radius: 20px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.main-nav button:hover {
  background-color: rgba(255, 255, 255, 0.4);
}

.main-nav button.active {
    background-color: white;
    color: #4a4e9d;
    font-weight: bold;
}

/* =============================================== */
/* Build Conversation Mode Styles                  */
/* =============================================== */
#peoplePrompt {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: white;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#peoplePrompt label {
  font-weight: bold;
}

#buildMode h2 {
  text-align: center;
  margin-top: 0;
}

.build-mode-controls {
  display: flex;
  justify-content: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
  align-items: center;
}

.word-bank-container {
  display: flex;
  align-items: center;
  margin-bottom: 1.5rem;
}

.scroll-arrow {
  font-size: 2rem;
  padding: 0 1rem;
  border: none;
  background: none;
  cursor: pointer;
}

.word-bank {
  flex-grow: 1;
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding: 1rem;
  background-color: #e9e9ed;
  border-radius: 8px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.word-bank::-webkit-scrollbar {
    display: none;
}

.word-block {
  position: relative;
  background-color: white;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  border: 1px solid #ccc;
  white-space: nowrap;
  cursor: grab;
  user-select: none;
}

#conversationLanesContainer {
  display: flex;
  flex-direction: row;
  gap: 1rem;
  flex-wrap: wrap;
  justify-content: center;
}

.conversation-lane {
  background-color: white;
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 1rem;
}

.conversation-lane h4 {
  margin-top: 0;
  border-bottom: 1px solid #eee;
  padding-bottom: 0.5rem;
}

.conversation-lane-dropzone {
  min-height: 60px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: flex-start;
}

.sequence-badge {
  position: absolute;
  top: -8px;
  left: -8px;
  background-color: #4a4e9d;
  color: white;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: bold;
}

/* =============================================== */
/* Quiz Setup Mode Styles                          */
/* =============================================== */
#quizModeSetup {
  padding: 1rem 0;
}

.quiz-setup-card {
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
  padding: 1.5rem 2rem;
  max-width: 800px;
  margin: 0 auto;
}

.quiz-setup-card h2 {
  margin-top: 0;
  text-align: center;
}

.quiz-setup-card p {
  text-align: center;
  margin-bottom: 2rem;
  color: #555;
}

.quiz-setup-section {
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1rem 1.5rem;
  margin-bottom: 1.5rem;
}

.quiz-setup-section legend {
  font-weight: bold;
  font-size: 1.1rem;
  padding: 0 0.5rem;
  color: #4a4e9d;
}

.quiz-levels-container {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

.quiz-lesson-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #eee;
}

.lesson-square {
  border: 2px solid;
  border-radius: 4px;
  padding: 0.5rem;
  text-align: center;
  cursor: pointer;
  font-weight: bold;
  transition: all 0.2s;
  user-select: none;
}

.lesson-square.level-1 { background-color: #e3f2fd; border-color: #90caf9; }
.lesson-square.level-2 { background-color: #e8f5e9; border-color: #a5d6a7; }
.lesson-square.level-3 { background-color: #fff3e0; border-color: #ffcc80; }
.lesson-square.level-4 { background-color: #fce4ec; border-color: #f48fb1; }
.lesson-square.level-5 { background-color: #ede7f6; border-color: #b39ddb; }

.lesson-square.selected {
  color: white;
}
.lesson-square.level-1.selected { background-color: #1976d2; border-color: #1976d2; }
.lesson-square.level-2.selected { background-color: #388e3c; border-color: #388e3c; }
.lesson-square.level-3.selected { background-color: #f57c00; border-color: #f57c00; }
.lesson-square.level-4.selected { background-color: #d81b60; border-color: #d81b60; }
.lesson-square.level-5.selected { background-color: #5e35b1; border-color: #5e35b1; }

.quiz-config-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1rem;
  align-items: center;
}

.device-check-container {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.mic-test-result {
    font-style: italic;
    color: #555;
}

.start-quiz-container {
  text-align: center;
  margin-top: 2rem;
}

.start-quiz-btn {
  background-color: #4a4e9d;
  color: white;
  font-size: 1.2rem;
  padding: 0.8rem 2.5rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.start-quiz-btn:hover {
  background-color: #3b3f8a;
}

/* =============================================== */
/* Quiz Overlay Styles                             */
/* =============================================== */
.quiz-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.quiz-modal {
  background-color: white;
  border-radius: 12px;
  box-shadow: 0 5px 20px rgba(0,0,0,0.3);
  width: 90%;
  max-width: 700px;
  padding: 2rem;
  text-align: center;
  position: relative; /* Needed for the in-modal celebration */
  overflow: hidden; /* Hide confetti that goes off-modal */
}

.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  font-size: 1.1rem;
  color: #555;
}

.exit-quiz-btn {
  background: none;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  color: #aaa;
}

.quiz-question-area {
  margin-bottom: 2rem;
}

.quiz-answer-area {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.quiz-answer-area button.correct {
    background-color: #4caf50;
    color: white;
    border-color: #4caf50;
}

.quiz-answer-area button.incorrect {
    background-color: #f44336;
    color: white;
    border-color: #f44336;
    opacity: 0.7;
}

.quiz-footer {
  margin-top: 1.5rem;
  min-height: 50px;
}

.quiz-feedback {
  font-size: 1.1rem;
  font-weight: bold;
}

#celebrationOverlay {
    position: absolute; /* Changed to absolute */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10; /* Sit on top of modal content */
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    background-color: #4a4e9d;
    background-image: url('img/sakura-pattern.png');
    background-repeat: repeat;
    background-size: 180px auto;
    animation: scroll-background 30s linear infinite;
}

#celebrationOverlay h2 {
    font-size: 3rem; /* Adjusted for modal size */
    color: white;
    text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.5);
}

#celebrationOverlay p {
    font-size: 1.2rem; /* Adjusted for modal size */
    color: #eee;
    text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.5);
}

@keyframes scroll-background {
    from { background-position: 0 0; }
    to { background-position: -180px 0; }
}

/* =============================================== */
/* Animated Header Background                      */
/* =============================================== */
header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url('img/sakura-pattern.png');
  background-repeat: repeat;
  background-size: 180px auto;
  animation: sakura-fade 40s ease-in-out infinite alternate;
  z-index: -1;
}

@keyframes sakura-fade {
  0% { opacity: 0.1; }
  50% { opacity: 0.3; }
  100% { opacity: 0.1; }
}