/* ==========================================
   LINGODEV - DESIGN SYSTEM & STYLESHEET
   ========================================== */

:root {
  /* HSL Color Palette (Developer Theme) */
  --bg-main: hsl(222, 47%, 9%);       /* Deep Space */
  --bg-card: hsla(222, 47%, 15%, 0.7); /* Translucent Slate */
  --border-color: hsl(223, 27%, 24%);  /* Slate Border */
  
  --text-main: hsl(210, 40%, 98%);     /* Bright White/Blue */
  --text-muted: hsl(215, 20%, 65%);    /* Silver Gray */
  
  /* Accent Colors */
  --color-primary: hsl(263, 90%, 65%);   /* Electric Violet */
  --color-primary-hover: hsl(263, 90%, 70%);
  --color-secondary: hsl(217, 91%, 60%); /* Royal Blue */
  --color-accent: hsl(190, 95%, 50%);    /* Neon Cyan */
  
  /* Game State Colors */
  --color-success: hsl(142, 70%, 45%);   /* Emerald Green */
  --color-success-bg: hsla(142, 70%, 15%, 0.8);
  --color-success-border: hsl(142, 70%, 30%);
  
  --color-error: hsl(350, 85%, 55%);     /* Crimson Red */
  --color-error-bg: hsla(350, 85%, 15%, 0.8);
  --color-error-border: hsl(350, 85%, 30%);
  
  /* Utilities */
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --shadow-glow: 0 0 20px hsla(263, 90%, 65%, 0.25);
  --shadow-card: 0 10px 30px rgba(0, 0, 0, 0.4);
  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-main);
  color: var(--text-main);
  height: 100dvh;
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  position: fixed;
  left: 0;
  top: 0;
  background-image: 
    radial-gradient(at 0% 0%, hsla(263, 90%, 65%, 0.08) 0px, transparent 50%),
    radial-gradient(at 100% 100%, hsla(190, 95%, 50%, 0.08) 0px, transparent 50%);
}

/* App Viewport Container */
.app-container {
  width: 100%;
  max-width: 650px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  padding: 0;
  overflow: hidden;
}

@media (min-width: 650px) {
  .app-container {
    height: 85vh;
    max-height: 750px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background-color: hsla(222, 47%, 6%, 0.5);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-card);
  }
}

/* Screens States */
.screen {
  display: none;
  flex-direction: column;
  width: 100%;
  height: 100%;
  max-height: 100%;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: opacity var(--transition-normal);
}

.screen.active {
  display: flex;
  opacity: 1;
}

/* Buttons */
.primary-btn {
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
  color: #fff;
  border: none;
  padding: 16px 32px;
  font-size: 1.1rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  cursor: pointer;
  box-shadow: var(--shadow-glow);
  transition: all var(--transition-fast);
  text-align: center;
  position: relative;
  overflow: hidden;
}

.primary-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 0 25px hsla(263, 90%, 65%, 0.4);
  filter: brightness(1.1);
}

