/* PyCourse design system — playful, for young learners (≈13 y/o).
   One stylesheet for LTR (en) and RTL (fa): CSS logical properties only,
   so the layout mirrors automatically under <html dir="rtl">.
   Never use left/right physical properties here (code blocks excepted —
   code is always LTR). */

:root {
  --bg: #f4f5ff;
  --bg-soft: #ebedff;
  --surface: #ffffff;
  --ink: #23264d;
  --muted: #62688f;
  --brand: #5b5bf0;
  --brand-ink: #4338ca;
  --brand-soft: #e4e6ff;
  --violet: #8b5cf6;
  --pink: #ec4899;
  --sun: #ffb703;
  --orange: #ff8a3d;
  --ok: #10b981;
  --ok-ink: #047857;
  --ok-soft: #d9f7ec;
  --bad: #ef4444;
  --bad-soft: #fee2e2;
  --warn: #f59e0b;
  --warn-soft: #fef3d8;
  --border: #e4e7fb;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow: 0 1px 2px rgba(35, 38, 77, 0.06), 0 4px 12px rgba(35, 38, 77, 0.06);
  --shadow-lift: 0 4px 10px rgba(35, 38, 77, 0.08), 0 12px 28px rgba(35, 38, 77, 0.12);
  --grad-brand: linear-gradient(135deg, #6366f1 0%, #8b5cf6 55%, #d946ef 100%);
  --grad-sun: linear-gradient(90deg, #ffb703, #ff8a3d);
  font-size: 16px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system,
    "Segoe UI", Roboto, sans-serif;
  line-height: 1.65;
  display: flex;
  flex-direction: column;
}

/* Soft candy background: two glows + a faint dot grid */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(38rem 24rem at 12% -4%, rgba(99, 102, 241, 0.14), transparent 60%),
    radial-gradient(34rem 22rem at 96% 8%, rgba(236, 72, 153, 0.10), transparent 60%),
    radial-gradient(circle, rgba(99, 102, 241, 0.10) 1px, transparent 1.5px);
  background-size: auto, auto, 26px 26px;
}

[dir="rtl"] body,
[dir="rtl"] button,
[dir="rtl"] input,
[dir="rtl"] select,
[dir="rtl"] textarea {
  font-family: Vazirmatn, system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
}

h1, h2, h3 { line-height: 1.3; letter-spacing: -0.015em; }
h1 { font-size: 1.75rem; font-weight: 800; }
h2 { font-size: 1.3rem; font-weight: 800; }

.container {
  width: 100%;
  max-width: 1020px;
  margin-inline: auto;
  padding-inline: 1rem;
}

main.container { flex: 1; padding-block-end: 2rem; }

/* ============ Header ============ */
.site-header {
  position: sticky;
  inset-block-start: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-block-end: 1px solid var(--border);
}
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 4rem;
  flex-wrap: wrap;
  padding-block: 0.4rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--ink);
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}
.brand-logo {
  display: grid;
  place-items: center;
  inline-size: 2.35rem;
  block-size: 2.35rem;
  border-radius: 12px;
  background: var(--grad-brand);
  font-size: 1.25rem;
  box-shadow: 0 4px 10px rgba(99, 102, 241, 0.35);
  rotate: -4deg;
  transition: rotate 0.2s ease, scale 0.2s ease;
}
.brand:hover .brand-logo { rotate: 4deg; scale: 1.06; }
.brand-name b { color: var(--brand); }

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.nav-links > a,
.nav-links .linklike {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-links > a:hover,
.nav-links .linklike:hover { background: var(--brand-soft); color: var(--brand-ink); }

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
  padding: 0.25rem 0.8rem 0.25rem 0.3rem;
  padding-inline: 0.3rem 0.8rem;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.user-chip:hover { border-color: var(--brand); box-shadow: var(--shadow); }
.avatar {
  display: grid;
  place-items: center;
  inline-size: 1.9rem;
  block-size: 1.9rem;
  border-radius: 50%;
  background: var(--grad-brand);
  color: #fff;
  font-weight: 800;
  font-size: 0.9rem;
  text-transform: uppercase;
}

.inline-form { display: inline; }
.linklike {
  background: none;
  border: none;
  padding: 0;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
}
.lang-switch .linklike {
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.3rem 0.75rem;
}
.lang-switch .linklike:hover { border-color: var(--brand); }

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: var(--grad-brand);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.4rem;
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
  transition: translate 0.15s ease, box-shadow 0.15s ease, scale 0.1s ease;
}
.btn:hover {
  translate: 0 -2px;
  box-shadow: 0 8px 18px rgba(99, 102, 241, 0.4);
  color: #fff;
}
.btn:active { scale: 0.97; translate: 0 0; }
.btn-small { padding: 0.35rem 1rem; font-size: 0.9rem; }
.btn-secondary {
  background: var(--surface);
  color: var(--brand-ink);
  border: 2px solid var(--brand-soft);
  box-shadow: none;
}
.btn-secondary:hover {
  border-color: var(--brand);
  color: var(--brand-ink);
  box-shadow: var(--shadow);
}
.btn-sun {
  background: var(--grad-sun);
  box-shadow: 0 4px 12px rgba(255, 138, 61, 0.4);
}
.btn-sun:hover { box-shadow: 0 8px 18px rgba(255, 138, 61, 0.45); }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; translate: none; scale: none; }

