:root {
  --bg-color: #f0f8ff;
  --primary-color: #333;
  --secondary-color: #555;
  --button-bg: #fff0d5;
  --button-hover-bg: #ffe4b5;
  --button-selected-bg: #b6d7a8;
  --correct-bg: #93c47d;
  --correct-hover-bg: #6aa84f;
  --incorrect-bg: #e06666; /* Added for general incorrect feedback */
  --border-color: #ccc;
  --border-width: 3px;
  --border-radius: 15px;
  --main-font: 'Quicksand', sans-serif; /* Updated to Quicksand */
  --canvas-border: #a8dadc;
  --canvas-drawing-color: #457b9d;
}

html, body {
  /* Prevent scrolling on the entire page */
  overflow: hidden; 
  height: 100%; /* Ensure body and html take full height */
  margin: 0; /* Remove default body margin */
  padding: 0; /* Remove default body padding */
}

body {
  font-family: var(--main-font);
  background-color: var(--bg-color);
  color: var(--primary-color);
  text-align: center;
  padding: 30px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

h1 {
  font-size: clamp(2em, 8vw, 3em);
  margin-bottom: 20px;
}

button {
  font-family: inherit;
  border: none;
  background: none;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

button:active {
    transform: scale(0.95);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.home-button {
    position: absolute;
    top: 20px;
    left: 20px;
    background-color: var(--home-button-bg);
    color: var(--primary-color);
    font-size: clamp(1em, 3vw, 1.2em);
    padding: 10px 20px;
    border-radius: var(--border-radius);
    border: 2px solid var(--border-color);
    box-shadow: 2px 2px 5px rgba(0,0,0,0.2);
}

.home-button:hover {
    background-color: var(--home-button-hover-bg);
}

.menu-button {
  background: var(--button-bg);
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 20px;
  margin: 15px;
  font-size: clamp(1em, 4vw, 1.5em);
  box-shadow: 3px 3px 8px rgba(0,0,0,0.2);
}

.menu-button:hover {
  background: var(--button-hover-bg);
}

/* Style for Flashcard Pack Selection buttons */
#flashcardPackSelection .menu-button {
    background-color: var(--button-bg);
    border: var(--border-width) solid var(--border-color);
    margin: 10px;
    padding: 15px;
    font-size: clamp(1em, 3.5vw, 1.3em);
}
#flashcardPackSelection .menu-button:hover {
    background-color: var(--button-hover-bg);
}


/* Re-added score and stars display */
.score {
  font-size: 1.5em;
  margin-bottom: 10px;
}

.stars {
  display: flex;
  justify-content: center;
  margin-bottom: 10px;
  height: 2em;
}

.star {
  font-size: 2em;
  margin: 0 5px;
}


#prompt {
  font-size: clamp(1em, 4vw, 1.3em); /* Made smaller */
  margin-bottom: 20px;
  min-height: 1.2em;
}

.blend-box {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  justify-content: center;
  gap: 15px;
  margin-bottom: 20px;
  max-width: 900px;
  width: 100%;
}

.blend-box.horizontal {
    flex-direction: row;
}

/* Styles for flashcard in Learn Mode */
#flashcardContainer {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 300px;
    min-height: 200px; /* Maintain height to prevent jumping */
    margin: 20px auto;
    background-color: var(--button-bg);
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: 3px 3px 8px rgba(0,0,0,0.2);
    opacity: 1; /* Default state */
    transition: opacity 0.3s ease-in-out; /* Smooth transition for opacity */
    padding-bottom: 10px; /* Add padding for description */
}

#flashcardContainer.fade-out {
    opacity: 0;
}

#flashcardLetter {
    font-size: clamp(4em, 15vw, 8em);
    font-weight: bold;
    color: var(--primary-color);
    margin: 0;
    padding: 20px;
    transition: color 0.3s ease-in-out; /* Smooth color transition for reveal */
}

#flashcardLetter.hidden-content { /* Renamed for clarity */
    color: transparent; /* Hide the letter but keep its space */
}

