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

:root {
  --blue: #2563eb;
  --blue-light: #eff6ff;
  --blue-dark: #1d4ed8;
  --green: #16a34a;
  --green-light: #f0fdf4;
  --red: #dc2626;
  --red-light: #fef2f2;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #9ca3af;
  --gray-600: #4b5563;
  --gray-800: #1f2937;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --nav-height: 64px;
  --header-height: 56px;
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  min-height: 100vh;
  padding-bottom: var(--nav-height);
}

.hidden { display: none !important; }

/* ─── Header ────────────────────────────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: white;
  border-bottom: 1px solid var(--gray-200);
  height: var(--header-height);
}
.header-inner {
  max-width: 640px;
  margin: 0 auto;
  height: 100%;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo { font-size: 1.1rem; font-weight: 700; }
.header-title { font-size: 0.95rem; font-weight: 600; color: var(--gray-600); }

.lang-toggle {
  background: var(--blue);
  color: white;
  border: none;
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: background 0.2s;
}
.lang-toggle:hover { background: var(--blue-dark); }

.back-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--gray-600);
  border-radius: 8px;
}
.back-btn:hover { background: var(--gray-100); }

/* ─── Bottom Nav ────────────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  height: var(--nav-height);
  background: white;
  border-top: 1px solid var(--gray-200);
  display: flex;
  z-index: 100;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--gray-400);
  font-size: 0.72rem;
  font-weight: 500;
  transition: color 0.2s;
}
.nav-item.active { color: var(--blue); }
.nav-icon { font-size: 1.3rem; }

/* ─── Main ──────────────────────────────────────────────────────────────────── */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px;
}

/* ─── Home ──────────────────────────────────────────────────────────────────── */
.home-title {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 20px;
  color: var(--gray-800);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 32px;
}

.exam-card {
  background: white;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 20px 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}
.exam-card:hover { border-color: var(--blue); transform: translateY(-2px); box-shadow: var(--shadow); }
.exam-card.selected { border-color: var(--blue); background: var(--blue-light); }
.card-icon { font-size: 1.8rem; margin-bottom: 8px; }
.card-title { font-size: 0.82rem; font-weight: 700; color: var(--gray-800); line-height: 1.3; }
.card-sub { font-size: 0.72rem; color: var(--gray-400); margin-top: 4px; }

.mode-section { margin-bottom: 24px; }
.mode-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--gray-800);
}

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

.mode-card {
  background: white;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 20px 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}
.mode-card:hover { border-color: var(--blue); transform: translateY(-2px); box-shadow: var(--shadow); }
.mode-icon { font-size: 1.6rem; margin-bottom: 8px; }
.mode-name { font-size: 0.82rem; font-weight: 700; color: var(--gray-800); }
.mode-desc { font-size: 0.72rem; color: var(--gray-400); margin-top: 4px; }

.section-picker { margin-top: 24px; }
.section-picker h3 { font-size: 1rem; font-weight: 700; margin-bottom: 12px; }
.section-list { display: flex; flex-direction: column; gap: 10px; }

.section-btn {
  background: white;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 16px;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all 0.2s;
}
.section-btn:hover { border-color: var(--blue); background: var(--blue-light); }
.sec-fr { font-weight: 700; font-size: 0.9rem; flex: 1; }
.sec-en { font-size: 0.8rem; color: var(--gray-600); flex: 1; }
.sec-count { font-size: 0.75rem; color: var(--gray-400); white-space: nowrap; }

/* ─── Quiz ──────────────────────────────────────────────────────────────────── */
.quiz { padding-top: 16px; }

.progress-bar-wrap {
  background: var(--gray-200);
  border-radius: 99px;
  height: 6px;
  margin-bottom: 8px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--blue);
  border-radius: 99px;
  transition: width 0.4s ease;
}
.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--gray-400);
  margin-bottom: 20px;
}
.score-label { font-weight: 700; color: var(--green); }