/* ============ Cards ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.4rem 1.5rem;
  margin-block: 1.1rem;
}
.card > h2:first-child { margin-block-start: 0; }
.card-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-block: 0 0.75rem;
}

/* Page header row (back link + title) */
.page-back {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--muted);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.92rem;
  margin-block: 1rem 0.25rem;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
}
.page-back:hover { background: var(--brand-soft); color: var(--brand-ink); }

/* ============ Forms ============ */
form p { margin-block: 0.85rem; }
label { display: block; font-weight: 700; margin-block-end: 0.3rem; }
input[type="text"], input[type="password"], input[type="email"],
input[type="number"], input[type="url"], select, textarea {
  width: 100%;
  max-width: 28rem;
  padding: 0.6rem 0.9rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  font: inherit;
  background: var(--surface);
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(91, 91, 240, 0.15);
}
.helptext { color: var(--muted); font-size: 0.85rem; display: block; }
.errorlist {
  color: var(--bad);
  list-style: none;
  padding: 0;
  margin-block: 0.25rem;
  font-weight: 600;
  font-size: 0.9rem;
}

/* Self-hosted captcha widget */
img.captcha {
  display: block;
  border: 2px solid var(--border);
  border-radius: 12px;
  margin-block: 0.4rem;
  background: #fff;
}
input[name="captcha_1"] {
  direction: ltr; /* challenge characters are Latin */
  max-width: 12rem;
}

/* Auth pages */
.auth-card {
  max-width: 26.5rem;
  margin-inline: auto;
  margin-block-start: 2.5rem;
  text-align: start;
}
.auth-hero {
  display: block;
  text-align: center;
  font-size: 2.6rem;
  margin-block-end: 0.25rem;
  filter: drop-shadow(0 6px 10px rgba(99, 102, 241, 0.3));
}
.auth-card h1 { text-align: center; margin-block: 0.25rem 0.5rem; }
.auth-sub { text-align: center; color: var(--muted); margin-block-start: 0; }
.auth-card input { max-width: none; }
.auth-card .btn { width: 100%; margin-block-start: 0.5rem; }
.auth-links { text-align: center; font-size: 0.95rem; }
.auth-links a { color: var(--brand-ink); font-weight: 700; }

/* Flash messages */
.flash {
  border-radius: var(--radius);
  padding: 0.7rem 1.1rem;
  margin-block: 1rem;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  box-shadow: var(--shadow);
}
.flash-success { border-color: var(--ok); background: var(--ok-soft); color: var(--ok-ink); }
.flash-error { border-color: var(--bad); background: var(--bad-soft); }