#flashcardPhonemeDescription {
    font-size: clamp(0.9em, 2.5vw, 1.1em);
    color: var(--secondary-color);
    margin-top: -10px; /* Pull it slightly closer to the letter */
    margin-bottom: 10px;
    min-height: 1.2em; /* Prevent layout shift if no text */
    text-align: center;
    padding: 0 10px;
}


.flashcard-nav-buttons {
    display: flex;
    justify-content: center;
    width: 100%;
    margin-top: 15px;
    padding: 0 10px;
}

.flashcard-nav-buttons button {
    background-color: var(--home-button-bg);
    padding: 10px 20px;
    border-radius: var(--border-radius);
    border: 2px solid var(--border-color);
    font-size: 1.2em;
    min-width: 100px;
}
.flashcard-nav-buttons button:hover {
    background-color: var(--home-button-hover-bg);
}

/* Buttons for flashcard self-assessment */
.flashcard-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
}
.flashcard-actions button {
    background-color: var(--correct-bg);
    color: white;
    padding: 10px 20px;
    border-radius: var(--border-radius);
    font-size: 1.1em;
    min-width: 120px;
    box-shadow: 1px 1px 3px rgba(0,0,0,0.2);
}
.flashcard-actions button:hover {
    opacity: 0.9;
}

#flashcardProgress {
    margin-top: 10px;
    font-size: 1em;
    color: var(--secondary-color);
}

/* Hide individual letter set containers in flashcard mode */
.letter-set-container {
    display: none; 
}

.letter-set-title {
  font-size: clamp(1.2em, 4vw, 1.5em);
  color: var(--secondary-color);
  margin-bottom: 15px;
  font-weight: bold;
  text-transform: uppercase;
}

.letters-wrapper {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.letter {
  background: var(--button-bg);
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--border-radius);
  width: clamp(70px, 18vw, 90px); /* Made larger */
  height: clamp(70px, 18vw, 90px); /* Made larger */
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(3em, 10vw, 4em); /* Increased font size */
  box-shadow: 2px 2px 5px rgba(0,0,0,0.1);
  transition: background-color 0.2s ease-in-out; /* For click feedback */
}

.letter.selected {
  background-color: var(--button-selected-bg);
  border-color: #79ac65;
  box-shadow: inset 1px 1px 3px rgba(0,0,0,0.3);
}

/* New styles for letter click feedback */
.letter.blended-active {
    background-color: var(--home-button-hover-bg); /* Highlight color on click */
    transform: scale(1.05); /* Slightly pop out */
    transition: all 0.1s ease-out;
}

.letter:hover,
.word-choice:hover {
  background: var(--button-hover-bg);
}

.blended-word {
  font-size: clamp(4em, 14vw, 6em); /* Increased font size */
  font-weight: bold;
  margin: 20px 0;
  color: var(--primary-color);
  min-height: 1.5em;
}

.choices {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  max-width: 900px;
  width: 100%;
}

.word-choice {
  background: var(--button-bg);
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--border-radius);
  padding: clamp(15px, 5vw, 30px);
  font-size: clamp(1.5em, 5vw, 2em);
  flex: 1 1 30%;
  min-width: 150px;
  box-shadow: 3px 3px 8px rgba(0,0,0,0.2);
  transition: background-color 0.3s ease-in-out, border-color 0.3s ease-in-out; /* For feedback colors */
}

/* New styles for word choice feedback */
.word-choice.correct-feedback {
    background-color: var(--correct-bg);
    border-color: #6aa84f;
    color: white;
}

.word-choice.incorrect-feedback {
    background-color: var(--incorrect-bg); 
    border-color: #a63f3f;
    color: white;
}

.reset-button {
  background: var(--button-bg);
  border: var(--border-width) solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 15px 25px;
  font-size: clamp(1em, 4vw, 1.5em);
  margin-bottom: 20px; /* Keep existing margin */
  /* margin-top: 40px; /* Removed this specific margin-top */
  box-shadow: 2px 2px 5px rgba(0,0,0,0.2);
}

.reset-button:hover {
  background: var(--button-hover-bg);
}

.feedback {
  font-size: clamp(1.5em, 6vw, 2em);
  margin-top: 30px;
  font-weight: bold;
  min-height: 1.5em;
}

