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

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #16213e;
  --accent: #4ade80;
  --accent-dark: #16a34a;
  --blue: #60a5fa;
  --purple: #a78bfa;
  --red: #f87171;
  --yellow: #fbbf24;
  --orange: #fb923c;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #2d3748;
  --radius: 16px;
  --radius-sm: 10px;
}

html, body {
  height: 100%;
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ── Screens ──────────────────────────────────────────────────────────────── */
.screen { display: none; position: fixed; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.screen.active { display: flex; flex-direction: column; }

/* ── Auth ─────────────────────────────────────────────────────────────────── */
.auth-container {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 32px 24px; gap: 24px;
}
.app-logo { text-align: center; }
.logo-icon { font-size: 64px; margin-bottom: 8px; }
.app-title { font-size: 36px; font-weight: 900; letter-spacing: -1px; }
.app-title span { color: var(--accent); }
.app-subtitle { color: var(--text-muted); font-size: 16px; margin-top: 4px; }

.tab-switch {
  display: flex; background: var(--surface); border-radius: 50px;
  padding: 4px; gap: 4px; width: 100%; max-width: 360px;
}
.tab-btn {
  flex: 1; padding: 12px; border: none; border-radius: 50px;
  background: transparent; color: var(--text-muted);
  font-size: 15px; font-weight: 700; cursor: pointer; font-family: inherit; transition: all 0.2s;
}
.tab-btn.active { background: var(--accent); color: #000; }

.auth-form { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 360px; }

.input-field {
  padding: 16px 20px; border-radius: var(--radius);
  border: 2px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 16px; font-family: inherit;
  outline: none; transition: border-color 0.2s;
}
.input-field:focus { border-color: var(--accent); }
.input-field::placeholder { color: var(--text-muted); }
.error-msg { color: var(--red); font-size: 14px; text-align: center; padding: 8px; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn-primary {
  padding: 18px; border-radius: var(--radius); border: none;
  background: var(--accent); color: #000; font-size: 17px; font-weight: 800;
  cursor: pointer; width: 100%; font-family: inherit; transition: transform 0.1s, opacity 0.1s;
}
.btn-primary:active { transform: scale(0.97); opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  padding: 16px; border-radius: var(--radius); border: 2px solid var(--border);
  background: transparent; color: var(--text); font-size: 16px; font-weight: 700;
  cursor: pointer; width: 100%; font-family: inherit;
}
.btn-secondary:active { opacity: 0.7; }

.btn-icon {
  background: none; border: none; color: var(--text-muted); font-size: 20px;
  cursor: pointer; padding: 8px; border-radius: 50%;
  min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center;
}
.btn-icon:active { background: var(--surface); }

/* ── Home ─────────────────────────────────────────────────────────────────── */
.top-bar {
  display: flex; align-items: center; padding: 16px 20px;
  background: var(--surface); border-bottom: 1px solid var(--border); gap: 12px;
  flex-shrink: 0;
}
.xp-badge {
  background: var(--surface2); border: 1px solid var(--accent);
  color: var(--accent); padding: 6px 14px; border-radius: 50px;
  font-size: 14px; font-weight: 800; white-space: nowrap;
}
.user-badge { flex: 1; color: var(--text-muted); font-size: 14px; font-weight: 600; }

.home-content {
  flex: 1; padding: 24px 20px;
  display: flex; flex-direction: column; gap: 20px;
  max-width: 480px; width: 100%; margin: 0 auto;
}
.home-greeting { font-size: 22px; font-weight: 800; }

/* ── Level Cards ──────────────────────────────────────────────────────────── */
.level-cards { display: flex; flex-direction: column; gap: 12px; }
.level-card {
  display: flex; align-items: center; gap: 16px; padding: 16px;
  background: var(--surface); border-radius: var(--radius);
  border: 2px solid var(--border); cursor: pointer;
  transition: all 0.2s; user-select: none;
}
.level-card.active { border-color: var(--accent); }
.level-card.locked { opacity: 0.45; cursor: not-allowed; }
.level-card:not(.locked):active { transform: scale(0.98); }
.level-icon { font-size: 28px; }
.level-info { flex: 1; }
.level-name { font-size: 15px; font-weight: 800; }
.level-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.level-mastery { font-size: 11px; color: var(--accent); margin-top: 3px; font-weight: 700; }
.level-badge {
  font-size: 18px; width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
}
.level-badge.unlocked { background: var(--accent); color: #000; border-radius: 50%; font-size: 14px; font-weight: 900; }

/* ── Progress ─────────────────────────────────────────────────────────────── */
.progress-section { display: flex; flex-direction: column; gap: 8px; }
.progress-label { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-muted); font-weight: 600; }
.progress-bar-wrap { height: 12px; background: var(--surface); border-radius: 50px; overflow: hidden; border: 1px solid var(--border); }
.progress-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--blue)); border-radius: 50px; transition: width 0.5s ease; width: 0%; }
.accuracy-hint { font-size: 12px; color: var(--text-muted); text-align: center; }

.home-actions { display: flex; flex-direction: column; gap: 10px; }
.btn-start {
  padding: 20px; border-radius: var(--radius); border: none;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  color: #000; font-size: 20px; font-weight: 900; cursor: pointer;
  width: 100%; font-family: inherit; transition: transform 0.1s;
  box-shadow: 0 4px 20px rgba(74, 222, 128, 0.3);
}
.btn-start:active { transform: scale(0.97); }

.btn-vocab {
  padding: 14px; border-radius: var(--radius); border: 2px solid var(--purple);
  background: transparent; color: var(--purple); font-size: 16px; font-weight: 800;
  cursor: pointer; width: 100%; font-family: inherit; transition: all 0.15s;
}
.btn-vocab:active { background: rgba(167, 139, 250, 0.1); }

/* ── Quiz Header ──────────────────────────────────────────────────────────── */
.quiz-header {
  display: flex; align-items: center; padding: 12px 16px; gap: 12px;
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.quiz-progress-wrap { flex: 1; height: 10px; background: var(--surface2); border-radius: 50px; overflow: hidden; }
.quiz-progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--blue)); border-radius: 50px; transition: width 0.4s ease; width: 0%; }
.quiz-xp-badge { color: var(--yellow); font-weight: 800; font-size: 14px; white-space: nowrap; }
.quiz-question-count { text-align: center; padding: 12px; font-size: 13px; color: var(--text-muted); font-weight: 700; flex-shrink: 0; }