/* ============ Hero (logged-out roadmap) ============ */
.hero {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  flex-wrap: wrap;
  background: var(--grad-brand);
  color: #fff;
  border-radius: calc(var(--radius-lg) * 1.2);
  padding: 2.4rem 2.4rem;
  margin-block: 1.5rem;
  box-shadow: var(--shadow-lift);
}
.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 85% 20%, rgba(255, 255, 255, 0.18) 0 6rem, transparent 6.5rem),
    radial-gradient(circle at 70% 90%, rgba(255, 255, 255, 0.10) 0 4rem, transparent 4.5rem),
    radial-gradient(circle, rgba(255, 255, 255, 0.16) 1.5px, transparent 2px);
  background-size: auto, auto, 30px 30px;
  pointer-events: none;
}
.hero h1 { margin: 0 0 0.4rem; font-size: 2.1rem; }
.hero p { margin: 0; opacity: 0.92; font-size: 1.05rem; max-width: 34rem; }
.hero .btn { position: relative; z-index: 1; margin-block-start: 1.1rem; }
.hero-art {
  position: relative;
  z-index: 1;
  font-size: 4.5rem;
  filter: drop-shadow(0 10px 16px rgba(0, 0, 0, 0.25));
  animation: float 4s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { translate: 0 0; rotate: -4deg; }
  50% { translate: 0 -12px; rotate: 4deg; }
}
.hero-progress { text-align: center; }
.hero-progress small { opacity: 0.85; }

/* Progress ring */
.ring {
  --p: 0;
  inline-size: 92px;
  block-size: 92px;
  border-radius: 50%;
  background:
    radial-gradient(closest-side, #4c46b6 79%, transparent 80% 100%),
    conic-gradient(#ffd166 calc(var(--p) * 1%), rgba(255, 255, 255, 0.25) 0);
  display: grid;
  place-items: center;
  margin-inline: auto;
  margin-block-end: 0.35rem;
}
.ring span { font-weight: 800; font-size: 1.15rem; }

/* ============ Player HUD ============ */
.hud {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  background: linear-gradient(135deg, #232160 0%, #3b2f8f 55%, #5b21b6 100%);
  color: #fff;
  border-radius: calc(var(--radius-lg) * 1.2);
  padding: 1.35rem 1.8rem;
  margin-block: 1.5rem;
  box-shadow: var(--shadow-lift);
}
.hud::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.18) 1px, transparent 1.6px);
  background-size: 22px 22px;
  mask-image: linear-gradient(115deg, transparent 35%, #000);
  pointer-events: none;
}
.hud-rank { display: flex; align-items: center; gap: 0.8rem; }
.hud-rank-emoji {
  font-size: 2rem;
  display: grid;
  place-items: center;
  inline-size: 3.4rem;
  block-size: 3.4rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.hud-rank-name { font-weight: 800; font-size: 1.15rem; }
.hud-level { opacity: 0.8; font-size: 0.9rem; font-weight: 600; }
.hud-xp { flex: 1; min-inline-size: 190px; }
.hud-xp-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  font-weight: 700;
  margin-block-end: 0.3rem;
}
.hud-xp .helptext { color: rgba(255, 255, 255, 0.65); }
.hud-badges {
  display: flex;
  gap: 0.3rem;
  font-size: 1.45rem;
  flex-wrap: wrap;
  max-inline-size: 12rem;
}
.hud-badge {
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.45));
  transition: scale 0.15s ease;
}
.hud-badge:hover { scale: 1.3; }
.ring-hud {
  inline-size: 76px;
  block-size: 76px;
  background:
    radial-gradient(closest-side, #37307c 79%, transparent 80% 100%),
    conic-gradient(#ffd166 calc(var(--p) * 1%), rgba(255, 255, 255, 0.2) 0);
}
.ring-hud span { font-size: 0.95rem; }

/* Progress bars */
.bar {
  flex: 0 1 180px;
  block-size: 12px;
  border-radius: 999px;
  background: var(--bg-soft);
  overflow: hidden;
}
.bar-fill {
  position: relative;
  block-size: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand), var(--violet));
  transition: inline-size 0.5s ease;
}
.bar-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.5) 50%, transparent 70%);
  animation: shimmer 2.4s ease-in-out infinite;
}
@keyframes shimmer {
  0% { translate: -100% 0; }
  60%, 100% { translate: 100% 0; }
}
.bar-hud { background: rgba(255, 255, 255, 0.18); }
.bar-hud .bar-fill { background: var(--grad-sun); }
.bar-label { color: var(--muted); font-size: 0.85rem; font-weight: 700; }