.question-card {
  background: white;
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.section-badge {
  display: inline-block;
  background: var(--blue-light);
  color: var(--blue);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 99px;
  margin-bottom: 16px;
  letter-spacing: 0.03em;
}

.question-text {
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.5;
  color: var(--gray-800);
  margin-bottom: 6px;
}
.question-text-en {
  font-size: 0.88rem;
  color: var(--gray-400);
  font-style: italic;
  margin-bottom: 20px;
}

.options { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }

.option-btn {
  background: var(--gray-50);
  border: 2px solid var(--gray-200);
  border-radius: 10px;
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transition: all 0.15s;
  width: 100%;
}
.option-btn:hover:not(:disabled) { border-color: var(--blue); background: var(--blue-light); }
.option-btn:disabled { cursor: default; }
.option-btn.correct { border-color: var(--green); background: var(--green-light); }
.option-btn.wrong { border-color: var(--red); background: var(--red-light); }

.option-letter {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.option-btn.correct .option-letter { background: var(--green); color: white; }
.option-btn.wrong .option-letter { background: var(--red); color: white; }

.option-text { display: flex; flex-direction: column; gap: 2px; }
.opt-fr { font-size: 0.92rem; font-weight: 600; color: var(--gray-800); }
.opt-en { font-size: 0.78rem; color: var(--gray-400); font-style: italic; }

.next-btn {
  width: 100%;
  background: var(--blue);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}
.next-btn:hover { background: var(--blue-dark); }

/* ─── Results overlay ────────────────────────────────────────────────────────── */
.results-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.results-card {
  background: white;
  border-radius: 20px;
  padding: 32px 24px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.results-emoji { font-size: 3rem; margin-bottom: 12px; }
.results-score { font-size: 2.5rem; font-weight: 900; color: var(--gray-800); }
.results-sub { color: var(--gray-600); margin: 8px 0 20px; }
.results-breakdown { text-align: left; margin-bottom: 24px; }
.breakdown-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.85rem;
}
.breakdown-sec { color: var(--gray-600); }
.breakdown-score { font-weight: 700; color: var(--gray-800); }
.results-actions { display: flex; flex-direction: column; gap: 10px; }
.btn-primary {
  background: var(--blue);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-800);
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-secondary:hover { background: var(--gray-200); }

/* ─── Dictionary ─────────────────────────────────────────────────────────────── */
.dictionary { padding-top: 16px; }

.dict-controls { margin-bottom: 16px; }
.search-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--gray-200);
  border-radius: 10px;
  font-size: 1rem;
  outline: none;
  margin-bottom: 10px;
  transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--blue); }

.dict-filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filter-select {
  flex: 1;
  min-width: 120px;
  padding: 8px 10px;
  border: 2px solid var(--gray-200);
  border-radius: 8px;
  font-size: 0.8rem;
  outline: none;
  background: white;
  cursor: pointer;
}
.filter-select:focus { border-color: var(--blue); }

.dict-stats {
  font-size: 0.8rem;
  color: var(--gray-400);
  margin-bottom: 12px;
}

.word-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
}

.word-card {
  background: white;
  border: 2px solid var(--gray-200);
  border-radius: 10px;
  padding: 12px 10px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
}
.word-card:hover { border-color: var(--blue); background: var(--blue-light); transform: translateY(-1px); }
.word-fr { font-size: 0.88rem; font-weight: 700; color: var(--gray-800); margin-bottom: 4px; word-break: break-word; }
.word-count { font-size: 0.7rem; color: var(--gray-400); }

.dict-more {
  grid-column: 1 / -1;
  text-align: center;
  padding: 16px;
  color: var(--gray-400);
  font-size: 0.85rem;
}

/* ─── Modal ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
}
.modal {
  background: white;
  border-radius: 20px 20px 0 0;
  padding: 24px 20px 32px;
  width: 100%;
  max-width: 640px;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 16px; right: 16px;
  background: var(--gray-100);
  border: none;
  border-radius: 50%;
  width: 32px; height: 32px;
  font-size: 1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.modal-word {
  font-size: 2rem;
  font-weight: 900;
  color: var(--blue);
  margin-bottom: 4px;
}
.modal-translation {
  font-size: 1rem;
  color: var(--gray-600);
  margin-bottom: 20px;
}
.modal-section-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-400);
  margin-bottom: 12px;
}
.modal-questions { display: flex; flex-direction: column; gap: 12px; }
.modal-q {
  background: var(--gray-50);
  border-radius: 10px;
  padding: 12px 14px;
}
.modal-q-text { font-size: 0.88rem; font-weight: 600; color: var(--gray-800); margin-bottom: 4px; }
.modal-q-answer { font-size: 0.8rem; color: var(--green); font-weight: 600; margin-bottom: 2px; }
.modal-q-exam { font-size: 0.72rem; color: var(--gray-400); }

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 400px) {
  .card-grid { grid-template-columns: 1fr; }
  .mode-grid { grid-template-columns: 1fr; }
}

/* ─── Dictionary redesign ─────────────────────────────────────────────────── */
.dict-mode-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.dict-tab {
  flex: 1;
  padding: 10px;
  border: 2px solid var(--gray-200);
  border-radius: 10px;
  background: white;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--gray-600);
}
.dict-tab.active { border-color: var(--blue); background: var(--blue-light); color: var(--blue); }