.primary-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.primary-btn.disabled, .primary-btn:disabled {
  background: hsl(223, 15%, 20%);
  color: var(--text-muted);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.secondary-btn {
  background-color: transparent;
  color: var(--text-muted);
  border: 2px solid var(--border-color);
  padding: 16px 32px;
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.secondary-btn:hover {
  border-color: var(--text-muted);
  color: var(--text-main);
  background-color: hsla(222, 47%, 20%, 0.3);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 8px;
  transition: color var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  color: var(--text-main);
}

/* 1. WELCOME SCREEN */
#welcome-screen {
  align-items: center;
  padding: 40px 24px;
  overflow-y: auto !important;
  overflow-x: hidden;
}

.welcome-card {
  width: 100%;
  max-width: 500px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 32px;
  margin: 20px 0;
}

.logo-area h1 {
  font-size: 3.5rem;
  font-weight: 800;
  letter-spacing: -1px;
  margin-top: 10px;
  background: linear-gradient(135deg, var(--text-main) 30%, var(--color-accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-area h1 span {
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-area .mascot-avatar {
  font-size: 4.5rem;
  animation: float 4s ease-in-out infinite;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1.05rem;
  line-height: 1.6;
}

.config-section {
  display: flex;
  flex-direction: column;
  gap: 24px;
  text-align: left;
}

.config-group h3 {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--color-accent);
  margin-bottom: 12px;
}

.radio-tiles {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.tile-option {
  position: relative;
  cursor: pointer;
}

.tile-option input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.tile-label {
  display: block;
  padding: 14px;
  background-color: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  font-weight: 600;
  text-align: center;
  transition: all var(--transition-fast);
  color: var(--text-muted);
}

.tile-option input:checked + .tile-label {
  border-color: var(--color-primary);
  background-color: hsla(263, 90%, 65%, 0.1);
  color: var(--text-main);
  box-shadow: 0 0 15px hsla(263, 90%, 65%, 0.15);
}

.tile-option:hover .tile-label {
  border-color: var(--text-muted);
}

/* Animations */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.pulse {
  animation: pulse-glow 2.5s infinite;
}

@keyframes pulse-glow {
  0% { box-shadow: 0 0 0 0 hsla(263, 90%, 65%, 0.4); }
  70% { box-shadow: 0 0 0 15px hsla(263, 90%, 65%, 0); }
  100% { box-shadow: 0 0 0 0 hsla(263, 90%, 65%, 0); }
}

/* 2. GAME SCREEN */
#game-screen {
  height: 100%;
  overflow: hidden;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  gap: 16px;
  border-bottom: 1px solid var(--border-color);
}

.progress-bar-container {
  flex: 1;
  height: 16px;
  background-color: var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--color-accent), var(--color-secondary));
  border-radius: 8px;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 10px hsla(190, 95%, 50%, 0.4);
}

.hearts-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.score-badge {
  background-color: hsla(190, 95%, 50%, 0.1);
  border: 1px solid hsla(190, 95%, 50%, 0.3);
  color: var(--color-accent);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 700;
}

.hearts-display {
  display: flex;
  gap: 4px;
  font-size: 1.25rem;
}

.heart {
  opacity: 0.3;
  transform: scale(0.85);
  transition: all var(--transition-fast);
}

.heart.active {
  opacity: 1;
  transform: scale(1);
  animation: heart-beat 1.2s infinite alternate;
}

@keyframes heart-beat {
  0% { transform: scale(1); }
  100% { transform: scale(1.1); }
}

.heart.shake {
  animation: shake 0.5s ease-in-out;
}

/* Game Content layout */
.game-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px 20px;
  gap: 20px;
  max-width: 550px;
  margin: 0 auto;
  width: 100%;
  overflow-y: auto;
}

.prompt-bubble-container {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  flex-shrink: 0;
}

.mascot-small {
  font-size: 2.5rem;
}

.speech-bubble {
  position: relative;
  background-color: var(--bg-card);
  border: 2px solid var(--border-color);
  padding: 16px 20px;
  border-radius: var(--radius-md);
  flex: 1;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.speech-bubble::before {
  content: '';
  position: absolute;
  left: -10px;
  top: 18px;
  width: 0;
  height: 0;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-right: 10px solid var(--border-color);
}

.speech-bubble::after {
  content: '';
  position: absolute;
  left: -7px;
  top: 18px;
  width: 0;
  height: 0;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-right: 10px solid hsl(222, 47%, 15%);
}

.instruction {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
  font-weight: 600;
}

#vietnamese-sentence {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.4;
}

/* Interactive Workspace Styles */
.workspace {
  min-height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex-shrink: 0;
}

/* Workspace Specifics: Sentence Builder */
.sentence-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px;
  border-bottom: 2px dashed var(--border-color);
  min-height: 70px;
  align-items: center;
}

.sentence-slots:focus {
  outline: none;
  border-bottom-color: var(--color-primary);
}