/* ============ Worlds & quest map ============ */
.world { margin-block: 2.6rem; --world-accent: var(--brand); --world-soft: var(--brand-soft); }
.world-b { --world-accent: #0ea5e9; --world-soft: #dbf1ff; }
.world-c { --world-accent: #ec4899; --world-soft: #ffe0ef; }

.world-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.world-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.4rem;
  margin-block: 0.5rem;
}
.world-emoji {
  display: grid;
  place-items: center;
  inline-size: 2.6rem;
  block-size: 2.6rem;
  border-radius: 14px;
  background: var(--world-soft);
  font-size: 1.3rem;
  rotate: -4deg;
}
.world-conquered .world-emoji { background: #fef3c7; }
.world-count {
  font-weight: 800;
  color: var(--world-accent);
  background: var(--surface);
  border: 2px solid var(--world-soft);
  border-radius: 999px;
  padding: 0.25rem 0.9rem;
}

/* The winding path */
.quest-path {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
  position: relative;
}
.quest-path::before {
  content: "";
  position: absolute;
  inset-block: 1.6rem;
  inset-inline-start: 1.55rem;
  border-inline-start: 3px dashed color-mix(in srgb, var(--world-accent) 35%, transparent);
}
.quest-node {
  position: relative;
  display: flex;
  gap: 1rem;
  padding-block: 0.75rem;
  align-items: flex-start;
}
.node-marker {
  position: relative;
  z-index: 1;
  inline-size: 3.2rem;
  block-size: 3.2rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.1rem;
  background: var(--surface);
  border: 3px solid var(--border);
  color: var(--muted);
  flex-shrink: 0;
  box-shadow: var(--shadow);
}
.state-conquered .node-marker {
  background: linear-gradient(135deg, #fcd34d, #f59e0b);
  border-color: #f59e0b;
  font-size: 1.35rem;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.45);
}
.state-active .node-marker {
  background: var(--world-accent);
  border-color: color-mix(in srgb, var(--world-accent) 70%, #000);
  color: #fff;
  animation: node-pulse 1.6s ease-in-out infinite;
}
@keyframes node-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--world-accent) 45%, transparent); }
  50% { box-shadow: 0 0 0 13px transparent; }
}

