/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f5f7ff;
  --surface: #ffffff;
  --border: #e4e7f0;
  --text: #1a1d2e;
  --muted: #6b7280;
  --primary: #4F46E5;
  --primary-dark: #3730a3;
  --success: #10b981;
  --danger: #ef4444;
  --warn: #f59e0b;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --font: 'Nunito', system-ui, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 24px;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--primary);
  flex: 1;
}

.stats-bar {
  display: flex;
  gap: 8px;
}

.stat {
  font-size: .8rem;
  font-weight: 700;
  background: var(--bg);
  padding: 3px 8px;
  border-radius: 20px;
  color: var(--text);
}

.back-btn {
  background: none;
  border: none;
  font-size: .9rem;
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
  padding: 4px;
}

/* ── XP Bar ── */
.xp-bar-wrap {
  padding: 10px 16px 4px;
}

.xp-bar-label {
  font-size: .72rem;
  color: var(--muted);
  margin-bottom: 4px;
  font-weight: 700;
}

.xp-bar {
  height: 8px;
  background: var(--border);
  border-radius: 20px;
  overflow: hidden;
}

.xp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #818cf8);
  border-radius: 20px;
  transition: width .4s ease;
}

/* ── Section Title ── */
.section-title {
  font-size: 1rem;
  font-weight: 800;
  padding: 16px 16px 8px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ── Language Grid ── */
.lang-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 0 16px;
}

.lang-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 16px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform .15s, border-color .15s, box-shadow .15s;
  font-family: var(--font);
}

.lang-card:hover, .lang-card:active {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: var(--shadow);
}

.lang-flag { font-size: 2.4rem; }

.lang-name {
  font-size: .9rem;
  font-weight: 800;
  color: var(--text);
}

/* ── Daily Tip ── */
.daily-tip {
  margin: 16px;
  padding: 12px 14px;
  background: #fef3c7;
  border-radius: var(--radius-sm);
  font-size: .82rem;
  display: flex;
  gap: 8px;
  color: #92400e;
  font-weight: 600;
}

/* ── Lessons ── */
.lessons-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 16px;
}

.lesson-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  transition: border-color .15s;
}

.lesson-card.done { border-color: var(--success); }
.lesson-card.locked { opacity: .55; }

.lesson-icon { font-size: 1.6rem; flex-shrink: 0; }

.lesson-info { flex: 1; }
.lesson-title { font-weight: 800; font-size: .95rem; }
.lesson-meta { font-size: .75rem; color: var(--muted); margin-top: 2px; }

.lesson-actions { display: flex; gap: 6px; flex-shrink: 0; }

.locked-label { font-size: .72rem; color: var(--muted); font-weight: 700; }

/* ── Buttons ── */
.btn-sm {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: .78rem;
  font-weight: 800;
  cursor: pointer;
  font-family: var(--font);
  border: 2px solid transparent;
  transition: opacity .15s, transform .1s;
}
.btn-sm:active { transform: scale(.96); }

.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: #ede9fe; }

.btn-block { width: 100%; padding: 14px; font-size: 1rem; border-radius: var(--radius); }

/* ── Vocab ── */
.vocab-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 12px 16px;
  flex: 1;
}

.vocab-card {
  height: 120px;
  perspective: 600px;
  cursor: pointer;
}

.vocab-front, .vocab-back {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px;
  backface-visibility: hidden;
  transition: transform .35s ease;
  text-align: center;
}

.vocab-front {
  background: var(--surface);
  border: 2px solid var(--border);
}

.vocab-back {
  background: var(--primary);
  color: #fff;
  transform: rotateY(180deg);
}

.vocab-card { position: relative; transform-style: preserve-3d; }
.vocab-card.flipped .vocab-front { transform: rotateY(180deg); }
.vocab-card.flipped .vocab-back  { transform: rotateY(0); }

.vocab-word {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 4px;
}

.vocab-tap { font-size: .68rem; color: var(--muted); }

.vocab-translation { font-size: .9rem; font-weight: 800; margin-bottom: 4px; }
.vocab-example { font-size: .68rem; opacity: .85; }

.rtl { direction: rtl; }

.vocab-footer { padding: 12px 16px; }

/* ── Quiz ── */
.quiz-progress-wrap {
  flex: 1;
  padding: 0 6px;
}

.quiz-progress {
  height: 8px;
  background: var(--border);
  border-radius: 20px;
  overflow: hidden;
}

.quiz-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #818cf8);
  border-radius: 20px;
  transition: width .3s ease;
}

.quiz-counter {
  font-size: .8rem;
  font-weight: 800;
  color: var(--muted);
  white-space: nowrap;
}

.quiz-body {
  flex: 1;
  padding: 20px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.quiz-question {
  font-size: 1.05rem;
  font-weight: 800;
  text-align: center;
  line-height: 1.4;
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.option-btn {
  padding: 16px 10px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: .88rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
  word-break: break-word;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: #ede9fe;
}

.option-btn:active:not(:disabled) { transform: scale(.97); }

.option-btn.correct { background: #d1fae5; border-color: var(--success); color: #065f46; }
.option-btn.wrong   { background: #fee2e2; border-color: var(--danger);  color: #991b1b; }
.option-btn:disabled { cursor: default; }

.quiz-feedback {
  text-align: center;
  font-weight: 800;
  font-size: .9rem;
  min-height: 22px;
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}

.fb-correct { background: #d1fae5; color: #065f46; }
.fb-wrong   { background: #fee2e2; color: #991b1b; }

.hint-area {
  font-size: .8rem;
  color: var(--muted);
  text-align: center;
  min-height: 20px;
  font-style: italic;
}

.quiz-foot {
  padding: 14px 16px;
}

#nextBtn {
  width: 100%;
  padding: 14px;
  font-size: 1rem;
  border-radius: var(--radius);
  font-family: var(--font);
  font-weight: 800;
  background: var(--primary);
  color: #fff;
  border: none;
  cursor: pointer;
  transition: background .15s;
}

#nextBtn:hover { background: var(--primary-dark); }

/* ── Result ── */
.result-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  flex: 1;
  gap: 12px;
  text-align: center;
}

.result-medal { font-size: 4rem; animation: pop .4s ease; }
.result-title { font-size: 1.5rem; font-weight: 900; }
.result-stars { font-size: 1.8rem; letter-spacing: 4px; }
.result-score { font-size: 1.1rem; font-weight: 700; color: var(--muted); }
.result-xp { font-size: 1rem; font-weight: 800; color: var(--primary); background: #ede9fe; padding: 6px 16px; border-radius: 20px; }
.result-streak { font-size: .9rem; color: var(--warn); font-weight: 800; }
.result-actions { display: flex; flex-direction: column; gap: 10px; width: 100%; margin-top: 8px; }

/* ── Animations ── */
@keyframes pop {
  0%   { transform: scale(.4); opacity: 0; }
  70%  { transform: scale(1.1); }
  100% { transform: scale(1);   opacity: 1; }
}

/* ── Mobile ── */
@media (max-width: 360px) {
  .lang-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .vocab-grid { grid-template-columns: 1fr 1fr; }
  .options-grid { grid-template-columns: 1fr 1fr; }
  .lesson-actions { flex-direction: column; }
}

@media (min-width: 481px) {
  body { background: #dde1f7; }
  #app {
    margin: 20px auto;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0,0,0,0.12);
    min-height: auto;
  }
}
