/* ============================================
   EduCRS Flashcards — Components
   ============================================ */

/* ---------- Level Selector ---------- */
.level-selector {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  z-index: 1000;
  animation: levelFadeIn var(--dur-slow) var(--ease-out);
}

.level-selector-inner {
  text-align: center;
  max-width: 520px;
  padding: var(--space-8);
}

.level-selector h1 {
  font-size: var(--fs-3xl);
  font-weight: var(--fw-bold);
  letter-spacing: -1px;
  margin-bottom: var(--space-3);
}

.level-selector p {
  font-size: var(--fs-md);
  color: var(--text-secondary);
  margin-bottom: var(--space-12);
  line-height: 1.6;
}

.level-options {
  display: flex;
  gap: var(--space-4);
  justify-content: center;
  flex-wrap: wrap;
}

.level-btn {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  transition: all var(--dur-normal) var(--ease-out);
  position: relative;
  overflow: hidden;
}

.level-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--text-primary);
  opacity: 0;
  transition: opacity var(--dur-normal);
}

.level-btn:hover {
  border-color: var(--text-primary);
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.level-btn:hover::after { opacity: 0.05; }
.level-btn:active { transform: translateY(0); }

/* ---------- Modal Overlay ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: overlayFadeIn var(--dur-normal) var(--ease-out);
  padding: var(--space-5);
}

.modal {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 580px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  animation: modalSlideUp var(--dur-slow) var(--ease-out);
}

.modal-header {
  padding: var(--space-6) var(--space-6) 0;
}

.modal-body {
  padding: var(--space-5) var(--space-6) var(--space-6);
}

.modal-footer {
  padding: var(--space-4) var(--space-6) var(--space-6);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
}

/* ---------- Segmented Control ---------- */
.segment-control {
  display: flex;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 3px;
}

.segment-btn {
  flex: 1;
  padding: var(--space-3) var(--space-4);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  border-radius: calc(var(--radius-md) - 2px);
  text-align: center;
  transition: all var(--dur-fast);
  color: var(--text-secondary);
}

.segment-btn.active {
  background: var(--bg-primary);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
  font-weight: var(--fw-semibold);
}

.segment-btn:not(.active):hover {
  color: var(--text-primary);
}

/* ---------- Form Elements ---------- */
.form-group {
  margin-bottom: var(--space-5);
}

.form-label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
  transition: all var(--dur-fast);
}

.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-placeholder); }

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  border-color: var(--border-strong);
  background: var(--bg-primary);
  box-shadow: var(--shadow-sm);
}

.form-textarea {
  min-height: 80px;
  resize: vertical;
  line-height: 1.5;
}

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%238a8a8a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 5l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.form-number {
  max-width: 120px;
}

/* ---------- Source Pills (Multi-select) ---------- */
.source-selector {
  position: relative;
}

.source-pills {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-height: 42px;
  cursor: text;
  transition: all var(--dur-fast);
}

.source-pills:focus-within {
  border-color: var(--border-strong);
  background: var(--bg-primary);
}

.source-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  background: var(--bg-surface-active);
  border-radius: var(--radius-full);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
}

.source-pill-remove {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  transition: background var(--dur-fast);
}
.source-pill-remove:hover { background: var(--bg-surface-hover); }

.source-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: var(--space-1);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 10;
  max-height: 200px;
  overflow-y: auto;
  display: none;
}

.source-dropdown.open { display: block; }

.source-option {
  padding: var(--space-3) var(--space-4);
  font-size: var(--fs-sm);
  cursor: pointer;
  transition: background var(--dur-fast);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.source-option:hover { background: var(--bg-surface); }
.source-option.selected { font-weight: var(--fw-medium); }
.source-option-check {
  width: 16px;
  height: 16px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--dur-fast);
}
.source-option.selected .source-option-check {
  background: var(--text-primary);
  border-color: var(--text-primary);
}
.source-option.selected .source-option-check svg { stroke: var(--bg-primary); }