.node-card {
  position: relative;
  flex: 1;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1rem 1.2rem;
  transition: box-shadow 0.15s ease, translate 0.15s ease, border-color 0.15s ease;
}
.quest-node:hover .node-card {
  box-shadow: var(--shadow-lift);
  translate: 0 -2px;
  border-color: color-mix(in srgb, var(--world-accent) 45%, var(--border));
}
.state-conquered .node-card {
  background: linear-gradient(180deg, #fffbeb 0%, var(--surface) 65%);
  border-color: #fcd34d;
}
.state-active .node-card { border-color: var(--world-accent); }
.state-unexplored .node-card { opacity: 0.8; filter: saturate(0.55); }

.node-title {
  font-weight: 800;
  font-size: 1.08rem;
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
}
.node-title:hover { color: var(--world-accent); }

.stamp {
  position: absolute;
  inset-block-start: 0.7rem;
  inset-inline-end: 0.9rem;
  border: 2px solid #d97706;
  color: #b45309;
  border-radius: 8px;
  padding: 0.05rem 0.55rem;
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  rotate: -6deg;
  opacity: 0.9;
  background: rgba(255, 251, 235, 0.85);
}
[dir="rtl"] .stamp { rotate: 6deg; }
.here-label {
  position: absolute;
  inset-block-start: -0.75rem;
  inset-inline-start: 1rem;
  background: var(--world-accent);
  color: #fff;
  border-radius: 999px;
  padding: 0.12rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.node-meta { display: flex; gap: 0.4rem; margin-block: 0.45rem; flex-wrap: wrap; }
.meta-chip {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.65rem;
}
.meta-on { color: var(--ok-ink); background: var(--ok-soft); border-color: transparent; }

/* Challenge pills */
.pill-row, .pill-row-quest {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-block-start: 0.5rem;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 999px;
  padding: 0.3rem 0.9rem;
  font-size: 0.87rem;
  font-weight: 700;
  text-decoration: none;
  border: 1.5px solid var(--border);
  color: var(--muted);
  background: var(--surface);
  transition: translate 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.pill-lg { font-size: 0.98rem; padding: 0.45rem 1.1rem; }
.pill:hover {
  border-color: var(--brand);
  color: var(--brand-ink);
  translate: 0 -1px;
  box-shadow: var(--shadow);
}
.pill-done { background: var(--ok-soft); color: var(--ok-ink); border-color: transparent; }
.pill-half { background: var(--warn-soft); color: #b45309; border-color: transparent; }
.pill-todo { background: var(--surface); }
.stars { font-size: 0.78rem; letter-spacing: -0.05em; }

/* ============ Badges ============ */
.badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.8rem;
}
.badge-card {
  border: 1.5px solid #fde68a;
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  display: grid;
  gap: 0.25rem;
  background: linear-gradient(180deg, #fffbea 0%, var(--surface) 75%);
  transition: translate 0.15s ease, box-shadow 0.15s ease;
}
.badge-card:hover { translate: 0 -3px; box-shadow: var(--shadow-lift); }
.badge-emoji { font-size: 2.2rem; filter: drop-shadow(0 3px 4px rgba(180, 83, 9, 0.25)); }
.badge-card small { color: var(--muted); }
.badge-toast {
  position: fixed;
  inset-block-end: 1.5rem;
  inset-inline-end: 1.5rem;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius);
  padding: 0.85rem 1.25rem;
  font-weight: 700;
  box-shadow: var(--shadow-lift);
  z-index: 100;
  animation: toast-in 0.3s ease;
}
@keyframes toast-in { from { opacity: 0; translate: 0 12px; } }

/* ============ Quiz ============ */
.quiz-q {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.3rem 1.1rem;
  margin-block: 1.1rem;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.quiz-q legend {
  font-weight: 800;
  padding-inline: 0.45rem;
  font-size: 1.02rem;
}
.quiz-solved { border-color: var(--ok); background: var(--ok-soft); }
.quiz-choice {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.7rem;
  margin-block: 0.3rem;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  transition: border-color 0.12s ease, background 0.12s ease, translate 0.12s ease;
}
.quiz-choice:hover { border-color: var(--brand); translate: 0 -1px; }
.quiz-choice:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.quiz-solved .quiz-choice:has(input:checked) { border-color: var(--ok); background: #c9f2e3; }
.quiz-choice input {
  accent-color: var(--brand);
  inline-size: 1.1rem;
  block-size: 1.1rem;
  flex-shrink: 0;
}
.quiz-feedback { margin: 0.5rem 0 0; font-weight: 700; min-block-size: 1.2rem; }
.quiz-solved .quiz-feedback { color: var(--ok-ink); }

.cta-card { text-align: center; }

/* ============ Difficulty tabs ============ */
.diff-tabs { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-block: 1rem; }
.diff-tab {
  border-radius: 999px;
  padding: 0.4rem 1.1rem;
  font-weight: 800;
  font-size: 0.9rem;
  text-decoration: none;
  border: 2px solid var(--border);
  color: var(--muted);
  background: var(--surface);
  transition: translate 0.12s ease, border-color 0.12s ease;
}
.diff-tab:hover { border-color: var(--brand); color: var(--brand-ink); translate: 0 -1px; }
.diff-easy.diff-current { border-color: var(--ok); color: var(--ok-ink); background: var(--ok-soft); }
.diff-medium.diff-current { border-color: var(--warn); color: #b45309; background: var(--warn-soft); }
.diff-hard.diff-current { border-color: var(--bad); color: #b91c1c; background: var(--bad-soft); }
.diff-solved { color: var(--ok); font-weight: 900; }

/* ============ Video embed ============ */
.video-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  margin-block: 1rem;
}
.video-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lift);
}

/* ============ Code — always LTR, even on the Persian site ============ */
/* unicode-bidi: isolate is what makes this work for INLINE <code> inside
   RTL sentences — without it, direction has no effect on inline elements
   and snippets like print() render as ()print. */
pre, code, .code-ltr, .highlight {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left; /* physical on purpose: code is always LTR */
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
code {
  background: #eef0ff;
  color: #4338ca;
  border-radius: 6px;
  padding: 0.06rem 0.4rem;
  font-size: 0.9em;
}
pre code { background: none; padding: 0; color: inherit; }
pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 1rem 1.15rem;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 0.9rem;
}

/* Sample-test tables on exercise pages */
.sample-table pre {
  margin: 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  background: #f6f7ff;
  color: var(--ink);
  border: 1px solid var(--border);
}

/* ============ Editor card ============ */
.editor-chrome {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #1e293b;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 0.55rem 0.9rem;
  direction: ltr;
}
.editor-dots { display: flex; gap: 0.35rem; }
.editor-dots i {
  inline-size: 0.72rem;
  block-size: 0.72rem;
  border-radius: 50%;
  display: block;
}
.editor-dots i:nth-child(1) { background: #f87171; }
.editor-dots i:nth-child(2) { background: #fbbf24; }
.editor-dots i:nth-child(3) { background: #34d399; }
.editor-filename {
  color: #94a3b8;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  margin-inline: auto;
}
.editor-pybadge {
  color: #cbd5e1;
  font-size: 0.75rem;
  font-weight: 700;
  background: rgba(148, 163, 184, 0.18);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
}

/* Editor + syntax-highlight overlay.
   The <pre> overlay sits behind a transparent-text textarea; both MUST share
   identical font metrics, padding, and white-space handling or the colors
   drift off the letters. */
.editor-wrap {
  position: relative;
  border-radius: 0 0 var(--radius) var(--radius);
  background: #0f172a;
  overflow: hidden;
}
#code-editor,
.code-highlight {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 16px; /* below 16px iOS zooms the page on focus */
  line-height: 1.5;
  padding: 1rem;
  tab-size: 4;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  margin: 0;
  border: 0;
}
.code-highlight {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #0f172a;
  color: #e2e8f0;
  pointer-events: none;
}
#code-editor {
  position: relative;
  display: block;
  width: 100%;
  max-width: none;
  background: transparent;
  color: transparent;         /* the overlay paints the letters */
  caret-color: #e2e8f0;
  border: 0;
  border-radius: 0 0 var(--radius) var(--radius);
  resize: vertical;
  overflow: auto;
  min-block-size: 16rem;
  box-shadow: none;
}
#code-editor:focus { box-shadow: none; border: 0; outline: none; }
#code-editor::selection { background: rgba(96, 165, 250, 0.35); }

/* Token colors (dark background) */
.tok-kw  { color: #c084fc; font-weight: 600; }  /* keywords: for, if, def… */
.tok-blt { color: #60a5fa; }                    /* builtins: print, input… */
.tok-str { color: #34d399; }                    /* strings */
.tok-num { color: #fbbf24; }                    /* numbers */
.tok-com { color: #7c8aa5; font-style: italic; }/* comments */

/* Autocomplete suggestion strip (phone-keyboard style) */
.suggest-strip {
  display: flex;
  gap: 0.3rem;
  overflow-x: auto;
  padding: 0.3rem 0.45rem;
  background: #1e293b;
  direction: ltr;
}
.suggest-chip {
  flex-shrink: 0;
  border: 1px solid #334155;
  border-radius: 8px;
  background: #0f172a;
  color: #e2e8f0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  min-block-size: 2.2rem;
  touch-action: manipulation;
}
.suggest-chip b { color: #60a5fa; }
.suggest-chip:active { background: #334155; }

/* Mobile-friendly editor toolbar */
.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  background: #1e293b;
  padding: 0.45rem;
  position: sticky;
  inset-block-start: 4rem; /* below the sticky site header */
  z-index: 5;
}
.editor-toolbar button {
  min-inline-size: 2.5rem;
  min-block-size: 2.5rem;
  border: 1px solid #334155;
  border-radius: 8px;
  background: #0f172a;
  color: #e2e8f0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  padding-inline: 0.5rem;
  touch-action: manipulation; /* no double-tap zoom on phones */
}
.editor-toolbar button:active { background: #334155; }
.editor-toolbar button svg {
  inline-size: 1.15rem;
  block-size: 1.15rem;
  display: block;
  margin-inline: auto;
  pointer-events: none; /* clicks land on the button, not the svg */
}
.editor-toolbar button[data-action] { color: #cbd5e1; }
.editor-toolbar .tb-snippet { color: #93c5fd; }
.editor-toolbar .tb-sep {
  inline-size: 1px;
  background: #334155;
  margin-inline: 0.2rem;
  align-self: stretch;
}

.editor-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-block: 1rem 0.5rem;
}

/* ============ Judge results ============ */
.test-grid { display: flex; gap: 0.55rem; flex-wrap: wrap; margin-block: 1rem; }
.test-badge {
  border-radius: var(--radius);
  padding: 0.5rem 0.9rem;
  font-weight: 700;
  font-size: 0.85rem;
  border: 1.5px solid var(--border);
  background: var(--surface);
  line-height: 1.4;
}
.test-badge small { font-weight: 600; opacity: 0.85; }
.test-pass { border-color: var(--ok); color: var(--ok-ink); background: var(--ok-soft); }
.test-fail { border-color: var(--bad); color: #b91c1c; background: var(--bad-soft); }
.test-pending { color: var(--muted); }

.score-big { font-size: 2.4rem; font-weight: 800; }
.score-good { color: var(--ok); }
.score-mid { color: var(--warn); }
.score-low { color: var(--bad); }

/* ============ Chat panel ============ */
.chat-panel { max-block-size: 30rem; display: flex; flex-direction: column; }
.chat-messages { overflow-y: auto; flex: 1; display: grid; gap: 0.5rem; padding-block: 0.5rem; }
.chat-msg { border-radius: var(--radius); padding: 0.55rem 0.95rem; max-inline-size: 85%; }
.chat-user { background: var(--grad-brand); color: #fff; justify-self: end; }
.chat-assistant { background: var(--bg); border: 1.5px solid var(--border); justify-self: start; }
.chat-details summary {
  cursor: pointer;
  font-weight: 700;
  margin-block: 0.75rem 0.25rem;
  color: var(--brand-ink);
}
.chat-input { display: flex; gap: 0.5rem; margin-block-start: 0.5rem; }
.chat-input input { flex: 1; max-width: none; }

/* ============ Confetti ============ */
.confetti-bit {
  position: fixed;
  z-index: 999;
  pointer-events: none;
  font-size: 1.2rem;
  animation: confetti-fall var(--dur, 1.8s) ease-in forwards;
}
@keyframes confetti-fall {
  0% { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(90vh) rotate(var(--spin, 540deg)); opacity: 0; }
}

/* ============ Error pages ============ */
.oops {
  text-align: center;
  margin-block-start: 4rem;
}
.oops-emoji { font-size: 5rem; display: block; animation: float 4s ease-in-out infinite; }
.oops h1 { margin-block: 0.5rem 0.25rem; }
.oops p { color: var(--muted); }

/* ============ Footer ============ */
.site-footer {
  margin-block-start: 3rem;
  padding-block: 1.6rem;
  color: var(--muted);
  font-size: 0.9rem;
  border-block-start: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.55);
}
.site-footer .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Plain tables outside markdown (profile, samples) */
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid var(--border); padding: 0.55rem 0.8rem; text-align: start; }
th { background: var(--bg); font-weight: 800; }

/* ============ Motion preferences & small screens ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 640px) {
  h1 { font-size: 1.45rem; }
  .hero { padding: 1.6rem 1.4rem; }
  .hero h1 { font-size: 1.6rem; }
  .hero-art { font-size: 3.2rem; }
  .hud { padding: 1.1rem 1.2rem; gap: 1rem; }
  .card { padding: 1.1rem 1.15rem; }
  .node-marker { inline-size: 2.7rem; block-size: 2.7rem; }
  .quest-path::before { inset-inline-start: 1.3rem; }
  .editor-toolbar { inset-block-start: 0; }
}
