:root {
  --bg: #f4f5f7;
  --card-bg: #ffffff;
  --text: #1f2430;
  --text-muted: #6b7280;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --correct: #16a34a;
  --correct-bg: #ecfdf3;
  --incorrect: #dc2626;
  --incorrect-bg: #fef2f2;
  --border: #e5e7eb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c;
    --card-bg: #1d2029;
    --text: #f0f1f5;
    --text-muted: #9ca3af;
    --primary: #6366f1;
    --primary-dark: #818cf8;
    --correct: #4ade80;
    --correct-bg: #10261a;
    --incorrect: #f87171;
    --incorrect-bg: #2a1414;
    --border: #2e323d;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 32px 16px;
}

.app {
  width: 100%;
  max-width: 560px;
}

.screen.hidden { display: none; }

h1 {
  font-size: 1.6rem;
  margin: 0 0 4px;
}

.subtitle {
  color: var(--text-muted);
  margin: 0 0 28px;
}

.field-group {
  margin-bottom: 24px;
}

.field-label {
  display: block;
  font-weight: 600;
  margin-bottom: 10px;
  font-size: 0.95rem;
}

.category-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.category-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-bg);
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.category-option:hover {
  border-color: var(--primary);
}

.category-option input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

.category-option .cat-name {
  flex: 1;
  font-weight: 500;
}

.category-option .cat-count {
  color: var(--text-muted);
  font-size: 0.85rem;
}

input[type="number"], input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-size: 1rem;
}

input[type="number"]:focus, input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
}

.hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 8px 0 0;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 13px 20px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  width: 100%;
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
  width: 100%;
  margin-top: 12px;
}

.button-row {
  display: flex;
  gap: 12px;
}

.button-row .btn {
  margin-top: 0;
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

.study-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 20px 0;
  max-height: 55vh;
  overflow-y: auto;
}

.study-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--card-bg);
  border: 1px solid var(--border);
}

.study-row-speak {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.study-row-speak svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.study-row-speak:hover {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 10%, transparent);
}

.study-row-speak.speaking svg {
  animation: speak-pulse 0.9s ease-in-out infinite;
}

.study-row-es {
  font-weight: 600;
  flex: 0 0 40%;
}

.study-row-en {
  color: var(--text-muted);
  flex: 1;
  text-align: right;
}

.study-quiz-cta {
  margin-top: 4px;
}

.error-text {
  color: var(--incorrect);
  font-size: 0.9rem;
  margin-top: 10px;
  min-height: 1.2em;
}

.quiz-header {
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 24px;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.25s ease;
}

.quiz-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 28px;
  text-align: center;
}

.category-tag {
  display: inline-block;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  padding: 4px 10px;
  border-radius: 999px;
  margin: 0 0 18px;
}

.word-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0 0 24px;
}

.spanish-word {
  font-size: 2.1rem;
  font-weight: 700;
  margin: 0;
  word-break: break-word;
}

.speak-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--card-bg);
  color: var(--primary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.05s ease, border-color 0.15s ease;
}

.speak-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.speak-btn:hover {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 10%, transparent);
}

.speak-btn:active {
  transform: scale(0.94);
}

.speak-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.speak-btn.speaking svg {
  animation: speak-pulse 0.9s ease-in-out infinite;
}

@keyframes speak-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

#answer-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.feedback {
  margin-top: 20px;
  padding: 16px;
  border-radius: 10px;
  text-align: left;
}

.feedback.hidden { display: none; }

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

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

.feedback p {
  margin: 0;
  font-weight: 600;
}

.feedback .answer-detail {
  font-weight: 400;
  margin-top: 4px;
  color: var(--text);
}

.result-score {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 24px;
}

.review-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 28px;
  max-height: 360px;
  overflow-y: auto;
}

.review-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  font-size: 0.9rem;
}

.review-item.wrong { border-color: var(--incorrect); }
.review-item.right { border-color: var(--correct); }

.review-item .rw-word { font-weight: 600; }
.review-item .rw-answer { color: var(--text-muted); text-align: right; }
.review-item .rw-answer .wrong-guess { color: var(--incorrect); text-decoration: line-through; margin-right: 6px; }
.review-item .rw-answer .correct-answer { color: var(--correct); }