.dict-filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.mode-panel { }

/* ── Flashcard ── */
.fc-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.fc-counter { font-size: 0.8rem; color: var(--gray-400); white-space: nowrap; }
.fc-progress-bar-wrap {
  flex: 1;
  height: 6px;
  background: var(--gray-200);
  border-radius: 99px;
  overflow: hidden;
}
.fc-progress-known {
  height: 100%;
  background: var(--green);
  border-radius: 99px;
  transition: width 0.4s;
}
.fc-known-label { font-size: 0.8rem; color: var(--green); font-weight: 700; white-space: nowrap; }

.flashcard {
  perspective: 1000px;
  height: 220px;
  cursor: pointer;
  margin-bottom: 20px;
  user-select: none;
}
.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s cubic-bezier(0.4,0,0.2,1);
  transform-style: preserve-3d;
}
.flashcard-inner.flipped { transform: rotateY(180deg); }

.flashcard-front, .flashcard-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-shadow: var(--shadow);
}
.flashcard-front {
  background: white;
  border: 2px solid var(--gray-200);
}
.flashcard-back {
  background: var(--blue);
  border: 2px solid var(--blue-dark);
  transform: rotateY(180deg);
}

.fc-lang-badge {
  position: absolute;
  top: 14px; left: 14px;
  background: var(--blue-light);
  color: var(--blue);
  font-size: 0.7rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 99px;
  letter-spacing: 0.05em;
}
.fc-lang-badge.en {
  background: rgba(255,255,255,0.2);
  color: white;
}
.flashcard-back .fc-word { color: white; }
.fc-word {
  font-size: 2rem;
  font-weight: 900;
  color: var(--gray-800);
  text-align: center;
  line-height: 1.2;
}
.fc-word-fr-small {
  font-size: 0.9rem;
  color: rgba(255,255,255,0.7);
  margin-top: 8px;
}
.fc-hint {
  position: absolute;
  bottom: 14px;
  font-size: 0.72rem;
  color: var(--gray-400);
}

.fc-actions {
  display: flex;
  gap: 12px;
}
.fc-btn {
  flex: 1;
  padding: 16px;
  border-radius: 12px;
  border: none;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
}
.fc-btn-skip { background: var(--red-light); color: var(--red); }
.fc-btn-skip:hover { background: #fecaca; }
.fc-btn-know { background: var(--green-light); color: var(--green); }
.fc-btn-know:hover { background: #bbf7d0; }
.fc-btn-icon { font-size: 1.1rem; }

.fc-done {
  text-align: center;
  padding: 32px 16px;
}
.fc-done-emoji { font-size: 3rem; margin-bottom: 12px; }
.fc-done-title { font-size: 1.4rem; font-weight: 800; margin-bottom: 8px; }
.fc-done-sub { color: var(--gray-600); font-size: 0.9rem; }

/* ── Word List ── */
.list-controls { display: flex; gap: 8px; margin-bottom: 10px; }
.list-controls .search-input { margin-bottom: 0; }
.dict-stats { font-size: 0.8rem; color: var(--gray-400); margin-bottom: 10px; }

.word-list { display: flex; flex-direction: column; }
.word-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.9rem;
}
.wr-fr { font-weight: 700; color: var(--gray-800); min-width: 120px; }
.wr-arrow { color: var(--gray-400); }
.wr-en { color: var(--gray-600); flex: 1; }
.wr-count { font-size: 0.72rem; color: var(--gray-400); white-space: nowrap; }

/* ── Word Quiz ── */
.quiz-word-progress {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--gray-400);
  margin-bottom: 16px;
}
.quiz-word-progress span:last-child { color: var(--green); font-weight: 700; }

.wq-card { }
.wq-direction {
  font-size: 0.8rem;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  margin-bottom: 10px;
}
.wq-prompt {
  font-size: 2rem;
  font-weight: 900;
  color: var(--blue);
  margin-bottom: 24px;
  line-height: 1.2;
}
.wq-options { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.wq-done { text-align: center; padding: 32px 16px; }
