/* ============================================================
   LexiRoots - Quiz Styles
   Dark-mode, mobile-first, modern with vibrant accents
   Class names match quiz-engine.js template exactly
   ============================================================ */


/* =========================
   QUIZ LAYOUT
   ========================= */
.quiz-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: var(--safe-area-top);
  padding-bottom: var(--safe-area-bottom);
  background: var(--color-bg);
  position: relative;
}

.quiz-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  flex-shrink: 0;
}

.quiz-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  color: var(--color-text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--duration-fast) ease, color var(--duration-fast) ease;
}

.quiz-close:hover {
  background: var(--color-surface-light);
  color: var(--color-text);
}

.quiz-close svg {
  width: 22px;
  height: 22px;
}

.quiz-progress-bar {
  flex: 1;
  height: 6px;
  background: var(--color-surface-light);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.quiz-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-primary-light), var(--color-accent));
  border-radius: var(--radius-full);
  transition: width var(--duration-slow) var(--ease-out);
  position: relative;
}

.quiz-progress-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  animation: progressShimmer 2s ease-in-out infinite;
}

@keyframes progressShimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.quiz-counter {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  flex-shrink: 0;
  min-width: 36px;
  text-align: right;
}

.quiz-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: var(--space-6) var(--space-4);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}


/* =========================
   QUESTION AREA
   ========================= */
.quiz-question-area {
  text-align: center;
  margin-bottom: var(--space-6);
  width: 100%;
  max-width: 400px;
  animation: slideInRight var(--duration-slow) var(--ease-out);
}

.quiz-question-text {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  line-height: var(--leading-tight);
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

.quiz-hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-style: italic;
  margin-top: var(--space-2);
}


/* =========================
   MULTIPLE CHOICE
   ========================= */
.mc-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
  width: 100%;
  max-width: 420px;
}

.mc-option {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-3);
  background: var(--color-surface);
  border: 2px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--color-text);
  cursor: pointer;
  min-height: 68px;
  text-align: left;
  word-break: break-word;
  position: relative;
  overflow: hidden;
  transition:
    transform var(--duration-fast) ease,
    border-color var(--duration-fast) ease,
    background var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease;
  animation: popIn var(--duration-base) var(--ease-bounce) both;
}

.mc-option:nth-child(1) { animation-delay: 0ms; }
.mc-option:nth-child(2) { animation-delay: 50ms; }
.mc-option:nth-child(3) { animation-delay: 100ms; }
.mc-option:nth-child(4) { animation-delay: 150ms; }

