:root {
  --purple: #7c3aed;
  --purple-dark: #5b21b6;
  --pink: #ec4899;
  --blue: #3b82f6;
  --green: #22c55e;
  --yellow: #f59e0b;
  --red: #ef4444;
  --bg: #f3e8ff;
  --card: #ffffff;
  --text: #2d1b4e;
  --radius: 22px;
  --shadow: 0 10px 30px rgba(124, 58, 237, 0.18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  direction: rtl;
  font-family: "Segoe UI", "Rubik", Arial, Tahoma, sans-serif;
  background: linear-gradient(160deg, #f3e8ff 0%, #e0f2fe 50%, #fce7f3 100%);
  color: var(--text);
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: linear-gradient(90deg, var(--purple), var(--pink));
  color: #fff;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar .brand {
  font-size: 1.3rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: #fff;
}

.topbar nav {
  display: flex;
  gap: 10px;
  align-items: center;
}

.topbar nav a, .topbar nav button {
  color: #fff;
  background: rgba(255,255,255,0.18);
  border: none;
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.95rem;
}

.topbar nav a:hover, .topbar nav button:hover { background: rgba(255,255,255,0.32); }

.score-pill {
  background: rgba(255,255,255,0.25) !important;
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}

/* Nudges the coin pill once the player has enough points that the store
   is worth a visit - a subtle grow/shrink + glow, not a jarring blink. */
#topbar-coins.coins-hint { animation: coins-hint-pulse 1.6s ease-in-out infinite; }
@keyframes coins-hint-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 rgba(255,215,0,0); }
  50% { transform: scale(1.14); box-shadow: 0 0 14px 4px rgba(255,215,0,0.6); }
}

/* Profile menu */
.profile-menu-wrap { position: relative; }
.profile-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  background: #fff;
  color: var(--text);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  width: 240px;
  z-index: 60;
}
.profile-dropdown.open { display: block; }
.profile-dropdown-title { font-weight: 800; color: var(--purple-dark); margin-bottom: 10px; }

.volume-row { padding: 8px 0; font-size: 0.9rem; font-weight: 600; }
.volume-row input[type=range] { width: 100%; margin-top: 6px; accent-color: var(--purple); }