/* ---------- Option Mark (MC correct answer) ---------- */
.option-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.option-mark {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--dur-fast);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  cursor: pointer;
}
.option-mark:hover { border-color: var(--border-strong); }
.option-mark.correct {
  background: var(--text-primary);
  color: var(--bg-primary);
  border-color: var(--text-primary);
}

.option-row .form-input { flex: 1; }

/* ---------- Buttons ---------- */
.btn {
  padding: var(--space-3) var(--space-6);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  border-radius: var(--radius-md);
  transition: all var(--dur-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

.btn-primary {
  background: var(--text-primary);
  color: var(--bg-primary);
}
.btn-primary:hover { opacity: 0.85; }
.btn-primary:active { opacity: 0.7; }

.btn-secondary {
  border: 1px solid var(--border);
  background: var(--bg-surface);
}
.btn-secondary:hover { background: var(--bg-surface-hover); border-color: var(--border-strong); }

.btn-ghost {
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--bg-surface); color: var(--text-primary); }

/* ---------- Prompt Builder (AI Tab) ---------- */
.prompt-builder {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.prompt-fixed-text {
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  margin-bottom: var(--space-2);
}

/* ---------- Q&A Card ---------- */
.qa-card {
  perspective: 1000px;
  cursor: pointer;
  min-height: 220px;
}

.qa-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 220px;
  transition: transform var(--dur-slow) var(--ease-out);
  transform-style: preserve-3d;
}

.qa-card.flipped .qa-card-inner { transform: rotateY(180deg); }

.qa-card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: var(--space-8) var(--space-6);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-primary);
  text-align: center;
  transition: border-color var(--dur-fast), background var(--dur-normal);
}

.qa-card-face:hover { border-color: var(--border-strong); }

.qa-card-back {
  transform: rotateY(180deg);
}

.qa-card-label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-tertiary);
  margin-bottom: var(--space-4);
}

.qa-card-text {
  font-size: var(--fs-lg);
  font-weight: var(--fw-medium);
  line-height: 1.5;
}

.qa-card-hint {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  margin-top: auto;
  padding-top: var(--space-4);
}

/* ---------- MC Card ---------- */
.mc-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-primary);
  overflow: hidden;
  transition: border-color var(--dur-fast), background var(--dur-normal);
}

.mc-card-question {
  padding: var(--space-6);
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  line-height: 1.6;
  border-bottom: 1px solid var(--border);
}

.mc-card-options {
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.mc-option-btn {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-size: var(--fs-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--dur-fast);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.mc-option-btn:not(.answered):hover {
  background: var(--bg-surface);
  border-color: var(--border-strong);
}

.mc-option-btn:not(.answered) { cursor: pointer; }
.mc-option-btn.answered { cursor: default; }

.mc-option-letter {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  flex-shrink: 0;
  transition: all var(--dur-fast);
}

.mc-option-btn.selected .mc-option-letter {
  background: var(--text-primary);
  color: var(--bg-primary);
  border-color: var(--text-primary);
}

.mc-option-btn.selected {
  border-color: var(--text-primary);
  font-weight: var(--fw-medium);
}

.mc-feedback {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border);
  font-size: var(--fs-sm);
  line-height: 1.6;
  display: none;
}

.mc-feedback.visible { display: block; }

.mc-feedback-label {
  font-weight: var(--fw-semibold);
  margin-bottom: var(--space-1);
}

/* ---------- Sentence Card ---------- */
.sentence-card {
  perspective: 1000px;
  cursor: pointer;
  min-height: 220px;
}

.sentence-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 220px;
  transition: transform var(--dur-slow) var(--ease-out);
  transform-style: preserve-3d;
}

.sentence-card.flipped .sentence-card-inner { transform: rotateY(180deg); }

.sentence-card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: var(--space-8) var(--space-6);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-primary);
  text-align: center;
  transition: border-color var(--dur-fast), background var(--dur-normal);
}

