:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e9e9ec;
  --text: #1c1c1e;
  --text-muted: #6b6b74;
  --primary: #5b5bf0;
  --primary-dark: #4747c9;
  --primary-light: #eef0ff;
  --green: #2fb673;
  --green-light: #e7f8ef;
  --amber: #e2a13b;
  --amber-light: #fdf3e2;
  --red: #e05c5c;
  --red-light: #fdeaea;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 2px 10px rgba(20, 20, 30, 0.05);
  --shadow-lg: 0 10px 30px rgba(20, 20, 30, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

html[dir="rtl"] body {
  font-family: 'Cairo', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
html[dir="rtl"] .chip,
html[dir="rtl"] .stat-label,
html[dir="rtl"] .category-bar-name {
  letter-spacing: 0;
}
.lang-toggle {
  border: 1.5px solid var(--border);
}

/* ---------------- Top nav ---------------- */
.topnav {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topnav-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 1.05rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
}
.brand-badge { font-size: 1.3rem; }
.topnav-links { display: flex; gap: 4px; }
.nav-link {
  background: none;
  border: none;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--primary-light); color: var(--primary-dark); }

/* ---------------- Layout / views ---------------- */
#app { max-width: 1080px; margin: 0 auto; padding: 0 20px 80px; }
.view { display: none; animation: fadeIn 0.25s ease; }
.view.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------- Landing ---------------- */
.hero {
  text-align: center;
  padding: 72px 12px 40px;
}
.hero h1 {
  font-size: clamp(2rem, 5vw, 3.1rem);
  font-weight: 800;
  line-height: 1.15;
  margin: 0 0 18px;
  letter-spacing: -0.02em;
}
.hero-sub {
  font-size: clamp(1rem, 2vw, 1.2rem);
  color: var(--text-muted);
  max-width: 560px;
  margin: 0 auto 32px;
}
.hero-actions {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}

.benefits {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin: 40px 0 20px;
}
.benefit-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 22px;
  box-shadow: var(--shadow);
}
.benefit-icon { font-size: 1.8rem; margin-bottom: 10px; }
.benefit-card h3 { margin: 0 0 8px; font-size: 1.05rem; }
.benefit-card p { margin: 0; color: var(--text-muted); font-size: 0.92rem; line-height: 1.5; }

/* ---------------- Buttons ---------------- */
.btn {
  border: none;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  padding: 12px 22px;
  font-size: 0.95rem;
  transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-lg { padding: 15px 28px; font-size: 1.02rem; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 14px rgba(91,91,240,0.28); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--primary-light); color: var(--primary-dark); }
.btn-secondary:hover { background: #e2e4ff; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: #f2f2f4; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

/* ---------------- Challenge screen ---------------- */
.challenge-wrap { padding: 40px 0; max-width: 720px; margin: 0 auto; }

.challenge-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-lg);
}

.challenge-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.chip-number { background: #f0f0f2; color: var(--text-muted); }
.chip-category { background: var(--primary-light); color: var(--primary-dark); }
.chip-difficulty { background: var(--green-light); color: var(--green); }
.chip-difficulty.intermediate { background: var(--amber-light); color: var(--amber); }
.chip-difficulty.challenge { background: var(--red-light); color: var(--red); }

#challenge-title { font-size: 1.5rem; margin: 0 0 10px; }
.challenge-task { color: var(--text-muted); font-size: 1.02rem; line-height: 1.55; margin: 0 0 22px; }

.prompt-label { display: block; font-weight: 600; margin-bottom: 8px; font-size: 0.92rem; }
.prompt-input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  min-height: 140px;
  transition: border-color 0.15s;
}
.prompt-input:focus { outline: none; border-color: var(--primary); }

.challenge-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

.hint-box {
  margin-top: 16px;
  background: var(--amber-light);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  animation: fadeIn 0.2s ease;
}
.hint-box-title { font-weight: 700; margin-bottom: 4px; font-size: 0.9rem; }

/* ---------------- Loading / empty / error states ---------------- */
.loading-state, .empty-state, .error-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-state p { color: var(--red); margin-bottom: 14px; }

/* ---------------- Results ---------------- */
.results-panel { margin-top: 28px; animation: fadeIn 0.3s ease; }