/* ── Quiz Area ────────────────────────────────────────────────────────────── */
.quiz-area {
  flex: 1; padding: 16px 20px 120px;
  display: flex; flex-direction: column; gap: 16px;
  max-width: 480px; width: 100%; margin: 0 auto;
}
.quiz-instruction { font-size: 13px; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 1px; }
.quiz-word {
  font-size: 34px; font-weight: 900; text-align: center; padding: 24px;
  background: var(--surface); border-radius: var(--radius); border: 2px solid var(--border); line-height: 1.2;
}

/* Multiple Choice */
.options-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.option-btn {
  padding: 20px 12px; border-radius: var(--radius); border: 2px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 16px; font-weight: 700;
  cursor: pointer; font-family: inherit; transition: all 0.15s; min-height: 72px; text-align: center; line-height: 1.3;
}
.option-btn:active { transform: scale(0.96); }
.option-btn.correct { border-color: var(--accent); background: rgba(74,222,128,0.15); color: var(--accent); }
.option-btn.wrong { border-color: var(--red); background: rgba(248,113,113,0.15); color: var(--red); }
.option-btn.disabled { cursor: not-allowed; opacity: 0.6; }

/* Sentence Builder */
.sentence-target {
  background: var(--surface2); border-radius: var(--radius); padding: 16px;
  min-height: 64px; display: flex; flex-wrap: wrap; gap: 8px;
  align-content: flex-start; border: 2px dashed var(--border);
}
.sentence-target.has-words { border-color: var(--blue); }

.word-bubble {
  padding: 10px 16px; border-radius: 50px; background: var(--blue);
  color: #000; font-size: 16px; font-weight: 800; cursor: pointer;
  transition: transform 0.1s, opacity 0.1s; user-select: none;
}
.word-bubble:active { transform: scale(0.94); }
.word-bubble.placed { opacity: 0.3; cursor: not-allowed; pointer-events: none; }
.word-bubble.answer { background: var(--purple); }
.word-bank { display: flex; flex-wrap: wrap; gap: 10px; padding: 8px 0; }

/* Matching */
.matching-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match-col { display: flex; flex-direction: column; gap: 10px; }
.match-item {
  padding: 14px 10px; border-radius: var(--radius-sm); border: 2px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 14px; font-weight: 700;
  cursor: pointer; text-align: center; transition: all 0.15s; min-height: 52px;
  display: flex; align-items: center; justify-content: center;
  font-family: inherit; line-height: 1.2;
}
.match-item:active { transform: scale(0.96); }
.match-item.selected { border-color: var(--blue); background: rgba(96,165,250,0.2); color: var(--blue); }
.match-item.matched { border-color: var(--accent); background: rgba(74,222,128,0.15); color: var(--accent); cursor: default; }
.match-item.wrong-flash { border-color: var(--red); background: rgba(248,113,113,0.15); }