/* Tiles Styling */
.word-tile {
  background-color: var(--bg-card);
  border: 2px solid var(--border-color);
  border-bottom-width: 4px;
  color: var(--text-main);
  padding: 10px 18px;
  font-size: 1.05rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
  transition: transform var(--transition-fast), border-color var(--transition-fast), background-color var(--transition-fast);
  display: inline-block;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.word-tile:hover {
  transform: translateY(-2px);
  border-color: var(--text-muted);
}

.word-tile:active {
  transform: translateY(1px);
  border-bottom-width: 2px;
  margin-top: 2px;
}

.word-tile.used {
  opacity: 0.15;
  cursor: default;
  pointer-events: none;
  transform: none !important;
  border-bottom-width: 2px;
}

/* Options Container: Word Tiles */
.options-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  min-height: 100px;
  align-content: flex-start;
  flex-shrink: 0;
}

/* Workspace Specifics: Fill in the Blank */
.fill-blank-sentence {
  font-size: 1.5rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.8;
  letter-spacing: 0.5px;
}

.blank-slot {
  display: inline-block;
  min-width: 90px;
  border-bottom: 3px dashed var(--color-primary);
  margin: 0 10px;
  text-align: center;
  color: var(--color-accent);
  padding-bottom: 2px;
  font-weight: 700;
}

.blank-slot.filled {
  border-bottom-style: solid;
  color: var(--color-primary);
  animation: scale-up 0.2s ease-out;
}

/* Workspace Specifics: Multiple Choice Cards */
.choice-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.choice-card {
  display: flex;
  align-items: center;
  background-color: var(--bg-card);
  border: 2px solid var(--border-color);
  border-bottom-width: 4px;
  border-radius: var(--radius-md);
  padding: 16px 20px;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: left;
  user-select: none;
  color: var(--text-main);
  font-family: inherit;
}

.choice-card:hover {
  border-color: var(--text-muted);
  transform: translateY(-2px);
}

.choice-card:active {
  transform: translateY(1px);
  border-bottom-width: 2px;
}

.choice-card.selected {
  border-color: var(--color-primary);
  background-color: hsla(263, 90%, 65%, 0.08);
  box-shadow: 0 0 15px hsla(263, 90%, 65%, 0.1);
}

.choice-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  margin-right: 16px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

.choice-card.selected .choice-number {
  border-color: var(--color-primary);
  background-color: var(--color-primary);
  color: #fff;
}

.choice-text {
  font-size: 1.1rem;
  font-weight: 600;
  flex: 1;
}

/* 3. VALIDATION BOTTOM DRAWER */
.validation-drawer {
  position: relative;
  background-color: hsl(222, 47%, 6%);
  border-top: 2px solid var(--border-color);
  padding: 20px 24px;
  transition: all var(--transition-normal);
  z-index: 100;
  width: 100%;
}

@media (min-width: 650px) {
  .validation-drawer {
    border-bottom-left-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
  }
}

.drawer-inner {
  max-width: 550px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.drawer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Feedback message container */
.feedback-message {
  display: none;
  font-size: 1.1rem;
  font-weight: 700;
  align-items: center;
  gap: 12px;
  animation: slide-up-subtle 0.25s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.feedback-message svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}

.feedback-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.feedback-correct-label {
  font-size: 0.85rem;
  text-transform: uppercase;
  font-weight: 600;
  opacity: 0.8;
}

/* Drawer States (Correct/Incorrect) */
.validation-drawer.correct {
  background-color: var(--color-success-bg);
  border-top-color: var(--color-success-border);
}

.validation-drawer.correct .feedback-message {
  display: flex;
  color: var(--color-success);
}

.validation-drawer.correct #check-btn {
  background: var(--color-success) !important;
  box-shadow: 0 0 15px hsla(142, 70%, 45%, 0.4);
}

.validation-drawer.incorrect {
  background-color: var(--color-error-bg);
  border-top-color: var(--color-error-border);
}

.validation-drawer.incorrect .feedback-message {
  display: flex;
  color: var(--color-error);
}