.score-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 30px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  position: relative;
}
.score-number {
  font-size: 3.6rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
  animation: popIn 0.35s cubic-bezier(.34,1.56,.64,1);
}
@keyframes popIn { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.score-out-of { color: var(--text-muted); font-size: 0.95rem; margin-top: 2px; }
.score-label {
  display: inline-block;
  margin-top: 12px;
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 0.9rem;
}

.short-feedback { text-align: center; color: var(--text-muted); max-width: 560px; margin: 18px auto 0; font-size: 1rem; }

.feedback-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 22px;
}
.feedback-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
}
.feedback-col h4 { margin: 0 0 10px; font-size: 0.95rem; }
.feedback-col ul { margin: 0; padding-left: 0; list-style: none; }
.feedback-col li { padding: 4px 0; font-size: 0.92rem; line-height: 1.4; }
.feedback-good li::before { content: "✓ "; color: var(--green); font-weight: 700; }
.feedback-missing li::before { content: "+ "; color: var(--amber); font-weight: 700; }

.suggestions-box {
  margin-top: 16px;
  background: var(--primary-light);
  border-radius: var(--radius-md);
  padding: 20px;
}
.suggestions-box h4 { margin: 0 0 10px; font-size: 0.95rem; color: var(--primary-dark); }
.suggestions-box ul { margin: 0; padding-left: 20px; }
.suggestions-box li { padding: 3px 0; font-size: 0.92rem; }

.results-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; justify-content: center; }

.example-panel {
  margin-top: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 22px;
  animation: fadeIn 0.25s ease;
}
.example-col { margin-bottom: 16px; }
.example-col h4 { margin: 0 0 6px; font-size: 0.88rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.example-col p { margin: 0; line-height: 1.5; white-space: pre-wrap; }
.example-col-strong { background: var(--green-light); padding: 14px 16px; border-radius: var(--radius-sm); }
.example-col-strong h4 { color: var(--green); }
.example-why { background: var(--primary-light); padding: 14px 16px; border-radius: var(--radius-sm); }
.example-why h4 { color: var(--primary-dark); margin: 0 0 6px; font-size: 0.88rem; text-transform: uppercase; letter-spacing: 0.03em; }
.example-why p { margin: 0; line-height: 1.5; }

/* ---------------- Progress ---------------- */
.progress-wrap { padding: 40px 0; }
.progress-wrap h2 { font-size: 1.7rem; margin-bottom: 24px; }

.progress-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 32px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-number { font-size: 2rem; font-weight: 800; color: var(--primary); }
.stat-label { color: var(--text-muted); font-size: 0.85rem; margin-top: 4px; }

.categories-title { font-size: 1.1rem; margin: 28px 0 14px; }
.category-bars { display: flex; flex-direction: column; gap: 12px; }
.category-bar-row { display: flex; align-items: center; gap: 12px; }
.category-bar-name { width: 90px; font-weight: 600; font-size: 0.9rem; text-transform: capitalize; flex-shrink: 0; }
.category-bar-track {
  flex: 1;
  height: 12px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.category-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--green));
  border-radius: 999px;
  transition: width 0.4s ease;
}
.category-bar-count { width: 60px; text-align: right; font-size: 0.82rem; color: var(--text-muted); flex-shrink: 0; }

.recent-attempts { display: flex; flex-direction: column; gap: 8px; }
.recent-attempt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 18px;
}
.recent-attempt-title { font-weight: 600; font-size: 0.92rem; }
.recent-attempt-date { color: var(--text-muted); font-size: 0.8rem; }
.recent-attempt-score {
  font-weight: 800;
  color: var(--primary);
  font-size: 1rem;
  min-width: 46px;
  text-align: right;
}

/* ---------------- About ---------------- */
.about-wrap { max-width: 640px; margin: 0 auto; padding: 48px 0; }
.about-wrap h2 { font-size: 1.7rem; margin-bottom: 18px; }
.about-wrap p { line-height: 1.7; color: var(--text-muted); font-size: 1.02rem; }
.about-loop {
  text-align: center;
  font-weight: 700;
  color: var(--primary-dark);
  background: var(--primary-light);
  border-radius: var(--radius-md);
  padding: 18px;
  font-size: 0.95rem;
}

/* ---------------- Responsive ---------------- */
@media (max-width: 760px) {
  .benefits { grid-template-columns: 1fr; }
  .progress-stats { grid-template-columns: repeat(2, 1fr); }
  .feedback-grid { grid-template-columns: 1fr; }
  .challenge-card { padding: 22px; }
  .topnav-links { gap: 0; }
  .nav-link { padding: 8px 10px; font-size: 0.85rem; }
}