/* ── Feedback ─────────────────────────────────────────────────────────────── */
.quiz-feedback {
  position: fixed; bottom: 0; left: 0; right: 0;
  padding: 20px 24px 32px; display: flex; flex-direction: column;
  align-items: center; gap: 12px; z-index: 100;
}
.quiz-feedback.correct-fb { background: rgba(74,222,128,0.12); border-top: 2px solid var(--accent); backdrop-filter: blur(8px); }
.quiz-feedback.wrong-fb { background: rgba(248,113,113,0.12); border-top: 2px solid var(--red); backdrop-filter: blur(8px); }
.feedback-icon { font-size: 32px; }
.feedback-text { font-size: 17px; font-weight: 800; text-align: center; }
.btn-next {
  padding: 16px 40px; border-radius: var(--radius); border: none;
  background: var(--accent); color: #000; font-size: 17px; font-weight: 800;
  cursor: pointer; font-family: inherit; width: 100%; max-width: 360px;
}
.btn-next:active { opacity: 0.85; }

/* ── Results ──────────────────────────────────────────────────────────────── */
.results-container {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; padding: 40px 24px 32px; gap: 16px;
  max-width: 480px; width: 100%; margin: 0 auto;
}
.results-emoji { font-size: 72px; }
.results-title { font-size: 26px; font-weight: 900; text-align: center; }
.results-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; width: 100%; }
.stat-box { background: var(--surface); border-radius: var(--radius); padding: 20px; text-align: center; border: 1px solid var(--border); }
.stat-value { font-size: 30px; font-weight: 900; color: var(--accent); }
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 700; margin-top: 4px; }
.levelup-banner {
  background: linear-gradient(135deg, var(--purple), var(--blue));
  color: #fff; padding: 14px 20px; border-radius: var(--radius);
  font-size: 15px; font-weight: 800; text-align: center; width: 100%;
  animation: pulse 1s ease-in-out infinite alternate;
}
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.02); } }

/* ── Session Recap ────────────────────────────────────────────────────────── */
.recap-section { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.recap-title { font-size: 15px; font-weight: 800; color: var(--text-muted); text-align: center; }
.recap-group { display: flex; flex-direction: column; gap: 6px; }
.recap-group-label { font-size: 13px; font-weight: 800; padding: 4px 0; }
.correct-label { color: var(--accent); }
.wrong-label { color: var(--red); }
.recap-list { display: flex; flex-wrap: wrap; gap: 6px; }
.recap-chip {
  padding: 5px 12px; border-radius: 50px; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; gap: 4px;
}
.recap-chip.correct-chip { background: rgba(74,222,128,0.15); color: var(--accent); border: 1px solid rgba(74,222,128,0.3); }
.recap-chip.wrong-chip { background: rgba(248,113,113,0.15); color: var(--red); border: 1px solid rgba(248,113,113,0.3); }
.recap-chip .mastered-star { color: var(--yellow); }

/* ── Vocabulary Screen ────────────────────────────────────────────────────── */
.vocab-tabs {
  display: flex; background: var(--surface); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.vocab-tab {
  flex: 1; padding: 14px; border: none; background: transparent;
  color: var(--text-muted); font-size: 14px; font-weight: 800;
  cursor: pointer; font-family: inherit; transition: all 0.2s;
  border-bottom: 3px solid transparent;
}
.vocab-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.vocab-tab:disabled { opacity: 0.35; cursor: not-allowed; }

.vocab-legend {
  display: flex; gap: 12px; padding: 10px 16px; flex-wrap: wrap;
  background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.legend-item { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-muted); font-weight: 700; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.mastered { background: var(--accent); }
.dot.inprogress { background: var(--yellow); }
.dot.wrong { background: var(--red); }
.dot.unseen { background: var(--border); }

.vocab-content { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.vocab-loading { color: var(--text-muted); text-align: center; padding: 40px; font-size: 16px; }
.vocab-section-title {
  font-size: 12px; font-weight: 800; text-transform: uppercase;
  letter-spacing: 1px; color: var(--text-muted); padding: 8px 0 4px;
}
.vocab-stats-bar {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface); border-radius: var(--radius-sm);
  padding: 12px 16px; margin-bottom: 8px;
}
.vocab-stats-num { font-size: 22px; font-weight: 900; color: var(--accent); }
.vocab-stats-label { font-size: 12px; color: var(--text-muted); font-weight: 700; }

.vocab-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--surface); border-radius: var(--radius-sm);
  border-left: 4px solid var(--border);
}
.vocab-item.status-mastered { border-left-color: var(--accent); }
.vocab-item.status-inprogress { border-left-color: var(--yellow); }
.vocab-item.status-wrong { border-left-color: var(--red); }
.vocab-item.status-unseen { border-left-color: var(--border); opacity: 0.6; }

.vocab-item-text { flex: 1; }
.vocab-en { font-size: 15px; font-weight: 800; }
.vocab-it { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.vocab-it.sentence-it { font-style: italic; }
.vocab-status-icon { font-size: 18px; width: 28px; text-align: center; }
.vocab-score { font-size: 11px; color: var(--text-muted); font-weight: 700; text-align: right; min-width: 40px; }

/* ── Utils ────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
@media (min-width: 480px) {
  .quiz-area, .home-content, .results-container { padding-left: 24px; padding-right: 24px; }
  .quiz-word { font-size: 40px; }
}