.emoji {
  font-size: 1.5em;
  margin-left: 0.2em;
}

.play-again {
  background: var(--correct-bg);
  color: white;
  border-radius: var(--border-radius);
  padding: 20px 30px;
  font-size: clamp(1em, 4vw, 1.2em);
  margin-top: 30px;
  box-shadow: 3px 3px 8px rgba(0,0,0,0.2);
}

.play-again:hover {
  background: var(--correct-hover-bg);
}

.hidden {
    display: none !important;
}

/* Styles for Build a Word mode */
#buildWordDisplay {
    font-size: clamp(2.5em, 10vw, 4em);
    font-weight: bold;
    color: var(--primary-color);
    display: flex;
    justify-content: center;
    gap: 10px; /* Increased gap between letters in built word */
    border-bottom: 2px solid var(--secondary-color);
    padding-bottom: 10px;
    margin: 20px 0 30px 0; /* Combined margin properties */
    min-height: 1.5em;
    transition: background-color 0.3s ease-in-out, border-color 0.3s ease-in-out; /* For feedback colors */
}
/* New style for incorrect feedback on buildWordDisplay */
#buildWordDisplay.incorrect-feedback {
    background-color: var(--incorrect-bg); 
    border-color: #a63f3f;
    color: white;
}


/* New styles for the build word target flashcard */
#buildWordTargetFlashcard {
    display: flex;
    flex-direction: column; /* Allow text description below word */
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 300px;
    min-height: 100px; /* Adjusted height for words */
    margin: 15px auto;
    background-color: var(--button-bg);
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: 3px 33px 8px rgba(0,0,0,0.2);
    font-size: clamp(2.5em, 8vw, 4em); /* Size for target word */
    font-weight: bold;
    color: var(--primary-color);
    opacity: 0; /* Start hidden for fade-in */
    transition: opacity 0.5s ease-in-out;
}
#buildWordTargetFlashcard.fade-in {
    opacity: 1;
}


#letterPool {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
}

#letterPool .letter { /* Re-use existing .letter style for pool */
    background-color: var(--build-button-bg);
}
#letterPool .letter:hover {
    background-color: var(--build-button-hover-bg);
}
#letterPool .letter.selected { /* This class is now used for letters moved to userBuiltWord */
    background-color: var(--button-selected-bg);
    border-color: #79ac65;
}

.build-actions {
    margin-top: 30px;
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}
.build-actions button {
    background-color: var(--home-button-bg);
    padding: 15px 30px;
    border-radius: var(--border-radius);
    border: 2px solid var(--border-color);
    font-size: 1.2em;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.2);
}
.build-actions button:hover {
    background-color: var(--home-button-hover-bg);
}

/* Styles for the new Picture-Word Matching mode */
#pictureWordMatchingSection {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 600px;
    margin-top: 20px;
}

#pictureWordImage {
    width: clamp(180px, 45vw, 300px);
    height: clamp(180px, 45vw, 300px);
    object-fit: contain;
    margin-bottom: 25px;
    border-radius: 15px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

#pictureWordChoices {
    display: grid; /* Changed to grid */
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); /* Responsive grid, min width 140px, fills space */
    justify-items: center; /* Center items within their grid cells */
    gap: 15px;
    width: 100%;
}

#pictureWordChoices .word-choice {
    width: 100%; /* Make it fill its grid cell */
    max-width: 200px; /* Optional: cap max width for very large screens */
    padding: clamp(15px, 4vw, 25px);
    font-size: clamp(1.3em, 4.5vw, 1.8em);
}

/* Styles for the new Tricky Word Sorting Game */
#trickyWordSortingSection {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 900px;
    margin-top: 20px;
}

.sort-zones-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
    width: 100%;
    margin-bottom: 0; /* Reduced to 0 */
}

.sort-zone {
    flex: 1 1 45%; /* Two columns */
    min-width: 280px;
    border: 3px dashed var(--border-color); /* Changed to solid for clarity */
    border-radius: var(--border-radius);
    padding: 20px;
    min-height: 200px;
    display: flex;
    flex-direction: column; /* Keep column for h3 and words-container */
    align-items: center;
    background-color: #f8f8f8;
    transition: background-color 0.2s, border-color 0.2s;
}