.mc-option:hover:not(.disabled) {
  border-color: var(--color-primary);
  background: var(--color-surface-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.mc-option:active:not(.disabled) {
  transform: scale(0.97);
}

.mc-option.disabled {
  pointer-events: none;
  opacity: 0.5;
  cursor: default;
}

.mc-option.correct {
  border-color: var(--color-success) !important;
  background: rgba(0, 184, 148, 0.12) !important;
  box-shadow: 0 0 0 3px rgba(0, 184, 148, 0.15), 0 0 20px rgba(0, 184, 148, 0.1) !important;
  opacity: 1 !important;
  animation: correctFlash 0.6s ease;
}

.mc-option.correct .mc-option-letter {
  background: var(--color-success);
  color: #fff;
  border-color: var(--color-success);
}

.mc-option.correct .mc-option-text {
  color: var(--color-success-light);
}

.mc-option.wrong {
  border-color: var(--color-danger) !important;
  background: rgba(214, 48, 49, 0.12) !important;
  box-shadow: 0 0 0 3px rgba(214, 48, 49, 0.15) !important;
  opacity: 1 !important;
  animation: shake 0.5s ease;
}

.mc-option.wrong .mc-option-letter {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}

.mc-option-letter {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface-light);
  border: 1.5px solid var(--color-border-light);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  color: var(--color-text-muted);
  flex-shrink: 0;
  transition: background var(--duration-fast) ease, color var(--duration-fast) ease, border-color var(--duration-fast) ease;
}

.mc-option-text {
  flex: 1;
  line-height: var(--leading-tight);
}

/* Single column on very small screens */
@media (max-width: 340px) {
  .mc-options {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 640px) {
  .mc-option {
    font-size: var(--text-lg);
    padding: var(--space-5) var(--space-4);
    min-height: 80px;
  }
}


/* =========================
   MATCHING
   ========================= */
.match-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  width: 100%;
  max-width: 420px;
}

.match-column {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.match-roots,
.match-meanings {
  /* inherits from .match-column */
}

.match-item {
  padding: var(--space-3);
  background: var(--color-surface);
  border: 2px solid var(--color-border-light);
  border-radius: var(--radius-md);
  text-align: center;
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--color-text);
  cursor: pointer;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition:
    transform var(--duration-fast) ease,
    border-color var(--duration-fast) ease,
    background var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease;
}

.match-item:hover:not(.matched):not(.wrong) {
  border-color: var(--color-primary);
  background: var(--color-surface-light);
  transform: translateY(-1px);
}

.match-item:active:not(.matched) {
  transform: scale(0.96);
}

.match-root,
.match-meaning {
  /* share .match-item styles */
}

.match-root {
  font-weight: var(--font-bold);
  color: var(--color-primary-light);
}

.match-item.selected {
  border-color: var(--color-primary);
  background: rgba(108, 92, 231, 0.12);
  box-shadow: 0 0 16px rgba(108, 92, 231, 0.2);
}

.match-item.matched {
  border-color: var(--color-success);
  background: rgba(0, 184, 148, 0.1);
  opacity: 0.6;
  cursor: default;
  pointer-events: none;
  animation: correctFlash 0.5s ease;
}

.match-item.correct {
  border-color: var(--color-success);
  background: rgba(0, 184, 148, 0.12);
}

/* Distinct pair colors so users can see which left matches which right */
.match-item.match-pair-0 { border-color: #00b894; background: rgba(0, 184, 148, 0.15); opacity: 1; }
.match-item.match-pair-1 { border-color: #0984e3; background: rgba(9, 132, 227, 0.15); opacity: 1; }
.match-item.match-pair-2 { border-color: #6c5ce7; background: rgba(108, 92, 231, 0.15); opacity: 1; }
.match-item.match-pair-3 { border-color: #e17055; background: rgba(225, 112, 85, 0.15); opacity: 1; }
.match-item.match-pair-4 { border-color: #fd79a8; background: rgba(253, 121, 168, 0.15); opacity: 1; }
.match-item.match-pair-5 { border-color: #fdcb6e; background: rgba(253, 203, 110, 0.15); opacity: 1; }
.match-item.match-pair-6 { border-color: #55efc4; background: rgba(85, 239, 196, 0.15); opacity: 1; }
.match-item.match-pair-7 { border-color: #74b9ff; background: rgba(116, 185, 255, 0.15); opacity: 1; }

.match-item.wrong {
  border-color: var(--color-danger);
  background: rgba(214, 48, 49, 0.1);
  animation: shake 0.5s ease;
}

.match-status {
  text-align: center;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-top: var(--space-3);
  min-height: 20px;
}


/* =========================
   WORD BUILDING
   ========================= */
.word-builder {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  width: 100%;
  max-width: 420px;
}

.word-builder-slots {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

.word-slot {
  min-width: 80px;
  min-height: 52px;
  padding: var(--space-3) var(--space-4);
  border: 2px dashed var(--color-surface-lighter);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--color-text-dim);
  text-align: center;
  transition:
    border-color var(--duration-fast) ease,
    background var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease;
}

.word-slot.filled {
  border-style: solid;
  border-color: var(--color-border-light);
  background: var(--color-surface-light);
  color: var(--color-text);
  cursor: pointer;
}

.word-slot.correct {
  border-color: var(--color-success) !important;
  background: rgba(0, 184, 148, 0.12) !important;
  color: var(--color-success-light);
  animation: correctFlash 0.5s ease;
}

.word-slot.wrong {
  border-color: var(--color-danger) !important;
  background: rgba(214, 48, 49, 0.1) !important;
  color: var(--color-danger-light);
  animation: shake 0.5s ease;
}

.word-builder-pieces {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-4);
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  min-height: 64px;
}

.word-piece {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  font-size: var(--text-base);
  font-weight: var(--font-bold);
  cursor: pointer;
  border: 2px solid transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition:
    transform var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease,
    opacity var(--duration-fast) ease;
}

.word-piece:hover:not(.used) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.word-piece:active:not(.used) {
  transform: scale(1.05);
}

.word-piece-prefix {
  background: rgba(253, 121, 168, 0.15);
  border-color: rgba(253, 121, 168, 0.4);
  color: var(--color-accent-secondary);
}

.word-piece-root {
  background: rgba(108, 92, 231, 0.15);
  border-color: rgba(108, 92, 231, 0.4);
  color: var(--color-primary-light);
}

.word-piece-suffix {
  background: rgba(0, 206, 201, 0.15);
  border-color: rgba(0, 206, 201, 0.4);
  color: var(--color-accent);
}

.word-piece.used {
  opacity: 0.35;
  cursor: pointer;
  transform: none !important;
  border-style: dashed;
}


/* =========================
   FILL IN THE BLANK
   ========================= */
.fitb-sentence {
  font-size: var(--text-xl);
  font-weight: var(--font-medium);
  line-height: 1.8;
  text-align: center;
  color: var(--color-text);
}

.fitb-blank {
  display: inline-block;
  min-width: 100px;
  border-bottom: 3px solid var(--color-primary);
  padding: var(--space-1) var(--space-2);
  margin: 0 var(--space-1);
  color: var(--color-primary-light);
  font-weight: var(--font-bold);
  background: rgba(108, 92, 231, 0.08);
  border-radius: var(--radius-xs) var(--radius-xs) 0 0;
  transition:
    border-color var(--duration-fast) ease,
    background var(--duration-fast) ease;
}

.fitb-input-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  max-width: 360px;
  margin-top: var(--space-4);
}

.fitb-input {
  width: 100%;
  padding: var(--space-4);
  background: var(--color-surface);
  border: 2px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  text-align: center;
  color: var(--color-text);
  -webkit-appearance: none;
  transition:
    border-color var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease;
}

.fitb-input::placeholder {
  color: var(--color-text-dim);
  font-weight: var(--font-normal);
}

.fitb-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px rgba(108, 92, 231, 0.12);
  outline: none;
}

.fitb-input.correct {
  border-color: var(--color-success);
  box-shadow: 0 0 0 4px rgba(0, 184, 148, 0.12);
  color: var(--color-success-light);
}

.fitb-input.wrong {
  border-color: var(--color-danger);
  box-shadow: 0 0 0 4px rgba(214, 48, 49, 0.12);
  animation: shake 0.5s ease;
}

.fitb-input.show-answer {
  border-color: var(--color-warning);
  color: var(--color-warning);
  font-style: italic;
}

.quiz-check-btn {
  margin-top: var(--space-2);
  width: 100%;
}


/* =========================
   DEFINITION DEDUCTION
   ========================= */
.deduction-clues {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-6);
  width: 100%;
  max-width: 420px;
}

.deduction-clue {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  animation: slideInRight var(--duration-slow) var(--ease-out) both;
}

.deduction-clue:nth-child(2) { animation-delay: 150ms; }
.deduction-clue:nth-child(3) { animation-delay: 300ms; }

.clue-part {
  font-weight: var(--font-bold);
  font-size: var(--text-lg);
}

.clue-prefix {
  color: var(--color-accent-secondary);
}

.clue-root {
  color: var(--color-primary-light);
}

.clue-equals {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.clue-meaning {
  font-style: italic;
  color: var(--color-text);
  font-size: var(--text-sm);
}

.clue-plus {
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  color: var(--color-text-muted);
}


/* =========================
   QUIZ RESULTS
   ========================= */
.quiz-results {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-8) var(--space-4);
  min-height: 100vh;
  min-height: 100dvh;
  animation: popIn var(--duration-slow) var(--ease-out);
}

/* Score Ring */
.results-score-ring {
  position: relative;
  width: 140px;
  height: 140px;
  margin: 0 auto var(--space-6);
}

.score-ring-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.score-ring-fill {
  fill: none;
  stroke-linecap: round;
  transition: stroke-dashoffset 1.5s var(--ease-out);
}

.score-ring-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.score-percent {
  font-size: var(--text-4xl);
  font-weight: var(--font-black);
  line-height: 1;
  color: var(--color-text);
  animation: popIn var(--duration-slow) var(--ease-bounce) 0.5s both;
}

/* Title */
.results-title {
  font-size: var(--text-3xl);
  font-weight: var(--font-black);
  color: var(--color-text);
  margin-bottom: var(--space-6);
  background: linear-gradient(135deg, var(--color-primary-light), var(--color-accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Stats Row */
.results-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
  width: 100%;
  max-width: 360px;
  margin-bottom: var(--space-6);
}

.results-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  animation: popIn var(--duration-base) var(--ease-bounce) both;
}

.results-stat:nth-child(1) { animation-delay: 0.3s; }
.results-stat:nth-child(2) { animation-delay: 0.4s; }
.results-stat:nth-child(3) { animation-delay: 0.5s; }

.results-stat-value {
  font-size: var(--text-2xl);
  font-weight: var(--font-black);
  line-height: 1;
  color: var(--color-text);
  margin-bottom: var(--space-1);
}

.results-stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* XP Earned */
.xp-earned {
  color: var(--color-primary-light);
  text-shadow: 0 0 12px rgba(108, 92, 231, 0.5);
}

/* Message */
.results-message {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-6);
  max-width: 300px;
}

/* Actions */
.results-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: 100%;
  max-width: 320px;
}


/* =========================
   ANIMATIONS
   ========================= */

/* Shake - horizontal shake for wrong answers */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 50%, 90% { transform: translateX(-6px); }
  30%, 70% { transform: translateX(6px); }
}

/* Correct flash - green glow pulse */
@keyframes correctFlash {
  0% {
    box-shadow: 0 0 0 0 rgba(0, 184, 148, 0.4);
  }
  50% {
    box-shadow: 0 0 20px 4px rgba(0, 184, 148, 0.25);
  }
  100% {
    box-shadow: 0 0 0 3px rgba(0, 184, 148, 0.15);
  }
}

/* Slide in from right - new question entrance */
@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Pop in - scale pop for results and options */
@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}


/* =========================
   DRAG AND DROP
   ========================= */
.drag-ghost {
  position: fixed;
  z-index: 9999;
  opacity: 0.9;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  will-change: transform;
  transition: none;
}

.match-item.dragging,
.word-piece.dragging {
  opacity: 0.3;
  transform: scale(0.95);
}

.drop-target {
  border: 2px dashed var(--color-primary) !important;
  background: rgba(108, 92, 231, 0.06) !important;
}

.drop-hover {
  border: 2px solid var(--color-primary-light) !important;
  background: rgba(108, 92, 231, 0.12) !important;
  transform: scale(1.04);
  box-shadow: 0 0 12px rgba(108, 92, 231, 0.25);
}


/* =========================
   REDUCED MOTION
   ========================= */
@media (prefers-reduced-motion: reduce) {
  .quiz-progress-fill::after {
    animation: none;
  }

  .mc-option,
  .match-item,
  .deduction-clue,
  .quiz-question-area,
  .results-stat,
  .score-percent,
  .quiz-results {
    animation: none !important;
  }

  .drag-ghost,
  .drop-hover,
  .match-item.dragging,
  .word-piece.dragging {
    transform: none !important;
  }
}