.validation-drawer.incorrect #check-btn {
  background: var(--color-error) !important;
  box-shadow: 0 0 15px hsla(350, 85%, 55%, 0.4);
}

/* Key Helper Style */
.keyboard-help {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  pointer-events: none;
  padding: 8px 0;
  width: 100%;
  display: none;
}

@media (min-width: 650px) {
  .keyboard-help {
    display: block;
  }
}

/* 4. RESULT SCREEN */
#result-screen {
  align-items: center;
  padding: 40px 24px;
  overflow-y: auto !important;
  overflow-x: hidden;
}

.result-card {
  width: 100%;
  max-width: 500px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 24px;
  margin: 20px 0;
}

.trophy-icon {
  font-size: 5rem;
  animation: bounce-rotate 1.5s ease infinite alternate;
}

.result-subtitle {
  color: var(--text-muted);
  margin-top: -10px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 10px 0;
}

.stat-card {
  background-color: var(--bg-card);
  border: 2px solid var(--border-color);
  padding: 16px 8px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--color-accent);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.review-section {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 250px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  background-color: hsla(222, 47%, 5%, 0.3);
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

.review-section::-webkit-scrollbar {
  width: 6px;
}
.review-section::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 3px;
}

.review-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.review-item {
  display: flex;
  gap: 12px;
  font-size: 0.9rem;
  line-height: 1.4;
  padding-bottom: 12px;
  border-bottom: 1px solid hsla(222, 27%, 20%, 0.5);
}

.review-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.review-status-icon {
  font-size: 1.1rem;
}

.review-details {
  flex: 1;
}

.review-vi {
  font-weight: 600;
  color: var(--text-main);
}

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

.review-eng.wrong {
  color: var(--color-error);
  text-decoration: line-through;
  margin-right: 8px;
}

.review-correct {
  color: var(--color-success);
  font-weight: 500;
}

/* Animations */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.shake-active {
  animation: shake 0.4s ease-in-out;
}

@keyframes bounce-rotate {
  0% { transform: scale(1) rotate(0deg); }
  100% { transform: scale(1.1) rotate(10deg); }
}

@keyframes scale-up {
  0% { transform: scale(0.9); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes slide-up-subtle {
  0% { transform: translateY(15px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

/* Confetti styling for complete state */
.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 999;
  animation: confetti-fall 3s ease-out forwards;
}

@keyframes confetti-fall {
  0% { transform: translateY(-50px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(800px) rotate(720deg); opacity: 0; }
}

/* Custom Scrollbar Styles for consistent look */
#welcome-screen,
#result-screen,
.game-content {
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

#welcome-screen::-webkit-scrollbar,
#result-screen::-webkit-scrollbar,
.game-content::-webkit-scrollbar {
  width: 6px;
}

#welcome-screen::-webkit-scrollbar-thumb,
#result-screen::-webkit-scrollbar-thumb,
.game-content::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 3px;
}

/* Matching Card Layout and Card States */
.matching-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: 100%;
  margin-top: 10px;
}

.matching-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.matching-card {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-card);
  border: 2px solid var(--border-color);
  border-bottom-width: 4px;
  border-radius: var(--radius-md);
  padding: 16px 12px;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
  user-select: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  min-height: 70px;
}

.matching-card:hover:not(.matched) {
  border-color: var(--text-muted);
  transform: translateY(-2px);
}

.matching-card:active:not(.matched) {
  transform: translateY(1px);
  border-bottom-width: 2px;
}

.matching-card.selected {
  border-color: var(--color-primary);
  background-color: hsla(263, 90%, 65%, 0.12);
  box-shadow: 0 0 15px hsla(263, 90%, 65%, 0.15);
}

.matching-card.matched {
  border-color: var(--color-success-border);
  background-color: var(--color-success-bg);
  color: var(--color-success);
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
  border-bottom-width: 2px;
  transform: none !important;
}

.matching-card.wrong {
  border-color: var(--color-error-border);
  background-color: var(--color-error-bg);
  color: var(--color-error);
  animation: shake 0.4s ease-in-out;
}