.sentence-card-face:hover { border-color: var(--border-strong); }

.sentence-card-back {
  transform: rotateY(180deg);
}

.sentence-card-label {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-tertiary);
  margin-bottom: var(--space-4);
}

.sentence-card-sentence {
  font-size: var(--fs-md);
  font-weight: var(--fw-normal);
  line-height: 1.8;
  margin-bottom: var(--space-4);
}

.sentence-highlight {
  font-weight: var(--fw-semibold);
  border-bottom: 2px solid var(--text-primary);
}

.sentence-card-meaning {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}

.sentence-card-word {
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
}

.sentence-card-meaning p {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  line-height: 1.6;
}

.sentence-card-hint {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  margin-top: auto;
  padding-top: var(--space-4);
}

.sentence-card-word-display {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  letter-spacing: -0.5px;
  margin-bottom: var(--space-2);
}

.word-form-badge {
  display: inline-block;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 2px var(--space-3);
  border: 1px solid;
  border-radius: 999px;
  margin-bottom: var(--space-4);
  opacity: 0.85;
}

/* ---------- Word List View ---------- */
.word-list-control {
  display: flex;
  justify-content: center;
  margin-bottom: var(--space-6);
}

.word-list-toggle {
  padding: var(--space-3) var(--space-6);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  transition: all var(--dur-fast);
  cursor: pointer;
}

.word-list-toggle:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-strong);
}

.word-list-toggle.active {
  background: var(--text-primary);
  color: var(--bg-primary);
  border-color: var(--text-primary);
}

.word-list-view {
  padding: var(--space-6);
}

.word-list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
}

.word-list-item {
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  transition: all var(--dur-fast);
}

.word-list-item:hover {
  border-color: var(--border-strong);
  background: var(--bg-primary);
}

.word-list-word {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  margin-bottom: var(--space-2);
  display: block;
}

.word-list-meaning {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  line-height: 1.6;
}

.word-list-form-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 1px var(--space-2);
  border: 1px solid;
  border-radius: 999px;
  margin-bottom: var(--space-2);
  opacity: 0.8;
}

/* ---------- Prompt Composer (Chat-style) ---------- */
.prompt-composer {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.prompt-input-wrapper {
  position: relative;
}

.prompt-input-area {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: text;
  transition: all var(--dur-fast);
  min-height: 44px;
}

.prompt-input-area:focus-within {
  border-color: var(--border-strong);
  background: var(--bg-primary);
}

.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.prompt-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--text-primary);
  color: var(--bg-primary);
  border-radius: var(--radius-full);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
}

.chip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 14px;
  flex-shrink: 0;
}

.prompt-chip-remove {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--dur-fast);
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  font-size: var(--fs-md);
  line-height: 1;
}

.prompt-chip-remove:hover {
  opacity: 0.7;
}

.prompt-input {
  flex: 1;
  min-width: 100px;
  border: none;
  background: transparent;
  font-size: var(--fs-sm);
  padding: 0;
  outline: none;
}

.prompt-input::placeholder {
  color: var(--text-placeholder);
}

.prompt-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: var(--space-1);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 10;
  max-height: 200px;
  overflow-y: auto;
  display: none;
}

.prompt-dropdown-header {
  padding: var(--space-2) var(--space-4);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border);
  sticky;
  top: 0;
  background: var(--bg-surface);
}

.prompt-suggestion {
  padding: var(--space-3) var(--space-4);
  font-size: var(--fs-sm);
  cursor: pointer;
  transition: background var(--dur-fast);
  border-bottom: 1px solid var(--border);
}

.prompt-suggestion:last-child {
  border-bottom: none;
}

.prompt-suggestion:hover {
  background: var(--bg-surface);
}

.prompt-suggestion-skip {
  font-style: italic;
  color: var(--text-tertiary);
}

.prompt-hint {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  text-align: center;
  min-height: 18px;
}