.sort-zone .words-container { /* New style for inner container */
    display: flex;
    flex-wrap: wrap;
    justify-content: center; /* Center words horizontally */
    align-items: flex-start; /* Align words to the top of the container */
    width: 100%; /* Take full width of parent sort-zone */
    min-height: 150px; /* Give it some height to drop into */
    padding: 10px; /* Some padding inside */
    box-sizing: border-box; /* Include padding in width */
}

.sort-zone.drag-over {
    border-color: var(--drop-zone-active-border);
    background-color: #e0f2f7;
}

.sort-zone h3 {
    font-size: clamp(1.5em, 5vw, 2em);
    margin-bottom: 15px;
    color: var(--secondary-color);
}

.sortable-word {
    background: var(--button-bg);
    border: var(--border-width) solid var(--border-color);
    border-radius: 10px;
    padding: 10px 20px;
    margin: 8px;
    font-size: clamp(1.2em, 4vw, 1.5em);
    font-weight: bold;
    cursor: grab;
    box-shadow: 1px 2px 3px rgba(0,0,0,0.15);
    transition: transform 0.1s, box-shadow 0.1s, background-color 0.2s;
    user-select: none;
}

.sortable-word:hover {
    background-color: var(--button-hover-bg);
}

.sortable-word:active {
    cursor: grabbing;
    transform: scale(1.05);
    box-shadow: 2px 3px 5px rgba(0,0,0,0.2);
}

.word-pool-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-bottom: 0; /* Reduced to 0 */
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 15px;
    background-color: #e6f7ff; /* Light blue background for pool */
}

.sort-feedback {
    font-size: clamp(1.2em, 4vw, 1.6em);
    margin: 2px 0; /* Set margin to 2px top/bottom */
    min-height: 0; /* Allow it to collapse when empty */
    font-weight: bold;
}

#trickySortFeedback:empty {
    display: none; /* Hide when empty */
}

.sort-feedback.correct {
    color: var(--correct-bg);
}

.sort-feedback.incorrect {
    color: var(--incorrect-bg);
}

/* New style for action buttons (e.g., Check, Next) */
.action-buttons {
    background-color: var(--correct-bg); /* Use a distinct color */
    color: white; /* Ensure text is visible */
    border: var(--border-width) solid var(--correct-hover-bg); /* Solid border */
    border-radius: var(--border-radius);
    padding: 15px 30px;
    font-size: clamp(1em, 4vw, 1.5em);
    box-shadow: 2px 2px 5px rgba(0,0,0,0.2);
    /* Removed individual margin-top to be controlled by parent .sort-actions */
    display: inline-block; /* Explicitly set display */
    min-width: 180px; /* Added for guaranteed width */
}

.action-buttons:hover {
    background-color: var(--correct-hover-bg);
}

/* New container for sort buttons */
.sort-actions {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 0; /* Reduced to 0 */
    flex-wrap: wrap;
}

/* Styles for Canvas Drawing Tracer */
#canvasDrawingTracerSection {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: min(90vw, 400px);
    aspect-ratio: 1 / 1; 
    border-radius: 15px;
    padding: 0;
    box-sizing: border-box; 
    margin: 20px auto;
}

#letterCanvas {
    background-color: #ffffff;
    border: 3px solid var(--canvas-border);
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    touch-action: none;
    width: 100%;
    height: 100%;
    display: block;
}

.canvas-actions {
    display: flex;
    gap: 15px;
    margin-top: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.canvas-actions button {
    background-color: var(--home-button-bg);
    color: var(--primary-color);
    padding: 12px 25px;
    border-radius: var(--border-radius);
    border: 2px solid var(--border-color);
    font-size: clamp(1em, 3.5vw, 1.2em);
    box-shadow: 2px 2px 5px rgba(0,0,0,0.2);
}
.canvas-actions button:hover {
    background-color: var(--home-button-hover-bg);
}