.dropdown-logout-btn {
  width: 100%;
  margin-top: 14px;
  background: #fee2e2;
  color: #b91c1c;
  border: none;
  border-radius: 10px;
  padding: 9px;
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
}
.dropdown-logout-btn:hover { background: #fecaca; }

/* Fake "ad" link used as a teaching trap: text looks like it goes to an
   external freebie site, but it's a plain button that navigates to the
   fake-URLs lesson - never an actual link out to any external address. */
.fake-ad-banner {
  cursor: pointer;
  text-align: center;
  border: 2px dashed var(--yellow);
  background: #fffbeb;
}
.fake-ad-banner:hover { background: #fef3c7; }
.fake-ad-banner .bait-title { font-size: 1.15rem; font-weight: 900; color: #92400e; }
.fake-ad-banner .bait-url { direction: ltr; font-weight: 700; color: #1d4ed8; text-decoration: underline; margin-top: 4px; }
.fake-ad-banner .bait-sub { font-size: 0.85rem; color: #6b7280; margin-top: 4px; }

.parent-pill { padding: 3px 10px; border-radius: 999px; font-weight: 700; font-size: 0.78rem; background: #fce7f3; color: #9d174d; }
.btn-mini-parent { background: #fce7f3; color: #9d174d; }
.btn-mini-unparent { background: #f3f4f6; color: #374151; }

/* Sound/music icon toggles - a red X badge overlays the icon when muted/off,
   so the current state is legible at a glance instead of a plain switch. */
.topbar .icon-toggle-btn {
  position: relative;
  background: rgba(255,255,255,0.18);
  border: none;
  border-radius: 999px;
  width: 38px;
  height: 38px;
  font-size: 1.05rem;
  cursor: pointer;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.topbar .icon-toggle-btn:hover { background: rgba(255,255,255,0.32); }
.icon-toggle-btn.muted .icon-toggle-emoji { opacity: 0.45; }
.icon-toggle-x {
  display: none;
  position: absolute;
  top: -3px;
  left: -3px;
  background: var(--red);
  color: #fff;
  border-radius: 50%;
  width: 17px;
  height: 17px;
  font-size: 0.62rem;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  border: 2px solid #fff;
  line-height: 1;
}
.icon-toggle-btn.muted .icon-toggle-x { display: flex; }

/* Logout - deliberately high-contrast (white on the gradient topbar) so
   it's never the "almost invisible" button. Selectors here are scoped as
   `.topbar .logout-btn-visible` (not just `.logout-btn-visible`) because
   the generic `.topbar nav button` rule above has higher specificity
   (one class + two elements) and would otherwise win over a single-class
   selector, silently overriding this back to the plain nav-button look. */
.topbar .logout-btn-visible {
  background: #fff;
  color: #b91c1c;
  border: none;
  border-radius: 999px;
  padding: 9px 16px;
  font-weight: 800;
  font-size: 0.92rem;
  cursor: pointer;
  flex-shrink: 0;
}
.topbar .logout-btn-visible:hover { background: #fee2e2; }

/* Avatar */
.avatar-circle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  box-shadow: 0 3px 8px rgba(0,0,0,0.2);
  vertical-align: middle;
  line-height: 1;
}
.avatar-acc {
  position: absolute;
  bottom: -4px;
  left: -4px;
  background: #fff;
  border-radius: 50%;
  padding: 1px;
  line-height: 1;
}
.profile-btn { display: flex; align-items: center; gap: 8px; }

main {
  flex: 1;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 28px 18px 60px;
}

.center-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

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

h1 { font-size: 1.9rem; margin: 0 0 10px; }
h2 { font-size: 1.4rem; margin: 22px 0 10px; color: var(--purple-dark); }
p { line-height: 1.7; font-size: 1.05rem; }

.term-en {
  direction: ltr;
  display: inline-block;
  font-weight: 700;
  color: var(--purple-dark);
  background: #ede9fe;
  padding: 1px 8px;
  border-radius: 8px;
  font-family: "Consolas", monospace;
}

.btn {
  display: inline-block;
  border: none;
  border-radius: 999px;
  padding: 13px 26px;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(90deg, var(--purple), var(--pink));
  box-shadow: 0 6px 16px rgba(124,58,237,0.35);
  transition: transform 0.12s ease;
}
.btn:hover { transform: translateY(-2px) scale(1.02); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: #fff;
  color: var(--purple-dark);
  border: 2px solid #e9d5ff;
  box-shadow: none;
}

.btn-green { background: linear-gradient(90deg, #16a34a, #22c55e); }
.btn-block { display: block; width: 100%; text-align: center; }

input[type=text], input[type=password], select {
  width: 100%;
  padding: 13px 16px;
  border-radius: 14px;
  border: 2px solid #e9d5ff;
  font-size: 1.05rem;
  margin-bottom: 14px;
  direction: rtl;
  font-family: inherit;
  background: #fff;
}
input:focus, select:focus { outline: 3px solid #c4b5fd; border-color: var(--purple); }

.field-label { font-weight: 700; margin-bottom: 6px; display: block; }

.error-box {
  background: #fee2e2;
  color: #991b1b;
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-weight: 700;
  display: none;
}
.error-box.show { display: block; }

.hint-box {
  background: #fef9c3;
  border: 2px dashed #eab308;
  border-radius: 14px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 0.95rem;
}

/* Lesson path / dashboard */
.lesson-path {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.lesson-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  border: 3px solid transparent;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.lesson-card:hover { transform: translateY(-4px); border-color: #ddd6fe; }
.lesson-card .emoji { font-size: 2.4rem; }
.lesson-card .title { font-weight: 800; font-size: 1.1rem; }
.lesson-card .desc { font-size: 0.9rem; color: #6b7280; }
.lesson-card.completed { border-color: var(--green); }
.lesson-card .badge-check {
  position: absolute; top: 14px; left: 14px;
  background: var(--green); color: #fff;
  border-radius: 999px; width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
}
.lesson-card .score-tag {
  font-weight: 800; color: var(--purple-dark);
  font-size: 0.9rem;
}
.mini-progress-outer {
  background: #ede9fe;
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
  margin-top: 4px;
}
.mini-progress-inner {
  background: linear-gradient(90deg, var(--purple), var(--pink));
  height: 100%;
  width: 0%;
  border-radius: 999px;
  transition: width 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}

.progress-summary {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin: 18px 0;
}
.stat-box {
  background: #fff;
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 16px 22px;
  text-align: center;
  flex: 1;
  min-width: 130px;
}
.stat-box .num { font-size: 1.7rem; font-weight: 900; color: var(--purple); }
.stat-box .label { font-size: 0.85rem; color: #6b7280; font-weight: 700; }

.badges-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.badge-pill {
  background: linear-gradient(90deg, var(--yellow), #fbbf24);
  color: #7c2d12;
  font-weight: 800;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
}

/* Quiz */
.quiz-question { margin-bottom: 18px; }
.quiz-options { display: flex; flex-direction: column; gap: 10px; }
.quiz-option {
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 14px;
  padding: 12px 16px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  text-align: right;
  transition: all 0.12s ease;
}
.quiz-option:hover { background: #ede9fe; border-color: #c4b5fd; }
.quiz-option.selected { border-color: var(--purple); background: #ede9fe; }
.quiz-option.correct { border-color: var(--green); background: #dcfce7; }
.quiz-option.wrong { border-color: var(--red); background: #fee2e2; }
.quiz-option:disabled, .quiz-option[data-locked=true] { cursor: default; }

.feedback-box {
  margin-top: 12px;
  padding: 12px 16px;
  border-radius: 14px;
  font-weight: 700;
  display: none;
}
.feedback-box.show { display: block; }
.feedback-box.good { background: #dcfce7; color: #166534; }
.feedback-box.bad { background: #fee2e2; color: #991b1b; }

.bonus-box {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  border: 3px dashed #f59e0b;
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 24px;
}
.bonus-box .bonus-title { font-weight: 900; font-size: 1.2rem; color: #92400e; }

.completion-screen { text-align: center; }
.completion-screen .big-emoji { font-size: 4rem; }

.leaderboard-table { width: 100%; border-collapse: collapse; margin-top: 16px; }
.leaderboard-table th, .leaderboard-table td {
  padding: 12px 14px;
  text-align: right;
  border-bottom: 1px solid #eee;
}
.leaderboard-table th { color: #6b7280; font-size: 0.85rem; }
.leaderboard-table tr:first-child td { font-weight: 900; }
.rank-medal { font-size: 1.3rem; }

footer {
  text-align: center;
  padding: 18px;
  color: #7c3aed99;
  font-size: 0.85rem;
}

#fx-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
}

.mute-btn { font-size: 1.1rem; }

.progress-bar-outer {
  background: #ede9fe;
  border-radius: 999px;
  height: 14px;
  overflow: hidden;
  margin: 10px 0 20px;
}
.progress-bar-inner {
  background: linear-gradient(90deg, var(--purple), var(--pink));
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* Ask-a-mentor floating button + modal */
.mentor-fab {
  position: fixed;
  bottom: 22px;
  left: 22px;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--purple), var(--pink));
  color: #fff;
  font-size: 1.7rem;
  box-shadow: 0 8px 22px rgba(124,58,237,0.45);
  cursor: pointer;
  z-index: 80;
  transition: transform 0.15s ease;
  animation: mentor-bob 2.4s ease-in-out infinite;
}
.mentor-fab:hover { transform: scale(1.08); }
@keyframes mentor-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.mentor-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(45, 27, 78, 0.45);
  z-index: 90;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.mentor-overlay.open { display: flex; }
.mentor-modal {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
}
.mentor-close {
  position: absolute;
  top: 16px;
  left: 16px;
  border: none;
  background: #f3e8ff;
  color: var(--purple-dark);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
}

/* Security flashcard toast */
.safety-toast {
  position: fixed;
  top: 86px;
  right: 50%;
  transform: translate(50%, -20px);
  opacity: 0;
  background: #fff;
  border: 2px solid #fde68a;
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 12px 16px;
  max-width: 420px;
  width: calc(100% - 32px);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 70;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
.safety-toast.show { opacity: 1; transform: translate(50%, 0); }
.safety-toast-label { font-weight: 800; color: #b45309; white-space: nowrap; font-size: 0.85rem; }
.safety-toast-text { font-size: 0.9rem; flex: 1; }
.safety-toast-close {
  border: none; background: #f3f4f6; border-radius: 50%;
  width: 24px; height: 24px; cursor: pointer; flex-shrink: 0; font-size: 0.8rem;
}

@media (max-width: 600px) {
  h1 { font-size: 1.5rem; }
  .card { padding: 18px; }
  .mentor-fab { bottom: 16px; left: 16px; width: 54px; height: 54px; font-size: 1.4rem; }
}
